From f48a71ce12129073cf412d00dc1fa21332af0731 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Mon, 12 Nov 2018 14:16:03 +0100 Subject: [PATCH] UiBridge.Bridge.CloseModelessFormHandler isn't used, tank draining before a test is optional, fixes in simulations, ver. 2.18.1056 --- .../CombinedWithDetectionSeq.cs | 2 +- .../FixedStartTankCollectionSeq.cs | 19 ++-- .../FlyingStartFirstRepetWithMassCollSeq.cs | 2 +- .../FlyingStartMassCollProlongedSeq.cs | 2 +- .../FlyingStartMassCollectionSeq.cs | 4 +- .../FlyingStartTankCollectionSeq.cs | 102 ++++++++++++++++-- .../ManualLevelMsrmnt/ManualLevelMsrmnt.cs | 30 +++--- .../ManualLevelMsrmnt/WaterLevelForm.cs | 54 +++++++--- .../Various/TankWithLevelMsrmnt/Tank.cs | 8 +- TBF/Properties/AssemblyInfo.cs | 4 +- 10 files changed, 164 insertions(+), 63 deletions(-) diff --git a/TBF/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs b/TBF/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs index 8300b7aef..d2e05221e 100644 --- a/TBF/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs +++ b/TBF/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs @@ -25,7 +25,7 @@ namespace TBF.BenchControl.TestMethods.CombinedWithDetection { if (debugLevel == Config.Entities.DebugMode.Simulate) { - Simulate(test, repetitionNr, isLastRepetition, testParams); + return Simulate(test, repetitionNr, isLastRepetition, testParams); } diff --git a/TBF/BenchControl/TestMethods/FixedStartTankCollection/FixedStartTankCollectionSeq.cs b/TBF/BenchControl/TestMethods/FixedStartTankCollection/FixedStartTankCollectionSeq.cs index 900285da4..23daaf6bd 100644 --- a/TBF/BenchControl/TestMethods/FixedStartTankCollection/FixedStartTankCollectionSeq.cs +++ b/TBF/BenchControl/TestMethods/FixedStartTankCollection/FixedStartTankCollectionSeq.cs @@ -95,14 +95,17 @@ namespace TBF.BenchControl.TestMethods.FixedStartTankCollection string testName = Results.Utils.GetTestName(test.Name, test.Repeats, repetitionNr); - /// - /// Drain the water tank - /// - switch (DrainTheTank(tank)) - { - case Event.Error: { retVal = Event.Error; goto stopTest; } - case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; } - } + /// + /// Optionally drain the water tank + /// + if (test.DoDraining) + { + switch (DrainTheTank(tank)) + { + case Event.Error: { retVal = Event.Error; goto stopTest; } + case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; } + } + } //------------------------------------------------ diff --git a/TBF/BenchControl/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs b/TBF/BenchControl/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs index fc3e82d05..8777a8bc9 100644 --- a/TBF/BenchControl/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs +++ b/TBF/BenchControl/TestMethods/FlyingStartFirstRepetWithMassColl/FlyingStartFirstRepetWithMassCollSeq.cs @@ -35,7 +35,7 @@ namespace TBF.BenchControl.TestMethods.FlyingStartFirstRepetWithMassColl { if (debugLevel == Config.Entities.DebugMode.Simulate) { - Simulate(test, repetitionNr, isLastRepetition, singleTestParams, compoundTestParams, heatMetersTestParams); + return Simulate(test, repetitionNr, isLastRepetition, singleTestParams, compoundTestParams, heatMetersTestParams); } diff --git a/TBF/BenchControl/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs b/TBF/BenchControl/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs index 50f92e90c..9ae942bbc 100644 --- a/TBF/BenchControl/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs +++ b/TBF/BenchControl/TestMethods/FlyingStartMassCollProlonged/FlyingStartMassCollProlongedSeq.cs @@ -36,7 +36,7 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollProlonged { if (debugLevel == Config.Entities.DebugMode.Simulate) { - Simulate(test, repetitionNr, isLastRepetition, singleTestParams, compoundTestParams, heatMetersTestParams); + return Simulate(test, repetitionNr, isLastRepetition, singleTestParams, compoundTestParams, heatMetersTestParams); } diff --git a/TBF/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs b/TBF/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs index 360259eed..e77533dc2 100644 --- a/TBF/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs +++ b/TBF/BenchControl/TestMethods/FlyingStartMassCollection/FlyingStartMassCollectionSeq.cs @@ -34,11 +34,11 @@ namespace TBF.BenchControl.TestMethods.FlyingStartMassCollection { if (debugLevel == Config.Entities.DebugMode.Simulate) { - Simulate1(test, repetitionNr, isLastRepetition, compoundTestParams, heatMetersTestParams); + return Simulate1(test, repetitionNr, isLastRepetition, compoundTestParams, heatMetersTestParams); } else if (debugLevel == Config.Entities.DebugMode.Inherit) { - Simulate2(test, repetitionNr, isLastRepetition, compoundTestParams, heatMetersTestParams); + return Simulate2(test, repetitionNr, isLastRepetition, compoundTestParams, heatMetersTestParams); } diff --git a/TBF/BenchControl/TestMethods/FlyingStartTankCollection/FlyingStartTankCollectionSeq.cs b/TBF/BenchControl/TestMethods/FlyingStartTankCollection/FlyingStartTankCollectionSeq.cs index 98fc11899..b7ea3be14 100644 --- a/TBF/BenchControl/TestMethods/FlyingStartTankCollection/FlyingStartTankCollectionSeq.cs +++ b/TBF/BenchControl/TestMethods/FlyingStartTankCollection/FlyingStartTankCollectionSeq.cs @@ -29,7 +29,12 @@ namespace TBF.BenchControl.TestMethods.FlyingStartTankCollection Compound.CombinedTestParams compoundTestParams, Config.Entities.DebugMode debugLevel) { - IList e = new List(); /// Events from currently running operations + if (debugLevel == Config.Entities.DebugMode.Simulate) + { + return Simulate(test, repetitionNr, isLastRepetition, compoundTestParams); + } + + IList e = new List(); /// Events from currently running operations ITankWithVolumeMsrmnt tank = outPath.Scale as ITankWithVolumeMsrmnt; if (tank == null) @@ -90,14 +95,17 @@ namespace TBF.BenchControl.TestMethods.FlyingStartTankCollection TestStartTime = DateTime.Now; - /// - /// Drain the water tank - /// - switch (DrainTheTank(tank)) - { - case Event.Error: { retVal = Event.Error; goto stopTest; } - case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; } - } + /// + /// Optionally drain the water tank + /// + if (test.DoDraining) + { + switch (DrainTheTank(tank)) + { + case Event.Error: { retVal = Event.Error; goto stopTest; } + case Event.UiCmdStop: { retVal = Event.UiCmdStop; goto stopTest; } + } + } //------------------------------------------------ @@ -759,5 +767,81 @@ namespace TBF.BenchControl.TestMethods.FlyingStartTankCollection retList.Add(retVal); return retList; } + + + public IList Simulate(Config.Entities.Test test, int repetitionNr, bool isLastRepetition, + Compound.CombinedTestParams compoundTestParams) + { + /// + /// Test method simulation + /// + ITankWithVolumeMsrmnt tank = outPath.Scale as ITankWithVolumeMsrmnt; + if (tank == null) + { + Bridge.OnError(this, Strings.Missing_a_tank_with_volume_measurement); + + /// Create a list with one item 'retVal' (default is Event.Done) and return it + IList retListSim1 = new List(1); + retListSim1.Add(Event.ConfigurationError); + return retListSim1; + } + + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.FlowSetting)); + + IList e = new List(); /// Events from currently running operations + Event retVal = Event.Done; + DoubleBox volumeBox = new DoubleBox(); + /// + IOperation msrVolOp = tank.MeasureVolumeOp(ref volumeBox); + State.Create(string.Format("{0}({1}) : Water level measurement", test.Method, test.Name)) + .AddOperation(checkUiOp) + .AddOperation(msrVolOp) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopSimulation; } + if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; goto stopSimulation; } + } + while (!e.Contains(Event.VolumeDone)); + /// + log.WarnFormat("Volumes = {0}l", volumeBox.Val); + + + if (compoundTestParams != null) + { + if (test.Name.ToLower().Contains("nok")) MakeSimulatedCompound(test, 1, 0, 4.7f, 0.9f); + else MakeSimulatedCompound(test, 1, 0, 0.7f, 1.0f); + } + else + { + float errorPctBase = -1.0f; + if (test.Name.ToLower().Contains("q3")) errorPctBase = -0.5f; + else if (test.Name.ToLower().Contains("q2")) errorPctBase = 0.5f; + else if (test.Name.ToLower().Contains("q1")) errorPctBase = -5.1f; + + MakeSimulated(test, repetitionNr, 0, errorPctBase + repetitionNr * 0.1f); + } + + Bridge.OnTestProgress(this, new TestProgressEventArgs(test, repetitionNr, Config.Entities.Progress.Completed)); + Bridge.OnTestCompleted(this, new TestCompletedEventArgs(test.Name, BatchRslts.GetTestRslt(Results.Utils.GetTestName(test.Name, 1, 1), 0))); + allResults.Info(TestResult2CsvLine(test.Name, 0)); /// Append the results to the CSV-file + + //------------------------------------------------------------------- + Bridge.OnActivity(this, string.Format("{0} Simulation", test.Name)); + //------------------------------------------------------------------- + + State.Create(string.Format("{0}({1}) : Simulation", test.Method, test.Name)) + .AddOperation(checkUiOp) + .EnterState(); + e = StateMachine.WaitRunDevsRunOps(); + + stopSimulation: + + /// Create a list with one item 'retVal' (default is Event.Done) and return it + IList retListSim = new List(1); + retListSim.Add(retVal); + return retListSim; + } } } diff --git a/TBF/BenchControl/Various/ManualLevelMsrmnt/ManualLevelMsrmnt.cs b/TBF/BenchControl/Various/ManualLevelMsrmnt/ManualLevelMsrmnt.cs index a7559036c..1436dc9c6 100644 --- a/TBF/BenchControl/Various/ManualLevelMsrmnt/ManualLevelMsrmnt.cs +++ b/TBF/BenchControl/Various/ManualLevelMsrmnt/ManualLevelMsrmnt.cs @@ -18,9 +18,9 @@ namespace TBF.BenchControl.Various.ManualLevelMsrmnt DoubleBox levelBox; - public double WaterLevelMm; + public double WaterLevelMm; - System.Windows.Forms.Form modelessDlg; + WaterLevelForm waterLevelForm; bool resultSaved; /// Set in Run() when results are saved @@ -61,10 +61,11 @@ namespace TBF.BenchControl.Various.ManualLevelMsrmnt /// void OpenWaterLevelForm(ManualLevelMsrmnt myRef) { - myRef.modelessDlg = new WaterLevelForm(); - modelessDlg.Show(); + myRef.waterLevelForm = new WaterLevelForm(); + waterLevelForm.Show(); } + /// Start this operation public void Start() { @@ -79,20 +80,17 @@ namespace TBF.BenchControl.Various.ManualLevelMsrmnt /// Event.ResultsPrinted public Event Run() { - if ((modelessDlg is IHasCompleted) && !(modelessDlg as IHasCompleted).Completed) + if ((waterLevelForm != null) && !waterLevelForm.Completed) { return Event.Busy; /// = Form open } - if (!resultSaved) /// This is to save the result only once + if (!resultSaved && (currentOp == CurrentOp.EnterLevel) && (waterLevelForm != null)) { - if ((modelessDlg is WaterLevelForm) && (currentOp == CurrentOp.EnterLevel)) - { - WaterLevelMm = (modelessDlg as WaterLevelForm).WaterLevelMm; - if (levelBox != null) levelBox.Val = WaterLevelMm; - resultSaved = true; - modelessDlg = null; - } + /// Save the result (only once) + WaterLevelMm = waterLevelForm.WaterLevelMm; + if (levelBox != null) levelBox.Val = WaterLevelMm; + resultSaved = true; } return Event.LevelDone; /// = Form closed @@ -101,10 +99,10 @@ namespace TBF.BenchControl.Various.ManualLevelMsrmnt /// Stop this operation public void Stop() { - if (modelessDlg is IHasCompleted) + if (waterLevelForm != null) { - UiBridge.Bridge.OnCloseModelessForm(this, null); - modelessDlg = null; + waterLevelForm.OnCloseThisForm(this, null); + waterLevelForm = null; } currentOp = CurrentOp.None; } diff --git a/TBF/BenchControl/Various/ManualLevelMsrmnt/WaterLevelForm.cs b/TBF/BenchControl/Various/ManualLevelMsrmnt/WaterLevelForm.cs index 2c8645348..e1a848d51 100644 --- a/TBF/BenchControl/Various/ManualLevelMsrmnt/WaterLevelForm.cs +++ b/TBF/BenchControl/Various/ManualLevelMsrmnt/WaterLevelForm.cs @@ -8,7 +8,7 @@ using TBF.Resources; namespace TBF.BenchControl.Various.ManualLevelMsrmnt { - public partial class WaterLevelForm : Form, GenericDevices.IHasCompleted + public partial class WaterLevelForm : Form { private static readonly ILog log = LogManager.GetLogger(typeof(WaterLevelForm)); @@ -69,23 +69,43 @@ namespace TBF.BenchControl.Various.ManualLevelMsrmnt Close(); } - #region Forced close handling + #region Forced close handling - public void StartForceCloseHandler() - { - UiBridge.Bridge.CloseModelessFormHandler += delegate(object sender, EventArgs args) - { - if (InvokeRequired) { Invoke(new EventHandler(OnForceClose), sender, args); } - else OnForceClose(sender, args); - }; - } + /// + /// Used by CoverTest, AskYesNoOp and MessageBoxOp. + /// + public void OnCloseThisForm(object sender, EventArgs args) + { + if (CloseThisFormHandler == null) return; + try + { + CloseThisFormHandler(sender, null); + } + catch (Exception e) + { + log.Error("CloseThisFormHandler(...) failed", e); + } + } - void OnForceClose(object sender, EventArgs args) - { - DialogResult = DialogResult.Cancel; - Close(); - } + public event EventHandler CloseThisFormHandler; - #endregion - } + public void StartForceCloseHandler() + { + CloseThisFormHandler += delegate(object sender, EventArgs args) + { + if (InvokeRequired) + Invoke(new EventHandler(OnForceClose), sender, args); + else + OnForceClose(sender, args); + }; + } + + private void OnForceClose(object sender, EventArgs args) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + #endregion + } } diff --git a/TBF/BenchControl/Various/TankWithLevelMsrmnt/Tank.cs b/TBF/BenchControl/Various/TankWithLevelMsrmnt/Tank.cs index 453669c3b..6a02e271e 100644 --- a/TBF/BenchControl/Various/TankWithLevelMsrmnt/Tank.cs +++ b/TBF/BenchControl/Various/TankWithLevelMsrmnt/Tank.cs @@ -300,12 +300,8 @@ namespace TBF.BenchControl.Various.TankWithLevelMsrmnt public IOperation MeasureVolumeOp(ref DoubleBox volume) { if (currentOp != CurrentOp.None) throw new Exception("Sequence error"); - - if (readLevelOp == null) - { - readLevelOp = levelMeter.ReadLevelOp(ref levelBox); - } - this.volumeBox = volume; + this.volumeBox = volume; + readLevelOp = levelMeter.ReadLevelOp(ref levelBox); currentOp = CurrentOp.MeasureVolume; return this; } diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index d5f2493cb..1d313a4de 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.18.1055.0")] -[assembly: AssemblyFileVersion("2.18.1055.0")] +[assembly: AssemblyVersion("2.18.1056.0")] +[assembly: AssemblyFileVersion("2.18.1056.0")]