2023-06-11 23:58:22 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Collections.ObjectModel;
|
2023-07-15 10:20:50 +08:00
|
|
|
|
using System.ComponentModel;
|
2023-06-11 23:58:22 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
|
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Models;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
|
|
|
|
|
{
|
2023-06-28 12:06:58 +08:00
|
|
|
|
public class BlockItemsContainerInfo : SelectableViewModelBase, IAttachTo
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
2023-06-18 16:21:18 +08:00
|
|
|
|
public BlockItemsContainerInfo(BlockDesignerItemViewModel dataItem, bool onlyOneChild, List<string> childFlag) : this(null, dataItem, onlyOneChild, childFlag)
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-18 16:21:18 +08:00
|
|
|
|
public BlockItemsContainerInfo(IDiagramViewModel root, BlockDesignerItemViewModel dataItem, bool onlyOneChild, List<string> childFlag) : base(root)
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
this.Parent = dataItem;
|
2023-06-18 16:21:18 +08:00
|
|
|
|
this.OnlyOneChild = onlyOneChild;
|
|
|
|
|
|
this.ChildFlag = childFlag;
|
2023-06-11 23:58:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-15 10:20:50 +08:00
|
|
|
|
public BlockItemsContainerInfo(IDiagramViewModel root, BlockDesignerItemViewModel dataItem, SelectableItemBase designer) : base(root, designer)
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
2023-07-15 10:20:50 +08:00
|
|
|
|
this.Parent = dataItem;
|
2023-06-11 23:58:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-15 10:20:50 +08:00
|
|
|
|
public BlockItemsContainerInfo(IDiagramViewModel root, BlockDesignerItemViewModel dataItem, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
2023-07-15 10:20:50 +08:00
|
|
|
|
this.Parent = dataItem;
|
2023-06-11 23:58:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-15 10:20:50 +08:00
|
|
|
|
public override SelectableItemBase GetSerializableObject()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new BlockItemsContainerInfoItem(this);
|
|
|
|
|
|
}
|
2023-06-11 23:58:22 +08:00
|
|
|
|
|
2024-02-18 16:40:33 +08:00
|
|
|
|
public override void Init(IDiagramViewModel root, bool initNew)
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
base.Init(root, initNew);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void InitNew()
|
|
|
|
|
|
{
|
|
|
|
|
|
ColorViewModel = new ColorViewModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
LineWidth = 1,
|
|
|
|
|
|
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
|
|
|
|
|
|
FillColor = new ColorObject() { Color = Colors.Transparent },
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void LoadDesignerItemViewModel(SelectableItemBase designerbase)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.LoadDesignerItemViewModel(designerbase);
|
|
|
|
|
|
|
2023-07-15 10:20:50 +08:00
|
|
|
|
if (designerbase is BlockItemsContainerInfoItem designer)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.OnlyOneChild = designer.OnlyOneChild;
|
|
|
|
|
|
this.ChildFlag = designer.ChildFlag;
|
|
|
|
|
|
this.PhysicalItemWidth = designer.PhysicalItemWidth;
|
|
|
|
|
|
this.PhysicalItemHeight = designer.PhysicalItemHeight;
|
2023-08-26 21:30:31 +08:00
|
|
|
|
this.Parameter = new ConstParameter(designer.Parameter);
|
2023-07-15 10:20:50 +08:00
|
|
|
|
if (designer.Children != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var child in designer.Children)
|
|
|
|
|
|
{
|
|
|
|
|
|
BlockDesignerItemViewModel fullyCreatedConnectorInfo = new BlockDesignerItemViewModel(this.Root, child);
|
2023-08-13 11:36:47 +08:00
|
|
|
|
InsertChild(fullyCreatedConnectorInfo, -1);
|
2023-07-15 10:20:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-06-11 23:58:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region 属性
|
2023-07-15 10:20:50 +08:00
|
|
|
|
public BlockDesignerItemViewModel DataItem
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return Parent as BlockDesignerItemViewModel;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-18 16:21:18 +08:00
|
|
|
|
public bool OnlyOneChild
|
|
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
|
|
|
|
|
} = true;
|
|
|
|
|
|
|
|
|
|
|
|
public List<string> ChildFlag
|
|
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
|
|
|
|
|
} = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-11 23:58:22 +08:00
|
|
|
|
private double _itemWidth = double.NaN;
|
|
|
|
|
|
public double ItemWidth
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _itemWidth;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value <= 0) return;
|
|
|
|
|
|
SetProperty(ref _itemWidth, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private double _itemHeight = double.NaN;
|
|
|
|
|
|
public double ItemHeight
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _itemHeight;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value <= 0) return;
|
|
|
|
|
|
SetProperty(ref _itemHeight, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-15 10:20:50 +08:00
|
|
|
|
[DisplayName("ItemWidth(mm)")]
|
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
|
public double PhysicalItemWidth
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2023-07-15 10:20:50 +08:00
|
|
|
|
return ScreenHelper.WidthToMm(ItemWidth);
|
2023-06-11 23:58:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2023-07-15 10:20:50 +08:00
|
|
|
|
ItemWidth = ScreenHelper.MmToWidth(value);
|
2023-06-11 23:58:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-15 10:20:50 +08:00
|
|
|
|
[DisplayName("ItemHeight(mm)")]
|
|
|
|
|
|
[Browsable(true)]
|
|
|
|
|
|
public double PhysicalItemHeight
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2023-07-15 10:20:50 +08:00
|
|
|
|
return ScreenHelper.WidthToMm(ItemHeight);
|
2023-06-11 23:58:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2023-07-15 10:20:50 +08:00
|
|
|
|
ItemHeight = ScreenHelper.MmToWidth(value);
|
2023-06-11 23:58:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-15 10:20:50 +08:00
|
|
|
|
private double _actualItemWidth;
|
|
|
|
|
|
public double ActualItemWidth
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
2023-07-15 10:20:50 +08:00
|
|
|
|
get
|
2023-06-27 19:58:08 +08:00
|
|
|
|
{
|
2023-07-15 10:20:50 +08:00
|
|
|
|
return _actualItemWidth;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _actualItemWidth, value);
|
2023-06-27 19:58:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-15 10:20:50 +08:00
|
|
|
|
private double _actualItemHeight;
|
|
|
|
|
|
public double ActualItemHeight
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2023-07-15 10:20:50 +08:00
|
|
|
|
return _actualItemHeight;
|
2023-06-11 23:58:22 +08:00
|
|
|
|
}
|
2023-07-15 10:20:50 +08:00
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _actualItemHeight, value);
|
|
|
|
|
|
}
|
2023-07-22 19:11:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-26 21:30:31 +08:00
|
|
|
|
private ConstParameter _parameter;
|
|
|
|
|
|
public ConstParameter Parameter
|
2023-07-22 19:11:08 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _parameter;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _parameter, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-06-11 23:58:22 +08:00
|
|
|
|
|
2023-06-17 23:55:54 +08:00
|
|
|
|
private ObservableCollection<BlockDesignerItemViewModel> _children = new ObservableCollection<BlockDesignerItemViewModel>();
|
2023-06-11 23:58:22 +08:00
|
|
|
|
public ObservableCollection<BlockDesignerItemViewModel> Children
|
|
|
|
|
|
{
|
2023-06-17 23:55:54 +08:00
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _children;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _children, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-06-11 23:58:22 +08:00
|
|
|
|
|
2023-06-18 16:21:18 +08:00
|
|
|
|
public int ContainerLevel
|
2023-06-14 19:41:29 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2023-06-17 23:55:54 +08:00
|
|
|
|
if (DataItem.ParentContainer == null)
|
2023-06-14 19:41:29 +08:00
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2023-06-18 16:21:18 +08:00
|
|
|
|
return DataItem.ParentContainer.ContainerLevel + 1;
|
2023-06-14 19:41:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-06-11 23:58:22 +08:00
|
|
|
|
|
|
|
|
|
|
private Func<Point> _getOffSetFunc;
|
|
|
|
|
|
public Func<Point> GetOffSetFunc
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _getOffSetFunc;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _getOffSetFunc, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool _beAttachTo;
|
|
|
|
|
|
public bool BeAttachTo
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _beAttachTo;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _beAttachTo, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool _disableAttachTo;
|
|
|
|
|
|
public bool DisableAttachTo
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _disableAttachTo;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _disableAttachTo, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-17 23:55:54 +08:00
|
|
|
|
public virtual bool CanAttachTo(BlockDesignerItemViewModel item)
|
2023-06-18 16:21:18 +08:00
|
|
|
|
=> item != null && item != this.DataItem && !item.IsReadOnly && (this.ChildFlag == null || this.ChildFlag.Count == 0 || this.ChildFlag.Contains(item.Flag));
|
2023-06-11 23:58:22 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2023-07-15 10:20:50 +08:00
|
|
|
|
|
2023-06-11 23:58:22 +08:00
|
|
|
|
public double GetItemWidth()
|
|
|
|
|
|
{
|
|
|
|
|
|
return double.IsNaN(ItemWidth) ? ActualItemWidth : ItemWidth;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public double GetItemHeight()
|
|
|
|
|
|
{
|
|
|
|
|
|
return double.IsNaN(ItemHeight) ? ActualItemHeight : ItemHeight;
|
|
|
|
|
|
}
|
2023-06-14 19:41:29 +08:00
|
|
|
|
|
2023-06-27 22:57:08 +08:00
|
|
|
|
public void InsertChild(BlockDesignerItemViewModel child, int index)
|
2023-06-14 19:41:29 +08:00
|
|
|
|
{
|
2023-06-17 23:55:54 +08:00
|
|
|
|
child.ParentContainer = this;
|
2023-08-13 11:36:47 +08:00
|
|
|
|
if (index == -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
Children.Add(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Children.Insert(index, child);
|
|
|
|
|
|
}
|
2023-06-14 19:41:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RemoveChild(BlockDesignerItemViewModel child)
|
|
|
|
|
|
{
|
2023-06-17 23:55:54 +08:00
|
|
|
|
child.ParentContainer = null;
|
2023-06-14 19:41:29 +08:00
|
|
|
|
Children.Remove(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-18 18:43:48 +08:00
|
|
|
|
public List<BlockItemsContainerInfo> GetAllContainers(ObservableCollection<BlockDesignerItemViewModel> children, bool self)
|
2023-06-14 19:41:29 +08:00
|
|
|
|
{
|
2023-06-18 16:21:18 +08:00
|
|
|
|
List<BlockItemsContainerInfo> itemsContainers = new List<BlockItemsContainerInfo>();
|
2023-06-15 22:44:12 +08:00
|
|
|
|
if (self)
|
|
|
|
|
|
{
|
|
|
|
|
|
itemsContainers.Add(this);
|
|
|
|
|
|
}
|
2023-06-14 19:41:29 +08:00
|
|
|
|
if (children != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in children)
|
|
|
|
|
|
{
|
2023-06-17 23:55:54 +08:00
|
|
|
|
if (item.Containers != null)
|
2023-06-14 19:41:29 +08:00
|
|
|
|
{
|
2023-06-17 23:55:54 +08:00
|
|
|
|
foreach (var container in item.Containers)
|
2023-06-14 19:41:29 +08:00
|
|
|
|
{
|
2023-06-17 23:55:54 +08:00
|
|
|
|
itemsContainers.Add(container);
|
2023-06-18 18:43:48 +08:00
|
|
|
|
itemsContainers.AddRange(container.GetAllContainers(container.Children, false));
|
2023-06-14 19:41:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return itemsContainers;
|
|
|
|
|
|
}
|
2023-07-15 10:20:50 +08:00
|
|
|
|
|
|
|
|
|
|
public RectangleBase GetBounds()
|
|
|
|
|
|
{
|
|
|
|
|
|
var offset = GetOffSetFunc?.Invoke() ?? new Point(0, 0);
|
|
|
|
|
|
|
|
|
|
|
|
var containBound = new RectangleBase(DataItem.Left + offset.X, DataItem.Top + offset.Y, GetItemWidth(), GetItemHeight());
|
|
|
|
|
|
double height = 0;
|
|
|
|
|
|
foreach (var child in Children)
|
|
|
|
|
|
{
|
|
|
|
|
|
child.Left = DataItem.Left + offset.X;
|
|
|
|
|
|
child.Top = DataItem.Top + offset.Y + height;
|
|
|
|
|
|
height += child.GetItemHeight();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return containBound;
|
|
|
|
|
|
}
|
2023-07-20 19:12:43 +08:00
|
|
|
|
|
|
|
|
|
|
public object GetResult()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (OnlyOneChild)
|
|
|
|
|
|
{
|
2023-07-22 19:11:08 +08:00
|
|
|
|
if (Children?.Count == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Children.FirstOrDefault()?.GetResult();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return Parameter?.Value;
|
|
|
|
|
|
}
|
2023-07-20 19:12:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-08-27 23:03:07 +08:00
|
|
|
|
|
|
|
|
|
|
public override void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Dispose();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var child in Children)
|
|
|
|
|
|
{
|
|
|
|
|
|
child.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-06-11 23:58:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|