mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-11 11:46:37 +08:00
整理一下项目文件
This commit is contained in:
15
AIStudio.Wpf.DiagramApp/Models/ColorType.cs
Normal file
15
AIStudio.Wpf.DiagramApp/Models/ColorType.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramApp.Models
|
||||
{
|
||||
public enum ColorType
|
||||
{
|
||||
Fill,
|
||||
Line,
|
||||
Text,
|
||||
}
|
||||
}
|
||||
57
AIStudio.Wpf.DiagramApp/Models/DiagramDocument.cs
Normal file
57
AIStudio.Wpf.DiagramApp/Models/DiagramDocument.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramApp.Models
|
||||
{
|
||||
[XmlRootAttribute(Namespace = DiagramDocument.XMLNS, IsNullable = false)]
|
||||
public class DiagramDocument
|
||||
{
|
||||
[XmlAttribute]
|
||||
public string Title { get; set; }
|
||||
|
||||
[XmlAttribute]
|
||||
public DiagramType DiagramType { get; set; }
|
||||
|
||||
[XmlArray]
|
||||
public List<DiagramItem> DiagramItems { get; set; }
|
||||
|
||||
public const string XMLNS = "http://AIStudio.Wpf.DiagramApp/DesignLayout";
|
||||
private readonly object saveLock = new Object();
|
||||
|
||||
public void Save(FileInfo designFile)
|
||||
{
|
||||
lock (saveLock)
|
||||
{
|
||||
|
||||
FileStream streamToUse;
|
||||
XmlSerializer serializer = new XmlSerializer(typeof(DiagramDocument));
|
||||
|
||||
if (designFile.Exists)
|
||||
{
|
||||
File.Delete(designFile.FullName);
|
||||
}
|
||||
streamToUse = designFile.Open(FileMode.OpenOrCreate, FileAccess.Write);
|
||||
|
||||
try
|
||||
{
|
||||
XmlWriterSettings settings = new XmlWriterSettings();
|
||||
settings.Indent = true;
|
||||
XmlWriter writer = XmlWriter.Create(streamToUse, settings);
|
||||
serializer.Serialize(writer, this);
|
||||
}
|
||||
finally
|
||||
{
|
||||
streamToUse.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
294
AIStudio.Wpf.DiagramApp/Models/DiagramItem.cs
Normal file
294
AIStudio.Wpf.DiagramApp/Models/DiagramItem.cs
Normal file
@@ -0,0 +1,294 @@
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using AIStudio.Wpf.Flowchart;
|
||||
using AIStudio.Wpf.DiagramHelper.Extensions.ViewModels;
|
||||
using AIStudio.Wpf.DiagramHelper.Extensions.Models;
|
||||
using Newtonsoft.Json;
|
||||
using AIStudio.Wpf.Flowchart.Models;
|
||||
using AIStudio.Wpf.Flowchart.ViewModels;
|
||||
using AIStudio.Wpf.SFC.Models;
|
||||
using AIStudio.Wpf.SFC.ViewModels;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramApp.Models
|
||||
{
|
||||
[Serializable]
|
||||
public class DiagramItem
|
||||
{
|
||||
public DiagramItem()
|
||||
{
|
||||
this.ConnectionIds = new List<Guid>();
|
||||
this.Connections = new List<ConnectionItem>();
|
||||
}
|
||||
|
||||
[XmlAttribute]
|
||||
public string Name { get; set; }
|
||||
|
||||
[XmlAttribute]
|
||||
public DiagramType DiagramType { get; set; }
|
||||
|
||||
[XmlAttribute]
|
||||
public bool ShowGrid { get; set; }
|
||||
|
||||
[XmlIgnore]
|
||||
public Size GridCellSize { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
[XmlAttribute("GridCellSize")]
|
||||
public string XmlGridCellSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return SerializeHelper.SerializeSize(GridCellSize);
|
||||
}
|
||||
set
|
||||
{
|
||||
GridCellSize = SerializeHelper.DeserializeSize(value);
|
||||
}
|
||||
}
|
||||
|
||||
[XmlAttribute]
|
||||
public CellHorizontalAlignment CellHorizontalAlignment { get; set; }
|
||||
|
||||
[XmlAttribute]
|
||||
public CellVerticalAlignment CellVerticalAlignment { get; set; }
|
||||
|
||||
[XmlAttribute]
|
||||
public PageSizeOrientation PageSizeOrientation { get; set; }
|
||||
|
||||
[XmlIgnore]
|
||||
public Size PageSize { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
[XmlAttribute("PageSize")]
|
||||
public string XmlPageSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return SerializeHelper.SerializeSize(PageSize);
|
||||
}
|
||||
set
|
||||
{
|
||||
PageSize = SerializeHelper.DeserializeSize(value);
|
||||
}
|
||||
}
|
||||
|
||||
[XmlAttribute]
|
||||
public PageSizeType PageSizeType { get; set; }
|
||||
|
||||
[XmlAttribute]
|
||||
public double GridMargin { get; set; }
|
||||
|
||||
[XmlIgnore]
|
||||
public Color GridColor { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
[XmlAttribute("GridColor")]
|
||||
public string XmlGridColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return SerializeHelper.SerializeColor(GridColor);
|
||||
}
|
||||
set
|
||||
{
|
||||
GridColor = SerializeHelper.DeserializeColor(value);
|
||||
}
|
||||
}
|
||||
|
||||
[XmlArray]
|
||||
public List<DesignerItemBase> DesignerItems { get; set; } = new List<DesignerItemBase>();
|
||||
|
||||
[XmlArray]
|
||||
public List<PersistDesignerItem> PersistDesignerItems { get; set; } = new List<PersistDesignerItem>();
|
||||
|
||||
[XmlArray]
|
||||
public List<SettingsDesignerItem> SettingsDesignerItems { get; set; } = new List<SettingsDesignerItem>();
|
||||
|
||||
[XmlArray]
|
||||
public List<PathDesignerItem> PathDesignerItems { get; set; } = new List<PathDesignerItem>();
|
||||
|
||||
[XmlArray]
|
||||
public List<MediaDesignerItem> MediaDesignerItems { get; set; } = new List<MediaDesignerItem>();
|
||||
|
||||
[XmlArray]
|
||||
public List<ImageDesignerItem> ImageDesignerItems { get; set; } = new List<ImageDesignerItem>();
|
||||
|
||||
[XmlArray]
|
||||
public List<TextDesignerItem> TextDesignerItems { get; set; } = new List<TextDesignerItem>();
|
||||
|
||||
[XmlArray]
|
||||
public List<LogicalGateDesignerItemBase> LogicalGateItems { get; set; } = new List<LogicalGateDesignerItemBase>();
|
||||
|
||||
[XmlArray]
|
||||
public List<FlowNodeDesignerItem> FlowNodeDesignerItems { get; set; } = new List<FlowNodeDesignerItem>();
|
||||
|
||||
[XmlArray]
|
||||
public List<SFCNodeDesignerItem> SFCNodeDesignerItems { get; set; } = new List<SFCNodeDesignerItem>();
|
||||
|
||||
[JsonIgnore]
|
||||
[XmlIgnore]
|
||||
public List<DesignerItemBase> AllDesignerItems
|
||||
{
|
||||
get
|
||||
{
|
||||
return
|
||||
DesignerItems.OfType<DesignerItemBase>()
|
||||
.Union(TextDesignerItems.OfType<DesignerItemBase>())
|
||||
.Union(LogicalGateItems.OfType<DesignerItemBase>())
|
||||
.Union(MediaDesignerItems.OfType<DesignerItemBase>())
|
||||
.Union(ImageDesignerItems.OfType<DesignerItemBase>())
|
||||
.Union(PathDesignerItems.OfType<DesignerItemBase>())
|
||||
.Union(PersistDesignerItems.OfType<DesignerItemBase>())
|
||||
.Union(SettingsDesignerItems.OfType<DesignerItemBase>())
|
||||
.Union(FlowNodeDesignerItems.OfType<DesignerItemBase>())
|
||||
.Union(SFCNodeDesignerItems.OfType<DesignerItemBase>())
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
[XmlArray]
|
||||
public List<Guid> ConnectionIds { get; set; }
|
||||
|
||||
[XmlArray]
|
||||
public List<ConnectionItem> Connections { get; set; }
|
||||
|
||||
public void AddItems(IEnumerable<SelectableDesignerItemViewModelBase> selectedDesignerItems)
|
||||
{
|
||||
foreach (var item in selectedDesignerItems.OfType<DesignerItemViewModelBase>())
|
||||
{
|
||||
if (item is PersistDesignerItemViewModel)
|
||||
{
|
||||
PersistDesignerItems.Add(new PersistDesignerItem(item as PersistDesignerItemViewModel));
|
||||
}
|
||||
else if (item is SettingsDesignerItemViewModel)
|
||||
{
|
||||
SettingsDesignerItems.Add(new SettingsDesignerItem(item as SettingsDesignerItemViewModel));
|
||||
}
|
||||
else if (item is PathItemViewModel)
|
||||
{
|
||||
PathDesignerItems.Add(new PathDesignerItem(item));
|
||||
}
|
||||
else if (item is GifImageItemViewModel)
|
||||
{
|
||||
MediaDesignerItems.Add(new MediaDesignerItem(item as GifImageItemViewModel));
|
||||
}
|
||||
else if (item is MediaItemViewModel)
|
||||
{
|
||||
MediaDesignerItems.Add(new MediaDesignerItem(item as MediaItemViewModel));
|
||||
}
|
||||
else if (item is ImageItemViewModel)
|
||||
{
|
||||
ImageDesignerItems.Add(new ImageDesignerItem(item as ImageItemViewModel));
|
||||
}
|
||||
else if (item is TextDesignerItemViewModel)
|
||||
{
|
||||
TextDesignerItems.Add(new TextDesignerItem(item as TextDesignerItemViewModel));
|
||||
}
|
||||
else if (item is LogicalGateItemViewModelBase)
|
||||
{
|
||||
LogicalGateItems.Add(new LogicalGateDesignerItemBase(item as LogicalGateItemViewModelBase));
|
||||
}
|
||||
else if (item is FlowNode)
|
||||
{
|
||||
FlowNodeDesignerItems.Add(new FlowNodeDesignerItem(item as FlowNode));
|
||||
}
|
||||
else if (item is SFCNode)
|
||||
{
|
||||
SFCNodeDesignerItems.Add(new SFCNodeDesignerItem(item as SFCNode));
|
||||
}
|
||||
else if (item is BarcodeDesignerItemViewModel)
|
||||
{
|
||||
DesignerItems.Add(new DesignerItemBase(item, (item as BarcodeDesignerItemViewModel).Format.ToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
DesignerItems.Add(new DesignerItemBase(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static DesignerItemBase ToXmlObject(SelectableDesignerItemViewModelBase item)
|
||||
{
|
||||
if (item is PersistDesignerItemViewModel)
|
||||
{
|
||||
return new PersistDesignerItem(item as PersistDesignerItemViewModel);
|
||||
}
|
||||
else if (item is SettingsDesignerItemViewModel)
|
||||
{
|
||||
return new SettingsDesignerItem(item as SettingsDesignerItemViewModel);
|
||||
}
|
||||
else if (item is PathItemViewModel)
|
||||
{
|
||||
return new PathDesignerItem(item as PathItemViewModel);
|
||||
}
|
||||
else if (item is GifImageItemViewModel)
|
||||
{
|
||||
return new MediaDesignerItem(item as GifImageItemViewModel);
|
||||
}
|
||||
else if (item is MediaItemViewModel)
|
||||
{
|
||||
return new MediaDesignerItem(item as MediaItemViewModel);
|
||||
}
|
||||
else if (item is ImageItemViewModel)
|
||||
{
|
||||
return new ImageDesignerItem(item as ImageItemViewModel);
|
||||
}
|
||||
else if (item is TextDesignerItemViewModel)
|
||||
{
|
||||
return new TextDesignerItem(item as TextDesignerItemViewModel);
|
||||
}
|
||||
else if (item is LogicalGateItemViewModelBase)
|
||||
{
|
||||
return new LogicalGateDesignerItemBase(item as LogicalGateItemViewModelBase);
|
||||
}
|
||||
else if (item is FlowNode)
|
||||
{
|
||||
return new FlowNodeDesignerItem(item as FlowNode);
|
||||
}
|
||||
else if (item is SFCNode)
|
||||
{
|
||||
return new SFCNodeDesignerItem(item as SFCNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new DesignerItemBase(item as DesignerItemViewModelBase);
|
||||
}
|
||||
}
|
||||
|
||||
public static Type GetTypeOfDiagramItem(DesignerItemViewModelBase vmType)
|
||||
{
|
||||
if (vmType is PersistDesignerItemViewModel)
|
||||
return typeof(PersistDesignerItem);
|
||||
if (vmType is SettingsDesignerItemViewModel)
|
||||
return typeof(SettingsDesignerItem);
|
||||
if (vmType is PathItemViewModel)
|
||||
return typeof(PathToolBoxData);
|
||||
if (vmType is GifImageItemViewModel)
|
||||
return typeof(MediaDesignerItem);
|
||||
if (vmType is MediaItemViewModel)
|
||||
return typeof(MediaDesignerItem);
|
||||
if (vmType is ImageItemViewModel)
|
||||
return typeof(ImageDesignerItem);
|
||||
if (vmType is LogicalGateItemViewModelBase)
|
||||
return typeof(LogicalGateDesignerItemBase);
|
||||
if (vmType is FlowNode)
|
||||
return typeof(FlowNodeDesignerItem);
|
||||
if (vmType is SFCNode)
|
||||
return typeof(SFCNodeDesignerItem);
|
||||
throw new InvalidOperationException(string.Format("Unknown diagram type. Currently only {0} and {1} are supported",
|
||||
typeof(PersistDesignerItem).AssemblyQualifiedName,
|
||||
typeof(SettingsDesignerItemViewModel).AssemblyQualifiedName
|
||||
));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
96
AIStudio.Wpf.DiagramApp/Models/PathToolBoxData.cs
Normal file
96
AIStudio.Wpf.DiagramApp/Models/PathToolBoxData.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using AIStudio.Wpf.Flowchart;
|
||||
using AIStudio.Wpf.SFC;
|
||||
using System;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
using AIStudio.Wpf.DiagramDesigner.Helpers;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramApp.Models
|
||||
{
|
||||
public class PathToolBoxData : ToolBoxData
|
||||
{
|
||||
public PathToolBoxData(string icon, Type type, double width = 32, double height = 32) : base(null, icon, type, width, height)
|
||||
{
|
||||
ColorViewModel.FillColor.Color = Colors.Orange;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class TextToolBoxData : ToolBoxData
|
||||
{
|
||||
public TextToolBoxData(string text, Type type, double width = 32, double height = 32) : base(text, null, type, width, height)
|
||||
{
|
||||
ColorViewModel.FillColor.Color = Colors.Orange;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class EllipseTextToolBoxData : ToolBoxData
|
||||
{
|
||||
public EllipseTextToolBoxData(string text, Type type, double width = 32, double height = 32) : base(text, null, type, width, height)
|
||||
{
|
||||
ColorViewModel.FillColor.Color = Colors.Orange;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ImageToolBoxData : ToolBoxData
|
||||
{
|
||||
public ImageToolBoxData(string icon, Type type, double width = 32, double height = 32) : base(null, icon, type, width, height)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class FlowchartToolBoxData : ToolBoxData
|
||||
{
|
||||
public NodeKinds Kind { get; set; }
|
||||
public FlowchartToolBoxData(NodeKinds kind, Type type, double width = 32, double height = 32) : base(kind.GetDescription(), null, type, width, height)
|
||||
{
|
||||
Kind = kind;
|
||||
ColorViewModel.LineColor.Color = Colors.Black;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class SFCToolBoxData : ToolBoxData
|
||||
{
|
||||
public SFCNodeKinds Kind { get; set; }
|
||||
public SFCToolBoxData(SFCNodeKinds kind, Type type, double width = 32, double height = 32) : base(null, null, type, width, height)
|
||||
{
|
||||
Kind = kind;
|
||||
ColorViewModel.LineColor.Color = Colors.Gray;
|
||||
ColorViewModel.FillColor.Color = Colors.Blue;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class DesignerItemToolBoxData : ToolBoxData
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public DesignerItemViewModelBase DesignerItemViewModel { get; set; }
|
||||
public DesignerItemToolBoxData(DesignerItemBase designerItemBase, string filename, Type type, double width = 32, double height = 32) : base(null, null, type, width, height)
|
||||
{
|
||||
Addition = designerItemBase;
|
||||
DesignerItemViewModel = (DesignerItemViewModelBase)Activator.CreateInstance(type, null, designerItemBase);
|
||||
FileName = filename;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class SvgToolBoxData : ToolBoxData
|
||||
{
|
||||
public SvgToolBoxData(string filename, Type type, double width = 32, double height = 32) : base(null, filename, type, width, height)
|
||||
{
|
||||
ColorViewModel.FillColor.Color = Colors.Blue;
|
||||
}
|
||||
}
|
||||
|
||||
public class MediaToolBoxData : ToolBoxData
|
||||
{
|
||||
public MediaToolBoxData(string icon, Type type, double width = 32, double height = 32) : base(icon, null, type, width, height)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user