mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
暂时存一版
This commit is contained in:
@@ -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