M182轴承端盖外观缺陷AOI
kingno
2025-05-26 5a405c7dce20d8c79a733c9c786cc42eb59fe81c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
using Autofac;
using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.Common.Model;
using System.ComponentModel;
using System.Drawing.Design;
 
namespace Bro.M141.Process
{
    public class CheckPoint : IComplexDisplay
    {
        [Browsable(false)]
        public string Id { get; set; } = Guid.NewGuid().ToString();
 
        [Category("检测点位")]
        [Description("点位名称")]
        [DisplayName("点位名称")]
        public string Name { get; set; } = "";
 
        [Category("检测点位")]
        [Description("点位坐标,检测点位的运动坐标")]
        [DisplayName("点位坐标")]
        [TypeConverter(typeof(ExpandableObjectConverter))]
        public CustomizedPoint PointPosition { get; set; } = new CustomizedPoint();
 
        [Category("检测点位")]
        [Description("点位坐标,检测点位的Z轴坐标")]
        [DisplayName("点位坐标Z")]
        public double PointZ { get; set; }
 
        [Category("标定设置")]
        [Description("该检测点位的标定矩阵,图像UV坐标转换为大板坐标系XY的标定矩阵")]
        [DisplayName("点位标定矩阵")]
        [TypeConverter(typeof(SimpleCollectionConvert<double>))]
        [Editor(typeof(SimpleCollectionEditor<double>), typeof(UITypeEditor))]
        public List<double> Matrix { get; set; } = new List<double>();
 
        [Category("启用配置")]
        [Description("true:启用该点位 false:禁用该点位")]
        [DisplayName("点位启用标志")]
        public bool IsEnabled { get; set; } = true;
 
        public string GetDisplayText()
        {
            return $"{(IsEnabled ? "" : "禁用 ")}{Name} {PointPosition.GetDisplayText()}";
        }
    }
 
    public enum ContourEdge
    {
        X,
        Y
    }
    public class ContourPoint : CustomizedPoint
    {
        [Category("点位名称")]
        [Description("点位名称")]
        [DisplayName("点位名称")]
        public string Name { get; set; } = "";
 
        [Category("轮廓选择")]
        [Description("轮廓选择。选择X边,表示计算时以X坐标为基准,计算Y数值。选择Y边,表示计算时以Y坐标为基准,计算X数值")]
        [DisplayName("轮廓选择")]
        public ContourEdge ContourEdge { get; set; } = ContourEdge.X;
 
        [Browsable(false)]
        public double ActualX { get; set; } = -999;
 
        [Browsable(false)]
        public double ActualY { get; set; } = -999;
 
        public ContourPoint Copy()
        {
            ContourPoint point = new ContourPoint();
 
            point.Name = Name;
            point.X = X;
            point.Y = Y;
            point.ContourEdge = this.ContourEdge;
 
            point.ActualX = ActualX;
            point.ActualY = ActualY;
 
            return point;
        }
 
        [Browsable(false)]
        public double Error { get; set; } = 0;
        public void CalculateError(bool isBySingleEdge)
        {
            if (isBySingleEdge)
            {
                if (ContourEdge == ContourEdge.X)
                {
                    Error = Math.Abs(ActualY - Y);
                }
                else
                {
                    Error = Math.Abs(ActualX - X);
                }
            }
            else
            {
                Error = Math.Sqrt(Math.Pow(ActualX - X, 2) + Math.Pow(ActualY - Y, 2));
            }
        }
 
        public override string GetDisplayText()
        {
            return $"{Name} {X.ToString("f3")}:{Y.ToString("f3")}  {ContourEdge.ToString()}基准";
        }
    }
 
    public class MeasureItemBind : IComplexDisplay, IHalconToolPath
    {
        [Category("检测标准")]
        [DisplayName("\t检测名称")]
        [Description("检测名称 填写检测名称内容,不填写时沿用SPEC的名称")]
        public string FAIName { get; set; }
 
        [Category("检测标准")]
        [DisplayName("\t检测标准")]
        [Description("检测标准选择")]
        [TypeConverter(typeof(SpecCodeSelectorConverter))]
        public string SpecCode { get; set; }
 
        [Category("算法配置")]
        [DisplayName("算法路径")]
        [Description("算法路径")]
        [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))]
        public string AlgorithemPath { get; set; }
 
        [Category("检测点位")]
        [DisplayName("\t检测点位集合")]
        [Description("该检测项所涉及的所有检测点位集合")]
        [TypeConverter(typeof(ComplexObjectConvert))]
        [Editor(typeof(ComplexCollectionEditor<MeasurePointSelector>), typeof(UITypeEditor))]
        public List<MeasurePointSelector> MeasurePointNameCollection { get; set; } = new List<MeasurePointSelector>();
 
        [Category("检测项分配")]
        [Description("是否将检测项需求分配到各个检测点位,true:每个检测点位都执行该检测项需求 false:所有检测点位作为一个整体执行检测需求")]
        [DisplayName("点位分配检测项")]
        public bool IsSubscribeSpecForPoints { get; set; } = false;
 
        public string GetDisplayText()
        {
            return $"{FAIName} {SpecCode} {string.Join(",", MeasurePointNameCollection.Select(u => u.GetDisplayText()))} {AlgorithemPath}";
        }
 
        public List<string> GetHalconToolPathList()
        {
            return new List<string>() { AlgorithemPath };
        }
    }
 
    public class MeasurePointSelector : IComplexDisplay
    {
        [Category("检测点位")]
        [Description("检测点位")]
        [DisplayName("检测点位")]
        [TypeConverter(typeof(MeasurePointNameSelectorConvertor))]
        public string MeasurePointName { get; set; } = "";
 
        public string GetDisplayText()
        {
            return $"{MeasurePointName}";
        }
    }
 
    public class MeasurePointNameSelectorConvertor : ComboBoxItemTypeConvert
    {
        public override Dictionary<string, string> GetConvertDict(ITypeDescriptorContext context)
        {
            Dictionary<string, string> dict = new Dictionary<string, string>();
 
            using (var scope = GlobalVar.Container.BeginLifetimeScope())
            {
                var config = scope.Resolve<IProcessConfig>();
                if (config is M141Config iConfig)
                {
                    iConfig.MeasurePointCollection.ForEach(u =>
                    {
                        dict[u.Name] = u.Name;
                    });
                }
            }
            dict[""] = "未指定";
 
            return dict;
        }
    }
}