111 lines
2.6 KiB
C#
111 lines
2.6 KiB
C#
///
|
|
/// Copyright (c) 2018 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using log4net;
|
|
using TBF.BenchControl.GenericDevices;
|
|
using TBF.BenchControl.Configs.NameOnly;
|
|
using TBF.Boxes;
|
|
|
|
namespace TBF.BenchControl.Various.ManualLevelMsrmnt
|
|
{
|
|
public class ManualLevelMsrmnt : ComponentBase, ILevelMeter, IOperation
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(ManualLevelMsrmnt));
|
|
public override string ToString() { return string.Format("ManualLevelMsrmnt({0})", Cfg.ToString(1)); }
|
|
|
|
readonly TestMethodCfg myCfg;
|
|
|
|
public double Level { get { return level_mm; } }
|
|
double level_mm;
|
|
DoubleBox levelBox;
|
|
|
|
WaterLevelForm waterLevelForm;
|
|
|
|
bool resultSaved; /// Set in Run() when results are saved
|
|
|
|
public enum CurrentOp
|
|
{
|
|
None,
|
|
EnterLevel,
|
|
}
|
|
CurrentOp currentOp;
|
|
|
|
|
|
public ManualLevelMsrmnt()
|
|
{
|
|
currentOp = CurrentOp.None;
|
|
}
|
|
|
|
public ManualLevelMsrmnt(Generic.IComponentCfg cfg)
|
|
: base(cfg)
|
|
{
|
|
myCfg = cfg as TestMethodCfg;
|
|
|
|
currentOp = CurrentOp.None;
|
|
log.Debug(this.ToString());
|
|
}
|
|
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
public IOperation ReadLevelOp(ref DoubleBox levelBox)
|
|
{
|
|
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
|
|
this.levelBox = levelBox;
|
|
currentOp = CurrentOp.EnterLevel;
|
|
return this;
|
|
}
|
|
|
|
|
|
delegate void EntryFormDlgt(ManualLevelMsrmnt myRef);
|
|
///
|
|
void OpenWaterLevelForm(ManualLevelMsrmnt myRef)
|
|
{
|
|
myRef.waterLevelForm = new WaterLevelForm();
|
|
waterLevelForm.Show();
|
|
}
|
|
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Start()
|
|
{
|
|
resultSaved = false;
|
|
if (currentOp == CurrentOp.EnterLevel)
|
|
{
|
|
Program.MainWnd.Invoke(new EntryFormDlgt(OpenWaterLevelForm), this);
|
|
}
|
|
}
|
|
|
|
/// <summary>Run this operation</summary>
|
|
/// <returns>Event.ResultsPrinted</returns>
|
|
public Event Run()
|
|
{
|
|
if ((waterLevelForm != null) && !waterLevelForm.Completed)
|
|
{
|
|
return Event.Busy; /// = Form open
|
|
}
|
|
|
|
if (!resultSaved && (currentOp == CurrentOp.EnterLevel) && (waterLevelForm != null))
|
|
{
|
|
/// Save the result (only once)
|
|
level_mm = waterLevelForm.Level_mm;
|
|
if (levelBox != null) levelBox.Val = level_mm;
|
|
resultSaved = true;
|
|
}
|
|
|
|
return Event.LevelDone; /// = Form closed
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop()
|
|
{
|
|
if (waterLevelForm != null)
|
|
{
|
|
waterLevelForm.OnCloseThisForm(this, null);
|
|
waterLevelForm = null;
|
|
}
|
|
currentOp = CurrentOp.None;
|
|
}
|
|
}
|
|
}
|