Portless序列化

This commit is contained in:
艾竹
2023-01-27 20:43:41 +08:00
parent e8bd6faa21
commit 6d1960a8df
9 changed files with 120 additions and 36 deletions

View File

@@ -10,16 +10,17 @@ namespace AIStudio.Wpf.DiagramDesigner
{
public class FullyCreatedConnectorInfo : ConnectorInfoBase
{
public FullyCreatedConnectorInfo(DesignerItemViewModelBase dataItem, ConnectorOrientation orientation, bool isInnerPoint = false, ValueTypePoint valueTypePoint = 0)
: this(null, dataItem, orientation, isInnerPoint, valueTypePoint)
public FullyCreatedConnectorInfo(DesignerItemViewModelBase dataItem, ConnectorOrientation orientation, bool isInnerPoint = false, bool isPortless = false, ValueTypePoint valueTypePoint = 0)
: this(null, dataItem, orientation, isInnerPoint, isPortless, valueTypePoint)
{
}
public FullyCreatedConnectorInfo(IDiagramViewModel root, DesignerItemViewModelBase dataItem, ConnectorOrientation orientation, bool isInnerPoint = false, ValueTypePoint valueTypePoint = 0)
public FullyCreatedConnectorInfo(IDiagramViewModel root, DesignerItemViewModelBase dataItem, ConnectorOrientation orientation, bool isInnerPoint = false, bool isPortless = false, ValueTypePoint valueTypePoint = 0)
: base(root, orientation)
{
this.Parent = dataItem;
this.IsInnerPoint = isInnerPoint;
this.IsPortless = IsPortless;
this.ValueTypePoint = valueTypePoint;
if (IsInnerPoint == true)
{
@@ -69,6 +70,7 @@ namespace AIStudio.Wpf.DiagramDesigner
XRatio = designer.XRatio;
YRatio = designer.YRatio;
IsInnerPoint = designer.IsInnerPoint;
IsPortless = designer.IsPortless;
ValueTypePoint = designer.ValueTypePoint;
}
}
@@ -231,18 +233,30 @@ namespace AIStudio.Wpf.DiagramDesigner
{
return XRatio;
}
else if (IsPortless)
{
return 0.5;
}
else
{
switch (Orientation)
{
case ConnectorOrientation.Top:
return 0.5;
case ConnectorOrientation.Left:
return 0;
case ConnectorOrientation.Bottom:
case ConnectorOrientation.TopLeft:
return 0;
case ConnectorOrientation.Top:
return 0.5;
case ConnectorOrientation.TopRight:
return 1;
case ConnectorOrientation.Right:
return 1;
case ConnectorOrientation.BottomRight:
return 1;
case ConnectorOrientation.Bottom:
return 0.5;
case ConnectorOrientation.BottomLeft:
return 0;
default: return XRatio;
}
}
@@ -254,18 +268,30 @@ namespace AIStudio.Wpf.DiagramDesigner
{
return YRatio;
}
else if (IsPortless)
{
return 0.5;
}
else
{
switch (Orientation)
{
case ConnectorOrientation.Top:
return 0;
case ConnectorOrientation.Left:
return 0.5;
case ConnectorOrientation.Bottom:
return 1;
case ConnectorOrientation.TopLeft:
return 0;
case ConnectorOrientation.Top:
return 0;
case ConnectorOrientation.TopRight:
return 0;
case ConnectorOrientation.Right:
return 0.5;
case ConnectorOrientation.BottomRight:
return 1;
case ConnectorOrientation.Bottom:
return 1;
case ConnectorOrientation.BottomLeft:
return 1;
default: return YRatio;
}
}

View File

@@ -1479,11 +1479,11 @@ namespace AIStudio.Wpf.DiagramDesigner
connectionItem.SinkType = System.Type.GetType(connectionItem.SinkTypeName);
DesignerItemViewModelBase sourceItem = GetConnectorDataItem(this, connectionItem.SourceId, connectionItem.SourceType);
ConnectorOrientation sourceConnectorOrientation = connectionItem.SourceOrientation;
FullyCreatedConnectorInfo sourceConnectorInfo = GetFullConnectorInfo(connectionItem.Id, sourceItem, sourceConnectorOrientation, connectionItem.SourceXRatio, connectionItem.SourceYRatio, connectionItem.SourceInnerPoint);
FullyCreatedConnectorInfo sourceConnectorInfo = GetFullConnectorInfo(connectionItem.Id, sourceItem, sourceConnectorOrientation, connectionItem.SourceXRatio, connectionItem.SourceYRatio, connectionItem.SourceInnerPoint, connectionItem.SourceIsPortless);
DesignerItemViewModelBase sinkItem = GetConnectorDataItem(this, connectionItem.SinkId, connectionItem.SinkType);
ConnectorOrientation sinkConnectorOrientation = connectionItem.SinkOrientation;
FullyCreatedConnectorInfo sinkConnectorInfo = GetFullConnectorInfo(connectionItem.Id, sinkItem, sinkConnectorOrientation, connectionItem.SinkXRatio, connectionItem.SinkYRatio, connectionItem.SinkInnerPoint);
FullyCreatedConnectorInfo sinkConnectorInfo = GetFullConnectorInfo(connectionItem.Id, sinkItem, sinkConnectorOrientation, connectionItem.SinkXRatio, connectionItem.SinkYRatio, connectionItem.SinkInnerPoint, connectionItem.SinkIsPortless);
ConnectionViewModel connectionVM = new ConnectionViewModel(this, sourceConnectorInfo, sinkConnectorInfo, connectionItem);
connectors.Add(connectionVM);
@@ -1514,24 +1514,36 @@ namespace AIStudio.Wpf.DiagramDesigner
return dataItem;
}
private FullyCreatedConnectorInfo GetFullConnectorInfo(Guid connectorId, DesignerItemViewModelBase dataItem, ConnectorOrientation connectorOrientation, double xRatio, double yRatio, bool isInnerPoint)
private FullyCreatedConnectorInfo GetFullConnectorInfo(Guid connectorId, DesignerItemViewModelBase dataItem, ConnectorOrientation connectorOrientation, double xRatio, double yRatio, bool isInnerPoint, bool isPortless)
{
if (isInnerPoint)
{
return dataItem.Connectors.Where(p => p.XRatio == xRatio && p.YRatio == yRatio).FirstOrDefault();
}
else if (isPortless)
{
return dataItem.PortlessConnector;
}
else
{
switch (connectorOrientation)
{
case ConnectorOrientation.Top:
return dataItem.TopConnector;
case ConnectorOrientation.Left:
return dataItem.LeftConnector;
case ConnectorOrientation.TopLeft:
return dataItem.TopLeftConnector;
case ConnectorOrientation.Top:
return dataItem.TopConnector;
case ConnectorOrientation.TopRight:
return dataItem.TopRightConnector;
case ConnectorOrientation.Right:
return dataItem.RightConnector;
case ConnectorOrientation.BottomRight:
return dataItem.BottomRightConnector;
case ConnectorOrientation.Bottom:
return dataItem.BottomConnector;
case ConnectorOrientation.BottomLeft:
return dataItem.BottomLeftConnector;
default:
throw new InvalidOperationException(