/// /// Copyright (c) 2023 Sensus Slovensko a.s. /// using System; using System.Windows.Forms; using Common; using Config.Entities; using TBF.Rig.Generic; using TBF.UI.Bench.Components; namespace TBF.Rig.Uni.RegValveAnalog { public partial class RegValveCfgCtrl : UserControl, IComponentCfgCtrl { ComponentParametersDlg parent; public bool ShowMore { get { return true; } } RegValveCfg config; public IComponentCfg Config { get { return config as IComponentCfg; } set { config = value as RegValveCfg; Redraw(); } } public RegValveCfgCtrl() { InitializeComponent(); } private void RegulationValveCfgCtrl_Load(object sender, EventArgs e) { parent = ParentForm as ComponentParametersDlg; if (parent == null) return; if (parent.CmpntEntities != null) { foreach (var cmpnt in parent.CmpntEntities) { if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is ControlBoard.Uni.Factory) { parentNameComboBox.Items.Add(cmpnt.Name); } } } categoryComboBox.Items.Add(ValveCategory.Feeding.ToString()); categoryComboBox.Items.Add(ValveCategory.Output.ToString()); for (Common.Unit units = 0; units < global::Common.Unit.Count; units++) { if (global::Common.Units.IsQuantity(units, Quantity.Error)) { unitsComboBox.Items.Add(units.ToString()); } } Redraw(); } public void Closing() { } 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; categoryComboBox.Text = config.Category.ToString(); stableTimeTextBox.Text = config.StableTimeMs.ToString(); flowStableSecTextBox.Text = config.FlowStableSec.ToString(); storedPosReuseCheckBox.Checked = config.StoredPositionReuse; formatTextBox.Text = config.SetpFormat; unitsComboBox.Text = config.SetpUnit.ToString(); } public void Unlock() { nameTextBox.Enabled = true; parentNameComboBox.Enabled = true; categoryComboBox.Enabled = true; stableTimeTextBox.Enabled = true; flowStableSecTextBox.Enabled = true; storedPosReuseCheckBox.Enabled = true; formatTextBox.Enabled = true; unitsComboBox.Enabled = true; } public CfgUpdateFlags VerifyCfg(ref string message) { CfgUpdateFlags flags = CfgUpdateFlags.None; int dummy; if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text)) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "Invalid 'Parent Name'"; } if (!categoryComboBox.Text.Equals(ValveCategory.Feeding.ToString()) && !categoryComboBox.Text.Equals(ValveCategory.Output.ToString())) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "Invalid 'Category'"; } if (!int.TryParse(stableTimeTextBox.Text, out dummy) || dummy < 200 || dummy > 1500 || (dummy % 50) != 0) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'Stable time' should be between 200 and 1500 ms in 50 ms steps"; } if (!int.TryParse(flowStableSecTextBox.Text, out dummy) || dummy < 0 || dummy > 60) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "'Flow stable' should be between 0 and 60 sec"; } if (!unitsComboBox.Items.Contains(unitsComboBox.Text)) { flags |= CfgUpdateFlags.Error; message += Environment.NewLine + "Invalid 'Units'"; } return flags; } public CfgUpdateFlags UpdateCfg() { CfgUpdateFlags flags = CfgUpdateFlags.None; if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed /// if (!config.Name.Equals(nameTextBox.Text)) { config.Name = nameTextBox.Text; flags |= CfgUpdateFlags.RestartRqrd; } string parentname = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text; if (!config.ParentName.Equals(parentname)) { config.ParentName = parentname; flags |= CfgUpdateFlags.RestartRqrd; } ValveCategory newCategory; if (categoryComboBox.Text.Equals(ValveCategory.Feeding.ToString())) newCategory = ValveCategory.Feeding; else if (categoryComboBox.Text.Equals(ValveCategory.Output.ToString())) newCategory = ValveCategory.Output; else newCategory = ValveCategory.None; if (newCategory != config.Category) { config.Category = newCategory; flags |= CfgUpdateFlags.RestartRqrd; } int tmp = int.Parse(stableTimeTextBox.Text); if (config.StableTimeMs != tmp) { config.StableTimeMs = tmp; flags |= CfgUpdateFlags.RestartRqrd; } tmp = int.Parse(flowStableSecTextBox.Text); if (config.FlowStableSec != tmp) { config.FlowStableSec = tmp; flags |= CfgUpdateFlags.RestartRqrd; } bool btmp = storedPosReuseCheckBox.Checked; if (config.StoredPositionReuse != btmp) { config.StoredPositionReuse = btmp; flags |= CfgUpdateFlags.RestartRqrd; } config.SetpUnit = global::Common.Unit.None; for (Common.Unit units = 0; units < global::Common.Unit.Count; units++) { if (unitsComboBox.Text == units.ToString()) { config.SetpUnit = units; break; } } return flags; } private void openButton_Click(object sender, EventArgs e) { /// TODO } private void closeButton_Click(object sender, EventArgs e) { /// TODO } } }