领胜LDS 键盘AOI检测项目
wells.liu
2020-06-28 19a9489aef9b3353171eca5e6b583aadb2828593
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
using Bro.Common.Helper;
using Bro.Common.Model;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
 
namespace Bro.UI.Model.Winform
{
    public class CrossHair : 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 CalibrationPoint CenterPoint { get; set; }
 
        [Category("显示属性")]
        [Description("标记框大小")]
        [Browsable(false)]
        public int HalfRectangleSize { get; set; } = 10;
 
        [Category("显示属性")]
        [Description("标记线长度")]
        [Browsable(false)]
        public int HalfLength { get; set; } = 30;
        #endregion
 
        #region 构造方法
        public CrossHair() { }
 
        public CrossHair(PointF centerPoint, int halfRectSiez = 10, int halfLength = 30)
        {
            CenterPoint = new CalibrationPoint(centerPoint);
            HalfRectangleSize = halfRectSiez;
            HalfLength = halfLength;
 
            CenterPoint.PropertyChanged -= CenterPoint_PropertyChanged;
            CenterPoint.PropertyChanged += CenterPoint_PropertyChanged;
 
            CalculateBaseRectangle();
        }
 
        public CrossHair(CalibrationPoint centerPoint, int halfRectSiez = 10, int halfLength = 30)
        {
            CenterPoint = centerPoint;
            HalfRectangleSize = halfRectSiez;
            HalfLength = halfLength;
 
            CenterPoint.PropertyChanged -= CenterPoint_PropertyChanged;
            CenterPoint.PropertyChanged += CenterPoint_PropertyChanged;
 
            CalculateBaseRectangle();
        }
        #endregion
 
        #region ElementBase
        private void CenterPoint_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            SetNormalPen();
        }
 
        protected override void SetNormalPen()
        {
            if (CenterPoint.IsBasePoint)
            {
                HalfRectangleSize = 20;
                HalfLength = 80;
 
                Pen = new Pen(Color.DarkGreen, 1);
            }
            else
            {
                HalfRectangleSize = 10;
                HalfLength = 30;
 
                base.SetNormalPen();
            }
        }
 
        public override void Calculate(string imagePath)
        {
            //throw new NotImplementedException();
        }
 
        public override void Calculate(Bitmap image)
        {
            //throw new NotImplementedException();
        }
 
        public override void Calculate(IntPtr imagePtr, int ptrSize, int imageWidth, int imageHeight)
        {
            //throw new NotImplementedException();
        }
 
        public override object Clone()
        {
            //throw new NotImplementedException();
            return null;
        }
 
        public override void Draw(Graphics g)
        {
            g.DrawRectangle(Pen, (float)CenterPoint.U - HalfRectangleSize, (float)CenterPoint.V - HalfRectangleSize, HalfRectangleSize * 2, HalfRectangleSize * 2);
 
            g.DrawLine(Pen, (float)CenterPoint.U, (float)CenterPoint.V - HalfLength, (float)CenterPoint.U, (float)CenterPoint.V + HalfLength);
            g.DrawLine(Pen, (float)CenterPoint.U - HalfLength, (float)CenterPoint.V, (float)CenterPoint.U + HalfLength, (float)CenterPoint.V);
 
            if (IsShowRemark)
            {
                string info = Index.ToString() + ":(" + CenterPoint.X.ToString() + ";" + CenterPoint.Y.ToString() + ")";
                g.DrawString(info, new Font("NewRoman", FontSize), new SolidBrush(Pen.Color), new PointF((float)CenterPoint.U + FontDistance, (float)CenterPoint.V + 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 override void CalculateBaseRectangle()
        {
            BaseRectangle = new Rectangle(new Point((int)CenterPoint.U - HalfLength, (int)CenterPoint.V - HalfLength), new Size(HalfLength * 2, HalfLength * 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
    }
}