First unfinished version with VirtualBenchSequences, requires DB upgrade
This commit is contained in:
parent
9868c41640
commit
26620f1fd1
BIN
Doc/Virtual-bench-components.ods
Normal file
BIN
Doc/Virtual-bench-components.ods
Normal file
Binary file not shown.
35
TestBenchFramework/Entities/VirtualBenchSequence.cs
Normal file
35
TestBenchFramework/Entities/VirtualBenchSequence.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TBF.Entities
|
||||
{
|
||||
public class VirtualBenchSequence : IHasItemNr
|
||||
{
|
||||
public virtual int Id { get; protected set; }
|
||||
public virtual int ItemNr { get; set; }
|
||||
public virtual string Name { get; set; }
|
||||
public virtual string Description { get; set; } /// Short description
|
||||
public virtual IList<VirtualBenchStep> VirtualBenchSteps { get; set; }
|
||||
|
||||
public VirtualBenchSequence()
|
||||
{
|
||||
VirtualBenchSteps = new List<VirtualBenchStep>();
|
||||
}
|
||||
|
||||
public VirtualBenchSequence(string name, int itemNr)
|
||||
: this()
|
||||
{
|
||||
Name = name;
|
||||
ItemNr = itemNr;
|
||||
}
|
||||
|
||||
public virtual VirtualBenchSequence Clone()
|
||||
{
|
||||
VirtualBenchSequence result = new VirtualBenchSequence();
|
||||
result.Name = Name;
|
||||
result.Description = Description;
|
||||
foreach (var step in VirtualBenchSteps) { result.VirtualBenchSteps.Add(step.Clone()); }
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
36
TestBenchFramework/Entities/VirtualBenchStep.cs
Normal file
36
TestBenchFramework/Entities/VirtualBenchStep.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TBF.Entities
|
||||
{
|
||||
public class VirtualBenchStep : IHasItemNr
|
||||
{
|
||||
public virtual int Id { get; protected set; }
|
||||
public virtual int ItemNr { get; set; } /// Order of the preparation step
|
||||
public virtual int Duration { get; set; } /// Duration in seconds
|
||||
///
|
||||
|
||||
public virtual VirtualBenchSequence VirtualBenchSequence { get; set; }
|
||||
|
||||
/// ------------- Additional stuff not mapped into the database -------------
|
||||
|
||||
public VirtualBenchStep()
|
||||
{
|
||||
Duration = 5; /// sec.
|
||||
}
|
||||
|
||||
public VirtualBenchStep(int itemNr, VirtualBenchSequence sequence)
|
||||
: this()
|
||||
{
|
||||
ItemNr = itemNr;
|
||||
VirtualBenchSequence = sequence;
|
||||
}
|
||||
|
||||
public virtual VirtualBenchStep Clone()
|
||||
{
|
||||
VirtualBenchStep result = new VirtualBenchStep(ItemNr, VirtualBenchSequence);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
96
TestBenchFramework/Forms/TabNameDlg.Designer.cs
generated
96
TestBenchFramework/Forms/TabNameDlg.Designer.cs
generated
@ -28,40 +28,66 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.tabNameTextBox = new System.Windows.Forms.TextBox();
|
||||
this.okButton = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// tabNameTextBox
|
||||
//
|
||||
this.tabNameTextBox.Location = new System.Drawing.Point(33, 25);
|
||||
this.tabNameTextBox.Name = "tabNameTextBox";
|
||||
this.tabNameTextBox.Size = new System.Drawing.Size(145, 20);
|
||||
this.tabNameTextBox.TabIndex = 1;
|
||||
//
|
||||
// okButton
|
||||
//
|
||||
this.okButton.Location = new System.Drawing.Point(209, 18);
|
||||
this.okButton.Name = "okButton";
|
||||
this.okButton.Size = new System.Drawing.Size(85, 33);
|
||||
this.okButton.TabIndex = 2;
|
||||
this.okButton.Text = "OK";
|
||||
this.okButton.UseVisualStyleBackColor = true;
|
||||
this.okButton.Click += new System.EventHandler(this.okButton_Click);
|
||||
//
|
||||
// TabNameDlg
|
||||
//
|
||||
this.AcceptButton = this.okButton;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(316, 69);
|
||||
this.Controls.Add(this.okButton);
|
||||
this.Controls.Add(this.tabNameTextBox);
|
||||
this.Name = "TabNameDlg";
|
||||
this.Text = "TabName";
|
||||
this.Load += new System.EventHandler(this.TabNameDlg_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
this.tabNameTextBox = new System.Windows.Forms.TextBox();
|
||||
this.okButton = new System.Windows.Forms.Button();
|
||||
this.radioButton1 = new System.Windows.Forms.RadioButton();
|
||||
this.radioButton2 = new System.Windows.Forms.RadioButton();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// tabNameTextBox
|
||||
//
|
||||
this.tabNameTextBox.Location = new System.Drawing.Point(33, 25);
|
||||
this.tabNameTextBox.Name = "tabNameTextBox";
|
||||
this.tabNameTextBox.Size = new System.Drawing.Size(145, 20);
|
||||
this.tabNameTextBox.TabIndex = 1;
|
||||
//
|
||||
// okButton
|
||||
//
|
||||
this.okButton.Location = new System.Drawing.Point(209, 18);
|
||||
this.okButton.Name = "okButton";
|
||||
this.okButton.Size = new System.Drawing.Size(85, 33);
|
||||
this.okButton.TabIndex = 2;
|
||||
this.okButton.Text = "OK";
|
||||
this.okButton.UseVisualStyleBackColor = true;
|
||||
this.okButton.Click += new System.EventHandler(this.okButton_Click);
|
||||
//
|
||||
// radioButton1
|
||||
//
|
||||
this.radioButton1.AutoSize = true;
|
||||
this.radioButton1.Checked = true;
|
||||
this.radioButton1.Location = new System.Drawing.Point(37, 64);
|
||||
this.radioButton1.Name = "radioButton1";
|
||||
this.radioButton1.Size = new System.Drawing.Size(121, 17);
|
||||
this.radioButton1.TabIndex = 3;
|
||||
this.radioButton1.TabStop = true;
|
||||
this.radioButton1.Text = "Transition sequence";
|
||||
this.radioButton1.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// radioButton2
|
||||
//
|
||||
this.radioButton2.AutoSize = true;
|
||||
this.radioButton2.Location = new System.Drawing.Point(37, 87);
|
||||
this.radioButton2.Name = "radioButton2";
|
||||
this.radioButton2.Size = new System.Drawing.Size(137, 17);
|
||||
this.radioButton2.TabIndex = 4;
|
||||
this.radioButton2.Text = "Virtual bench sequence";
|
||||
this.radioButton2.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// TabNameDlg
|
||||
//
|
||||
this.AcceptButton = this.okButton;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(316, 117);
|
||||
this.Controls.Add(this.radioButton2);
|
||||
this.Controls.Add(this.radioButton1);
|
||||
this.Controls.Add(this.okButton);
|
||||
this.Controls.Add(this.tabNameTextBox);
|
||||
this.Name = "TabNameDlg";
|
||||
this.Text = "TabName";
|
||||
this.Load += new System.EventHandler(this.TabNameDlg_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
@ -69,5 +95,7 @@
|
||||
|
||||
private System.Windows.Forms.TextBox tabNameTextBox;
|
||||
private System.Windows.Forms.Button okButton;
|
||||
private System.Windows.Forms.RadioButton radioButton1;
|
||||
private System.Windows.Forms.RadioButton radioButton2;
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,7 @@ namespace TBF.Forms
|
||||
{
|
||||
public string TabNameLabel;
|
||||
public string TabName;
|
||||
public bool IsVirtualBenchSeq;
|
||||
|
||||
public TabNameDlg()
|
||||
{
|
||||
@ -18,12 +19,14 @@ namespace TBF.Forms
|
||||
{
|
||||
Text = TabNameLabel;
|
||||
tabNameTextBox.Text = TabName;
|
||||
IsVirtualBenchSeq = false;
|
||||
okButton.Text = Strings.OkBtnText;
|
||||
}
|
||||
|
||||
private void okButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
TabName = tabNameTextBox.Text;
|
||||
IsVirtualBenchSeq = radioButton2.Checked;
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
|
||||
19
TestBenchFramework/Mappings/VirtualBenchSequenceMap.cs
Normal file
19
TestBenchFramework/Mappings/VirtualBenchSequenceMap.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using FluentNHibernate.Mapping;
|
||||
using TBF.Entities;
|
||||
|
||||
namespace TBF.Mappings
|
||||
{
|
||||
class VirtualBenchSequenceMap : ClassMap<VirtualBenchSequence>
|
||||
{
|
||||
public VirtualBenchSequenceMap()
|
||||
{
|
||||
Id(x => x.Id);
|
||||
Map(x => x.ItemNr);
|
||||
Map(x => x.Name);
|
||||
Map(x => x.Description);
|
||||
HasMany(x => x.VirtualBenchSteps)
|
||||
.OrderBy("ItemNr")
|
||||
.Cascade.All();
|
||||
}
|
||||
}
|
||||
}
|
||||
17
TestBenchFramework/Mappings/VirtualBenchStepMap.cs
Normal file
17
TestBenchFramework/Mappings/VirtualBenchStepMap.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using FluentNHibernate.Mapping;
|
||||
using TBF.Entities;
|
||||
|
||||
namespace TBF.Mappings
|
||||
{
|
||||
class VirtualBenchStepMap : ClassMap<VirtualBenchStep>
|
||||
{
|
||||
public VirtualBenchStepMap()
|
||||
{
|
||||
Id(x => x.Id);
|
||||
Map(x => x.ItemNr);
|
||||
Map(x => x.Duration);
|
||||
|
||||
References(x => x.VirtualBenchSequence);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -502,6 +502,8 @@
|
||||
<Compile Include="Entities\IHasValves.cs" />
|
||||
<Compile Include="Entities\TransitionSequence.cs" />
|
||||
<Compile Include="Entities\TransitionStep.cs" />
|
||||
<Compile Include="Entities\VirtualBenchSequence.cs" />
|
||||
<Compile Include="Entities\VirtualBenchStep.cs" />
|
||||
<Compile Include="Forms\ClosingProgram.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
@ -528,6 +530,8 @@
|
||||
</Compile>
|
||||
<Compile Include="Mappings\TransitionSequenceMap.cs" />
|
||||
<Compile Include="Mappings\TransitionStepMap.cs" />
|
||||
<Compile Include="Mappings\VirtualBenchSequenceMap.cs" />
|
||||
<Compile Include="Mappings\VirtualBenchStepMap.cs" />
|
||||
<Compile Include="Screens\PicturesTabPageCtrl.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
@ -931,6 +935,9 @@
|
||||
<Compile Include="UiControls\TransitionStepsCtrl.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="UiControls\VirtualBenchStepsCtrl.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Utils.cs" />
|
||||
<EmbeddedResource Include="BenchControl\BenchId\ComponentCfgCtrl.resx">
|
||||
<DependentUpon>ComponentCfgCtrl.cs</DependentUpon>
|
||||
|
||||
@ -27,15 +27,16 @@ namespace TBF
|
||||
public ISession Session;
|
||||
|
||||
/// <summary>
|
||||
/// Procedure to be updated by this dialog.
|
||||
/// Transition sequences to be updated by this dialog.
|
||||
/// Set by the constructor or updated by the parent after creation and before loading.
|
||||
/// </summary>
|
||||
public IList<Entities.TransitionSequence> LoadedSequences;
|
||||
public IList<Entities.TransitionSequence> TransitionSequences;
|
||||
|
||||
/// <summary>
|
||||
/// A list of tests to be deleted after closing this dialog
|
||||
/// </summary>
|
||||
public IList<Entities.TransitionStep> ToBeDeletedSteps;
|
||||
/// <summary>
|
||||
/// Virtual bench sequences to be updated by this dialog.
|
||||
/// Set by the constructor or updated by the parent after creation and before loading.
|
||||
/// </summary>
|
||||
public IList<Entities.VirtualBenchSequence> VirtualBenchSequences;
|
||||
|
||||
|
||||
/// Auxiliary public lists used also by user controls in tab pages
|
||||
@ -44,7 +45,8 @@ namespace TBF
|
||||
public IList<IRegulValve> RegulValves;
|
||||
|
||||
|
||||
IList<TransitionStepsCtrl> transStepsCtrls;
|
||||
IList<TransitionStepsCtrl> transitionStepsCtrls;
|
||||
IList<VirtualBenchStepsCtrl> virtualBenchStepsCtrls;
|
||||
|
||||
bool unlocked;
|
||||
|
||||
@ -72,8 +74,11 @@ namespace TBF
|
||||
sharedButtons.RenameTabClicked += renameTabButton_Click;
|
||||
sharedButtons.RemoveTabClicked += removeTabButton_Click;
|
||||
|
||||
transStepsCtrls = new List<TransitionStepsCtrl>();
|
||||
ToBeDeletedSteps = new List<Entities.TransitionStep>();
|
||||
transitionStepsCtrls = new List<TransitionStepsCtrl>();
|
||||
virtualBenchStepsCtrls = new List<VirtualBenchStepsCtrl>();
|
||||
|
||||
TransitionSequences = new List<TransitionSequence>();
|
||||
VirtualBenchSequences = new List<VirtualBenchSequence>();
|
||||
}
|
||||
|
||||
void Localize()
|
||||
@ -89,60 +94,88 @@ namespace TBF
|
||||
Left = (ls.TransitionsDlgLeft != 0) ? ls.TransitionsDlgLeft : 150;
|
||||
Top = (ls.TransitionsDlgTop != 0) ? ls.TransitionsDlgTop : 150;
|
||||
|
||||
/// Load the procedures
|
||||
/// Open the database
|
||||
Session = FluentCommon.CreateSession(Database.Procedures);
|
||||
LoadedSequences = Session.CreateQuery("FROM TransitionSequence ORDER BY ItemNr")
|
||||
.List<Entities.TransitionSequence>();
|
||||
|
||||
/// Prepare a list of components and a list of all valves in the test bench
|
||||
TbfComponents = BenchControl.TbfComponents.LoadComponentsFromDB(Session);
|
||||
Valves = BenchControl.GenericDevices.ValveBase.MasterValves(TbfComponents);
|
||||
RegulValves = new List<IRegulValve>();
|
||||
foreach (var cmpnt in TbfComponents)
|
||||
{
|
||||
if (cmpnt is IRegulValve) RegulValves.Add(cmpnt as IRegulValve);
|
||||
}
|
||||
/// Prepare a list of components and a list of all valves in the test bench
|
||||
TbfComponents = BenchControl.TbfComponents.LoadComponentsFromDB(Session);
|
||||
Valves = BenchControl.GenericDevices.ValveBase.MasterValves(TbfComponents);
|
||||
RegulValves = new List<IRegulValve>();
|
||||
foreach (var cmpnt in TbfComponents)
|
||||
{
|
||||
if (cmpnt is IRegulValve) RegulValves.Add(cmpnt as IRegulValve);
|
||||
}
|
||||
|
||||
/// Create a tab with a TestParamsCtrl control for each used test method
|
||||
foreach (var sequence in LoadedSequences) AddTab(sequence);
|
||||
/// Load the sequences
|
||||
TransitionSequences = Session.CreateQuery("FROM TransitionSequence ORDER BY ItemNr")
|
||||
.List<Entities.TransitionSequence>();
|
||||
|
||||
VirtualBenchSequences = Session.CreateQuery("FROM VirtualBenchSequence ORDER BY ItemNr")
|
||||
.List<Entities.VirtualBenchSequence>();
|
||||
|
||||
/// Create a tab with sequence steps for each sequence
|
||||
foreach (var sequence in TransitionSequences) AddTransitionSeqTab(sequence);
|
||||
foreach (var sequence in VirtualBenchSequences) AddVirtualBenchSeqTab(sequence);
|
||||
|
||||
/// Now refresh the content of the dialog
|
||||
RefreshAllTabs();
|
||||
}
|
||||
|
||||
void AddTab(TransitionSequence sequence)
|
||||
void AddTransitionSeqTab(TransitionSequence sequence)
|
||||
{
|
||||
TabPage nwTab = new TabPage(sequence.Name);
|
||||
TransitionStepsCtrl newCtrl = new TransitionStepsCtrl();
|
||||
transStepsCtrls.Add(newCtrl);
|
||||
transitionStepsCtrls.Add(newCtrl);
|
||||
nwTab.Controls.Add(newCtrl);
|
||||
this.tabControl.TabPages.Add(nwTab);
|
||||
newCtrl.Initialize(sequence, this, this.tabControl.TabPages[this.tabControl.TabPages.Count - 1]);
|
||||
}
|
||||
|
||||
void AddVirtualBenchSeqTab(VirtualBenchSequence sequence)
|
||||
{
|
||||
TabPage nwTab = new TabPage(sequence.Name);
|
||||
VirtualBenchStepsCtrl newCtrl = new VirtualBenchStepsCtrl();
|
||||
virtualBenchStepsCtrls.Add(newCtrl);
|
||||
nwTab.Controls.Add(newCtrl);
|
||||
this.tabControl.TabPages.Add(nwTab);
|
||||
newCtrl.Initialize(sequence, this, this.tabControl.TabPages[this.tabControl.TabPages.Count - 1]);
|
||||
}
|
||||
|
||||
void RefreshAllTabs()
|
||||
{
|
||||
foreach (var ctrl in transStepsCtrls) ctrl.Refresh();
|
||||
foreach (var ctrl in transitionStepsCtrls) ctrl.Refresh();
|
||||
foreach (var ctrl in virtualBenchStepsCtrls) ctrl.Refresh();
|
||||
}
|
||||
|
||||
private void Unlocked(object sender, EventArgs e)
|
||||
{
|
||||
unlocked = true;
|
||||
foreach (var ctrl in transStepsCtrls) ctrl.Unlock();
|
||||
}
|
||||
foreach (var ctrl in transitionStepsCtrls) ctrl.Unlock();
|
||||
foreach (var ctrl in virtualBenchStepsCtrls) ctrl.Unlock();
|
||||
}
|
||||
|
||||
private void newTabButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
int tabId = LoadedSequences.Count;
|
||||
int tabId = TransitionSequences.Count + VirtualBenchSequences.Count;
|
||||
Forms.TabNameDlg dlg = new Forms.TabNameDlg();
|
||||
dlg.TabNameLabel = Strings.New_transition_name;
|
||||
dlg.TabName = "Tr1";
|
||||
dlg.ShowDialog();
|
||||
TransitionSequence sequence = new TransitionSequence(dlg.TabName, tabId);
|
||||
LoadedSequences.Add(sequence);
|
||||
AddTab(sequence);
|
||||
transStepsCtrls[tabId].Unlock();
|
||||
tabControl.SelectTab(tabId);
|
||||
if (dlg.IsVirtualBenchSeq)
|
||||
{
|
||||
VirtualBenchSequence sequence = new VirtualBenchSequence(dlg.TabName, tabId);
|
||||
VirtualBenchSequences.Add(sequence);
|
||||
AddVirtualBenchSeqTab(sequence);
|
||||
virtualBenchStepsCtrls[tabId].Unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
TransitionSequence sequence = new TransitionSequence(dlg.TabName, tabId);
|
||||
TransitionSequences.Add(sequence);
|
||||
AddTransitionSeqTab(sequence);
|
||||
transitionStepsCtrls[tabId].Unlock();
|
||||
}
|
||||
tabControl.SelectTab(tabId);
|
||||
}
|
||||
|
||||
private void renameTabButton_Click(object sender, EventArgs e)
|
||||
@ -155,16 +188,15 @@ namespace TBF
|
||||
|
||||
private void okButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (transStepsCtrls.Count > slctdTab) transStepsCtrls[slctdTab].OkBtnClicked();
|
||||
if (transitionStepsCtrls.Count > slctdTab) transitionStepsCtrls[slctdTab].OkBtnClicked();
|
||||
|
||||
using (var transaction = Session.BeginTransaction())
|
||||
{
|
||||
foreach (var sequence in LoadedSequences)
|
||||
{
|
||||
Session.SaveOrUpdate(sequence);
|
||||
}
|
||||
try { transaction.Commit(); }
|
||||
catch { }
|
||||
foreach (var transSeq in TransitionSequences) Session.SaveOrUpdate(transSeq);
|
||||
foreach (var vBnchSeq in VirtualBenchSequences) Session.SaveOrUpdate(vBnchSeq);
|
||||
|
||||
try { transaction.Commit(); }
|
||||
catch { log.Error("Update of sequences in the database failed"); }
|
||||
}
|
||||
|
||||
Program.LocalSettings.TransitionsDlgLeft = Location.X;
|
||||
@ -195,9 +227,9 @@ namespace TBF
|
||||
|
||||
private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (transStepsCtrls.Count > slctdTab)
|
||||
if (transitionStepsCtrls.Count > slctdTab)
|
||||
{
|
||||
transStepsCtrls[slctdTab].OkBtnClicked();
|
||||
transitionStepsCtrls[slctdTab].OkBtnClicked();
|
||||
}
|
||||
slctdTab = tabControl.SelectedIndex;
|
||||
sharedButtons.SetEnabled(SharedButtons.Buttons.Add, true);
|
||||
@ -207,22 +239,22 @@ namespace TBF
|
||||
|
||||
private void addButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (transStepsCtrls.Count > slctdTab) transStepsCtrls[slctdTab].AddOne();
|
||||
if (transitionStepsCtrls.Count > slctdTab) transitionStepsCtrls[slctdTab].AddOne();
|
||||
}
|
||||
|
||||
private void removeButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (transStepsCtrls.Count > slctdTab) transStepsCtrls[slctdTab].RemoveSelected();
|
||||
if (transitionStepsCtrls.Count > slctdTab) transitionStepsCtrls[slctdTab].RemoveSelected();
|
||||
}
|
||||
|
||||
private void upButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (transStepsCtrls.Count > slctdTab) transStepsCtrls[slctdTab].MoveUpSelected();
|
||||
if (transitionStepsCtrls.Count > slctdTab) transitionStepsCtrls[slctdTab].MoveUpSelected();
|
||||
}
|
||||
|
||||
private void downButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (transStepsCtrls.Count > slctdTab) transStepsCtrls[slctdTab].MoveDownSelected();
|
||||
if (transitionStepsCtrls.Count > slctdTab) transitionStepsCtrls[slctdTab].MoveDownSelected();
|
||||
}
|
||||
|
||||
public void UpdateButtonStates(SharedButtons.SelectedItemPos selectedItemPos)
|
||||
|
||||
224
TestBenchFramework/UiControls/VirtualBenchStepsCtrl.cs
Normal file
224
TestBenchFramework/UiControls/VirtualBenchStepsCtrl.cs
Normal file
@ -0,0 +1,224 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using log4net;
|
||||
using TBF.BenchControl;
|
||||
using TBF.BenchControl.GenericDevices;
|
||||
using TBF.Resources;
|
||||
|
||||
namespace TBF.UiControls
|
||||
{
|
||||
public partial class VirtualBenchStepsCtrl : BaseWithListViewEx<Entities.VirtualBenchStep>, ITabWithListViewEx
|
||||
{
|
||||
static readonly ILog log = LogManager.GetLogger(typeof(VirtualBenchStepsCtrl));
|
||||
|
||||
/// <summary>
|
||||
/// Fixed ListViewEx columns
|
||||
/// </summary>
|
||||
enum Column
|
||||
{
|
||||
Duration,
|
||||
FixedColumnsCount,
|
||||
}
|
||||
readonly int fixedCount = (int)Column.FixedColumnsCount;
|
||||
|
||||
Entities.VirtualBenchSequence sequence;
|
||||
|
||||
TransitionsDlg parent;
|
||||
Control parentControl;
|
||||
Control[] editors;
|
||||
|
||||
int fmPumpCount; /// Number of pumps with FM control
|
||||
int regvCount; /// Number of regulating valves
|
||||
int vCount; /// Number of valves
|
||||
|
||||
public VirtualBenchStepsCtrl()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public void Initialize(Entities.VirtualBenchSequence sequence, TransitionsDlg parent, Control parentControl)
|
||||
{
|
||||
this.sequence = sequence;
|
||||
this.parent = parent;
|
||||
this.parentControl = parentControl;
|
||||
Name = sequence.Name;
|
||||
MyItems = sequence.VirtualBenchSteps;
|
||||
|
||||
SubItemClicked += new SubItemEventHandler(listViewEx_SubItemClicked);
|
||||
SubItemEndEditing += new SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing);
|
||||
|
||||
vCount = 0;
|
||||
fmPumpCount = 0;
|
||||
regvCount = 0;
|
||||
|
||||
///
|
||||
/// ListViewEx columns
|
||||
///
|
||||
Columns.Add(Strings.Duration_s, 70 * parent.Dpi / PathsDlg.Dpi100pct);
|
||||
//foreach (var vlv in parent.Valves)
|
||||
//{
|
||||
// if (vlv is BenchControl.GenericDevices.IPumpFM)
|
||||
// {
|
||||
// Columns.Add(vlv.Cfg.Name + " [%]", 45 * parent.Dpi / PathsDlg.Dpi100pct);
|
||||
// fmPumpCount++;
|
||||
// }
|
||||
//}
|
||||
//foreach (var rvlv in parent.RegulValves)
|
||||
//{
|
||||
// Columns.Add(rvlv.Cfg.Name + " [%]", 55 * parent.Dpi / PathsDlg.Dpi100pct);
|
||||
//}
|
||||
//foreach (var vlv in parent.Valves)
|
||||
//{
|
||||
// if (!(vlv is BenchControl.GenericDevices.IPumpFM))
|
||||
// {
|
||||
// Columns.Add(vlv.Cfg.Name, 40 * parent.Dpi / PathsDlg.Dpi100pct);
|
||||
// vCount++;
|
||||
// }
|
||||
//}
|
||||
|
||||
///
|
||||
/// Prepare valve combo-boxes
|
||||
///
|
||||
editors = new Control[fixedCount + vCount + fmPumpCount + regvCount];
|
||||
|
||||
editors[0] = new TextBox(); /// Duration
|
||||
parent.Controls.Add(editors[0]);
|
||||
|
||||
//for (int i = fixedCount; i < fixedCount + fmPumpCount; i++)
|
||||
//{
|
||||
// ComboBox cb = new ComboBox();
|
||||
// cb.Items.Add("---");
|
||||
// cb.Items.Add(Strings.dflt);
|
||||
// cb.Items.Add("0");
|
||||
// cb.Items.Add("25");
|
||||
// cb.Items.Add("50");
|
||||
// cb.Items.Add("75");
|
||||
// cb.Items.Add("100");
|
||||
// editors[i] = cb;
|
||||
// parent.Controls.Add(editors[i]);
|
||||
//}
|
||||
|
||||
//for (int i = fixedCount + fmPumpCount; i < fixedCount + fmPumpCount + regvCount; i++)
|
||||
//{
|
||||
// ComboBox cb = new ComboBox();
|
||||
// cb.Items.Add("---");
|
||||
// cb.Items.Add("0");
|
||||
// cb.Items.Add("25");
|
||||
// cb.Items.Add("50");
|
||||
// cb.Items.Add("75");
|
||||
// cb.Items.Add("100");
|
||||
// editors[i] = cb;
|
||||
// parent.Controls.Add(editors[i]);
|
||||
//}
|
||||
|
||||
//for (int i = fixedCount + fmPumpCount + regvCount; i < fixedCount + fmPumpCount + regvCount + vCount; i++)
|
||||
//{
|
||||
// ComboBox cb = new ComboBox();
|
||||
// cb.Items.Add("---");
|
||||
// cb.Items.Add(Strings.open);
|
||||
// cb.Items.Add(Strings.close);
|
||||
// editors[i] = cb;
|
||||
// parent.Controls.Add(cb);
|
||||
//}
|
||||
|
||||
base.RedrawAll();
|
||||
}
|
||||
|
||||
void listViewEx_SubItemClicked(object sender, SubItemEventArgs e)
|
||||
{
|
||||
if (!Unlocked || e.SubItem >= editors.Length) return;
|
||||
StartEditing(editors[e.SubItem], e.Item, e.SubItem);
|
||||
}
|
||||
|
||||
void listViewEx_SubItemEndEditing(object sender, 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 >= fixedCount) && (e.SubItem < fixedCount + fmPumpCount))
|
||||
//{
|
||||
// float pct;
|
||||
// if (!e.DisplayText.Equals("---") &&
|
||||
// !e.DisplayText.Equals(Strings.dflt) &&
|
||||
// !(Utils.TryParseUFloat(e.DisplayText, out pct) && (pct >= 0) && (pct <= 100.0f)))
|
||||
// {
|
||||
// e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
// e.Cancel = true;
|
||||
// }
|
||||
//}
|
||||
//else if ((e.SubItem >= fixedCount + fmPumpCount) && (e.SubItem < fixedCount + fmPumpCount + regvCount))
|
||||
//{
|
||||
// float pct;
|
||||
// if (!e.DisplayText.Equals("---") &&
|
||||
// !(Utils.TryParseUFloat(e.DisplayText, out pct) && (pct >= 0) && (pct <= 100.0f)))
|
||||
// {
|
||||
// e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
// e.Cancel = true;
|
||||
// }
|
||||
//}
|
||||
//else if ((e.SubItem >= fixedCount + fmPumpCount + regvCount) && (e.SubItem < fixedCount + fmPumpCount + regvCount + vCount))
|
||||
//{
|
||||
// if ((e.DisplayText != Strings.open) && (e.DisplayText != Strings.close) && (e.DisplayText != "---"))
|
||||
// {
|
||||
// e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
// e.Cancel = true;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
public override void DrawOne(object myItem)
|
||||
{
|
||||
Entities.VirtualBenchStep step = (Entities.VirtualBenchStep)myItem;
|
||||
|
||||
ListViewItem lvi = new ListViewItem(step.Duration.ToString());
|
||||
|
||||
/// TODO: All the rest
|
||||
|
||||
lvi.Tag = step;
|
||||
|
||||
Items.Add(lvi);
|
||||
}
|
||||
|
||||
public override void UpdateOne(ListViewItem lvi, object myItem)
|
||||
{
|
||||
Entities.VirtualBenchStep step = (Entities.VirtualBenchStep)myItem;
|
||||
|
||||
/// Duration
|
||||
try
|
||||
{
|
||||
step.Duration = int.Parse(lvi.Text);
|
||||
if (step.Duration < 2) throw (new System.Exception());
|
||||
}
|
||||
catch
|
||||
{
|
||||
lvi.Text = step.Duration.ToString();
|
||||
}
|
||||
|
||||
// TODO: Replace the following:
|
||||
//step.PumpWithFMPcts = fmPumpsPcts;
|
||||
//step.RegulValvesPct = regulValvesPct;
|
||||
//step.ValvesOpen = valvesOpen;
|
||||
//step.ValvesClose = valvesClose;
|
||||
}
|
||||
|
||||
public void AddOne()
|
||||
{
|
||||
base.AddOne(new Entities.VirtualBenchStep(MyItems.Count, sequence));
|
||||
}
|
||||
|
||||
public new void RemoveSelected()
|
||||
{
|
||||
bool lastItemRemoved = base.RemoveSelected();
|
||||
if (lastItemRemoved && parent != null)
|
||||
{
|
||||
parent.UpdateButtonStates(SharedButtons.SelectedItemPos.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user