mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
可以把连线从节点上拖下来,并且依附上去。
This commit is contained in:
@@ -5,6 +5,7 @@ using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Controls;
|
||||
@@ -480,7 +481,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
protected override void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (IsLoaded == false) return;
|
||||
if (IsLoaded == false || IsInternalChanged == true ) return;
|
||||
|
||||
if (sender is ConnectionViewModel)
|
||||
{
|
||||
@@ -513,10 +514,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
SourceConnectorInfoFully.DataItem.PropertyChanged += new WeakINPCEventHandler(Item_PropertyChanged).Handler;
|
||||
}
|
||||
//else if (SourceConnectorInfoPart != null)
|
||||
//{
|
||||
// SourceConnectorInfoPart.PropertyChanged += new WeakINPCEventHandler(Item_PropertyChanged).Handler;
|
||||
//}
|
||||
}
|
||||
break;
|
||||
case nameof(SinkConnectorInfo):
|
||||
@@ -527,10 +524,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
SinkConnectorInfoFully.DataItem.PropertyChanged += new WeakINPCEventHandler(Item_PropertyChanged).Handler;
|
||||
}
|
||||
//else if (SinkConnectorInfoPart != null)
|
||||
//{
|
||||
// SinkConnectorInfoPart.PropertyChanged += new WeakINPCEventHandler(Item_PropertyChanged).Handler;
|
||||
//}
|
||||
}
|
||||
break;
|
||||
case nameof(IsSelected):
|
||||
@@ -580,15 +573,48 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (sender is ConnectorVertexModel)
|
||||
else if (sender is ConnectorVertexModel connectorVertexModel)
|
||||
{
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
case nameof(ConnectorPointModel.X):
|
||||
case nameof(ConnectorPointModel.Y):
|
||||
UpdatePathGeneratorResult();
|
||||
if (connectorVertexModel.ConnectorVertexType == ConnectorVertexType.None)
|
||||
{
|
||||
UpdatePathGeneratorResult();
|
||||
}
|
||||
else if(connectorVertexModel.ConnectorVertexType == ConnectorVertexType.Start)
|
||||
{
|
||||
SetSourcePort(new PartCreatedConnectorInfo(connectorVertexModel.Position.X, connectorVertexModel.Position.Y));
|
||||
this.ZIndex = -1;
|
||||
}
|
||||
else if (connectorVertexModel.ConnectorVertexType == ConnectorVertexType.End)
|
||||
{
|
||||
SetSinkPort(new PartCreatedConnectorInfo(connectorVertexModel.Position.X, connectorVertexModel.Position.Y));
|
||||
this.ZIndex = -1;
|
||||
}
|
||||
break;
|
||||
case nameof(ConnectorPointModel.DragStart):
|
||||
if (connectorVertexModel.DragStart == false)
|
||||
{
|
||||
if (connectorVertexModel.ConnectorVertexType == ConnectorVertexType.Start)
|
||||
{
|
||||
var nearPort = Root.FindNearPortToAttachTo(this, ConnectorVertexType.Start);
|
||||
if (nearPort != null)
|
||||
{
|
||||
SetSourcePort(nearPort);
|
||||
}
|
||||
}
|
||||
else if (connectorVertexModel.ConnectorVertexType == ConnectorVertexType.End)
|
||||
{
|
||||
var nearPort = Root.FindNearPortToAttachTo(this, ConnectorVertexType.End);
|
||||
if (nearPort != null)
|
||||
{
|
||||
SetSinkPort(nearPort);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
else if (sender is ConnectorLabelModel linkLabelModel)
|
||||
@@ -613,21 +639,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
}
|
||||
//else if (sender is PartCreatedConnectorInfo)
|
||||
//{
|
||||
// if (e.PropertyName == "Position")
|
||||
// {
|
||||
// if (sender == SourceConnectorInfoPart)
|
||||
// {
|
||||
// SourceA = SourceConnectorInfo.Position;
|
||||
// }
|
||||
// else if (sender == SinkConnectorInfoPart)
|
||||
// {
|
||||
// SourceB = SinkConnectorInfo.Position;
|
||||
// }
|
||||
// UpdatePathGeneratorResult();
|
||||
// }
|
||||
//}
|
||||
else if (sender is ColorViewModel)
|
||||
{
|
||||
|
||||
@@ -679,29 +690,31 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
var startVertice = Vertices.FirstOrDefault(p => p.ConnectorVertexType == ConnectorVertexType.Start);
|
||||
if (startVertice == null)
|
||||
{
|
||||
startVertice = new ConnectorVertexModel(this, StartPoint) { ConnectorVertexType = ConnectorVertexType.Start };
|
||||
startVertice.ColorViewModel.FillColor.Color = Colors.DarkRed;
|
||||
startVertice.ColorViewModel.LineColor.Color = Colors.DarkRed;
|
||||
Vertices.Add(startVertice);
|
||||
{
|
||||
startVertice = AddEndsVertex(StartPoint, ConnectorVertexType.Start);
|
||||
}
|
||||
else
|
||||
{
|
||||
IsInternalChanged = true;
|
||||
startVertice.SetPosition(StartPoint);
|
||||
IsInternalChanged = true;
|
||||
}
|
||||
startVertice.ColorViewModel.FillColor.Color = SourceConnectorInfoFully != null? Colors.DarkRed : Colors.Blue;
|
||||
startVertice.ColorViewModel.LineColor.Color = SourceConnectorInfoFully != null ? Colors.DarkRed : Colors.Blue;
|
||||
|
||||
var endVertice = Vertices.FirstOrDefault(p => p.ConnectorVertexType == ConnectorVertexType.End);
|
||||
if (endVertice == null)
|
||||
{
|
||||
endVertice = new ConnectorVertexModel(this, EndPoint) { ConnectorVertexType = ConnectorVertexType.End };
|
||||
endVertice.ColorViewModel.FillColor.Color = Colors.DarkRed;
|
||||
endVertice.ColorViewModel.LineColor.Color = Colors.DarkRed;
|
||||
Vertices.Add(endVertice);
|
||||
endVertice = AddEndsVertex(EndPoint, ConnectorVertexType.End);
|
||||
}
|
||||
else
|
||||
{
|
||||
IsInternalChanged = true;
|
||||
endVertice.SetPosition(EndPoint);
|
||||
IsInternalChanged = false;
|
||||
}
|
||||
endVertice.ColorViewModel.FillColor.Color = SinkConnectorInfoFully != null ? Colors.DarkRed : Colors.Blue;
|
||||
endVertice.ColorViewModel.LineColor.Color = SinkConnectorInfoFully != null ? Colors.DarkRed : Colors.Blue;
|
||||
|
||||
var paths = Labels.Count > 0 ? PathGeneratorResult.Paths.Select(p => new SvgPath(p)).ToArray() : Array.Empty<SvgPath>();
|
||||
foreach (var label in Labels)
|
||||
@@ -809,12 +822,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return minPoint;
|
||||
}
|
||||
|
||||
public void SetSourcePort(FullyCreatedConnectorInfo port)
|
||||
public void SetSourcePort(ConnectorInfoBase port)
|
||||
{
|
||||
SourceConnectorInfo = port;
|
||||
}
|
||||
|
||||
public void SetSinkPort(FullyCreatedConnectorInfo port)
|
||||
public void SetSinkPort(ConnectorInfoBase port)
|
||||
{
|
||||
SinkConnectorInfo = port;
|
||||
}
|
||||
@@ -943,6 +956,16 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
UpdatePathGeneratorResult();
|
||||
}
|
||||
|
||||
public ConnectorVertexModel AddEndsVertex(PointBase pointBase, ConnectorVertexType connectorVertexType)
|
||||
{
|
||||
var vertice = new ConnectorVertexModel(this, pointBase);
|
||||
vertice.ConnectorVertexType= connectorVertexType;
|
||||
vertice.PropertyChanged += new WeakINPCEventHandler(Item_PropertyChanged).Handler;
|
||||
Vertices.Add(vertice);
|
||||
|
||||
return vertice;
|
||||
}
|
||||
|
||||
public void RemoveVertex(ConnectorVertexModel vertice)
|
||||
{
|
||||
Vertices.Remove(vertice);
|
||||
|
||||
Reference in New Issue
Block a user