mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-18 15:36:36 +08:00
block
This commit is contained in:
@@ -12,14 +12,16 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class BlockItemsContainerInfo : SelectableViewModelBase
|
||||
{
|
||||
public BlockItemsContainerInfo(BlockDesignerItemViewModel dataItem) : this(null, dataItem)
|
||||
public BlockItemsContainerInfo(BlockDesignerItemViewModel dataItem, bool onlyOneChild, List<string> childFlag) : this(null, dataItem, onlyOneChild, childFlag)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public BlockItemsContainerInfo(IDiagramViewModel root, BlockDesignerItemViewModel dataItem) : base(root)
|
||||
public BlockItemsContainerInfo(IDiagramViewModel root, BlockDesignerItemViewModel dataItem, bool onlyOneChild, List<string> childFlag) : base(root)
|
||||
{
|
||||
this.Parent = dataItem;
|
||||
this.OnlyOneChild = onlyOneChild;
|
||||
this.ChildFlag = childFlag;
|
||||
}
|
||||
|
||||
public BlockItemsContainerInfo(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
@@ -65,6 +67,17 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
|
||||
#region 属性
|
||||
public bool OnlyOneChild
|
||||
{
|
||||
get; set;
|
||||
} = true;
|
||||
|
||||
public List<string> ChildFlag
|
||||
{
|
||||
get; set;
|
||||
} = new List<string>();
|
||||
|
||||
|
||||
private double _itemWidth = double.NaN;
|
||||
public double ItemWidth
|
||||
{
|
||||
@@ -147,7 +160,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public List<BlockItemsContainerInfo> ChildrenContain
|
||||
public List<BlockItemsContainerInfo> ChildrenContainer
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -155,7 +168,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public int ContainLevel
|
||||
public int ContainerLevel
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -165,7 +178,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
else
|
||||
{
|
||||
return DataItem.ParentContainer.ContainLevel + 1;
|
||||
return DataItem.ParentContainer.ContainerLevel + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -210,7 +223,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
|
||||
public virtual bool CanAttachTo(BlockDesignerItemViewModel item)
|
||||
=> item != null && item != this.DataItem && !item.IsReadOnly && item.CanContainTo;
|
||||
=> item != null && item != this.DataItem && !item.IsReadOnly && (this.ChildFlag == null || this.ChildFlag.Count == 0 || this.ChildFlag.Contains(item.Flag));
|
||||
#endregion
|
||||
|
||||
public double GetItemWidth()
|
||||
@@ -237,7 +250,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public List<BlockItemsContainerInfo> GetAllContain(ObservableCollection<BlockDesignerItemViewModel> children, bool self)
|
||||
{
|
||||
List <BlockItemsContainerInfo> itemsContainers= new List <BlockItemsContainerInfo>();
|
||||
List<BlockItemsContainerInfo> itemsContainers = new List<BlockItemsContainerInfo>();
|
||||
if (self)
|
||||
{
|
||||
itemsContainers.Add(this);
|
||||
|
||||
@@ -3221,7 +3221,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (port.GetBounds().IntersectsWith(blockDesignerItemViewModel.GetBounds())) //如果两个位置相交
|
||||
{
|
||||
var innerport = port.GetAllContain(port.Children, false).Where(p => p.GetBounds().IntersectsWith(blockDesignerItemViewModel.GetBounds())).OrderByDescending(p => p.ContainLevel).FirstOrDefault();
|
||||
var innerport = port.GetAllContain(port.Children, false).Where(p => p.GetBounds().IntersectsWith(blockDesignerItemViewModel.GetBounds())).OrderByDescending(p => p.ContainerLevel).FirstOrDefault();
|
||||
if (innerport != null)
|
||||
{
|
||||
innerport.DataItem.ShowConnectors = true;
|
||||
@@ -3356,7 +3356,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (port.GetBounds().IntersectsWith(blockDesignerItemTempLink.GetBounds())) //如果两个位置相交
|
||||
{
|
||||
var innerport = port.GetAllContain(port.Children, false).Where(p => p.GetBounds().IntersectsWith(blockDesignerItemTempLink.GetBounds())).OrderByDescending(p => p.ContainLevel).FirstOrDefault();
|
||||
var innerport = port.GetAllContain(port.Children, false).Where(p => p.GetBounds().IntersectsWith(blockDesignerItemTempLink.GetBounds())).OrderByDescending(p => p.ContainerLevel).FirstOrDefault();
|
||||
if (innerport != null)
|
||||
{
|
||||
innerport.DataItem.ShowConnectors = true;
|
||||
@@ -3446,7 +3446,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
var container = FindNearContainerToAttachTo(item);
|
||||
if (container != null)
|
||||
{
|
||||
(container.DataItem as BlockDesignerItemViewModel).AddChild(item.Items.FirstOrDefault(), container);//待完善
|
||||
container.DataItem.AddChild(item.Items.FirstOrDefault(), container);//待完善
|
||||
container.BeAttachTo = false;
|
||||
container.DisableAttachTo = false;
|
||||
continue;
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class BlockContainDesignerItemViewModel : BlockDesignerItemViewModel
|
||||
{
|
||||
public BlockContainDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public BlockContainDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public BlockContainDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public BlockContainDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
base.InitNew();
|
||||
|
||||
Containers.Add(new BlockItemsContainerInfo(this.Root, this));
|
||||
}
|
||||
|
||||
public override void AddChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
|
||||
{
|
||||
if (container == null)
|
||||
{
|
||||
container = FirstContainer;
|
||||
}
|
||||
var oldchildren = container.Children.FirstOrDefault();
|
||||
if (oldchildren != null)
|
||||
{
|
||||
this.RemoveChild(oldchildren, container);
|
||||
}
|
||||
|
||||
Root.Items.Remove(child);
|
||||
container.AddChild(child);
|
||||
|
||||
base.AddChild(child, container);
|
||||
}
|
||||
|
||||
public override void RemoveChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
|
||||
{
|
||||
if (container == null)
|
||||
{
|
||||
container = FirstContainer;
|
||||
}
|
||||
Root.Items.Add(child);
|
||||
container.RemoveChild(child);
|
||||
|
||||
this.RemoveFromSelection();
|
||||
child.AddToSelection(true, false);
|
||||
|
||||
base.RemoveChild(child, container);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class BlockContainListDesignerItemViewModel : BlockDesignerItemViewModel
|
||||
{
|
||||
public BlockContainListDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public BlockContainListDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public BlockContainListDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public BlockContainListDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
base.InitNew();
|
||||
|
||||
Containers.Add(new BlockItemsContainerInfo(this.Root, this));
|
||||
}
|
||||
|
||||
public override void AddChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
|
||||
{
|
||||
if (container == null)
|
||||
{
|
||||
container = FirstContainer;
|
||||
}
|
||||
Root.Items.Remove(child);
|
||||
container.Children.Add(child);
|
||||
|
||||
base.AddChild(child, container);
|
||||
}
|
||||
|
||||
public override void RemoveChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
|
||||
{
|
||||
if (container == null)
|
||||
{
|
||||
container = FirstContainer;
|
||||
}
|
||||
Root.Items.Add(child);
|
||||
container.Children.Remove(child);
|
||||
|
||||
base.RemoveChild(child, container);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
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
|
||||
{
|
||||
public List<BlockDesignerItemViewModel> Items
|
||||
{
|
||||
get; set;
|
||||
} = new List<BlockDesignerItemViewModel>();
|
||||
|
||||
public RectangleBase GetBounds(bool includePorts = false)
|
||||
{
|
||||
return Items.FirstOrDefault().GetBounds();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
@@ -61,7 +62,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
await Task.Delay(10);
|
||||
GetLast().AddNext(oldnext);
|
||||
}));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,19 +109,41 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public virtual void AddChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
|
||||
{
|
||||
if (container == null)
|
||||
{
|
||||
container = FirstContainer;
|
||||
}
|
||||
|
||||
if (container.OnlyOneChild)
|
||||
{
|
||||
var oldchildren = container.Children.FirstOrDefault();
|
||||
if (oldchildren != null)
|
||||
{
|
||||
this.RemoveChild(oldchildren, container);
|
||||
}
|
||||
}
|
||||
Root.Items.Remove(child);
|
||||
container.AddChild(child);
|
||||
|
||||
child.RemoveFromSelection();
|
||||
this.GetRootContainItem.AddToSelection(true, true);
|
||||
|
||||
System.Windows.Application.Current?.Dispatcher.BeginInvoke(new Action(async () => {
|
||||
await Task.Delay(10);
|
||||
AlignNext(this.Next);
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
public virtual void RemoveChild(BlockDesignerItemViewModel child, BlockItemsContainerInfo container)
|
||||
{
|
||||
this.RemoveFromSelection();
|
||||
if (container == null)
|
||||
{
|
||||
container = FirstContainer;
|
||||
}
|
||||
Root.Items.Add(child);
|
||||
container.RemoveChild(child);
|
||||
|
||||
this.RemoveFromSelection();
|
||||
child.AddToSelection(true, true);
|
||||
|
||||
System.Windows.Application.Current?.Dispatcher.BeginInvoke(new Action(async () => {
|
||||
@@ -129,6 +152,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}));
|
||||
}
|
||||
|
||||
public string Flag
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public int BlockLevel
|
||||
{
|
||||
get
|
||||
@@ -157,11 +185,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
get; set;
|
||||
}
|
||||
|
||||
public bool CanContainTo
|
||||
{
|
||||
get; set;
|
||||
} = true;
|
||||
|
||||
public BlockItemsContainerInfo ParentContainer
|
||||
{
|
||||
get; set;
|
||||
@@ -194,7 +217,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
return Containers?.Skip(2)?.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BlockDesignerItemViewModel GetFirst()
|
||||
{
|
||||
@@ -242,4 +265,124 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region 扩展
|
||||
public class BlockContainDesignerItemViewModel : BlockDesignerItemViewModel
|
||||
{
|
||||
public BlockContainDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public BlockContainDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public BlockContainDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public BlockContainDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
base.InitNew();
|
||||
|
||||
Containers.Add(new BlockItemsContainerInfo(this.Root, this, true, null));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class BlockContainListDesignerItemViewModel : BlockDesignerItemViewModel
|
||||
{
|
||||
public BlockContainListDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public BlockContainListDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public BlockContainListDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public BlockContainListDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
base.InitNew();
|
||||
|
||||
Containers.Add(new BlockItemsContainerInfo(this.Root, this, false, null));
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 帮助
|
||||
public class BlockDesignerItemTempLink
|
||||
{
|
||||
public List<BlockDesignerItemViewModel> Items
|
||||
{
|
||||
get; set;
|
||||
} = new List<BlockDesignerItemViewModel>();
|
||||
|
||||
public RectangleBase GetBounds()
|
||||
{
|
||||
return Items.FirstOrDefault().GetBounds();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user