154 lines
4.3 KiB
C#
154 lines
4.3 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using TBF.BenchControl.Generic;
|
|
|
|
namespace TBF.BenchControl.Network.Camera.Roi
|
|
{
|
|
public partial class RoiCfgCtrl : UserControl, IComponentCfgCtrl
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(RoiCfgCtrl));
|
|
|
|
ComponentParametersDlg parent;
|
|
|
|
public bool ShowMore { get { return false; } }
|
|
|
|
RoiCfg config;
|
|
public IComponentCfg Config
|
|
{
|
|
get { return config as IComponentCfg; }
|
|
set
|
|
{
|
|
config = value as RoiCfg;
|
|
Redraw();
|
|
}
|
|
}
|
|
|
|
public RoiCfgCtrl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void PumpCfgCtrl_Load(object sender, EventArgs e)
|
|
{
|
|
parent = ParentForm as ComponentParametersDlg;
|
|
if (parent == null) return;
|
|
|
|
previousRoiComboBox.Items.Add("---");
|
|
if (parent.TbfComponents != null)
|
|
{
|
|
foreach (var cmpnt in parent.TbfComponents)
|
|
{
|
|
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is TBF.BenchControl.Network.Camera.CLP1611.Factory)
|
|
{
|
|
parentNameComboBox.Items.Add(cmpnt.Name);
|
|
}
|
|
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is TBF.BenchControl.Network.Camera.Roi.Factory)
|
|
{
|
|
previousRoiComboBox.Items.Add(cmpnt.Name);
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
previousRoiComboBox.Text = string.IsNullOrEmpty(config.PreviousRoi) ? "---" : config.PreviousRoi;
|
|
argsTextBox.Text = config.RoiParams;
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
parentNameComboBox.Enabled = true;
|
|
previousRoiComboBox.Enabled = true;
|
|
argsTextBox.Enabled = true;
|
|
}
|
|
|
|
public CfgUpdateFlags UpdateCfg()
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
|
|
|
if (config.Name != nameTextBox.Text)
|
|
{
|
|
config.Name = nameTextBox.Text;
|
|
flags |= (CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
|
|
}
|
|
|
|
string newParentName = parentNameComboBox.Text.Equals("---") ? string.Empty : parentNameComboBox.Text;
|
|
if (config.ParentName != newParentName)
|
|
{
|
|
config.ParentName = newParentName;
|
|
flags |= (CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
|
|
}
|
|
|
|
string newPreviousRoi = previousRoiComboBox.Text.Equals("---") ? string.Empty : previousRoiComboBox.Text;
|
|
if (config.PreviousRoi != newPreviousRoi)
|
|
{
|
|
config.PreviousRoi = newPreviousRoi;
|
|
flags |= (CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
|
|
}
|
|
|
|
if (config.RoiParams != argsTextBox.Text)
|
|
{
|
|
config.RoiParams = argsTextBox.Text;
|
|
flags |= CfgUpdateFlags.AnyChange;
|
|
Roi.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.CfgChange, config));
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Parent Name'";
|
|
}
|
|
|
|
if (!previousRoiComboBox.Items.Contains(previousRoiComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + "Invalid 'Previous RoI'";
|
|
}
|
|
|
|
return flags;
|
|
}
|
|
|
|
#region Configuration Change Handling
|
|
|
|
public static void OnCmdResponse(object sender, CmdResponseArgs args)
|
|
{
|
|
if (CmdResponseHandler == null) return;
|
|
try { CmdResponseHandler(sender, args); }
|
|
catch (Exception e) { log.Error("CmdResponseHandler(...) failed", e); }
|
|
}
|
|
|
|
public static event EventHandler<CmdResponseArgs> CmdResponseHandler;
|
|
|
|
public void StartResponseHandler() { }
|
|
public void StopResponseHandler() { }
|
|
|
|
#endregion Configuration Change Handling
|
|
}
|
|
}
|