diff --git a/TestBenchFramework/BenchControl/DataEntry/Munich/CycleBeginningForm.cs b/TestBenchFramework/BenchControl/DataEntry/Munich/CycleBeginningForm.cs index 2d8d7fc84..e14510452 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Munich/CycleBeginningForm.cs +++ b/TestBenchFramework/BenchControl/DataEntry/Munich/CycleBeginningForm.cs @@ -1,5 +1,6 @@ using System; using System.Windows.Forms; +using log4net; using TBF.Resources; #pragma warning disable 162 /// Disables 'Unreachable code detected' warning @@ -8,6 +9,8 @@ namespace TBF.BenchControl.DataEntry.Munich { public partial class CycleBeginningForm : Form, GenericDevices.IHasCompleted { + private static readonly ILog log = LogManager.GetLogger(typeof(CycleBeginningForm)); + // To be retrieved after the form closes public string[] MainSNText; public string[] AuxSNText; @@ -23,6 +26,7 @@ namespace TBF.BenchControl.DataEntry.Munich MainSNText = new string[Program.WMsCount / 2]; AuxSNText = new string[Program.WMsCount / 2]; completed = false; + StartForceCloseHandler(); if (Program.WMsCount / 2 < 2) Height = 200; else if (Program.WMsCount / 2 < 3) Height = 355; @@ -65,5 +69,24 @@ namespace TBF.BenchControl.DataEntry.Munich completed = true; Close(); } - } + + #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); + }; + } + + void OnForceClose(object sender, EventArgs args) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + #endregion + } } diff --git a/TestBenchFramework/BenchControl/DataEntry/Munich/CycleEndForm.cs b/TestBenchFramework/BenchControl/DataEntry/Munich/CycleEndForm.cs index 0d6453ba6..d9d6bead9 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Munich/CycleEndForm.cs +++ b/TestBenchFramework/BenchControl/DataEntry/Munich/CycleEndForm.cs @@ -1,5 +1,6 @@ using System; using System.Windows.Forms; +using log4net; using TBF.Resources; #pragma warning disable 162 /// Disables 'Unreachable code detected' warning @@ -8,6 +9,8 @@ namespace TBF.BenchControl.DataEntry.Munich { public partial class CycleEndForm : Form, GenericDevices.IHasCompleted { + private static readonly ILog log = LogManager.GetLogger(typeof(CycleEndForm)); + // To be set before the form opens public string ProtocolName1; public string ProtocolName2; @@ -33,6 +36,7 @@ namespace TBF.BenchControl.DataEntry.Munich QRise = new float[Program.WMsCount / 2]; QFall = new float[Program.WMsCount / 2]; completed = false; + StartForceCloseHandler(); Localize(); } @@ -127,5 +131,24 @@ namespace TBF.BenchControl.DataEntry.Munich Close(); } } - } + + #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); + }; + } + + void OnForceClose(object sender, EventArgs args) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + #endregion + } } diff --git a/TestBenchFramework/BenchControl/DataEntry/Munich/EntryForm.cs b/TestBenchFramework/BenchControl/DataEntry/Munich/EntryForm.cs index 55d55e68b..624882770 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Munich/EntryForm.cs +++ b/TestBenchFramework/BenchControl/DataEntry/Munich/EntryForm.cs @@ -26,7 +26,7 @@ namespace TBF.BenchControl.DataEntry.Munich public float WMState(int wmNr) { return 0; } - System.Windows.Forms.Form mdlessDlg; + System.Windows.Forms.Form modelessDlg; bool resultSaved; @@ -84,8 +84,8 @@ namespace TBF.BenchControl.DataEntry.Munich /// void OpenBeginningDlg(EntryForm myRef) { - myRef.mdlessDlg = new CycleBeginningForm(); - mdlessDlg.Show(); + myRef.modelessDlg = new CycleBeginningForm(); + modelessDlg.Show(); } /// void OpenEndDlg(EntryForm myRef) @@ -94,8 +94,8 @@ namespace TBF.BenchControl.DataEntry.Munich endForm.ProtocolName1 = entryFormCfg.ProtocolTitle1; endForm.ProtocolName2 = entryFormCfg.ProtocolTitle2; endForm.ProtocolName3 = entryFormCfg.ProtocolTitle3; - myRef.mdlessDlg = endForm; - mdlessDlg.Show(); + myRef.modelessDlg = endForm; + modelessDlg.Show(); } /// Start this operation @@ -117,33 +117,34 @@ namespace TBF.BenchControl.DataEntry.Munich /// Event.ResultsPrinted public Event Run() { - if (!(mdlessDlg as IHasCompleted).Completed) + if (!(modelessDlg as IHasCompleted).Completed) { - return Event.None; /// Return 'None' when form was not closed yet + return Event.ModelessFormIsOpen; } if (!resultSaved) /// This is to save the result only once { - if (mdlessDlg is CycleBeginningForm) + if (modelessDlg is CycleBeginningForm) { - if (wMeters.Count >= 2 && wMeters[0] != null) wMeters[0].SerialNr = (mdlessDlg as CycleBeginningForm).MainSNText[0]; - if (wMeters.Count >= 2 && wMeters[1] != null) wMeters[1].SerialNr = (mdlessDlg as CycleBeginningForm).AuxSNText[0]; - if (wMeters.Count >= 4 && wMeters[2] != null) wMeters[2].SerialNr = (mdlessDlg as CycleBeginningForm).MainSNText[1]; - if (wMeters.Count >= 4 && wMeters[3] != null) wMeters[3].SerialNr = (mdlessDlg as CycleBeginningForm).AuxSNText[1]; - if (wMeters.Count >= 6 && wMeters[4] != null) wMeters[4].SerialNr = (mdlessDlg as CycleBeginningForm).MainSNText[2]; - if (wMeters.Count >= 6 && wMeters[5] != null) wMeters[5].SerialNr = (mdlessDlg as CycleBeginningForm).AuxSNText[2]; + if (wMeters.Count >= 2 && wMeters[0] != null) wMeters[0].SerialNr = (modelessDlg as CycleBeginningForm).MainSNText[0]; + if (wMeters.Count >= 2 && wMeters[1] != null) wMeters[1].SerialNr = (modelessDlg as CycleBeginningForm).AuxSNText[0]; + if (wMeters.Count >= 4 && wMeters[2] != null) wMeters[2].SerialNr = (modelessDlg as CycleBeginningForm).MainSNText[1]; + if (wMeters.Count >= 4 && wMeters[3] != null) wMeters[3].SerialNr = (modelessDlg as CycleBeginningForm).AuxSNText[1]; + if (wMeters.Count >= 6 && wMeters[4] != null) wMeters[4].SerialNr = (modelessDlg as CycleBeginningForm).MainSNText[2]; + if (wMeters.Count >= 6 && wMeters[5] != null) wMeters[5].SerialNr = (modelessDlg as CycleBeginningForm).AuxSNText[2]; } else { - if (wMeters.Count >= 2 && wMeters[0] != null) wMeters[0].EndState = (mdlessDlg as CycleEndForm).MainStateText[0]; - if (wMeters.Count >= 2 && wMeters[1] != null) wMeters[1].EndState = (mdlessDlg as CycleEndForm).AuxStateText[0]; - if (wMeters.Count >= 4 && wMeters[2] != null) wMeters[2].EndState = (mdlessDlg as CycleEndForm).MainStateText[1]; - if (wMeters.Count >= 4 && wMeters[3] != null) wMeters[3].EndState = (mdlessDlg as CycleEndForm).AuxStateText[1]; - if (wMeters.Count >= 6 && wMeters[4] != null) wMeters[4].EndState = (mdlessDlg as CycleEndForm).MainStateText[2]; - if (wMeters.Count >= 6 && wMeters[5] != null) wMeters[5].EndState = (mdlessDlg as CycleEndForm).AuxStateText[2]; - protocolTitle = (mdlessDlg as CycleEndForm).ProtocolTitle; + if (wMeters.Count >= 2 && wMeters[0] != null) wMeters[0].EndState = (modelessDlg as CycleEndForm).MainStateText[0]; + if (wMeters.Count >= 2 && wMeters[1] != null) wMeters[1].EndState = (modelessDlg as CycleEndForm).AuxStateText[0]; + if (wMeters.Count >= 4 && wMeters[2] != null) wMeters[2].EndState = (modelessDlg as CycleEndForm).MainStateText[1]; + if (wMeters.Count >= 4 && wMeters[3] != null) wMeters[3].EndState = (modelessDlg as CycleEndForm).AuxStateText[1]; + if (wMeters.Count >= 6 && wMeters[4] != null) wMeters[4].EndState = (modelessDlg as CycleEndForm).MainStateText[2]; + if (wMeters.Count >= 6 && wMeters[5] != null) wMeters[5].EndState = (modelessDlg as CycleEndForm).AuxStateText[2]; + protocolTitle = (modelessDlg as CycleEndForm).ProtocolTitle; } resultSaved = true; + modelessDlg = null; } return Event.ModelessFormClosed; /// Form closed @@ -152,7 +153,11 @@ namespace TBF.BenchControl.DataEntry.Munich /// Stop this operation public void Stop() { - mdlessDlg = null; + if (modelessDlg is IHasCompleted) + { + UiBridge.Bridge.OnCloseModelessForm(this, null); + modelessDlg = null; + } currentOp = CurrentOp.None; } diff --git a/TestBenchFramework/BenchControl/DataEntry/Munich3/CycleBeginningForm.cs b/TestBenchFramework/BenchControl/DataEntry/Munich3/CycleBeginningForm.cs index 7bda3c373..6b8e7c3cd 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Munich3/CycleBeginningForm.cs +++ b/TestBenchFramework/BenchControl/DataEntry/Munich3/CycleBeginningForm.cs @@ -1,12 +1,15 @@ using System; using System.Windows.Forms; +using log4net; using TBF.Resources; namespace TBF.BenchControl.DataEntry.Munich3 { public partial class CycleBeginningForm : Form, GenericDevices.IHasCompleted { - /// Number of text boxes for serial numbers + private static readonly ILog log = LogManager.GetLogger(typeof(CycleBeginningForm)); + + /// Number of text boxes for serial numbers public readonly int WaterMetersCount; /// To be retrieved after the form is closed @@ -26,6 +29,7 @@ namespace TBF.BenchControl.DataEntry.Munich3 InitializeComponent(); SNText = new string[WaterMetersCount]; completed = false; + StartForceCloseHandler(); //Height = 55 + WaterMetersCount * 105; } @@ -78,5 +82,24 @@ namespace TBF.BenchControl.DataEntry.Munich3 completed = true; Close(); } + + #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); + }; + } + + private void OnForceClose(object sender, EventArgs args) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + #endregion } } diff --git a/TestBenchFramework/BenchControl/DataEntry/Munich3/CycleEndForm.cs b/TestBenchFramework/BenchControl/DataEntry/Munich3/CycleEndForm.cs index f92414001..f45d3123a 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Munich3/CycleEndForm.cs +++ b/TestBenchFramework/BenchControl/DataEntry/Munich3/CycleEndForm.cs @@ -1,12 +1,15 @@ using System; using System.Windows.Forms; +using log4net; using TBF.Resources; namespace TBF.BenchControl.DataEntry.Munich3 { public partial class CycleEndForm : Form, GenericDevices.IHasCompleted { - /// Number of text boxes for serial numbers + private static readonly ILog log = LogManager.GetLogger(typeof(CycleEndForm)); + + /// Number of text boxes for serial numbers public readonly int WaterMetersCount; // To be set before the form opens @@ -32,7 +35,8 @@ namespace TBF.BenchControl.DataEntry.Munich3 InitializeComponent(); EndStateText = new string[WaterMetersCount]; completed = false; - } + StartForceCloseHandler(); + } /// Parameterless constructor for 3 watermeters public CycleEndForm() @@ -93,5 +97,24 @@ namespace TBF.BenchControl.DataEntry.Munich3 completed = true; Close(); } - } + + #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); + }; + } + + void OnForceClose(object sender, EventArgs args) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + #endregion + } } diff --git a/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryForm.cs b/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryForm.cs index 13fc1f9c6..65e8bd1b7 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryForm.cs +++ b/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryForm.cs @@ -119,7 +119,7 @@ namespace TBF.BenchControl.DataEntry.Munich3 { if (!(modelessDlg as IHasCompleted).Completed) { - return Event.None; /// Return 'None' when form was not closed yet + return Event.ModelessFormIsOpen; } if (!resultSaved) /// This is to save the result only once @@ -150,6 +150,7 @@ namespace TBF.BenchControl.DataEntry.Munich3 if (count > 5 && waterMeters[5] != null) waterMeters[5].EndState = dlg.EndStateText[5]; } resultSaved = true; + modelessDlg = null; } return Event.ModelessFormClosed; /// Form closed @@ -158,7 +159,11 @@ namespace TBF.BenchControl.DataEntry.Munich3 /// Stop this operation public void Stop() { - modelessDlg = null; + if (modelessDlg is IHasCompleted) + { + UiBridge.Bridge.OnCloseModelessForm(this, null); + modelessDlg = null; + } currentOp = CurrentOp.None; } diff --git a/TestBenchFramework/BenchControl/DataEntry/WMStates/EntryForm.cs b/TestBenchFramework/BenchControl/DataEntry/WMStates/EntryForm.cs index e4b541511..f77b09553 100644 --- a/TestBenchFramework/BenchControl/DataEntry/WMStates/EntryForm.cs +++ b/TestBenchFramework/BenchControl/DataEntry/WMStates/EntryForm.cs @@ -128,7 +128,7 @@ namespace TBF.BenchControl.DataEntry.WMStates { if (!(modelessDlg as IHasCompleted).Completed) { - return Event.None; /// Return 'None' when form was not closed yet + return Event.ModelessFormIsOpen; } if (!resultSaved) /// This is to save the result only once @@ -163,6 +163,7 @@ namespace TBF.BenchControl.DataEntry.WMStates if (dlg.WaterMetersCount > 5) wmState[5] = dlg.WMState[5]; } resultSaved = true; + modelessDlg = null; } return Event.ModelessFormClosed; /// Form closed @@ -171,7 +172,11 @@ namespace TBF.BenchControl.DataEntry.WMStates /// Stop this operation public void Stop() { - modelessDlg = null; + if (modelessDlg is IHasCompleted) + { + UiBridge.Bridge.OnCloseModelessForm(this, null); + modelessDlg = null; + } currentOp = CurrentOp.None; } } diff --git a/TestBenchFramework/BenchControl/DataEntry/WMStates/WMSNsAndStatesForm.cs b/TestBenchFramework/BenchControl/DataEntry/WMStates/WMSNsAndStatesForm.cs index fac00e745..a54ac4322 100644 --- a/TestBenchFramework/BenchControl/DataEntry/WMStates/WMSNsAndStatesForm.cs +++ b/TestBenchFramework/BenchControl/DataEntry/WMStates/WMSNsAndStatesForm.cs @@ -1,12 +1,15 @@ using System; using System.Windows.Forms; +using log4net; using TBF.Resources; namespace TBF.BenchControl.DataEntry.WMStates { public partial class WMSNsAndStatesForm : Form, GenericDevices.IHasCompleted { - /// Number of text boxes for serial numbers + private static readonly ILog log = LogManager.GetLogger(typeof(WMSNsAndStatesForm)); + + /// Number of text boxes for serial numbers public readonly int WaterMetersCount; /// To be retrieved after the form is closed @@ -30,6 +33,7 @@ namespace TBF.BenchControl.DataEntry.WMStates SNText = new string[WaterMetersCount]; WMState = new float[WaterMetersCount]; completed = false; + StartForceCloseHandler(); //Height = 55 + WaterMetersCount * 105; } @@ -102,5 +106,24 @@ namespace TBF.BenchControl.DataEntry.WMStates completed = true; Close(); } - } + + #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); + }; + } + + void OnForceClose(object sender, EventArgs args) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + #endregion + } } diff --git a/TestBenchFramework/BenchControl/DataEntry/WMStates/WMStatesForm.cs b/TestBenchFramework/BenchControl/DataEntry/WMStates/WMStatesForm.cs index 98fa038b9..548052005 100644 --- a/TestBenchFramework/BenchControl/DataEntry/WMStates/WMStatesForm.cs +++ b/TestBenchFramework/BenchControl/DataEntry/WMStates/WMStatesForm.cs @@ -1,12 +1,15 @@ using System; using System.Windows.Forms; +using log4net; using TBF.Resources; namespace TBF.BenchControl.DataEntry.WMStates { public partial class WMStatesForm : Form, GenericDevices.IHasCompleted { - /// Number of text boxes for serial numbers + private static readonly ILog log = LogManager.GetLogger(typeof(WMStatesForm)); + + /// Number of text boxes for serial numbers public readonly int WaterMetersCount; // To be retrieved after the form closes @@ -26,7 +29,8 @@ namespace TBF.BenchControl.DataEntry.WMStates InitializeComponent(); WMState = new float[WaterMetersCount]; completed = false; - } + StartForceCloseHandler(); + } /// Parameterless constructor for 3 watermeters public WMStatesForm() @@ -85,5 +89,24 @@ namespace TBF.BenchControl.DataEntry.WMStates completed = true; Close(); } - } + + #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); + }; + } + + void OnForceClose(object sender, EventArgs args) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + #endregion + } } diff --git a/TestBenchFramework/BenchControl/Events.cs b/TestBenchFramework/BenchControl/Events.cs index d0d03490a..9672f6b10 100644 --- a/TestBenchFramework/BenchControl/Events.cs +++ b/TestBenchFramework/BenchControl/Events.cs @@ -53,85 +53,86 @@ /// /// StateMachine events (issued by operations, IOperation derived classes) /// - public enum Event - { - None = 0, - Busy, /// Useful when waiting in state until at least one is busy (all are done) - Done, /// Useful when waiting in state until the first is done, the rest miht still be busy - /// - ModelessFormClosed, + public enum Event + { + None = 0, + Busy, /// Useful when waiting in state until at least one is busy (all are done) + Done, /// Useful when waiting in state until the first is done, the rest miht still be busy + /// + ModelessFormIsOpen, + ModelessFormClosed, - ValvesBusy, - ValvesSet, + ValvesBusy, + ValvesSet, - AmbientDone, - BalanceDone, - BalanceOverload, - PressureDone, - PressureInDone, - PressureOutDone, - TempDone, - TempInDone, - TempOutDone, - TempDivDone, - FlowMeasurementDone, - FlowReached, - PositionReached, - RegulValveTimeOut, /// Maximum allowed flow setting time has elapsed - ReadRegisterDone, - ReadReferenceDone, - AllPositionsReached, /// Used in SetAllRegulValvesOp - TurnPumpOnOffDone, + AmbientDone, + BalanceDone, + BalanceOverload, + PressureDone, + PressureInDone, + PressureOutDone, + TempDone, + TempInDone, + TempOutDone, + TempDivDone, + FlowMeasurementDone, + FlowReached, + PositionReached, + RegulValveTimeOut, /// Maximum allowed flow setting time has elapsed + ReadRegisterDone, + ReadReferenceDone, + AllPositionsReached, /// Used in SetAllRegulValvesOp + TurnPumpOnOffDone, - /// CheckUi events - UiCmdStartTest, - UiCmdStartQ1, - UiCmdStartQ2, - UiCmdStartQ3, - UiCmdStartCycle, - UiCmdStop, - UiCmdPurgeBegin, - UiCmdPurgeEnd, - UiCmdEmptyTank1, - UiCmdEmptyTank2, - UiCmdEmptyTank3, - UiCmdTestOpticalHeads, - UiCmdResetResults, - UiCmdAcceptResults, - UiCmdCalibration, - UiCmdCameraTest, - UiCmdSensitivityTest, - UiCmdB1, - UiCmdB2, - UiCmdB3, + /// CheckUi events + UiCmdStartTest, + UiCmdStartQ1, + UiCmdStartQ2, + UiCmdStartQ3, + UiCmdStartCycle, + UiCmdStop, + UiCmdPurgeBegin, + UiCmdPurgeEnd, + UiCmdEmptyTank1, + UiCmdEmptyTank2, + UiCmdEmptyTank3, + UiCmdTestOpticalHeads, + UiCmdResetResults, + UiCmdAcceptResults, + UiCmdCalibration, + UiCmdCameraTest, + UiCmdSensitivityTest, + UiCmdB1, + UiCmdB2, + UiCmdB3, - /// Process/Test oriented - PreviousStopped, - Wait, - ProcedureLoaded, - MeasurementStarted, - ReadAllRegistersDone, - MeasurementCompleted, - ResultsPrinted, - ResultsWritten, + /// Process/Test oriented + PreviousStopped, + Wait, + ProcedureLoaded, + MeasurementStarted, + ReadAllRegistersDone, + MeasurementCompleted, + ResultsPrinted, + ResultsWritten, - /// Timer events - TimerExpired, + /// Timer events + TimerExpired, - /// IDC camera events - CameraBusy, - CameraOpCompleted, - CameraOpFailed, - DetectionFailed, + /// IDC camera events + CameraBusy, + CameraOpCompleted, + CameraOpFailed, + DetectionFailed, - /// Generic - Error, /// Many ops.: Fatal error occurred - OpArgumentError, - ConfigurationError, - Yes, - No, - Next, /// To move to the next state when debugging - OK, - TimerBusy, - } + /// Generic + Error, /// Many ops.: Fatal error occurred + OpArgumentError, + ConfigurationError, + Yes, + No, + Next, /// To move to the next state when debugging + OK, + TimerBusy, + } } diff --git a/TestBenchFramework/BenchControl/GenericDevices/IHasCompleted.cs b/TestBenchFramework/BenchControl/GenericDevices/IHasCompleted.cs index 894c2e851..80e100bec 100644 --- a/TestBenchFramework/BenchControl/GenericDevices/IHasCompleted.cs +++ b/TestBenchFramework/BenchControl/GenericDevices/IHasCompleted.cs @@ -1,8 +1,10 @@ - +using System; + namespace TBF.BenchControl.GenericDevices { interface IHasCompleted { bool Completed { get; } + void StartForceCloseHandler(); } } diff --git a/TestBenchFramework/BenchControl/Sequences/MainSeq.cs b/TestBenchFramework/BenchControl/Sequences/MainSeq.cs index 930610ae1..582d224fb 100644 --- a/TestBenchFramework/BenchControl/Sequences/MainSeq.cs +++ b/TestBenchFramework/BenchControl/Sequences/MainSeq.cs @@ -159,11 +159,8 @@ namespace TBF.BenchControl.Sequences select_procedure: /// Make sure the CycleBeginForm is closed (aftrer an abnormal procedure/test end, etc.) - if (cycleBeginFormOpened) - { - cycleBeginFormOpened = false; - if (CloseCycleBeginForm()) goto stop; - } + CloseBeginForm(); + cycleBeginFormOpened = false; selection = MakeSelection(MKSelContext.ProcedureNotSelected); @@ -285,7 +282,7 @@ namespace TBF.BenchControl.Sequences if (cycleBeginFormOpened) { cycleBeginFormOpened = false; - if (CloseCycleBeginForm()) goto stop; + if (WaitBeginFormClosed()) goto stop; } if (e.Contains(Event.ConfigurationError)) goto select_cycle_or_test; @@ -331,7 +328,7 @@ namespace TBF.BenchControl.Sequences if (cycleBeginFormOpened) { cycleBeginFormOpened = false; - if (CloseCycleBeginForm()) goto stop; + if (WaitBeginFormClosed()) goto stop; } if (e.Contains(Event.Error)) goto error; @@ -364,7 +361,7 @@ namespace TBF.BenchControl.Sequences if (cycleBeginFormOpened) { cycleBeginFormOpened = false; - if (CloseCycleBeginForm()) goto stop; + if (WaitBeginFormClosed()) goto stop; } Bridge.OnActivity(this, "Enter protocol data"); diff --git a/TestBenchFramework/BenchControl/Sequences/SequenceBase.cs b/TestBenchFramework/BenchControl/Sequences/SequenceBase.cs index 827d98aec..a57c88416 100644 --- a/TestBenchFramework/BenchControl/Sequences/SequenceBase.cs +++ b/TestBenchFramework/BenchControl/Sequences/SequenceBase.cs @@ -581,26 +581,25 @@ namespace TBF.BenchControl.Sequences /// This function is typically called at the end of the first test of the procedure. /// /// false = OK, true = stop pressed - protected bool CloseCycleBeginForm() + protected bool WaitBeginFormClosed() { - IList e; GenericDevices.IDataEntry dataEntryCmpnt = TbfComponents.FindComponent(StateMachine.Procedure.DataEntry) as GenericDevices.IDataEntry; - if (dataEntryCmpnt as IHasCycleBeginForm != null) + + if ((dataEntryCmpnt as IHasCycleBeginForm != null) && State.LastEvents.Contains(Event.ModelessFormIsOpen)) { - if (!State.LastEvents.Contains(Event.ModelessFormClosed)) + IList e; + + /// Wait until modeless dialg is closed + State.Create("MainSeq : Check whether the entry form is closed") + .AddOperation(checkUiOp) + .EnterState(); + do { - /// Wait until modeless dialg is closed - State.Create("MainSeq : Check whether the entry form is closed") - .AddOperation(checkUiOp) - .EnterState(); - do - { - e = StateMachine.WaitRunDevsRunOps(); - if (e.Contains(Event.UiCmdStop)) return true; - } - while (!e.Contains(Event.ModelessFormClosed)); + e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.UiCmdStop)) return true; } + while (!e.Contains(Event.ModelessFormClosed)); /// A state without any dataEntryCmpnt operation so that Stop() when entering /// this state and Start() when entering the following state are executed. @@ -609,12 +608,44 @@ namespace TBF.BenchControl.Sequences .RemovePermanentOperation(dataEntryCmpnt as IOperation) .EnterState(); e = StateMachine.WaitRunDevsRunOps(); + if (e.Contains(Event.UiCmdStop)) return true; } + return false; } + /// + /// Forces closing of a modeless dialog for entering data at the beginnig of a procedure. + /// This function is typically called before starting a new cycle + /// in case previous cycle was aborted. + /// + protected void CloseBeginForm() + { + if (StateMachine.Procedure == null || StateMachine.Procedure.DataEntry == null) return; + + GenericDevices.IDataEntry dataEntryCmpnt = + TbfComponents.FindComponent(StateMachine.Procedure.DataEntry) as GenericDevices.IDataEntry; + + if ((dataEntryCmpnt as IHasCycleBeginForm != null) && State.LastEvents.Contains(Event.ModelessFormIsOpen)) + { + IList e; + + /// A state without any dataEntryCmpnt operation so that Stop() when entering + /// this state and Start() when entering the following state are executed. + State.Create("MainSeq : Nothing") + .RemovePermanentOperation(dataEntryCmpnt as IOperation) + .EnterState(); + do + { + e = StateMachine.WaitRunDevsRunOps(); + } + while (e.Contains(Event.ModelessFormIsOpen)); + } + } + + /// /// Main loop where measurements are collected. /// diff --git a/TestBenchFramework/BenchControl/TestMethods/Adjustment/AdjustmentSeq.cs b/TestBenchFramework/BenchControl/TestMethods/Adjustment/AdjustmentSeq.cs index 81ca4dfd8..df437899b 100644 --- a/TestBenchFramework/BenchControl/TestMethods/Adjustment/AdjustmentSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/Adjustment/AdjustmentSeq.cs @@ -240,7 +240,7 @@ namespace TBF.BenchControl.TestMethods.Adjustment if (cycleBeginFormOpened) { cycleBeginFormOpened = false; - if (CloseCycleBeginForm()) goto stopTest; + if (WaitBeginFormClosed()) goto stopTest; } /// diff --git a/TestBenchFramework/BenchControl/TestMethods/Adjustment/WMErrorsForm.cs b/TestBenchFramework/BenchControl/TestMethods/Adjustment/WMErrorsForm.cs index fc63672d3..cd3a34802 100644 --- a/TestBenchFramework/BenchControl/TestMethods/Adjustment/WMErrorsForm.cs +++ b/TestBenchFramework/BenchControl/TestMethods/Adjustment/WMErrorsForm.cs @@ -1,13 +1,16 @@ using System; using System.Drawing; using System.Windows.Forms; +using log4net; using TBF.Resources; namespace TBF.BenchControl.TestMethods.Adjustment { public partial class WMErrorsForm : Form, GenericDevices.IHasCompleted { - /// Number of text boxes for serial numbers + private static readonly ILog log = LogManager.GetLogger(typeof(WMErrorsForm)); + + /// Number of text boxes for serial numbers public readonly int WaterMetersCount; Entities.TestResult tr; @@ -167,5 +170,24 @@ namespace TBF.BenchControl.TestMethods.Adjustment g.FillPolygon(blackBrush, triangle); } } + + #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); + }; + } + + void OnForceClose(object sender, EventArgs args) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + #endregion } } diff --git a/TestBenchFramework/BenchControl/TestMethods/CombinedMeters/CombinedMetersSeq.cs b/TestBenchFramework/BenchControl/TestMethods/CombinedMeters/CombinedMetersSeq.cs index 6c4f0780b..aa30a1e7e 100644 --- a/TestBenchFramework/BenchControl/TestMethods/CombinedMeters/CombinedMetersSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/CombinedMeters/CombinedMetersSeq.cs @@ -338,7 +338,7 @@ namespace TBF.BenchControl.TestMethods.CombinedMeters if (cycleBeginFormOpened) { cycleBeginFormOpened = false; - if (CloseCycleBeginForm()) goto stopTest; + if (WaitBeginFormClosed()) goto stopTest; } /// Optionally supress pulses from the large water meter diff --git a/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs b/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs index 6c5a5aca0..0345cadb1 100644 --- a/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/CombinedWithDetection/CombinedWithDetectionSeq.cs @@ -541,7 +541,7 @@ namespace TBF.BenchControl.TestMethods.CombinedWithDetection if (cycleBeginFormOpened) { cycleBeginFormOpened = false; - if (CloseCycleBeginForm()) goto stop; + if (WaitBeginFormClosed()) goto stop; } /// Optionally supress pulses from the large water meter diff --git a/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs b/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs index 1b33f7ec0..f19ef43f4 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FixedStartMassCollection/FixedStartMassCollectionSeq.cs @@ -462,7 +462,7 @@ namespace TBF.BenchControl.TestMethods.FixedStartMassCollection if (cycleBeginFormOpened) { cycleBeginFormOpened = false; - if (CloseCycleBeginForm()) goto stopTest; + if (WaitBeginFormClosed()) goto stopTest; } /// diff --git a/TestBenchFramework/BenchControl/TestMethods/FlyingStart/FlyingStartSeq.cs b/TestBenchFramework/BenchControl/TestMethods/FlyingStart/FlyingStartSeq.cs index 816495af3..56013891c 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FlyingStart/FlyingStartSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FlyingStart/FlyingStartSeq.cs @@ -209,7 +209,7 @@ namespace TBF.BenchControl.TestMethods.FlyingStart if (cycleBeginFormOpened) { cycleBeginFormOpened = false; - if (CloseCycleBeginForm()) goto stopTest; + if (WaitBeginFormClosed()) goto stopTest; } /// diff --git a/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/FlyingStartCollectionMethodSeq.cs b/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/FlyingStartCollectionMethodSeq.cs index a26b1a509..76c442a2d 100644 --- a/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/FlyingStartCollectionMethodSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/FlyingStartCollectionMethod/FlyingStartCollectionMethodSeq.cs @@ -347,7 +347,7 @@ namespace TBF.BenchControl.TestMethods.FlyingStartCollectionMethod if (cycleBeginFormOpened) { cycleBeginFormOpened = false; - if (CloseCycleBeginForm()) goto stopTest; + if (WaitBeginFormClosed()) goto stopTest; } /// diff --git a/TestBenchFramework/BenchControl/TestMethods/LeakTest/LeakTestSeq.cs b/TestBenchFramework/BenchControl/TestMethods/LeakTest/LeakTestSeq.cs index 824c476eb..6b46412fc 100644 --- a/TestBenchFramework/BenchControl/TestMethods/LeakTest/LeakTestSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/LeakTest/LeakTestSeq.cs @@ -253,7 +253,7 @@ namespace TBF.BenchControl.TestMethods.LeakTest if (cycleBeginFormOpened) { cycleBeginFormOpened = false; - if (CloseCycleBeginForm()) goto stopTest; + if (WaitBeginFormClosed()) goto stopTest; } /// diff --git a/TestBenchFramework/BenchControl/TestMethods/PMaxTest/PMaxTestSeq.cs b/TestBenchFramework/BenchControl/TestMethods/PMaxTest/PMaxTestSeq.cs index cbad21127..f38a01b0d 100644 --- a/TestBenchFramework/BenchControl/TestMethods/PMaxTest/PMaxTestSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/PMaxTest/PMaxTestSeq.cs @@ -172,7 +172,7 @@ namespace TBF.BenchControl.TestMethods.PMaxTest if (cycleBeginFormOpened) { cycleBeginFormOpened = false; - if (CloseCycleBeginForm()) goto stopTest; + if (WaitBeginFormClosed()) goto stopTest; } /// diff --git a/TestBenchFramework/BenchControl/TestMethods/ReferenceFlowmeterCalibration/ReferenceFlowmeterCalibrationSeq.cs b/TestBenchFramework/BenchControl/TestMethods/ReferenceFlowmeterCalibration/ReferenceFlowmeterCalibrationSeq.cs index e5fae505c..3713fabef 100644 --- a/TestBenchFramework/BenchControl/TestMethods/ReferenceFlowmeterCalibration/ReferenceFlowmeterCalibrationSeq.cs +++ b/TestBenchFramework/BenchControl/TestMethods/ReferenceFlowmeterCalibration/ReferenceFlowmeterCalibrationSeq.cs @@ -326,7 +326,7 @@ namespace TBF.BenchControl.TestMethods.ReferenceFlowmeterCalibration if (cycleBeginFormOpened) { cycleBeginFormOpened = false; - if (CloseCycleBeginForm()) goto stopTest; + if (WaitBeginFormClosed()) goto stopTest; } /// diff --git a/TestBenchFramework/UiBridge/Bridge.cs b/TestBenchFramework/UiBridge/Bridge.cs index e74c19d77..5bca1bd49 100644 --- a/TestBenchFramework/UiBridge/Bridge.cs +++ b/TestBenchFramework/UiBridge/Bridge.cs @@ -208,5 +208,17 @@ namespace TBF.UiBridge catch (Exception e) { log.Error("EmergencyStopHandler(...) failed", e); } } public static event EventHandler EmergencyStopChangedHandler; - } + + + /// + /// Called from the state machine when an operation forces a modeless dialog close. + /// + public static void OnCloseModelessForm(object sender, EventArgs args) + { + if (CloseModelessFormHandler == null) return; + try { CloseModelessFormHandler(sender, null); } + catch (Exception e) { log.Error("CloseModelessFormHandler(...) failed", e); } + } + public static event EventHandler CloseModelessFormHandler; + } }