mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-05 08:46:34 +08:00
分离逻辑与常规连接点
This commit is contained in:
@@ -51,8 +51,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
protected virtual void Init(FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo)
|
||||
{
|
||||
this.Root = sourceConnectorInfo.DataItem.Root;
|
||||
|
||||
this.ColorViewModel.FillColor.Color = Colors.Red;
|
||||
|
||||
if (sinkConnectorInfo is FullyCreatedConnectorInfo sink && sink.DataItem.ShowArrow == false)
|
||||
{
|
||||
this.ShapeViewModel.SinkMarker = LinkMarker.None;
|
||||
@@ -417,14 +416,14 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
break;
|
||||
case nameof(SourceConnectorInfo):
|
||||
SourceA = PointHelper.GetPointForConnector(SourceConnectorInfo);
|
||||
(SourceConnectorInfo.DataItem as INotifyPropertyChanged).PropertyChanged += new WeakINPCEventHandler(ConnectorViewModel_PropertyChanged).Handler;
|
||||
(SourceConnectorInfo.DataItem as INotifyPropertyChanged).PropertyChanged += new WeakINPCEventHandler(ConnectorViewModel_PropertyChanged).Handler;
|
||||
break;
|
||||
case nameof(SinkConnectorInfo):
|
||||
SourceB = SinkConnectorInfo.Position;
|
||||
if (SinkConnectorInfo is FullyCreatedConnectorInfo)
|
||||
{
|
||||
(((FullyCreatedConnectorInfo)SinkConnectorInfo).DataItem as INotifyPropertyChanged).PropertyChanged += new WeakINPCEventHandler(ConnectorViewModel_PropertyChanged).Handler;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case nameof(IsSelected):
|
||||
if (IsSelected == false)
|
||||
@@ -521,67 +520,74 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
PathGeneratorResult = PathGenerator.Get(Root, this, route, source.Value, target.Value);
|
||||
|
||||
//修正旋转
|
||||
switch (SourceConnectorInfo.Orientation)
|
||||
if (IsFullConnection)
|
||||
{
|
||||
case ConnectorOrientation.Left:
|
||||
{
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X, PathGeneratorResult.SourceMarkerPosition.Y - GetSourceMarkerWidth() / 2);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Top:
|
||||
{
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X - GetSourceMarkerWidth() / 2, PathGeneratorResult.SourceMarkerPosition.Y);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Right:
|
||||
{
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X - GetSourceMarkerWidth(), PathGeneratorResult.SourceMarkerPosition.Y - GetSourceMarkerWidth() / 2);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Bottom:
|
||||
{
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X - GetSourceMarkerWidth() / 2, PathGeneratorResult.SourceMarkerPosition.Y - GetSourceMarkerWidth());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
StartPoint = PathGeneratorResult.SourceMarkerPosition;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//修正旋转
|
||||
switch (SourceConnectorInfo.Orientation)
|
||||
{
|
||||
case ConnectorOrientation.Left:
|
||||
{
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X, PathGeneratorResult.SourceMarkerPosition.Y - GetSourceMarkerWidth() / 2);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Top:
|
||||
{
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X - GetSourceMarkerWidth() / 2, PathGeneratorResult.SourceMarkerPosition.Y);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Right:
|
||||
{
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X - GetSourceMarkerWidth(), PathGeneratorResult.SourceMarkerPosition.Y - GetSourceMarkerWidth() / 2);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Bottom:
|
||||
{
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X - GetSourceMarkerWidth() / 2, PathGeneratorResult.SourceMarkerPosition.Y - GetSourceMarkerWidth());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
StartPoint = PathGeneratorResult.SourceMarkerPosition;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//修正旋转
|
||||
switch (SinkConnectorInfo.Orientation)
|
||||
//修正旋转
|
||||
switch (SinkConnectorInfo.Orientation)
|
||||
{
|
||||
case ConnectorOrientation.Left:
|
||||
{
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X, PathGeneratorResult.TargetMarkerPosition.Y - GetSinkMarkerWidth() / 2);
|
||||
break;
|
||||
}
|
||||
|
||||
case ConnectorOrientation.Top:
|
||||
{
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X - GetSinkMarkerWidth() / 2, PathGeneratorResult.TargetMarkerPosition.Y);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Right:
|
||||
{
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X - GetSinkMarkerWidth(), PathGeneratorResult.TargetMarkerPosition.Y - GetSinkMarkerWidth() / 2);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Bottom:
|
||||
{
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X - GetSinkMarkerWidth() / 2, PathGeneratorResult.TargetMarkerPosition.Y - GetSinkMarkerWidth());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
EndPoint = PathGeneratorResult.TargetMarkerPosition;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
case ConnectorOrientation.Left:
|
||||
{
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X, PathGeneratorResult.TargetMarkerPosition.Y - GetSinkMarkerWidth() / 2);
|
||||
break;
|
||||
}
|
||||
|
||||
case ConnectorOrientation.Top:
|
||||
{
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X - GetSinkMarkerWidth() / 2, PathGeneratorResult.TargetMarkerPosition.Y);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Right:
|
||||
{
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X - GetSinkMarkerWidth(), PathGeneratorResult.TargetMarkerPosition.Y - GetSinkMarkerWidth() / 2);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Bottom:
|
||||
{
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X - GetSinkMarkerWidth() / 2, PathGeneratorResult.TargetMarkerPosition.Y - GetSinkMarkerWidth());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
EndPoint = PathGeneratorResult.TargetMarkerPosition;
|
||||
break;
|
||||
}
|
||||
StartPoint = PathGeneratorResult.SourceMarkerPosition;
|
||||
EndPoint = PathGeneratorResult.TargetMarkerPosition;
|
||||
}
|
||||
|
||||
StartAngle = PathGeneratorResult.SourceMarkerAngle;
|
||||
EndAngle = PathGeneratorResult.TargetMarkerAngle;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
this.Parent = dataItem;
|
||||
this.IsInnerPoint = isInnerPoint;
|
||||
this.IsPortless = IsPortless;
|
||||
this.ValueTypePoint = valueTypePoint;
|
||||
|
||||
if (IsInnerPoint == true)
|
||||
{
|
||||
BuildMenuOptions();
|
||||
@@ -71,7 +71,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
YRatio = designer.YRatio;
|
||||
IsInnerPoint = designer.IsInnerPoint;
|
||||
IsPortless = designer.IsPortless;
|
||||
ValueTypePoint = designer.ValueTypePoint;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,19 +149,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
get; set;
|
||||
}
|
||||
|
||||
public ValueTypePoint _valueTypePoint;
|
||||
public ValueTypePoint ValueTypePoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return _valueTypePoint;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _valueTypePoint, value);
|
||||
}
|
||||
}
|
||||
|
||||
private Style _style;
|
||||
public Style Style
|
||||
{
|
||||
@@ -191,6 +177,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
public void ExecuteMenuItemCommand(object arg)
|
||||
{
|
||||
Orientation = (ConnectorOrientation)arg;
|
||||
DataItem.Left += 0.1;
|
||||
DataItem.Left -= 0.1;
|
||||
}
|
||||
|
||||
public void ExecuteDeleteCommand(object arg)
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class LogicalConnectorInfo : FullyCreatedConnectorInfo
|
||||
{
|
||||
public LogicalConnectorInfo(DesignerItemViewModelBase dataItem, ConnectorOrientation orientation, bool isInnerPoint = false, bool isPortless = false, ValueTypePoint valueTypePoint = ValueTypePoint.Real) : base(dataItem, orientation, isInnerPoint, isPortless, valueTypePoint)
|
||||
{
|
||||
}
|
||||
|
||||
public LogicalConnectorInfo(IDiagramViewModel root, DesignerItemViewModelBase dataItem, ConnectorOrientation orientation, bool isInnerPoint = false, bool isPortless = false, ValueTypePoint valueTypePoint = ValueTypePoint.Real) : base(root, dataItem, orientation, isInnerPoint, isPortless, valueTypePoint)
|
||||
{
|
||||
this.ValueTypePoint = valueTypePoint;
|
||||
}
|
||||
|
||||
public LogicalConnectorInfo(IDiagramViewModel root, DesignerItemViewModelBase dataItem, SelectableItemBase designer) : base(root, dataItem, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public LogicalConnectorInfo(IDiagramViewModel root, DesignerItemViewModelBase dataItem, SerializableItem serializableItem, string serializableType) : base(root, dataItem, serializableItem, serializableType)
|
||||
{
|
||||
}
|
||||
|
||||
public override SelectableItemBase GetSerializableObject()
|
||||
{
|
||||
return new LogicalConnectorInfoItem(this);
|
||||
}
|
||||
|
||||
protected override void LoadDesignerItemViewModel(SelectableItemBase designerbase)
|
||||
{
|
||||
base.LoadDesignerItemViewModel(designerbase);
|
||||
|
||||
if (designerbase is LogicalConnectorInfoItem designer)
|
||||
{
|
||||
ValueTypePoint = designer.ValueTypePoint;
|
||||
}
|
||||
}
|
||||
|
||||
public ValueTypePoint _valueTypePoint;
|
||||
public ValueTypePoint ValueTypePoint
|
||||
{
|
||||
get
|
||||
{
|
||||
return _valueTypePoint;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _valueTypePoint, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,17 +43,16 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
|
||||
protected override void Init(IDiagramViewModel root)
|
||||
{
|
||||
{
|
||||
base.Init(root);
|
||||
|
||||
ClearConnectors();
|
||||
//propertyChangedSubscription = WhenPropertyChanged.Where(o => o.ToString() == "Left" || o.ToString() == "Top" || o.ToString() == "ItemWidth" || o.ToString() == "ItemHeight").Subscribe(ChangeImageElement);
|
||||
//connectorsChangedSubscription = WhenConnectorsChanged.Subscribe(OnConnectorsChanged);
|
||||
|
||||
BuildMenuOptions();
|
||||
|
||||
|
||||
AddItemCommand = new SimpleCommand(Command_Enable, ExecuteAddItemCommand);
|
||||
ImageSwitchCommand = new SimpleCommand(Command_Enable, ExecuteImageSwitchCommand);
|
||||
BuildMenuOptions();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
foreach (var connector in designer.Connectors)
|
||||
{
|
||||
FullyCreatedConnectorInfo fullyCreatedConnectorInfo = new FullyCreatedConnectorInfo(this.Root, this, connector);
|
||||
LogicalConnectorInfo fullyCreatedConnectorInfo = new LogicalConnectorInfo(this.Root, this, connector);
|
||||
|
||||
if (fullyCreatedConnectorInfo.Orientation == ConnectorOrientation.Left)
|
||||
{
|
||||
@@ -213,8 +213,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
public LogicalType LogicalType { get; set; }
|
||||
|
||||
|
||||
public Dictionary<int, FullyCreatedConnectorInfo> Input { get; set; } = new Dictionary<int, FullyCreatedConnectorInfo>();
|
||||
public Dictionary<int, FullyCreatedConnectorInfo> Output { get; set; } = new Dictionary<int, FullyCreatedConnectorInfo>();
|
||||
public Dictionary<int, LogicalConnectorInfo> Input { get; set; } = new Dictionary<int, LogicalConnectorInfo>();
|
||||
public Dictionary<int, LogicalConnectorInfo> Output { get; set; } = new Dictionary<int, LogicalConnectorInfo>();
|
||||
|
||||
public virtual void ExecuteAddInput(object parameter, int index = 0)
|
||||
{
|
||||
@@ -222,7 +222,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
this.ItemHeight = this.ItemHeight * (Input.Values.Count + 1) / Input.Values.Count;
|
||||
}
|
||||
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Left, true, false, ValueTypeInput.Count > index ? ValueTypeInput[index] : ValueTypeInput[0]);
|
||||
LogicalConnectorInfo connector = new LogicalConnectorInfo(this, ConnectorOrientation.Left, true, false, ValueTypeInput.Count > index ? ValueTypeInput[index] : ValueTypeInput[0]);
|
||||
connector.XRatio = 0;
|
||||
Input.Add(Input.Count, connector);
|
||||
for (int i = 0; i < Input.Values.Count; i++)
|
||||
@@ -234,7 +234,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public virtual void ExecuteAddOutput(object parameter, int index = 0)
|
||||
{
|
||||
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Right, true, false, ValueTypeOutput.Count > index ? ValueTypeOutput[index] : ValueTypeInput[0]);
|
||||
LogicalConnectorInfo connector = new LogicalConnectorInfo(this, ConnectorOrientation.Right, true, false, ValueTypeOutput.Count > index ? ValueTypeOutput[index] : ValueTypeInput[0]);
|
||||
connector.XRatio = 1;
|
||||
Output.Add(Output.Count, connector);
|
||||
for (int i = 0; i < Output.Values.Count; i++)
|
||||
|
||||
Reference in New Issue
Block a user