This commit is contained in:
艾竹
2023-06-15 22:44:12 +08:00
parent 207523eb16
commit 1dd09a2240
4 changed files with 65 additions and 14 deletions

View File

@@ -227,19 +227,23 @@ namespace AIStudio.Wpf.DiagramDesigner
Children.Remove(child);
}
public List<ItemsContainerInfo> GetAllContain(ObservableCollection<BlockDesignerItemViewModel> children)
public List<ItemsContainerInfo> GetAllContain(ObservableCollection<BlockDesignerItemViewModel> children, bool self)
{
List <ItemsContainerInfo> itemsContainers= new List <ItemsContainerInfo>();
if (self)
{
itemsContainers.Add(this);
}
if (children != null)
{
foreach (var item in children)
{
if (item.Contains != null)
{
itemsContainers.AddRange(item.Contains);
foreach (var contain in item.Contains)
{
itemsContainers.AddRange(contain.GetAllContain(contain.Children));
itemsContainers.Add(contain);
itemsContainers.AddRange(contain.GetAllContain(contain.Children, false));
}
}
}

View File

@@ -3160,17 +3160,33 @@ namespace AIStudio.Wpf.DiagramDesigner
{
if (port.GetBounds().IntersectsWith(blockDesignerItemViewModel.GetBounds())) //如果两个位置相交
{
port.DataItem.ShowConnectors = true;
if (port.CanAttachTo(blockDesignerItemViewModel) == true)
var innerport = port.GetAllContain(port.Children, false).Where(p => p.GetBounds().IntersectsWith(blockDesignerItemViewModel.GetBounds())).OrderByDescending(p => p.ContainLevel).FirstOrDefault();
if (innerport != null)
{
port.BeAttachTo = true;
innerport.DataItem.ShowConnectors = true;
if (innerport.CanAttachTo(blockDesignerItemViewModel) == true)
{
innerport.BeAttachTo = true;
}
else
{
innerport.DisableAttachTo = true;
}
return innerport;
}
else
{
port.DisableAttachTo = true;
port.DataItem.ShowConnectors = true;
if (port.CanAttachTo(blockDesignerItemViewModel) == true)
{
port.BeAttachTo = true;
}
else
{
port.DisableAttachTo = true;
}
return port;
}
return port;
}
}
@@ -3190,7 +3206,7 @@ namespace AIStudio.Wpf.DiagramDesigner
public void ClearNearContain()
{
Items.OfType<BlockDesignerItemViewModel>().ToList().SelectMany(n => n.Contains).Where(p => p.BeAttachTo == true || p.DisableAttachTo == true).ToList()
Items.OfType<BlockDesignerItemViewModel>().ToList().SelectMany(n => n.GetAllContain()).Where(p => p.BeAttachTo == true || p.DisableAttachTo == true).ToList()
.ForEach(p => {
p.DisableAttachTo = false;
p.BeAttachTo = false;