准备添加中间端点

This commit is contained in:
艾竹
2023-01-15 11:59:51 +08:00
parent 717cc43827
commit 7d77864311
19 changed files with 1440 additions and 117 deletions

View File

@@ -11,7 +11,11 @@ namespace AIStudio.Wpf.DiagramDesigner
{
if (value is ArrowPathStyle arrowStyle)
{
return ArrowPathData.Arrow[(int)arrowStyle];
return ArrowPathData.Arrow[arrowStyle];
}
else if (value is string)
{
return value;
}
return null;
}

View File

@@ -7,16 +7,9 @@ namespace AIStudio.Wpf.DiagramDesigner
public enum ArrowPathStyle
{
None,
Arrow1,
Arrow2,
Arrow3,
Arrow4,
Arrow5,
Arrow6,
Arrow7,
Arrow8,
Arrow9,
Arrow10,
Arrow11,
Arrow,
Circle,
Square,
}
}

View File

@@ -4,8 +4,8 @@ namespace AIStudio.Wpf.DiagramDesigner
{
public class PathGeneratorResult
{
public PathGeneratorResult(string[] paths, double? sourceMarkerAngle = null, PointBase? sourceMarkerPosition = null,
double? targetMarkerAngle = null, PointBase? targetMarkerPosition = null)
public PathGeneratorResult(string[] paths, double sourceMarkerAngle, PointBase sourceMarkerPosition,
double targetMarkerAngle, PointBase targetMarkerPosition)
{
Paths = paths;
SourceMarkerAngle = sourceMarkerAngle;
@@ -15,9 +15,9 @@ namespace AIStudio.Wpf.DiagramDesigner
}
public string[] Paths { get; }
public double? SourceMarkerAngle { get; }
public PointBase? SourceMarkerPosition { get; }
public double? TargetMarkerAngle { get; }
public PointBase? TargetMarkerPosition { get; }
public double SourceMarkerAngle { get; }
public PointBase SourceMarkerPosition { get; }
public double TargetMarkerAngle { get; }
public PointBase TargetMarkerPosition { get; }
}
}

View File

@@ -15,11 +15,9 @@ namespace AIStudio.Wpf.DiagramDesigner
return CurveThroughPoints(route, link);
route = GetRouteWithMiddlePoints(_, link, route);
double? sourceAngle = null;
double? targetAngle = null;
sourceAngle = SourceMarkerAdjustement(route, link.ColorViewModel.LeftArrowPathStyle == ArrowPathStyle.None ? 0d : (double)link.ColorViewModel.LeftArrowSizeStyle);
targetAngle = TargetMarkerAdjustement(route, link.ColorViewModel.RightArrowPathStyle == ArrowPathStyle.None ? 0d : (double)link.ColorViewModel.RightArrowPathStyle);
double sourceAngle = SourceMarkerAdjustement(route, link.ColorViewModel.LeftArrowPathStyle == ArrowPathStyle.None ? 0d : (double)link.ColorViewModel.LeftArrowSizeStyle);
double targetAngle = TargetMarkerAdjustement(route, link.ColorViewModel.RightArrowPathStyle == ArrowPathStyle.None ? 0d : (double)link.ColorViewModel.RightArrowPathStyle);
DoShift(route, link);

View File

@@ -18,11 +18,9 @@ namespace AIStudio.Wpf.DiagramDesigner
route = GetRouteWithFullConnectionLine(_, link, route);
else
route = GetRouteWithPartConnectionLine(_, link, route);
double? sourceAngle = null;
double? targetAngle = null;
sourceAngle = SourceMarkerAdjustement(route, link.ColorViewModel.LeftArrowPathStyle == ArrowPathStyle.None ? 0d : (double)link.ColorViewModel.LeftArrowSizeStyle);
targetAngle = TargetMarkerAdjustement(route, link.ColorViewModel.RightArrowPathStyle == ArrowPathStyle.None ? 0d : (double)link.ColorViewModel.RightArrowPathStyle);
double sourceAngle = SourceMarkerAdjustement(route, link.ColorViewModel.LeftArrowPathStyle == ArrowPathStyle.None ? 0d : (double)link.ColorViewModel.LeftArrowSizeStyle);
double targetAngle = TargetMarkerAdjustement(route, link.ColorViewModel.RightArrowPathStyle == ArrowPathStyle.None ? 0d : (double)link.ColorViewModel.RightArrowPathStyle);
DoShift(route, link);

View File

