2023-06-11 23:58:22 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
|
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-16 19:03:15 +08:00
|
|
|
|
public class BlockItemsContainerInfo : SelectableViewModelBase
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
2023-06-16 19:03:15 +08:00
|
|
|
|
public BlockItemsContainerInfo(BlockDesignerItemViewModel dataItem) : this(null, dataItem)
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-16 19:03:15 +08:00
|
|
|
|
public BlockItemsContainerInfo(IDiagramViewModel root, BlockDesignerItemViewModel dataItem) : base(root)
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
this.Parent = dataItem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-16 19:03:15 +08:00
|
|
|
|
public BlockItemsContainerInfo(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-16 19:03:15 +08:00
|
|
|
|
public BlockItemsContainerInfo(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
2023-06-11 23:58:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//public override SelectableItemBase GetSerializableObject()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// return new ConnectorInfoItemBase(this);
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Init(IDiagramViewModel root, bool initNew)
|
|
|
|
|
|
{
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
//if (designerbase is ConnectorInfoItemBase designer)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// PhysicalConnectorWidth = designer.PhysicalConnectorWidth;
|
|
|
|
|
|
// PhysicalConnectorHeight = designer.PhysicalConnectorHeight;
|
|
|
|
|
|
// Orientation = designer.Orientation;
|
|
|
|
|
|
//}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region 属性
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private double _actualItemWidth;
|
|
|
|
|
|
public double ActualItemWidth
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _actualItemWidth;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _actualItemWidth, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private double _actualItemHeight;
|
|
|
|
|
|
public double ActualItemHeight
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _actualItemHeight;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _actualItemHeight, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public RectangleBase GetBounds()
|
|
|
|
|
|
{
|
|
|
|
|
|
var offset = GetOffSetFunc?.Invoke() ?? new Point(0, 0);
|
|
|
|
|
|
|
|
|
|
|
|
return new RectangleBase(DataItem.Left + offset.X, DataItem.Top + offset.Y, GetItemWidth(), GetItemHeight());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public BlockDesignerItemViewModel DataItem
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return Parent as BlockDesignerItemViewModel;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<BlockDesignerItemViewModel> Children
|
|
|
|
|
|
{
|
|
|
|
|
|
get; set;
|
|
|
|
|
|
} = new ObservableCollection<BlockDesignerItemViewModel>();
|
|
|
|
|
|
|
2023-06-16 19:03:15 +08:00
|
|
|
|
public List<BlockItemsContainerInfo> ChildrenContain
|
2023-06-14 19:41:29 +08:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return Children?.SelectMany(p => p.Contains)?.ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int ContainLevel
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (DataItem.ParentContain == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return DataItem.ParentContain.ContainLevel + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual bool CanAttachTo(DesignerItemViewModelBase item)
|
|
|
|
|
|
=> item != null && item != this.DataItem && !item.IsReadOnly && item is BlockDesignerItemViewModel;
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
public void AddChild(BlockDesignerItemViewModel child)
|
|
|
|
|
|
{
|
|
|
|
|
|
child.ParentContain = this;
|
|
|
|
|
|
Children.Add(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RemoveChild(BlockDesignerItemViewModel child)
|
|
|
|
|
|
{
|
|
|
|
|
|
child.ParentContain = null;
|
|
|
|
|
|
Children.Remove(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-16 19:03:15 +08:00
|
|
|
|
public List<BlockItemsContainerInfo> GetAllContain(ObservableCollection<BlockDesignerItemViewModel> children, bool self)
|
2023-06-14 19:41:29 +08:00
|
|
|
|
{
|
2023-06-16 19:03:15 +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)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.Contains != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var contain in item.Contains)
|
|
|
|
|
|
{
|
2023-06-15 22:44:12 +08:00
|
|
|
|
itemsContainers.Add(contain);
|
|
|
|
|
|
itemsContainers.AddRange(contain.GetAllContain(contain.Children, false));
|
2023-06-14 19:41:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return itemsContainers;
|
|
|
|
|
|
}
|
2023-06-11 23:58:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|