连接线修改,为支持改变连接点做准备

This commit is contained in:
akwkevin
2021-08-05 18:20:22 +08:00
parent b0c9855d05
commit e9c043ae3a
19 changed files with 405 additions and 50 deletions

View File

@@ -27,6 +27,7 @@ namespace Util.DiagramDesigner
return DrawMode.Normal;
}
public void ResetDrawMode()
{
CursorDrawModeSelected = true;
@@ -104,7 +105,7 @@ namespace Util.DiagramDesigner
}
}
private DrawMode _vectorLineDrawMode = DrawMode.ConnectingLine;
private DrawMode _vectorLineDrawMode = DrawMode.RadiusConnectingLine;
public DrawMode VectorLineDrawMode
{
get

View File

@@ -12,5 +12,6 @@ namespace Util.DiagramDesigner
void ResetDrawMode();
CursorMode CursorMode { get; set; }
DrawMode VectorLineDrawMode { get; set; }
}
}

View File

@@ -271,7 +271,7 @@ namespace Util.DiagramDesigner
/// <summary>
/// 连接点是否可以按偏移自定义
/// </summary>
public bool IsRatioConnector { get; set; }
public bool IsInnerConnector { get; set; }
private ObservableCollection<FullyCreatedConnectorInfo> connectors = new ObservableCollection<FullyCreatedConnectorInfo>();
public IEnumerable<FullyCreatedConnectorInfo> Connectors { get { return connectors; } }

View File

@@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
namespace Util.DiagramDesigner
{
public class PointInfoBase : BindableBase
{
public PointInfoBase()
{
ColorViewModel = new ColorViewModel()
{
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
FillColor = new ColorObject() { Color = Colors.Lavender },
};
}
public PointInfoBase(Point point) : this()
{
X = point.X;
Y = point.Y;
}
private double _x;
public double X
{
get
{
return _x;
}
set
{
if(SetProperty(ref _x, value))
{
RaisePropertyChanged(nameof(Left));
}
}
}
private double _y;
public double Y
{
get
{
return _y;
}
set
{
if (SetProperty(ref _y, value))
{
RaisePropertyChanged(nameof(Top));
}
}
}
public double Left
{
get
{
return X - ConnectorWidth / 2;
}
}
public double Top
{
get
{
return Y - ConnectorHeight / 2;
}
}
private double connectorWidth = 8;
public double ConnectorWidth
{
get { return connectorWidth; }
set { connectorWidth = value; }
}
private double connectorHeight = 8;
public double ConnectorHeight
{
get { return connectorHeight; }
set { connectorHeight = value; }
}
private IColorViewModel _colorViewModel;
public IColorViewModel ColorViewModel
{
get
{
return _colorViewModel;
}
set
{
SetProperty(ref _colorViewModel, value);
}
}
public static implicit operator PointInfoBase(Point point)
{
return new PointInfoBase(point);
}
public static implicit operator Point(PointInfoBase pointInfoBase)
{
return new Point(pointInfoBase.X, pointInfoBase.Y);
}
public static List<PointInfoBase> ToList(List<Point> lst)
{
return lst.Select(p => (PointInfoBase)p).ToList();
}
}
}

View File

