This commit is contained in:
艾竹
2023-06-17 23:55:54 +08:00
parent 56545ece4b
commit 0b0f81faac
12 changed files with 346 additions and 81 deletions

View File

@@ -29,32 +29,40 @@ namespace AIStudio.Wpf.DiagramDesigner
{
base.InitNew();
Contains.Add(new BlockItemsContainerInfo(this.Root, this));
Containers.Add(new BlockItemsContainerInfo(this.Root, this));
}
public override void AddChild(BlockDesignerItemViewModel child)
public override void AddChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
{
var oldchildren = FirstContain.Children.FirstOrDefault();
if (container == null)
{
container = FirstContainer;
}
var oldchildren = container.Children.FirstOrDefault();
if (oldchildren != null)
{
this.RemoveChild(oldchildren);
this.RemoveChild(oldchildren, container);
}
Root.Items.Remove(child);
FirstContain.AddChild(child);
container.AddChild(child);
base.AddChild(child);
base.AddChild(child, container);
}
public override void RemoveChild(BlockDesignerItemViewModel child)
{
public override void RemoveChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
{
if (container == null)
{
container = FirstContainer;
}
Root.Items.Add(child);
FirstContain.RemoveChild(child);
container.RemoveChild(child);
this.RemoveFromSelection();
child.AddToSelection(true, false);
base.RemoveChild(child);
base.RemoveChild(child, container);
}
}
}

View File

@@ -29,23 +29,31 @@ namespace AIStudio.Wpf.DiagramDesigner
{
base.InitNew();
Contains.Add(new BlockItemsContainerInfo(this.Root, this));
Containers.Add(new BlockItemsContainerInfo(this.Root, this));
}
public override void AddChild(BlockDesignerItemViewModel child)
public override void AddChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
{
if (container == null)
{
container = FirstContainer;
}
Root.Items.Remove(child);
FirstContain.Children.Add(child);
container.Children.Add(child);
base.AddChild(child);
base.AddChild(child, container);
}
public override void RemoveChild(BlockDesignerItemViewModel child)
public override void RemoveChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
{
if (container == null)
{
container = FirstContainer;
}
Root.Items.Add(child);
FirstContain.Children.Remove(child);
container.Children.Remove(child);
base.RemoveChild(child);
base.RemoveChild(child, container);
}
}
}

View File

@@ -1,24 +1,72 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AIStudio.Wpf.DiagramDesigner.Geometrys;
namespace AIStudio.Wpf.DiagramDesigner
{
public class BlockDesignerItemTempLink
{
List<BlockDesignerItemViewModel> Items
public List<BlockDesignerItemViewModel> Items
{
get;set;
get; set;
} = new List<BlockDesignerItemViewModel>();
//public static List<BlockDesignerItemTempLink> Build(List<BlockDesignerItemViewModel> blocks)
//{
// List<BlockDesignerItemTempLink> links = new List<BlockDesignerItemTempLink>(){
// new BlockDesignerItemTempLink() };
public RectangleBase GetBounds(bool includePorts = false)
{
return Items.FirstOrDefault().GetBounds();
}
// foreach(var )
//}
public List<FullyCreatedConnectorInfo> Connectors
{
get
{
List<FullyCreatedConnectorInfo> connectors = new List<FullyCreatedConnectorInfo>();
if (Items.FirstOrDefault().TopConnector != null)
{
connectors.Add(Items.FirstOrDefault().TopConnector);
}
if (Items.FirstOrDefault().LeftConnector != null)
{
connectors.Add(Items.FirstOrDefault().LeftConnector);
}
if (Items.LastOrDefault().BottomConnector != null)
{
connectors.Add(Items.LastOrDefault().BottomConnector);
}
if (Items.LastOrDefault().RightConnector != null)
{
connectors.Add(Items.LastOrDefault().RightConnector);
}
return connectors;
}
}
public static List<BlockDesignerItemTempLink> Build(List<BlockDesignerItemViewModel> blocks)
{
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;
}
}
if (success == false)
{
BlockDesignerItemTempLink link = new BlockDesignerItemTempLink();
link.Items.Add(block);
links.Add(link);
}
}
return links;
}
}
}

View File

@@ -43,6 +43,7 @@ namespace AIStudio.Wpf.DiagramDesigner
AlignNext(next);
return;
}
var oldnext = this.Next;
RemoveNext();
next.Left = this.Left;
@@ -54,6 +55,14 @@ namespace AIStudio.Wpf.DiagramDesigner
{
next.AlignNext(next.Next);
}
if (oldnext != null)
{
System.Windows.Application.Current?.Dispatcher.BeginInvoke(new Action(async () => {
await Task.Delay(10);
GetLast().AddNext(oldnext);
}));
}
}
public void AlignNext(BlockDesignerItemViewModel next)
@@ -97,7 +106,7 @@ namespace AIStudio.Wpf.DiagramDesigner
IsSelected = selected;
}
public virtual void AddChild(BlockDesignerItemViewModel child)
public virtual void AddChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
{
child.RemoveFromSelection();
this.GetRootContainItem.AddToSelection(true, true);
@@ -108,7 +117,7 @@ namespace AIStudio.Wpf.DiagramDesigner
}));
}
public virtual void RemoveChild(BlockDesignerItemViewModel child)
public virtual void RemoveChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
{
this.RemoveFromSelection();
@@ -120,6 +129,21 @@ namespace AIStudio.Wpf.DiagramDesigner
}));
}
public int BlockLevel
{
get
{
if (Prev == null)
{
return 0;
}
else
{
return Prev.BlockLevel + 1;
}
}
}
public BlockDesignerItemViewModel Prev
{
get
@@ -133,24 +157,45 @@ namespace AIStudio.Wpf.DiagramDesigner
get; set;
}
public BlockItemsContainerInfo ParentContain
public bool CanContainTo
{
get; set;
} = true;
public BlockItemsContainerInfo ParentContainer
{
get; set;
}
public ObservableCollection<BlockItemsContainerInfo> Contains
public ObservableCollection<BlockItemsContainerInfo> Containers
{
get; set;
} = new ObservableCollection<BlockItemsContainerInfo>();
public BlockItemsContainerInfo FirstContain
public BlockItemsContainerInfo FirstContainer
{
get
{
return Contains?.FirstOrDefault();
return Containers?.FirstOrDefault();
}
}
public BlockItemsContainerInfo SecondContainer
{
get
{
return Containers?.Skip(1)?.FirstOrDefault();
}
}
public BlockItemsContainerInfo ThirdContainer
{
get
{
return Containers?.Skip(2)?.FirstOrDefault();
}
}
public BlockDesignerItemViewModel GetFirst()
{
var parent = this.Next;
@@ -179,20 +224,20 @@ namespace AIStudio.Wpf.DiagramDesigner
public List<BlockItemsContainerInfo> GetAllContain()
{
return Contains.SelectMany(p => p.GetAllContain(p.Children, true)).ToList();
return Containers.SelectMany(p => p.GetAllContain(p.Children, true)).ToList();
}
public BlockDesignerItemViewModel GetRootContainItem
{
get
{
if (ParentContain == null)
if (ParentContainer == null)
{
return this;
}
else
{
return ParentContain.DataItem.GetRootContainItem;
return ParentContainer.DataItem.GetRootContainItem;
}
}
}