mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
block
This commit is contained in:
@@ -6,8 +6,13 @@ using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public static class DiagramViewModelHelper
|
||||
public static partial class DiagramViewModelHelper
|
||||
{
|
||||
static List<IAttachTo> AttachTos
|
||||
{
|
||||
get; set;
|
||||
} = new List<IAttachTo>();
|
||||
|
||||
public static DesignerItemViewModelBase GetConnectorDataItem(IEnumerable<SelectableDesignerItemViewModelBase> items, Guid conectorDataItemId, Type connectorDataItemType)
|
||||
{
|
||||
DesignerItemViewModelBase dataItem = items.OfType<DesignerItemViewModelBase>().Single(x => x.Id == conectorDataItemId);
|
||||
@@ -44,7 +49,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (partialConnection == null)
|
||||
return null;
|
||||
|
||||
diagramViewModel.ClearNearPort();
|
||||
diagramViewModel.ClearAttachTo();
|
||||
foreach (var port in diagramViewModel.Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors))
|
||||
{
|
||||
if (connectorVertexType == ConnectorVertexType.Start)
|
||||
@@ -54,13 +59,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (partialConnection.SinkConnectorInfo?.CanAttachTo(port) == true)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.BeAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, true);
|
||||
return port;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.DisableAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, false);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -72,13 +77,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (partialConnection.SourceConnectorInfo?.CanAttachTo(port) == true)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.BeAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, true);
|
||||
return port;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
port.DisableAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, false);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -93,7 +98,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (partialConnection == null)
|
||||
return null;
|
||||
|
||||
diagramViewModel.ClearNearPort();
|
||||
diagramViewModel.ClearAttachTo();
|
||||
foreach (var port in diagramViewModel.Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors))
|
||||
{
|
||||
if (partialConnection.OnGoingPosition.DistanceTo(port.Position) < diagramViewModel.DiagramOption.SnappingOption.SnappingRadius)
|
||||
@@ -101,31 +106,44 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (partialConnection.SourceConnectorInfo?.CanAttachTo(port) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, true);
|
||||
return port;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DisableAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, false);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void ClearNearPort(this IDiagramViewModel diagramViewModel)
|
||||
public static void AddAttachTo(this IDiagramViewModel diagramViewModel, IAttachTo item, bool beAttachTo)
|
||||
{
|
||||
diagramViewModel.Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors).Where(p => p.BeAttachTo == true || p.DisableAttachTo == true).ToList()
|
||||
.ForEach(p => {
|
||||
p.DisableAttachTo = false;
|
||||
p.BeAttachTo = false;
|
||||
});
|
||||
if (beAttachTo)
|
||||
{
|
||||
item.BeAttachTo = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.DisableAttachTo = true;
|
||||
}
|
||||
AttachTos.Add(item);
|
||||
}
|
||||
|
||||
public static void ClearAttachTo(this IDiagramViewModel diagramViewModel)
|
||||
{
|
||||
AttachTos.ForEach(p => {
|
||||
p.DisableAttachTo = false;
|
||||
p.BeAttachTo = false;
|
||||
});
|
||||
AttachTos.Clear();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user