mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
block
This commit is contained in:
@@ -130,9 +130,34 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
this.RemoveChild(oldchildren, container);
|
||||
}
|
||||
Root.Items.Remove(child);
|
||||
if (child.Prev != null)
|
||||
{
|
||||
child.Prev.RemoveNext();
|
||||
}
|
||||
if (child.Next != null)
|
||||
{
|
||||
child.RemoveNext();
|
||||
}
|
||||
container.InsertChild(child, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = child.GetNexts(true);
|
||||
list.Reverse();
|
||||
list.ForEach(p => {
|
||||
Root.Items.Remove(p);
|
||||
if (p.Prev != null)
|
||||
{
|
||||
p.Prev.RemoveNext();
|
||||
}
|
||||
if (p.Next != null)
|
||||
{
|
||||
p.RemoveNext();
|
||||
}
|
||||
container.InsertChild(p, index);
|
||||
});
|
||||
}
|
||||
Root.Items.Remove(child);
|
||||
container.InsertChild(child, index);
|
||||
|
||||
child.RemoveFromSelection();
|
||||
this.GetRootContainItem.AddToSelection(true, true);
|
||||
@@ -237,28 +262,44 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public BlockDesignerItemViewModel GetFirst()
|
||||
{
|
||||
var parent = this.Next;
|
||||
if (parent != null)
|
||||
var parent = this.Prev;
|
||||
while (parent?.Prev != null)
|
||||
{
|
||||
while (parent.Prev != null)
|
||||
{
|
||||
parent = Prev;
|
||||
}
|
||||
parent = parent.Prev;
|
||||
}
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
public BlockDesignerItemViewModel GetLast()
|
||||
{
|
||||
var next = this;
|
||||
if (next != null)
|
||||
while (next.Next != null)
|
||||
{
|
||||
while (next.Next != null)
|
||||
next = next.Next;
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
public List<BlockDesignerItemViewModel> GetNexts(bool self)
|
||||
{
|
||||
List<BlockDesignerItemViewModel> blockDesignerItemViewModels = new List<BlockDesignerItemViewModel>();
|
||||
if (self)
|
||||
{
|
||||
blockDesignerItemViewModels.Add(this);
|
||||
}
|
||||
var next = this;
|
||||
while (next != null)
|
||||
{
|
||||
next = next.Next;
|
||||
if (next != null)
|
||||
{
|
||||
next = next.Next;
|
||||
blockDesignerItemViewModels.Add(next);
|
||||
}
|
||||
}
|
||||
return next;
|
||||
|
||||
return blockDesignerItemViewModels;
|
||||
}
|
||||
|
||||
public void AddContainer(BlockItemsContainerInfo container)
|
||||
@@ -404,12 +445,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
List<BlockDesignerItemTempLink> links = new List<BlockDesignerItemTempLink>();
|
||||
foreach (var block in blocks.OrderBy(p => p.BlockLevel).ToList())
|
||||
{
|
||||
{
|
||||
bool success = false;
|
||||
foreach (var link in links)
|
||||
{
|
||||
if (link.Items.LastOrDefault() == block.Prev)
|
||||
{
|
||||
{
|
||||
link.Items.Add(block);
|
||||
success = true;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -34,30 +35,32 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
FullyCreatedConnectorInfo parent = null;
|
||||
FullyCreatedConnectorInfo next = null;
|
||||
|
||||
foreach (var item in items)
|
||||
|
||||
foreach (var port2 in blockDesignerItemTempLink.Connectors.OfType<BlockConnectorInfo>())
|
||||
{
|
||||
bool success = false;
|
||||
foreach (var port in item.Connectors.OfType<BlockConnectorInfo>())
|
||||
{
|
||||
//已经被连接的不允许在顶部吸附了
|
||||
if ((port.Orientation == ConnectorOrientation.Top || port.Orientation == ConnectorOrientation.Left) && port.DataItem.Prev != null)
|
||||
foreach (var item in items)
|
||||
{
|
||||
foreach (var port in item.Connectors.OfType<BlockConnectorInfo>())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
//已经被连接的不允许在顶部吸附了
|
||||
if ((port.Orientation == ConnectorOrientation.Top || port.Orientation == ConnectorOrientation.Left) && port.DataItem.Prev != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var port2 in blockDesignerItemTempLink.Connectors.OfType<BlockConnectorInfo>())
|
||||
{
|
||||
//parent
|
||||
if (parent == null)
|
||||
{
|
||||
if ((port.Orientation == ConnectorOrientation.Right && port2.Orientation == ConnectorOrientation.Left)
|
||||
|| (port.Orientation == ConnectorOrientation.Bottom && port2.Orientation == ConnectorOrientation.Top))
|
||||
{
|
||||
|
||||
if (port.DistanceTo(port2) < diagramViewModel.DiagramOption.SnappingOption.BlockSnappingRadius)
|
||||
var dis = port.DistanceTo(port2);
|
||||
Debug.WriteLine($"{port.DataItem.Name}-{port2.DataItem.Name}:{dis}");
|
||||
if (dis < diagramViewModel.DiagramOption.SnappingOption.BlockSnappingRadius)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port2.CanAttachTo(port) == true)
|
||||
if (port.CanAttachTo(port2) == true)
|
||||
{
|
||||
diagramViewModel.AddAttachTo(port, true);
|
||||
parent = port;
|
||||
@@ -79,11 +82,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
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)
|
||||
var dis = port.DistanceTo(port2);
|
||||
Debug.WriteLine($"{port.DataItem.Name}-{port2.DataItem.Name}:{dis}");
|
||||
if (dis < diagramViewModel.DiagramOption.SnappingOption.BlockSnappingRadius)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port2.CanAttachTo(port) == true)
|
||||
if (port.CanAttachTo(port2) == true)
|
||||
{
|
||||
diagramViewModel.AddAttachTo(port, true);
|
||||
next = port;
|
||||
@@ -105,6 +109,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (success)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo>(parent, next);
|
||||
@@ -125,17 +134,17 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
var innerport = container.GetAllContainers(container.Children, false).Where(p => p.GetBounds().IntersectsWith(blockDesignerItemTempLink.GetBounds())).OrderByDescending(p => p.ContainerLevel).FirstOrDefault();
|
||||
if (innerport != null)
|
||||
{
|
||||
{
|
||||
if (innerport.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true)
|
||||
{
|
||||
innerport.DataItem.ShowConnectors = true;
|
||||
innerport.DataItem.ShowConnectors = true;
|
||||
if (innerport.OnlyOneChild || innerport.Children.Count == 0)
|
||||
{
|
||||
diagramViewModel.AddAttachTo(innerport, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
diagramViewModel.FindNearPortToAttachTo(innerport.Children.ToList(), blockDesignerItemTempLink);
|
||||
diagramViewModel.FindNearPortToAttachTo(innerport.Children.ToList(), blockDesignerItemTempLink);
|
||||
}
|
||||
return innerport;
|
||||
}
|
||||
@@ -148,7 +157,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
if (container.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true)
|
||||
{
|
||||
container.DataItem.ShowConnectors = true;
|
||||
@@ -158,7 +167,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
else
|
||||
{
|
||||
diagramViewModel.FindNearPortToAttachTo(container.Children.ToList(), blockDesignerItemTempLink);
|
||||
diagramViewModel.FindNearPortToAttachTo(container.Children.ToList(), blockDesignerItemTempLink);
|
||||
}
|
||||
return container;
|
||||
}
|
||||
@@ -209,11 +218,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return;
|
||||
|
||||
if (blocks.Any())
|
||||
{
|
||||
{
|
||||
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;
|
||||
p.ZIndex = diagramViewModel.Items.Where(q => q.ZIndex != int.MaxValue).Any() ? diagramViewModel.Items.Where(q => q.ZIndex != int.MaxValue).Max(r => r.ZIndex) + 1 : 0;
|
||||
});
|
||||
|
||||
foreach (BlockDesignerItemTempLink item in links)
|
||||
@@ -228,10 +237,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
index = container.Children.IndexOf(child);
|
||||
if (child.RightConnector?.BeAttachTo == true || child.BottomConnector?.BeAttachTo == true)
|
||||
{
|
||||
index ++;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
diagramViewModel.InsertChildCommand.Execute(new BlockContainerPara() { Item = container.DataItem, Child = item.Items.FirstOrDefault(), Container = container, Index = index });
|
||||
diagramViewModel.InsertChildCommand.Execute(new BlockContainerPara() { Item = container.DataItem, Child = item.Items.FirstOrDefault(), Container = container, Index = index });
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -267,7 +276,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
diagramViewModel.ClearAttachTo();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user