@@ -10,6 +10,8 @@ namespace Util.DiagramDesigner
{
public class ConnectorViewModel : SelectableDesignerItemViewModelBase
{
private IDiagramServiceProvider _service { get { return DiagramServicesProvider.Instance.Provider; } }
public ConnectorViewModel(IDiagramViewModel parent, FullyCreatedConnectorInfo sourceConnectorInfo, FullyCreatedConnectorInfo sinkConnectorInfo,
SelectableDesignerItemBase designer) : base(parent, designer)
{
@@ -61,8 +63,8 @@ namespace Util.DiagramDesigner
}
}
private List<Point> _connectionPoints;
public List<Point> ConnectionPoints
private List<PointInfoBase> _connectionPoints;
public List<PointInfoBase> ConnectionPoints
{
get
{
@@ -70,7 +72,15 @@ namespace Util.DiagramDesigner
}
private set
{
if (_connectionPoints != null)
{
_connectionPoints.ForEach(p => p.PropertyChanged -= new WeakINPCEventHandler(ConnectionPoint_PropertyChanged).Handler);
}
SetProperty(ref _connectionPoints, value);
if (_connectionPoints != null)
{
_connectionPoints.ForEach(p => p.PropertyChanged += new WeakINPCEventHandler(ConnectionPoint_PropertyChanged).Handler);
}
}
}
@@ -179,35 +189,36 @@ namespace Util.DiagramDesigner
private void UpdateConnectionPoints()
{
if (SinkConnectorInfo is FullyCreatedConnectorInfo && SourceConnectorInfo.DataItem is LinkPointDesignerItemViewModel && ((FullyCreatedConnectorInfo)SinkConnectorInfo).DataItem is LinkPointDesignerItemViewModel)
if (_service.DrawModeViewModel.VectorLineDrawMode == DrawMode.ConnectingLine)
{
UpdateConnectionPointsByLine();
return;
}
if (Parent.DiagramType == DiagramType.FlowChart || Parent.DiagramType == DiagramType.SFC)
else if (_service.DrawModeViewModel.VectorLineDrawMode == DrawMode.BoundaryConnectingLine)
{
UpdateConnectionPointsByFlowChart();
UpdateConnectionPointsByBoundary();
}
else
{
UpdateConnectionPointsByNormal();
UpdateConnectionPointsByCorner();
}
}
private void UpdateConnectionPointsByLine()
{
ConnectionPoints = new List<Point>()
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];
EndPoint = ConnectionPoints.Last();
}
private void UpdateConnectionPointsByNormal()
private void UpdateConnectionPointsByCorner()
{
ConnectionPoints = new List<Point>()
var points = new List<Point>()
{
new Point(SourceA.X < SourceB.X ? 0d : Area.Width, SourceA.Y < SourceB.Y ? 0d : Area.Height ),
@@ -215,34 +226,34 @@ namespace Util.DiagramDesigner
};
ConnectorInfo sourceInfo = ConnectorInfo(SourceConnectorInfo.Orientation,
ConnectionPoints[0].X,
ConnectionPoints[0].Y,
points[0].X,
points[0].Y,
SourceConnectorInfo.DataItem.ItemWidth,
SourceConnectorInfo.DataItem.ItemHeight,
ConnectionPoints[0]);
points[0]);
StartPoint = ConnectionPoints[0];
StartPoint = points[0];
if (IsFullConnection)
{
EndPoint = ConnectionPoints.Last();
EndPoint = points.Last();
ConnectorInfo sinkInfo = ConnectorInfo(SinkConnectorInfo.Orientation,
ConnectionPoints[1].X,
ConnectionPoints[1].Y,
points[1].X,
points[1].Y,
((FullyCreatedConnectorInfo)_sinkConnectorInfo).DataItem.ItemWidth,
((FullyCreatedConnectorInfo)_sinkConnectorInfo).DataItem.ItemHeight,
ConnectionPoints[1]);
points[1]);
ConnectionPoints = PathFinder.GetConnectionLine(sourceInfo, sinkInfo, false, SourceConnectorInfo.IsInnerPoint);
ConnectionPoints = PointInfoBase.ToList(PathFinder.GetConnectionLine(sourceInfo, sinkInfo, false, SourceConnectorInfo.IsInnerPoint));
}
else
{
ConnectionPoints = PathFinder.GetConnectionLine(sourceInfo, ConnectionPoints[1], SourceConnectorInfo.Orientation, SourceConnectorInfo.IsInnerPoint);
ConnectionPoints = PointInfoBase.ToList(PathFinder.GetConnectionLine(sourceInfo, points[1], SourceConnectorInfo.Orientation, SourceConnectorInfo.IsInnerPoint));
EndPoint = new Point();
}
}
#region
private void UpdateConnectionPointsByFlowChart()
private void UpdateConnectionPointsByBoundary()
{
var points = new List<Point>();
var ends = GetEndPoinds();
@@ -253,7 +264,7 @@ namespace Util.DiagramDesigner
var res = points.ToArray();
//UpdateEdges(res);
DoShift(res);
ConnectionPoints = res.ToList();
ConnectionPoints = PointInfoBase.ToList(res.ToList());
StartPoint = ConnectionPoints[0];
EndPoint = ConnectionPoints.Last();
}
@@ -372,6 +383,18 @@ namespace Util.DiagramDesigner
}
}
private void ConnectionPoint_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "Left":
case "Top":
RaisePropertyChanged(nameof(ConnectionPoints));
break;
}
}
private void Init(FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo)
{
this.Parent = sourceConnectorInfo.DataItem.Parent;