using System;
using System.ComponentModel;
using System.Drawing;
using Newtonsoft.Json;
namespace AGVNavigationCore.Models
{
///
/// 맵 상의 마그넷(Magnet) 정보를 나타내는 클래스
///
public class MapMagnet : NodeBase
{
public MapMagnet() {
Type = NodeType.Magnet;
}
[Category("위치 정보")]
[Description("시작점 좌표")]
public MagnetPoint P1 { get; set; } = new MagnetPoint();
[Category("위치 정보")]
[Description("끝점 좌표")]
public MagnetPoint P2 { get; set; } = new MagnetPoint();
[Category("위치 정보")]
[Description("제어점 좌표 (곡선인 경우)")]
public MagnetPoint ControlPoint { get; set; } = null;
public class MagnetPoint
{
public double X { get; set; }
public double Y { get; set; }
}
[JsonIgnore]
public override Point Position
{
get => new Point((int)P1.X, (int)P1.Y);
set
{
double dx = value.X - P1.X;
double dy = value.Y - P1.Y;
P1.X += dx;
P1.Y += dy;
P2.X += dx;
P2.Y += dy;
if (ControlPoint != null)
{
ControlPoint.X += dx;
ControlPoint.Y += dy;
}
}
}
///
/// 시작점 Point 반환 및 설정
///
[Browsable(false)]
[JsonIgnore]
public Point StartPoint
{
get => new Point((int)P1.X, (int)P1.Y);
set { P1.X = value.X; P1.Y = value.Y; }
}
///
/// 끝점 Point 반환 및 설정
///
[Browsable(false)]
[JsonIgnore]
public Point EndPoint
{
get => new Point((int)P2.X, (int)P2.Y);
set { P2.X = value.X; P2.Y = value.Y; }
}
public override string ToString()
{
if (ControlPoint == null)
{
return $"[LINE] ({P1.X:F0},{P1.Y:F0}) -> ({P2.X:F0},{P2.Y:F0})";
}
else
{
return $"[CURVE] ({P1.X:F0},{P1.Y:F0}) -> ({P2.X:F0},{P2.Y:F0})";
}
}
}
}