mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-13 04:36:37 +08:00
简单demo继续完善
This commit is contained in:
180
AIStudio.Wpf.DiagramDesigner/Helpers/BoundaryPathFinder.cs
Normal file
180
AIStudio.Wpf.DiagramDesigner/Helpers/BoundaryPathFinder.cs
Normal file
@@ -0,0 +1,180 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class BoundaryPathFinder : IPathFinder
|
||||
{
|
||||
public List<PointInfoBase> UpdateConnectionPoints(IDiagramViewModel diagramViewModel, Point sourceA, Point sourceB, FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo)
|
||||
{
|
||||
List<PointInfoBase> connectionPoints;
|
||||
var isFullConnection = sinkConnectorInfo is FullyCreatedConnectorInfo;
|
||||
|
||||
var points = new List<Point>()
|
||||
{
|
||||
sourceA,
|
||||
sourceB
|
||||
};
|
||||
|
||||
ConnectorInfo sourceInfo = ConnectorInfo(sourceConnectorInfo.Orientation,
|
||||
points[0].X,
|
||||
points[0].Y,
|
||||
sourceConnectorInfo.DataItem.ItemWidth,
|
||||
sourceConnectorInfo.DataItem.ItemHeight,
|
||||
points[0]);
|
||||
|
||||
|
||||
//StartPoint = points[0];
|
||||
if (isFullConnection)
|
||||
{
|
||||
|
||||
ConnectorInfo sinkInfo = ConnectorInfo(sinkConnectorInfo.Orientation,
|
||||
points[1].X,
|
||||
points[1].Y,
|
||||
((FullyCreatedConnectorInfo)sinkConnectorInfo).DataItem.ItemWidth,
|
||||
((FullyCreatedConnectorInfo)sinkConnectorInfo).DataItem.ItemHeight,
|
||||
points[1]);
|
||||
|
||||
connectionPoints = PointInfoBase.ToList(GetConnectionLine(diagramViewModel, sourceInfo, sinkInfo, false, sourceConnectorInfo.IsInnerPoint));
|
||||
//EndPoint = ConnectionPoints.Last();
|
||||
}
|
||||
else
|
||||
{
|
||||
connectionPoints = PointInfoBase.ToList(GetConnectionLine(diagramViewModel, sourceInfo, points[1], sourceConnectorInfo.Orientation, false, sourceConnectorInfo.IsInnerPoint));
|
||||
//EndPoint = new Point();
|
||||
}
|
||||
|
||||
return connectionPoints;
|
||||
}
|
||||
|
||||
public ConnectorInfo ConnectorInfo(ConnectorOrientation orientation, double left, double top, double width, double height, Point position)
|
||||
{
|
||||
return new ConnectorInfo()
|
||||
{
|
||||
Orientation = orientation,
|
||||
DesignerItemSize = new Size(width, height),
|
||||
DesignerItemLeft = left,
|
||||
DesignerItemTop = top,
|
||||
Position = position
|
||||
};
|
||||
}
|
||||
|
||||
public List<Point> GetConnectionLine(IDiagramViewModel diagramViewModel, ConnectorInfo source, ConnectorInfo sink, bool showLastLine, bool sourceInnerPoint = false)
|
||||
{
|
||||
var points = new List<Point>();
|
||||
var ends = new List<Point> { source.Position, sink.Position };
|
||||
|
||||
points.Add(ends[0]);
|
||||
points.AddRange(GetMiddlePoints(source, sink, diagramViewModel.GridCellSize, diagramViewModel.GridMargin, true));
|
||||
points.Add(ends[1]);
|
||||
var res = points.ToArray();
|
||||
DoShift(res);
|
||||
return res.ToList();
|
||||
}
|
||||
|
||||
public List<Point> GetConnectionLine(IDiagramViewModel diagramViewModel, ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation, bool showLastLine, bool isInnerPoint = false)
|
||||
{
|
||||
var points = new List<Point>();
|
||||
var ends = new List<Point> { source.Position, sinkPoint };
|
||||
|
||||
points.Add(ends[0]);
|
||||
points.AddRange(GetMiddlePoints(source, new ConnectorInfo() { Orientation = ConnectorOrientation.Top, Position = sinkPoint }, diagramViewModel.GridCellSize, diagramViewModel.GridMargin, false));
|
||||
points.Add(ends[1]);
|
||||
var res = points.ToArray();
|
||||
DoShift(res);
|
||||
return res.ToList();
|
||||
}
|
||||
|
||||
private IEnumerable<Point> GetMiddlePoints(ConnectorInfo source, ConnectorInfo sink, Size gridCellSize, double gridMargin, bool isFullConnection)
|
||||
{
|
||||
var points = new List<Point>();
|
||||
if (isFullConnection)
|
||||
{
|
||||
var p0 = GetFirstSegment(source.Orientation, source.Position, gridCellSize, gridMargin);
|
||||
var p1 = GetFirstSegment(sink.Orientation, sink.Position, gridCellSize, gridMargin);
|
||||
|
||||
if (p0 == p1)
|
||||
return points;
|
||||
|
||||
|
||||
var p2 = new Point(GetNearestCross(p0.X, p1.X), GetNearestCross(p0.Y, p1.Y));
|
||||
var p3 = new Point(GetNearestCross(p1.X, p0.X), GetNearestCross(p1.Y, p0.Y));
|
||||
if (p2 == p3)
|
||||
{
|
||||
points.Add(p0);
|
||||
points.Add(p2);
|
||||
points.Add(p1);
|
||||
}
|
||||
else
|
||||
{
|
||||
points.Add(p0);
|
||||
points.Add(p2);
|
||||
if (!(Math.Abs(p2.X - p3.X) < 0.0001) && !(Math.Abs(p2.Y - p3.Y) < 0.0001))
|
||||
points.Add(new Point(p2.X, p3.Y));
|
||||
points.Add(p3);
|
||||
points.Add(p1);
|
||||
}
|
||||
DoScale(points, gridCellSize, gridMargin);
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
private Point GetFirstSegment(ConnectorOrientation orientation, Point point, Size cellSize, double margin)
|
||||
{
|
||||
double x = (int)((point.X - margin) / cellSize.Width) + 0.5;
|
||||
double y = (int)((point.Y - margin) / cellSize.Height) + 0.5;
|
||||
if (orientation == ConnectorOrientation.Top)
|
||||
return new Point(x, y - 0.5);
|
||||
else if (orientation == ConnectorOrientation.Bottom)
|
||||
return new Point(x, y + 0.5);
|
||||
else if (orientation == ConnectorOrientation.Left)
|
||||
return new Point(x - 0.5, y);
|
||||
else
|
||||
return new Point(x + 0.5, y);
|
||||
}
|
||||
|
||||
public static double GetNearestCross(double a, double b)
|
||||
{
|
||||
if (Math.Abs(a - b) < 0.0001 && (int)a == a)
|
||||
return a;
|
||||
else if (a < b)
|
||||
return Math.Ceiling(a);
|
||||
else
|
||||
return Math.Floor(a);
|
||||
}
|
||||
|
||||
public static Point SegmentMiddlePoint(Point p1, Point p2)
|
||||
{
|
||||
return new Point((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2);
|
||||
}
|
||||
|
||||
|
||||
private void DoScale(List<Point> points, Size cellSize, double margin)
|
||||
{
|
||||
for (int i = 0; i < points.Count; i++)
|
||||
{
|
||||
points[i] = new Point(points[i].X * cellSize.Width + margin,
|
||||
points[i].Y * cellSize.Height + margin);
|
||||
}
|
||||
}
|
||||
|
||||
private void DoShift(Point[] points)
|
||||
{
|
||||
double left = new Point[] { points.FirstOrDefault(), points.LastOrDefault() }.Min(p => p.X);
|
||||
double top = new Point[] { points.FirstOrDefault(), points.LastOrDefault() }.Min(p => p.Y);
|
||||
|
||||
for (int i = 0; i < points.Length; i++)
|
||||
{
|
||||
points[i].X = points[i].X - left;
|
||||
points[i].Y = points[i].Y - top;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public interface IPathFinder
|
||||
{
|
||||
List<Point> GetConnectionLine(ConnectorInfo source, ConnectorInfo sink, bool showLastLine, bool sourceInnerPoint = false);
|
||||
List<Point> GetConnectionLine(ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation, bool showLastLine, bool isInnerPoint = false);
|
||||
List<PointInfoBase> UpdateConnectionPoints(IDiagramViewModel diagramViewModel, Point sourceA, Point sourceB, FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo);
|
||||
List<Point> GetConnectionLine(IDiagramViewModel diagramViewModel, ConnectorInfo source, ConnectorInfo sink, bool showLastLine, bool sourceInnerPoint = false);
|
||||
List<Point> GetConnectionLine(IDiagramViewModel diagramViewModel, ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation, bool showLastLine, bool isInnerPoint = false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,61 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
private const int const_margin = 20;
|
||||
|
||||
public List<Point> GetConnectionLine(ConnectorInfo source, ConnectorInfo sink, bool showLastLine, bool sourceInnerPoint = false)
|
||||
public List<PointInfoBase> UpdateConnectionPoints(IDiagramViewModel diagramViewModel, Point sourceA, Point sourceB, FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo)
|
||||
{
|
||||
List<PointInfoBase> connectionPoints;
|
||||
var isFullConnection = sinkConnectorInfo is FullyCreatedConnectorInfo;
|
||||
var area = new Rect(sourceA, sourceB);
|
||||
|
||||
var points = new List<Point>()
|
||||
{
|
||||
new Point(sourceA.X < sourceB.X ? 0d : area.Width, sourceA.Y < sourceB.Y ? 0d : area.Height ),
|
||||
new Point(sourceA.X > sourceB.X ? 0d : area.Width, sourceA.Y > sourceB.Y ? 0d : area.Height)
|
||||
};
|
||||
|
||||
ConnectorInfo sourceInfo = ConnectorInfo(sourceConnectorInfo.Orientation,
|
||||
points[0].X,
|
||||
points[0].Y,
|
||||
sourceConnectorInfo.DataItem.ItemWidth,
|
||||
sourceConnectorInfo.DataItem.ItemHeight,
|
||||
points[0]);
|
||||
|
||||
//StartPoint = points[0];
|
||||
if (isFullConnection)
|
||||
{
|
||||
|
||||
ConnectorInfo sinkInfo = ConnectorInfo(sinkConnectorInfo.Orientation,
|
||||
points[1].X,
|
||||
points[1].Y,
|
||||
((FullyCreatedConnectorInfo)sinkConnectorInfo).DataItem.ItemWidth,
|
||||
((FullyCreatedConnectorInfo)sinkConnectorInfo).DataItem.ItemHeight,
|
||||
points[1]);
|
||||
|
||||
connectionPoints = PointInfoBase.ToList(GetConnectionLine(diagramViewModel, sourceInfo, sinkInfo, false, sourceConnectorInfo.IsInnerPoint));
|
||||
//EndPoint = ConnectionPoints.Last();
|
||||
}
|
||||
else
|
||||
{
|
||||
connectionPoints = PointInfoBase.ToList(GetConnectionLine(diagramViewModel, sourceInfo, points[1], sourceConnectorInfo.Orientation, false, sourceConnectorInfo.IsInnerPoint));
|
||||
//EndPoint = new Point();
|
||||
}
|
||||
|
||||
return connectionPoints;
|
||||
}
|
||||
|
||||
public ConnectorInfo ConnectorInfo(ConnectorOrientation orientation, double left, double top, double width, double height, Point position)
|
||||
{
|
||||
return new ConnectorInfo()
|
||||
{
|
||||
Orientation = orientation,
|
||||
DesignerItemSize = new Size(width, height),
|
||||
DesignerItemLeft = left,
|
||||
DesignerItemTop = top,
|
||||
Position = position
|
||||
};
|
||||
}
|
||||
|
||||
public List<Point> GetConnectionLine(IDiagramViewModel diagramViewModel, ConnectorInfo source, ConnectorInfo sink, bool showLastLine, bool sourceInnerPoint = false)
|
||||
{
|
||||
List<Point> linePoints = new List<Point>();
|
||||
int margin1 = sourceInnerPoint ? 0 : const_margin;
|
||||
@@ -213,11 +267,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return linePoints;
|
||||
}
|
||||
|
||||
public List<Point> GetConnectionLine(ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation, bool showLastLine, bool isInnerPoint = false)
|
||||
public List<Point> GetConnectionLine(IDiagramViewModel diagramViewModel, ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation, bool showLastLine, bool isInnerPoint = false)
|
||||
{
|
||||
List<Point> linePoints = new List<Point>();
|
||||
int margin = isInnerPoint ? 0 : const_margin;
|
||||
|
||||
int margin = isInnerPoint ? 0 : const_margin;
|
||||
|
||||
Rect rectSource = GetRectWithMargin(source, margin);
|
||||
Point startPoint = GetOffsetPoint(source, rectSource, isInnerPoint);
|
||||
Point endPoint = sinkPoint;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class StraightLinePathFinder : IPathFinder
|
||||
{
|
||||
|
||||
|
||||
public List<PointInfoBase> UpdateConnectionPoints(IDiagramViewModel diagramViewModel, Point sourceA, Point sourceB, FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo)
|
||||
{
|
||||
var area = new Rect(sourceA, sourceB);
|
||||
var connectionPoints = PointInfoBase.ToList(new List<Point>()
|
||||
{
|
||||
|
||||
new Point(sourceA.X < sourceB.X ? 0d : area.Width, sourceA.Y < sourceB.Y ? 0d : area.Height ),
|
||||
new Point(sourceA.X > sourceB.X ? 0d : area.Width, sourceA.Y > sourceB.Y ? 0d : area.Height)
|
||||
});
|
||||
|
||||
return connectionPoints;
|
||||
}
|
||||
|
||||
public List<Point> GetConnectionLine(IDiagramViewModel diagramViewModel, ConnectorInfo source, ConnectorInfo sink, bool showLastLine, bool sourceInnerPoint = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<Point> GetConnectionLine(IDiagramViewModel diagramViewModel, ConnectorInfo source, Point sinkPoint, ConnectorOrientation preferredOrientation, bool showLastLine, bool isInnerPoint = false)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
VectorLineDrawMode = vectorLineDrawMode;
|
||||
Init(sourceConnectorInfo, sinkConnectorInfo);
|
||||
|
||||
}
|
||||
|
||||
public ConnectorViewModel(FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo, DrawMode vectorLineDrawMode)
|
||||
@@ -24,11 +25,17 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
|
||||
|
||||
public static IPathFinder PathFinder { get; set; }
|
||||
public IPathFinder PathFinder
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public bool IsFullConnection
|
||||
{
|
||||
get { return _sinkConnectorInfo is FullyCreatedConnectorInfo; }
|
||||
get
|
||||
{
|
||||
return _sinkConnectorInfo is FullyCreatedConnectorInfo;
|
||||
}
|
||||
}
|
||||
|
||||
private Point _sourceA;
|
||||
@@ -127,7 +134,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public DrawMode VectorLineDrawMode { get; set; }
|
||||
public DrawMode VectorLineDrawMode
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public ConnectorInfo ConnectorInfo(ConnectorOrientation orientation, double left, double top, double width, double height, Point position)
|
||||
{
|
||||
@@ -191,181 +201,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
private void UpdateConnectionPoints()
|
||||
{
|
||||
if (VectorLineDrawMode == DrawMode.ConnectingLine)
|
||||
{
|
||||
UpdateConnectionPointsByLine();
|
||||
}
|
||||
else if (VectorLineDrawMode == DrawMode.BoundaryConnectingLine)
|
||||
{
|
||||
UpdateConnectionPointsByBoundary();
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateConnectionPointsByCorner();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void UpdateConnectionPointsByLine()
|
||||
{
|
||||
ConnectionPoints = PointInfoBase.ToList(new List<Point>()
|
||||
{
|
||||
|
||||
new Point(SourceA.X < SourceB.X ? 0d : Area.Width, SourceA.Y < SourceB.Y ? 0d : Area.Height ),
|
||||
new Point(SourceA.X > SourceB.X ? 0d : Area.Width, SourceA.Y > SourceB.Y ? 0d : Area.Height)
|
||||
});
|
||||
StartPoint = ConnectionPoints[0];
|
||||
ConnectionPoints = PathFinder.UpdateConnectionPoints(Parent, SourceA, SourceB, SourceConnectorInfo, SinkConnectorInfo);
|
||||
StartPoint = ConnectionPoints.First();
|
||||
EndPoint = ConnectionPoints.Last();
|
||||
}
|
||||
|
||||
private void UpdateConnectionPointsByCorner()
|
||||
{
|
||||
var points = new List<Point>()
|
||||
{
|
||||
|
||||
new Point(SourceA.X < SourceB.X ? 0d : Area.Width, SourceA.Y < SourceB.Y ? 0d : Area.Height ),
|
||||
new Point(SourceA.X > SourceB.X ? 0d : Area.Width, SourceA.Y > SourceB.Y ? 0d : Area.Height)
|
||||
};
|
||||
|
||||
ConnectorInfo sourceInfo = ConnectorInfo(SourceConnectorInfo.Orientation,
|
||||
points[0].X,
|
||||
points[0].Y,
|
||||
SourceConnectorInfo.DataItem.ItemWidth,
|
||||
SourceConnectorInfo.DataItem.ItemHeight,
|
||||
points[0]);
|
||||
|
||||
StartPoint = points[0];
|
||||
if (IsFullConnection)
|
||||
{
|
||||
EndPoint = points.Last();
|
||||
ConnectorInfo sinkInfo = ConnectorInfo(SinkConnectorInfo.Orientation,
|
||||
points[1].X,
|
||||
points[1].Y,
|
||||
((FullyCreatedConnectorInfo)_sinkConnectorInfo).DataItem.ItemWidth,
|
||||
((FullyCreatedConnectorInfo)_sinkConnectorInfo).DataItem.ItemHeight,
|
||||
points[1]);
|
||||
|
||||
ConnectionPoints = PointInfoBase.ToList(PathFinder.GetConnectionLine(sourceInfo, sinkInfo, false, SourceConnectorInfo.IsInnerPoint));
|
||||
}
|
||||
else
|
||||
{
|
||||
ConnectionPoints = PointInfoBase.ToList(PathFinder.GetConnectionLine(sourceInfo, points[1], SourceConnectorInfo.Orientation, false, SourceConnectorInfo.IsInnerPoint));
|
||||
EndPoint = new Point();
|
||||
}
|
||||
}
|
||||
|
||||
#region
|
||||
private void UpdateConnectionPointsByBoundary()
|
||||
{
|
||||
var points = new List<Point>();
|
||||
var ends = GetEndPoinds();
|
||||
|
||||
points.Add(ends[0]);
|
||||
points.AddRange(GetMiddlePoints(ends[0], ends[1]));
|
||||
points.Add(ends[1]);
|
||||
var res = points.ToArray();
|
||||
//UpdateEdges(res);
|
||||
DoShift(res);
|
||||
ConnectionPoints = PointInfoBase.ToList(res.ToList());
|
||||
StartPoint = ConnectionPoints[0];
|
||||
EndPoint = ConnectionPoints.Last();
|
||||
}
|
||||
|
||||
private IEnumerable<Point> GetMiddlePoints(Point start, Point end)
|
||||
{
|
||||
var points = new List<Point>();
|
||||
if (IsFullConnection)
|
||||
{
|
||||
var p0 = GetFirstSegment(SourceConnectorInfo, start, Parent.GridCellSize, Parent.GridMargin);
|
||||
var p1 = GetFirstSegment(SinkConnectorInfo, end, Parent.GridCellSize, Parent.GridMargin);
|
||||
|
||||
if (p0 == p1)
|
||||
return points;
|
||||
|
||||
|
||||
var p2 = new Point(GetNearestCross(p0.X, p1.X), GetNearestCross(p0.Y, p1.Y));
|
||||
var p3 = new Point(GetNearestCross(p1.X, p0.X), GetNearestCross(p1.Y, p0.Y));
|
||||
if (p2 == p3)
|
||||
{
|
||||
points.Add(p0);
|
||||
points.Add(p2);
|
||||
points.Add(p1);
|
||||
}
|
||||
else
|
||||
{
|
||||
points.Add(p0);
|
||||
points.Add(p2);
|
||||
if (!(Math.Abs(p2.X - p3.X) < 0.0001) && !(Math.Abs(p2.Y - p3.Y) < 0.0001))
|
||||
points.Add(new Point(p2.X, p3.Y));
|
||||
points.Add(p3);
|
||||
points.Add(p1);
|
||||
}
|
||||
DoScale(points, Parent.GridCellSize, Parent.GridMargin);
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
private Point[] GetEndPoinds()
|
||||
{
|
||||
var linePoints = new Point[2];
|
||||
linePoints[0] = SourceA;
|
||||
linePoints[1] = SourceB;
|
||||
|
||||
return linePoints;
|
||||
}
|
||||
|
||||
private Point GetFirstSegment(ConnectorInfoBase port, Point point, Size cellSize, double margin)
|
||||
{
|
||||
double x = (int)((point.X - margin) / cellSize.Width) + 0.5;
|
||||
double y = (int)((point.Y - margin) / cellSize.Height) + 0.5;
|
||||
if (port.Orientation == ConnectorOrientation.Top)
|
||||
return new Point(x, y - 0.5);
|
||||
else if (port.Orientation == ConnectorOrientation.Bottom)
|
||||
return new Point(x, y + 0.5);
|
||||
else if (port.Orientation == ConnectorOrientation.Left)
|
||||
return new Point(x - 0.5, y);
|
||||
else
|
||||
return new Point(x + 0.5, y);
|
||||
}
|
||||
|
||||
private double GetNearestCross(double a, double b)
|
||||
{
|
||||
if (Math.Abs(a - b) < 0.0001 && (int)a == a)
|
||||
return a;
|
||||
else if (a < b)
|
||||
return Math.Ceiling(a);
|
||||
else
|
||||
return Math.Floor(a);
|
||||
}
|
||||
|
||||
private void DoScale(List<Point> points, Size cellSize, double margin)
|
||||
{
|
||||
for (int i = 0; i < points.Count; i++)
|
||||
{
|
||||
points[i] = new Point(points[i].X * cellSize.Width + margin,
|
||||
points[i].Y * cellSize.Height + margin);
|
||||
}
|
||||
}
|
||||
|
||||
private void DoShift(Point[] points)
|
||||
{
|
||||
double left = new Point[] { points.FirstOrDefault(), points.LastOrDefault() }.Min(p => p.X);
|
||||
double top = new Point[] { points.FirstOrDefault(), points.LastOrDefault() }.Min(p => p.Y);
|
||||
|
||||
for (int i = 0; i < points.Length; i++)
|
||||
{
|
||||
points[i].X = points[i].X - left;
|
||||
points[i].Y = points[i].Y - top;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private Point SegmentMiddlePoint(Point p1, Point p2)
|
||||
{
|
||||
return new Point((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
private void ConnectorViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
@@ -400,9 +240,20 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
private void Init(FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo)
|
||||
{
|
||||
this.Parent = sourceConnectorInfo.DataItem.Parent;
|
||||
if (VectorLineDrawMode == DrawMode.ConnectingLine)
|
||||
{
|
||||
PathFinder = new StraightLinePathFinder();
|
||||
}
|
||||
else if (VectorLineDrawMode == DrawMode.BoundaryConnectingLine)
|
||||
{
|
||||
PathFinder = new BoundaryPathFinder();
|
||||
}
|
||||
else
|
||||
{
|
||||
PathFinder = new OrthogonalPathFinder();
|
||||
}
|
||||
this.SourceConnectorInfo = sourceConnectorInfo;
|
||||
this.SinkConnectorInfo = sinkConnectorInfo;
|
||||
PathFinder = new OrthogonalPathFinder();
|
||||
this.SinkConnectorInfo = sinkConnectorInfo;
|
||||
DeleteConnectionCommand = new SimpleCommand(DeleteConnection);
|
||||
|
||||
if (sinkConnectorInfo is FullyCreatedConnectorInfo sink && sink.DataItem.ShowArrow == false)
|
||||
@@ -411,7 +262,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleCommand DeleteConnectionCommand { get; set; }
|
||||
public SimpleCommand DeleteConnectionCommand
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
private void DeleteConnection(object args)
|
||||
{
|
||||
if (this.Parent is IDiagramViewModel)
|
||||
@@ -439,7 +293,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (diagramVM.DiagramType == DiagramType.FlowChart)
|
||||
{
|
||||
var mid = (int)(ConnectionPoints.Count / 2);
|
||||
var p = SegmentMiddlePoint(ConnectionPoints[mid - 1], ConnectionPoints[mid]);
|
||||
var p = BoundaryPathFinder.SegmentMiddlePoint(ConnectionPoints[mid - 1], ConnectionPoints[mid]);
|
||||
textitem.Left = this.Area.Left + p.X + 2;
|
||||
textitem.Top = this.Area.Top + p.Y - 15;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user