mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-03 23:56:37 +08:00
支持多个node保存到工具栏,显示还有点问题。
This commit is contained in:
@@ -5,6 +5,10 @@ using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Helpers;
|
||||
using System.Windows;
|
||||
using System.Collections.Generic;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramApp.Models
|
||||
{
|
||||
@@ -47,12 +51,73 @@ namespace AIStudio.Wpf.DiagramApp.Models
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public DesignerItemViewModelBase DesignerItemViewModel { get; set; }
|
||||
public DesignerItemToolBoxData(DesignerItemBase designerItemBase, string filename, Type type, double width = 32, double height = 32, Size? desiredSize = null, string description = null) : base(null, null, type, width, height, desiredSize, description)
|
||||
public DesignerItemToolBoxData(DesignerItemBase designerItemBase, string filename, Type type, double width = 32, double height = 32, Size? desiredSize = null, string description = null) : base(null, null, type, width, height, desiredSize, description)
|
||||
{
|
||||
Addition = designerItemBase;
|
||||
DesignerItemViewModel = Activator.CreateInstance(type, null, designerItemBase) as DesignerItemViewModelBase;
|
||||
FileName = filename;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class MultipleDesignerItemToolBoxData : ToolBoxData
|
||||
{
|
||||
public string FileName
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public List<SelectableDesignerItemViewModelBase> SelectableDesignerItemViewModel
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public MultipleDesignerItemToolBoxData(DiagramItem designerItemBase, string filename, double width = 32, double height = 32, Size? desiredSize = null, string description = null) : base(null, null, typeof(List<SelectableDesignerItemViewModelBase>), width, height, desiredSize, description)
|
||||
{
|
||||
List<DesignerItemViewModelBase> items = new List<DesignerItemViewModelBase>();
|
||||
foreach (var diagramItemData in designerItemBase.DesignerItems)
|
||||
{
|
||||
Type itemtype = TypeHelper.GetType(diagramItemData.ModelTypeName);
|
||||
DesignerItemViewModelBase itemBase = Activator.CreateInstance(itemtype, null, diagramItemData, ".json") as DesignerItemViewModelBase;
|
||||
items.Add(itemBase);
|
||||
}
|
||||
List<ConnectionViewModel> connects = new List<ConnectionViewModel>();
|
||||
foreach (var connection in designerItemBase.Connections)
|
||||
{
|
||||
Type itemtype = TypeHelper.GetType(connection.SerializableTypeName);
|
||||
var connectionItem = SerializeHelper.DeserializeObject(itemtype, connection.SerializableString, ".json") as ConnectionItem;
|
||||
|
||||
connectionItem.SourceType = System.Type.GetType(connectionItem.SourceTypeName);
|
||||
connectionItem.SinkType = System.Type.GetType(connectionItem.SinkTypeName);
|
||||
DesignerItemViewModelBase sourceItem = DiagramViewModelHelper.GetConnectorDataItem(items, connectionItem.SourceId, connectionItem.SourceType);
|
||||
if (sourceItem == null)
|
||||
continue;
|
||||
ConnectorOrientation sourceConnectorOrientation = connectionItem.SourceOrientation;
|
||||
FullyCreatedConnectorInfo sourceConnectorInfo = sourceItem.GetFullConnectorInfo(connectionItem.Id, sourceConnectorOrientation, connectionItem.SourceXRatio, connectionItem.SourceYRatio, connectionItem.SourceInnerPoint, connectionItem.SourceInnerPoint);
|
||||
|
||||
DesignerItemViewModelBase sinkItem = DiagramViewModelHelper.GetConnectorDataItem(items, connectionItem.SinkId, connectionItem.SinkType);
|
||||
if (sinkItem == null)
|
||||
continue;
|
||||
ConnectorOrientation sinkConnectorOrientation = connectionItem.SinkOrientation;
|
||||
FullyCreatedConnectorInfo sinkConnectorInfo = sinkItem.GetFullConnectorInfo(connectionItem.Id, sinkConnectorOrientation, connectionItem.SinkXRatio, connectionItem.SinkYRatio, connectionItem.SinkInnerPoint, connectionItem.SinkInnerPoint);
|
||||
|
||||
ConnectionViewModel connectionVM = new ConnectionViewModel(null, sourceConnectorInfo, sinkConnectorInfo, connectionItem);
|
||||
connects.Add(connectionVM);
|
||||
}
|
||||
|
||||
var minleft = items.OfType<DesignerItemViewModelBase>().Min(p => p.Left);
|
||||
var mintop = items.OfType<DesignerItemViewModelBase>().Min(p => p.Top);
|
||||
foreach (var item in items)
|
||||
{
|
||||
item.Left -= minleft;
|
||||
item.Top -= mintop;
|
||||
}
|
||||
|
||||
SelectableDesignerItemViewModel = new List<SelectableDesignerItemViewModelBase>();
|
||||
SelectableDesignerItemViewModel.AddRange(items);
|
||||
SelectableDesignerItemViewModel.AddRange(connects);
|
||||
|
||||
Addition = SelectableDesignerItemViewModel;
|
||||
FileName = filename;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,4 +136,6 @@ namespace AIStudio.Wpf.DiagramApp.Models
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user