TestMethods.GrabImage : ImageFileName etc. added to cfg, GrabImageCfg implemented, interfaces changes, ver. 2.15.627

This commit is contained in:
Milan Hanajik
2017-07-25 15:43:36 +03:00
parent 548973cf11
commit 4867b031b9
22 changed files with 416 additions and 254 deletions
@@ -1,82 +0,0 @@
///
/// Copyright (c) 2017 Sensus Metering Systems
///
using System;
using System.Windows.Forms;
using log4net;
using TBF.BenchControl.Generic;
namespace TBF.BenchControl.TestMethods.GrabImage
{
public partial class CfgCtrl : UserControl, IComponentCfgCtrl
{
static readonly ILog log = LogManager.GetLogger(typeof(CfgCtrl));
public bool ShowMore { get { return false; } }
Cfg config;
public IComponentCfg Config
{
get { return config as IComponentCfg; }
set
{
config = value as Cfg;
Redraw();
}
}
public CfgCtrl()
{
InitializeComponent();
}
private void EntryFormCfgCtrl_Load(object sender, EventArgs e)
{
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;
hiResolutionCheckBox.Checked = config.LowResolution;
}
public void Unlock()
{
nameTextBox.Enabled = true;
hiResolutionCheckBox.Enabled = true;
}
public CfgUpdateFlags VerifyCfg(ref string message)
{
return CfgUpdateFlags.None;
}
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.AnyChange | CfgUpdateFlags.RestartRqrd);
}
if (config.LowResolution != hiResolutionCheckBox.Checked)
{
config.LowResolution = hiResolutionCheckBox.Checked;
flags |= (CfgUpdateFlags.AnyChange | CfgUpdateFlags.RestartRqrd);
}
return flags;
}
}
}
@@ -1,97 +0,0 @@
///
/// Copyright (c) 2017 Sensus Metering Systems
///
namespace TBF.BenchControl.TestMethods.GrabImage
{
partial class CfgCtrl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.nameTextBox = new System.Windows.Forms.TextBox();
this.nameLabel = new System.Windows.Forms.Label();
this.classNameLabel = new System.Windows.Forms.Label();
this.hiResolutionCheckBox = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// nameTextBox
//
this.nameTextBox.Enabled = false;
this.nameTextBox.Location = new System.Drawing.Point(134, 69);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(130, 20);
this.nameTextBox.TabIndex = 7;
//
// nameLabel
//
this.nameLabel.AutoSize = true;
this.nameLabel.Location = new System.Drawing.Point(24, 72);
this.nameLabel.Name = "nameLabel";
this.nameLabel.Size = new System.Drawing.Size(35, 13);
this.nameLabel.TabIndex = 6;
this.nameLabel.Text = "Name";
//
// classNameLabel
//
this.classNameLabel.AutoSize = true;
this.classNameLabel.Location = new System.Drawing.Point(131, 43);
this.classNameLabel.Name = "classNameLabel";
this.classNameLabel.Size = new System.Drawing.Size(83, 13);
this.classNameLabel.TabIndex = 5;
this.classNameLabel.Text = "ComonentName";
//
// hiResolutionCheckBox
//
this.hiResolutionCheckBox.AutoSize = true;
this.hiResolutionCheckBox.Enabled = false;
this.hiResolutionCheckBox.Location = new System.Drawing.Point(134, 104);
this.hiResolutionCheckBox.Name = "hiResolutionCheckBox";
this.hiResolutionCheckBox.Size = new System.Drawing.Size(96, 17);
this.hiResolutionCheckBox.TabIndex = 8;
this.hiResolutionCheckBox.Text = "High resolution";
this.hiResolutionCheckBox.UseVisualStyleBackColor = true;
//
// CfgCtrl
//
this.Controls.Add(this.hiResolutionCheckBox);
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.classNameLabel);
this.Name = "CfgCtrl";
this.Size = new System.Drawing.Size(300, 240);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox nameTextBox;
private System.Windows.Forms.Label nameLabel;
private System.Windows.Forms.Label classNameLabel;
private System.Windows.Forms.CheckBox hiResolutionCheckBox;
}
}
@@ -18,7 +18,40 @@ namespace TBF.BenchControl.TestMethods.GrabImage
public bool Publish(Test test) { return false; }
public bool CanTest(MetersKind meters) { return true; }
Cfg cfg;
GrabImageCfg cfg;
#region Configuration Change Handling
public static void OnCfgChange(object sender, CfgChangeArgs args)
{
if (CfgChangeHandler == null) return;
try { CfgChangeHandler(sender, args); }
catch (Exception e) { log.Error("CfgChangeHandler(...) failed", e); }
}
public static event EventHandler<CfgChangeArgs> CfgChangeHandler;
public override void StartChangeHandler()
{
CfgChangeHandler += delegate(object sender, CfgChangeArgs args)
{
GrabImageCfg tmpcfg = args.Cfg as GrabImageCfg;
if (tmpcfg != null && tmpcfg.Name.Equals(Name))
{
if (args.Command == CfgChangeCmd.CfgChange)
{
cfg.ImageFileName = tmpcfg.ImageFileName;
cfg.BlackAndWhite = tmpcfg.BlackAndWhite;
cfg.LowResolution = tmpcfg.LowResolution;
cfg.ImageRotation = tmpcfg.ImageRotation;
}
}
};
}
#endregion Configuration Change Handling
public Component()
{
@@ -27,13 +60,15 @@ namespace TBF.BenchControl.TestMethods.GrabImage
public Component(Generic.IComponentCfg cfg)
: base(cfg)
{
this.cfg = cfg as GrabImageCfg;
StartChangeHandler();
log.Debug(this.ToString());
this.cfg = cfg as Cfg;
}
public IList<Event> Execute(Test test, bool bdummy, int idummy)
{
return (new GrabImageSeq()).Execute(test, cfg.LowResolution);
return (new GrabImageSeq()).Execute(test, cfg);
}
}
}
@@ -16,11 +16,11 @@ namespace TBF.BenchControl.TestMethods.GrabImage
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new Component(cfg); }
public IComponentCfg DefaultConfig() { return new Cfg(this, this.GetType().Namespace.Substring(29)); }
public IComponentCfg DefaultConfig() { return new GrabImageCfg(this, this.GetType().Namespace.Substring(29)); }
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
{
return ComponentCfgBase.CreateFromDbEntity(Cfg.Serializer, component, this);
return ComponentCfgBase.CreateFromDbEntity(GrabImageCfg.Serializer, component, this);
}
}
}
@@ -5,27 +5,30 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using Config.Entities;
using TBF.BenchControl.Generic;
using TBF.Resources;
namespace TBF.BenchControl.TestMethods.GrabImage
{
public class Cfg : ComponentCfgBase, Generic.IComponentCfg
public class GrabImageCfg : ComponentCfgBase, Generic.IComponentCfg
{
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(Cfg) })[0];
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(GrabImageCfg) })[0];
protected override XmlSerializer GetSerializer() { return Serializer; }
public IComponentCfgCtrl GetControl() { return new CfgCtrl(); }
public IComponentCfgCtrl GetControl() { return new GrabImageCfgCtrl(); }
public string ImageFileName;
public bool BlackAndWhite;
public bool LowResolution;
public ImageRotation ImageRotation;
/// Private parameterless constructor invoked by all other (public) constructors
Cfg() {}
GrabImageCfg() {}
public Cfg(IComponentFactory factory, string name)
public GrabImageCfg(IComponentFactory factory, string name)
: this()
{
this.Factory = factory;
@@ -33,11 +36,13 @@ namespace TBF.BenchControl.TestMethods.GrabImage
ParentName = string.Empty;
BlackAndWhite = false;
LowResolution = false;
ImageRotation = ImageRotation.None;
}
public string ToString(int i)
{
return string.Format("Name={0}, B&W={1}, LowRes={2}", Name, BlackAndWhite, LowResolution);
return string.Format("Name={0}, Img={1}, B&W={2}, LowRes={3}, Rotation={4}",
Name, ImageFileName, BlackAndWhite, LowResolution, ImageRotation);
}
}
}
@@ -0,0 +1,131 @@
///
/// Copyright (c) 2017 Sensus Metering Systems
///
using System;
using System.Windows.Forms;
using log4net;
using Config.Entities;
using TBF.BenchControl.Generic;
using TBF.Resources;
namespace TBF.BenchControl.TestMethods.GrabImage
{
public partial class GrabImageCfgCtrl : UserControl, IComponentCfgCtrl
{
static readonly ILog log = LogManager.GetLogger(typeof(GrabImageCfgCtrl));
public bool ShowMore { get { return false; } }
GrabImageCfg config;
public IComponentCfg Config
{
get { return config as IComponentCfg; }
set
{
config = value as GrabImageCfg;
Redraw();
}
}
public GrabImageCfgCtrl()
{
InitializeComponent();
}
private void GrabImageCfgCtrl_Load(object sender, EventArgs e)
{
for (ImageRotation ir = 0; ir < ImageRotation.Count; ir++)
{
imageRotationComboBox.Items.Add(ir.ToDescription());
}
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;
imageNameTextBox.Text = config.ImageFileName;
blackAndWhiteCheckBox.Checked = config.BlackAndWhite;
loResolutionCheckBox.Checked = config.LowResolution;
imageRotationComboBox.Text = config.ImageRotation.ToDescription();
}
public void Unlock()
{
nameTextBox.Enabled = true;
imageNameTextBox.Enabled = true;
blackAndWhiteCheckBox.Enabled = true;
loResolutionCheckBox.Enabled = true;
imageRotationComboBox.Enabled = true;
}
public CfgUpdateFlags VerifyCfg(ref string message)
{
for (ImageRotation ir = 0; ir < ImageRotation.Count; ir++)
{
if (imageRotationComboBox.Text == ir.ToDescription()) return CfgUpdateFlags.None;
}
message += Environment.NewLine + string.Format(Strings.Invalid_0, imageRotationLabel.Text);
return CfgUpdateFlags.Error;
}
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.AnyChange | CfgUpdateFlags.RestartRqrd);
}
if (config.ImageFileName != imageNameTextBox.Text)
{
config.ImageFileName = imageNameTextBox.Text;
flags |= (CfgUpdateFlags.AnyChange | CfgUpdateFlags.InvokeCfgChange);
}
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 ((flags & CfgUpdateFlags.InvokeCfgChange) != 0)
{
Component.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.CfgChange, config));
}
return flags;
}
}
}
@@ -0,0 +1,159 @@
///
/// Copyright (c) 2017 Sensus Metering Systems
///
namespace TBF.BenchControl.TestMethods.GrabImage
{
partial class GrabImageCfgCtrl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.nameTextBox = new System.Windows.Forms.TextBox();
this.nameLabel = new System.Windows.Forms.Label();
this.classNameLabel = new System.Windows.Forms.Label();
this.loResolutionCheckBox = new System.Windows.Forms.CheckBox();
this.blackAndWhiteCheckBox = new System.Windows.Forms.CheckBox();
this.imageNameTextBox = new System.Windows.Forms.TextBox();
this.imageNameLabel = new System.Windows.Forms.Label();
this.imageRotationLabel = new System.Windows.Forms.Label();
this.imageRotationComboBox = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// nameTextBox
//
this.nameTextBox.Enabled = false;
this.nameTextBox.Location = new System.Drawing.Point(149, 69);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(171, 20);
this.nameTextBox.TabIndex = 2;
//
// nameLabel
//
this.nameLabel.AutoSize = true;
this.nameLabel.Location = new System.Drawing.Point(24, 72);
this.nameLabel.Name = "nameLabel";
this.nameLabel.Size = new System.Drawing.Size(95, 13);
this.nameLabel.TabIndex = 1;
this.nameLabel.Text = "Test method name";
//
// classNameLabel
//
this.classNameLabel.AutoSize = true;
this.classNameLabel.Location = new System.Drawing.Point(146, 43);
this.classNameLabel.Name = "classNameLabel";
this.classNameLabel.Size = new System.Drawing.Size(83, 13);
this.classNameLabel.TabIndex = 0;
this.classNameLabel.Text = "ComonentName";
//
// loResolutionCheckBox
//
this.loResolutionCheckBox.AutoSize = true;
this.loResolutionCheckBox.Enabled = false;
this.loResolutionCheckBox.Location = new System.Drawing.Point(149, 149);
this.loResolutionCheckBox.Name = "loResolutionCheckBox";
this.loResolutionCheckBox.Size = new System.Drawing.Size(94, 17);
this.loResolutionCheckBox.TabIndex = 6;
this.loResolutionCheckBox.Text = "Low resolution";
this.loResolutionCheckBox.UseVisualStyleBackColor = true;
//
// blackAndWhiteCheckBox
//
this.blackAndWhiteCheckBox.AutoSize = true;
this.blackAndWhiteCheckBox.Enabled = false;
this.blackAndWhiteCheckBox.Location = new System.Drawing.Point(149, 126);
this.blackAndWhiteCheckBox.Name = "blackAndWhiteCheckBox";
this.blackAndWhiteCheckBox.Size = new System.Drawing.Size(93, 17);
this.blackAndWhiteCheckBox.TabIndex = 5;
this.blackAndWhiteCheckBox.Text = "Black && White";
this.blackAndWhiteCheckBox.UseVisualStyleBackColor = true;
//
// imageNameTextBox
//
this.imageNameTextBox.Enabled = false;
this.imageNameTextBox.Location = new System.Drawing.Point(149, 95);
this.imageNameTextBox.Name = "imageNameTextBox";
this.imageNameTextBox.Size = new System.Drawing.Size(171, 20);
this.imageNameTextBox.TabIndex = 4;
//
// imageNameLabel
//
this.imageNameLabel.AutoSize = true;
this.imageNameLabel.Location = new System.Drawing.Point(24, 98);
this.imageNameLabel.Name = "imageNameLabel";
this.imageNameLabel.Size = new System.Drawing.Size(81, 13);
this.imageNameLabel.TabIndex = 3;
this.imageNameLabel.Text = "Image file name";
//
// imageRotationLabel
//
this.imageRotationLabel.AutoSize = true;
this.imageRotationLabel.Location = new System.Drawing.Point(24, 175);
this.imageRotationLabel.Name = "imageRotationLabel";
this.imageRotationLabel.Size = new System.Drawing.Size(103, 13);
this.imageRotationLabel.TabIndex = 7;
this.imageRotationLabel.Text = "Image rotation (ccw)";
//
// imageRotationComboBox
//
this.imageRotationComboBox.Enabled = false;
this.imageRotationComboBox.FormattingEnabled = true;
this.imageRotationComboBox.Location = new System.Drawing.Point(149, 172);
this.imageRotationComboBox.Name = "imageRotationComboBox";
this.imageRotationComboBox.Size = new System.Drawing.Size(171, 21);
this.imageRotationComboBox.TabIndex = 8;
//
// GrabImageCfgCtrl
//
this.Controls.Add(this.imageRotationComboBox);
this.Controls.Add(this.imageRotationLabel);
this.Controls.Add(this.imageNameTextBox);
this.Controls.Add(this.imageNameLabel);
this.Controls.Add(this.blackAndWhiteCheckBox);
this.Controls.Add(this.loResolutionCheckBox);
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.classNameLabel);
this.Name = "GrabImageCfgCtrl";
this.Size = new System.Drawing.Size(400, 250);
this.Load += new System.EventHandler(this.GrabImageCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox nameTextBox;
private System.Windows.Forms.Label nameLabel;
private System.Windows.Forms.Label classNameLabel;
private System.Windows.Forms.CheckBox loResolutionCheckBox;
private System.Windows.Forms.CheckBox blackAndWhiteCheckBox;
private System.Windows.Forms.TextBox imageNameTextBox;
private System.Windows.Forms.Label imageNameLabel;
private System.Windows.Forms.Label imageRotationLabel;
private System.Windows.Forms.ComboBox imageRotationComboBox;
}
}
@@ -5,6 +5,7 @@ using System.Collections.Generic;
using log4net;
using Config.Entities;
using TBF.UiBridge;
using System.IO;
namespace TBF.BenchControl.TestMethods.GrabImage
{
@@ -13,7 +14,7 @@ namespace TBF.BenchControl.TestMethods.GrabImage
private static readonly ILog log = LogManager.GetLogger(typeof(GrabImageSeq));
public IList<Event> Execute(Test test, bool hiResolution)
public IList<Event> Execute( Test test, GrabImageCfg cfg)
{
IList<Event> e = new List<Event>(); /// Events from currently running operations
Event retVal = Event.Done;
@@ -32,22 +33,19 @@ namespace TBF.BenchControl.TestMethods.GrabImage
//------------------------------------------------
State state = State.Create(string.Format("{0}({1}) : Grabbing images", test.Method, test.Name))
.AddOperation(checkUiOp);
foreach (var rr in sensPath.RegisterReaders)
for (int i = 0; i < sensPath.RegisterReaders.Length; i++)
{
if (rr is GenericDevices.IRoi)
GenericDevices.IRoi roi = sensPath.RegisterReaders[i] as GenericDevices.IRoi;
if (roi != null)
{
GenericDevices.ICamera camera = (rr as GenericDevices.IRoi).Camera;
if (!cameras.Contains(camera))
{
cameras.Add(camera);
grabImagesOp.Add(camera.LiveStreamOp(hiResolution));
}
string directory = Path.Combine(Program.ImagesDir, BatchRslts.Batch.BatchNr.ToString(), i.ToString());
Directory.CreateDirectory(directory);
state.AddOperation(roi.GrabImageOp(Path.Combine(directory, cfg.ImageFileName),
cfg.BlackAndWhite,
cfg.LowResolution,
cfg.ImageRotation));
}
}
state.AddOperations(grabImagesOp);
state.EnterState();
do
{
@@ -55,17 +53,10 @@ namespace TBF.BenchControl.TestMethods.GrabImage
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, 1, Config.Entities.Progress.Test));
if (e.Contains(Event.Error))
{
break;
}
if (TestAndLogUiCmdStop(test,e))
{
break;
}
if (e.Contains(Event.Error)) { retVal = Event.Error; break; }
if (TestAndLogUiCmdStop(test, e)) { retVal = Event.UiCmdStop; break; }
}
while (true);
while (e.Contains(Event.CameraBusy));
Bridge.OnTestProgress(this, new TestProgressEventArgs(test, 1, Config.Entities.Progress.Completed));