/// /// Copyright (c) 2017 Sensus Metering Systems /// using System; using System.Collections.Generic; using System.Text; using log4net; using Config.Entities; using TBF.BenchControl.GenericDevices; using System.Windows.Forms; namespace TBF.BenchControl.Network.Camera.Display { public class Display : ComponentBase, IOperation, ICameraDisplay { private static readonly ILog log = LogManager.GetLogger(typeof(Display)); public override string ToString() { return string.Format("{0}({1})", this.GetType().Namespace.Substring(17), Cfg.ToString(1)); } public readonly DisplayCfg DisplayCfg; /// public Display() { } /// public Display(Generic.IComponentCfg cfg, IList components) : base(cfg) { DisplayCfg = cfg as DisplayCfg; log.Debug(this.ToString()); } public bool[] SelectedImages { get { return selectedImages; } } bool[] selectedImages; public enum CurrentOp { None, StaticImage, LiveStream, } CurrentOp currentOp; DialogResult result; string title; string[] imageFileNames; DisplayForm displayForm; /// delegate void DisplayFormDlgt(Display myRef); /// void OpenStaticImageDisplay(Display myRef) { myRef.displayForm = new DisplayForm(imageFileNames, title); displayForm.Show(); } /// void OpenLiveStreamDisplay(Display myRef) { myRef.displayForm = new DisplayForm(imageFileNames, title); displayForm.Show(); } /// Reference to the operation public IOperation ShowStaticImageOp(string[] imageFileNames, string title) { if (currentOp != CurrentOp.None) throw new Exception("Sequence error"); this.imageFileNames = imageFileNames; this.title = title; currentOp = CurrentOp.StaticImage; return this; } /// Reference to the operation public IOperation ShowLiveStreamOp(string[] imageFileNames, string title) { if (currentOp != CurrentOp.None) throw new Exception("Sequence error"); this.imageFileNames = imageFileNames; this.title = title; currentOp = CurrentOp.LiveStream; return this; } /// Start this operation public void Start() { result = DialogResult.None; switch (currentOp) { case CurrentOp.StaticImage: Program.MainWnd.Invoke(new DisplayFormDlgt(OpenStaticImageDisplay), this); break; case CurrentOp.LiveStream: Program.MainWnd.Invoke(new DisplayFormDlgt(OpenLiveStreamDisplay), this); break; } } /// Run this operation /// Event.None public Event Run() { if (!displayForm.Completed) { return Event.ModelessFormIsOpen; } if (result == DialogResult.None) { /// Save the result (once) selectedImages = displayForm.SelectedImages; result = displayForm.Result; displayForm = null; } if (result == DialogResult.OK) return Event.OK; else if (result == DialogResult.Retry) return Event.Retry; else if (result == DialogResult.Abort) return Event.Abort; else return Event.None; /// Should never happen } /// Stop this operation public void Stop() { if (displayForm != null) { displayForm.CloseForm(this, null); displayForm = null; } currentOp = CurrentOp.None; } } }