2023-01-25 15:58:05 +08:00
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Additionals.Commands;
|
2021-07-29 13:55:18 +08:00
|
|
|
|
using AIStudio.Wpf.Flowchart;
|
2023-01-25 15:58:05 +08:00
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Additionals.Extensions.ViewModels;
|
|
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Additionals;
|
2022-10-28 22:45:39 +08:00
|
|
|
|
using AIStudio.Wpf.DiagramApp.Models;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using System.Xml.Serialization;
|
2022-10-28 22:45:39 +08:00
|
|
|
|
using AIStudio.Wpf.DiagramDesigner;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
using ZXing;
|
2022-12-08 20:54:45 +08:00
|
|
|
|
using AIStudio.Wpf.DiagramDesigner.Helpers;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2022-10-28 22:45:39 +08:00
|
|
|
|
namespace AIStudio.Wpf.DiagramApp.ViewModels
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
2023-02-12 21:30:16 +08:00
|
|
|
|
public partial class PageViewModel : BindableBase
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
2021-08-05 18:20:22 +08:00
|
|
|
|
protected IDiagramServiceProvider _service { get { return DiagramServicesProvider.Instance.Provider; } }
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-02-12 21:30:16 +08:00
|
|
|
|
public PageViewModel(string title, string status, DiagramType diagramType)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
Title = title;
|
|
|
|
|
|
Status = status;
|
|
|
|
|
|
DiagramType = diagramType;
|
|
|
|
|
|
|
|
|
|
|
|
Init();
|
|
|
|
|
|
}
|
2023-02-12 21:30:16 +08:00
|
|
|
|
public PageViewModel(string filename)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
FileName = filename;
|
2023-01-25 11:11:27 +08:00
|
|
|
|
string ext = Path.GetExtension(filename);
|
|
|
|
|
|
var diagramDocument = OpenFile(filename, ext);
|
|
|
|
|
|
OpenFile(diagramDocument, ext);
|
2021-08-03 18:19:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-12 21:30:16 +08:00
|
|
|
|
public PageViewModel(string filename, DiagramDocument diagramDocument)
|
2021-08-03 18:19:47 +08:00
|
|
|
|
{
|
|
|
|
|
|
FileName = filename;
|
2023-01-25 11:11:27 +08:00
|
|
|
|
string ext = Path.GetExtension(filename);
|
|
|
|
|
|
OpenFile(diagramDocument, ext);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void InitDiagramViewModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void Init()
|
|
|
|
|
|
{
|
2023-03-05 21:30:53 +08:00
|
|
|
|
DiagramViewModels = new ObservableCollection<IDiagramViewModel>()
|
|
|
|
|
|
{
|
2023-03-08 19:45:07 +08:00
|
|
|
|
GetDiagramViewModel("页-1", DiagramType),
|
2023-03-05 21:30:53 +08:00
|
|
|
|
};
|
|
|
|
|
|
DiagramViewModel = DiagramViewModels.FirstOrDefault();
|
|
|
|
|
|
|
2021-07-23 09:42:22 +08:00
|
|
|
|
InitDiagramViewModel();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string FileName { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
#region 属性
|
|
|
|
|
|
|
|
|
|
|
|
private string _title;
|
|
|
|
|
|
public string Title
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _title;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _title, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string _status;
|
|
|
|
|
|
public string Status
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _status;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _status, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool _showGrid;
|
|
|
|
|
|
public bool ShowGrid
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _showGrid;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (SetProperty(ref _showGrid, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in DiagramViewModels)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.ShowGrid = _showGrid;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DiagramType DiagramType { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
private ObservableCollection<IDiagramViewModel> _diagramViewModels;
|
|
|
|
|
|
public ObservableCollection<IDiagramViewModel> DiagramViewModels
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _diagramViewModels;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
SetProperty(ref _diagramViewModels, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private IDiagramViewModel _diagramViewModel;
|
|
|
|
|
|
public IDiagramViewModel DiagramViewModel
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return _diagramViewModel;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_diagramViewModel != value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_diagramViewModel != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_diagramViewModel.PropertyChanged -= DiagramViewModel_PropertyChanged;
|
|
|
|
|
|
_diagramViewModel.OutAddVerify -= AddVerify;
|
|
|
|
|
|
}
|
|
|
|
|
|
SetProperty(ref _diagramViewModel, value);
|
|
|
|
|
|
if (_diagramViewModel != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_diagramViewModel.PropertyChanged += DiagramViewModel_PropertyChanged;
|
|
|
|
|
|
_diagramViewModel.OutAddVerify += AddVerify;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region
|
|
|
|
|
|
|
|
|
|
|
|
private void DiagramViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.PropertyName == "IsSelected")
|
|
|
|
|
|
{
|
2023-02-03 18:23:53 +08:00
|
|
|
|
_service.SelectedItems = DiagramViewModel?.SelectedItems;
|
|
|
|
|
|
|
2023-03-11 22:27:23 +08:00
|
|
|
|
_service.SelectedItem = DiagramViewModel?.SelectedItem;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var property = sender.GetType().GetProperty(e.PropertyName);
|
|
|
|
|
|
var attr = property.GetCustomAttributes(typeof(BrowsableAttribute), true);
|
|
|
|
|
|
if (attr != null && attr.Length != 0 && (attr[0] as BrowsableAttribute).Browsable == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Status = "*";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2023-01-24 09:02:40 +08:00
|
|
|
|
protected virtual bool AddVerify(SelectableDesignerItemViewModelBase arg)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
public static DiagramDocument OpenFile(string filename, string ext)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
DiagramDocument diagramDocument = null;
|
|
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
if (ext == ".xml")
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
XmlSerializer serializer = new XmlSerializer(typeof(DiagramDocument));
|
|
|
|
|
|
FileInfo fileInfo = new FileInfo(filename);
|
|
|
|
|
|
|
|
|
|
|
|
using (TextReader reader = fileInfo.OpenText())
|
|
|
|
|
|
{
|
|
|
|
|
|
diagramDocument = (DiagramDocument)serializer.Deserialize(reader);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
diagramDocument = JsonConvert.DeserializeObject<DiagramDocument>(File.ReadAllText(filename));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-03 18:19:47 +08:00
|
|
|
|
return diagramDocument;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (System.IO.FileNotFoundException fnfe)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new FileNotFoundException("The system document could not be found ", fnfe);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (System.IO.DirectoryNotFoundException dnfe)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new DirectoryNotFoundException("A required directory was nt found", dnfe);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (System.IO.IOException ioe)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new IOException("A file system error occurred", ioe);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (System.UnauthorizedAccessException uae)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new UnauthorizedAccessException("The requested file system access wasnot granted", uae);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (System.Security.SecurityException se)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new System.Security.SecurityException("The security policy prevents access to a file system resource", se);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (System.Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new System.Exception(
|
|
|
|
|
|
string.Format("The database format vc invalid \r\n Exception:{0} \r\n InnerException:{1}", e.Message, e.InnerException.Message));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
protected virtual void OpenFile(DiagramDocument diagramDocument, string ext)
|
2021-08-03 18:19:47 +08:00
|
|
|
|
{
|
|
|
|
|
|
Title = diagramDocument.Title;
|
|
|
|
|
|
DiagramType = diagramDocument.DiagramType;
|
|
|
|
|
|
|
|
|
|
|
|
List<DiagramViewModel> viewModels = new List<DiagramViewModel>();
|
|
|
|
|
|
foreach (var diagramItem in diagramDocument.DiagramItems)
|
|
|
|
|
|
{
|
2023-03-08 19:45:07 +08:00
|
|
|
|
var viewModel = GetDiagramViewModel(diagramItem.Name, diagramItem.DiagramType);
|
2021-08-03 18:19:47 +08:00
|
|
|
|
viewModel.ShowGrid = diagramItem.ShowGrid;
|
2023-02-11 23:51:48 +08:00
|
|
|
|
viewModel.PhysicalGridCellSize = diagramItem.PhysicalGridCellSize;
|
2021-08-03 18:19:47 +08:00
|
|
|
|
viewModel.CellHorizontalAlignment = diagramItem.CellHorizontalAlignment;
|
|
|
|
|
|
viewModel.CellVerticalAlignment = diagramItem.CellVerticalAlignment;
|
|
|
|
|
|
viewModel.PageSizeOrientation = diagramItem.PageSizeOrientation;
|
2023-02-11 23:51:48 +08:00
|
|
|
|
viewModel.PhysicalPageSize = diagramItem.PhysicalPageSize;
|
2021-08-03 18:19:47 +08:00
|
|
|
|
viewModel.PageSizeType = diagramItem.PageSizeType;
|
2023-02-11 23:51:48 +08:00
|
|
|
|
viewModel.PhysicalGridMarginSize = diagramItem.PhysicalGridMarginSize;
|
2021-08-03 18:19:47 +08:00
|
|
|
|
viewModel.GridColor = diagramItem.GridColor;
|
2023-02-12 21:30:16 +08:00
|
|
|
|
viewModel.AllowDrop = diagramItem.AllowDrop;
|
2021-08-03 18:19:47 +08:00
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
foreach (var diagramItemData in diagramItem.DesignerItems)
|
2021-08-03 18:19:47 +08:00
|
|
|
|
{
|
2023-01-25 11:11:27 +08:00
|
|
|
|
Type type = TypeHelper.GetType(diagramItemData.ModelTypeName);
|
|
|
|
|
|
DesignerItemViewModelBase itemBase = Activator.CreateInstance(type, viewModel, diagramItemData, ext) as DesignerItemViewModelBase;
|
|
|
|
|
|
viewModel.Items.Add(itemBase);
|
2021-08-03 18:19:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var connection in diagramItem.Connections)
|
|
|
|
|
|
{
|
2023-01-25 11:11:27 +08:00
|
|
|
|
Type type = TypeHelper.GetType(connection.SerializableTypeName);
|
|
|
|
|
|
var connectionItem = SerializeHelper.DeserializeObject(type, connection.SerializableString, ext) as ConnectionItem;
|
2021-08-03 18:19:47 +08:00
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
connectionItem.SourceType = System.Type.GetType(connectionItem.SourceTypeName);
|
|
|
|
|
|
connectionItem.SinkType = System.Type.GetType(connectionItem.SinkTypeName);
|
2023-02-03 18:23:53 +08:00
|
|
|
|
DesignerItemViewModelBase sourceItem = DiagramViewModelHelper.GetConnectorDataItem(viewModel.Items, connectionItem.SourceId, connectionItem.SourceType);
|
2023-01-25 11:11:27 +08:00
|
|
|
|
ConnectorOrientation sourceConnectorOrientation = connectionItem.SourceOrientation;
|
2023-02-03 18:23:53 +08:00
|
|
|
|
FullyCreatedConnectorInfo sourceConnectorInfo = sourceItem.GetFullConnectorInfo(connectionItem.Id, sourceConnectorOrientation, connectionItem.SourceXRatio, connectionItem.SourceYRatio, connectionItem.SourceInnerPoint, connectionItem.SourceInnerPoint);
|
2021-08-03 18:19:47 +08:00
|
|
|
|
|
2023-02-03 18:23:53 +08:00
|
|
|
|
DesignerItemViewModelBase sinkItem = DiagramViewModelHelper.GetConnectorDataItem(viewModel.Items, connectionItem.SinkId, connectionItem.SinkType);
|
2023-01-25 11:11:27 +08:00
|
|
|
|
ConnectorOrientation sinkConnectorOrientation = connectionItem.SinkOrientation;
|
2023-02-03 18:23:53 +08:00
|
|
|
|
FullyCreatedConnectorInfo sinkConnectorInfo = sinkItem.GetFullConnectorInfo(connectionItem.Id, sinkConnectorOrientation, connectionItem.SinkXRatio, connectionItem.SinkYRatio, connectionItem.SinkInnerPoint, connectionItem.SinkInnerPoint);
|
2023-01-25 11:11:27 +08:00
|
|
|
|
|
|
|
|
|
|
ConnectionViewModel connectionVM = new ConnectionViewModel(viewModel, sourceConnectorInfo, sinkConnectorInfo, connectionItem);
|
2021-08-03 18:19:47 +08:00
|
|
|
|
viewModel.Items.Add(connectionVM);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
viewModels.Add(viewModel);
|
|
|
|
|
|
}
|
|
|
|
|
|
DiagramViewModels = new ObservableCollection<IDiagramViewModel>(viewModels);
|
|
|
|
|
|
DiagramViewModel = DiagramViewModels.FirstOrDefault();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-23 09:42:22 +08:00
|
|
|
|
public bool SaveFile(bool isSaveAs = false)
|
|
|
|
|
|
{
|
|
|
|
|
|
string filter = "Files (*.xml)|*.xml|Files (*.json)|*.json|All Files (*.*)|*.*";
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(FileName) || isSaveAs == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
Microsoft.Win32.SaveFileDialog saveFile = new Microsoft.Win32.SaveFileDialog();
|
|
|
|
|
|
saveFile.Filter = filter;
|
|
|
|
|
|
if (saveFile.ShowDialog() == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
FileName = saveFile.FileName;
|
|
|
|
|
|
Title = Path.GetFileNameWithoutExtension(FileName);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
var ext = Path.GetExtension(FileName);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
|
|
|
|
|
DiagramDocument diagramDocument = new DiagramDocument();
|
|
|
|
|
|
diagramDocument.DiagramItems = new List<DiagramItem>();
|
|
|
|
|
|
diagramDocument.Title = Title;
|
|
|
|
|
|
diagramDocument.DiagramType = DiagramType;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var viewModel in DiagramViewModels)
|
|
|
|
|
|
{
|
2023-02-11 23:51:48 +08:00
|
|
|
|
DiagramItem diagramItem = new DiagramItem(viewModel);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
var selectedDesignerItems = viewModel.Items.OfType<DesignerItemViewModelBase>();
|
|
|
|
|
|
var selectedConnections = viewModel.Items.OfType<ConnectionViewModel>();
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
diagramItem.DesignerItems = selectedDesignerItems.Select(p => p.ToSerializableItem(ext)).Where(p => p != null).ToList();
|
|
|
|
|
|
diagramItem.Connections = selectedConnections.Select(p => p.ToSerializableItem(ext)).Where(p => p != null).ToList();
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
|
|
|
|
|
diagramDocument.DiagramItems.Add(diagramItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
if (ext == ".xml")
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
FileInfo file = new FileInfo(FileName);
|
|
|
|
|
|
diagramDocument.Save(file);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
File.WriteAllText(FileName, JsonConvert.SerializeObject(diagramDocument));
|
|
|
|
|
|
}
|
|
|
|
|
|
Status = "";
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
2022-12-08 20:54:45 +08:00
|
|
|
|
}
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-24 09:02:40 +08:00
|
|
|
|
private bool ItemsToDeleteHasConnector(List<SelectableDesignerItemViewModelBase> itemsToRemove, ConnectorInfoBase connector)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (connector is FullyCreatedConnectorInfo fully)
|
|
|
|
|
|
{
|
|
|
|
|
|
return itemsToRemove.Contains(fully.DataItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region 主题
|
2023-01-24 09:02:40 +08:00
|
|
|
|
public void SetPropertyValue(SelectableDesignerItemViewModelBase selectable, string propertyName)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in DiagramViewModel.SelectedItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item != selectable)
|
|
|
|
|
|
{
|
|
|
|
|
|
CopyHelper.CopyPropertyValue(selectable, item, propertyName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetFont(IFontViewModel fontViewModel, string propertyName)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in DiagramViewModel.SelectedItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.FontViewModel != fontViewModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
CopyHelper.CopyPropertyValue(fontViewModel, item.FontViewModel, propertyName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetColor(IColorViewModel colorViewModel, string propertyName)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in DiagramViewModel.SelectedItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.ColorViewModel != colorViewModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
CopyHelper.CopyPropertyValue(colorViewModel, item.ColorViewModel, propertyName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-26 18:27:17 +08:00
|
|
|
|
public void SetSharp(IShapeViewModel shapeViewModel, string propertyName)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in DiagramViewModel.SelectedItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.ShapeViewModel != shapeViewModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
CopyHelper.CopyPropertyValue(shapeViewModel, item.ShapeViewModel, propertyName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-23 09:42:22 +08:00
|
|
|
|
public void SetQuickItem(IQuickThemeViewModel quickThemeViewModel, string propertyName)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (propertyName == nameof(QuickTheme) && quickThemeViewModel.QuickTheme != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in DiagramViewModel.SelectedItems)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetFont(quickThemeViewModel.QuickTheme.FontViewModel, "FontColor");
|
|
|
|
|
|
SetColor(quickThemeViewModel.QuickTheme.ColorViewModel, "FillColor");
|
|
|
|
|
|
SetColor(quickThemeViewModel.QuickTheme.ColorViewModel, "LineColor");
|
|
|
|
|
|
SetColor(quickThemeViewModel.QuickTheme.ColorViewModel, "LineWidth");
|
|
|
|
|
|
}
|
|
|
|
|
|
quickThemeViewModel.QuickTheme = null;
|
|
|
|
|
|
}
|
2022-12-08 20:54:45 +08:00
|
|
|
|
}
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
|
|
|
|
|
public void LockAction(LockObject lockObject, string propertyName)
|
|
|
|
|
|
{
|
2023-01-25 11:11:27 +08:00
|
|
|
|
foreach (var item in DiagramViewModel?.SelectedItems)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
item.LockObjectViewModel.SetValue(lockObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void AddPageExecuted(object para)
|
|
|
|
|
|
{
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
if (para is DiagramViewModel oldpage)
|
|
|
|
|
|
{
|
|
|
|
|
|
index = DiagramViewModels.IndexOf(oldpage) + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
index = DiagramViewModels.Count;
|
|
|
|
|
|
}
|
2023-03-08 19:45:07 +08:00
|
|
|
|
var page = GetDiagramViewModel(null, DiagramType);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
DiagramViewModels.Insert(index, page);
|
|
|
|
|
|
DiagramViewModel = page;
|
|
|
|
|
|
InitDiagramViewModel();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-08 19:45:07 +08:00
|
|
|
|
protected virtual DiagramViewModel GetDiagramViewModel(string name, DiagramType diagramType)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new DiagramViewModel() { Name = name??NewNameHelper.GetNewName(DiagramViewModels.Select(p => p.Name), "页-"), DiagramType = diagramType };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-23 09:42:22 +08:00
|
|
|
|
public void AddCopyPageExecuted(object para)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (DiagramViewModel != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var viewModel = DiagramViewModel;
|
2023-02-11 23:51:48 +08:00
|
|
|
|
DiagramItem diagramItem = new DiagramItem(viewModel);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
var selectedDesignerItems = viewModel.Items.OfType<DesignerItemViewModelBase>();
|
|
|
|
|
|
var selectedConnections = viewModel.Items.OfType<ConnectionViewModel>();
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
diagramItem.DesignerItems = selectedDesignerItems.Select(p => p.ToSerializableItem("json")).Where(p => p != null).ToList();
|
|
|
|
|
|
diagramItem.Connections = selectedConnections.Select(p => p.ToSerializableItem("json")).Where(p => p != null).ToList();
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-02-11 23:51:48 +08:00
|
|
|
|
viewModel = new DiagramViewModel(diagramItem);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
viewModel.Name = NewNameHelper.GetNewName(DiagramViewModels.Select(p => p.Name), "页-");
|
|
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
foreach (var diagramItemData in diagramItem.DesignerItems)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
2023-01-25 11:11:27 +08:00
|
|
|
|
Type type = TypeHelper.GetType(diagramItemData.ModelTypeName);
|
|
|
|
|
|
DesignerItemViewModelBase itemBase = Activator.CreateInstance(type, viewModel, diagramItemData, "json") as DesignerItemViewModelBase;
|
2021-07-23 09:42:22 +08:00
|
|
|
|
viewModel.Items.Add(itemBase);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var connection in diagramItem.Connections)
|
|
|
|
|
|
{
|
2023-01-25 11:11:27 +08:00
|
|
|
|
var connectionItem = JsonConvert.DeserializeObject<ConnectionItem>(connection.SerializableString);
|
|
|
|
|
|
|
|
|
|
|
|
connectionItem.SourceType = System.Type.GetType(connectionItem.SourceTypeName);
|
|
|
|
|
|
connectionItem.SinkType = System.Type.GetType(connectionItem.SinkTypeName);
|
2023-02-03 18:23:53 +08:00
|
|
|
|
DesignerItemViewModelBase sourceItem = DiagramViewModelHelper.GetConnectorDataItem(viewModel.Items, connectionItem.SourceId, connectionItem.SourceType);
|
2023-01-25 11:11:27 +08:00
|
|
|
|
ConnectorOrientation sourceConnectorOrientation = connectionItem.SourceOrientation;
|
2023-02-03 18:23:53 +08:00
|
|
|
|
FullyCreatedConnectorInfo sourceConnectorInfo = sourceItem.GetFullConnectorInfo(connectionItem.Id,sourceConnectorOrientation, connectionItem.SourceXRatio, connectionItem.SourceYRatio, connectionItem.SourceInnerPoint, connectionItem.SourceIsPortless);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-02-03 18:23:53 +08:00
|
|
|
|
DesignerItemViewModelBase sinkItem = DiagramViewModelHelper.GetConnectorDataItem(viewModel.Items, connectionItem.SinkId, connectionItem.SinkType);
|
2023-01-25 11:11:27 +08:00
|
|
|
|
ConnectorOrientation sinkConnectorOrientation = connectionItem.SinkOrientation;
|
2023-02-03 18:23:53 +08:00
|
|
|
|
FullyCreatedConnectorInfo sinkConnectorInfo = sinkItem.GetFullConnectorInfo(connectionItem.Id, sinkConnectorOrientation, connectionItem.SinkXRatio, connectionItem.SinkYRatio, connectionItem.SinkInnerPoint, connectionItem.SinkIsPortless);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-25 11:11:27 +08:00
|
|
|
|
ConnectionViewModel connectionVM = new ConnectionViewModel(viewModel, sourceConnectorInfo, sinkConnectorInfo, connectionItem);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
viewModel.Items.Add(connectionVM);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DiagramViewModels.Add(viewModel);
|
|
|
|
|
|
DiagramViewModel = viewModel;
|
|
|
|
|
|
InitDiagramViewModel();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void DeletePageExecuted(object para)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (para is DiagramViewModel oldpage)
|
|
|
|
|
|
{
|
|
|
|
|
|
int index = DiagramViewModels.IndexOf(oldpage) - 1;
|
|
|
|
|
|
DiagramViewModels.Remove(oldpage);
|
|
|
|
|
|
if (index > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
DiagramViewModel = DiagramViewModels[index];
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DiagramViewModel = DiagramViewModels.FirstOrDefault();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RenamePageExecuted(object para)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (para is DiagramViewModel oldpage)
|
|
|
|
|
|
{
|
|
|
|
|
|
oldpage.IsEditName = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void EndRenamePageExecuted(object para)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (para is DiagramViewModel oldpage)
|
|
|
|
|
|
{
|
|
|
|
|
|
oldpage.IsEditName = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddImageExecuted(object para)
|
|
|
|
|
|
{
|
|
|
|
|
|
ImageItemViewModel itemBase = new ImageItemViewModel();
|
2023-01-25 11:11:27 +08:00
|
|
|
|
DiagramViewModel?.DirectAddItemCommand.Execute(itemBase);
|
2023-01-24 16:20:39 +08:00
|
|
|
|
if (itemBase.Root != null)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
_service.DrawModeViewModel.CursorMode = CursorMode.Move;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void EditImageExecuted(object para)
|
|
|
|
|
|
{
|
|
|
|
|
|
ImageItemViewModel itemBase = para as ImageItemViewModel;
|
|
|
|
|
|
if (itemBase != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
itemBase.EditData();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ResizeImageExecuted(object para)
|
|
|
|
|
|
{
|
|
|
|
|
|
ImageItemViewModel itemBase = para as ImageItemViewModel;
|
|
|
|
|
|
if (itemBase != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
itemBase.StartResize();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ResetImageExecuted(object para)
|
|
|
|
|
|
{
|
|
|
|
|
|
ImageItemViewModel itemBase = para as ImageItemViewModel;
|
|
|
|
|
|
if (itemBase != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
itemBase.Reset();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddVideoExecuted(object para)
|
|
|
|
|
|
{
|
|
|
|
|
|
VideoItemViewModel itemBase = new VideoItemViewModel();
|
2023-01-25 11:11:27 +08:00
|
|
|
|
DiagramViewModel?.DirectAddItemCommand.Execute(itemBase);
|
2023-01-24 16:20:39 +08:00
|
|
|
|
if (itemBase.Root != null)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
_service.DrawModeViewModel.CursorMode = CursorMode.Move;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddOutLineTextExecuted(object para)
|
|
|
|
|
|
{
|
|
|
|
|
|
OutLineTextDesignerItemViewModel itemBase = new OutLineTextDesignerItemViewModel();
|
2023-01-25 11:11:27 +08:00
|
|
|
|
DiagramViewModel?.DirectAddItemCommand.Execute(itemBase);
|
2023-01-24 16:20:39 +08:00
|
|
|
|
if (itemBase.Root != null)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
_service.DrawModeViewModel.CursorMode = CursorMode.Move;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddBarcodeExecuted(object para)
|
|
|
|
|
|
{
|
2022-10-28 22:45:39 +08:00
|
|
|
|
BarcodeDesignerItemViewModel itemBase = new BarcodeDesignerItemViewModel() { Format = (BarcodeFormat)Enum.Parse(typeof(BarcodeFormat), para.ToString()), Text="AIStudio.Wpf.DiagramApp" };
|
2023-01-25 11:11:27 +08:00
|
|
|
|
DiagramViewModel?.DirectAddItemCommand.Execute(itemBase);
|
2023-01-24 16:20:39 +08:00
|
|
|
|
if (itemBase.Root != null)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
_service.DrawModeViewModel.CursorMode = CursorMode.Move;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
private Size MeasureString(OutLineTextDesignerItemViewModel itemBase)
|
|
|
|
|
|
{
|
|
|
|
|
|
var formattedText = new FormattedText(
|
|
|
|
|
|
itemBase.Text,
|
|
|
|
|
|
CultureInfo.CurrentUICulture,
|
|
|
|
|
|
FlowDirection.LeftToRight,
|
|
|
|
|
|
new Typeface(new FontFamily(itemBase.FontViewModel.FontFamily), itemBase.FontViewModel.FontStyle, itemBase.FontViewModel.FontWeight, itemBase.FontViewModel.FontStretch),
|
|
|
|
|
|
itemBase.FontViewModel.FontSize,
|
|
|
|
|
|
Brushes.Black);
|
|
|
|
|
|
|
|
|
|
|
|
return new Size(formattedText.Width, formattedText.Height);
|
|
|
|
|
|
}
|
2021-08-02 18:08:43 +08:00
|
|
|
|
|
|
|
|
|
|
public virtual void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|