Files
aistudio-wpf-diagram/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/ConnectorPoint.cs
艾竹 ad227aee0c xx
2023-01-21 23:25:42 +08:00

157 lines
3.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using AIStudio.Wpf.DiagramDesigner.Geometrys;
namespace AIStudio.Wpf.DiagramDesigner
{
public class ConnectorPoint : BindableBase
{
public ConnectorPoint()
{
ColorViewModel = new ColorViewModel()
{
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
FillColor = new ColorObject() { Color = Colors.Lavender },
};
}
public ConnectorPoint(PointBase point) : this()
{
X = point.X;
Y = point.Y;
}
public ConnectorPoint(double x, double y) : this()
{
X = x;
Y = y;
}
/// <summary>
/// 中间X
/// </summary>
private double _x;
public double X
{
get
{
return _x;
}
set
{
if(SetProperty(ref _x, value))
{
RaisePropertyChanged(nameof(Left));
}
}
}
/// <summary>
/// 中间Y
/// </summary>
private double _y;
public double Y
{
get
{
return _y;
}
set
{
if (SetProperty(ref _y, value))
{
RaisePropertyChanged(nameof(Top));
}
}
}
/// <summary>
/// 边界Left
/// </summary>
public double Left
{
get
{
return X - ConnectorWidth / 2;
}
}
/// <summary>
/// 边界Top
/// </summary>
public double Top
{
get
{
return Y - ConnectorHeight / 2;
}
}
public virtual PointBase Position
{
get
{
return new PointBase(Left, Top);
}
}
public virtual PointBase MiddlePosition => new PointBase(X, Y);
private double connectorWidth = 8;
public double ConnectorWidth
{
get { return connectorWidth; }
set { connectorWidth = value; }
}
private double connectorHeight = 8;
public double ConnectorHeight
{
get { return connectorHeight; }
set { connectorHeight = value; }
}
private IColorViewModel _colorViewModel;
public IColorViewModel ColorViewModel
{
get
{
return _colorViewModel;
}
set
{
SetProperty(ref _colorViewModel, value);
}
}
public static ConnectorPoint operator -(ConnectorPoint a, ConnectorPoint b)
{
return new ConnectorPoint(a.X - b.X, a.Y - b.Y);
}
public static ConnectorPoint operator +(ConnectorPoint a, ConnectorPoint b)
{
return new ConnectorPoint(a.X + b.X, a.Y + b.Y);
}
public static implicit operator ConnectorPoint(PointBase point)
{
return new ConnectorPoint(point);
}
public static implicit operator PointBase(ConnectorPoint pointInfoBase)
{
return new PointBase(pointInfoBase.X, pointInfoBase.Y);
}
public static List<ConnectorPoint> ToList(List<PointBase> lst)
{
return lst.Select(p => (ConnectorPoint)p).ToList();
}
public override string ToString() => $"ConnectorPoint(x={X}, y={Y})";
}
}