2021-07-29 13:55:18 +08:00
|
|
|
|
using AIStudio.Wpf.Flowchart;
|
2021-07-30 18:26:35 +08:00
|
|
|
|
using AIStudio.Wpf.SFC;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Windows.Media;
|
2022-10-28 22:45:39 +08:00
|
|
|
|
using AIStudio.Wpf.DiagramDesigner;
|
|
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Helpers;
|
2023-01-25 23:55:30 +08:00
|
|
|
|
using System.Windows;
|
2023-02-03 18:23:53 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Models;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2022-10-28 22:45:39 +08:00
|
|
|
|
namespace AIStudio.Wpf.DiagramApp.Models
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
public class PathToolBoxData : ToolBoxData
|
|
|
|
|
|
{
|
2023-01-25 23:55:30 +08:00
|
|
|
|
public PathToolBoxData(string icon, Type type, double width = 32, double height = 32, Size? desiredSize = null, string description = null) : base(null, icon, type, width, height, desiredSize, description)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
ColorViewModel.FillColor.Color = Colors.Orange;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class TextToolBoxData : ToolBoxData
|
|
|
|
|
|
{
|
2023-01-25 23:55:30 +08:00
|
|
|
|
public TextToolBoxData(string text, Type type, double width = 32, double height = 32, Size? desiredSize = null, string description = null) : base(text, null, type, width, height, desiredSize, description)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
ColorViewModel.FillColor.Color = Colors.Orange;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class EllipseTextToolBoxData : ToolBoxData
|
|
|
|
|
|
{
|
2023-01-25 23:55:30 +08:00
|
|
|
|
public EllipseTextToolBoxData(string text, Type type, double width = 32, double height = 32, Size? desiredSize = null, string description = null) : base(text, null, type, width, height, desiredSize, description)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
ColorViewModel.FillColor.Color = Colors.Orange;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class ImageToolBoxData : ToolBoxData
|
|
|
|
|
|
{
|
2023-01-25 23:55:30 +08:00
|
|
|
|
public ImageToolBoxData(string icon, Type type, double width = 32, double height = 32, Size? desiredSize = null, string description = null) : base(null, icon, type, width, height, desiredSize, description)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class DesignerItemToolBoxData : ToolBoxData
|
|
|
|
|
|
{
|
|
|
|
|
|
public string FileName { get; set; }
|
|
|
|
|
|
public DesignerItemViewModelBase DesignerItemViewModel { get; set; }
|
2023-02-03 18:23:53 +08:00
|
|
|
|
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)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
Addition = designerItemBase;
|
2023-01-24 23:10:57 +08:00
|
|
|
|
DesignerItemViewModel = Activator.CreateInstance(type, null, designerItemBase) as DesignerItemViewModelBase;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
FileName = filename;
|
2023-02-03 18:23:53 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class SvgToolBoxData : ToolBoxData
|
|
|
|
|
|
{
|
2023-01-25 23:55:30 +08:00
|
|
|
|
public SvgToolBoxData(string filename, Type type, double width = 32, double height = 32, Size? desiredSize = null, string description = null) : base(null, filename, type, width, height, desiredSize, description)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
ColorViewModel.FillColor.Color = Colors.Blue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class MediaToolBoxData : ToolBoxData
|
|
|
|
|
|
{
|
2023-01-25 23:55:30 +08:00
|
|
|
|
public MediaToolBoxData(string icon, Type type, double width = 32, double height = 32, Size? desiredSize = null, string description = null) : base(icon, null, type, width, height, desiredSize, description)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-02-03 18:23:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|