using System; using System.IO; using System.Text; using System.Xml.Serialization; using TBF.BenchControl.Generic; using TBF.Resources; namespace TBF.BenchControl.Cameras.CameraRoi { public class RoiProcedureParams : ProcedureParamsBase, IParamsProvider, IProcedureParams { public int IRoiX; public int IRoiY; public int IRoiW; public int IRoiH; public float GradPerLtr; public bool CCW; /// Clockwise = false, Counter clockwise = true public float ORoiW; public float ORoiH; public float CX; public float CY; public float R1; public float R2; public float R3; public float Ang1; public float Ang2; public float AngStep; public int MinMvmt; public int MaxMvmt; public int SequenceLen; public int SequenceTiming; public int BackgroundCorr; public float BrightnessRoi; public override void InitializeAll() { IRoiX = 60; IRoiY = 1; IRoiW = 520; IRoiH = 478; GradPerLtr = 40; CCW = true; ORoiW = 64.0f; ORoiH = 64.0f; CX = 31.0f; CY = 31.0f; R1 = 21.0f; R2 = 31.0f; R3 = 0; Ang1 = 0; Ang2 = 400.0f; AngStep = 40.0f; MinMvmt = 0; MaxMvmt = 0; SequenceLen = 8; SequenceTiming = 1; BackgroundCorr = 0; BrightnessRoi = 1.0f; } string[] paramNames = new string[] { "IRoiX", "IRoiY", "IRoiW", "IRoiH", "Grad per liter", "CW/CCW", "ORoiW", "ORoiH", "CX", "CY", "R1", "R2", "R3", "Ang1", "Ang2", "AngStep", "Min.Mvmt.", "Max.Mvmt.", "Det.Seq.Len", "Det.Seq.Timing", "Background", "Brightness", }; 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 IRoiX.ToString(); case 1: return IRoiY.ToString(); case 2: return IRoiW.ToString(); case 3: return IRoiH.ToString(); case 4: return GradPerLtr.ToString(); case 5: return (CCW ? "ccw" : "cw"); case 6: return ORoiW.ToString(); case 7: return ORoiH.ToString(); case 8: return CX.ToString(); case 9: return CY.ToString(); case 10: return R1.ToString(); case 11: return R2.ToString(); case 12: return R3.ToString(); case 13: return Ang1.ToString(); case 14: return Ang2.ToString(); case 15: return AngStep.ToString(); case 16: return MinMvmt.ToString(); case 17: return MaxMvmt.ToString(); case 18: return SequenceLen.ToString(); case 19: return SequenceTiming.ToString(); case 20: return BackgroundCorr.ToString(); case 21: return ((int)(100.0f * BrightnessRoi)).ToString(); default: return string.Empty; } } public void UpdateParam(int i, string strValue) { switch (i) { case 0: IRoiX = int.Parse(strValue); return; case 1: IRoiY = int.Parse(strValue); return; case 2: IRoiW = int.Parse(strValue); return; case 3: IRoiH = int.Parse(strValue); return; case 4: GradPerLtr = Utils.ParseUFloat(strValue); return; case 5: CCW = strValue.ToLower().Equals("ccw"); return; case 6: ORoiW = Utils.ParseUFloat(strValue); return; case 7: ORoiH = Utils.ParseUFloat(strValue); return; case 8: CX = Utils.ParseUFloat(strValue); return; case 9: CY = Utils.ParseUFloat(strValue); return; case 10: R1 = Utils.ParseUFloat(strValue); return; case 11: R2 = Utils.ParseUFloat(strValue); return; case 12: R3 = Utils.ParseSFloat(strValue); return; case 13: Ang1 = Utils.ParseSFloat(strValue); return; case 14: Ang2 = Utils.ParseSFloat(strValue); return; case 15: AngStep = Utils.ParseUFloat(strValue); return; case 16: MinMvmt = int.Parse(strValue); return; case 17: MaxMvmt = int.Parse(strValue); return; case 18: SequenceLen = int.Parse(strValue); return; case 19: SequenceTiming = int.Parse(strValue); return; case 20: BackgroundCorr = int.Parse(strValue); return; case 21: BrightnessRoi = ((float)int.Parse(strValue) / 100.0f); return; default: return; } } /// /// Parses the text in the control to verify whether it represents a valid parameter. /// /// Parameter nr. /// String to be verified /// Message to be shown when verification fails /// 'true' if parameter string is valid, 'false' otherwise public bool ValidateParam(int i, string strValue, out string message) { message = string.Empty; int iDummy; float dummy; switch (i) { case 0: case 1: case 2: case 3: case 16: case 17: case 18: case 19: case 20: if (int.TryParse(strValue, out iDummy)) return true; break; case 4: case 6: case 7: case 8: case 9: case 10: case 11: case 15: case 21: if (Utils.TryParseUFloat(strValue, out dummy)) return true; break; case 12: case 13: case 14: if (Utils.TryParseSFloat(strValue, out dummy)) return true; break; case 5: if (strValue.ToLower().Equals("cw") || strValue.ToLower().Equals("ccw")) return true; break; default: message = "Invalid index"; return false; } message = ParamName(i) + " is invalid"; return false; } public override void UpdateProcedureParams(Entities.ComponentProcedure dbEntity) { if (dbEntity == null) return; try { RoiProcedureParams tmp = (RoiProcedureParams)(new XmlSerializer(typeof(RoiProcedureParams))) .Deserialize(new StringReader(dbEntity.Parameters)); procedureParamsEntity = dbEntity; componentName = dbEntity.CmpntName; procedure = dbEntity.Procedure; IRoiX = tmp.IRoiX; IRoiY = tmp.IRoiY; IRoiW = tmp.IRoiW; IRoiH = tmp.IRoiH; GradPerLtr = tmp.GradPerLtr; CCW = tmp.CCW; ORoiW = tmp.ORoiW; ORoiH = tmp.ORoiH; CX = tmp.CX; CY = tmp.CY; R1 = tmp.R1; R2 = tmp.R2; R3 = tmp.R3; Ang1 = tmp.Ang1; Ang2 = tmp.Ang2; AngStep = tmp.AngStep; MinMvmt = tmp.MinMvmt; MaxMvmt = tmp.MaxMvmt; SequenceLen = tmp.SequenceLen; SequenceTiming = tmp.SequenceTiming; BackgroundCorr = tmp.BackgroundCorr; BrightnessRoi = tmp.BrightnessRoi; } catch { } } public RoiProcedureParams() { } public RoiProcedureParams(Entities.ComponentProcedure procedureParamsEntity, string componentName, Entities.Procedure procedure) { this.procedureParamsEntity = procedureParamsEntity; this.componentName = componentName; this.procedure = procedure; } } }