领胜LDS 键盘AOI检测项目
xcd
2020-06-24 d6c577e17ee7bb5331dd51d803f9b42441b0f0e5
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
using Bro.Common.Model;
using System;
using System.Windows;
using System.Windows.Media;
 
namespace Bro.Common.ImageCanvas.Shapes
{
    public class ComplexPointIndicator : ShapeElementBase
    {
        public ComplexPoint PointInfo { get; set; }
 
        public float Angle { get; set; }
 
        readonly int halfRectSize = 20;
        readonly int halfLength = 100;
 
        public override void SetNormalPen()
        {
            if (PointInfo.PlatPoint.IsAvailable)
            {
                Pen = new Pen(new SolidColorBrush(Colors.Green), 3);
            }
            else
            {
                Pen = new Pen(new SolidColorBrush(Colors.Red), 3);
            }
        }
 
        protected override void DrawShape(DrawingContext dc)
        {
            Text = $"{Index}  图像坐标:{PointInfo.ImagePoint.X},{PointInfo.ImagePoint.Y}\r\n机台坐标:{PointInfo.PlatPoint.X},{PointInfo.PlatPoint.Y}\r\n角度:{Angle}";
            dc.DrawText(new FormattedText(Text, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, Typeface, FontSize, Pen.Brush), new Point(PointInfo.ImagePoint.X + FontDistance, PointInfo.ImagePoint.Y - FontDistance));
 
            dc.PushTransform(new RotateTransform(0 - Angle, PointInfo.ImagePoint.X, PointInfo.ImagePoint.Y));
 
            dc.DrawRectangle(null, Pen, new Rect(PointInfo.ImagePoint.X - halfRectSize, PointInfo.ImagePoint.Y - halfRectSize, halfRectSize * 2, halfRectSize * 2));
            dc.DrawLine(Pen, new Point(PointInfo.ImagePoint.X, PointInfo.ImagePoint.Y - halfLength), new Point(PointInfo.ImagePoint.X, PointInfo.ImagePoint.Y + halfLength));
            dc.DrawLine(Pen, new Point(PointInfo.ImagePoint.X - halfLength, PointInfo.ImagePoint.Y), new Point(PointInfo.ImagePoint.X + halfLength, PointInfo.ImagePoint.Y));
        }
 
        protected override bool IsMouseInSide(Point point)
        {
            return Math.Sqrt(Math.Pow(PointInfo.ImagePoint.X - point.X, 2) + Math.Pow(PointInfo.ImagePoint.Y - point.Y, 2)) < halfLength;
        }
 
        protected override bool IsMouseHover(Point point)
        {
            return false;
        }
    }
}