mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
Block图鉴
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
@@ -33,64 +34,75 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
FullyCreatedConnectorInfo parent = null;
|
||||
FullyCreatedConnectorInfo next = null;
|
||||
|
||||
foreach (var port in items.SelectMany(n => n.Connectors).OfType<BlockConnectorInfo>())
|
||||
foreach (var item in items)
|
||||
{
|
||||
//已经被连接的不允许在顶部吸附了
|
||||
if ((port.Orientation == ConnectorOrientation.Top || port.Orientation == ConnectorOrientation.Left) && port.DataItem.Prev != null)
|
||||
bool success = false;
|
||||
foreach (var port in item.Connectors.OfType<BlockConnectorInfo>())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var port2 in blockDesignerItemTempLink.Connectors)
|
||||
{
|
||||
//parent
|
||||
if (parent == null)
|
||||
//已经被连接的不允许在顶部吸附了
|
||||
if ((port.Orientation == ConnectorOrientation.Top || port.Orientation == ConnectorOrientation.Left) && port.DataItem.Prev != null)
|
||||
{
|
||||
if ((port.Orientation == ConnectorOrientation.Right && port2.Orientation == ConnectorOrientation.Left)
|
||||
|| (port.Orientation == ConnectorOrientation.Bottom && port2.Orientation == ConnectorOrientation.Top))
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var port2 in blockDesignerItemTempLink.Connectors.OfType<BlockConnectorInfo>())
|
||||
{
|
||||
//parent
|
||||
if (parent == null)
|
||||
{
|
||||
|
||||
if (port.Position.DistanceTo(port2.Position) < diagramViewModel.DiagramOption.SnappingOption.SnappingRadius)
|
||||
if ((port.Orientation == ConnectorOrientation.Right && port2.Orientation == ConnectorOrientation.Left)
|
||||
|| (port.Orientation == ConnectorOrientation.Bottom && port2.Orientation == ConnectorOrientation.Top))
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port2.CanAttachTo(port) == true)
|
||||
{
|
||||
diagramViewModel.AddAttachTo(port, true);
|
||||
parent = port;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
diagramViewModel.AddAttachTo(port, false);
|
||||
}
|
||||
|
||||
if (port.DistanceTo(port2) < diagramViewModel.DiagramOption.SnappingOption.BlockSnappingRadius)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port2.CanAttachTo(port) == true)
|
||||
{
|
||||
diagramViewModel.AddAttachTo(port, true);
|
||||
parent = port;
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
diagramViewModel.AddAttachTo(port, false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//next
|
||||
if (next == null)
|
||||
{
|
||||
if ((port.Orientation == ConnectorOrientation.Left && port2.Orientation == ConnectorOrientation.Right)
|
||||
|| (port.Orientation == ConnectorOrientation.Top && port2.Orientation == ConnectorOrientation.Bottom))
|
||||
{
|
||||
|
||||
if (port.Position.DistanceTo(port2.Position) < diagramViewModel.DiagramOption.SnappingOption.BlockSnappingRadius)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port2.CanAttachTo(port) == true)
|
||||
{
|
||||
diagramViewModel.AddAttachTo(port, true);
|
||||
next = port;
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
diagramViewModel.AddAttachTo(port, false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//next
|
||||
if (next == null)
|
||||
if (success)
|
||||
{
|
||||
if ((port.Orientation == ConnectorOrientation.Left && port2.Orientation == ConnectorOrientation.Right)
|
||||
|| (port.Orientation == ConnectorOrientation.Top && port2.Orientation == ConnectorOrientation.Bottom))
|
||||
{
|
||||
|
||||
if (port.Position.DistanceTo(port2.Position) < diagramViewModel.DiagramOption.SnappingOption.SnappingRadius)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port2.CanAttachTo(port) == true)
|
||||
{
|
||||
diagramViewModel.AddAttachTo(port, true);
|
||||
next = port;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
diagramViewModel.AddAttachTo(port, false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,6 +184,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
diagramViewModel.ClearAttachTo();
|
||||
var links = BlockDesignerItemTempLink.Build(blocks);
|
||||
|
||||
blocks.ToList().ForEach(p => {
|
||||
p.ZIndex = int.MaxValue;
|
||||
});
|
||||
|
||||
foreach (BlockDesignerItemTempLink item in links)
|
||||
{
|
||||
var container = diagramViewModel.FindNearContainerToAttachTo(item);
|
||||
@@ -195,6 +212,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
var links = BlockDesignerItemTempLink.Build(blocks);
|
||||
|
||||
blocks.ToList().ForEach(p => {
|
||||
p.ZIndex = diagramViewModel.Items.Any() ? diagramViewModel.Items.Where(q => q.ZIndex != int.MaxValue).Max(r => r.ZIndex) + 1 : 0;
|
||||
});
|
||||
|
||||
foreach (BlockDesignerItemTempLink item in links)
|
||||
{
|
||||
var container = diagramViewModel.FindNearContainerToAttachTo(item);
|
||||
@@ -246,7 +267,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
diagramViewModel.ClearAttachTo();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user