From 5c9adba751514ae9933b1df4dc38a8fae176ff1d Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Wed, 7 Dec 2016 17:19:01 +0100 Subject: [PATCH] Endurance cycle steps dialog added. --- .../BenchControl/Elde/Valve/Valve.cs | 2 + .../TestMethods/Endurance/CycleDlg.cs | 265 ++++++++++++++++++ .../Endurance/CycleDlg.designer.cs | 91 ++++++ .../TestMethods/Endurance/CycleDlg.resx | 246 ++++++++++++++++ .../TestMethods/Endurance/CycleStep.cs | 91 ++++++ .../TestMethods/Endurance/CycleStepsCtrl.cs | 258 +++++++++++++++++ .../TestMethods/Endurance/TestMethodCfg.cs | 2 + .../Endurance/TestMethodCfgCtrl.cs | 16 ++ .../Endurance/TestMethodCfgCtrl.designer.cs | 18 +- TestBenchFramework/LocalSettings.cs | 5 + .../Resources/Strings.Designer.cs | 18 ++ TestBenchFramework/Resources/Strings.resx | 6 + TestBenchFramework/TBF.csproj | 13 + 13 files changed, 1029 insertions(+), 2 deletions(-) create mode 100644 TestBenchFramework/BenchControl/TestMethods/Endurance/CycleDlg.cs create mode 100644 TestBenchFramework/BenchControl/TestMethods/Endurance/CycleDlg.designer.cs create mode 100644 TestBenchFramework/BenchControl/TestMethods/Endurance/CycleDlg.resx create mode 100644 TestBenchFramework/BenchControl/TestMethods/Endurance/CycleStep.cs create mode 100644 TestBenchFramework/BenchControl/TestMethods/Endurance/CycleStepsCtrl.cs diff --git a/TestBenchFramework/BenchControl/Elde/Valve/Valve.cs b/TestBenchFramework/BenchControl/Elde/Valve/Valve.cs index ca9a119e4..c2e235757 100644 --- a/TestBenchFramework/BenchControl/Elde/Valve/Valve.cs +++ b/TestBenchFramework/BenchControl/Elde/Valve/Valve.cs @@ -30,6 +30,8 @@ namespace TBF.BenchControl.Elde.Valve public readonly ulong Mask; /// derived from bitPosition in the constructor + public int BitPosition { get { return valveCfg.BitPosition; } } + public Valve() { diff --git a/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleDlg.cs b/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleDlg.cs new file mode 100644 index 000000000..ea0922f46 --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleDlg.cs @@ -0,0 +1,265 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using log4net; +using NHibernate; +using Config.Entities; +using TBF.BenchControl.GenericDevices; +using TBF.Resources; + +namespace TBF.BenchControl.TestMethods.Endurance +{ + public partial class CycleDlg : Form, TBF.UiControls.IParentOfListViewEx + { + static readonly ILog log = LogManager.GetLogger(typeof(CycleDlg)); + + /// Used when re-scaling the dialog: 100% = 96dpi, 125% = 120dpi, 150% = 144dpi + public readonly int Dpi; + public const int Dpi100pct = 96; + + /// + /// Transition sequences to be updated by this dialog. + /// Set by the constructor or updated by the parent after creation and before loading. + /// + public IList EnduranceCycle; + + + /// Auxiliary public lists used also by user controls in tab pages + public IList TbfComponents; + public IList Valves; + + + TBF.UiControls.ITabWithListViewEx seqStepsCtrl; + + + public CycleDlg() + : this(new List()) + { + } + + public CycleDlg(IList cycle) + { + /// Detect display setting: 100% = 96dpi, 125% = 120dpi, 150% = 144dpi. + Dpi = (int)this.CreateGraphics().DpiX; + + InitializeComponent(); + + /// SharedDlgButtons configuration + sharedButtons.RequiredGroupMembership = Config.Grp.GID.Metrologists; + sharedButtons.OptionalButtons = TBF.UiControls.SharedButtons.Buttons.Add | + TBF.UiControls.SharedButtons.Buttons.Remove | + TBF.UiControls.SharedButtons.Buttons.Up | + TBF.UiControls.SharedButtons.Buttons.Down; + sharedButtons.Unlocked += Unlocked; + sharedButtons.OKClicked += okButton_Click; + sharedButtons.CancelClicked += cancelButton_Click; + sharedButtons.AddClicked += addButton_Click; + sharedButtons.RemoveClicked += removeButton_Click; + sharedButtons.UpClicked += upButton_Click; + sharedButtons.DownClicked += downButton_Click; + + seqStepsCtrl = new CycleStepsCtrl(); + + /// Prepare a list of valves for the endurance test + TbfComponents = BenchControl.TbfComponents.LoadComponentsFromDB(Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config)); + Valves = new List(); + for (int bitNr = 0; bitNr < 8; bitNr++) + { + foreach (var vlv in TbfComponents) + { + if (vlv is BenchControl.Elde.Valve.Valve && (vlv as BenchControl.Elde.Valve.Valve).BitPosition == bitNr) + { + Valves.Add(vlv as IValve); + break; + } + } + } + + EnduranceCycle = (cycle != null) ? cycle : new List(); /// TODO: Load from component parameters + + /// Create a tab with sequence steps for each sequence ordered by ItemNr. + AddCycleStepsTab(EnduranceCycle); + } + + void AddCycleStepsTab(IList sequence) + { + TabPage nwTab = new TabPage(); + nwTab.Tag = sequence; + CycleStepsCtrl newCtrl = new CycleStepsCtrl(); + seqStepsCtrl = newCtrl; + nwTab.Controls.Add(newCtrl); + tabControl.TabPages.Add(nwTab); + newCtrl.Initialize(sequence, this, tabControl.TabPages[tabControl.TabPages.Count - 1]); + newCtrl.SelectedIndexChanged += new System.EventHandler(SelectedIndexChanged); + } + + private void CycleDlg_Load(object sender, EventArgs e) + { + Localize(); + + TBF.LocalSettings ls = Program.LocalSettings; + Width = (ls.EnduranceDlgWidth > 0) ? ls.EnduranceDlgWidth : 1050; + Height = (ls.EnduranceDlgHeight > 0) ? ls.EnduranceDlgHeight : 360; + Left = (ls.EnduranceDlgLeft != 0) ? ls.EnduranceDlgLeft : 150; + Top = (ls.EnduranceDlgTop != 0) ? ls.EnduranceDlgTop : 150; + + /// Now refresh the content of the dialog + RefreshAllTabs(); + } + + void Localize() + { + Text = Strings.Endurance_cycle_steps; + } + + void RefreshAllTabs() + { + if (seqStepsCtrl != null) (seqStepsCtrl as Results.Forms.ListViewEx).Refresh(); + } + + private void Unlocked(object sender, EventArgs e) + { + if (seqStepsCtrl != null) seqStepsCtrl.Unlock(); + } + + private void okButton_Click(object sender, EventArgs e) + { + if (seqStepsCtrl != null) seqStepsCtrl.OkBtnClicked(); + + //if (EnduranceCycle != null) + //{ + // using (var transaction = Session.BeginTransaction()) + // { + // try + // { + // Session.SaveOrUpdate(EnduranceCycle); + // transaction.Commit(); + // } + // catch (Exception e2) + // { + // MessageBox.Show(Strings.Cannot_save_changes, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + // log.ErrorFormat("Update of sequence 'Tr1' in the database failed: {0}", e2.Message); + // } + // } + //} + + Program.LocalSettings.EnduranceDlgLeft = Location.X; + Program.LocalSettings.EnduranceDlgTop = Location.Y; + Program.LocalSettings.EnduranceDlgWidth = Size.Width; + Program.LocalSettings.EnduranceDlgHeight = Size.Height; + Program.LocalSettings.Save(); + + DialogResult = DialogResult.OK; + Close(); + return; + } + + private void cancelButton_Click(object sender, EventArgs e) + { + Program.LocalSettings.EnduranceDlgLeft = Location.X; + Program.LocalSettings.EnduranceDlgTop = Location.Y; + Program.LocalSettings.EnduranceDlgWidth = Size.Width; + Program.LocalSettings.EnduranceDlgHeight = Size.Height; + Program.LocalSettings.Save(); + + DialogResult = DialogResult.Cancel; + Close(); + return; + } + + int slctdTab; + + private void tabControl_SelectedIndexChanged(object sender, EventArgs e) + { + if (seqStepsCtrl != null) + { + seqStepsCtrl.OkBtnClicked(); + } + slctdTab = tabControl.SelectedIndex; + sharedButtons.SetEnabled(TBF.UiControls.SharedButtons.Buttons.Add, true); + sharedButtons.DisableButtons(TBF.UiControls.SharedButtons.Buttons.Remove); + RefreshAllTabs(); + } + + private void addButton_Click(object sender, EventArgs e) + { + if (seqStepsCtrl != null) seqStepsCtrl.AddOne(); + } + + private void removeButton_Click(object sender, EventArgs e) + { + if (seqStepsCtrl != null) seqStepsCtrl.RemoveSelected(); + } + + private void upButton_Click(object sender, EventArgs e) + { + if (seqStepsCtrl != null) seqStepsCtrl.MoveUpSelected(); + } + + private void downButton_Click(object sender, EventArgs e) + { + if (seqStepsCtrl != null) seqStepsCtrl.MoveDownSelected(); + } + + public void UpdateButtonStates(TBF.UiControls.SharedButtons.SelectedItemPos selectedItemPos) + { + if (selectedItemPos == TBF.UiControls.SharedButtons.SelectedItemPos.None) + { + sharedButtons.DisableButtons(TBF.UiControls.SharedButtons.Buttons.Up | + TBF.UiControls.SharedButtons.Buttons.Down); + } + else if (selectedItemPos == TBF.UiControls.SharedButtons.SelectedItemPos.First) + { + sharedButtons.EnableButtons(TBF.UiControls.SharedButtons.Buttons.Down); + sharedButtons.DisableButtons(TBF.UiControls.SharedButtons.Buttons.Up); + } + else if (selectedItemPos == TBF.UiControls.SharedButtons.SelectedItemPos.Last) + { + sharedButtons.EnableButtons(TBF.UiControls.SharedButtons.Buttons.Up); + sharedButtons.DisableButtons(TBF.UiControls.SharedButtons.Buttons.Down); + } + else if (selectedItemPos == TBF.UiControls.SharedButtons.SelectedItemPos.FirstAndLast) + { + sharedButtons.DisableButtons(TBF.UiControls.SharedButtons.Buttons.Up | + TBF.UiControls.SharedButtons.Buttons.Down); + } + else + { + sharedButtons.EnableButtons(TBF.UiControls.SharedButtons.Buttons.Up | + TBF.UiControls.SharedButtons.Buttons.Down); + } + } + + /// + /// Common part for three xxxListViewEx_SelectedIndexChanged event handlers + /// + /// + void SelectedIndexChanged(object sender, EventArgs e) + { + Results.Forms.ListViewEx listViewEx = sender as Results.Forms.ListViewEx; + if (listViewEx.SelectedItems.Count != 1) + { + UpdateButtonStates(TBF.UiControls.SharedButtons.SelectedItemPos.None); + } + else if (listViewEx.Items.Count == 1) + { + UpdateButtonStates(TBF.UiControls.SharedButtons.SelectedItemPos.FirstAndLast); + } + else if (listViewEx.SelectedIndices[0] == 0) + { + UpdateButtonStates(TBF.UiControls.SharedButtons.SelectedItemPos.First); + } + else if (listViewEx.SelectedIndices[0] == (listViewEx.Items.Count - 1)) + { + UpdateButtonStates(TBF.UiControls.SharedButtons.SelectedItemPos.Last); + } + else + { + UpdateButtonStates(TBF.UiControls.SharedButtons.SelectedItemPos.Middle); + } + } + } +} diff --git a/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleDlg.designer.cs b/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleDlg.designer.cs new file mode 100644 index 000000000..4f0d0ac55 --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleDlg.designer.cs @@ -0,0 +1,91 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +namespace TBF.BenchControl.TestMethods.Endurance +{ + partial class CycleDlg + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CycleDlg)); + this.mainSplitContainer = new System.Windows.Forms.SplitContainer(); + this.tabControl = new System.Windows.Forms.TabControl(); + this.sharedButtons = new TBF.UiControls.SharedButtons(); + ((System.ComponentModel.ISupportInitialize)(this.mainSplitContainer)).BeginInit(); + this.mainSplitContainer.Panel1.SuspendLayout(); + this.mainSplitContainer.Panel2.SuspendLayout(); + this.mainSplitContainer.SuspendLayout(); + this.SuspendLayout(); + // + // mainSplitContainer + // + resources.ApplyResources(this.mainSplitContainer, "mainSplitContainer"); + this.mainSplitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel2; + this.mainSplitContainer.Name = "mainSplitContainer"; + // + // mainSplitContainer.Panel1 + // + this.mainSplitContainer.Panel1.Controls.Add(this.tabControl); + // + // mainSplitContainer.Panel2 + // + this.mainSplitContainer.Panel2.Controls.Add(this.sharedButtons); + // + // tabControl + // + resources.ApplyResources(this.tabControl, "tabControl"); + this.tabControl.Name = "tabControl"; + this.tabControl.SelectedIndex = 0; + this.tabControl.SelectedIndexChanged += new System.EventHandler(this.tabControl_SelectedIndexChanged); + // + // sharedButtons + // + resources.ApplyResources(this.sharedButtons, "sharedButtons"); + this.sharedButtons.Name = "sharedButtons"; + // + // CycleDlg + // + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.mainSplitContainer); + this.Name = "CycleDlg"; + this.Load += new System.EventHandler(this.CycleDlg_Load); + this.mainSplitContainer.Panel1.ResumeLayout(false); + this.mainSplitContainer.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.mainSplitContainer)).EndInit(); + this.mainSplitContainer.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.SplitContainer mainSplitContainer; + private System.Windows.Forms.TabControl tabControl; + private UiControls.SharedButtons sharedButtons; + } +} \ No newline at end of file diff --git a/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleDlg.resx b/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleDlg.resx new file mode 100644 index 000000000..cd69c302b --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleDlg.resx @@ -0,0 +1,246 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + Fill + + + + True + + + + 0, 0 + + + Fill + + + 1, 1 + + + 0, 0 + + + 760, 366 + + + 1 + + + tabControl + + + System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + mainSplitContainer.Panel1 + + + 0 + + + mainSplitContainer.Panel1 + + + System.Windows.Forms.SplitterPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + mainSplitContainer + + + 0 + + + -1, 0 + + + 100, 636 + + + 0 + + + sharedButtons + + + TBF.UiControls.SharedButtons, TBF, Version=2.12.404.1, Culture=neutral, PublicKeyToken=null + + + mainSplitContainer.Panel2 + + + 0 + + + mainSplitContainer.Panel2 + + + System.Windows.Forms.SplitterPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + mainSplitContainer + + + 1 + + + 863, 366 + + + 760 + + + 1 + + + mainSplitContainer + + + System.Windows.Forms.SplitContainer, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + True + + + 6, 13 + + + 863, 366 + + + CenterParent + + + Cycle steps + + + CycleDlg + + + System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleStep.cs b/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleStep.cs new file mode 100644 index 000000000..e2e5503e7 --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleStep.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace TBF.BenchControl.TestMethods.Endurance +{ + public class CycleStep + { + public virtual int Duration { get; set; } /// Duration in seconds + public virtual string Message { get; set; } /// Message + public virtual int ValvesOpen { get; set; } /// List of valves to be opened + public virtual int ValvesClose { get; set; } /// List of valves to be closed + + + public CycleStep() + { + Duration = 1; + Message = string.Empty; + ValvesOpen = 0; + ValvesClose = 0; + } + + + public override string ToString() + { + return string.Format("{0}~{1}~{2}~{3}", Duration, Message, ValvesOpen, ValvesClose); + } + + + /// + /// Create CycleStep from a string generated previously by ToString() function + /// + /// String generated by ToString() + public CycleStep(string savedStr) + + { + string[] strArr = savedStr.Split(new char[] { '~' }); + int duration; + int vO; + int vC; + if (strArr.Length != 4 || !int.TryParse(strArr[0], out duration) + || !int.TryParse(strArr[2], out vO) + || !int.TryParse(strArr[3], out vC)) + { + Duration = 1; + Message = string.Empty; + ValvesOpen = 0; + ValvesClose = 0; + } + else + { + Duration = duration; + Message = strArr[1]; + ValvesOpen = vO; + ValvesClose = vC; + } + } + + + public static string CycleToString(IList cycle) + { + if (cycle == null) return string.Empty; + + StringBuilder sb = new StringBuilder(); + foreach (var step in cycle) + { + if (sb.Length > 0) sb.Append('§'); + sb.Append(step.ToString()); + } + return sb.ToString(); + } + + + public static IList StringToCycle(string savedCycle) + { + IList cycle = new List(); + + if (!string.IsNullOrEmpty(savedCycle)) + { + + string[] lines = savedCycle.Split(new char[] { '§' }); + foreach (var line in lines) + { + cycle.Add(new CycleStep(line)); + } + } + + return cycle; + } + } +} diff --git a/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleStepsCtrl.cs b/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleStepsCtrl.cs new file mode 100644 index 000000000..0e801d0d9 --- /dev/null +++ b/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleStepsCtrl.cs @@ -0,0 +1,258 @@ +/// +/// Copyright (c) 2016 Sensus Metering Systems +/// +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms; +using log4net; +using Config.Entities; +using TBF.BenchControl.GenericDevices; +using TBF.Resources; + +namespace TBF.BenchControl.TestMethods.Endurance +{ + public partial class CycleStepsCtrl : TBF.UiControls.BaseWithListViewEx, TBF.UiControls.ITabWithListViewEx + { + static readonly ILog log = LogManager.GetLogger(typeof(CycleStepsCtrl)); + + /// + /// Fixed ListViewEx columns + /// + enum Column + { + Duration, + Message, + FixedColumnsCount, + } + readonly int fixedCount = (int)Column.FixedColumnsCount; + + IList sequence; + + CycleDlg parent; + Control parentControl; + Control[] editors; + + int vCount; /// Number of valves + + public CycleStepsCtrl() + : base() + { + } + + public void Initialize(IList sequence, CycleDlg parent, Control parentControl) + { + this.sequence = sequence; + this.parent = parent; + this.parentControl = parentControl; + Name = "Dummy"; + MyItems = sequence; + + SubItemClicked += new Results.Forms.SubItemEventHandler(listViewEx_SubItemClicked); + SubItemRightClicked += new Results.Forms.SubItemEventHandler(listViewEx_SubItemRightClicked); + SubItemEndEditing += new Results.Forms.SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing); + + + /// + /// ListViewEx columns + /// + Columns.Add(Strings.Duration_s, 70 * parent.Dpi / PathsDlg.Dpi100pct); + Columns.Add(Strings.Message, 100 * parent.Dpi / PathsDlg.Dpi100pct); + /// + vCount = 0; + foreach (var vlv in parent.Valves) + { + Columns.Add(vlv.Cfg.Name, 50 * parent.Dpi / PathsDlg.Dpi100pct); + vCount++; + } + + /// + /// Prepare valve combo-boxes + /// + TextBox tb; + ComboBox cb; + editors = new Control[fixedCount + vCount]; + + /// Duration + editors[(int)Column.Duration] = tb = new TextBox(); + tb.Visible = false; + parent.Controls.Add(tb); + + /// Message + editors[(int)Column.Message] = tb = new TextBox(); + tb.Visible = false; + parent.Controls.Add(tb); + + /// Valves + for (int i = fixedCount; i < fixedCount + vCount; i++) + { + editors[i] = cb = new ComboBox(); + cb.Visible = false; + cb.Items.Add("---"); + cb.Items.Add(Strings.open); + cb.Items.Add(Strings.close); + parent.Controls.Add(cb); + } + + base.RedrawAll(); + } + + void listViewEx_SubItemClicked(object sender, Results.Forms.SubItemEventArgs e) + { + if (!Unlocked || e.SubItem >= editors.Length) return; + StartEditing(editors[e.SubItem], e.Item, e.SubItem); + } + + void listViewEx_SubItemRightClicked(object sender, Results.Forms.SubItemEventArgs e) + { + if (!Unlocked || e.SubItem >= editors.Length) return; + + if (DialogResult.Yes == MessageBox.Show(Strings.Do_you_want_to_copy_this_value_to_all_cells_below_this_cell, + Strings.Confirmation, MessageBoxButtons.YesNo, MessageBoxIcon.Question)) + { + int columnNr = e.SubItem; + string value = null; + System.Drawing.Color backColor = System.Drawing.Color.White; + foreach (ListViewItem item in Items) + { + if (value != null) + { + item.SubItems[columnNr].Text = value; + item.SubItems[columnNr].BackColor = backColor; + } + else if (item == e.Item) + { + value = item.SubItems[columnNr].Text; + backColor = item.SubItems[columnNr].BackColor; + } + } + } + } + + void listViewEx_SubItemEndEditing(object sender, Results.Forms.SubItemEndEditingEventArgs e) + { + if (e.SubItem == (int)Column.Duration) + { + int duration; + if (!int.TryParse(e.DisplayText, out duration) || duration <= 0) + { + e.DisplayText = e.Item.Text; + e.Cancel = true; + } + } + else if (e.SubItem == (int)Column.Message) + { + if (e.DisplayText.Length >= 255) + { + // Message too long + e.DisplayText = e.Item.SubItems[e.SubItem].Text; + e.Cancel = true; + } + } + else if ((e.SubItem >= fixedCount) && (e.SubItem < fixedCount + vCount)) + { + if ((e.DisplayText != Strings.open) && (e.DisplayText != Strings.close) && (e.DisplayText != "---")) + { + e.DisplayText = e.Item.SubItems[e.SubItem].Text; + e.Cancel = true; + } + else + { + e.Item.SubItems[e.SubItem].BackColor = e.DisplayText == Strings.open ? Color.LightGray : Color.White; + } + } + } + + public override void DrawOne(object myItem) + { + CycleStep step = (CycleStep)myItem; + + ListViewItem lvi = new ListViewItem(step.Duration.ToString()); + lvi.UseItemStyleForSubItems = false; + + lvi.SubItems.Add(string.IsNullOrEmpty(step.Message) ? string.Empty : step.Message); + + for (int i = 0; i < parent.Valves.Count; i++) + { + if ((step.ValvesOpen & (1 << i)) != 0) + { + lvi.SubItems.Add(Strings.open); + lvi.SubItems[lvi.SubItems.Count - 1].BackColor = Color.LightGray; + } + else if ((step.ValvesClose & (1 << i)) != 0) + { + lvi.SubItems.Add(Strings.close); + lvi.SubItems[lvi.SubItems.Count - 1].BackColor = Color.White; + } + else + { + lvi.SubItems.Add("---"); + lvi.SubItems[lvi.SubItems.Count - 1].BackColor = Color.White; + } + } + + lvi.Tag = step; + + Items.Add(lvi); + } + + public override void UpdateOne(ListViewItem lvi, object myItem) + { + CycleStep step = (CycleStep)myItem; + + /// + /// Duration + /// + int duration; + if (int.TryParse(lvi.Text, out duration) && duration > 0) + step.Duration = duration; + else + lvi.Text = step.Duration.ToString(); + + /// + /// Message + /// + if (lvi.SubItems[(int)Column.Message].Text.Length == 0) + step.Message = string.Empty; + else + step.Message = lvi.SubItems[(int)Column.Message].Text; + + + /// + /// Valves + /// + int k = 0; + int valvesOpen = 0; + int valvesClose = 0; + /// + for (int i = 0; i < parent.Valves.Count; i++) + { + IValve valve = parent.Valves[i]; + string lviSubitText = lvi.SubItems[fixedCount + k++].Text; + if (lviSubitText.Equals(Strings.open)) + { + valvesOpen += (1 << i); + } + if (lviSubitText.Equals(Strings.close)) + { + valvesClose += (1 << i); + } + } + step.ValvesOpen = valvesOpen; + step.ValvesClose = valvesClose; + } + + public void AddOne() + { + base.AddOne(new CycleStep()); + } + + public new void RemoveSelected() + { + bool lastItemRemoved = base.RemoveSelected(); + if (lastItemRemoved && parent != null) + { + parent.UpdateButtonStates(TBF.UiControls.SharedButtons.SelectedItemPos.None); + } + } + } +} diff --git a/TestBenchFramework/BenchControl/TestMethods/Endurance/TestMethodCfg.cs b/TestBenchFramework/BenchControl/TestMethods/Endurance/TestMethodCfg.cs index ab0f2d4dd..e6f458a10 100644 --- a/TestBenchFramework/BenchControl/TestMethods/Endurance/TestMethodCfg.cs +++ b/TestBenchFramework/BenchControl/TestMethods/Endurance/TestMethodCfg.cs @@ -14,6 +14,8 @@ namespace TBF.BenchControl.TestMethods.Endurance { public IComponentCfgCtrl GetControl() { return new TestMethodCfgCtrl(); } + public string Cycle; + /// Test parameters [XmlIgnore] public TestParams TestParams; diff --git a/TestBenchFramework/BenchControl/TestMethods/Endurance/TestMethodCfgCtrl.cs b/TestBenchFramework/BenchControl/TestMethods/Endurance/TestMethodCfgCtrl.cs index 5bad7a130..21c199efa 100644 --- a/TestBenchFramework/BenchControl/TestMethods/Endurance/TestMethodCfgCtrl.cs +++ b/TestBenchFramework/BenchControl/TestMethods/Endurance/TestMethodCfgCtrl.cs @@ -5,6 +5,7 @@ using System; using System.Windows.Forms; using log4net; using TBF.BenchControl.Generic; +using TBF.Resources; namespace TBF.BenchControl.TestMethods.Endurance { @@ -14,6 +15,8 @@ namespace TBF.BenchControl.TestMethods.Endurance public bool ShowMore { get { return false; } } + string cycle; + TestMethodCfg config; public IComponentCfg Config { @@ -32,6 +35,8 @@ namespace TBF.BenchControl.TestMethods.Endurance private void EntryFormCfgCtrl_Load(object sender, EventArgs e) { + enduranceCycleButton.Text = Strings.Endurance_cycle; + cycle = config.Cycle; Redraw(); } @@ -49,6 +54,7 @@ namespace TBF.BenchControl.TestMethods.Endurance public void Unlock() { nameTextBox.Enabled = true; + enduranceCycleButton.Enabled = true; } public CfgUpdateFlags VerifyCfg(ref string message) @@ -64,8 +70,18 @@ namespace TBF.BenchControl.TestMethods.Endurance if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed config.Name = nameTextBox.Text; + config.Cycle = cycle; return flags; } + + private void enduranceCycleButton_Click(object sender, EventArgs e) + { + CycleDlg dlg = new CycleDlg(CycleStep.StringToCycle(cycle)); + if (dlg.ShowDialog() == DialogResult.OK) + { + cycle = CycleStep.CycleToString(dlg.EnduranceCycle); + } + } } } diff --git a/TestBenchFramework/BenchControl/TestMethods/Endurance/TestMethodCfgCtrl.designer.cs b/TestBenchFramework/BenchControl/TestMethods/Endurance/TestMethodCfgCtrl.designer.cs index 58dde76b1..14ef77a4d 100644 --- a/TestBenchFramework/BenchControl/TestMethods/Endurance/TestMethodCfgCtrl.designer.cs +++ b/TestBenchFramework/BenchControl/TestMethods/Endurance/TestMethodCfgCtrl.designer.cs @@ -34,6 +34,7 @@ namespace TBF.BenchControl.TestMethods.Endurance this.nameTextBox = new System.Windows.Forms.TextBox(); this.nameLabel = new System.Windows.Forms.Label(); this.classNameLabel = new System.Windows.Forms.Label(); + this.enduranceCycleButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // // nameTextBox @@ -62,14 +63,26 @@ namespace TBF.BenchControl.TestMethods.Endurance this.classNameLabel.TabIndex = 3; this.classNameLabel.Text = "ComonentName"; // - // BasicPrinterCfgCtrl + // enduranceCycleButton + // + this.enduranceCycleButton.Enabled = false; + this.enduranceCycleButton.Location = new System.Drawing.Point(137, 83); + this.enduranceCycleButton.Name = "enduranceCycleButton"; + this.enduranceCycleButton.Size = new System.Drawing.Size(130, 31); + this.enduranceCycleButton.TabIndex = 6; + this.enduranceCycleButton.Text = "Endurance cycle"; + this.enduranceCycleButton.UseVisualStyleBackColor = true; + this.enduranceCycleButton.Click += new System.EventHandler(this.enduranceCycleButton_Click); + // + // TestMethodCfgCtrl // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.enduranceCycleButton); this.Controls.Add(this.nameTextBox); this.Controls.Add(this.nameLabel); this.Controls.Add(this.classNameLabel); - this.Name = "BasicPrinterCfgCtrl"; + this.Name = "TestMethodCfgCtrl"; this.Size = new System.Drawing.Size(300, 200); this.Load += new System.EventHandler(this.EntryFormCfgCtrl_Load); this.ResumeLayout(false); @@ -82,5 +95,6 @@ namespace TBF.BenchControl.TestMethods.Endurance private System.Windows.Forms.TextBox nameTextBox; private System.Windows.Forms.Label nameLabel; private System.Windows.Forms.Label classNameLabel; + private System.Windows.Forms.Button enduranceCycleButton; } } diff --git a/TestBenchFramework/LocalSettings.cs b/TestBenchFramework/LocalSettings.cs index a4b9c2d84..6a5332817 100644 --- a/TestBenchFramework/LocalSettings.cs +++ b/TestBenchFramework/LocalSettings.cs @@ -154,6 +154,11 @@ namespace TBF [XmlIgnore] public int HistoryColumnCount { get { return (HistoryColumnWidths != null) ? HistoryColumnWidths.Length : 0; } } + /// Endurance test cycle steps + public int EnduranceDlgLeft; + public int EnduranceDlgTop; + public int EnduranceDlgWidth; + public int EnduranceDlgHeight; /// Serial numbers public string[] LastSNTexts; diff --git a/TestBenchFramework/Resources/Strings.Designer.cs b/TestBenchFramework/Resources/Strings.Designer.cs index d2a55058c..415fe4b3b 100644 --- a/TestBenchFramework/Resources/Strings.Designer.cs +++ b/TestBenchFramework/Resources/Strings.Designer.cs @@ -1176,6 +1176,24 @@ namespace TBF.Resources { } } + /// + /// Looks up a localized string similar to Endurance cycle. + /// + internal static string Endurance_cycle { + get { + return ResourceManager.GetString("Endurance_cycle", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Endurance cycle steps. + /// + internal static string Endurance_cycle_steps { + get { + return ResourceManager.GetString("Endurance_cycle_steps", resourceCulture); + } + } + /// /// Looks up a localized string similar to Energy. /// diff --git a/TestBenchFramework/Resources/Strings.resx b/TestBenchFramework/Resources/Strings.resx index 8f4a994f8..238d85ad1 100644 --- a/TestBenchFramework/Resources/Strings.resx +++ b/TestBenchFramework/Resources/Strings.resx @@ -1594,4 +1594,10 @@ Do you want to save changes? + + Endurance cycle steps + + + Endurance cycle + \ No newline at end of file diff --git a/TestBenchFramework/TBF.csproj b/TestBenchFramework/TBF.csproj index c6ba6c237..54b377e6f 100644 --- a/TestBenchFramework/TBF.csproj +++ b/TestBenchFramework/TBF.csproj @@ -567,6 +567,7 @@ WMErrorsForm24.cs + @@ -577,6 +578,15 @@ TestMethodCfgCtrl.cs + + Form + + + CycleDlg.cs + + + Component + @@ -1818,6 +1828,9 @@ TestMethodCfgCtrl.cs + + CycleDlg.cs + TestMethodCfgCtrl.cs