mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-01 22:56:35 +08:00
暂时存一版
This commit is contained in:
@@ -30,7 +30,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
else
|
||||
{
|
||||
RaisePropertyChanged(nameof(SourceMarker));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,10 +77,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public class LinkMarker : BindableBase, ILinkMarker
|
||||
{
|
||||
public static LinkMarker None { get; } = new LinkMarker("", 10, ArrowPathStyle.None, ArrowSizeStyle.Middle);
|
||||
public static LinkMarker Arrow { get; } = new LinkMarker("M 0 -5 10 0 0 5 z", 10, ArrowPathStyle.Arrow, ArrowSizeStyle.Middle);
|
||||
public static LinkMarker Circle { get; } = new LinkMarker("M 0, 0 a 5,5 0 1,0 10,0 a 5,5 0 1,0 -10,0", 10, ArrowPathStyle.Circle, ArrowSizeStyle.Middle);
|
||||
public static LinkMarker Square { get; } = new LinkMarker("M 0 -5 10 -5 10 5 0 5 z", 10, ArrowPathStyle.Square, ArrowSizeStyle.Middle);
|
||||
public static LinkMarker None { get; } = new LinkMarker("", 10, 10, ArrowPathStyle.None, ArrowSizeStyle.Middle);
|
||||
public static LinkMarker Arrow { get; } = new LinkMarker("M 0 -5 10 0 0 5 z", 10, 10, ArrowPathStyle.Arrow, ArrowSizeStyle.Middle);
|
||||
public static LinkMarker Circle { get; } = new LinkMarker("M 0, 0 a 5,5 0 1,0 10,0 a 5,5 0 1,0 -10,0", 10, 10, ArrowPathStyle.Circle, ArrowSizeStyle.Middle);
|
||||
public static LinkMarker Square { get; } = new LinkMarker("M 0 -5 10 -5 10 5 0 5 z", 10, 10, ArrowPathStyle.Square, ArrowSizeStyle.Middle);
|
||||
|
||||
public static readonly Dictionary<ArrowPathStyle, string> ArrowDictionary = new Dictionary<ArrowPathStyle, string>()
|
||||
{
|
||||
@@ -95,10 +95,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
}
|
||||
|
||||
public LinkMarker(string path, double width, ArrowPathStyle arrowPathStyle, ArrowSizeStyle arrowSizeStyle)
|
||||
public LinkMarker(string path, double width, double height, ArrowPathStyle arrowPathStyle, ArrowSizeStyle arrowSizeStyle)
|
||||
{
|
||||
Path = path;
|
||||
Width = width;
|
||||
Height = height;
|
||||
_pathStyle = arrowPathStyle;
|
||||
_sizeStyle = arrowSizeStyle;
|
||||
}
|
||||
@@ -112,7 +113,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _path, value);
|
||||
SetProperty(ref _path, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,6 +130,19 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private double _height;
|
||||
public double Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return _height;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _height, value);
|
||||
}
|
||||
}
|
||||
|
||||
private ArrowPathStyle _pathStyle = ArrowPathStyle.None;
|
||||
public ArrowPathStyle PathStyle
|
||||
{
|
||||
@@ -165,13 +179,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
|
||||
public static LinkMarker NewArrow(double width, double height)
|
||||
=> new LinkMarker(FormattableString.Invariant($"M 0 -{height / 2} {width} 0 0 {height / 2}"), width, ArrowPathStyle.Arrow, (ArrowSizeStyle)width);
|
||||
=> new LinkMarker(FormattableString.Invariant($"M 0 -{height / 2} {width} 0 0 {height / 2}"), width, height, ArrowPathStyle.Arrow, (ArrowSizeStyle)width);
|
||||
|
||||
public static LinkMarker NewCircle(double r)
|
||||
=> new LinkMarker(FormattableString.Invariant($"M 0, 0 a {r},{r} 0 1,0 {r * 2},0 a {r},{r} 0 1,0 -{r * 2},0"), r * 2, ArrowPathStyle.Circle, (ArrowSizeStyle)(r * 2));
|
||||
=> new LinkMarker(FormattableString.Invariant($"M 0, 0 a {r},{r} 0 1,0 {r * 2},0 a {r},{r} 0 1,0 -{r * 2},0"), r * 2, r * 2, ArrowPathStyle.Circle, (ArrowSizeStyle)(r * 2));
|
||||
|
||||
public static LinkMarker NewRectangle(double width, double height)
|
||||
=> new LinkMarker(FormattableString.Invariant($"M 0 -{height / 2} {width} -{height / 2} {width} {height / 2} 0 {height / 2} z"), width, ArrowPathStyle.Square, (ArrowSizeStyle)width);
|
||||
=> new LinkMarker(FormattableString.Invariant($"M 0 -{height / 2} {width} -{height / 2} {width} {height / 2} 0 {height / 2} z"), width, height, ArrowPathStyle.Square, (ArrowSizeStyle)width);
|
||||
|
||||
public static LinkMarker NewSquare(double size) => NewRectangle(size, size);
|
||||
}
|
||||
@@ -188,6 +202,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
get; set;
|
||||
}
|
||||
|
||||
double Height
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
ArrowPathStyle PathStyle
|
||||
{
|
||||
get; set;
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
protected virtual void Init(FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo)
|
||||
{
|
||||
this.Root = sourceConnectorInfo.DataItem.Root;
|
||||
|
||||
|
||||
if (sinkConnectorInfo is FullyCreatedConnectorInfo sink && sink.DataItem.ShowArrow == false)
|
||||
{
|
||||
this.ShapeViewModel.SinkMarker = LinkMarker.None;
|
||||
@@ -416,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)
|
||||
@@ -520,74 +520,36 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
PathGeneratorResult = PathGenerator.Get(Root, this, route, source.Value, target.Value);
|
||||
|
||||
if (IsFullConnection)
|
||||
{
|
||||
//修正旋转
|
||||
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)
|
||||
{
|
||||
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
|
||||
var offsetX = Math.Sin(EndAngle / 180 * Math.PI) * GetSinkMarkerWidth() / 2;
|
||||
var offsetY = Math.Cos(EndAngle / 180 * Math.PI) * GetSinkMarkerHeight() / 2;
|
||||
if (PathGeneratorResult.Last1.X - PathGeneratorResult.Last2.X < -0.000001d)
|
||||
{
|
||||
StartPoint = PathGeneratorResult.SourceMarkerPosition;
|
||||
EndPoint = PathGeneratorResult.TargetMarkerPosition;
|
||||
offsetX += GetSinkMarkerWidth();
|
||||
}
|
||||
if (PathGeneratorResult.Last1.Y - PathGeneratorResult.Last2.Y < -0.000001d)
|
||||
{
|
||||
offsetY += GetSinkMarkerHeight();
|
||||
}
|
||||
|
||||
StartPoint = PathGeneratorResult.SourceMarkerPosition;
|
||||
EndPoint = new PointBase
|
||||
(
|
||||
PathGeneratorResult.TargetMarkerPosition.X - Math.Abs(offsetX),
|
||||
PathGeneratorResult.TargetMarkerPosition.Y - Math.Abs(offsetY)
|
||||
);
|
||||
|
||||
//StartPoint = new PointBase
|
||||
// (
|
||||
// Math.Min(PathGeneratorResult.SourceMarkerPosition.X, source.Value.X),
|
||||
// Math.Min(PathGeneratorResult.SourceMarkerPosition.Y, source.Value.Y)
|
||||
// );
|
||||
//EndPoint = new PointBase
|
||||
// (
|
||||
// Math.Min(PathGeneratorResult.TargetMarkerPosition.X, target.Value.X),
|
||||
// Math.Min(PathGeneratorResult.TargetMarkerPosition.Y, target.Value.Y)
|
||||
// );
|
||||
|
||||
StartAngle = PathGeneratorResult.SourceMarkerAngle;
|
||||
EndAngle = PathGeneratorResult.TargetMarkerAngle;
|
||||
|
||||
@@ -613,7 +575,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (SourceConnectorInfo.DataItem == null || (IsFullConnection && SinkConnectorInfoFully.DataItem == null))
|
||||
return (null, null);
|
||||
|
||||
|
||||
var sourceCenter = SourceConnectorInfo.IsPortless ? SourceConnectorInfo.DataItem.GetBounds().Center : SourceConnectorInfo.MiddlePosition;
|
||||
var targetCenter = SinkConnectorInfoFully?.IsPortless == true ? SinkConnectorInfoFully?.DataItem?.GetBounds().Center ?? OnGoingPosition : SinkConnectorInfoFully?.MiddlePosition ?? OnGoingPosition;
|
||||
var firstPt = route.Length > 0 ? route[0] : targetCenter;
|
||||
@@ -625,7 +587,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
var sourceIntersection = GetClosestPointTo(sourceIntersections, firstPt);
|
||||
var targetIntersection = GetClosestPointTo(targetIntersections, secondPt);
|
||||
|
||||
return (sourceIntersection ?? sourceCenter,targetIntersection ?? targetCenter);
|
||||
return (sourceIntersection ?? sourceCenter, targetIntersection ?? targetCenter);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -634,7 +596,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return (source, target);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private PointBase? GetPortPositionBasedOnAlignment(ConnectorInfoBase port, ArrowSizeStyle marker)
|
||||
@@ -697,22 +659,40 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public double GetSourceMarkerWidth()
|
||||
{
|
||||
if (string.IsNullOrEmpty(ShapeViewModel.SourceMarker.Path))
|
||||
if (!IsFullConnection || string.IsNullOrEmpty(ShapeViewModel.SourceMarker.Path))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return ShapeViewModel.SourceMarker.Width;
|
||||
}
|
||||
|
||||
public double GetSourceMarkerHeight()
|
||||
{
|
||||
if (!IsFullConnection || string.IsNullOrEmpty(ShapeViewModel.SourceMarker.Path))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return ShapeViewModel.SourceMarker.Height;
|
||||
}
|
||||
|
||||
public double GetSinkMarkerWidth()
|
||||
{
|
||||
if (string.IsNullOrEmpty(ShapeViewModel.SinkMarker.Path))
|
||||
if (!IsFullConnection || string.IsNullOrEmpty(ShapeViewModel.SinkMarker.Path))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return ShapeViewModel.SinkMarker.Width;
|
||||
}
|
||||
|
||||
public double GetSinkMarkerHeight()
|
||||
{
|
||||
if (!IsFullConnection || string.IsNullOrEmpty(ShapeViewModel.SinkMarker.Path))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return ShapeViewModel.SinkMarker.Height;
|
||||
}
|
||||
|
||||
#region 双击添加
|
||||
private void AddVertex(object parameter)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user