@@ -16,11 +16,9 @@ namespace AIStudio.Wpf.DiagramDesigner
return CurveThroughPoints(route, link);
route = GetRouteWithCurvePoints(link, route);
double? sourceAngle = null;
double? targetAngle = null;
sourceAngle = SourceMarkerAdjustement(route, link.ColorViewModel.LeftArrowPathStyle == ArrowPathStyle.None ? 0d : (double)link.ColorViewModel.LeftArrowSizeStyle);
targetAngle = TargetMarkerAdjustement(route, link.ColorViewModel.RightArrowPathStyle == ArrowPathStyle.None ? 0d : (double)link.ColorViewModel.RightArrowPathStyle);
double sourceAngle = SourceMarkerAdjustement(route, link.ColorViewModel.LeftArrowPathStyle == ArrowPathStyle.None ? 0d : (double)link.ColorViewModel.LeftArrowSizeStyle);
double targetAngle = TargetMarkerAdjustement(route, link.ColorViewModel.RightArrowPathStyle == ArrowPathStyle.None ? 0d : (double)link.ColorViewModel.RightArrowPathStyle);
DoShift(route, link);
@@ -30,11 +28,8 @@ namespace AIStudio.Wpf.DiagramDesigner
private static PathGeneratorResult CurveThroughPoints(PointBase[] route, ConnectorViewModel link)
{
double? sourceAngle = null;
double? targetAngle = null;
sourceAngle = SourceMarkerAdjustement(route, (double)link.ColorViewModel.LeftArrowSizeStyle);
targetAngle = TargetMarkerAdjustement(route, (double)link.ColorViewModel.RightArrowPathStyle);
double sourceAngle = SourceMarkerAdjustement(route, (double)link.ColorViewModel.LeftArrowSizeStyle);
double targetAngle = TargetMarkerAdjustement(route, (double)link.ColorViewModel.RightArrowPathStyle);
BezierSpline.GetCurveControlPoints(route, out var firstControlPoints, out var secondControlPoints);
var paths = new string[firstControlPoints.Length];

View File

@@ -8,11 +8,9 @@ namespace AIStudio.Wpf.DiagramDesigner
public static PathGeneratorResult Straight(IDiagramViewModel _, ConnectorViewModel link, PointBase[] route, PointBase source, PointBase target)
{
route = ConcatRouteAndSourceAndTarget(route, source, target);
double? sourceAngle = null;
double? targetAngle = null;
sourceAngle = SourceMarkerAdjustement(route, (double)link.ColorViewModel.LeftArrowSizeStyle);
targetAngle = TargetMarkerAdjustement(route, (double)link.ColorViewModel.RightArrowPathStyle);
double sourceAngle = SourceMarkerAdjustement(route, (double)link.ColorViewModel.LeftArrowSizeStyle);
double targetAngle = TargetMarkerAdjustement(route, (double)link.ColorViewModel.RightArrowPathStyle);
DoShift(route, link);

View File

@@ -6,20 +6,12 @@ namespace AIStudio.Wpf.DiagramDesigner
{
public class ArrowPathData
{
public static readonly List<string> Arrow = new List<string>()
public static readonly Dictionary<ArrowPathStyle, string> Arrow = new Dictionary<ArrowPathStyle, string>()
{
"",
"M0,10 L5,0 10,10 z",
"M832 664c0 10.752-3.968 20.096-11.904 28.096C812.096 700.096 802.752 704 792 704l-560 0c-10.816 0-20.16-3.904-28.096-11.904C195.904 684.096 192 674.752 192 664s3.904-20.096 11.904-28.096l280-280C491.84 348.032 501.184 344 512 344c10.752 0 20.096 3.968 28.096 11.904l280 280C828.032 643.904 832 653.248 832 664z",
"M691.626667 682.666667H332.373333a75.093333 75.093333 0 0 1-67.84-42.666667 89.6 89.6 0 0 1 11.093334-94.293333l179.626666-217.6a75.093333 75.093333 0 0 1 113.493334 0l179.626666 217.6A89.6 89.6 0 0 1 759.466667 640a75.093333 75.093333 0 0 1-67.84 42.666667z",
"M171.64288 701.41952a47.18592 47.18592 0 0 1 4.11648-57.344l276.70528-310.12864a79.60576 79.60576 0 0 1 119.05024 0l276.72576 310.10816a47.18592 47.18592 0 0 1 3.072 58.83904c-11.30496 15.29856-32.768 18.45248-47.9232 7.04512l-255.488-192.14336a59.65824 59.65824 0 0 0-71.80288 0l-255.488 192.14336a34.05824 34.05824 0 0 1-48.9472-8.54016z",
"M119.466667 827.733333L512 435.2l392.533333 392.533333 119.466667-119.466666-512-512-512 512z",
"M957.44 772.813L509.952 391.066 66.97 772.608 0 694.886 509.542 256 1024 694.784z",
"M828.47744 660.7872a81.7152 81.7152 0 0 1-62.48448 28.89728 81.73568 81.73568 0 0 1-52.98176-19.47648l-172.46208-146.45248-172.4416 146.45248a81.94048 81.94048 0 0 1-106.06592-124.86656l225.4848-191.50848a81.89952 81.89952 0 0 1 106.06592 0l225.4848 191.50848a81.85856 81.85856 0 0 1 9.40032 115.44576z",
"M256.917333 780.288c-40.725333 40.405333-106.645333 40.512-147.264 0.192l-36.373333-36.096a103.36 103.36 0 0 1 0.085333-146.944l350.421334-347.754667a125.290667 125.290667 0 0 1 176.490666 0l350.4 347.754667a103.466667 103.466667 0 0 1 0.085334 146.944l-36.352 36.096c-40.682667 40.362667-106.56 40.192-147.264-0.192L512.021333 527.104 256.917333 780.288z m225.066667-343.594667a42.666667 42.666667 0 0 1 60.096 0l285.184 283.029334a19.328 19.328 0 0 0 27.029333 0.192l36.352-36.096a18.154667 18.154667 0 0 0-0.064-25.813334L540.16 310.250667a39.957333 39.957333 0 0 0-56.256 0L133.482667 658.005333a18.026667 18.026667 0 0 0-0.085334 25.813334l36.373334 36.096a19.349333 19.349333 0 0 0 27.029333-0.192L481.962667 436.693333z",
"M67.969 562.046c0 23.955 19.441 43.396 43.396 43.396 10.773 0 20.33-4.346 27.937-10.86l0.425 0.425 2.235-2.235c0.044-0.044 0.067-0.063 0.112-0.106l358.336-358.338c6.256-6.239 16.377-6.239 22.61 0l360.685 360.679 0.658-0.659c7.647 6.685 17.356 11.093 28.3 11.093 23.935 0 43.374-19.441 43.374-43.396 0-15.289-8.389-28.084-20.355-35.812-0.724-1.344-0.576-2.983-1.705-4.112l-410.958-410.948c-6.234-6.244-16.354-6.244-22.61 0l-410.95 410.949c-1.279 1.279-1.172 3.108-1.916 4.641-11.522 7.794-19.571 20.336-19.571 35.283zM67.969 874.116c0 23.955 19.441 43.394 43.396 43.394 10.773 0 20.33-4.342 27.937-10.855l0.425 0.425 2.235-2.235c0.044-0.045 0.067-0.065 0.112-0.109l358.336-358.339c6.256-6.239 16.377-6.239 22.61 0l360.685 360.684 0.658-0.66c7.647 6.685 17.356 11.091 28.3 11.091 23.935 0 43.374-19.439 43.374-43.394 0-15.289-8.389-28.087-20.355-35.815-0.724-1.341-0.576-2.98-1.705-4.109l-410.958-410.951c-6.234-6.239-16.354-6.239-22.61 0l-410.95 410.953c-1.279 1.277-1.172 3.107-1.916 4.641-11.522 7.794-19.571 20.334-19.571 35.282z",
"M548.010667 233.088c-15.658667-24.576-56.32-24.576-72.021334 0l-298.666666 469.333333a42.794667 42.794667 0 0 0-1.408 43.477334c7.509333 13.610667 21.845333 22.101333 37.418666 22.101333h597.333334a42.709333 42.709333 0 0 0 36.010666-65.621333l-298.666666-469.290667zM291.029333 682.666667L512 335.488 732.970667 682.666667H291.029333z",
"M512.1 511.2m-447.3 0a447.3 447.3 0 1 0 894.6 0 447.3 447.3 0 1 0-894.6 0Z",
{ ArrowPathStyle.None, "" },
{ ArrowPathStyle.Arrow, "M 0 -5 10 0 0 5 z" },
{ ArrowPathStyle.Circle, "M 0, 0 a 5,5 0 1,0 10,0 a 5,5 0 1,0 -10,0" },
{ ArrowPathStyle.Square, "M 0 -5 10 -5 10 5 0 5 z" },
};
}
}

View File

@@ -530,6 +530,7 @@
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="删除" Command="{Binding DeleteConnectionCommand}" CommandParameter="{Binding}"/>
<MenuItem Header="插入点(按住ctrl可一直插入)" IsCheckable="True" IsChecked="{Binding ShouldInsertAnchor}" />
</ContextMenu>
</Grid.ContextMenu>
@@ -568,7 +569,7 @@
VerticalAlignment="Top"
RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform>
<RotateTransform x:Name="rightrot" />
<RotateTransform x:Name="rightrot" Angle="{Binding EndAngle}"/>
</Path.RenderTransform>
</Path>
@@ -586,7 +587,7 @@
VerticalAlignment="Top"
RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform>
<RotateTransform x:Name="leftrot" />
<RotateTransform x:Name="leftrot" Angle="{Binding StartAngle}"/>
</Path.RenderTransform>
</Path>
</Canvas>
@@ -615,7 +616,11 @@
</Style>
</s:PointContainer.Resources>
</s:PointContainer>
<Rectangle Fill="#7F243859" Opacity="0.5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Visibility="{Binding ShouldInsertAnchor, Converter={StaticResource BooleanToVisibilityConverter}}">
<i:Interaction.Behaviors>
<s:ControlMouseLeftButtonDownCommandBehavior Command="{Binding AddVertexCommand}" />
</i:Interaction.Behaviors>
</Rectangle>
</Grid>
<DataTemplate.Triggers>
<DataTrigger Value="True"
@@ -634,54 +639,53 @@
Value="Visible"/>
</DataTrigger>
<DataTrigger Value="True"
Binding="{Binding IsSelected}">
<Setter TargetName="poly"
Property="Stroke"
Value="Black" />
<Setter TargetName="rightarrow"
Property="Stroke"
Value="Black" />
<Setter TargetName="rightarrow"
Property="Fill"
Value="Black" />
<Setter TargetName="PART_PointContainer"
Property="Visibility"
Value="Visible"/>
</DataTrigger>
<DataTrigger Value="True"
Binding="{Binding ShouldInsertAnchor}">
<Setter TargetName="PART_PointContainer"
Property="Visibility"
Value="Visible"/>
</DataTrigger>
<!--右箭头-->
<DataTrigger Binding="{Binding Path=SinkConnectorInfo.Orientation}"
Value="Left">
<Setter TargetName="rightarrow"
Property="Margin"
Value="-10,-5,0,0" />
<Setter TargetName="rightarrow"
Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="90" />
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Path=SinkConnectorInfo.Orientation}"
Value="Top">
<Setter TargetName="rightarrow"
Property="Margin"
Value="-5,-10,0,0" />
<Setter TargetName="rightarrow"
Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="180" />
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Path=SinkConnectorInfo.Orientation}"
Value="Right">
<Setter TargetName="rightarrow"
Property="Margin"
Value="0,-5,0,0" />
<Setter TargetName="rightarrow"
Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="-90" />
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Path=SinkConnectorInfo.Orientation}"
Value="Bottom">
<Setter TargetName="rightarrow"
Property="Margin"
Value="-5,0,0,0" />
<Setter TargetName="rightarrow"
Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="0" />
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Path=ColorViewModel.RightArrowPathStyle}" Value="None">
<Setter TargetName="rightarrow" Property="Visibility" Value="Hidden"/>
@@ -693,48 +697,24 @@
<Setter TargetName="leftarrow"
Property="Margin"
Value="-10,-5,0,0" />
<Setter TargetName="leftarrow"
Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="90" />
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Path=SourceConnectorInfo.Orientation}"
Value="Top">
<Setter TargetName="leftarrow"
Property="Margin"
Value="-5,-10,0,0" />
<Setter TargetName="leftarrow"
Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="180" />
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Path=SourceConnectorInfo.Orientation}"
Value="Right">
<Setter TargetName="leftarrow"
Property="Margin"
Value="0,-5,0,0" />
<Setter TargetName="leftarrow"
Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="-90" />
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Path=SourceConnectorInfo.Orientation}"
Value="Bottom">
<Setter TargetName="leftarrow"
Property="Margin"
Value="-5,0,0,0" />
<Setter TargetName="leftarrow"
Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="0" />
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Path=ColorViewModel.LeftArrowPathStyle}" Value="None">
<Setter TargetName="leftarrow" Property="Visibility" Value="Hidden"/>

