157 lines
5.6 KiB
C#
157 lines
5.6 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using TBF.BenchControl.Generic;
|
|
|
|
namespace TBF.BenchControl.Elde.Valve
|
|
{
|
|
public partial class ValveCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(ValveCfgCtrl));
|
|
|
|
ComponentParametersDlg parent;
|
|
ValveCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as ValveCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public ValveCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void ValveCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
parent = ParentForm as ComponentParametersDlg;
|
|
if (parent == null) return;
|
|
|
|
categoryComboBox.Items.Add(ValveCategory.All.ToString());
|
|
categoryComboBox.Items.Add(ValveCategory.Feeding.ToString());
|
|
categoryComboBox.Items.Add(ValveCategory.Bench.ToString());
|
|
categoryComboBox.Items.Add(ValveCategory.Output.ToString());
|
|
categoryComboBox.Items.Add(ValveCategory.None.ToString());
|
|
|
|
if (parent.TbfComponents != null)
|
|
{
|
|
parentNameComboBox.Items.Add("---");
|
|
coupledToComboBox.Items.Add("---");
|
|
foreach (var cmpnt in parent.TbfComponents)
|
|
{
|
|
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Elde.ControlBoardFactory)
|
|
{
|
|
parentNameComboBox.Items.Add(cmpnt.Name);
|
|
}
|
|
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is Elde.Valve.ValveFactory)
|
|
{
|
|
coupledToComboBox.Items.Add(cmpnt.Name);
|
|
}
|
|
}
|
|
}
|
|
|
|
Redraw();
|
|
}
|
|
|
|
void Redraw()
|
|
{
|
|
if (config == null) return; /// Control was not loaded, settings were not changed
|
|
|
|
classNameLabel.Text = config.Factory.ClassName;
|
|
nameTextBox.Text = config.Name;
|
|
parentNameComboBox.Text = string.IsNullOrEmpty(config.ParentName) ? "---" : config.ParentName;
|
|
bitPositionTextBox.Text = config.BitPosition.ToString();
|
|
invertedCheckBox.Checked = config.Inverted;
|
|
openCloseTimeTextBox.Text = config.OpenCloseTime.ToString();
|
|
categoryComboBox.Text = config.Category.ToString();
|
|
coupledToComboBox.Text = string.IsNullOrEmpty(config.CoupledToName) ? "---" : config.CoupledToName;
|
|
invertCoupleCheckBox.Checked = config.InvertCouple;
|
|
lagOpeningTextBox.Text = config.LagOpening.ToString();
|
|
lagClosingTextBox.Text = config.LagClosing.ToString();
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
parentNameComboBox.Enabled = true;
|
|
bitPositionTextBox.Enabled = true;
|
|
invertedCheckBox.Enabled = true;
|
|
openCloseTimeTextBox.Enabled = true;
|
|
categoryComboBox.Enabled = true;
|
|
coupledToComboBox.Enabled = true;
|
|
invertCoupleCheckBox.Enabled = true;
|
|
lagOpeningTextBox.Enabled = true;
|
|
lagClosingTextBox.Enabled = true;
|
|
}
|
|
|
|
public void UpdateCfg()
|
|
{
|
|
if (config == null) return; /// Control was not loaded, settings were not changed
|
|
|
|
config.Name = nameTextBox.Text;
|
|
config.ParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
|
|
config.BitPosition = int.Parse(bitPositionTextBox.Text);
|
|
config.OpenCloseTime = int.Parse(openCloseTimeTextBox.Text);
|
|
config.Inverted = invertedCheckBox.Checked;
|
|
|
|
if (categoryComboBox.Text.Equals(ValveCategory.All.ToString())) config.Category = ValveCategory.All;
|
|
else if (categoryComboBox.Text.Equals(ValveCategory.Feeding.ToString())) config.Category = ValveCategory.Feeding;
|
|
else if (categoryComboBox.Text.Equals(ValveCategory.Bench.ToString())) config.Category = ValveCategory.Bench;
|
|
else if (categoryComboBox.Text.Equals(ValveCategory.Output.ToString())) config.Category = ValveCategory.Output;
|
|
else config.Category = ValveCategory.None;
|
|
|
|
config.CoupledToName = coupledToComboBox.Text.Equals("---") ? string.Empty : coupledToComboBox.Text;
|
|
config.InvertCouple = invertCoupleCheckBox.Checked;
|
|
config.LagOpening = int.Parse(lagOpeningTextBox.Text);
|
|
config.LagClosing = int.Parse(lagClosingTextBox.Text);
|
|
}
|
|
|
|
public CfgVerifyFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgVerifyFlags flags = CfgVerifyFlags.None;
|
|
|
|
int dummy;
|
|
if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text))
|
|
{
|
|
flags |= CfgVerifyFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Parent Name'";
|
|
}
|
|
if (!categoryComboBox.Items.Contains(categoryComboBox.Text))
|
|
{
|
|
flags |= CfgVerifyFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Category'";
|
|
}
|
|
if (!coupledToComboBox.Items.Contains(coupledToComboBox.Text))
|
|
{
|
|
flags |= CfgVerifyFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Coupled To'";
|
|
}
|
|
if (!int.TryParse(bitPositionTextBox.Text, out dummy) || dummy < 0 || dummy >= 64)
|
|
{
|
|
flags |= CfgVerifyFlags.Error;
|
|
message += Environment.NewLine + "'Bit Position' should be between 0 and 63";
|
|
}
|
|
if (!int.TryParse(openCloseTimeTextBox.Text, out dummy) || dummy < 0 || dummy > 300)
|
|
{
|
|
flags |= CfgVerifyFlags.Error;
|
|
message += Environment.NewLine + "'Open/close time' should be between 0 and 300 s";
|
|
}
|
|
if (!int.TryParse(lagOpeningTextBox.Text, out dummy))
|
|
{
|
|
flags |= CfgVerifyFlags.Error;
|
|
message += Environment.NewLine + "'Delay when opening' error";
|
|
}
|
|
if (!int.TryParse(lagClosingTextBox.Text, out dummy))
|
|
{
|
|
flags |= CfgVerifyFlags.Error;
|
|
message += Environment.NewLine + "'Delay when closing' error";
|
|
}
|
|
return flags;
|
|
}
|
|
}
|
|
}
|