领胜LDS 键盘AOI检测项目
patrick.xu
2021-01-24 b5e7fa2db4ac36fdb7bf9fd330d12a72ade9d483
src/Bro.M071.Process/M071Models.cs
@@ -3,6 +3,7 @@
using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.Common.Model;
using HalconDotNet;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@@ -11,10 +12,46 @@
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Bro.M071.Process
{
    public class KeyLocation : IComplexDisplay
    {
        [Category("键名配置")]
        [Description("单键键名")]
        [TypeConverter(typeof(KeyNameDictConverter))]
        public string Key { get; set; }
        [Category("默认配置")]
        [Description("是否默认尺寸配置")]
        public bool IsDefault { get; set; } = false;
        //[Category("位置配置")]
        //[Description("单键在键盘平面图上的位置显示")]
        //public RectangleF KeyRect { get; set; } = new RectangleF(0, 0, 0, 0);
        [Category("位置配置")]
        [Description("单键左上角坐标")]
        [TypeConverter(typeof(ComplexObjectConvert))]
        [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
        public CustomizedPoint KeyPosition { get; set; } = new CustomizedPoint();
        [Category("位置配置")]
        [Description("单键尺寸")]
        public SizeF KeySize { get; set; } = new SizeF();
        [Category("位置配置")]
        [Description("单键之后间隙位置")]
        public SizeF IntervalSize { get; set; } = new SizeF();
        public string GetDisplayText()
        {
            return $"{(IsDefault ? "Default" : Key)}:{KeyPosition.X},{KeyPosition.Y},{KeySize.Width},{KeySize.Height}";
        }
    }
    public class KeyAlgorithem : IComplexDisplay
    {
        [Browsable(false)]
@@ -46,6 +83,15 @@
        [Description("检测算法路径")]
        [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))]
        public string AlgorithemPath { get; set; }
        [Category("上传NG代码")]
        [Description("上传NG代码")]
        public string NGCode { get; set; }
        [Category("显示配置")]
        [Description("显示区域大小")]
        [DisplayName("标签大小")]
        public Size DisplayRect { get; set; }
    }
    public class KeyResult : IComplexDisplay
@@ -73,7 +119,7 @@
    {
        public string GetDisplayText()
        {
            return (IsEnabled ? "" : "禁用 ") + Name + " " + string.Join(" ", Destination.Select(u => u.GetDisplayText())) + " " + CameraOp.GetDisplayText();
            return (IsEnabled ? "" : "禁用 ") + Name + " " + MotionOp.GetDisplayText() + " " + CameraOp.GetDisplayText();
        }
        public List<string> GetHalconToolPathList()
@@ -99,16 +145,22 @@
        [Description("true:启用 false:禁用")]
        public bool IsEnabled { get; set; } = true;
        [Category("设备配置")]
        [Description("运动设备")]
        [TypeConverter(typeof(DeviceSelectorConverter<IMotion>))]
        public string MotionDevice { get; set; }
        //[Category("设备配置")]
        //[Description("运动设备")]
        //[TypeConverter(typeof(DeviceSelectorConverter<IMotion>))]
        //public string MotionDevice { get; set; }
        [Category("运动点位")]
        [Description("运动点位")]
        //[Category("运动点位")]
        //[Description("运动点位")]
        //[TypeConverter(typeof(ComplexObjectConvert))]
        //[Editor(typeof(ComplexCollectionEditor<AxisInfo>), typeof(UITypeEditor))]
        //public List<AxisInfo> Destination { get; set; } = new List<AxisInfo>();
        [Category("运动机构配置")]
        [Description("运动机构配置")]
        [TypeConverter(typeof(ComplexObjectConvert))]
        [Editor(typeof(ComplexCollectionEditor<AxisInfo>), typeof(UITypeEditor))]
        public List<AxisInfo> Destination { get; set; } = new List<AxisInfo>();
        [Editor(typeof(IOperationConfigByDeviceEditor), typeof(UITypeEditor))]
        public DeviceOpBind MotionOp { get; set; } = new DeviceOpBind();
        [Category("相机和操作配置")]
        [Description("相机和操作配置")]
@@ -129,13 +181,13 @@
            get => key;
            set
            {
                AlignName = key = value;
                AliasName = key = value;
            }
        }
        [Category("键名配置")]
        [Description("别名")]
        public string AlignName { get; set; }
        public string AliasName { get; set; }
        [Category("启用设置")]
        [Description("true:启用 false:禁用")]
@@ -170,7 +222,22 @@
        public string GetDisplayText()
        {
            return $"{AlignName}";
            string snapShot = "未指定";
            using (var scope = GlobalVar.Container.BeginLifetimeScope())
            {
                var config = scope.Resolve<IProcessConfig>();
                if (config != null)
                {
                    var snapshotPoint = (config as M071Config).SnapshotPointCollection.FirstOrDefault(u => u.Id == SnapshotPointId);
                    if (snapshotPoint != null)
                    {
                        snapShot = snapshotPoint.Name;
                    }
                }
            }
            return $"{AliasName}-{snapShot}-{ImageSeq}";
        }
        public List<string> GetHalconToolPathList()
