mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-04 08:40:51 +08:00
箭头分离到独立的model中,方便自定义path
This commit is contained in:
@@ -53,17 +53,14 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
protected virtual void Init(FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo)
|
||||
{
|
||||
this.Root = sourceConnectorInfo.DataItem.Root;
|
||||
|
||||
if (Root != null && Root.ColorViewModel != null)
|
||||
{
|
||||
this.ColorViewModel = CopyHelper.Mapper(Root.ColorViewModel);
|
||||
}
|
||||
|
||||
this.ColorViewModel.FillColor.Color = Colors.Red;
|
||||
if (sinkConnectorInfo is FullyCreatedConnectorInfo sink && sink.DataItem.ShowArrow == false)
|
||||
{
|
||||
this.ColorViewModel.RightArrowPathStyle = ArrowPathStyle.None;
|
||||
this.ShapeViewModel.SinkMarker = LinkMarker.None;
|
||||
}
|
||||
ColorViewModel.PropertyChanged += ConnectorViewModel_PropertyChanged;
|
||||
this.ColorViewModel.PropertyChanged += ConnectorViewModel_PropertyChanged;
|
||||
this.ShapeViewModel.PropertyChanged += ConnectorViewModel_PropertyChanged;
|
||||
this.PropertyChanged += ConnectorViewModel_PropertyChanged;
|
||||
|
||||
var routetype = GlobalType.AllTypes.Where(p => typeof(IRouter).IsAssignableFrom(p)).FirstOrDefault(p => p.Name == RouterMode);
|
||||
@@ -76,7 +73,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
this.SinkConnectorInfo = sinkConnectorInfo;
|
||||
DeleteConnectionCommand = new SimpleCommand(Command_Enable, DeleteConnection);
|
||||
AddVertexCommand = new SimpleCommand(Command_Enable, AddVertex);
|
||||
AddLabelCommand = new SimpleCommand(Command_Enable, AddLabel);
|
||||
AddLabelCommand = new SimpleCommand(Command_Enable, para => AddLabel());
|
||||
}
|
||||
|
||||
protected override void LoadDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designerbase)
|
||||
@@ -452,12 +449,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
}
|
||||
}
|
||||
else if (sender is ColorViewModel)
|
||||
else if (sender is ShapeViewModel)
|
||||
{
|
||||
if (e.PropertyName == nameof(ColorViewModel.LeftArrowPathStyle) ||
|
||||
e.PropertyName == nameof(ColorViewModel.LeftArrowSizeStyle) ||
|
||||
e.PropertyName == nameof(ColorViewModel.RightArrowPathStyle) ||
|
||||
e.PropertyName == nameof(ColorViewModel.RightArrowSizeStyle))
|
||||
if (e.PropertyName == nameof(ShapeViewModel.SourceMarker) ||
|
||||
e.PropertyName == nameof(ShapeViewModel.SinkMarker))
|
||||
{
|
||||
UpdatePathGeneratorResult();
|
||||
}
|
||||
@@ -536,22 +531,22 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
case ConnectorOrientation.Left:
|
||||
{
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X, PathGeneratorResult.SourceMarkerPosition.Y - ColorViewModel.LeftArrowSize / 2);
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X, PathGeneratorResult.SourceMarkerPosition.Y - GetSourceMarkerWidth() / 2);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Top:
|
||||
{
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X - ColorViewModel.LeftArrowSize / 2, PathGeneratorResult.SourceMarkerPosition.Y);
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X - GetSourceMarkerWidth() / 2, PathGeneratorResult.SourceMarkerPosition.Y);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Right:
|
||||
{
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X - ColorViewModel.LeftArrowSize, PathGeneratorResult.SourceMarkerPosition.Y - ColorViewModel.LeftArrowSize / 2);
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X - GetSourceMarkerWidth(), PathGeneratorResult.SourceMarkerPosition.Y - GetSourceMarkerWidth() / 2);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Bottom:
|
||||
{
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X - ColorViewModel.LeftArrowSize / 2, PathGeneratorResult.SourceMarkerPosition.Y - ColorViewModel.LeftArrowSize);
|
||||
StartPoint = new PointBase(PathGeneratorResult.SourceMarkerPosition.X - GetSourceMarkerWidth() / 2, PathGeneratorResult.SourceMarkerPosition.Y - GetSourceMarkerWidth());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -566,23 +561,23 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
case ConnectorOrientation.Left:
|
||||
{
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X, PathGeneratorResult.TargetMarkerPosition.Y - ColorViewModel.RightArrowSize / 2);
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X, PathGeneratorResult.TargetMarkerPosition.Y - GetSinkMarkerWidth() / 2);
|
||||
break;
|
||||
}
|
||||
|
||||
case ConnectorOrientation.Top:
|
||||
{
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X - ColorViewModel.RightArrowSize / 2, PathGeneratorResult.TargetMarkerPosition.Y);
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X - GetSinkMarkerWidth() / 2, PathGeneratorResult.TargetMarkerPosition.Y);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Right:
|
||||
{
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X - ColorViewModel.RightArrowSize, PathGeneratorResult.TargetMarkerPosition.Y - ColorViewModel.RightArrowSize / 2);
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X - GetSinkMarkerWidth(), PathGeneratorResult.TargetMarkerPosition.Y - GetSinkMarkerWidth() / 2);
|
||||
break;
|
||||
}
|
||||
case ConnectorOrientation.Bottom:
|
||||
{
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X - ColorViewModel.RightArrowSize / 2, PathGeneratorResult.TargetMarkerPosition.Y - ColorViewModel.RightArrowSize);
|
||||
EndPoint = new PointBase(PathGeneratorResult.TargetMarkerPosition.X - GetSinkMarkerWidth() / 2, PathGeneratorResult.TargetMarkerPosition.Y - GetSinkMarkerWidth());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -686,6 +681,34 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return minPoint;
|
||||
}
|
||||
|
||||
public void SetSourcePort(FullyCreatedConnectorInfo port)
|
||||
{
|
||||
SourceConnectorInfo = port;
|
||||
}
|
||||
|
||||
public void SetSinkPort(FullyCreatedConnectorInfo port)
|
||||
{
|
||||
SinkConnectorInfo = port;
|
||||
}
|
||||
|
||||
public double GetSourceMarkerWidth()
|
||||
{
|
||||
if (string.IsNullOrEmpty(ShapeViewModel.SourceMarker.Path))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return ShapeViewModel.SourceMarker.Width;
|
||||
}
|
||||
|
||||
public double GetSinkMarkerWidth()
|
||||
{
|
||||
if (string.IsNullOrEmpty(ShapeViewModel.SinkMarker.Path))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return ShapeViewModel.SinkMarker.Width;
|
||||
}
|
||||
|
||||
#region 双击添加
|
||||
private void AddVertex(object parameter)
|
||||
{
|
||||
@@ -708,9 +731,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
AddLabel();
|
||||
}
|
||||
|
||||
public void AddLabel(object text = null)
|
||||
public void AddLabel(string text = null, double? distance = null, PointBase? offset = null)
|
||||
{
|
||||
var label = new ConnectorLabelModel(this, text?.ToString());
|
||||
var label = new ConnectorLabelModel(this, text?.ToString(), distance, offset);
|
||||
label.PropertyChanged += new WeakINPCEventHandler(ConnectorViewModel_PropertyChanged).Handler;
|
||||
label.IsSelected = true;
|
||||
Labels.Add(label);
|
||||
|
||||
Reference in New Issue
Block a user