From 96b6869bb20677f9b945f67c014a9b992ee05ac4 Mon Sep 17 00:00:00 2001
From: patrick.xu <patrick.xu@broconcentric.com>
Date: 星期三, 28 四月 2021 11:40:01 +0800
Subject: [PATCH] 1. 添加离线测试功能 2. 单键分开测量修改赋值和释放时判断

---
 src/Bro.M071.Process/M071Converters.cs          |    9 ++
 src/Bro.M071.Process/M071Process_OfflineTest.cs |  129 ++++++++++++++++++++++++++++++++
 src/Bro.M071.Process/M071Process.cs             |   37 ++++++---
 src/Bro.M071.Process/Bro.M071.Process.csproj    |    1 
 src/Bro.M071.Process/M071Config.cs              |    5 +
 src/Bro.Common.Device/DeviceBase/CameraBase.cs  |    2 
 src/Bro.Common.Model/Model/LaserScanParam.cs    |   15 +++
 7 files changed, 182 insertions(+), 16 deletions(-)

diff --git a/src/Bro.Common.Device/DeviceBase/CameraBase.cs b/src/Bro.Common.Device/DeviceBase/CameraBase.cs
index d96dc0d..6a5accc 100644
--- a/src/Bro.Common.Device/DeviceBase/CameraBase.cs
+++ b/src/Bro.Common.Device/DeviceBase/CameraBase.cs
@@ -785,7 +785,7 @@
         [Category("鍥剧墖淇濆瓨")]
         [Description("鏄惁淇濆瓨鍘熷鍥剧墖")]
         [DisplayName("淇濆瓨鍘熷鍥剧墖")]
-        public bool IsSaveOriginImage { get; set; } = true;
+        public bool IsSaveOriginImage { get; set; } = false;
 
         [Category("鍥剧墖淇濆瓨")]
         [Description("鍥剧墖淇濆瓨鏍煎紡")]
diff --git a/src/Bro.Common.Model/Model/LaserScanParam.cs b/src/Bro.Common.Model/Model/LaserScanParam.cs
index a7eb899..8c42409 100644
--- a/src/Bro.Common.Model/Model/LaserScanParam.cs
+++ b/src/Bro.Common.Model/Model/LaserScanParam.cs
@@ -1,4 +1,5 @@
-锘縰sing System;
+锘縰sing Bro.Common.Helper;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -6,7 +7,7 @@
 
 namespace Bro.Common.Model
 {
-    public class LaserScanParam
+    public class LaserScanParam : IComplexDisplay
     {
         public int Resolution_X { get; set; }
         public int Resolution_Y { get; set; }
@@ -17,5 +18,15 @@
         public int Offset_Z { get; set; }
 
         public int Angle_Z { get; set; }
+
+        public override string ToString()
+        {
+            return GetDisplayText();
+        }
+
+        public string GetDisplayText()
+        {
+            return $"Resolution:{Resolution_X},{Resolution_Y},{Resolution_Z}; Offset:{Offset_X},{Offset_Y},{Offset_Z}; Angel_Z:{Angle_Z}";
+        }
     }
 }
diff --git a/src/Bro.M071.Process/Bro.M071.Process.csproj b/src/Bro.M071.Process/Bro.M071.Process.csproj
index d8872b2..8f9aab1 100644
--- a/src/Bro.M071.Process/Bro.M071.Process.csproj
+++ b/src/Bro.M071.Process/Bro.M071.Process.csproj
@@ -123,6 +123,7 @@
     <Compile Include="M071Process.cs" />
     <Compile Include="M071Process_MES.cs" />
     <Compile Include="M071Process_MotionCard.cs" />
+    <Compile Include="M071Process_OfflineTest.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="UI\KeyIndicator.cs" />
     <Compile Include="UI\M071Node.cs" />
diff --git a/src/Bro.M071.Process/M071Config.cs b/src/Bro.M071.Process/M071Config.cs
index d2bcd20..34346d5 100644
--- a/src/Bro.M071.Process/M071Config.cs
+++ b/src/Bro.M071.Process/M071Config.cs
@@ -42,6 +42,11 @@
         public List<KeyResult> KeyResultCollection { get; set; } = new List<KeyResult>();
         #endregion
 
+        [Category("绂荤嚎娴嬭瘯妯″紡")]
+        [Description("true锛氳澶囩绾挎ā寮�  false锛氳澶囪繛绾挎ā寮�")]
+        [DisplayName("绂荤嚎妯″紡")]
+        public bool IsOfflineMode { get; set; } = false;
+
         [Category("鏄剧ず閰嶇疆")]
         [Description("杩愯鑳屾櫙鍥剧墖璺緞")]
         [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))]
