DataEntry.Uni camera support in TestStartEndForm, ver. 3.6.2072

This commit is contained in:
Milan Hanajik 2023-07-18 17:46:57 +02:00
parent 3f35506b26
commit dd5b20ab38
13 changed files with 966 additions and 160 deletions

View File

@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("3.6.2068.0")]
[assembly: AssemblyFileVersion("3.6.2068.0")]
[assembly: AssemblyVersion("3.6.2072.0")]
[assembly: AssemblyFileVersion("3.6.2072.0")]

View File

@ -44,6 +44,28 @@ namespace TBF.Rig.DataEntry
Count
}
///
/// Identifies image instance
///
public enum Tst
{
Start,
End,
Both,
}
///
/// Image rotation
///
public enum Rotation
{
R0,
R90,
R180,
R270,
Count
}
public class DEItem
{
public readonly Ct Content;

View File

@ -1,9 +1,12 @@
using System.Collections.Generic;
///
/// Copyright (c) 2022 Sensus Slovensko a.s.
///
using System.Collections.Generic;
#if OCR
using ViDi2;
#endif
namespace TBF.Rig.DataEntry.StandardCamera
namespace TBF.Rig.DataEntry
{
public class OcrVidi
{

View File

@ -5,8 +5,6 @@ using System;
using System.Collections.Generic;
using log4net;
using Common;
using Config.Entities;
using TBF.Rig;
using TBF.Rig.GenericDevices;
namespace TBF.Rig.DataEntry.StandardCamera

View File

@ -14,35 +14,31 @@ using TBF.Resources;
namespace TBF.Rig.DataEntry.StandardCamera
{
/// Type for argument that identifies images
enum Tst
{
Start,
End,
Both,
}
enum Rotation
{
R0,
R90,
R180,
R270,
Count
}
public partial class TestStartEndForm : Form, GenericDevices.IHasCompleted
{
private static readonly ILog log = LogManager.GetLogger(typeof(TestStartEndForm));
const Unit unit = Unit.m3;
// Set to 'true' when the form closes
public bool Completed { get { return completed; } }
bool completed;
///
/// Static members and constructor
///
static int wmNr0b;
static Rotation imageRotation;
static bool[] isZoomed;
static Point[] zoomCenterLoc;
///
static TestStartEndForm()
{
wmNr0b = 0;
//imageRotation = new Rotation[TextBoxesCount];
isZoomed = new bool[TextBoxesCount];
zoomCenterLoc = new Point[TextBoxesCount];
}
/// <summary> Number of text boxes for serial numbers </summary>
readonly Tst mode; /// Start, End or Deferred
/// Arguments
readonly Tst mode; /// Start, End or Deferred
public readonly int WaterMetersCount;
readonly IRegReader[] regReaders;
readonly bool[] disabled;
@ -78,19 +74,6 @@ namespace TBF.Rig.DataEntry.StandardCamera
public delegate void OcrTextObtainedDelegate(int ix, bool isEnd, string text);
OcrTextObtainedDelegate ocrTextObtained;
static int wmNr0b;
static Rotation imageRotation;
static bool[] isZoomed;
static Point[] zoomCenterLoc;
///
static TestStartEndForm()
{
wmNr0b = 0;
//imageRotation = new Rotation[TextBoxesCount];
isZoomed = new bool[TextBoxesCount];
zoomCenterLoc = new Point[TextBoxesCount];
}
readonly Label[] labels;
readonly TextBox[] startTextBoxes;
readonly TextBox[] endTextBoxes;
@ -101,10 +84,15 @@ namespace TBF.Rig.DataEntry.StandardCamera
IList<TextBox> enabledTextBoxes;
/// <summary>
/// Parameterless constructor initializing common part for start and endstate form
/// </summary>
public TestStartEndForm()
/// Set to 'true' when the form closes
public bool Completed { get { return completed; } }
bool completed;
/// <summary>
/// Parameterless constructor initializing common part for start and endstate form
/// </summary>
public TestStartEndForm()
{
InitializeComponent();
ControlBox = false;

View File

@ -19,7 +19,7 @@ namespace TBF.Rig.DataEntry.Uni
/// Arguments
public readonly IList<WaterMeter> WaterMeters;
readonly int lineSize;
readonly Sz sz;
readonly FontSz sz;
readonly bool isLrOrder; /// true = controls obtain focus after ENTER key in left-right order, false = top-down order
readonly IList<DEItem> commonItems;
readonly IList<DEItem> colItems;
@ -82,8 +82,8 @@ namespace TBF.Rig.DataEntry.Uni
/// <param name="commonItems">Common items displayed in the upper part of the form</param>
/// <param name="colItems">Water meter items displayed in columns (in the matrix in the main part of the form)</param>
/// <param name="isEnd">true = This form is displayed at the end of cycle</param>
public CycleBgEnForm(IList<WaterMeter> waterMeters, int lineSize, string title, Sz sz, bool isLrOrder, string formCloseKeys,
IList<DEItem> commonItems, IList<DEItem> colItems, bool isEnd = false)
public CycleBgEnForm(IList<WaterMeter> waterMeters, int lineSize, string title, FontSz sz, bool isLrOrder, bool isCameraPicture,
string formCloseKeys, IList<DEItem> commonItems, IList<DEItem> colItems, bool isEnd = false)
: this()
{
/// Arguments
@ -127,7 +127,7 @@ namespace TBF.Rig.DataEntry.Uni
/// Layout related readonly variables derived from argument 'sz'
switch (sz)
{
case Sz.S:
case FontSz.S:
font = new Font("Verdana", 12, FontStyle.Regular);
meterHeight = 26; /// Height of a ComboBox control
margin = 20;
@ -139,7 +139,7 @@ namespace TBF.Rig.DataEntry.Uni
break;
default:
case Sz.M:
case FontSz.M:
font = new Font("Verdana", 14, FontStyle.Regular);
meterHeight = 31; /// Height of a ComboBox control
margin = 25;
@ -150,7 +150,7 @@ namespace TBF.Rig.DataEntry.Uni
checkBoxWid = 23;
break;
case Sz.L:
case FontSz.L:
font = new Font("Verdana", 18, FontStyle.Regular);
meterHeight = 37; /// Height of a ComboBox control
margin = 30;

View File

@ -5,7 +5,7 @@ using TBF.Rig.GenericDevices;
namespace TBF.Rig.DataEntry.Uni
{
public class EntryForm : EntryFormNoStartEnd, IHasWMStatesForm
public class EntryForm : EntryFormNoStartEnd, IDataEntryForCamera, IHasWMStatesForm
{
public EntryForm()
: base()

View File

@ -12,7 +12,7 @@ using TBF.Rig.Generic;
namespace TBF.Rig.DataEntry.Uni
{
public enum Sz
public enum FontSz
{
[Description("Small")] S,
[Description("Medium")] M,
@ -35,29 +35,29 @@ namespace TBF.Rig.DataEntry.Uni
///
public bool BgShowForm; /// 0
public string BgTitle; /// 1
public Sz BgSize; /// 2
public FontSz BgSize; /// 2
// int BgItemsCount; /// 3
// int BgColumnsCount; /// 4
public bool BgIsLrOrder; /// 5
public bool BgIsVertArrangement; /// 6
public bool BgIsCameraPicture; /// 6
public string BgFormCloseKeys; /// 7
public bool EnShowForm; /// 8
public string EnTitle; /// 9
public Sz EnSize; /// 10
public FontSz EnSize; /// 10
// int EnItemsCount; /// 11
// int EnColumnsCount; /// 12
public bool EnIsLrOrder; /// 13
public bool EnIsVertArrangement; /// 14
public bool EnIsCameraPicture; /// 14
public string EnFormCloseKeys; /// 15
public bool TestStartEndShowForm; /// 16
public string TestTitle; /// 17
public Sz TestSize; /// 18
public FontSz TestSize; /// 18
// int TestColumnsCount; /// 19
public bool TestStartBoxAlwaysEn; /// 20
public bool TestIsLrOrder; /// 21
public bool TestIsVertArrangement; /// 22
public bool TestIsCameraPicture; /// 22
public string TestFormCloseKeys; /// 23
public Ct[] BgItemContent; /// 24 + 4 * ix
@ -86,7 +86,7 @@ namespace TBF.Rig.DataEntry.Uni
public int[] TestColumnWidth; /// 27 + 4 * ix
///
/// Not serialized
/// Not serialized (private)
///
int oriBgItemsCount = -1;
int oriBgColumnsCount = -1;
@ -94,6 +94,15 @@ namespace TBF.Rig.DataEntry.Uni
int oriEnColumnsCount = -1;
int oriTestColumnsCount = -1;
///
/// Procedure parameters
///
[XmlIgnore]
public ProcParams ProcParams;
public override IParamsProvider GetRuntimeProcParamsProvider() { return ProcParams; }
public override IParamsProvider CreateProcParamsProvider() { return new ProcParams(true); }
///
/// Wrappers
///
@ -308,13 +317,16 @@ namespace TBF.Rig.DataEntry.Uni
///
/// Private parameterless constructor invoked by all other (public) constructors
///
EntryFormCfg() { }
EntryFormCfg()
{
ProcParams = new ProcParams(true);
}
public EntryFormCfg(IComponentFactory factory, string name)
: this()
{
this.Factory = factory;
this.Name = name;
Factory = factory;
Name = name;
ParentName = string.Empty;
InitializeAll();
}
@ -325,24 +337,24 @@ namespace TBF.Rig.DataEntry.Uni
{
BgShowForm = true;
BgTitle = "Enter water meter data";
BgSize = Sz.M;
BgSize = FontSz.M;
BgIsLrOrder = false;
BgIsVertArrangement = false;
BgIsCameraPicture = false;
BgFormCloseKeys = string.Empty;
EnShowForm = false;
EnTitle = "Enter water meter data";
EnSize = Sz.M;
EnSize = FontSz.M;
EnIsLrOrder = false;
EnIsVertArrangement = false;
EnIsCameraPicture = false;
EnFormCloseKeys = string.Empty;
TestStartEndShowForm = true;
TestTitle = "Enter states of water meters";
TestSize = Sz.M;
TestSize = FontSz.M;
TestStartBoxAlwaysEn = false;
TestIsLrOrder = false;
TestIsVertArrangement = false;
TestIsCameraPicture = false;
TestFormCloseKeys = string.Empty;
BgItemContent = new Ct[1] { Ct.BatchAndWmOrder };
@ -379,7 +391,7 @@ namespace TBF.Rig.DataEntry.Uni
"Beginning: Common items count",
"Beginning: Columns count",
"Beginning: Left-to-right order",
"Beginning: Vertical arrangement",
"Beginning: Show camera picture",
"Beginning: Keys to close the form",
"End: Show form",
@ -388,7 +400,7 @@ namespace TBF.Rig.DataEntry.Uni
"End: Common items count",
"End: Columns count",
"End: Left-to-right order",
"End: Vertical arrangement",
"End: Show camera picture",
"End: Keys to close the form",
"Test start/end: Show form",
@ -397,7 +409,7 @@ namespace TBF.Rig.DataEntry.Uni
"Test start/end: Columns count",
"Test start/end: Start text box always enabled",
"Test start/end: Left-to-right order",
"Test start/end: Vertical arrangement",
"Test start/end: Show camera picture",
"Test start/end: Keys to close the form",
};
public string ParamName(int i)
@ -501,7 +513,7 @@ namespace TBF.Rig.DataEntry.Uni
case 2:
case 10:
case 18:
for (Sz sz = 0; sz < Sz.Count; sz++) list.Add(sz.ToDescription());
for (FontSz sz = 0; sz < FontSz.Count; sz++) list.Add(sz.ToDescription());
return list;
default:
return null;
@ -573,7 +585,7 @@ namespace TBF.Rig.DataEntry.Uni
case 3: return GetBgItemsCount().ToString();
case 4: return GetBgColumnsCount().ToString();
case 5: return BgIsLrOrder ? Strings.yes : Strings.no;
case 6: return BgIsVertArrangement ? Strings.yes : Strings.no;
case 6: return BgIsCameraPicture ? Strings.yes : Strings.no;
case 7: return BgFormCloseKeys;
case 8: return EnShowForm ? Strings.yes : Strings.no;
@ -582,7 +594,7 @@ namespace TBF.Rig.DataEntry.Uni
case 11: return GetEnItemsCount().ToString();
case 12: return GetEnColumnsCount().ToString();
case 13: return EnIsLrOrder ? Strings.yes : Strings.no;
case 14: return EnIsVertArrangement ? Strings.yes : Strings.no;
case 14: return EnIsCameraPicture ? Strings.yes : Strings.no;
case 15: return EnFormCloseKeys;
case 16: return TestStartEndShowForm ? Strings.yes : Strings.no;
@ -591,7 +603,7 @@ namespace TBF.Rig.DataEntry.Uni
case 19: return GetTestColumnsCount().ToString();
case 20: return TestStartBoxAlwaysEn ? Strings.yes : Strings.no;
case 21: return TestIsLrOrder ? Strings.yes : Strings.no;
case 22: return TestIsVertArrangement ? Strings.yes : Strings.no;
case 22: return TestIsCameraPicture ? Strings.yes : Strings.no;
case 23: return TestFormCloseKeys;
default: return string.Empty;
@ -677,7 +689,7 @@ namespace TBF.Rig.DataEntry.Uni
case 0: BgShowForm = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
case 1: BgTitle = str; return CfgUpdateFlags.RestartRqrd;
case 2:
for (Sz sz = 0; sz < Sz.Count; sz++)
for (FontSz sz = 0; sz < FontSz.Count; sz++)
{
if (str == sz.ToDescription())
{
@ -689,13 +701,13 @@ namespace TBF.Rig.DataEntry.Uni
case 3: SetBgItemsCount(int.Parse(str)); return CfgUpdateFlags.RestartRqrd;
case 4: SetBgColumnsCount(int.Parse(str)); return CfgUpdateFlags.RestartRqrd;
case 5: BgIsLrOrder = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
case 6: BgIsVertArrangement = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
case 6: BgIsCameraPicture = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
case 7: BgFormCloseKeys = str; return CfgUpdateFlags.RestartRqrd;
case 8: EnShowForm = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
case 9: EnTitle = str; return CfgUpdateFlags.RestartRqrd;
case 10:
for (Sz sz = 0; sz < Sz.Count; sz++)
for (FontSz sz = 0; sz < FontSz.Count; sz++)
{
if (str == sz.ToDescription())
{
@ -707,13 +719,13 @@ namespace TBF.Rig.DataEntry.Uni
case 11: SetEnItemsCount(int.Parse(str)); return CfgUpdateFlags.RestartRqrd;
case 12: SetEnColumnsCount(int.Parse(str)); return CfgUpdateFlags.RestartRqrd;
case 13: EnIsLrOrder = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
case 14: EnIsVertArrangement = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
case 14: EnIsCameraPicture = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
case 15: EnFormCloseKeys = str; return CfgUpdateFlags.RestartRqrd;
case 16: TestStartEndShowForm = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
case 17: TestTitle = str; return CfgUpdateFlags.RestartRqrd;
case 18:
for (Sz sz = 0; sz < Sz.Count; sz++)
for (FontSz sz = 0; sz < FontSz.Count; sz++)
{
if (str == sz.ToDescription())
{
@ -725,7 +737,7 @@ namespace TBF.Rig.DataEntry.Uni
case 19: SetTestColumnsCount(int.Parse(str)); return CfgUpdateFlags.RestartRqrd;
case 20: TestStartBoxAlwaysEn = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
case 21: TestIsLrOrder = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
case 22: TestIsVertArrangement = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
case 22: TestIsCameraPicture = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd;
case 23: TestFormCloseKeys = str; return CfgUpdateFlags.RestartRqrd;
default:
@ -909,18 +921,18 @@ namespace TBF.Rig.DataEntry.Uni
void CopyContentTo(EntryFormCfg prms)
{
prms.BgShowForm = BgShowForm;
prms.BgShowForm = BgShowForm;
prms.BgTitle = BgTitle;
prms.BgSize = BgSize;
prms.BgIsLrOrder = BgIsLrOrder;
prms.BgIsVertArrangement = BgIsVertArrangement;
prms.BgIsCameraPicture = BgIsCameraPicture;
prms.BgFormCloseKeys = BgFormCloseKeys;
prms.EnShowForm = EnShowForm;
prms.EnShowForm = EnShowForm;
prms.EnTitle = EnTitle;
prms.EnSize = EnSize;
prms.EnIsLrOrder = EnIsLrOrder;
prms.EnIsVertArrangement = EnIsVertArrangement;
prms.EnIsCameraPicture = EnIsCameraPicture;
prms.EnFormCloseKeys = EnFormCloseKeys;
prms.TestStartEndShowForm = TestStartEndShowForm;
@ -928,7 +940,7 @@ namespace TBF.Rig.DataEntry.Uni
prms.TestSize = TestSize;
prms.TestStartBoxAlwaysEn = TestStartBoxAlwaysEn;
prms.TestIsLrOrder = TestIsLrOrder;
prms.TestIsVertArrangement = TestIsVertArrangement;
prms.TestIsCameraPicture = TestIsCameraPicture;
prms.TestFormCloseKeys = TestFormCloseKeys;
prms.BgItemContent = new Ct[GetBgItemsCount()];

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using log4net;
using Common;
using TBF.Rig.GenericDevices;
namespace TBF.Rig.DataEntry.Uni
@ -13,15 +14,65 @@ namespace TBF.Rig.DataEntry.Uni
private static readonly ILog log = LogManager.GetLogger(typeof(EntryFormNoStartEnd));
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
public bool UsesCameras() { return false; }
const string DfltOcrWorkspaceFolder = "C:\\TBF\\OCR\\";
const string DfltOcrWorkspaceExt = ".vrws";
static Dictionary<string, OcrVidi> ocrDictionary = new Dictionary<string, OcrVidi>();
readonly EntryFormCfg myCfg;
IRegReader[] regReaders;
/// <summary>
/// Properties set by the Begin, End and WMStates form
/// </summary>
bool[] disabled; /// This array is shared between forms
public string OcrWorkspace
{
get { return (myCfg != null && myCfg.ProcParams != null) ? myCfg.ProcParams.OcrWorkspace : string.Empty; }
}
public string OcrStream
{
get { return (myCfg != null && myCfg.ProcParams != null) ? myCfg.ProcParams.OcrStream : string.Empty; }
}
IRegReader[] regReaders;
public string[] StartImages
{
get { return startImages; }
set
{
if (myCfg.DebugLevel == DebugMode.Simulate)
{
startImages = new string[] { "C:\\TBF\\Images\\Test\\Image1.bmp", "C:\\TBF\\Images\\Test\\Image2.bmp",
"C:\\TBF\\Images\\Test\\Image3.bmp", "C:\\TBF\\Images\\Test\\Image4.bmp", "C:\\TBF\\Images\\Test\\Image5.bmp",
"C:\\TBF\\Images\\Test\\Image1.bmp", "C:\\TBF\\Images\\Test\\Image2.bmp", "C:\\TBF\\Images\\Test\\Image3.bmp",
"C:\\TBF\\Images\\Test\\Image4.bmp", "C:\\TBF\\Images\\Test\\Image5.bmp", "C:\\TBF\\Images\\Test\\Image1.bmp",
"C:\\TBF\\Images\\Test\\Image2.bmp", "C:\\TBF\\Images\\Test\\Image3.bmp", "C:\\TBF\\Images\\Test\\Image4.bmp",
"C:\\TBF\\Images\\Test\\Image5.bmp", "C:\\TBF\\Images\\Test\\Image1.bmp", "C:\\TBF\\Images\\Test\\Image2.bmp",
"C:\\TBF\\Images\\Test\\Image3.bmp", "C:\\TBF\\Images\\Test\\Image4.bmp", "C:\\TBF\\Images\\Test\\Image5.bmp" };
}
else
{
startImages = value;
}
}
}
string[] startImages;
public string[] EndImages
{
get { return endImages; }
set { endImages = value; }
}
string[] endImages;
public bool SaveImages
{
get
{
return false; // return myCfg.SaveImages;
}
}
string[] wmCycleEndState;
public string WMCycleEndState(int wmNr) { return (wmNr >= 0 && wmNr < wmCycleEndState.Length) ? wmCycleEndState[wmNr] : string.Empty; }
@ -38,7 +89,7 @@ namespace TBF.Rig.DataEntry.Uni
System.Windows.Forms.Form modelessDlg;
public bool Completed { get { return (modelessDlg is IHasCompleted) ? (modelessDlg as IHasCompleted).Completed : true; } }
Common.Unit volumeUnit;
Unit volumeUnit;
double refVolume;
double errLimLo;
double errLimHi;
@ -50,13 +101,14 @@ namespace TBF.Rig.DataEntry.Uni
public enum CurrentOp
{
None,
ShowFormAtCycleBeginning,
ShowFormAtCycleEnd,
EnterTestStartStates,
EnterTestEndStates,
}
FormAtCycleBeginning,
FormAtCycleEnd,
TestStartStates,
TestEndStates,
DeferredTestEval,
}
CurrentOp currentOp;
CurrentOp currentOp;
public EntryFormNoStartEnd() { }
@ -69,12 +121,12 @@ namespace TBF.Rig.DataEntry.Uni
public override void Initialize()
{
disabled = new bool[TBF.Data.WMsCount];
wmStartState = new double[TBF.Data.WMsCount];
wmStartStateStr = new string[TBF.Data.WMsCount];
wmEndState = new double[TBF.Data.WMsCount];
wmCycleEndState = new string[TBF.Data.WMsCount];
volumeUnit = (TBF.Rig.Sequences.ProcessData.BenchInfo != null) ? TBF.Rig.Sequences.ProcessData.BenchInfo.VolumeUnit : Common.Unit.l;
volumeUnit = (Sequences.ProcessData.BenchInfo != null && Sequences.ProcessData.BenchInfo.VolumeUnit != Unit.None)
? Sequences.ProcessData.BenchInfo.VolumeUnit : Unit.l;
currentOp = CurrentOp.None;
log.FatalFormat("{0} initialized: {1}", Name, this);
}
@ -84,8 +136,8 @@ namespace TBF.Rig.DataEntry.Uni
public IOperation ShowCycleBeginFormOp()
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
currentOp = CurrentOp.ShowFormAtCycleBeginning;
this.waterMeters = TBF.Rig.Sequences.ProcessData.BatchRslts.Batch.WaterMeters;
currentOp = CurrentOp.FormAtCycleBeginning;
this.waterMeters = Sequences.ProcessData.BatchRslts.Batch.WaterMeters;
return this;
}
@ -93,7 +145,7 @@ namespace TBF.Rig.DataEntry.Uni
public IOperation ShowCycleEndFormOp(IList<Results.Entities.WaterMeter> waterMeters)
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
currentOp = CurrentOp.ShowFormAtCycleEnd;
currentOp = CurrentOp.FormAtCycleEnd;
this.waterMeters = waterMeters;
return this;
}
@ -102,8 +154,8 @@ namespace TBF.Rig.DataEntry.Uni
public IOperation ShowTestStartFormOp(IRegReader[] regReaders)
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
currentOp = CurrentOp.EnterTestStartStates;
this.waterMeters = TBF.Rig.Sequences.ProcessData.BatchRslts.Batch.WaterMeters;
currentOp = CurrentOp.TestStartStates;
this.waterMeters = Sequences.ProcessData.BatchRslts.Batch.WaterMeters;
this.regReaders = regReaders;
return this;
}
@ -112,8 +164,8 @@ namespace TBF.Rig.DataEntry.Uni
public IOperation ShowTestEndFormOp(IRegReader[] regReaders, double refVolume, double errLimLo, double errLimHi)
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
currentOp = CurrentOp.EnterTestEndStates;
this.waterMeters = TBF.Rig.Sequences.ProcessData.BatchRslts.Batch.WaterMeters;
currentOp = CurrentOp.TestEndStates;
this.waterMeters = Sequences.ProcessData.BatchRslts.Batch.WaterMeters;
this.regReaders = regReaders;
this.refVolume = refVolume;
this.errLimLo = errLimLo;
@ -121,15 +173,32 @@ namespace TBF.Rig.DataEntry.Uni
return this;
}
/// <returns>null (not implemented)</returns>
public IOperation ShowAdvancedTestStartFormOp(IRegReader[] regReaders, IList<Results.Entities.WaterMeter> waterMeters, bool isCondOp = false)
{
return null;
}
/// <returns>Reference to the operation</returns>
public IOperation ShowDeferredTestEvalFormOp(IRegReader[] regReaders, double refVolume, double errLimLo, double errLimHi)
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
currentOp = CurrentOp.DeferredTestEval;
this.waterMeters = Sequences.ProcessData.BatchRslts.Batch.WaterMeters;
this.regReaders = regReaders;
this.refVolume = refVolume;
this.errLimLo = errLimLo;
this.errLimHi = errLimHi;
return this;
}
delegate void EntryFormDlgt(EntryFormNoStartEnd myRef);
///
void OpenBeginningDlg(EntryFormNoStartEnd myRef)
{
string ocrMessage;
var ocr = GetOcr(myRef.OcrWorkspace, out ocrMessage);
DEItem.ClearItems();
for (int i = 0; i < myCfg.GetBgItemsCount(); i++)
{
@ -148,13 +217,16 @@ namespace TBF.Rig.DataEntry.Uni
}
}
modelessDlg = new CycleBgEnForm(waterMeters, TBF.Data.LineSize, myCfg.BgTitle, myCfg.BgSize, myCfg.BgIsLrOrder, myCfg.BgFormCloseKeys,
DEItem.GetItems(), DEItem.GetColumns(), false);
modelessDlg = new CycleBgEnForm(waterMeters, TBF.Data.LineSize, myCfg.BgTitle, myCfg.BgSize, myCfg.BgIsLrOrder, myCfg.BgIsCameraPicture,
myCfg.BgFormCloseKeys, DEItem.GetItems(), DEItem.GetColumns(), false);
modelessDlg.Show();
}
///
void OpenEndDlg(EntryFormNoStartEnd myRef)
{
string ocrMessage;
var ocr = GetOcr(myRef.OcrWorkspace, out ocrMessage);
DEItem.ClearItems();
for (int i = 0; i < myCfg.GetEnItemsCount(); i++)
{
@ -173,13 +245,16 @@ namespace TBF.Rig.DataEntry.Uni
}
}
modelessDlg = new CycleBgEnForm(waterMeters, TBF.Data.LineSize, myCfg.EnTitle, myCfg.EnSize, myCfg.EnIsLrOrder, myCfg.EnFormCloseKeys,
DEItem.GetItems(), DEItem.GetColumns(), true);
modelessDlg = new CycleBgEnForm(waterMeters, TBF.Data.LineSize, myCfg.EnTitle, myCfg.EnSize, myCfg.EnIsLrOrder, myCfg.EnIsCameraPicture,
myCfg.EnFormCloseKeys, DEItem.GetItems(), DEItem.GetColumns(), true);
modelessDlg.Show();
}
///
void OpenTestStartStatesDlg(EntryFormNoStartEnd myRef)
{
string ocrMessage;
var ocr = GetOcr(myRef.OcrWorkspace, out ocrMessage);
DEItem.ClearColumns();
for (int i = 0; i < myCfg.GetTestColumnsCount(); i++)
{
@ -190,13 +265,17 @@ namespace TBF.Rig.DataEntry.Uni
}
modelessDlg = new TestStartEndForm(waterMeters, myRef.regReaders, TBF.Data.LineSize, myCfg.TestTitle, myCfg.TestSize,
myCfg.TestStartBoxAlwaysEn, myCfg.TestIsLrOrder, myCfg.TestFormCloseKeys, DEItem.GetColumns(),
volumeUnit);
myCfg.TestStartBoxAlwaysEn, myCfg.TestIsLrOrder, myCfg.TestFormCloseKeys,
DEItem.GetColumns(), volumeUnit, myCfg.TestIsCameraPicture,
startImages, endImages, ocr, ocrMessage, myRef.OcrStream);
modelessDlg.Show();
}
///
void OpenTestEndStatesDlg(EntryFormNoStartEnd myRef)
{
string ocrMessage;
var ocr = GetOcr(myRef.OcrWorkspace, out ocrMessage);
DEItem.ClearColumns();
for (int i = 0; i < myCfg.GetTestColumnsCount(); i++)
{
@ -208,36 +287,110 @@ namespace TBF.Rig.DataEntry.Uni
modelessDlg = new TestStartEndForm(waterMeters, myRef.regReaders, TBF.Data.LineSize, myCfg.TestTitle, myCfg.TestSize,
myCfg.TestStartBoxAlwaysEn, myCfg.TestIsLrOrder, myCfg.TestFormCloseKeys, DEItem.GetColumns(),
volumeUnit, wmStartStateStr, refVolume, errLimLo, errLimHi);
volumeUnit, myCfg.TestIsCameraPicture, startImages, endImages,
ocr, ocrMessage, myRef.OcrStream, wmStartStateStr, refVolume, errLimLo, errLimHi);
modelessDlg.Show();
}
///
void OpenDeferredTestEvalDlg(EntryFormNoStartEnd myRef)
{
string ocrMessage;
var ocr = GetOcr(myRef.OcrWorkspace, out ocrMessage);
/// <summary>Start this operation</summary>
public void Start()
DEItem.ClearColumns();
for (int i = 0; i < myCfg.GetTestColumnsCount(); i++)
{
if (myCfg.TestColumnContent[i] != Ct.None)
{
DEItem.AddColumn(myCfg.TestColumnContent[i], myCfg.TestColumnCaption[i], myCfg.TestColumnAction[i], myCfg.TestColumnWidth[i]);
}
}
modelessDlg = new TestStartEndForm(waterMeters, myRef.regReaders, TBF.Data.LineSize, myCfg.TestTitle, myCfg.TestSize,
myCfg.TestStartBoxAlwaysEn, myCfg.TestIsLrOrder, myCfg.TestFormCloseKeys, DEItem.GetColumns(),
volumeUnit, myCfg.TestIsCameraPicture, startImages, endImages,
ocr, ocrMessage, myRef.OcrStream, wmStartStateStr, refVolume, errLimLo, errLimHi);
modelessDlg.Show();
}
///
OcrVidi GetOcr(string ocrWorkspace, out string message)
{
message = string.Empty;
if (string.IsNullOrEmpty(ocrWorkspace)) return null; /// No OCR was configured
string fullPath = (ocrWorkspace.Contains("\\") || ocrWorkspace.Contains("/"))
? ocrWorkspace.Replace('/', '\\')
: System.IO.Path.Combine(DfltOcrWorkspaceFolder, ocrWorkspace);
if (!fullPath.Contains(".")) fullPath = fullPath + DfltOcrWorkspaceExt;
OcrVidi ocrVidi;
if (ocrDictionary.TryGetValue(fullPath, out ocrVidi))
{
log.InfoFormat("existing OcrVidi({0}) was retrieved from dictionary", fullPath);
return ocrVidi;
}
try
{
ocrVidi = new OcrVidi(fullPath);
ocrDictionary.Add(fullPath, ocrVidi);
log.WarnFormat("new OcrVidi({0}) was added to dictionary", fullPath);
return ocrVidi;
}
catch (Exception e)
{
if (e.InnerException != null)
{
log.ErrorFormat("new OcrVidi({0}) thrown {1}: {2} / {3}",
fullPath, e.GetType().ToString(), e.Message, e.InnerException.Message);
}
else
{
log.ErrorFormat("new OcrVidi({0}) thrown {1}: {2}",
fullPath, e.GetType().ToString(), e.Message);
}
log.ErrorFormat("Stack trace:\r\n{0}", e.StackTrace);
message = string.Format("Cannot load OCR workspace:\r\n{0}\r\nOCR workspace file is {1}", e.Message, fullPath);
return null;
}
}
/// <summary>Start this operation</summary>
public void Start()
{
resultSaved = false;
switch (currentOp)
{
case CurrentOp.ShowFormAtCycleBeginning:
case CurrentOp.FormAtCycleBeginning:
if (myCfg.BgShowForm)
{
Program.MainWnd.Invoke(new EntryFormDlgt(OpenBeginningDlg), this);
}
break;
case CurrentOp.ShowFormAtCycleEnd:
case CurrentOp.FormAtCycleEnd:
if (myCfg.EnShowForm)
{
Program.MainWnd.Invoke(new EntryFormDlgt(OpenEndDlg), this);
}
break;
case CurrentOp.EnterTestStartStates:
Program.MainWnd.Invoke(new EntryFormDlgt(OpenTestStartStatesDlg), this);
case CurrentOp.TestStartStates:
if (myCfg.TestStartEndShowForm)
{
Program.MainWnd.Invoke(new EntryFormDlgt(OpenTestStartStatesDlg), this);
}
break;
case CurrentOp.TestEndStates:
if (myCfg.TestStartEndShowForm)
{
Program.MainWnd.Invoke(new EntryFormDlgt(OpenTestEndStatesDlg), this);
}
break;
case CurrentOp.EnterTestEndStates:
Program.MainWnd.Invoke(new EntryFormDlgt(OpenTestEndStatesDlg), this);
break;
}
}
case CurrentOp.DeferredTestEval:
Program.MainWnd.Invoke(new EntryFormDlgt(OpenDeferredTestEvalDlg), this);
break;
}
}
/// <summary>Run this operation</summary>
/// <returns>Event.ResultsPrinted</returns>
@ -250,7 +403,7 @@ namespace TBF.Rig.DataEntry.Uni
if (!resultSaved) /// This is to save the result only once
{
if (modelessDlg is TestStartEndForm && currentOp == CurrentOp.EnterTestStartStates)
if (modelessDlg is TestStartEndForm && currentOp == CurrentOp.TestStartStates)
{
/// Fixed start test - start
TestStartEndForm dlg = (modelessDlg as TestStartEndForm);
@ -267,7 +420,7 @@ namespace TBF.Rig.DataEntry.Uni
}
}
}
else if (modelessDlg is TestStartEndForm && currentOp == CurrentOp.EnterTestEndStates)
else if (modelessDlg is TestStartEndForm && currentOp == CurrentOp.TestEndStates)
{
/// Fixed start test - end
TestStartEndForm dlg = (modelessDlg as TestStartEndForm);

View File

@ -0,0 +1,132 @@
///
/// Copyright (c) 2022-2023 Sensus Slovensko a.s.
///
using System.IO;
using System.Xml.Serialization;
using Common;
using Config.Entities;
using TBF.Rig.Generic;
namespace TBF.Rig.DataEntry.Uni
{
public class ProcParams : ProcedureParamsBase, IParamsProvider, IProcedureParams
{
public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(ProcParams) })[0];
public override XmlSerializer GetSerializer() { return Serializer; }
public string OcrWorkspace; /// Path to a Cognex workspace file
public string OcrStream; /// Cognex workspace stream name
public override void InitializeAll()
{
OcrWorkspace = string.Empty;
OcrStream = "default";
}
string[] paramNames = new string[]
{
"OCR workspace file",
"OCR stream",
};
public override string ParamName(int i) { return paramNames[i]; }
public override int ParamsCount() { return paramNames.Length; }
public override string ToString(int i)
{
switch (i)
{
case 0: return OcrWorkspace;
case 1: return OcrStream;
default: return string.Empty;
}
}
public CfgUpdateFlags UpdateParam(int i, string str)
{
switch (i)
{
case 0: OcrWorkspace = str; return CfgUpdateFlags.None;
case 1: OcrStream = str; return CfgUpdateFlags.None;
default: return CfgUpdateFlags.None;
}
}
/// <summary>
/// Verifiy the string representation of the parameter
/// </summary>
/// <param name="i">Parameter ID</param>
/// <param name="str">String representation of the parameter</param>
/// <param name="message">In case false is returned this is the error messsage to be displayed</param>
/// <returns>true = parameter OK, false = parameter NOK</returns>
public bool ValidateParam(int i, string str, out string message)
{
message = string.Empty;
switch (i)
{
case 0:
return true;
case 1:
if (!string.IsNullOrEmpty(str)) return true;
break;
default:
message = "Invalid index";
return false;
}
message = ParamName(i) + " is invalid";
return false;
}
void CopyContentTo(ProcParams prms)
{
prms.OcrWorkspace = OcrWorkspace;
prms.OcrStream = OcrStream;
}
public IParamsProvider Clone()
{
ProcParams pars = new ProcParams();
CopyContentTo(pars);
return pars;
}
public override void UpdateFromDbEntity(ComponentProcedure dbEntity)
{
if (dbEntity == null) return;
try
{
ProcParams tmp = Serializer.Deserialize(new StringReader(dbEntity.Parameters)) as ProcParams;
procedureParamsEntity = dbEntity;
componentName = dbEntity.CmpntName;
procedure = dbEntity.Procedure;
if (tmp != null) tmp.CopyContentTo(this);
}
catch
{
}
}
/// <summary>
/// Parameterless constructor initializes the parameters
/// </summary>
public ProcParams()
{
}
public ProcParams(bool initialize)
{
if (initialize) InitializeAll();
}
public ProcParams(ComponentProcedure procParamsEntity, string componentName, Procedure procedure)
{
this.procedureParamsEntity = procParamsEntity;
this.componentName = componentName;
this.procedure = procedure;
}
}
}

View File

@ -11,6 +11,8 @@ using Common;
using Results.Entities;
using TBF.Rig.GenericDevices;
using TBF.Resources;
using System.Threading;
using System.IO;
namespace TBF.Rig.DataEntry.Uni
{
@ -18,22 +20,48 @@ namespace TBF.Rig.DataEntry.Uni
{
private static readonly ILog log = LogManager.GetLogger(typeof(TestStartEndForm));
const int PicSize = 480;
///
/// Static members and constructor
///
static int wmNr0b;
static Rotation imageRotation;
static bool[] isZoomed;
static Point[] zoomCenterLoc;
///
static TestStartEndForm()
{
wmNr0b = 0;
//imageRotation = new Rotation[40];
isZoomed = new bool[40];
zoomCenterLoc = new Point[40];
}
/// Arguments
public readonly IList<WaterMeter> waterMeters;
readonly IRegReader[] regReaders;
readonly int lineSize;
readonly Sz sz;
readonly FontSz sz;
readonly bool isStartBoxAlwaysEn;
readonly bool isLrOrder; /// true = controls obtain focus after ENTER key in left-right order, false = top-down order
readonly IList<DEItem> colItems;
readonly string formCloseKeys;
public readonly string[] WMStartStateStr;
readonly bool isCameraPicture; /// true = camera picture displayed on the left side
readonly string[] startImages;
readonly string[] endImages;
readonly OcrVidi ocrVidi;
readonly string ocrMessage;
readonly string streamName;
readonly double refVolume;
readonly double warningLimLo; /// limit to display exclamation mark, typically 2x errLimLo
readonly double warningLimHi; /// limit to display exclamation mark, typically 2x errLimHi
/// Derived from arguments in the constructor
readonly bool isEnd;
readonly Tst mode; /// Start, End or Deferred
readonly WaterMeter firstValidWM;
readonly int wmsCount;
readonly int linesCount;
@ -60,11 +88,25 @@ namespace TBF.Rig.DataEntry.Uni
readonly TextBox[,] textBoxes; /// Text boxes for values in columns
readonly Label[] exclamations;
/// Picture box related
PictureBox pictureBox1;
Label imageProcessingProgressLabel;
ProgressBar imageProcessingProgressBar;
string lastImageName;
int lastWmNr1;
Bitmap lastImage; /// non-zoomed image
Bitmap zoomedImage;
Thread imageProcessingThread; /// Thread to process images
public delegate void OcrTextObtainedDelegate(int ix, bool isEnd, string text);
OcrTextObtainedDelegate ocrTextObtained;
readonly LocalSettings ls;
bool isHandlersEnabled; /// Initially false, set to true after ComboBoxes are filled with data
// Set to 'true' when the form closes
/// Set to 'true' when the form closes
public bool Completed { get { return completed; } }
bool completed;
@ -76,7 +118,8 @@ namespace TBF.Rig.DataEntry.Uni
{
InitializeComponent();
ControlBox = false;
completed = false;
imageProcessingThread = null;
completed = false;
StartForceCloseHandler();
}
@ -96,10 +139,11 @@ namespace TBF.Rig.DataEntry.Uni
/// <param name="refVolume">Reference volume, it is used to verify the end state, show/hide exclamation if necessary</param>
/// <param name="errLimLo">Error limit low, it is used to verify the end state, show/hide exclamation if necessary</param>
/// <param name="errLimHi">Error limit high, it is used to verify the end state, show/hide exclamation if necessary</param>
public TestStartEndForm(IList<WaterMeter> waterMeters, IRegReader[] regReaders, int lineSize, string title, Sz sz,
public TestStartEndForm(IList<WaterMeter> waterMeters, IRegReader[] regReaders, int lineSize, string title, FontSz sz,
bool isStartBoxAlwaysEn, bool isLrOrder, string formCloseKeys, IList<DEItem> colItems,
Unit initialVolumeUnit, string[] wmStartStateStr = null,
double refVolume = 0, double errLimLo = 0, double errLimHi = 0)
Unit initialVolumeUnit, bool isCameraPicture, string[] startImages, string[] endImages,
OcrVidi ocrVidi, string ocrMessage, string streamName,
string[] wmStartStateStr = null, double refVolume = 0, double errLimLo = 0, double errLimHi = 0)
: this()
{
this.waterMeters = waterMeters;
@ -112,6 +156,12 @@ namespace TBF.Rig.DataEntry.Uni
this.formCloseKeys = !string.IsNullOrEmpty(formCloseKeys) ? formCloseKeys : string.Empty;
this.colItems = colItems;
this.VolumeUnit = initialVolumeUnit;
this.isCameraPicture = isCameraPicture;
this.startImages = startImages;
this.endImages = endImages;
this.ocrVidi = ocrVidi;
this.ocrMessage = ocrMessage;
this.streamName = streamName;
this.WMStartStateStr = wmStartStateStr;
this.refVolume = refVolume;
this.warningLimLo = 2 * errLimLo;
@ -127,6 +177,7 @@ namespace TBF.Rig.DataEntry.Uni
/// Readonly variables derived from arguments
isEnd = (wmStartStateStr != null);
mode = isEnd ? Tst.End : Tst.Start;
wmsCount = waterMeters.Count;
if (WMStartStateStr == null) WMStartStateStr = new string[wmsCount];
fixedErrorLimits = (errLimHi > errLimLo);
@ -136,6 +187,10 @@ namespace TBF.Rig.DataEntry.Uni
WMEndState = new double[wmsCount];
///
unitComboBox.Text = VolumeUnit.ToDescription();
for (Unit u = 0; u < Unit.Count; u++)
{
if (Units.IsVolume(u)) unitComboBox.Items.Add(u.ToDescription());
}
labels = new Label[wmsCount];
textBoxes = new TextBox[colItems.Count, wmsCount];
exclamations = new Label[wmsCount];
@ -145,7 +200,7 @@ namespace TBF.Rig.DataEntry.Uni
Font exclamationFont;
switch (sz)
{
case Sz.S:
case FontSz.S:
font = new Font("Verdana", 12, FontStyle.Regular);
//exclamationFont = new Font("Verdana", 24F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(238)));
exclamationFont = new Font("Verdana", 18, FontStyle.Bold);
@ -158,7 +213,7 @@ namespace TBF.Rig.DataEntry.Uni
break;
default:
case Sz.M:
case FontSz.M:
font = new Font("Verdana", 14, FontStyle.Regular);
exclamationFont = new Font("Verdana", 20, FontStyle.Bold);
meterHeight = 31; /// Height of a ComboBox control
@ -169,7 +224,7 @@ namespace TBF.Rig.DataEntry.Uni
checkBoxWid = 23;
break;
case Sz.L:
case FontSz.L:
font = new Font("Verdana", 18, FontStyle.Regular);
exclamationFont = new Font("Verdana", 24, FontStyle.Bold);
meterHeight = 37; /// Height of a ComboBox control
@ -188,11 +243,73 @@ namespace TBF.Rig.DataEntry.Uni
///
/// Table
///
int columnsLeft = 0;
if (isCameraPicture)
{
columnsLeft = PicSize + 10;
largeTextBox.Left += columnsLeft;
largeExclamationLabel.Left += columnsLeft;
/// Picture box
pictureBox1 = new PictureBox
{
Location = new System.Drawing.Point(4, 5),
Name = "pictureBox1",
Size = new System.Drawing.Size(PicSize, PicSize),
SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage,
TabIndex = tabIndex++,
TabStop = false,
};
pictureBox1.Click += new System.EventHandler(pictureBox1_Click);
Controls.Add(pictureBox1);
/// Rotate image button
var rotateImageButton = new Button
{
Font = new System.Drawing.Font("Arial", 27.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))),
Location = new System.Drawing.Point(24, PicSize + 31),
Name = "rotateImageButton",
Size = new System.Drawing.Size(50, 50),
TabIndex = tabIndex++,
Text = "↺",
UseVisualStyleBackColor = true,
};
rotateImageButton.Click += new System.EventHandler(rotateImageButton_Click);
Controls.Add(rotateImageButton);
/// Image processing progress bar
imageProcessingProgressBar = new ProgressBar
{
Location = new System.Drawing.Point(100, PicSize + 56),
Name = "imageProcessingProgressBar",
Size = new System.Drawing.Size(246, 23),
TabIndex = tabIndex++,
Visible = false,
};
Controls.Add(imageProcessingProgressBar);
/// Image processing progress label
imageProcessingProgressLabel = new Label
{
AutoSize = true,
Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))),
Location = new System.Drawing.Point(100, PicSize + 31),
Name = "imageProcessingProgressLabel",
Size = new System.Drawing.Size(249, 18),
TabIndex = tabIndex++,
Text = "Progress of image processing",
Visible = false,
};
Controls.Add(imageProcessingProgressLabel);
}
int columnsTop = hdrHeight;
for (int j = 0; j < linesCount; j++)
{
/// Captions
int capX = margin + j * (meterWidth + margin / 2) + labelWid + spacing;
int capX = columnsLeft + margin + j * (meterWidth + margin / 2) + labelWid + spacing;
int capY = columnsTop - meterHeight;
for (int k = 0; k < colItems.Count; k++)
{
@ -207,6 +324,7 @@ namespace TBF.Rig.DataEntry.Uni
Parent = this,
};
capX += colItems[k].Width + spacing;
Controls.Add(label);
}
/// Water meters
@ -215,7 +333,7 @@ namespace TBF.Rig.DataEntry.Uni
int wmPos0 = i + lineSize * j;
if (wmPos0 > wmsCount) continue;
int left = margin + j * (meterWidth + margin / 2);
int left = columnsLeft + margin + j * (meterWidth + margin / 2);
int top = columnsTop + i * (meterHeight + spacing);
var label = new Label
@ -230,7 +348,7 @@ namespace TBF.Rig.DataEntry.Uni
};
left += labelWid + spacing / 2;
labels[wmPos0] = label;
this.Controls.Add(label);
Controls.Add(label);
/// Columns
for (int k = 0; k < colItems.Count; k++)
@ -247,13 +365,15 @@ namespace TBF.Rig.DataEntry.Uni
Parent = this,
};
textBox.AcceptsTabChanged += new System.EventHandler(textBox_AcceptsTabChanged);
textBox.TextChanged += new System.EventHandler(textBox_TextChanged);
textBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(textBox_KeyPress);
textBox.MouseClick += new System.Windows.Forms.MouseEventHandler(textBox_MouseClick);
textBox.MouseDown += new System.Windows.Forms.MouseEventHandler(textBox_MouseDown);
left += ci.Width + spacing;
textBoxes[k, wmPos0] = textBox;
this.Controls.Add(textBox);
Controls.Add(textBox);
}
var exclamation = new Label
@ -268,7 +388,7 @@ namespace TBF.Rig.DataEntry.Uni
Visible = false,
};
exclamations[wmPos0] = exclamation;
this.Controls.Add(exclamation);
Controls.Add(exclamation);
}
}
@ -277,8 +397,8 @@ namespace TBF.Rig.DataEntry.Uni
///
Rectangle screenRectangle = this.RectangleToScreen(this.ClientRectangle);
int titleBarHeight = screenRectangle.Top - this.Top;
Size = new Size(Math.Max(meterWidth * linesCount + margin * (linesCount + 1), 1300),
titleBarHeight + columnsTop + lineSize * (meterHeight + spacing) + margin);
Size = new Size(columnsLeft + Math.Max(meterWidth * linesCount + margin * (linesCount + 1), 1040),
titleBarHeight + Math.Max(columnsTop + lineSize * (meterHeight + spacing) + margin, isCameraPicture ? 590 : 0));
Localize();
InitializeBoxes();
@ -286,6 +406,45 @@ namespace TBF.Rig.DataEntry.Uni
/// Set focus to the first enabled ComboBox
}
private void TestStartEndForm_Load(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(ocrMessage))
{
MessageBox.Show(ocrMessage, Strings.Warning, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
int imagesCount = ImagesToProcessCount();
log.WarnFormat("Images to process count = {0}", imagesCount);
///
if (imagesCount > 0 && ocrVidi != null)
{
log.WarnFormat("Starting image processing thread with OcrVidi={0} and OcrStream={1}", ocrVidi, streamName);
/// Delegate for a thread->form communication
ocrTextObtained = new OcrTextObtainedDelegate(OnOcrTextObtained);
/// Show and initalize the progress bar
imageProcessingProgressLabel.Visible = true;
imageProcessingProgressBar.Visible = true;
imageProcessingProgressBar.Minimum = 0;
imageProcessingProgressBar.Value = 0;
imageProcessingProgressBar.Maximum = imagesCount;
/// Start the image processing thread
imageProcessingThread = new Thread(new ThreadStart(ImageProcessingThread));
imageProcessingThread.Start();
}
}
private void TestStartEndForm_FormClosed(object sender, FormClosedEventArgs e)
{
if (imageProcessingThread != null && imageProcessingThread.IsAlive)
{
imageProcessingThread.Join(2000);
}
}
void Localize()
{
okButton.Text = Strings.OkBtnText;
@ -402,7 +561,136 @@ namespace TBF.Rig.DataEntry.Uni
}
}
private void okButton_Click(object sender, EventArgs eArgs)
int ImagesToProcessCount()
{
int count = 0;
/// Count the images
for (int i = 0; i < wmsCount; i++)
{
if ((mode == Tst.Start || mode == Tst.Both) &&
startStateColumn >= 0 && textBoxes[startStateColumn, i].Enabled &&
startImages != null && startImages.Length > i && !string.IsNullOrEmpty(startImages[i]))
{
count++;
}
if ((mode == Tst.End || mode == Tst.Both) &&
endStateColumn >= 0 && textBoxes[endStateColumn, i].Enabled &&
endImages != null && endImages.Length > i && !string.IsNullOrEmpty(endImages[i]))
{
count++;
}
}
return count;
}
void ImageProcessingThread()
{
double denominator; /// derived from PulsesPerLtr, passed to OcrVidi
string format; /// derived from PulsesPerLtr, passed to OcrVidi
Thread.Sleep(2000);
bool[] startImgProcessed = new bool[wmsCount];
bool[] endImgProcessed = new bool[wmsCount];
for (int attempt = 1; attempt <= 3; attempt++)
{
for (int i = 0; i < wmsCount; i++)
{
double pulsesPerLtr = (regReaders != null && regReaders.Length > i && regReaders[i] != null) ? regReaders[i].PulsesPerLtr : 1;
GetOcrParameters(pulsesPerLtr, out denominator, out format);
if ((mode == Tst.Start || mode == Tst.Both) &&
startStateColumn >= 0 && textBoxes[startStateColumn, i].Enabled &&
startImages != null && startImages.Length > i && !string.IsNullOrEmpty(startImages[i]))
{
if (!startImgProcessed[i])
{
try
{
/// Process a start image
var text = ocrVidi.Recognize(streamName, startImages[i], denominator, format); /// OCR
this.Invoke(ocrTextObtained, new object[] { i, false, text });
startImgProcessed[i] = true;
}
catch (Exception)
{
}
}
}
if ((mode == Tst.End || mode == Tst.Both) &&
endStateColumn >= 0 && textBoxes[endStateColumn, i].Enabled &&
endImages != null && endImages.Length > i && !string.IsNullOrEmpty(endImages[i]))
{
if (!endImgProcessed[i])
{
try
{
/// Process an end image
var text = ocrVidi.Recognize(streamName, endImages[i], denominator, format); /// OCR
this.Invoke(ocrTextObtained, new object[] { i, true, text });
endImgProcessed[i] = true;
}
catch (Exception)
{
}
}
}
}
}
}
void GetOcrParameters(double pulsesPerLtr, out double denominator, out string format)
{
if (pulsesPerLtr == 0.1)
{
denominator = 100;
format = "F2";
}
else if (pulsesPerLtr == 0.01)
{
denominator = 10;
format = "F1";
}
else if (pulsesPerLtr == 10)
{
denominator = 10000;
format = "F4";
}
else // if (pulsesPerLtr == 1)
{
denominator = 1000;
format = "F3";
}
}
public void OnOcrTextObtained(int ix, bool _isEnd, string text)
{
if (_isEnd)
{
if (endStateColumn>= 0 && textBoxes[endStateColumn, ix].Enabled)
{
textBoxes[endStateColumn, ix].Text = text;
LoadImage(null, Tst.End, ix);
}
}
else
{
if (startStateColumn >= 0 && textBoxes[startStateColumn, ix].Enabled)
{
textBoxes[endStateColumn, ix].Text = text;
LoadImage(null, Tst.Start, ix);
}
}
imageProcessingProgressBar.Value++;
}
private void okButton_Click(object sender, EventArgs eArgs)
{
UpdateWMsFromBoxes();
@ -452,11 +740,11 @@ namespace TBF.Rig.DataEntry.Uni
}
}
private void textBox_KeyPress(object sndr, KeyPressEventArgs e)
private void textBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (!isHandlersEnabled) return;
string[] kj = (sndr as TextBox).Name.Split(new char[] { '~' });
string[] kj = (sender as TextBox).Name.Split(new char[] { '~' });
int k = int.Parse(kj[0]);
int j = int.Parse(kj[1]);
@ -468,7 +756,7 @@ namespace TBF.Rig.DataEntry.Uni
{
if (e.KeyChar == formCloseKeys[ix])
{
okButton_Click(sndr, e);
okButton_Click(sender, e);
return;
}
}
@ -483,24 +771,30 @@ namespace TBF.Rig.DataEntry.Uni
}
else
{
textBoxes[k, j].Focus();
largeTextBox.Text = string.Format("{0}: {1}", j + 1, textBoxes[k, j].Text);
largeExclamationLabel.Visible = false;
if (k == startStateColumn || k == endStateColumn)
{
LoadImage(sender, (k == startStateColumn) ? Tst.Start : Tst.End, j);
}
textBoxes[k, j].Focus();
}
}
}
/// Handle mouse clicks so that the large text box and the large exclamation mark are updated
private void textBox_MouseClick(object sndr, MouseEventArgs e)
private void textBox_MouseClick(object sender, MouseEventArgs e)
{
textBox_TextChanged(sndr, e);
textBox_TextChanged(sender, e);
}
private void textBox_TextChanged(object sndr, EventArgs e)
private void textBox_TextChanged(object sender, EventArgs e)
{
if (!isHandlersEnabled) return;
string[] kj = (sndr as TextBox).Name.Split(new char[] { '~' });
string[] kj = (sender as TextBox).Name.Split(new char[] { '~' });
int k = int.Parse(kj[0]);
int j = int.Parse(kj[1]);
@ -531,6 +825,24 @@ namespace TBF.Rig.DataEntry.Uni
}
}
private void textBox_MouseDown(object sender, MouseEventArgs e)
{
textBox_AcceptsTabChanged(sender, e);
}
private void textBox_AcceptsTabChanged(object sender, EventArgs e)
{
if (!isHandlersEnabled) return;
string[] kj = (sender as TextBox).Name.Split(new char[] { '~' });
int k = int.Parse(kj[0]);
int j = int.Parse(kj[1]);
if (k != startStateColumn && k != endStateColumn) return;
LoadImage(sender, (k == startStateColumn) ? Tst.Start : Tst.End, j);
}
/// <summary>
/// Find the next enabled combo box, update k and i.
@ -578,6 +890,189 @@ namespace TBF.Rig.DataEntry.Uni
return pastTheEndOfArray;
}
/// <summary>
/// Loads appropriate image into pictureBox1.Image
/// Handles mouse clicks and Tab-changes inside text boxes.
/// </summary>
/// <param name="startOrEnd">Tst.Start or Tst.End</param>
/// <param name="wmNr0">0-based WM position</param>
void LoadImage(object sender, Tst startOrEnd, int wmNr0)
{
string imageFileName;
if (startOrEnd == Tst.Start && startImages[wmNr0] != null)
imageFileName = startImages[wmNr0];
else if (startOrEnd == Tst.End && endImages[wmNr0] != null)
imageFileName = endImages[wmNr0];
else
imageFileName = string.Empty;
if (imageFileName == lastImageName)
{
return;
}
lastImageName = imageFileName;
lastWmNr1 = wmNr0 + 1;
if (string.IsNullOrEmpty(imageFileName) || !File.Exists(imageFileName))
{
lastImage = null;
}
else
{
using (Bitmap tempBmp = Image.FromFile(imageFileName) as Bitmap)
{
Rectangle rect;
if (tempBmp.Height < tempBmp.Width)
{
int hght = tempBmp.Height;
int leftMargin = (tempBmp.Width - hght) / 2;
rect = new Rectangle(leftMargin, 0, hght, hght);
}
else
{
int hght = tempBmp.Height;
int wdth = tempBmp.Width;
int margin = (hght - wdth) / 2;
rect = new Rectangle(0, margin, wdth, wdth);
}
//int hght = tempBmp.Height;
//int leftMargin = (tempBmp.Width - hght) / 2;
//lastImage = new Bitmap(tempBmp.Clone(new Rectangle(leftMargin, 0, hght, hght), tempBmp.PixelFormat));
lastImage = new Bitmap(tempBmp.Clone(rect, tempBmp.PixelFormat));
if (isZoomed[wmNr0b])
{
zoomedImage = MakeZoomedImage(lastImage, zoomCenterLoc[wmNr0b]);
}
}
}
ShowImage();
}
/// <summary>
/// Left click = Zoom, Right click = Unzoom
/// </summary>
private void pictureBox1_Click(object sender, EventArgs e)
{
if (lastImage == null) return;
MouseEventArgs me = (MouseEventArgs)e;
if (me.Button == MouseButtons.Left && !isZoomed[wmNr0b])
{
switch (imageRotation)
{
case Rotation.R0:
zoomCenterLoc[wmNr0b] = me.Location;
break;
case Rotation.R90:
zoomCenterLoc[wmNr0b].X = pictureBox1.Size.Height - me.Location.Y - 1;
zoomCenterLoc[wmNr0b].Y = me.Location.X;
break;
case Rotation.R180:
zoomCenterLoc[wmNr0b].X = pictureBox1.Size.Width - me.Location.X - 1;
zoomCenterLoc[wmNr0b].Y = pictureBox1.Size.Height - me.Location.Y - 1;
break;
case Rotation.R270:
zoomCenterLoc[wmNr0b].X = me.Location.Y;
zoomCenterLoc[wmNr0b].Y = pictureBox1.Size.Width - me.Location.X - 1;
break;
}
zoomedImage = MakeZoomedImage(lastImage, zoomCenterLoc[wmNr0b]);
isZoomed[wmNr0b] = true;
ShowImage();
}
else if (me.Button == MouseButtons.Right)
{
isZoomed[wmNr0b] = false;
ShowImage();
}
}
private void rotateImageButton_Click(object sender, EventArgs e)
{
if (lastImage == null) return;
if (++imageRotation == Rotation.Count)
{
imageRotation = Rotation.R0;
}
ShowImage();
}
Bitmap MakeZoomedImage(Bitmap oriImage, Point centerLoc)
{
float picBoxW = (float)pictureBox1.Size.Width;
float picBoxH = (float)pictureBox1.Size.Height;
float newRelX = Math.Max(0, Math.Min(centerLoc.X / picBoxW - 0.25f, 0.5f));
float newRelY = Math.Max(0, Math.Min(centerLoc.Y / picBoxH - 0.25f, 0.5f));
Rectangle newRect = new Rectangle((int)(newRelX * oriImage.Width),
(int)(newRelY * oriImage.Height),
oriImage.Width / 2,
oriImage.Height / 2); /// image resolution, 1280 x 960
return lastImage.Clone(newRect, oriImage.PixelFormat);
}
///
/// Used by ShowImage()
///
Brush lightBrush = new SolidBrush(Color.LightGreen);
Brush darkBrush = new SolidBrush(Color.Green);
Font largeFont = new Font("arial", 24.0F, FontStyle.Bold); /// normal image
Font smallFont = new Font("arial", 12.0F, FontStyle.Bold); /// zoomed image
/// <summary>
/// Show selected image in the picture box.
/// lastWmNr1, lastImage, zoomedImage, isZoomed and imageRotation are used.
/// </summary>
void ShowImage()
{
if (lastImage == null)
{
pictureBox1.Image = new Bitmap(TBF.Properties.Resources.Empty);
return;
}
Bitmap tempBmp = isZoomed[wmNr0b]
? new Bitmap(zoomedImage.Clone(new Rectangle(0, 0, zoomedImage.Width, zoomedImage.Height), zoomedImage.PixelFormat))
: new Bitmap(lastImage.Clone(new Rectangle(0, 0, lastImage.Width, lastImage.Height), lastImage.PixelFormat));
switch (imageRotation)
{
case Rotation.R90: tempBmp.RotateFlip(RotateFlipType.Rotate270FlipNone); break;
case Rotation.R180: tempBmp.RotateFlip(RotateFlipType.Rotate180FlipNone); break;
case Rotation.R270: tempBmp.RotateFlip(RotateFlipType.Rotate90FlipNone); break;
}
/// Write water meter number to the bitmap
using (var grph = Graphics.FromImage(tempBmp))
{
Font font = isZoomed[wmNr0b] ? smallFont : largeFont;
int margin = isZoomed[wmNr0b] ? 1 : 2;
int pixelsCount = 0;
int brightness = 0;
for (int x = margin; x <= 8 * margin; x += margin)
{
for (int y = margin; y <= 8 * margin; y += margin)
{
brightness += (int)tempBmp.GetPixel(x, y).G;
pixelsCount++;
}
}
brightness /= pixelsCount;
Brush brush = (brightness > 160) ? darkBrush : lightBrush;
grph.DrawString(lastWmNr1.ToString(), font, brush, margin, margin);
}
pictureBox1.Image = tempBmp;
}
#region Forced close handling
public void StartForceCloseHandler()

