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
|
}
|
}
|