mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
block
This commit is contained in:
@@ -7,7 +7,7 @@ using System.Windows;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public static class BlockDesignerItemViewModelHelper
|
||||
public static partial class BlockDesignerItemViewModelHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// type=0最近且没有依附;=1
|
||||
@@ -55,13 +55,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port2.CanAttachTo(port) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, true);
|
||||
parent = port;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DisableAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -80,13 +80,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port2.CanAttachTo(port) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, true);
|
||||
next = port;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DisableAttachTo = true;
|
||||
diagramViewModel.AddAttachTo(port, false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -98,20 +98,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return new Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo>(parent, next);
|
||||
}
|
||||
|
||||
|
||||
public static void ClearNearContain(this IDiagramViewModel diagramViewModel)
|
||||
{
|
||||
diagramViewModel.Items.OfType<BlockDesignerItemViewModel>().ToList().SelectMany(n => n.GetAllContainers()).ToList()
|
||||
.ForEach(p => {
|
||||
p.DisableAttachTo = false;
|
||||
p.BeAttachTo = false;
|
||||
p.Children.SelectMany(n => n.Connectors).Where(q => q.BeAttachTo == true || q.DisableAttachTo == true).ToList().ForEach(q => {
|
||||
q.DisableAttachTo = false;
|
||||
q.BeAttachTo = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static BlockItemsContainerInfo FindNearContainerToAttachTo(this IDiagramViewModel diagramViewModel, BlockDesignerItemTempLink blockDesignerItemTempLink)
|
||||
{
|
||||
if (blockDesignerItemTempLink == null || blockDesignerItemTempLink.Items == null || blockDesignerItemTempLink.Items.Count == 0)
|
||||
@@ -127,20 +113,19 @@ 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)
|
||||
{
|
||||
innerport.DataItem.ShowConnectors = true;
|
||||
{
|
||||
if (innerport.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true)
|
||||
{
|
||||
innerport.DataItem.ShowConnectors = true;
|
||||
if (innerport.OnlyOneChild || innerport.Children.Count == 0)
|
||||
{
|
||||
innerport.BeAttachTo = true;
|
||||
return innerport;
|
||||
diagramViewModel.AddAttachTo(innerport, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
diagramViewModel.FindNearPortToAttachTo(innerport.Children.ToList(), blockDesignerItemTempLink);
|
||||
return innerport;
|
||||
diagramViewModel.FindNearPortToAttachTo(innerport.Children.ToList(), blockDesignerItemTempLink);
|
||||
}
|
||||
return innerport;
|
||||
}
|
||||
//else
|
||||
//{
|
||||
@@ -151,19 +136,19 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
else
|
||||
{
|
||||
container.DataItem.ShowConnectors = true;
|
||||
|
||||
if (container.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true)
|
||||
{
|
||||
container.DataItem.ShowConnectors = true;
|
||||
if (container.OnlyOneChild || container.Children.Count == 0)
|
||||
{
|
||||
container.BeAttachTo = true;
|
||||
return container;
|
||||
diagramViewModel.AddAttachTo(container, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
diagramViewModel.FindNearPortToAttachTo(container.Children.ToList(), blockDesignerItemTempLink);
|
||||
return container;
|
||||
}
|
||||
diagramViewModel.FindNearPortToAttachTo(container.Children.ToList(), blockDesignerItemTempLink);
|
||||
}
|
||||
return container;
|
||||
}
|
||||
//else
|
||||
//{
|
||||
@@ -185,8 +170,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
if (blocks.Any())
|
||||
{
|
||||
diagramViewModel.ClearNearPort();
|
||||
diagramViewModel.ClearNearContain();
|
||||
diagramViewModel.ClearAttachTo();
|
||||
var links = BlockDesignerItemTempLink.Build(blocks);
|
||||
foreach (BlockDesignerItemTempLink item in links)
|
||||
{
|
||||
@@ -208,9 +192,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return;
|
||||
|
||||
if (blocks.Any())
|
||||
{
|
||||
diagramViewModel.ClearNearPort();
|
||||
diagramViewModel.ClearNearContain();
|
||||
{
|
||||
var links = BlockDesignerItemTempLink.Build(blocks);
|
||||
|
||||
foreach (BlockDesignerItemTempLink item in links)
|
||||
@@ -228,14 +210,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
index ++;
|
||||
}
|
||||
}
|
||||
diagramViewModel.InsertChildCommand.Execute(new BlockContainerPara() { Item = container.DataItem, Child = item.Items.FirstOrDefault(), Container = container, Index = index });
|
||||
|
||||
container.BeAttachTo = false;
|
||||
container.DisableAttachTo = false;
|
||||
container.Children.SelectMany(n => n.Connectors).Where(q => q.BeAttachTo == true || q.DisableAttachTo == true).ToList().ForEach(q => {
|
||||
q.DisableAttachTo = false;
|
||||
q.BeAttachTo = false;
|
||||
});
|
||||
diagramViewModel.InsertChildCommand.Execute(new BlockContainerPara() { Item = container.DataItem, Child = item.Items.FirstOrDefault(), Container = container, Index = index });
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -271,6 +246,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
diagramViewModel.ClearAttachTo();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user