- Implemented functionality to handle multiple image captures with adjustable time gaps using the new `MultipleImageOpacity` class. - Enhanced `RoiCfgCtrl` and `RoiCfg` to integrate multi-image configuration. - Updated CJMS11 camera to support sequential image handling and delegate events for multiple images. - Introduced UI elements for specifying image count and time gap in the configuration panel. - Extended `GrabImagesOp` and event arguments to handle and store multiple grabbed images. - Refactored project to include `MultipleImageOpacity` utility in TBF solution.
270 lines
7.3 KiB
C#
270 lines
7.3 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.ComponentModel;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using Common;
|
|
using Config.Entities;
|
|
using TBF.Rig.Generic;
|
|
using TBF.Resources;
|
|
using TBF.Rig.Network.Camera.RoiForFixedStartCJMS11.common;
|
|
using TBF.UI.Bench.Components;
|
|
|
|
namespace TBF.Rig.Network.Camera.RoiForFixedStartCJMS11
|
|
{
|
|
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;
|
|
|
|
if (parent.CmpntEntities != null)
|
|
{
|
|
foreach (var cmpnt in parent.CmpntEntities)
|
|
{
|
|
if (TbfComponents.CmpntFactoryFromClassName(cmpnt.ClassName) is TBF.Rig.Network.Camera.CJMS11.Factory)
|
|
{
|
|
parentNameComboBox.Items.Add(cmpnt.Name);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
foreach (var resolutionFrame in ResolutionFrames.CommonResolutions)
|
|
{
|
|
resolutionComboBox.Items.Add(resolutionFrame.ToString());
|
|
}
|
|
|
|
|
|
for (ImageRotation ir = 0; ir < ImageRotation.Count; ir++)
|
|
{
|
|
imageRotationComboBox.Items.Add(ir.ToDescription());
|
|
}
|
|
|
|
for (int i = 0; i < MultipleImageOpacity.DefaultList.Count; i++)
|
|
{
|
|
comboBoxGabs.Items.Add(MultipleImageOpacity.DefaultList[i].ImageTimeGap);
|
|
}
|
|
|
|
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;
|
|
blackAndWhiteCheckBox.Checked = config.BlackAndWhite;
|
|
loResolutionCheckBox.Checked = config.LowResolution;
|
|
imageRotationComboBox.Text = config.ImageRotation.ToDescription();
|
|
resolutionComboBox.Text = config.ImageFrame.ToString();
|
|
comboBoxGabs.Text = config.ImageOpacity.ImageTimeGap.ToString();
|
|
textBoxMultipleImages.Text = config.ImageOpacity.Count.ToString();
|
|
}
|
|
|
|
public void Unlock()
|
|
{
|
|
nameTextBox.Enabled = true;
|
|
parentNameComboBox.Enabled = true;
|
|
blackAndWhiteCheckBox.Enabled = true;
|
|
loResolutionCheckBox.Enabled = true;
|
|
imageRotationComboBox.Enabled = true;
|
|
resolutionComboBox.Enabled = true;
|
|
comboBoxGabs.Enabled = true;
|
|
textBoxMultipleImages.Enabled = true;
|
|
}
|
|
|
|
public CfgUpdateFlags VerifyCfg(ref string message)
|
|
{
|
|
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
|
|
|
if (!parentNameComboBox.Items.Contains(parentNameComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + string.Format(Strings.Invalid_0, parentNameLabel.Text);
|
|
}
|
|
|
|
if (!imageRotationComboBox.Items.Contains(imageRotationComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + string.Format(Strings.Invalid_0, imageRotationLabel.Text);
|
|
}
|
|
|
|
if (!resolutionComboBox.Items.Contains(resolutionComboBox.Text))
|
|
{
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + string.Format(Strings.Invalid_0, resolutionComboBox.Text);
|
|
}
|
|
|
|
int gab = 0;
|
|
if(!int.TryParse(textBoxMultipleImages.Text, out gab)){
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + string.Format(Strings.Invalid_0, textBoxMultipleImages.Text);
|
|
}
|
|
|
|
if(!int.TryParse(comboBoxGabs.Text, out gab)){
|
|
flags |= CfgUpdateFlags.Error;
|
|
message += Environment.NewLine + string.Format(Strings.Invalid_0, comboBoxGabs.Text);
|
|
}
|
|
|
|
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 != 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);
|
|
}
|
|
|
|
if (config.BlackAndWhite != blackAndWhiteCheckBox.Checked)
|
|
{
|
|
config.BlackAndWhite = blackAndWhiteCheckBox.Checked;
|
|
flags |= (CfgUpdateFlags.AnyChange | CfgUpdateFlags.InvokeCfgChange);
|
|
}
|
|
|
|
if (config.LowResolution != loResolutionCheckBox.Checked)
|
|
{
|
|
config.LowResolution = loResolutionCheckBox.Checked;
|
|
flags |= (CfgUpdateFlags.AnyChange | CfgUpdateFlags.InvokeCfgChange);
|
|
}
|
|
|
|
for (ImageRotation ir = 0; ir < ImageRotation.Count; ir++)
|
|
{
|
|
if (imageRotationComboBox.Text == ir.ToDescription())
|
|
{
|
|
if (config.ImageRotation != ir)
|
|
{
|
|
config.ImageRotation = ir;
|
|
flags |= (CfgUpdateFlags.AnyChange | CfgUpdateFlags.InvokeCfgChange);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (resolutionComboBox.Text != config.ImageFrame.ToString())
|
|
{
|
|
config.ImageFrame = Frame.Parse(resolutionComboBox.Text);
|
|
flags |= (CfgUpdateFlags.AnyChange | CfgUpdateFlags.InvokeCfgChange);
|
|
}
|
|
|
|
try
|
|
{
|
|
if (int.Parse(textBoxMultipleImages.Text) != config.ImageOpacity.Count)
|
|
{
|
|
config.ImageOpacity.Count = int.Parse(textBoxMultipleImages.Text);
|
|
flags |= (CfgUpdateFlags.AnyChange | CfgUpdateFlags.InvokeCfgChange);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error("Error parsing multiple images", e);
|
|
}
|
|
|
|
try
|
|
{
|
|
if (int.Parse(comboBoxGabs.Text) != config.ImageOpacity.ImageTimeGap)
|
|
{
|
|
config.ImageOpacity.ImageTimeGap = int.Parse(comboBoxGabs.Text);
|
|
flags |= (CfgUpdateFlags.AnyChange | CfgUpdateFlags.InvokeCfgChange);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
log.Error("Error parsing multiple images", e);
|
|
}
|
|
|
|
if ((flags & CfgUpdateFlags.InvokeCfgChange) != 0)
|
|
{
|
|
Roi.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.CfgChange, config));
|
|
}
|
|
|
|
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
|
|
|
|
private void label3_Click(object sender, EventArgs e)
|
|
{
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
private void comboBoxGabs_Validating(object sender, CancelEventArgs e)
|
|
{
|
|
if (!int.TryParse(comboBoxGabs.Text, out _))
|
|
{
|
|
MessageBox.Show("Please enter a valid integer.");
|
|
e.Cancel = true;
|
|
}
|
|
}
|
|
|
|
private void comboBoxGabs_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
|
|
{
|
|
e.Handled = true;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|