暂时存一版

This commit is contained in:
艾竹
2023-02-04 11:16:39 +08:00
parent 848121ffa2
commit 8bec9b446f
10 changed files with 151 additions and 112 deletions

View File

@@ -5,19 +5,57 @@ namespace AIStudio.Wpf.DiagramDesigner
public class PathGeneratorResult
{
public PathGeneratorResult(string[] paths, double sourceMarkerAngle, PointBase sourceMarkerPosition,
double targetMarkerAngle, PointBase targetMarkerPosition)
double targetMarkerAngle, PointBase targetMarkerPosition, PointBase[] route)
{
Paths = paths;
SourceMarkerAngle = sourceMarkerAngle;
SourceMarkerPosition = sourceMarkerPosition;
TargetMarkerAngle = targetMarkerAngle;
TargetMarkerPosition = targetMarkerPosition;
Route = route;
}
public string[] Paths { get; }
public double SourceMarkerAngle { get; }
public PointBase SourceMarkerPosition { get; }
public double TargetMarkerAngle { get; }
public PointBase TargetMarkerPosition { get; }
public string[] Paths
{
get;
}
public double SourceMarkerAngle
{
get;
}
/// <summary>
/// SourceMarker左上角的点
/// </summary>
public PointBase SourceMarkerPosition
{
get;
}
public double TargetMarkerAngle
{
get;
}
/// <summary>
/// TargetMarker左上角的点
/// </summary>
public PointBase TargetMarkerPosition
{
get;
}
public PointBase[] Route
{
get;
}
public PointBase Last1
{
get => Route[Route.Length - 1];
}
public PointBase Last2
{
get => Route[Route.Length - 2];
}
}
}

View File

@@ -16,8 +16,8 @@ namespace AIStudio.Wpf.DiagramDesigner
route = GetRouteWithMiddlePoints(_, link, route);
double sourceAngle = SourceMarkerAdjustement(route, link.GetSourceMarkerWidth());
double targetAngle = TargetMarkerAdjustement(route, link.GetSinkMarkerWidth());
double sourceAngle = SourceMarkerAdjustement(route, link.GetSourceMarkerWidth(), link.GetSourceMarkerHeight());
double targetAngle = TargetMarkerAdjustement(route, link.GetSinkMarkerWidth(), link.GetSinkMarkerHeight());
DoShift(route, link);
@@ -27,7 +27,7 @@ namespace AIStudio.Wpf.DiagramDesigner
paths[i] = FormattableString.Invariant($"M {route[i].X} {route[i].Y} L {route[i + 1].X} {route[i + 1].Y}");
}
return new PathGeneratorResult(paths, sourceAngle, route[0], targetAngle, route[route.Length - 1]);
return new PathGeneratorResult(paths, sourceAngle, route[0], targetAngle, route[route.Length - 1], route);
}
private static PointBase[] GetRouteWithMiddlePoints(IDiagramViewModel _, ConnectionViewModel link, PointBase[] route)

View File

@@ -19,8 +19,8 @@ namespace AIStudio.Wpf.DiagramDesigner
else
route = GetRouteWithPartConnectionLine(_, link, route);
double sourceAngle = SourceMarkerAdjustement(route, link.GetSourceMarkerWidth());
double targetAngle = TargetMarkerAdjustement(route, link.GetSinkMarkerWidth());
double sourceAngle = SourceMarkerAdjustement(route, link.GetSourceMarkerWidth(), link.GetSourceMarkerHeight());
double targetAngle = TargetMarkerAdjustement(route, link.GetSinkMarkerWidth(), link.GetSinkMarkerHeight());
DoShift(route, link);
@@ -30,7 +30,7 @@ namespace AIStudio.Wpf.DiagramDesigner
paths[i] = FormattableString.Invariant($"M {route[i].X} {route[i].Y} L {route[i + 1].X} {route[i + 1].Y}");
}
return new PathGeneratorResult(paths, sourceAngle, route[0], targetAngle, route[route.Length - 1]);
return new PathGeneratorResult(paths, sourceAngle, route[0], targetAngle, route[route.Length - 1], route);
}
private const int const_margin = 20;

View File

