Files
aistudio-wpf-diagram/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/ConnectorPoint.cs

170 lines
4.0 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
2023-01-12 23:02:53 +08:00
using AIStudio.Wpf.DiagramDesigner.Geometrys;
2022-10-28 22:45:39 +08:00
namespace AIStudio.Wpf.DiagramDesigner
{
2023-01-08 09:22:37 +08:00
public class ConnectorPoint : BindableBase
{
2023-01-08 09:22:37 +08:00
public ConnectorPoint()
{
ColorViewModel = new ColorViewModel()
{
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
FillColor = new ColorObject() { Color = Colors.Lavender },
};
}
2023-01-08 09:22:37 +08:00
public ConnectorPoint(PointBase point) : this()
{
X = point.X;
Y = point.Y;
}
2023-01-08 09:22:37 +08:00
public ConnectorPoint(double x, double y) : this()
2023-01-07 11:32:01 +08:00
{
X = x;
Y = y;
}
2023-01-08 09:22:37 +08:00
/// <summary>
/// 中间X
/// </summary>
private double _x;
public double X
{
get
{
return _x;
}
set
{
if(SetProperty(ref _x, value))
{
RaisePropertyChanged(nameof(Left));
}
}
}
2023-01-08 09:22:37 +08:00
/// <summary>
/// 中间Y
/// </summary>
private double _y;
public double Y
{
get
{
return _y;
}
set
{
if (SetProperty(ref _y, value))
{
RaisePropertyChanged(nameof(Top));
}
}
}
2023-01-08 09:22:37 +08:00
/// <summary>
/// 边界Left
/// </summary>
public double Left
{
get
{
return X - ConnectorWidth / 2;
}
}
2023-01-08 09:22:37 +08:00
/// <summary>
/// 边界Top
/// </summary>
public double Top
{
get
{
return Y - ConnectorHeight / 2;
}
}
2023-01-21 22:01:10 +08:00
public virtual PointBase Position
2023-01-08 09:22:37 +08:00
{
get
{
return new PointBase(Left, Top);
}
}
2023-01-21 23:25:42 +08:00
public virtual PointBase MiddlePosition => new PointBase(X, Y);
2023-01-08 09:22:37 +08:00
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);
}
2023-01-22 21:46:59 +08:00
}
private IFontViewModel _fontViewModel;
public IFontViewModel FontViewModel
{
get
{
return _fontViewModel;
}
set
{
SetProperty(ref _fontViewModel, value);
}
}
2023-01-07 11:32:01 +08:00
2023-01-08 09:22:37 +08:00
public static ConnectorPoint operator -(ConnectorPoint a, ConnectorPoint b)
2023-01-07 11:32:01 +08:00
{
2023-01-08 09:22:37 +08:00
return new ConnectorPoint(a.X - b.X, a.Y - b.Y);
2023-01-07 11:32:01 +08:00
}
2023-01-08 09:22:37 +08:00
public static ConnectorPoint operator +(ConnectorPoint a, ConnectorPoint b)
2023-01-07 11:32:01 +08:00
{
2023-01-08 09:22:37 +08:00
return new ConnectorPoint(a.X + b.X, a.Y + b.Y);
2023-01-07 11:32:01 +08:00
}
2023-01-08 09:22:37 +08:00
public static implicit operator ConnectorPoint(PointBase point)
{
2023-01-08 09:22:37 +08:00
return new ConnectorPoint(point);
}
2023-01-08 09:22:37 +08:00
public static implicit operator PointBase(ConnectorPoint pointInfoBase)
{
2023-01-08 09:22:37 +08:00
return new PointBase(pointInfoBase.X, pointInfoBase.Y);
}
2023-01-08 09:22:37 +08:00
public static List<ConnectorPoint> ToList(List<PointBase> lst)
{
2023-01-08 09:22:37 +08:00
return lst.Select(p => (ConnectorPoint)p).ToList();
}
2023-01-07 11:32:01 +08:00
2023-01-08 09:22:37 +08:00
public override string ToString() => $"ConnectorPoint(x={X}, y={Y})";
}
}