View File

@@ -138,7 +138,7 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
private ArrowPathStyle _rightArrowPathStyle = ArrowPathStyle.Arrow1;
private ArrowPathStyle _rightArrowPathStyle = ArrowPathStyle.Arrow;
public ArrowPathStyle RightArrowPathStyle
{
get

View File

@@ -1,7 +1,10 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Input;
//using System.Windows;
using System.Windows.Media;
using AIStudio.Wpf.DiagramDesigner.Geometrys;
@@ -44,6 +47,7 @@ namespace AIStudio.Wpf.DiagramDesigner
this.SourceConnectorInfo = sourceConnectorInfo;
this.SinkConnectorInfo = sinkConnectorInfo;
DeleteConnectionCommand = new SimpleCommand(DeleteConnection);
AddVertexCommand = new SimpleCommand(AddVertex);
if (Parent != null && Parent.ColorViewModel != null)
{
@@ -106,8 +110,8 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
private List<ConnectorPoint> _connectionPoints;
public List<ConnectorPoint> ConnectionPoints
private ObservableCollection<ConnectorPoint> _connectionPoints = new ObservableCollection<ConnectorPoint>();
public ObservableCollection<ConnectorPoint> ConnectionPoints
{
get
{
@@ -117,12 +121,18 @@ namespace AIStudio.Wpf.DiagramDesigner
{
if (_connectionPoints != null)
{
_connectionPoints.ForEach(p => p.PropertyChanged -= new WeakINPCEventHandler(ConnectionPoint_PropertyChanged).Handler);
foreach (var connectionPoint in _connectionPoints)
{
connectionPoint.PropertyChanged -= new WeakINPCEventHandler(ConnectionPoint_PropertyChanged).Handler;
}
}
SetProperty(ref _connectionPoints, value);
if (_connectionPoints != null)
{
_connectionPoints.ForEach(p => p.PropertyChanged += new WeakINPCEventHandler(ConnectionPoint_PropertyChanged).Handler);
foreach (var connectionPoint in _connectionPoints)
{
connectionPoint.PropertyChanged += new WeakINPCEventHandler(ConnectionPoint_PropertyChanged).Handler;
}
}
}
}
@@ -153,6 +163,32 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
private double _startAngle;
public double StartAngle
{
get
{
return _startAngle;
}
private set
{
SetProperty(ref _startAngle, value);
}
}
private double _endAngle;
public double EndAngle
{
get
{
return _endAngle;
}
private set
{
SetProperty(ref _endAngle, value);
}
}
private RectangleBase _area;
public RectangleBase Area
{
@@ -204,6 +240,19 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
private bool _shouldInsertAnchor;
public bool ShouldInsertAnchor
{
get
{
return _shouldInsertAnchor;
}
set
{
SetProperty(ref _shouldInsertAnchor, value);
}
}
//待完善这两处
public List<LinkVertexModel> Vertices { get; } = new List<LinkVertexModel>();
public List<LinkLabelModel> Labels { get; set; } = new List<LinkLabelModel>();
@@ -307,8 +356,10 @@ namespace AIStudio.Wpf.DiagramDesigner
return;
PathGeneratorResult = PathGenerator.Get(Parent, this, route, source.Value, target.Value);
StartPoint = PathGeneratorResult.SourceMarkerPosition ?? new PointBase();
EndPoint = PathGeneratorResult.TargetMarkerPosition ?? new PointBase();
StartPoint = PathGeneratorResult.SourceMarkerPosition;
EndPoint = PathGeneratorResult.TargetMarkerPosition;
StartAngle = PathGeneratorResult.SourceMarkerAngle;
EndAngle = PathGeneratorResult.TargetMarkerAngle;
}
private void ConnectorViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -346,6 +397,11 @@ namespace AIStudio.Wpf.DiagramDesigner
get; set;
}
public SimpleCommand AddVertexCommand
{
get; set;
}
private void DeleteConnection(object args)
{
if (this.Parent is IDiagramViewModel)
@@ -355,6 +411,19 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
private void AddVertex(object parameter)
{
MouseButtonEventArgs mosueArg = ((EventToCommandArgs)parameter).EventArgs as MouseButtonEventArgs;
var position = mosueArg.GetPosition(((EventToCommandArgs)parameter).Sender as IInputElement);
ConnectionPoints.Add(new ConnectorPoint(position.X, position.Y));
if (!((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control))
{
ShouldInsertAnchor = false;
}
}
protected override void ExecuteEditCommand(object param)
{
if (this.OutTextItem != null) return;