mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
block
This commit is contained in:
@@ -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