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

219 lines
5.3 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;
2023-01-25 11:11:27 +08:00
using AIStudio.Wpf.DiagramDesigner.Models;
2022-10-28 22:45:39 +08:00
namespace AIStudio.Wpf.DiagramDesigner
{
2023-01-24 16:20:39 +08:00
public class ConnectorPointModel : SelectableViewModelBase
{
2023-01-27 14:54:03 +08:00
public ConnectorPointModel() : this(null)
{
}
2023-01-27 14:54:03 +08:00
public ConnectorPointModel(IDiagramViewModel root) : base(root)
2023-01-07 11:32:01 +08:00
{
2023-01-27 14:54:03 +08:00
2023-01-07 11:32:01 +08:00
}
2023-01-24 17:53:04 +08:00
public ConnectorPointModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
{
}
2023-01-25 11:11:27 +08:00
public ConnectorPointModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
2023-01-24 17:53:04 +08:00
{
}
2023-01-27 14:54:03 +08:00
public ConnectorPointModel(PointBase point) : this()
{
X = point.X;
Y = point.Y;
}
public ConnectorPointModel(double x, double y) : this()
{
X = x;
Y = y;
}
2023-01-25 11:11:27 +08:00
public override SelectableItemBase GetSerializableObject()
{
return new ConnectorPointItem(this);
}
2023-03-25 11:59:31 +08:00
protected override void Init(IDiagramViewModel root, bool initNew)
{
base.Init(root, initNew);
}
protected override void InitNew()
2023-01-24 16:20:39 +08:00
{
ColorViewModel = new ColorViewModel()
{
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
2023-01-25 14:42:01 +08:00
FillColor = new ColorObject() { Color = Colors.White },
2023-01-24 16:20:39 +08:00
};
}
2023-01-27 14:54:03 +08:00
protected override void LoadDesignerItemViewModel(SelectableItemBase designerbase)
2023-01-24 17:53:04 +08:00
{
2023-01-27 14:54:03 +08:00
base.LoadDesignerItemViewModel(designerbase);
2023-01-24 17:53:04 +08:00
if (designerbase is ConnectorPointItem designer)
{
X = designer.X;
Y = designer.Y;
ConnectorWidth = designer.ConnectorWidth;
ConnectorHeight = designer.ConnectorHeight;
}
}
2023-01-24 17:53:04 +08:00
2023-01-08 09:22:37 +08:00
/// <summary>
/// 中间X
/// </summary>
private double _x;
public double X
{
get
{
return _x;
}
set
{
2023-01-27 14:54:03 +08:00
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
{
2023-01-27 14:54:03 +08:00
get
{
return _connectorWidth;
2023-01-27 14:54:03 +08:00
}
set
{
_connectorWidth = value;
2023-01-27 14:54:03 +08:00
}
}
private double _connectorHeight = 8;
public double ConnectorHeight
{
2023-01-27 14:54:03 +08:00
get
{
return _connectorHeight;
2023-01-27 14:54:03 +08:00
}
set
{
_connectorHeight = value;
}
}
public void SetPosition(PointBase position)
{
X = position.X;
Y = position.Y;
}
private bool _dragStart;
public bool DragStart
{
get
{
return _dragStart;
}
set
{
SetProperty(ref _dragStart, value);
2023-01-27 14:54:03 +08:00
}
}
2023-01-24 16:20:39 +08:00
public static ConnectorPointModel operator -(ConnectorPointModel a, ConnectorPointModel b)
2023-01-07 11:32:01 +08:00
{
2023-01-24 16:20:39 +08:00
return new ConnectorPointModel(a.X - b.X, a.Y - b.Y);
2023-01-07 11:32:01 +08:00
}
2023-01-24 16:20:39 +08:00
public static ConnectorPointModel operator +(ConnectorPointModel a, ConnectorPointModel b)
2023-01-07 11:32:01 +08:00
{
2023-01-24 16:20:39 +08:00
return new ConnectorPointModel(a.X + b.X, a.Y + b.Y);
2023-01-07 11:32:01 +08:00
}
2023-01-24 16:20:39 +08:00
public static implicit operator ConnectorPointModel(PointBase point)
{
2023-01-24 16:20:39 +08:00
return new ConnectorPointModel(point);
}
2023-01-24 16:20:39 +08:00
public static implicit operator PointBase(ConnectorPointModel pointInfoBase)
{
2023-01-08 09:22:37 +08:00
return new PointBase(pointInfoBase.X, pointInfoBase.Y);
}
2023-01-24 16:20:39 +08:00
public static List<ConnectorPointModel> ToList(List<PointBase> lst)
{
2023-01-24 16:20:39 +08:00
return lst.Select(p => (ConnectorPointModel)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})";
}
}