2026-01-26 18:56:53 +09:00

413 lines
13 KiB
C#

using CoreUnit.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Windows.Forms;
using System.Xml;
namespace CoreUnit.Control.UserControl.Canvas
{
public class Dot : DrawObjectBase, IDrawObject, ISerialize
{
protected UnitPoint m_p1;
[Browsable(false)]
public UnitPoint P1 {
get { return m_p1; }
set { m_p1 = value; }
}
public static string ObjectType {
get { return "Dot"; }
}
public Dot()
{
}
public Dot(UnitPoint point, float width, Color color)
{
P1 = point;
Width = width;
Color = color;
Selected = false;
}
public override void InitializeFromModel(UnitPoint point, DrawingLayer layer, ISnapPoint snap)
{
P1 = point;
Width = layer.Width;
Color = layer.Color;
Selected = true;
}
static int ThresholdPixel = 6;
static float ThresholdWidth(ICanvas canvas, float objectwidth)
{
return ThresholdWidth(canvas, objectwidth, ThresholdPixel);
}
public static float ThresholdWidth(ICanvas canvas, float objectwidth, float pixelwidth)
{
double minWidth = canvas.ToUnit(pixelwidth);
double width = Math.Max(objectwidth / 2, minWidth);
return (float)width;
}
public RectangleF GetBoundingRect(ICanvas canvas)
{
float thWidth = ThresholdWidth(canvas, Width);
UnitPoint newPoint1 = new UnitPoint(m_p1.X - thWidth / 2, m_p1.Y - thWidth / 2);
UnitPoint newPoint2 = new UnitPoint(m_p1.X + thWidth / 2, m_p1.Y + thWidth / 2);
return ScreenUtils.GetRect(newPoint1, newPoint2, thWidth);
}
public virtual void Copy(Dot acopy)
{
base.Copy(acopy);
P1 = acopy.P1;
Type = acopy.Type;
m_no = acopy.m_no;
//마킹객체에 대한 속성 복사
ScannerParamNo = acopy.ScannerParamNo;
Enabled = acopy.Enabled;
Selected = acopy.Selected;
}
#region IDrawObject Members
#region 마킹 객체에 대한 속성
[Browsable(true)]
[ReadOnly(true)]
[CustomSortedCategory("Boundary", 1, 6)]
[CustomSortedDisplayName("Left,Bottom,Right,Top", 1, 1)]
[Description("Boundary of Object")]
[TypeConverter(typeof(RectangleFConverter))]
[JsonIgnore]
public RectangleF ClientRect {
get {
lock (this) { return ScreenUtils.GetRect(P1, P1, 0); }
}
}
bool m_enabled = true;
[Browsable(true)]
[ReadOnly(false)]
[CustomSortedCategory("Geometry", 3, 6)] // 용접 파라미터
[CustomSortedDisplayName("Enable Mark", 3, 3)] // 용접 작업 유무
[Description("Enable Mark")] // 용접 작업 진행 여부
[XmlSerializable]
public bool Enabled {
get { return m_enabled; }
set { m_enabled = value; }
}
bool m_lock = false;
[Browsable(true)]
[ReadOnly(false)]
[CustomSortedCategory("Geometry", 3, 6)]
[CustomSortedDisplayName("Lock", 2, 3)]
[Description("Lock")]
[XmlSerializable]
public bool Lock {
get { return m_lock; }
set { m_lock = value; }
}
int m_scannerParamNo = 0;
[Browsable(false)]
[ReadOnly(false)]
[Category("용접 파라미터")]
[DisplayName("용접 조건 번호")]
[Description("용접 조건(스캔속도 및 레이저 파워 값등..) 번호 설정")]
[XmlSerializable]
public int ScannerParamNo {
get { return m_scannerParamNo; }
set { m_scannerParamNo = value; }
}
[Browsable(false)]
[ReadOnly(false)]
[Category("용접 파라미터")]
[DisplayName("용접 조건 ID")]
[Description("용접 조건(스캔속도 및 레이저 파워 값등..) ID 설정")]
[XmlSerializable]
public int ScannerParamID {
get { return m_scannerParamNo + 1; }
set { m_scannerParamNo = value - 1; }
}
[Browsable(true)]
[ReadOnly(false)]
[CustomSortedCategory("Pen", 2, 6)]
[CustomSortedDisplayName("Parameter ID", 2, 2)]
[Description("Welding Paramter ID")]
[Editor(typeof(WeldingParameterIDEditor.WeldingParamterNoUITypeEditor), typeof(System.Drawing.Design.UITypeEditor))]
[XmlSerializable]
public WeldingParameterIDEditor.eWeldingParamterID WeldingParameterID {
get { return (WeldingParameterIDEditor.eWeldingParamterID)ScannerParamID; }
set { ScannerParamID = (int)value; }
}
public enum eAlignType { XY_ANGLE, XY_OFFSET, X_OFFSET, Y_OFFSET, ABSOLUTE_XY }
eAlignType m_alignType = eAlignType.ABSOLUTE_XY;
[Browsable(true)]
[ReadOnly(false)]
[CustomSortedCategory("Vision Align", 5, 6)]
[CustomSortedDisplayName("Align Type", 1, 2)]
[Description("Align Type")]
[XmlSerializable]
public eAlignType AlignType {
get { return m_alignType; }
set { m_alignType = value; }
}
int m_alignID = -1;
[Browsable(true)]
[ReadOnly(false)]
[CustomSortedCategory("Vision Align", 5, 6)]
[CustomSortedDisplayName("Align ID", 2, 2)]
[Description("Align ID")]
[XmlSerializable]
public int AlignID {
get { return m_alignID; }
set { m_alignID = value; }
}
#endregion
#region 드로잉 객체에 대한 속성
int m_no;
[Browsable(false)]
[XmlSerializable]
public int No {
get { return m_no; }
set { m_no = value; }
}
string m_type;
[Browsable(false)]
[ReadOnly(true)]
[Category("객체")]
[DisplayName("종류")]
[Description("드로잉 객체 종류")]
[XmlSerializable]
public string Type {
get {
m_type = Dot.ObjectType;
return m_type;
}
set { m_type = value; }
}
[Browsable(true)]
[ReadOnly(false)]
[CustomSortedCategory("Geometry", 3, 6)]
[CustomSortedDisplayName("중심점[X,Y](mm)", 1, 3)]
[Description("드로잉 객체의 시작점")]
[TypeConverter(typeof(PointFConverter))]
[XmlSerializable]
public PointF PF1 {
get { lock (this) { return P1.Point; } }
set { lock (this) { P1 = new UnitPoint(value); } }
}
[Browsable(false)]
[ReadOnly(false)]
[Category("GEOMETRY")]
[DisplayName("2.종료점[X,Y](mm)")]
[Description("드로잉 객체의 종료점")]
[TypeConverter(typeof(PointFConverter))]
[XmlSerializable]
public PointF PF2 {
get { lock (this) { return P1.Point; } }
set { lock (this) { P1 = new UnitPoint(value); } }
}
[Browsable(false)]
[ReadOnly(false)]
[Category("GEOMETRY")]
[DisplayName("3.중심점[X,Y](mm)")]
[Description("드로잉 객체의 중심점")]
[TypeConverter(typeof(PointFConverter))]
[JsonIgnore]
public PointF MiddlePoint {
get { return HitUtil.LineMidpoint(P1, P1).Point; }
set {
PointF offset = new PointF();
offset.X = (value.X - MiddlePoint.X);
offset.Y = (value.Y - MiddlePoint.Y);
Move(new UnitPoint(offset));
}
}
[Browsable(false)]
[ReadOnly(true)]
[Category("GEOMETRY")]
[DisplayName("4.각도(˚)")]
[Description("드로잉 객체의 각도")]
[JsonIgnore]
public float Angle {
get { return 0; }
set { }
}
[Browsable(false)]
[ReadOnly(true)]
[Category("GEOMETRY")]
[DisplayName("5.경계(↖Left,Bottom,↘Right,Top)")]
[Description("드로잉 객체의 경계")]
[TypeConverter(typeof(RectangleFConverter))]
[JsonIgnore]
public RectangleF ClientDot {
get {
lock (this) { return ScreenUtils.GetRect(P1, P1, 0); }
}
}
[Browsable(false)]
[ReadOnly(false)]
[Category("GEOMETRY")]
[DisplayName("6.길이(mm)")]
[Description("드로잉 객체의 길이")]
[JsonIgnore]
public double Distance {
get { return 0; }
}
[Browsable(false)]
public UnitPoint RepeatStartingPoint {
get { return m_p1; }
}
public void Rotate(float angle, UnitPoint center)
{
// Dot에 대한 Rotate 함수 구현이 안 되어 있었음. 현재 Line은 Rotate 가능
P1 = HitUtil.RotatePoint(angle, P1, center);
}
public void MakeLength(float distance)
{
}
public virtual IDrawObject Clone()
{
Dot l = new Dot();
l.Copy(this);
return l;
}
#endregion
public bool PointInObject(ICanvas canvas, UnitPoint point)
{
float thWidth = ThresholdWidth(canvas, Width);
return HitUtil.IsPointInLine(m_p1, m_p1, point, thWidth);
}
public bool ObjectInRectangle(ICanvas canvas, RectangleF rect, bool anyPoint)
{
RectangleF boundingrect = GetBoundingRect(canvas);
UnitPoint newPoint1 = new UnitPoint(boundingrect.X, boundingrect.Y);
UnitPoint newPoint2 = new UnitPoint(boundingrect.X + boundingrect.Width, boundingrect.Y + boundingrect.Height);
if (anyPoint)
return HitUtil.LineIntersectWithRect(newPoint1, newPoint2, rect);
return rect.Contains(boundingrect);
}
public virtual void Draw(ICanvas canvas, RectangleF unitrect)
{
Color color = Color;
color = WeldingParameterIDEditor.weldingColorList[(int)WeldingParameterID - 1];
Pen pen = canvas.CreatePen(color, Width);
pen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
pen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
float thWidth = ThresholdWidth(canvas, Width);
UnitPoint newPoint1 = new UnitPoint(m_p1.X - thWidth / 2, m_p1.Y - thWidth / 2);
UnitPoint newPoint2 = new UnitPoint(m_p1.X + thWidth / 2, m_p1.Y + thWidth / 2);
UnitPoint newPoint3 = new UnitPoint(m_p1.X - thWidth / 2, m_p1.Y + thWidth / 2);
UnitPoint newPoint4 = new UnitPoint(m_p1.X + thWidth / 2, m_p1.Y - thWidth / 2);
canvas.DrawLine(canvas, pen, newPoint1, newPoint2);
canvas.DrawLine(canvas, pen, newPoint3, newPoint4);
if (Selected) {
canvas.DrawLine(canvas, DrawUtils.SelectedPen, newPoint1, newPoint2);
canvas.DrawLine(canvas, DrawUtils.SelectedPen, newPoint3, newPoint4);
}
}
public virtual void OnMouseMove(ICanvas canvas, UnitPoint point)
{
}
public virtual eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint)
{
Selected = false;
m_p1 = point;
return eDrawObjectMouseDown.Done;
}
public void OnMouseUp(ICanvas canvas, UnitPoint point, ISnapPoint snappoint)
{
}
public virtual void OnKeyDown(ICanvas canvas, KeyEventArgs e)
{
}
public INodePoint NodePoint(ICanvas canvas, UnitPoint point)
{
return null;
}
public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint point, List<IDrawObject> otherobjs, Type[] runningsnaptypes, Type usersnaptype)
{
return null;
}
public void Move(UnitPoint offset)
{
m_p1.X += offset.X;
m_p1.Y += offset.Y;
}
public virtual string GetInfoAsString()
{
return string.Format("{1:D3} {0}@{2}",
this.Type,
No + 1,
P1.PosAsString());
}
#endregion
#region ISerialize
public void GetObjectData(XmlWriter wr)
{
wr.WriteStartElement("Dot");
XmlUtil.WriteProperties(this, wr);
wr.WriteEndElement();
}
public virtual string GetObjectData()
{
string jsonString = string.Empty;
var options = new JsonSerializerOptions { WriteIndented = true };
try {
jsonString += JsonSerializer.Serialize(this, options);
} catch {
}
return jsonString;
}
public void AfterSerializedIn()
{
}
#endregion
}
}