领胜LDS 键盘AOI检测项目
xcd
2020-06-27 998ad559883116280541553b761221bd8d486b9e
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
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
{
    [Element("圆形ROI", "")]
    public class ROI_Circle : ElementBase
    {
        #region ElementBase
        //默认不在列表中显示
        [Browsable(false)]
        public override bool ShowList { get; set; } = false;
 
        public override void Calculate(Bitmap image)
        {
        }
 
        public override void Calculate(IntPtr imagePtr, int ptrSize, int imageWidth, int imageHeight)
        {
        }
 
        public override void Calculate(string imagePath)
        {
        }
 
        public override void CalculateBaseRectangle()
        {
        }
 
        public override object Clone()
        {
            ROI_Circle circle = new ROI_Circle();
 
            circle.Center = Center;
            circle.Radius = Radius;
            circle.ROI_Index = ROI_Index + "_Clone";
 
            return circle;
        }
 
        public override void Draw(Graphics g)
        {
            g.FillEllipse(new SolidBrush(Color.Red), new RectangleF((float)Center.X, (float)Center.Y, 1.0f, 1.0f));
 
            Pen pen = null;
            if (ROI_Index == "1")
            {
                pen = new Pen(new SolidBrush(Color.Red), 6.0f);
 
                g.DrawString(
                    "P1",
                    new Font(new FontFamily("宋体"), 40.0f),
                    new SolidBrush(Color.Red),
                    new PointF((float)Center.X - Radius - 80, (float)Center.Y - Radius - 40)
                    );
            }
            else
            {
                pen = new Pen(new SolidBrush(Color.Green), 3.0f);
            }
 
            pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
            g.DrawEllipse(pen, (float)Center.X - Radius, (float)Center.Y - Radius, Radius * 2, Radius * 2);
 
            if (ROI_Index == "1")
            {
                g.DrawEllipse(pen, (float)Center.X - Radius - 15, (float)Center.Y - Radius - 15, Radius * 2 + 30, Radius * 2 + 30);
            }
        }
 
        public override bool IsIntersect(Rectangle rect)
        {
            return false;
        }
 
        public override bool IsMouseHover(Point p)
        {
            return false;
        }
 
        public override bool IsMouseInSide(Point p)
        {
            double dist = Math.Sqrt((Math.Pow((p.X - Center.X), 2) + Math.Pow((p.Y - Center.Y), 2)));
            return dist <= Radius;
        }
 
        public override void OnKeyDown(object sender, KeyEventArgs e)
        {
        }
 
        public override void OnKeyUp(object sender, KeyEventArgs e)
        {
        }
 
        public override void OnMouseDownWhenNew(Point p)
        {
        }
 
        public override void OnMouseMoveWhenNew(Point p)
        {
        }
 
        public override void OnMouseUpWhenNew(Point p)
        {
        }
 
        public override void Translate(int x, int y)
        {
        }
 
        protected override void DrawResult(Graphics g)
        {
        }
        #endregion
 
        #region IComplexDisplay
        public override string GetDisplayText()
        {
            return $"X:{Center.X},Y:{Center.Y},R:{Radius}";
        }
        #endregion
 
        #region Properties
        [Category("专有配置")]
        [Description("中心点")]
        [TypeConverter(typeof(ComplexObjectConvert))]
        [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))]
        public CustomizedPoint Center { get; set; } = new CustomizedPoint();
 
        [Category("专有配置")]
        [Description("ROI半径")]
        public float Radius { get; set; }
 
        [Category("专有配置")]
        [Description("ROI编号")]
        public string ROI_Index { get; set; }
        #endregion
    }
}