mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-13 21:16:37 +08:00
组合对象完成
This commit is contained in:
@@ -49,8 +49,14 @@ namespace AIStudio.Wpf.DiagramApp.Models
|
||||
|
||||
public class DesignerItemToolBoxData : ToolBoxData
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public DesignerItemViewModelBase DesignerItemViewModel { get; set; }
|
||||
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)
|
||||
{
|
||||
Addition = designerItemBase;
|
||||
@@ -66,58 +72,40 @@ namespace AIStudio.Wpf.DiagramApp.Models
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public List<SelectableDesignerItemViewModelBase> SelectableDesignerItemViewModel
|
||||
public List<SelectableDesignerItemViewModelBase> SelectableDesignerItemViewModels
|
||||
{
|
||||
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;
|
||||
public double CanvasWidth
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public double CanvasHeight
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public MultipleDesignerItemToolBoxData(SerializableObject 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)
|
||||
{
|
||||
SelectableDesignerItemViewModels = designerItemBase.ToObject();
|
||||
|
||||
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);
|
||||
var minleft = SelectableDesignerItemViewModels.OfType<DesignerItemViewModelBase>().Min(p => p.Left);
|
||||
var mintop = SelectableDesignerItemViewModels.OfType<DesignerItemViewModelBase>().Min(p => p.Top);
|
||||
var maxright = SelectableDesignerItemViewModels.OfType<DesignerItemViewModelBase>().Max(p => p.Left + p.ItemWidth);
|
||||
var maxbottom = SelectableDesignerItemViewModels.OfType<DesignerItemViewModelBase>().Max(p => p.Top + p.ItemHeight);
|
||||
|
||||
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)
|
||||
foreach (var item in SelectableDesignerItemViewModels.OfType<DesignerItemViewModelBase>())
|
||||
{
|
||||
item.Left -= minleft;
|
||||
item.Top -= mintop;
|
||||
}
|
||||
CanvasWidth = maxright - minleft;
|
||||
CanvasHeight = maxbottom - mintop;
|
||||
|
||||
SelectableDesignerItemViewModel = new List<SelectableDesignerItemViewModelBase>();
|
||||
SelectableDesignerItemViewModel.AddRange(items);
|
||||
SelectableDesignerItemViewModel.AddRange(connects);
|
||||
designerItemBase.DesignerItems = SelectableDesignerItemViewModels.OfType<DesignerItemViewModelBase>().Select(p => p.ToSerializableItem(".json")).Where(p => p != null).ToList();
|
||||
designerItemBase.Connections = SelectableDesignerItemViewModels.OfType<ConnectionViewModel>().Select(p => p.ToSerializableItem(".json")).Where(p => p != null).ToList();
|
||||
|
||||
Addition = SelectableDesignerItemViewModel;
|
||||
Addition = designerItemBase;
|
||||
FileName = filename;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,5 +125,5 @@ namespace AIStudio.Wpf.DiagramApp.Models
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ using AIStudio.Wpf.SFC.ViewModels;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
using AIStudio.Wpf.DiagramDesigner.Helpers;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramApp.Models
|
||||
{
|
||||
@@ -123,5 +124,7 @@ namespace AIStudio.Wpf.DiagramApp.Models
|
||||
|
||||
[XmlArray]
|
||||
public List<SerializableItem> Connections { get; set; } = new List<SerializableItem>();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ using AIStudio.Wpf.Flowchart.Models;
|
||||
using AIStudio.Wpf.SFC.Models;
|
||||
using System.Windows;
|
||||
using System;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
{
|
||||
@@ -272,7 +273,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
|
||||
if (xmlobject.DiagramItems[0].DesignerItems.Count > 1)
|
||||
{
|
||||
var itemBase = new MultipleDesignerItemToolBoxData(xmlobject.DiagramItems[0], filename);
|
||||
var itemBase = new MultipleDesignerItemToolBoxData(new SerializableObject() { DesignerItems = xmlobject.DiagramItems[0].DesignerItems, Connections = xmlobject.DiagramItems[0].Connections }, filename);
|
||||
|
||||
return itemBase;
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
<DataTemplate DataType="{x:Type model:MultipleDesignerItemToolBoxData}">
|
||||
<Grid Width="{Binding Width}" Height="{Binding Height}" ToolTip="{Binding Description}">
|
||||
<Grid ToolTip="{Binding Description}">
|
||||
<Grid.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="删除" Command="{StaticResource DeleteItemCommandReference}" CommandParameter="{Binding .}"/>
|
||||
@@ -173,8 +173,10 @@
|
||||
StrokeDashArray="2"
|
||||
Fill="Transparent"
|
||||
SnapsToDevicePixels="true"/>
|
||||
<Viewbox Stretch="Uniform">
|
||||
<ItemsControl ItemsSource="{Binding SelectableDesignerItemViewModel}">
|
||||
<Viewbox Stretch="Uniform" Width="{Binding Width}" Height="{Binding Height}">
|
||||
<ItemsControl ItemsSource="{Binding SelectableDesignerItemViewModels}"
|
||||
Width="{Binding CanvasWidth}"
|
||||
Height="{Binding CanvasHeight}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas x:Name="rootCanvas"/>
|
||||
|
||||
@@ -12,6 +12,8 @@ using System.Linq;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Resources;
|
||||
using System.Runtime.InteropServices;
|
||||
using Newtonsoft.Json;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
@@ -567,8 +569,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
_viewModel.ClearSelectedItemsCommand.Execute(null);
|
||||
Point position = e.GetPosition(this);
|
||||
if (dragObject.DesignerItem is List<SelectableDesignerItemViewModelBase> designerItems)
|
||||
if (dragObject.DesignerItem is SerializableObject serializableObject)
|
||||
{
|
||||
var designerItems = serializableObject.ToObject();
|
||||
foreach (var item in designerItems.OfType<DesignerItemViewModelBase>())
|
||||
{
|
||||
item.Left += position.X;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using AIStudio.Wpf.DiagramDesigner.Helpers;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.Models
|
||||
{
|
||||
@@ -49,5 +50,45 @@ namespace AIStudio.Wpf.DiagramDesigner.Models
|
||||
|
||||
[XmlArray]
|
||||
public List<SerializableItem> Connections { get; set; } = new List<SerializableItem>();
|
||||
|
||||
public List<SelectableDesignerItemViewModelBase> ToObject()
|
||||
{
|
||||
List<DesignerItemViewModelBase> items = new List<DesignerItemViewModelBase>();
|
||||
foreach (var diagramItemData in this.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 this.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 viewmodels = new List<SelectableDesignerItemViewModelBase>();
|
||||
viewmodels.AddRange(items);
|
||||
viewmodels.AddRange(connects);
|
||||
|
||||
return viewmodels;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,5 +159,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
ShowText = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user