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.Common.UI { 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 GetCrossHairList(List imagePointList, List platPointList) where T1 : CustomizedPoint where T2 : CustomizedPoint { if (imagePointList.Count != platPointList.Count) { return null; } List list = new List(); for (int i = 0; i < imagePointList.Count; i++) { list.Add(new CrossHairWithAngle(i + 1, imagePointList[i], platPointList[i])); } return list; } //public static List GetCrossHairList(List imagePointList, List platPointList) //{ // if (imagePointList.Count != platPointList.Count) // { // return null; // } // List list = new List(); // 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 //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, ImagePoint.X - HalfRectangleSize, ImagePoint.Y - HalfRectangleSize, HalfRectangleSize * 2, HalfRectangleSize * 2); g.DrawLine(Pen, ImagePoint.X, ImagePoint.Y - HalfLength, ImagePoint.X, ImagePoint.Y + HalfLength); g.DrawLine(Pen, ImagePoint.X - HalfLength, ImagePoint.Y, ImagePoint.X + HalfLength, 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, ImagePoint.X, ImagePoint.Y, ImagePoint.X + (float)(HalfLength * Math.Cos(Angle * Math.PI / 180.0)), 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, new Font("NewRoman", FontSize), new SolidBrush(Pen.Color), new PointF(ImagePoint.X + FontDistance, 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 override 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 } }