2023-05-21 22:06:59 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2023-06-11 23:58:22 +08:00
|
|
|
|
using System.Collections.ObjectModel;
|
2023-05-21 22:06:59 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Models;
|
2023-06-13 19:06:51 +08:00
|
|
|
|
using static System.Net.Mime.MediaTypeNames;
|
2023-05-21 22:06:59 +08:00
|
|
|
|
|
|
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
|
|
|
|
|
{
|
|
|
|
|
|
public class BlockDesignerItemViewModel : DesignerItemViewModelBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public BlockDesignerItemViewModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public BlockDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public BlockDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public BlockDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void InitNew()
|
|
|
|
|
|
{
|
2023-06-11 23:58:22 +08:00
|
|
|
|
ItemWidth = double.NaN;
|
|
|
|
|
|
ItemHeight = double.NaN;
|
2023-05-21 22:06:59 +08:00
|
|
|
|
AddConnector(new BlockConnectorInfo(this.Root, this, ConnectorOrientation.Top));
|
|
|
|
|
|
AddConnector(new BlockConnectorInfo(this.Root, this, ConnectorOrientation.Bottom));
|
2023-06-11 23:58:22 +08:00
|
|
|
|
IsReadOnlyText = true;
|
2023-05-21 22:06:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public BlockDesignerItemViewModel Next
|
|
|
|
|
|
{
|
2023-06-11 23:58:22 +08:00
|
|
|
|
get; set;
|
2023-06-14 19:41:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-16 19:03:15 +08:00
|
|
|
|
public BlockItemsContainerInfo ParentContain
|
2023-06-14 19:41:29 +08:00
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
2023-05-21 22:06:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddNext(BlockDesignerItemViewModel next)
|
|
|
|
|
|
{
|
2023-06-13 19:06:51 +08:00
|
|
|
|
if (this.Next == next)
|
|
|
|
|
|
{
|
|
|
|
|
|
AlignNext(next);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
RemoveNext();
|
|
|
|
|
|
|
2023-05-21 22:06:59 +08:00
|
|
|
|
next.Left = this.Left;
|
2023-06-11 23:58:22 +08:00
|
|
|
|
next.Top = this.Top + this.GetItemHeight();
|
2023-05-21 22:06:59 +08:00
|
|
|
|
next.ParentId = this.Id;
|
|
|
|
|
|
next.Parent = this;
|
|
|
|
|
|
this.Next = next;
|
2023-06-13 19:06:51 +08:00
|
|
|
|
if (next.Next != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
next.AlignNext(next.Next);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AlignNext(BlockDesignerItemViewModel next)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (next != null && this.Next == next)
|
|
|
|
|
|
{
|
|
|
|
|
|
next.Left = this.Left;
|
|
|
|
|
|
next.Top = this.Top + this.GetItemHeight();
|
|
|
|
|
|
if (next.Next != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
next.AlignNext(next.Next);
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-06-11 23:58:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RemoveNext()
|
|
|
|
|
|
{
|
|
|
|
|
|
var next = this.Next;
|
|
|
|
|
|
if (next != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
next.ParentId = new Guid();
|
|
|
|
|
|
next.Parent = null;
|
|
|
|
|
|
this.Next = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public BlockDesignerItemViewModel GetLastNext()
|
|
|
|
|
|
{
|
|
|
|
|
|
var next = this.Next;
|
|
|
|
|
|
if (next != null)
|
2023-05-21 22:06:59 +08:00
|
|
|
|
{
|
2023-06-11 23:58:22 +08:00
|
|
|
|
while (next.Next != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
next = next.Next;
|
|
|
|
|
|
}
|
2023-05-21 22:06:59 +08:00
|
|
|
|
}
|
2023-06-11 23:58:22 +08:00
|
|
|
|
return next;
|
2023-05-21 22:06:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void AddToSelection(bool selected, bool clearother)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (clearother)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (SelectableDesignerItemViewModelBase item in Root.SelectedItems.ToList())
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item != this)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.RemoveFromSelection();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IsSelected = selected;
|
|
|
|
|
|
}
|
2023-06-11 23:58:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void AddChild(BlockDesignerItemViewModel child)
|
|
|
|
|
|
{
|
|
|
|
|
|
child.RemoveFromSelection();
|
2023-06-15 22:44:12 +08:00
|
|
|
|
this.GetRootParent.AddToSelection(true, true);
|
2023-06-13 19:06:51 +08:00
|
|
|
|
|
2023-06-13 22:51:34 +08:00
|
|
|
|
System.Windows.Application.Current?.Dispatcher.BeginInvoke(new Action(async () => {
|
2023-06-13 22:51:59 +08:00
|
|
|
|
await Task.Delay(10);
|
2023-06-13 22:51:34 +08:00
|
|
|
|
AlignNext(this.Next);
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
2023-06-11 23:58:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void RemoveChild(BlockDesignerItemViewModel child)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.RemoveFromSelection();
|
2023-06-15 22:44:12 +08:00
|
|
|
|
|
|
|
|
|
|
child.AddToSelection(true, true);
|
2023-06-13 19:06:51 +08:00
|
|
|
|
|
2023-06-13 22:51:34 +08:00
|
|
|
|
System.Windows.Application.Current?.Dispatcher.BeginInvoke(new Action(async () => {
|
2023-06-13 22:51:59 +08:00
|
|
|
|
await Task.Delay(10);
|
2023-06-13 22:51:34 +08:00
|
|
|
|
AlignNext(this.Next);
|
|
|
|
|
|
}));
|
2023-06-11 23:58:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-16 19:03:15 +08:00
|
|
|
|
public ObservableCollection<BlockItemsContainerInfo> Contains
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
2023-06-16 19:03:15 +08:00
|
|
|
|
} = new ObservableCollection<BlockItemsContainerInfo>();
|
2023-06-11 23:58:22 +08:00
|
|
|
|
|
2023-06-16 19:03:15 +08:00
|
|
|
|
public BlockItemsContainerInfo FirstContain
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return Contains?.FirstOrDefault();
|
|
|
|
|
|
}
|
2023-06-15 22:44:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-16 19:03:15 +08:00
|
|
|
|
public List<BlockItemsContainerInfo> GetAllContain()
|
2023-06-15 22:44:12 +08:00
|
|
|
|
{
|
|
|
|
|
|
return Contains.SelectMany(p => p.GetAllContain(p.Children, true)).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public BlockDesignerItemViewModel GetRootParent
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ParentContain == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return ParentContain.DataItem.GetRootParent;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-06-11 23:58:22 +08:00
|
|
|
|
}
|
2023-05-21 22:06:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|