mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
序列化继续整理
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
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 ConnectorPointModel : SelectableViewModelBase
|
||||
{
|
||||
public ConnectorPointModel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ConnectorPointModel(PointBase point) : this()
|
||||
{
|
||||
X = point.X;
|
||||
Y = point.Y;
|
||||
}
|
||||
|
||||
public ConnectorPointModel(double x, double y) : this()
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public ConnectorPointModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ConnectorPointModel(IDiagramViewModel root, string json) : base(root, json)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
ColorViewModel = new ColorViewModel()
|
||||
{
|
||||
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
|
||||
FillColor = new ColorObject() { Color = Colors.Lavender },
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(root, designerbase);
|
||||
|
||||
if (designerbase is ConnectorPointItem designer)
|
||||
{
|
||||
X = designer.X;
|
||||
Y = designer.Y;
|
||||
ConnectorWidth = designer.ConnectorWidth;
|
||||
ConnectorHeight = designer.ConnectorHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public override SelectableItemBase ToXmlObject()
|
||||
{
|
||||
return new ConnectorPointItem(this);
|
||||
}
|
||||
|
||||
public override Type ToXmlType()
|
||||
{
|
||||
return typeof(ConnectorPointItem);
|
||||
}
|
||||
|
||||
/// <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; }
|
||||
}
|
||||
|
||||
public static ConnectorPointModel operator -(ConnectorPointModel a, ConnectorPointModel b)
|
||||
{
|
||||
return new ConnectorPointModel(a.X - b.X, a.Y - b.Y);
|
||||
}
|
||||
public static ConnectorPointModel operator +(ConnectorPointModel a, ConnectorPointModel b)
|
||||
{
|
||||
return new ConnectorPointModel(a.X + b.X, a.Y + b.Y);
|
||||
}
|
||||
|
||||
public static implicit operator ConnectorPointModel(PointBase point)
|
||||
{
|
||||
return new ConnectorPointModel(point);
|
||||
}
|
||||
|
||||
public static implicit operator PointBase(ConnectorPointModel pointInfoBase)
|
||||
{
|
||||
return new PointBase(pointInfoBase.X, pointInfoBase.Y);
|
||||
}
|
||||
|
||||
public static List<ConnectorPointModel> ToList(List<PointBase> lst)
|
||||
{
|
||||
return lst.Select(p => (ConnectorPointModel)p).ToList();
|
||||
}
|
||||
|
||||
public override string ToString() => $"ConnectorPoint(x={X}, y={Y})";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user