From 699bbf402e9d6333d4dcb0c75e6d32e4386fd6dc Mon Sep 17 00:00:00 2001
From: xcd <834800634@qq.com>
Date: 星期日, 28 六月 2020 18:59:26 +0800
Subject: [PATCH] 主体流程完成

---
 src/Bro.M071.Process/M071Models.cs |  205 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 193 insertions(+), 12 deletions(-)

diff --git a/src/Bro.M071.Process/M071Models.cs b/src/Bro.M071.Process/M071Models.cs
index 16af13a..be596b7 100644
--- a/src/Bro.M071.Process/M071Models.cs
+++ b/src/Bro.M071.Process/M071Models.cs
@@ -3,6 +3,7 @@
 using Bro.Common.Helper;
 using Bro.Common.Interface;
 using Bro.Common.Model;
+using Newtonsoft.Json;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -34,6 +35,19 @@
         }
     }
 
+    public class MeasureType : Spec
+    {
+        [Category("妫�娴嬬被鍨�")]
+        [Description("妫�娴嬬被鍨�")]
+        [DisplayName("妫�娴嬬被鍨�")]
+        public override string Code { get; set; }
+
+        [Category("妫�娴嬬畻娉�")]
+        [Description("妫�娴嬬畻娉曡矾寰�")]
+        [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))]
+        public string AlgorithemPath { get; set; }
+    }
+
     public class KeyResult : IComplexDisplay
     {
         [Browsable(false)]
@@ -59,7 +73,7 @@
     {
         public string GetDisplayText()
         {
-            return Name + " " + string.Join(" ", Destination.Select(u => u.GetDisplayText())) + " " + CameraOp.GetDisplayText();
+            return (IsEnabled ? "" : "绂佺敤 ") + Name + " " + string.Join(" ", Destination.Select(u => u.GetDisplayText())) + " " + CameraOp.GetDisplayText();
         }
 
         public List<string> GetHalconToolPathList()
@@ -81,6 +95,10 @@
         [Description("鎷嶇収鐐瑰悕绉�")]
         public string Name { get; set; }
 
+        [Category("鍚敤璁剧疆")]
+        [Description("true锛氬惎鐢� false锛氱鐢�")]
+        public bool IsEnabled { get; set; } = true;
+
         [Category("璁惧閰嶇疆")]
         [Description("杩愬姩璁惧")]
         [TypeConverter(typeof(DeviceSelectorConverter<IMotion>))]
@@ -101,6 +119,7 @@
 
     public class KeyUnit : IComplexDisplay, IHalconToolPath
     {
+        #region 閰嶇疆
         private string key = "";
         [Category("閿悕閰嶇疆")]
         [Description("鍗曢敭妫�娴嬮敭鍚�")]
@@ -118,24 +137,36 @@
         [Description("鍒悕")]
         public string AlignName { get; set; }
 
+        [Category("鍚敤璁剧疆")]
+        [Description("true锛氬惎鐢� false锛氱鐢�")]
+        public bool IsEnabled { get; set; } = true;
+
         [Category("鍥惧儚鏉ユ簮")]
         [Description("鎷嶇収鐐逛綅")]
         [TypeConverter(typeof(SnapshotPointConverter))]
-        public string SnapshotPoint { get; set; }
+        public string SnapshotPointId { get; set; }
 
         [Category("鍥惧儚鏉ユ簮")]
-        [Description("鎷嶇収鐐逛綅鑾峰彇鐨勫浘鐗囩储寮�")]
-        public int ImageIndex { get; set; } = 0;
+        [Description("鎷嶇収鐐逛綅鑾峰彇鐨勫浘鐗囧簭鍙凤紝浠�1寮�濮�")]
+        public int ImageSeq { get; set; } = 1;
 
         [Category("绠楁硶閰嶇疆")]
         [Description("鍗曢敭妫�娴嬮厤缃畻娉曠被鍨�")]
         [TypeConverter(typeof(KeyAlgorithemConverter))]
-        public string KeyAlgorithem { get; set; }
+        public string KeyAlgorithemId { get; set; }
 
         [Category("绠楁硶閰嶇疆")]
         [Description("鍗曢敭妫�娴嬮厤缃粨鏋滅被鍨�")]
         [TypeConverter(typeof(KeyResultConverter))]
-        public string KeyResult { get; set; }
+        public string KeyResultId { get; set; }
+        #endregion
+
+        #region 妫�娴嬬浉鍏冲瓧娈�
+        public Dictionary<string, double> KeyValues = null;
+        //public SnapshotPoint SnapshotPoint = null;
+        public string KeyAlgorithemPath = "";
+        public List<string> KeyResultList = null;
+        #endregion
 
         public string GetDisplayText()
         {
@@ -144,15 +175,68 @@
 
         public List<string> GetHalconToolPathList()
         {
-            return null;
+            using (var scope = GlobalVar.Container.BeginLifetimeScope())
+            {
+                IProcessConfig iConfig = scope.Resolve<IProcessConfig>();
+
+                if (iConfig is M071Config config)
+                {
+                    var algo = config.KeyAlgorithemCollection.FirstOrDefault(u => u.Id == KeyAlgorithemId);
+                    if (algo != null)
+                    {
+                        return new List<string>() { algo.AlgorithemPath };
+                    }
+                }
+            }
+
+            return new List<string>();
         }
     }
 
-    public class MeasurementUint : IComplexDisplay
+    public class ProductionMeasurement : INotifyPropertyChanged, IDisposable
     {
+        public string Barcode { get; set; }
+
+        public List<MeasurementUint> Measurements { get; set; } = new List<MeasurementUint>();
+
+        public event PropertyChangedEventHandler PropertyChanged;
+
+        public void Dispose()
+        {
+            Barcode = null;
+
+            Measurements?.ForEach(m => m?.Dispose());
+            Measurements = null;
+            GC.Collect();
+        }
+
+        public void InitialMeasurementsPropertyChanged()
+        {
+            Measurements.ForEach(m => m.PropertyChanged += M_PropertyChanged);
+        }
+
+        private object pChangedLock = new object();
+        private void M_PropertyChanged(object sender, PropertyChangedEventArgs e)
+        {
+            lock (pChangedLock)
+            {
+                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Measurements"));
+            }
+        }
+    }
+
+    public class MeasurementUint : IComplexDisplay, INotifyPropertyChanged, IDisposable
+    {
+        public string Id = Guid.NewGuid().ToString();
+
+        #region 閰嶇疆
         [Category("鍚嶇О")]
         [Description("鍚嶇О")]
         public string Name { get; set; } = "";
+
+        [Category("鍚敤璁剧疆")]
+        [Description("true锛氬惎鐢� false锛氱鐢�")]
+        public bool IsEnabled { get; set; } = true;
 
         [Category("绠楁硶閰嶇疆")]
         [Description("妫�娴嬪拰鏍囧噯绫诲瀷")]
@@ -164,24 +248,51 @@
         [TypeConverter(typeof(ComplexObjectConvert))]
         [Editor(typeof(ComplexCollectionEditor<KeyUnitBind>), typeof(UITypeEditor))]
         public List<KeyUnitBind> KeyUnitCollection { get; set; } = new List<KeyUnitBind>();
+        #endregion
 
+        #region 鏄剧ず
         [Browsable(false)]
-        public RectangleF DisplayLocation { get; set; } = new RectangleF();
+        public Rectangle DisplayLocation { get; set; } = new Rectangle();
+        #endregion
+
+        #region 妫�娴嬬粨鏋�
+        [Browsable(false)]
+        public MeasureType Spec { get; set; } = null;
+        #endregion
+
+        public bool IsUpdated = false;
+        public event PropertyChangedEventHandler PropertyChanged;
+
+        public void Dispose()
+        {
+            KeyUnitCollection?.ForEach(k => k?.Dispose());
+            KeyUnitCollection = null;
+        }
 
         public string GetDisplayText()
         {
             if (string.IsNullOrWhiteSpace(Name))
             {
-                return string.Join("-", KeyUnitCollection.Select(u => u.GetDisplayText())) + "-" + MeasureType.ToString();
+                return (IsEnabled ? "" : "绂佺敤 ") + string.Join("-", KeyUnitCollection.Select(u => u.GetDisplayText())) + "-" + MeasureType.ToString();
             }
             else
             {
-                return Name;
+                return (IsEnabled ? "" : "绂佺敤 ") + Name;
             }
+        }
+
+        public void InitialKeyUnitMeasureChanged()
+        {
+            KeyUnitCollection.ForEach(k => k.PropertyChanged += K_PropertyChanged);
+        }
+
+        private void K_PropertyChanged(object sender, PropertyChangedEventArgs e)
+        {
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("KeyUnitCollection"));
         }
     }
 
-    public class KeyUnitBind : IComplexDisplay
+    public class KeyUnitBind : IComplexDisplay, INotifyPropertyChanged, IDisposable
     {
         [Category("鍗曢敭閰嶇疆")]
         [Description("鍗曢敭閰嶇疆")]
@@ -193,6 +304,26 @@
         [TypeConverter(typeof(KeyUnitResultConverter))]
         public string KeyResult { get; set; } = "";
 
+        //[Browsable(false)]
+        //public NoticedDictionary<string, double?> MeasureValueDict { get; set; } = new NoticedDictionary<string, double?>();
+
+        [Browsable(false)]
+        public Dictionary<string, double?> MeasureValueDict { get; set; } = new Dictionary<string, double?>();
+
+        public event PropertyChangedEventHandler PropertyChanged;
+
+        //public void InitialMeasureValueDictPropertyChanged()
+        //{
+        //    MeasureValueDict.PropertyChanged += MeasureValueDict_PropertyChanged;
+        //}
+
+        //private void MeasureValueDict_PropertyChanged(object sender, PropertyChangedEventArgs e)
+        //{
+        //    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("MeasureValueDict"));
+        //}
+
+        public bool? IsDone = null;
+
         public string GetDisplayText()
         {
             string msg = Key;
@@ -201,5 +332,55 @@
 
             return msg;
         }
+
+        public void Dispose()
+        {
+            MeasureValueDict = null;
+        }
+
+        object valueDictLock = new object();
+        public void FillKeyValues(Dictionary<string, double> valuePairs)
+        {
+            lock (valueDictLock)
+            {
+                if (valuePairs == null || valuePairs.Count == 0)
+                {
+                    IsDone = false;
+                }
+
+                foreach (KeyValuePair<string, double> pair in valuePairs)
+                {
+                    if (MeasureValueDict.ContainsKey(pair.Key))
+                    {
+                        MeasureValueDict[pair.Key] = pair.Value;
+                    }
+                }
+
+                if (MeasureValueDict.Values.All(u => u != null))
+                {
+                    IsDone = true;
+                }
+
+                if (IsDone != null)
+                {
+                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsDone"));
+                }
+            }
+        }
     }
+
+    //public class NoticedDictionary<T1, T2> : Dictionary<T1, T2>, INotifyPropertyChanged
+    //{
+    //    public event PropertyChangedEventHandler PropertyChanged;
+
+    //    public new T2 this[T1 index]
+    //    {
+    //        get => base[index];
+    //        set
+    //        {
+    //            base[index] = value;
+    //            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Index"));
+    //        }
+    //    }
+    //}
 }

--
Gitblit v1.8.0