mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-05-01 21:41:28 +08:00
block的序列化与反序列化
This commit is contained in:
@@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
|
namespace AIStudio.Wpf.DiagramDesigner
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
[XmlInclude(typeof(BlockDesignerItem))]
|
||||||
|
public class BlockDesignerItem : DesignerItemBase
|
||||||
|
{
|
||||||
|
public BlockDesignerItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockDesignerItem(BlockDesignerItemViewModel viewmodel) : base(viewmodel)
|
||||||
|
{
|
||||||
|
Containers = new List<BlockItemsContainerInfoItem>(viewmodel.Containers.Select(p => new BlockItemsContainerInfoItem(p)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[XmlArray]
|
||||||
|
public List<BlockItemsContainerInfoItem> Containers
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace AIStudio.Wpf.DiagramDesigner
|
||||||
|
{
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
[XmlInclude(typeof(BlockItemsContainerInfoItem))]
|
||||||
|
public class BlockItemsContainerInfoItem : SelectableItemBase
|
||||||
|
{
|
||||||
|
public BlockItemsContainerInfoItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockItemsContainerInfoItem(BlockItemsContainerInfo viewmodel) : base(viewmodel)
|
||||||
|
{
|
||||||
|
this.OnlyOneChild = viewmodel.OnlyOneChild;
|
||||||
|
this.ChildFlag = viewmodel.ChildFlag;
|
||||||
|
this.PhysicalItemWidth = viewmodel.PhysicalItemWidth;
|
||||||
|
this.PhysicalItemHeight = viewmodel.PhysicalItemHeight;
|
||||||
|
|
||||||
|
Children = new List<BlockDesignerItem>(viewmodel.Children.Select(p => new BlockDesignerItem(p)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OnlyOneChild
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<string> ChildFlag
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "ItemWidth")]
|
||||||
|
[XmlAttribute("ItemWidth")]
|
||||||
|
public double PhysicalItemWidth
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonProperty(PropertyName = "ItemHeight")]
|
||||||
|
[XmlAttribute("ItemHeight")]
|
||||||
|
public double PhysicalItemHeight
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
[XmlArray]
|
||||||
|
public List<BlockDesignerItem> Children
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
this.ScaleY = viewmodel.ScaleY;
|
this.ScaleY = viewmodel.ScaleY;
|
||||||
this.PhysicalItemWidth = viewmodel.PhysicalItemWidth;
|
this.PhysicalItemWidth = viewmodel.PhysicalItemWidth;
|
||||||
this.PhysicalItemHeight = viewmodel.PhysicalItemHeight;
|
this.PhysicalItemHeight = viewmodel.PhysicalItemHeight;
|
||||||
|
this.MinItemWidth = viewmodel.MinItemWidth;
|
||||||
|
this.MinItemHeight = viewmodel.MinItemHeight;
|
||||||
this.Icon = viewmodel.Icon;
|
this.Icon = viewmodel.Icon;
|
||||||
this.ItemTypeName = viewmodel.GetType().FullName;
|
this.ItemTypeName = viewmodel.GetType().FullName;
|
||||||
this.Margin = viewmodel.Margin;
|
this.Margin = viewmodel.Margin;
|
||||||
@@ -89,6 +91,19 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[XmlAttribute]
|
||||||
|
public double MinItemWidth
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[XmlAttribute]
|
||||||
|
public double MinItemHeight
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
|
|
||||||
[XmlAttribute]
|
[XmlAttribute]
|
||||||
public string Icon
|
public string Icon
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@@ -24,20 +25,20 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
this.ChildFlag = childFlag;
|
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()
|
public override SelectableItemBase GetSerializableObject()
|
||||||
//{
|
{
|
||||||
// return new ConnectorInfoItemBase(this);
|
return new BlockItemsContainerInfoItem(this);
|
||||||
//}
|
}
|
||||||
|
|
||||||
protected override void Init(IDiagramViewModel root, bool initNew)
|
protected override void Init(IDiagramViewModel root, bool initNew)
|
||||||
{
|
{
|
||||||
@@ -58,15 +59,32 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
{
|
{
|
||||||
base.LoadDesignerItemViewModel(designerbase);
|
base.LoadDesignerItemViewModel(designerbase);
|
||||||
|
|
||||||
//if (designerbase is ConnectorInfoItemBase designer)
|
if (designerbase is BlockItemsContainerInfoItem designer)
|
||||||
//{
|
{
|
||||||
// PhysicalConnectorWidth = designer.PhysicalConnectorWidth;
|
this.OnlyOneChild = designer.OnlyOneChild;
|
||||||
// PhysicalConnectorHeight = designer.PhysicalConnectorHeight;
|
this.ChildFlag = designer.ChildFlag;
|
||||||
// Orientation = designer.Orientation;
|
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 属性
|
#region 属性
|
||||||
|
public BlockDesignerItemViewModel DataItem
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Parent as BlockDesignerItemViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool OnlyOneChild
|
public bool OnlyOneChild
|
||||||
{
|
{
|
||||||
get; set;
|
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;
|
private double _actualItemWidth;
|
||||||
public double ActualItemWidth
|
public double ActualItemWidth
|
||||||
{
|
{
|
||||||
@@ -132,32 +178,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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>();
|
private ObservableCollection<BlockDesignerItemViewModel> _children = new ObservableCollection<BlockDesignerItemViewModel>();
|
||||||
public ObservableCollection<BlockDesignerItemViewModel> Children
|
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
|
public int ContainerLevel
|
||||||
{
|
{
|
||||||
get
|
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));
|
=> item != null && item != this.DataItem && !item.IsReadOnly && (this.ChildFlag == null || this.ChildFlag.Count == 0 || this.ChildFlag.Contains(item.Flag));
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
public double GetItemWidth()
|
public double GetItemWidth()
|
||||||
{
|
{
|
||||||
return double.IsNaN(ItemWidth) ? ActualItemWidth : ItemWidth;
|
return double.IsNaN(ItemWidth) ? ActualItemWidth : ItemWidth;
|
||||||
@@ -247,6 +260,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
return double.IsNaN(ItemHeight) ? ActualItemHeight : ItemHeight;
|
return double.IsNaN(ItemHeight) ? ActualItemHeight : ItemHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void InsertChild(BlockDesignerItemViewModel child)
|
||||||
|
{
|
||||||
|
child.ParentContainer = this;
|
||||||
|
Children.Add(child);
|
||||||
|
}
|
||||||
|
|
||||||
public void InsertChild(BlockDesignerItemViewModel child, int index)
|
public void InsertChild(BlockDesignerItemViewModel child, int index)
|
||||||
{
|
{
|
||||||
child.ParentContainer = this;
|
child.ParentContainer = this;
|
||||||
@@ -282,5 +301,21 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
}
|
}
|
||||||
return itemsContainers;
|
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.ScaleY = designer.ScaleY;
|
||||||
this.PhysicalItemWidth = designer.PhysicalItemWidth;
|
this.PhysicalItemWidth = designer.PhysicalItemWidth;
|
||||||
this.PhysicalItemHeight = designer.PhysicalItemHeight;
|
this.PhysicalItemHeight = designer.PhysicalItemHeight;
|
||||||
|
this.MinItemWidth = designer.MinItemWidth;
|
||||||
|
this.MinItemHeight = designer.MinItemHeight;
|
||||||
this.Icon = designer.Icon;
|
this.Icon = designer.Icon;
|
||||||
this.CornerRadius = designer.CornerRadius;
|
this.CornerRadius = designer.CornerRadius;
|
||||||
this.BorderThickness = designer.BorderThickness;
|
this.BorderThickness = designer.BorderThickness;
|
||||||
|
|||||||
@@ -28,15 +28,56 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override SelectableItemBase GetSerializableObject()
|
||||||
|
{
|
||||||
|
return new BlockDesignerItem(this);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void InitNew()
|
protected override void InitNew()
|
||||||
{
|
{
|
||||||
ItemWidth = double.NaN;
|
ItemWidth = double.NaN;
|
||||||
ItemHeight = double.NaN;
|
ItemHeight = double.NaN;
|
||||||
AddConnector(new BlockConnectorInfo(this.Root, this, ConnectorOrientation.Top));
|
AddConnector(new BlockConnectorInfo(this.Root, this, ConnectorOrientation.Top));
|
||||||
AddConnector(new BlockConnectorInfo(this.Root, this, ConnectorOrientation.Bottom));
|
AddConnector(new BlockConnectorInfo(this.Root, this, ConnectorOrientation.Bottom));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Init(IDiagramViewModel root, bool initNew)
|
||||||
|
{
|
||||||
|
base.Init(root, initNew);
|
||||||
|
|
||||||
IsReadOnlyText = true;
|
IsReadOnlyText = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void LoadDesignerItemViewModel(SelectableItemBase designerbase)
|
||||||
|
{
|
||||||
|
base.LoadDesignerItemViewModel(designerbase);
|
||||||
|
|
||||||
|
if (designerbase is BlockDesignerItem designer)
|
||||||
|
{
|
||||||
|
if (designer.Connectors != null)
|
||||||
|
{
|
||||||
|
ClearConnectors();
|
||||||
|
foreach (var connector in designer.Connectors)
|
||||||
|
{
|
||||||
|
BlockConnectorInfo fullyCreatedConnectorInfo = new BlockConnectorInfo(this.Root, this, connector);
|
||||||
|
AddConnector(fullyCreatedConnectorInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (designer.Containers != null)
|
||||||
|
{
|
||||||
|
ClearContainers();
|
||||||
|
foreach (var container in designer.Containers)
|
||||||
|
{
|
||||||
|
BlockItemsContainerInfo blockitemsContainerInfo = new BlockItemsContainerInfo(this.Root, this, container);
|
||||||
|
AddContainer(blockitemsContainerInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void AddNext(BlockDesignerItemViewModel next, bool first = true)
|
public void AddNext(BlockDesignerItemViewModel next, bool first = true)
|
||||||
{
|
{
|
||||||
if (this.Next == next)
|
if (this.Next == next)
|
||||||
|
|||||||
Reference in New Issue
Block a user