diff --git a/src/Bro.M071.Process/M071Converters.cs b/src/Bro.M071.Process/M071Converters.cs
index fb8274b..56fd7ef 100644
--- a/src/Bro.M071.Process/M071Converters.cs
+++ b/src/Bro.M071.Process/M071Converters.cs
@@ -1,4 +1,5 @@
 锘縰sing Autofac;
+using Bro.Common.Base;
 using Bro.Common.Helper;
 using Bro.Common.Interface;
 using Bro.Common.Model;
@@ -51,7 +52,13 @@
                 {
                     config.SnapshotPointCollection.Where(u => u.IsEnabled).ToList().ForEach(s =>
                       {
-                          table[s.Id] = s.Name;
+                          if (s.CameraOp?.OpConfig is CameraOprerationConfigBase cameraOpConfig)
+                          {
+                              if (!string.IsNullOrWhiteSpace(cameraOpConfig?.AlgorithemPath))
+                              {
+                                  table[s.Id] = s.Name;
+                              }
+                          }
                       });
                 }
             }
diff --git a/src/Bro.M071.Process/M071Process.cs b/src/Bro.M071.Process/M071Process.cs
index 69301a8..b3c0725 100644
--- a/src/Bro.M071.Process/M071Process.cs
+++ b/src/Bro.M071.Process/M071Process.cs
@@ -58,25 +58,31 @@
         {
             InitialSetting();
 
-            base.Open();
+            if (!Config.IsOfflineMode)
+            {
+                base.Open();
 
-            InitialMotionCardBaseAxisAlarm();
+                InitialMotionCardBaseAxisAlarm();
 
-            SwitchBeep(false);
-            SwitchLightGreen(false);
-            SwitchLightRed(false);
-            SwitchLightYellow(false);
+                SwitchBeep(false);
+                SwitchLightGreen(false);
+                SwitchLightRed(false);
+                SwitchLightYellow(false);
 
-            Reset(null, null, null);
-            FullReset(null);
+                Reset(null, null, null);
+                FullReset(null);
+            }
 
             if (Config.Precision > 0)
             {
                 _precision = "f" + Config.Precision;
             }
 
-            IncomingCheckMethod = InitialMESWebServiceMethod(IncomingCheckMethodName, out IncomingCheckObj);
-            DataUploadMethod = InitialMESWebServiceMethod(DataUploadMethodName, out DataUploadObj);
+            if (Config.IsEnableMESUpload)
+            {
+                IncomingCheckMethod = InitialMESWebServiceMethod(IncomingCheckMethodName, out IncomingCheckObj);
+                DataUploadMethod = InitialMESWebServiceMethod(DataUploadMethodName, out DataUploadObj);
+            }
 
             var allowedShiftStr = ConfigurationManager.AppSettings["DataShift"];
             if (!double.TryParse(allowedShiftStr, out _allowedShift))
@@ -1438,8 +1444,15 @@
 
                             keyBindList.ForEach(kb =>
                             {
-                                kb.KeyImages.Add(image.ConvertHObjectToHImage());
-                                kb.FillKeyValues(resultDict);
+                                if (kb.KeyImages != null)
+                                {
+                                    kb.KeyImages.Add(image.ConvertHObjectToHImage());
+                                    kb.FillKeyValues(resultDict);
+                                }
+                                else
+                                { 
+                                
+                                }
                             });
                         });
 
