领胜LDS 键盘AOI检测项目
xcd
2020-07-01 9d05b4e5a7b667afb6d13cbcb460e377c175c170
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
using Bro.Common.Helper;
using Bro.Common.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
 
namespace Bro.UI.Model.Winform
{
    public class CrossHairWithAngle : ElementBase
    {
        #region 基类属性复写
        [Browsable(false)]
        public override string ID { get => base.ID; set => base.ID = value; }
 
        [Browsable(false)]
        public override int Index { get => base.Index; set => base.Index = value; }
 
        [Browsable(false)]
        public override string Name { get => base.Name; set => base.Name = value; }
 
        [Browsable(false)]
        public override bool IsEnabled { get => base.IsEnabled; set => base.IsEnabled = value; }
        #endregion
 
        #region 属性
        [Category("位置属性")]
        [Description("像素坐标信息")]
        [TypeConverter(typeof(ComplexObjectConvert))]
        [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
        public CustomizedPoint ImagePoint { get; set; }
 
        [Category("位置属性")]
        [Description("机台坐标信息")]
        [TypeConverter(typeof(ComplexObjectConvert))]
        [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
        public CustomizedPoint PlatPoint { get; set; }
 
        [Category("位置属性")]
        [Description("倾斜角度")]
        public float Angle { get; set; }
 
        [Category("显示属性")]
        [Description("标记框大小")]
        [Browsable(false)]
        public int HalfRectangleSize { get; set; } = 40;
 
        [Category("显示属性")]
        [Description("标记线长度")]
        [Browsable(false)]
        public int HalfLength { get; set; } = 100;
 
        [Category("显示属性")]
        [Description("标记点可用属性")]
        public bool IsAvailable { get; set; } = true;
        #endregion
 
        #region 构造方法
        public CrossHairWithAngle() { }
 
        public CrossHairWithAngle(int index, CustomizedPoint imagePoint, CustomizedPoint platPoint)
        {
            ImagePoint = imagePoint;
            PlatPoint = platPoint;
 
            {
                CustomizedPointWithAngle temp = imagePoint as CustomizedPointWithAngle;
                if (temp != null)
                {
                    Angle = temp.Angle;
                }
            }
 
            {
                AvailablePoint temp = imagePoint as AvailablePoint;
                if (temp != null)
                {
                    IsAvailable = temp.IsAvailable;
                }
            }
 
            Index = index;
            CalculateBaseRectangle();
        }
 
        public static List<CrossHairWithAngle> GetCrossHairList<T1, T2>(List<T1> imagePointList, List<T2> platPointList) where T1 : CustomizedPoint where T2 : CustomizedPoint
        {
            if (imagePointList.Count != platPointList.Count)
            {
                return null;
            }
 
            List<CrossHairWithAngle> list = new List<CrossHairWithAngle>();
            for (int i = 0; i < imagePointList.Count; i++)
            {
                list.Add(new CrossHairWithAngle(i + 1, imagePointList[i], platPointList[i]));
            }
 
            return list;
        }
 
        //public static List<CrossHairWithAngle> GetCrossHairList(List<CustomizedPoint> imagePointList, List<CustomizedPoint> platPointList)
        //{
        //    if (imagePointList.Count != platPointList.Count)
        //    {
        //        return null;
        //    }
 
        //    List<CrossHairWithAngle> list = new List<CrossHairWithAngle>();
        //    for (int i = 0; i < imagePointList.Count; i++)
        //    {
        //        list.Add(new CrossHairWithAngle(i + 1, imagePointList[i], platPointList[i]));
        //    }
 
        //    return list;
        //}
        #endregion
 
        #region 方法复写
        protected override void SetNormalPen()
        {
            if (IsAvailable)
            {
                Pen = new Pen(Color.Green, 1);
            }
            else
            {
                Pen = new Pen(Color.Red, 1);
            }
        }
        #endregion
 
        #region ElementBase
        public override object Clone()
        {
            //throw new NotImplementedException();
            return null;
        }
 
        public override void Draw(Graphics g)
        {
            g.DrawRectangle(Pen, (float)ImagePoint.X - HalfRectangleSize, (float)ImagePoint.Y - HalfRectangleSize, HalfRectangleSize * 2, HalfRectangleSize * 2);
 
            g.DrawLine(Pen, (float)ImagePoint.X, (float)ImagePoint.Y - HalfLength, (float)ImagePoint.X, (float)ImagePoint.Y + HalfLength);
            g.DrawLine(Pen, (float)ImagePoint.X - HalfLength, (float)ImagePoint.Y, (float)ImagePoint.X + HalfLength, (float)ImagePoint.Y);
 
            Pen arrowPen = new Pen(Pen.Color, Pen.Width + 3.5f);
            arrowPen.StartCap = System.Drawing.Drawing2D.LineCap.AnchorMask;
            arrowPen.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
            g.DrawLine(arrowPen, (float)ImagePoint.X, (float)ImagePoint.Y, (float)ImagePoint.X + (float)(HalfLength * Math.Cos(Angle * Math.PI / 180.0)), (float)ImagePoint.Y - (float)(HalfLength * Math.Sin(Angle * Math.PI / 180.0)));
 
            string info = $"{Index}  图像坐标:{ImagePoint.X},{ImagePoint.Y}\r\n机台坐标:{PlatPoint.X},{PlatPoint.Y}\r\n角度:{Angle}";
            g.DrawString(info, Font, new SolidBrush(Pen.Color), new PointF((float)ImagePoint.X + FontDistance, (float)ImagePoint.Y + FontDistance));
        }
 
        public override bool IsMouseHover(Point p)
        {
            //throw new NotImplementedException();
            return false;
        }
 
        public override bool IsMouseInSide(Point p)
        {
            return (p.X >= BaseRectangle.Location.X
                && p.X <= BaseRectangle.Location.X + BaseRectangle.Width
                && p.Y >= BaseRectangle.Location.Y
                && p.Y <= BaseRectangle.Location.Y + BaseRectangle.Height);
        }
 
        public override bool IsIntersect(Rectangle rect)
        {
            return rect.IntersectsWith(BaseRectangle);
        }
 
        public void CalculateBaseRectangle()
        {
            BaseRectangle = new Rectangle(new Point((int)ImagePoint.X - HalfRectangleSize, (int)ImagePoint.Y - HalfRectangleSize), new Size(HalfRectangleSize * 2, HalfRectangleSize * 2));
        }
 
        public override void OnKeyDown(object sender, KeyEventArgs e)
        {
            //throw new NotImplementedException();
        }
 
        public override void OnKeyUp(object sender, KeyEventArgs e)
        {
            //throw new NotImplementedException();
        }
 
        public override void OnMouseDownWhenNew(Point p)
        {
            //throw new NotImplementedException();
        }
 
        public override void OnMouseMoveWhenNew(Point p)
        {
            //throw new NotImplementedException();
        }
 
        public override void OnMouseUpWhenNew(Point p)
        {
            //throw new NotImplementedException();
        }
 
        public override void Translate(int x, int y)
        {
            //CenterPoint.U -= x;
            //CenterPoint.V -= y;
        }
 
        protected override void DrawResult(Graphics g)
        {
            //throw new NotImplementedException();
        }
 
        public override string GetDisplayText()
        {
            return "";
        }
        #endregion
    }
}