From 8cbf4a6b9f334246d88c8101ae3db9a21f1bab3f Mon Sep 17 00:00:00 2001
From: patrick.xu <patrick.xu@broconcentric.com>
Date: 星期三, 28 四月 2021 11:40:08 +0800
Subject: [PATCH] Merge branch 'master' of http://gitblit.broconcentric.com:8088/r/M071

---
 src/Bro.M071.Process/M071Process_OfflineTest.cs |  129 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 129 insertions(+), 0 deletions(-)

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