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,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
@@ -24,20 +25,20 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
this.ChildFlag = childFlag;
|
||||
}
|
||||
|
||||
public BlockItemsContainerInfo(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
public BlockItemsContainerInfo(IDiagramViewModel root, BlockDesignerItemViewModel dataItem, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
|
||||
this.Parent = dataItem;
|
||||
}
|
||||
|
||||
public BlockItemsContainerInfo(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
public BlockItemsContainerInfo(IDiagramViewModel root, BlockDesignerItemViewModel dataItem, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
|
||||
this.Parent = dataItem;
|
||||
}
|
||||
|
||||
//public override SelectableItemBase GetSerializableObject()
|
||||
//{
|
||||
// return new ConnectorInfoItemBase(this);
|
||||
//}
|
||||
public override SelectableItemBase GetSerializableObject()
|
||||
{
|
||||
return new BlockItemsContainerInfoItem(this);
|
||||
}
|
||||
|
||||
protected override void Init(IDiagramViewModel root, bool initNew)
|
||||
{
|
||||
@@ -58,15 +59,32 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
base.LoadDesignerItemViewModel(designerbase);
|
||||
|
||||
//if (designerbase is ConnectorInfoItemBase designer)
|
||||
//{
|
||||
// PhysicalConnectorWidth = designer.PhysicalConnectorWidth;
|
||||
// PhysicalConnectorHeight = designer.PhysicalConnectorHeight;
|
||||
// Orientation = designer.Orientation;
|
||||
//}
|
||||
if (designerbase is BlockItemsContainerInfoItem designer)
|
||||
{
|
||||
this.OnlyOneChild = designer.OnlyOneChild;
|
||||
this.ChildFlag = designer.ChildFlag;
|
||||
this.PhysicalItemWidth = designer.PhysicalItemWidth;
|
||||
this.PhysicalItemHeight = designer.PhysicalItemHeight;
|
||||
if (designer.Children != null)
|
||||
{
|
||||
foreach (var child in designer.Children)
|
||||
{
|
||||
BlockDesignerItemViewModel fullyCreatedConnectorInfo = new BlockDesignerItemViewModel(this.Root, child);
|
||||
InsertChild(fullyCreatedConnectorInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region 属性
|
||||
public BlockDesignerItemViewModel DataItem
|
||||
{
|
||||
get
|
||||
{
|
||||
return Parent as BlockDesignerItemViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public bool OnlyOneChild
|
||||
{
|
||||
get; set;
|
||||
@@ -106,6 +124,34 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("ItemWidth(mm)")]
|
||||
[Browsable(true)]
|
||||
public double PhysicalItemWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
return ScreenHelper.WidthToMm(ItemWidth);
|
||||
}
|
||||
set
|
||||
{
|
||||
ItemWidth = ScreenHelper.MmToWidth(value);
|
||||
}
|
||||
}
|
||||
|
||||
[DisplayName("ItemHeight(mm)")]
|
||||
[Browsable(true)]
|
||||
public double PhysicalItemHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return ScreenHelper.WidthToMm(ItemHeight);
|
||||
}
|
||||
set
|
||||
{
|
||||
ItemHeight = ScreenHelper.MmToWidth(value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _actualItemWidth;
|
||||
public double ActualItemWidth
|
||||
{
|
||||
@@ -130,33 +176,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
SetProperty(ref _actualItemHeight, value);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public BlockDesignerItemViewModel DataItem
|
||||
{
|
||||
get
|
||||
{
|
||||
return Parent as BlockDesignerItemViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ObservableCollection<BlockDesignerItemViewModel> _children = new ObservableCollection<BlockDesignerItemViewModel>();
|
||||
public ObservableCollection<BlockDesignerItemViewModel> Children
|
||||
@@ -171,14 +191,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public List<BlockItemsContainerInfo> ChildrenContainer
|
||||
{
|
||||
get
|
||||
{
|
||||
return Children.SelectMany(p => p.Containers)?.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public int ContainerLevel
|
||||
{
|
||||
get
|
||||
@@ -237,6 +249,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
=> item != null && item != this.DataItem && !item.IsReadOnly && (this.ChildFlag == null || this.ChildFlag.Count == 0 || this.ChildFlag.Contains(item.Flag));
|
||||
#endregion
|
||||
|
||||
|
||||
public double GetItemWidth()
|
||||
{
|
||||
return double.IsNaN(ItemWidth) ? ActualItemWidth : ItemWidth;
|
||||
@@ -247,6 +260,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
return double.IsNaN(ItemHeight) ? ActualItemHeight : ItemHeight;
|
||||
}
|
||||
|
||||
public void InsertChild(BlockDesignerItemViewModel child)
|
||||
{
|
||||
child.ParentContainer = this;
|
||||
Children.Add(child);
|
||||
}
|
||||
|
||||
public void InsertChild(BlockDesignerItemViewModel child, int index)
|
||||
{
|
||||
child.ParentContainer = this;
|
||||
@@ -282,5 +301,21 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
return itemsContainers;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
this.ScaleY = designer.ScaleY;
|
||||
this.PhysicalItemWidth = designer.PhysicalItemWidth;
|
||||
this.PhysicalItemHeight = designer.PhysicalItemHeight;
|
||||
this.MinItemWidth = designer.MinItemWidth;
|
||||
this.MinItemHeight = designer.MinItemHeight;
|
||||
this.Icon = designer.Icon;
|
||||
this.CornerRadius = designer.CornerRadius;
|
||||
this.BorderThickness = designer.BorderThickness;
|
||||
|
||||
Reference in New Issue
Block a user