@@ -195,18 +262,25 @@
    public class ProductionMeasurement : INotifyPropertyChanged, IDisposable
    {
        public string Barcode { get; set; }
        public string Barcode;
        public string PResult;
        public List<MeasurementUint> Measurements { get; set; } = new List<MeasurementUint>();
        public List<MeasurementUnit> Measurements = new List<MeasurementUnit>();
        public List<IShapeElement> ElementList = new List<IShapeElement>();
        public DateTime? StartTime = null;
        public DateTime? EndTime = null;
        public event PropertyChangedEventHandler PropertyChanged;
        public void Dispose()
        {
            Barcode = null;
            Measurements?.ForEach(m => m?.Dispose());
            Measurements = null;
            ElementList = null;
            //Barcode = null;
            GC.Collect();
        }
@@ -225,7 +299,7 @@
        }
    }
    public class MeasurementUint : IComplexDisplay, INotifyPropertyChanged, IDisposable
    public class MeasurementUnit : IComplexDisplay, INotifyPropertyChanged, IDisposable
    {
        public string Id = Guid.NewGuid().ToString();
@@ -252,7 +326,7 @@
        #region 显示
        [Browsable(false)]
        public Rectangle DisplayLocation { get; set; } = new Rectangle();
        public Rectangle DisplayLocation { get; set; } = new Rectangle(10, 10, 100, 100);
        #endregion
        #region 检测结果
@@ -273,7 +347,7 @@
        {
            if (string.IsNullOrWhiteSpace(Name))
            {
                return (IsEnabled ? "" : "禁用 ") + string.Join("-", KeyUnitCollection.Select(u => u.GetDisplayText())) + "-" + MeasureType.ToString();
                return (IsEnabled ? "" : "禁用 ") + string.Join("-", KeyUnitCollection.Select(u => u.GetDisplayText())) + "-" + MeasureType?.ToString();
            }
            else
            {
@@ -290,6 +364,44 @@
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("KeyUnitCollection"));
        }
        public MeasurementUnit Copy()
        {
            MeasurementUnit mUnit = new MeasurementUnit();
            mUnit.Id = this.Id;
            mUnit.Name = this.Name;
            if (string.IsNullOrWhiteSpace(mUnit.Name))
            {
                mUnit.Name = string.Join("-", KeyUnitCollection.Select(u => u.GetDisplayText()));
            }
            mUnit.IsEnabled = this.IsEnabled;
            mUnit.MeasureType = this.MeasureType;
            mUnit.DisplayLocation = new Rectangle(this.DisplayLocation.Location, this.DisplayLocation.Size);
            if (this.Spec == null)
            {
                mUnit.Spec = null;
            }
            else
            {
                mUnit.Spec = new MeasureType();
                mUnit.Spec.Code = this.Spec.Code;
                mUnit.Spec.AlgorithemPath = this.Spec.AlgorithemPath;
                mUnit.Spec.StandardValue = this.Spec.StandardValue;
                mUnit.Spec.Tolrenance_Positive = this.Spec.Tolrenance_Positive;
                mUnit.Spec.Tolrenance_Negative = this.Spec.Tolrenance_Negative;
            }
            this.KeyUnitCollection.ForEach(k =>
            {
                mUnit.KeyUnitCollection.Add(k.Copy());
            });
            return mUnit;
        }
    }
    public class KeyUnitBind : IComplexDisplay, INotifyPropertyChanged, IDisposable
@@ -302,8 +414,12 @@
        [Category("单键配置")]
        [Description("单键结果配置")]
        [TypeConverter(typeof(KeyUnitResultConverter))]
        public string KeyResult { get; set; } = "";
        public string KeyResultId { get; set; } = "";
        public List<HImage> KeyImages = new List<HImage>();
        public volatile int ImageSaveStatus = 0;
        //[Browsable(false)]
        //public NoticedDictionary<string, double?> MeasureValueDict { get; set; } = new NoticedDictionary<string, double?>();
@@ -328,13 +444,24 @@
        {
            string msg = Key;
            msg += string.IsNullOrWhiteSpace(KeyResult) ? "" : $"-{KeyResult}";
            msg += string.IsNullOrWhiteSpace(KeyResultId) ? "" : $"-{KeyResultId}";
            return msg;
        }
        public void Dispose()
        {
            while (ImageSaveStatus != 0)
            {
                Thread.Sleep(10);
            }
            KeyImages?.ForEach(i =>
            {
                i?.Dispose();
                i = null;
            });
            KeyImages = null;
            MeasureValueDict = null;
        }
@@ -346,6 +473,8 @@
                if (valuePairs == null || valuePairs.Count == 0)
                {
                    IsDone = false;
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsDone"));
                    return;
                }
                foreach (KeyValuePair<string, double> pair in valuePairs)
@@ -367,6 +496,37 @@
                }
            }
        }
        public KeyUnitBind Copy()
        {
            KeyUnitBind clone = new KeyUnitBind();
            clone.Key = this.Key;
            clone.KeyResultId = this.KeyResultId;
            this.MeasureValueDict.Keys.ToList().ForEach(k =>
            {
                clone.MeasureValueDict[k] = null;
            });
            return clone;
        }
    }
    public class KeyCodeMap : IComplexDisplay
    {
        [Category("键名映射配置")]
        [Description("键名")]
        [TypeConverter(typeof(KeyNameDictConverter))]
        public string Key { get; set; }
        [Category("键名映射配置")]
        [Description("上传对应键代码Code")]
        public string KeyCode { get; set; }
        public string GetDisplayText()
        {
            return $"{Key}--{KeyCode}";
        }
    }
    //public class NoticedDictionary<T1, T2> : Dictionary<T1, T2>, INotifyPropertyChanged