@@ -17,19 +17,19 @@ namespace AIStudio.Wpf.DiagramDesigner
route = GetRouteWithCurvePoints(link, route);
double sourceAngle = SourceMarkerAdjustement(route, link.GetSourceMarkerWidth());
double targetAngle = TargetMarkerAdjustement(route, link.GetSinkMarkerWidth());
double sourceAngle = SourceMarkerAdjustement(route, link.GetSourceMarkerWidth(), link.GetSourceMarkerHeight());
double targetAngle = TargetMarkerAdjustement(route, link.GetSinkMarkerWidth(), link.GetSinkMarkerHeight());
DoShift(route, link);
var path = FormattableString.Invariant($"M {route[0].X} {route[0].Y} C {route[1].X} {route[1].Y}, {route[2].X} {route[2].Y}, {route[3].X} {route[3].Y}");
return new PathGeneratorResult(new[] { path }, sourceAngle, route[0], targetAngle, route[route.Length - 1]);
return new PathGeneratorResult(new[] { path }, sourceAngle, route[0], targetAngle, route[route.Length - 1], route);
}
private static PathGeneratorResult CurveThroughPoints(PointBase[] route, ConnectionViewModel link)
{
double sourceAngle = SourceMarkerAdjustement(route, link.GetSourceMarkerWidth());
double targetAngle = TargetMarkerAdjustement(route, link.GetSinkMarkerWidth());
double sourceAngle = SourceMarkerAdjustement(route, link.GetSourceMarkerWidth(), link.GetSourceMarkerHeight());
double targetAngle = TargetMarkerAdjustement(route, link.GetSinkMarkerWidth(), link.GetSinkMarkerHeight());
BezierSpline.GetCurveControlPoints(route, out var firstControlPoints, out var secondControlPoints);
@@ -47,7 +47,7 @@ namespace AIStudio.Wpf.DiagramDesigner
}
// Todo: adjust marker positions based on closest control points
return new PathGeneratorResult(paths, sourceAngle, route[0], targetAngle, route[route.Length - 1]);
return new PathGeneratorResult(paths, sourceAngle, route[0], targetAngle, route[route.Length - 1], route);
}
private static PointBase[] GetRouteWithCurvePoints(ConnectionViewModel link, PointBase[] route)

View File

@@ -9,8 +9,8 @@ namespace AIStudio.Wpf.DiagramDesigner
{
route = ConcatRouteAndSourceAndTarget(route, source, target);
double sourceAngle = SourceMarkerAdjustement(route, link.GetSourceMarkerWidth());
double targetAngle = TargetMarkerAdjustement(route, link.GetSinkMarkerWidth());
double sourceAngle = SourceMarkerAdjustement(route, link.GetSourceMarkerWidth(), link.GetSourceMarkerHeight());
double targetAngle = TargetMarkerAdjustement(route, link.GetSinkMarkerWidth(), link.GetSinkMarkerHeight());
DoShift(route, link);
@@ -20,7 +20,7 @@ namespace AIStudio.Wpf.DiagramDesigner
paths[i] = FormattableString.Invariant($"M {route[i].X} {route[i].Y} L {route[i + 1].X} {route[i + 1].Y}");
}
return new PathGeneratorResult(paths, sourceAngle, route[0], targetAngle, route[route.Length - 1]);
return new PathGeneratorResult(paths, sourceAngle, route[0], targetAngle, route[route.Length - 1], route);
}
}
}

View File

@@ -6,7 +6,7 @@ namespace AIStudio.Wpf.DiagramDesigner
{
public static partial class PathGenerators
{
public static double SourceMarkerAdjustement(PointBase[] route, double markerWidth)
public static double SourceMarkerAdjustement(PointBase[] route, double markerWidth, double markerHeight)
{
var angleInRadians = Math.Atan2(route[1].Y - route[0].Y, route[1].X - route[0].X) + Math.PI;
var xChange = markerWidth * Math.Cos(angleInRadians);
@@ -15,7 +15,7 @@ namespace AIStudio.Wpf.DiagramDesigner
return angleInRadians * 180 / Math.PI;
}
public static double TargetMarkerAdjustement(PointBase[] route, double markerWidth)
public static double TargetMarkerAdjustement(PointBase[] route, double markerWidth, double markerHeight)
{
var angleInRadians = Math.Atan2(route[route.Length - 1].Y - route[route.Length - 2].Y, route[route.Length - 1].X - route[route.Length - 2].X);
var xChange = markerWidth * Math.Cos(angleInRadians);