diff --git a/src/Bro.M071.Process/M071Process_OfflineTest.cs b/src/Bro.M071.Process/M071Process_OfflineTest.cs
new file mode 100644
index 0000000..9a90e98
--- /dev/null
+++ b/src/Bro.M071.Process/M071Process_OfflineTest.cs
@@ -0,0 +1,129 @@
+锘縰sing Autofac;
+using Bro.Common.Base;
+using Bro.Common.Helper;
+using Bro.Common.Interface;
+using Bro.Common.Model;
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing.Design;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Bro.M071.Process
+{
+    public partial class M071Process
+    {
+        [ProcessMethod("OfflineTest", "OfflineTest", "绂荤嚎娴嬭瘯", InvokeType.TestInvoke)]
+        public ProcessResponse OfflineTest(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice)
+        {
+            if (opConfig is OfflineTestOpConfig config)
+            {
+                if (config.SnapshotConfigs.Count > 0)
+                {
+                    OnMeasureStart?.Invoke();
+
+                    List<MeasurementUnit> measurements = new List<MeasurementUnit>();
+                    Config.MeasurementUnitCollection.Where(u => u.IsEnabled).ToList().ForEach(u =>
+                    {
+                        var m = u.Copy();
+                        m.InitialKeyUnitMeasureChanged();
+                        measurements.Add(m);
+                    });
+
+                    var pMeasure = new ProductionMeasurement()
+                    {
+                        Barcode = $"OfflineTest_{DateTime.Now.ToString("HHmmss")}",
+                        Measurements = measurements,
+                        StartTime = DateTime.Now,
+                    };
+
+                    lock (productionLock)
+                    {
+                        var existedProduction = productionList.FirstOrDefault(u => u.Barcode == pMeasure.Barcode);
+                        if (existedProduction != null)
+                        {
+                            productionList.Remove(existedProduction);
+                            existedProduction.Dispose();
+                            existedProduction = null;
+                        }
+
+                        productionList.Add(pMeasure);
+                    }
+
+                    pMeasure.InitialMeasurementsPropertyChanged();
+                    pMeasure.PropertyChanged += MeasureProduction_PropertyChanged;
+
+                    config.SnapshotConfigs.ForEach(s =>
+                    {
+                        ImageSet set = new ImageSet();
+                        set.HImage = new HalconDotNet.HImage(s.OfflineImageFilePath);
+                        set.ImageData = JsonConvert.SerializeObject(config.ScanParam);
+
+                        var snapshotConfig = Config.SnapshotPointCollection.FirstOrDefault(u => u.Id == s.SnapshotPointId);
+
+                        RunImageHandle(snapshotConfig.CameraOp.OpConfig, set, snapshotConfig.Id, snapshotConfig.Name, pMeasure.Measurements);
+                    });
+                }
+
+            }
+
+            return new ProcessResponse(true);
+        }
+    }
+
+    [Device("OfflineTest", "绂荤嚎娴嬭瘯鎿嶄綔閰嶇疆", EnumHelper.DeviceAttributeType.OperationConfig)]
+    public class OfflineTestOpConfig : OperationConfigBase
+    {
+        [Category("鍙栧儚璁剧疆")]
+        [Description("鍙栧儚璁剧疆")]
+        [TypeConverter(typeof(CollectionCountConvert))]
+        [Editor(typeof(ComplexCollectionEditor<OfflineSnapshotPoint>), typeof(UITypeEditor))]
+        public List<OfflineSnapshotPoint> SnapshotConfigs { get; set; } = new List<OfflineSnapshotPoint>();
+
+        //[Category("绂荤嚎鍥惧儚鐩綍")]
+        //[Description("绂荤嚎鍥剧墖鏂囦欢鐩綍锛岀洰鍓嶅彧鏀寔涓�绾ф枃浠剁洰褰曪紝璇ョ洰褰曞寘鍚笖浠呭寘鍚竴娆″畬鏁存祴璇曢渶瑕佺殑鍥剧墖")]
+        //[Editor(typeof(FoldDialogEditor),typeof(UITypeEditor))]
+        //public string OfflineImageFolder { get; set; }
+
+        [Category("鎵弿鍥惧儚鍙傛暟")]
+        [Description("鎵弿鍥惧儚鍙傛暟")]
+        [TypeConverter(typeof(ExpandableObjectConverter))]
+        public LaserScanParam ScanParam { get; set; } = new LaserScanParam();
+    }
+
+    public class OfflineSnapshotPoint : IComplexDisplay
+    {
+        [Category("鍙栧儚鐐逛綅鍙婇厤缃�")]
+        [TypeConverter(typeof(SnapshotPointConverter))]
+        public string SnapshotPointId { get; set; }
+
+        [Category("绂荤嚎鍥惧儚鏂囦欢")]
+        [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))]
+        public string OfflineImageFilePath { get; set; }
+
+        public string GetDisplayText()
+        {
+            string snapshotPointName = "";
+
+            using (var scope = GlobalVar.Container.BeginLifetimeScope())
+            {
+                var config = scope.Resolve<IProcessConfig>() as M071Config;
+
+                if (config != null)
+                {
+                    snapshotPointName = config.SnapshotPointCollection.FirstOrDefault(u => u.Id == SnapshotPointId)?.Name;
+                }
+            }
+
+            if (string.IsNullOrWhiteSpace(snapshotPointName))
+            {
+                snapshotPointName = "鏈寚瀹�";
+            }
+
+            return snapshotPointName;
+        }
+    }
+}

--
Gitblit v1.8.0