Files
aistudio-wpf-diagram/AIStudio.Wpf.DiagramDesigner/Models/Serializables/ConnectionItem.cs
2023-01-22 22:10:39 +08:00

127 lines
3.6 KiB
C#

using AIStudio.Wpf.DiagramDesigner;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Xml.Serialization;
namespace AIStudio.Wpf.DiagramDesigner
{
[Serializable]
[XmlInclude(typeof(ConnectionItem))]
public class ConnectionItem : SelectableDesignerItemBase
{
public ConnectionItem()
{
}
public ConnectionItem(ConnectorViewModel viewmodel) : base(viewmodel)
{
this.SourceId = viewmodel.SourceConnectorInfo.DataItem.Id;
this.SourceOrientation = viewmodel.SourceConnectorInfo.Orientation;
this.SourceType = viewmodel.SourceConnectorInfo.DataItem.GetType();
this.SourceTypeName = viewmodel.SourceConnectorInfo.DataItem.GetType().FullName;
this.SourceXRatio = viewmodel.SourceConnectorInfo.GetXRatioFromConnector();
this.SourceYRatio = viewmodel.SourceConnectorInfo.GetYRatioFromConnector();
this.SourceInnerPoint = viewmodel.SourceConnectorInfo.IsInnerPoint;
this.SinkId = viewmodel.SinkConnectorInfoFully.DataItem.Id;
this.SinkOrientation = viewmodel.SinkConnectorInfoFully.Orientation;
this.SinkType = viewmodel.SinkConnectorInfoFully.DataItem.GetType();
this.SinkTypeName = viewmodel.SinkConnectorInfoFully.DataItem.GetType().FullName;
this.SinkXRatio = viewmodel.SinkConnectorInfoFully.GetXRatioFromConnector();
this.SinkYRatio = viewmodel.SinkConnectorInfoFully.GetYRatioFromConnector();
this.SinkInnerPoint = viewmodel.SinkConnectorInfoFully.IsInnerPoint;
this.RouterMode = viewmodel.RouterMode;
this.PathMode = viewmodel.PathMode;
this.Vertices = viewmodel.Vertices.Select(p => (Point)p.MiddlePosition).ToList();
}
[XmlAttribute]
public Guid SourceId { get; set; }
[XmlAttribute]
public ConnectorOrientation SourceOrientation { get; set; }
[XmlIgnore]
public Type SourceType { get; set; }
[XmlAttribute]
public string SourceTypeName { get; set; }
[XmlAttribute]
public double SourceXRatio { get; set; }
[XmlAttribute]
public double SourceYRatio { get; set; }
[XmlAttribute]
public bool SourceInnerPoint { get; set; }
[XmlAttribute]
public Guid SinkId { get; set; }
[XmlAttribute]
public ConnectorOrientation SinkOrientation { get; set; }
[XmlIgnore]
public Type SinkType { get; set; }
[XmlAttribute]
public string SinkTypeName { get; set; }
[XmlAttribute]
public double SinkXRatio { get; set; }
[XmlAttribute]
public double SinkYRatio { get; set; }
[XmlAttribute]
public bool SinkInnerPoint { get; set; }
[XmlAttribute]
public string RouterMode
{
get; set;
}
[XmlAttribute]
public string PathMode
{
get; set;
}
[XmlIgnore]
public List<Point> Vertices
{
get; set;
}
[JsonIgnore]
[XmlAttribute("Vertices")]
public string XmlVertices
{
get
{
return SerializeHelper.SerializePointList(Vertices);
}
set
{
Vertices = SerializeHelper.DeserializePointList(value);
}
}
[XmlArray]
public List<ConnectorLabelItem> Connectors
{
get; set;
}
}
}