View File

@ -42,7 +42,7 @@ namespace TBF.Rig.DataEntry.Uni
this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.okButton.Font = new System.Drawing.Font("Verdana", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.okButton.ForeColor = System.Drawing.Color.Black;
this.okButton.Location = new System.Drawing.Point(1120, 29);
this.okButton.Location = new System.Drawing.Point(860, 29);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(123, 63);
this.okButton.TabIndex = 100;
@ -55,7 +55,7 @@ namespace TBF.Rig.DataEntry.Uni
this.largeTextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.largeTextBox.Location = new System.Drawing.Point(35, 29);
this.largeTextBox.Name = "largeTextBox";
this.largeTextBox.Size = new System.Drawing.Size(849, 80);
this.largeTextBox.Size = new System.Drawing.Size(600, 80);
this.largeTextBox.TabIndex = 101;
//
// largeExclamationLabel
@ -63,7 +63,7 @@ namespace TBF.Rig.DataEntry.Uni
this.largeExclamationLabel.AutoSize = true;
this.largeExclamationLabel.Font = new System.Drawing.Font("Verdana", 48F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.largeExclamationLabel.ForeColor = System.Drawing.Color.Red;
this.largeExclamationLabel.Location = new System.Drawing.Point(890, 28);
this.largeExclamationLabel.Location = new System.Drawing.Point(640, 28);
this.largeExclamationLabel.Name = "largeExclamationLabel";
this.largeExclamationLabel.Size = new System.Drawing.Size(59, 78);
this.largeExclamationLabel.TabIndex = 102;
@ -75,7 +75,7 @@ namespace TBF.Rig.DataEntry.Uni
this.unitComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.unitComboBox.Font = new System.Drawing.Font("Verdana", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.unitComboBox.FormattingEnabled = true;
this.unitComboBox.Location = new System.Drawing.Point(962, 46);
this.unitComboBox.Location = new System.Drawing.Point(702, 46);
this.unitComboBox.Name = "unitComboBox";
this.unitComboBox.Size = new System.Drawing.Size(123, 31);
this.unitComboBox.TabIndex = 103;
@ -87,7 +87,7 @@ namespace TBF.Rig.DataEntry.Uni
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.DarkGray;
this.ClientSize = new System.Drawing.Size(1284, 676);
this.ClientSize = new System.Drawing.Size(1024, 676);
this.Controls.Add(this.unitComboBox);
this.Controls.Add(this.largeExclamationLabel);
this.Controls.Add(this.largeTextBox);
@ -98,6 +98,8 @@ namespace TBF.Rig.DataEntry.Uni
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "End States";
this.TopMost = true;
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.TestStartEndForm_FormClosed);
this.Load += new System.EventHandler(this.TestStartEndForm_Load);
this.ResumeLayout(false);
this.PerformLayout();

View File

@ -324,6 +324,7 @@
<Compile Include="Rig\DataEntry\iPerl\TestStartEndForm.designer.cs">
<DependentUpon>TestStartEndForm.cs</DependentUpon>
</Compile>
<Compile Include="Rig\DataEntry\OcrVidi.cs" />
<Compile Include="Rig\DataEntry\S620\BarcodeReceivedEventArgs.cs" />
<Compile Include="Rig\DataEntry\S620\BodySerNrResult.cs" />
<Compile Include="Rig\DataEntry\S620\CheckItems\Barcode.cs">
@ -526,7 +527,6 @@
</Compile>
<Compile Include="Rig\DataEntry\StandardCamera\EntryForm.cs" />
<Compile Include="Rig\DataEntry\StandardCamera\Factory.cs" />
<Compile Include="Rig\DataEntry\StandardCamera\OcrVidi.cs" />
<Compile Include="Rig\DataEntry\StandardCamera\ProcParams.cs" />
<Compile Include="Rig\DataEntry\StandardCamera\TestStartEndForm.cs">
<SubType>Form</SubType>
@ -546,6 +546,7 @@
<Compile Include="Rig\DataEntry\Uni\EntryFormNoStartEnd.cs" />
<Compile Include="Rig\DataEntry\Uni\Factory.cs" />
<Compile Include="Rig\DataEntry\Uni\FactoryNoStartEnd.cs" />
<Compile Include="Rig\DataEntry\Uni\ProcParams.cs" />
<Compile Include="Rig\DataEntry\Uni\TestStartEndForm.cs">
<SubType>Form</SubType>
</Compile>