调整了一下各种命令的位置,便于其他应用调用

This commit is contained in:
艾竹
2022-12-08 20:54:45 +08:00
parent 9a8d4c95f0
commit 9f91fbcdd3
41 changed files with 1363 additions and 769 deletions

View File

@@ -163,132 +163,50 @@ DesignerItems.OfType<DesignerItemBase>()
public void AddItems(IEnumerable<SelectableDesignerItemViewModelBase> selectedDesignerItems)
{
foreach (var item in selectedDesignerItems.OfType<DesignerItemViewModelBase>())
var items = selectedDesignerItems.OfType<DesignerItemViewModelBase>().Select(p => p.ToXmlObject());
foreach (var item in items)
{
if (item is PersistDesignerItemViewModel)
if (item is PersistDesignerItem persistDesignerItem)
{
PersistDesignerItems.Add(new PersistDesignerItem(item as PersistDesignerItemViewModel));
PersistDesignerItems.Add(persistDesignerItem);
}
else if (item is SettingsDesignerItemViewModel)
else if (item is SettingsDesignerItem settingsDesignerItem)
{
SettingsDesignerItems.Add(new SettingsDesignerItem(item as SettingsDesignerItemViewModel));
SettingsDesignerItems.Add(settingsDesignerItem);
}
else if (item is PathItemViewModel)
else if (item is PathDesignerItem pathDesignerItem)
{
PathDesignerItems.Add(new PathDesignerItem(item));
PathDesignerItems.Add(pathDesignerItem);
}
else if (item is GifImageItemViewModel)
else if (item is MediaDesignerItem mediaDesignerItem)
{
MediaDesignerItems.Add(new MediaDesignerItem(item as GifImageItemViewModel));
MediaDesignerItems.Add(mediaDesignerItem);
}
else if (item is MediaItemViewModel)
else if (item is ImageDesignerItem imageDesignerItem)
{
MediaDesignerItems.Add(new MediaDesignerItem(item as MediaItemViewModel));
ImageDesignerItems.Add(imageDesignerItem);
}
else if (item is ImageItemViewModel)
else if (item is TextDesignerItem textDesignerItem)
{
ImageDesignerItems.Add(new ImageDesignerItem(item as ImageItemViewModel));
TextDesignerItems.Add(textDesignerItem);
}
else if (item is TextDesignerItemViewModel)
else if (item is LogicalGateDesignerItemBase logicalGateDesignerItemBase)
{
TextDesignerItems.Add(new TextDesignerItem(item as TextDesignerItemViewModel));
LogicalGateItems.Add(logicalGateDesignerItemBase);
}
else if (item is LogicalGateItemViewModelBase)
else if (item is FlowNodeDesignerItem flowNodeDesignerItem)
{
LogicalGateItems.Add(new LogicalGateDesignerItemBase(item as LogicalGateItemViewModelBase));
FlowNodeDesignerItems.Add(flowNodeDesignerItem);
}
else if (item is FlowNode)
else if (item is SFCNodeDesignerItem sFCNodeDesignerItem)
{
FlowNodeDesignerItems.Add(new FlowNodeDesignerItem(item as FlowNode));
SFCNodeDesignerItems.Add(sFCNodeDesignerItem);
}
else if (item is SFCNode)
else if (item is DesignerItemBase designerItemBase)
{
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));
DesignerItems.Add(designerItemBase);
}
}
}
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
));
}
}
}
}

View File

@@ -17,6 +17,7 @@ using System.Windows.Media;
using System.Xml.Serialization;
using AIStudio.Wpf.DiagramDesigner;
using ZXing;
using AIStudio.Wpf.DiagramDesigner.Helpers;
namespace AIStudio.Wpf.DiagramApp.ViewModels
{
@@ -181,21 +182,6 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
return true;
}
public void ReDoExecuted()
{
DiagramViewModel.RedoCommand.Execute(null);
}
public void UnDoExecuted()
{
DiagramViewModel.UndoCommand.Execute(null);
}
public void SelectedAllExecuted()
{
DiagramViewModel.SelectAllCommand.Execute(null);
}
public static DiagramDocument OpenFile(string filename)
{
try
@@ -289,7 +275,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
ConnectorViewModel connectionVM = new ConnectorViewModel(viewModel, sourceConnectorInfo, sinkConnectorInfo, connection, connection.VectorLineDrawMode);
DesignerItemViewModelBase textItem = viewModel.Items.OfType<DesignerItemViewModelBase>().Single(x => x.ParentId == connection.Id);
DesignerItemViewModelBase textItem = viewModel.Items.OfType<DesignerItemViewModelBase>().FirstOrDefault(x => x.ParentId == connection.Id);
if (textItem != null)
{
connectionVM.OutTextItem = textItem;
@@ -354,15 +340,15 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
ConnectionItem connection = new ConnectionItem(
connectionVM.SourceConnectorInfo.DataItem.Id,
connectionVM.SourceConnectorInfo.Orientation,
DiagramItem.GetTypeOfDiagramItem(connectionVM.SourceConnectorInfo.DataItem),
GetXRatioFromConnector(connectionVM.SourceConnectorInfo),
GetYRatioFromConnector(connectionVM.SourceConnectorInfo),
connectionVM.SourceConnectorInfo.DataItem.GetType(),
connectionVM.GetXRatioFromConnector(connectionVM.SourceConnectorInfo),
connectionVM.GetYRatioFromConnector(connectionVM.SourceConnectorInfo),
connectionVM.SourceConnectorInfo.IsInnerPoint,
sinkConnector.DataItem.Id,
sinkConnector.Orientation,
DiagramItem.GetTypeOfDiagramItem(sinkConnector.DataItem),
GetXRatioFromConnector(sinkConnector),
GetYRatioFromConnector(sinkConnector),
sinkConnector.DataItem.GetType(),
connectionVM.GetXRatioFromConnector(sinkConnector),
connectionVM.GetYRatioFromConnector(sinkConnector),
sinkConnector.IsInnerPoint,
connectionVM);
@@ -385,225 +371,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
Status = "";
return true;
}
public void Paste()
{
if (Clipboard.ContainsData(DataFormats.Xaml))
{
String clipboardData = Clipboard.GetData(DataFormats.Xaml) as String;
if (String.IsNullOrEmpty(clipboardData))
return;
try
{
List<SelectableDesignerItemViewModelBase> items = new List<SelectableDesignerItemViewModelBase>();
DiagramItem copyitem = XmlSerializeHelper.DESerializer<DiagramItem>(clipboardData);
Dictionary<Guid, Guid> mappingOldToNewIDs = new Dictionary<Guid, Guid>();
foreach (var diagramItemData in copyitem.AllDesignerItems)
{
DesignerItemViewModelBase newItem = null;
Guid newID = Guid.NewGuid();
mappingOldToNewIDs.Add(diagramItemData.Id, newID);
diagramItemData.Id = newID;
diagramItemData.Left += OffsetX;
diagramItemData.Top += OffsetY;
Type type = TypeHelper.GetType(diagramItemData.ItemTypeName);
DesignerItemViewModelBase itemBase = (DesignerItemViewModelBase)Activator.CreateInstance(type, DiagramViewModel, diagramItemData);
newItem = itemBase;
if (newItem != null)
{
if (newItem.ParentId != Guid.Empty)
{
newItem.ParentId = mappingOldToNewIDs[newItem.ParentId];
}
items.Add(newItem);
}
}
OffsetX += 10;
OffsetY += 10;
foreach (var connection in copyitem.Connections)
{
Guid newID = Guid.NewGuid();
connection.SourceId = mappingOldToNewIDs[connection.SourceId];
connection.SinkId = mappingOldToNewIDs[connection.SinkId];
connection.SourceType = System.Type.GetType(connection.SourceTypeName);
connection.SinkType = System.Type.GetType(connection.SinkTypeName);
DesignerItemViewModelBase sourceItem = GetConnectorDataItem(DiagramViewModel, connection.SourceId, connection.SourceType);
ConnectorOrientation sourceConnectorOrientation = connection.SourceOrientation;
FullyCreatedConnectorInfo sourceConnectorInfo = GetFullConnectorInfo(connection.Id, sourceItem, sourceConnectorOrientation, connection.SourceXRatio, connection.SourceYRatio, connection.SourceInnerPoint);
DesignerItemViewModelBase sinkItem = GetConnectorDataItem(DiagramViewModel, connection.SinkId, connection.SinkType);
ConnectorOrientation sinkConnectorOrientation = connection.SinkOrientation;
FullyCreatedConnectorInfo sinkConnectorInfo = GetFullConnectorInfo(connection.Id, sinkItem, sinkConnectorOrientation, connection.SinkXRatio, connection.SinkYRatio, connection.SinkInnerPoint);
ConnectorViewModel connectionVM = new ConnectorViewModel(DiagramViewModel, sourceConnectorInfo, sinkConnectorInfo, connection, connection.VectorLineDrawMode);
items.Add(connectionVM);
}
DiagramViewModel.DirectAddItemCommand.Execute(items);
}
catch (Exception e)
{
MessageBox.Show(e.StackTrace, e.Message, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
public void CopyCurrentSelection()
{
IEnumerable<SelectableDesignerItemViewModelBase> selectedDesignerItems =
DiagramViewModel.SelectedItems.OfType<SelectableDesignerItemViewModelBase>();
List<ConnectorViewModel> selectedConnections =
DiagramViewModel.SelectedItems.OfType<ConnectorViewModel>().ToList();
foreach (ConnectorViewModel connection in DiagramViewModel.Items.OfType<ConnectorViewModel>())
{
if (!selectedConnections.Contains(connection))
{
DesignerItemViewModelBase sourceItem = (from item in selectedDesignerItems.OfType<DesignerItemViewModelBase>()
where item.Id == connection.SourceConnectorInfo.DataItem.Id
select item).FirstOrDefault();
DesignerItemViewModelBase sinkItem = (from item in DiagramViewModel.SelectedItems.OfType<DesignerItemViewModelBase>()
where item.Id == ((connection.SinkConnectorInfo as FullyCreatedConnectorInfo).DataItem).Id
select item).FirstOrDefault();
if (sourceItem != null &&
sinkItem != null &&
DiagramViewModel.BelongToSameGroup(sourceItem, sinkItem))
{
selectedConnections.Add(connection);
}
}
}
DiagramItem copyitem = new DiagramItem();
copyitem.AddItems(selectedDesignerItems);
foreach (var connectionVM in selectedConnections.OfType<ConnectorViewModel>())
{
FullyCreatedConnectorInfo sinkConnector = connectionVM.SinkConnectorInfo as FullyCreatedConnectorInfo;
ConnectionItem connection = new ConnectionItem(
connectionVM.SourceConnectorInfo.DataItem.Id,
connectionVM.SourceConnectorInfo.Orientation,
DiagramItem.GetTypeOfDiagramItem(connectionVM.SourceConnectorInfo.DataItem),
GetXRatioFromConnector(connectionVM.SourceConnectorInfo),
GetYRatioFromConnector(connectionVM.SourceConnectorInfo),
connectionVM.SourceConnectorInfo.IsInnerPoint,
sinkConnector.DataItem.Id,
sinkConnector.Orientation,
DiagramItem.GetTypeOfDiagramItem(sinkConnector.DataItem),
GetXRatioFromConnector(sinkConnector),
GetYRatioFromConnector(sinkConnector),
sinkConnector.IsInnerPoint,
connectionVM);
copyitem.ConnectionIds.Add(connectionVM.Id);
copyitem.Connections.Add(connection);
}
string xml = XmlSerializeHelper.XmlSerialize<DiagramItem>(copyitem);
OffsetX = 10;
OffsetY = 10;
Clipboard.Clear();
Clipboard.SetData(DataFormats.Xaml, xml);
}
public void DeleteCurrentSelection()
{
List<SelectableDesignerItemViewModelBase> itemsToRemove = DiagramViewModel.SelectedItems.OfType<SelectableDesignerItemViewModelBase>().ToList();
List<SelectableDesignerItemViewModelBase> connectionsToAlsoRemove = new List<SelectableDesignerItemViewModelBase>();
foreach (var connector in DiagramViewModel.Items.OfType<ConnectorViewModel>())
{
if (ItemsToDeleteHasConnector(itemsToRemove, connector.SourceConnectorInfo))
{
connectionsToAlsoRemove.Add(connector);
}
if (ItemsToDeleteHasConnector(itemsToRemove, connector.SinkConnectorInfo))
{
connectionsToAlsoRemove.Add(connector);
}
}
itemsToRemove.AddRange(connectionsToAlsoRemove);
DiagramViewModel.RemoveItemCommand.Execute(itemsToRemove);
}
public void CutCurrentSelection()
{
CopyCurrentSelection();
OffsetX = 0;
OffsetY = 0;
DeleteCurrentSelection();
}
private double GetXRatioFromConnector(FullyCreatedConnectorInfo info)
{
if (info.IsInnerPoint)
{
return info.XRatio;
}
else
{
switch (info.Orientation)
{
case ConnectorOrientation.Top:
return 0.5;
case ConnectorOrientation.Left:
return 0;
case ConnectorOrientation.Bottom:
return 0.5;
case ConnectorOrientation.Right:
return 1;
default: return info.XRatio;
}
}
}
private double GetYRatioFromConnector(FullyCreatedConnectorInfo info)
{
if (info.IsInnerPoint)
{
return info.YRatio;
}
else
{
switch (info.Orientation)
{
case ConnectorOrientation.Top:
return 0;
case ConnectorOrientation.Left:
return 0.5;
case ConnectorOrientation.Bottom:
return 1;
case ConnectorOrientation.Right:
return 0.5;
default: return info.YRatio;
}
}
}
}
private DesignerItemViewModelBase GetConnectorDataItem(IDiagramViewModel diagramViewModel, Guid conectorDataItemId, Type connectorDataItemType)
{
@@ -659,106 +427,6 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
return false;
}
#region
public void AlignTopExecuted(object para)
{
DiagramViewModel.AlignTopCommand.Execute(null);
}
public void AlignVerticalCentersExecuted(object para)
{
DiagramViewModel.AlignVerticalCentersCommand.Execute(null);
}
public void AlignBottomExecuted(object para)
{
DiagramViewModel.AlignBottomCommand.Execute(null);
}
public void AlignLeftExecuted(object para)
{
DiagramViewModel.AlignLeftCommand.Execute(null);
}
public void AlignHorizontalCentersExecuted(object para)
{
DiagramViewModel.AlignHorizontalCentersCommand.Execute(null);
}
public void AlignRightExecuted(object para)
{
DiagramViewModel.AlignRightCommand.Execute(null);
}
public void BringForwardExecuted(object para)
{
DiagramViewModel.BringForwardCommand.Execute(null);
}
public void BringToFrontExecuted(object para)
{
DiagramViewModel.BringToFrontCommand.Execute(null);
}
public void SendBackwardExecuted(object para)
{
DiagramViewModel.SendBackwardCommand.Execute(null);
}
public void SendToBackExecuted(object para)
{
DiagramViewModel.SendToBackCommand.Execute(null);
}
public void DistributeHorizontalExecuted(object para)
{
DiagramViewModel.DistributeHorizontalCommand.Execute(null);
}
public void DistributeVerticalExecuted(object para)
{
DiagramViewModel.DistributeVerticalCommand.Execute(null);
}
public void SelectAllExecuted(object para)
{
DiagramViewModel.SelectAllCommand.Execute(null);
}
public void GroupExecuted(object para)
{
var items = from item in DiagramViewModel.SelectedItems.OfType<DesignerItemViewModelBase>()
where item.ParentId == Guid.Empty
select item;
Rect rect = DiagramViewModel.GetBoundingRectangle(items);
GroupDesignerItemViewModel groupItem = new GroupDesignerItemViewModel();
groupItem.IsGroup = true;
groupItem.ItemWidth = rect.Width;
groupItem.ItemHeight = rect.Height;
groupItem.Left = rect.Left;
groupItem.Top = rect.Top;
groupItem.ZIndex = DiagramViewModel.Items.Count;
DiagramViewModel.DirectAddItemCommand.Execute(groupItem);
foreach (DesignerItemViewModelBase item in items)
item.ParentId = groupItem.Id;
DiagramViewModel.ClearSelectedItemsCommand.Execute(null);
//groupItem.IsSelected = true;
DiagramViewModel.SelectionService.AddToSelection(groupItem);
}
public void UngroupExecuted(object para)
{
var groups = (from item in DiagramViewModel.SelectedItems.OfType<DesignerItemViewModelBase>()
where item.IsGroup && item.ParentId == Guid.Empty
select item).ToArray();
foreach (DesignerItemViewModelBase groupRoot in groups)
{
var children = from child in DiagramViewModel.SelectedItems.OfType<DesignerItemViewModelBase>()
where child.ParentId == groupRoot.Id
select child;
foreach (DesignerItemViewModelBase child in children)
child.ParentId = Guid.Empty;
DiagramViewModel.RemoveItemCommand.Execute(groupRoot);
DiagramViewModel.UpdateZIndex();
}
}
#endregion
#region
public void SetPropertyValue(SelectableDesignerItemViewModelBase selectable, string propertyName)
{
@@ -806,93 +474,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
}
quickThemeViewModel.QuickTheme = null;
}
}
public void CenterMoveExecuted(object para)
{
foreach (var item in DiagramViewModel.SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.Left = (DiagramViewModel.PageSize.Width - item.ItemWidth) / 2;
item.Top = (DiagramViewModel.PageSize.Height - item.ItemHeight) / 2;
}
}
public void LeftMoveExecuted(object para)
{
foreach (var item in DiagramViewModel.SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.Left -= 0.5;
}
}
public void RightMoveExecuted(object para)
{
foreach (var item in DiagramViewModel.SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.Left += 0.5;
}
}
public void UpMoveExecuted(object para)
{
foreach (var item in DiagramViewModel.SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.Top -= 0.5;
}
}
public void DownMoveExecuted(object para)
{
foreach (var item in DiagramViewModel.SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.Top += 0.5;
}
}
public void SameWidthExecuted(object para)
{
if (para is DesignerItemViewModelBase designerItem)
{
foreach (var item in DiagramViewModel.SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.ItemWidth = designerItem.ItemWidth;
}
}
}
public void SameHeightExecuted(object para)
{
if (para is DesignerItemViewModelBase designerItem)
{
foreach (var item in DiagramViewModel.SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.ItemHeight = designerItem.ItemHeight;
}
}
}
public void SameAngleExecuted(object para)
{
if (para is DesignerItemViewModelBase designerItem)
{
foreach (var item in DiagramViewModel.SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.Angle = designerItem.Angle;
}
}
}
public void SameSizeExecuted(object para)
{
if (para is DesignerItemViewModelBase designerItem)
{
foreach (var item in DiagramViewModel.SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.ItemWidth = designerItem.ItemWidth;
item.ItemHeight = designerItem.ItemHeight;
}
}
}
}
public void LockAction(LockObject lockObject, string propertyName)
{
@@ -946,15 +528,15 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
ConnectionItem connection = new ConnectionItem(
connectionVM.SourceConnectorInfo.DataItem.Id,
connectionVM.SourceConnectorInfo.Orientation,
DiagramItem.GetTypeOfDiagramItem(connectionVM.SourceConnectorInfo.DataItem),
GetXRatioFromConnector(connectionVM.SourceConnectorInfo),
GetYRatioFromConnector(connectionVM.SourceConnectorInfo),
connectionVM.SourceConnectorInfo.DataItem.GetType(),
connectionVM.GetXRatioFromConnector(connectionVM.SourceConnectorInfo),
connectionVM.GetYRatioFromConnector(connectionVM.SourceConnectorInfo),
connectionVM.SourceConnectorInfo.IsInnerPoint,
sinkConnector.DataItem.Id,
sinkConnector.Orientation,
DiagramItem.GetTypeOfDiagramItem(sinkConnector.DataItem),
GetXRatioFromConnector(sinkConnector),
GetYRatioFromConnector(sinkConnector),
sinkConnector.DataItem.GetType(),
connectionVM.GetXRatioFromConnector(sinkConnector),
connectionVM.GetYRatioFromConnector(sinkConnector),
sinkConnector.IsInnerPoint,
connectionVM);
@@ -1039,7 +621,6 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
}
}
public void AddImageExecuted(object para)
{
ImageItemViewModel itemBase = new ImageItemViewModel();
@@ -1107,7 +688,6 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
}
}
#endregion
private Size MeasureString(OutLineTextDesignerItemViewModel itemBase)
{

View File

@@ -737,23 +737,17 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
private void UnDoExecuted()
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.UnDoExecuted();
DiagramsViewModel?.DiagramViewModel?.UndoCommand.Execute(null);
}
private void ReDoExecuted()
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.ReDoExecuted();
DiagramsViewModel?.DiagramViewModel?.RedoCommand.Execute(null);
}
private void SelectedAllExecuted()
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.SelectedAllExecuted();
DiagramsViewModel?.DiagramViewModel?.SelectAllCommand.Execute(null);
}
private void OpenExecuted(string para = null)
@@ -851,21 +845,17 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
private void PasteExecuted()
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.Paste();
DiagramsViewModel?.DiagramViewModel?.PasteCommand.Execute(null);
}
private bool Paste_Enabled()
{
return Clipboard.ContainsData(DataFormats.Xaml);
return Clipboard.ContainsData(DataFormats.Serializable);
}
private void CopyExecuted()
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.CopyCurrentSelection();
DiagramsViewModel?.DiagramViewModel?.CopyCommand.Execute(null);
}
private bool Copy_Enabled()
@@ -875,9 +865,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
private void DeleteExecuted()
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.DeleteCurrentSelection();
DiagramsViewModel?.DiagramViewModel?.DeleteCommand.Execute(null);
}
private bool Delete_Enabled()
@@ -887,9 +875,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
private void CutExecuted()
{
if (DiagramsViewModel != null)
DiagramsViewModel.CutCurrentSelection();
DiagramsViewModel?.DiagramViewModel?.CutCommand.Execute(null);
}
private bool Cut_Enabled()
@@ -937,267 +923,191 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
private void GroupExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.GroupExecuted(para);
DiagramsViewModel?.DiagramViewModel?.GroupCommand.Execute(para);
}
private void UngroupExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.UngroupExecuted(para);
DiagramsViewModel?.DiagramViewModel?.UngroupCommand.Execute(para);
}
#region
private void AlignTopExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.AlignTopExecuted(para);
DiagramsViewModel?.DiagramViewModel?.AlignTopCommand.Execute(para);
}
private void AlignVerticalCentersExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.AlignVerticalCentersExecuted(para);
DiagramsViewModel?.DiagramViewModel?.AlignVerticalCentersCommand.Execute(para);
}
private void AlignBottomExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.AlignBottomExecuted(para);
{
DiagramsViewModel?.DiagramViewModel?.AlignBottomCommand.Execute(para);
}
private void AlignLeftExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.AlignLeftExecuted(para);
{
DiagramsViewModel?.DiagramViewModel?.AlignLeftCommand.Execute(para);
}
private void AlignHorizontalCentersExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.AlignHorizontalCentersExecuted(para);
DiagramsViewModel?.DiagramViewModel?.AlignHorizontalCentersCommand.Execute(para);
}
private void AlignRightExecuted(object para)
{
DiagramsViewModel.AlignRightExecuted(para);
DiagramsViewModel?.DiagramViewModel?.AlignRightCommand.Execute(para);
}
private void BringForwardExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.BringForwardExecuted(para);
DiagramsViewModel?.DiagramViewModel?.BringForwardCommand.Execute(para);
}
private void BringToFrontExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.BringToFrontExecuted(para);
DiagramsViewModel?.DiagramViewModel?.BringToFrontCommand.Execute(para);
}
private void SendBackwardExecuted(object para)
{
DiagramsViewModel.SendBackwardExecuted(para);
DiagramsViewModel?.DiagramViewModel?.SendBackwardCommand.Execute(para);
}
private void SendToBackExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.SendToBackExecuted(para);
DiagramsViewModel?.DiagramViewModel?.SendBackwardCommand.Execute(para);
}
private void DistributeHorizontalExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.DistributeHorizontalExecuted(para);
DiagramsViewModel?.DiagramViewModel?.DistributeHorizontalCommand.Execute(para);
}
private void DistributeVerticalExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.DistributeVerticalExecuted(para);
DiagramsViewModel?.DiagramViewModel?.DistributeVerticalCommand.Execute(para);
}
private void SelectAllExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.SelectAllExecuted(para);
DiagramsViewModel?.DiagramViewModel?.SelectAllCommand.Execute(para);
}
#endregion
private void CenterMoveExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.CenterMoveExecuted(para);
DiagramsViewModel?.DiagramViewModel?.CenterMoveCommand.Execute(para);
}
private void LeftMoveExecuted(object para = null)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.LeftMoveExecuted(para);
DiagramsViewModel?.DiagramViewModel?.LeftMoveCommand.Execute(para);
}
private void RightMoveExecuted(object para = null)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.RightMoveExecuted(para);
DiagramsViewModel?.DiagramViewModel?.RightMoveCommand.Execute(para);
}
private void UpMoveExecuted(object para = null)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.UpMoveExecuted(para);
DiagramsViewModel?.DiagramViewModel?.UpMoveCommand.Execute(para);
}
private void DownMoveExecuted(object para = null)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.DownMoveExecuted(para);
DiagramsViewModel?.DiagramViewModel?.DownMoveCommand.Execute(para);
}
private void SameWidthExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.SameWidthExecuted(para);
DiagramsViewModel?.DiagramViewModel?.SameWidthCommand.Execute(para);
}
private void SameHeightExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.SameHeightExecuted(para);
DiagramsViewModel?.DiagramViewModel?.SameHeightCommand.Execute(para);
}
private void SameSizeExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.SameSizeExecuted(para);
DiagramsViewModel?.DiagramViewModel?.SameSizeCommand.Execute(para);
}
private void SameAngleExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.SameAngleExecuted(para);
DiagramsViewModel?.DiagramViewModel?.SameAngleCommand.Execute(para);
}
private void LockExecuted(object para)
{
if (DiagramsViewModel == null) return;
LockObjectViewModel.LockObject[0].IsChecked = true;
}
private void UnlockExecuted(object para)
{
if (DiagramsViewModel == null) return;
LockObjectViewModel.LockObject.ForEach(p => p.IsChecked = false);
}
private void AddPageExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.AddPageExecuted(para);
DiagramsViewModel?.AddPageExecuted(para);
}
private void AddCopyPageExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.AddCopyPageExecuted(para);
DiagramsViewModel?.AddCopyPageExecuted(para);
}
private void RenamePageExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.RenamePageExecuted(para);
DiagramsViewModel?.RenamePageExecuted(para);
}
private void EndRenamePageExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.EndRenamePageExecuted(para);
DiagramsViewModel?.EndRenamePageExecuted(para);
}
private void DeletePageExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.DeletePageExecuted(para);
DiagramsViewModel?.DeletePageExecuted(para);
}
private void AddImageExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.AddImageExecuted(null);
DiagramsViewModel?.AddImageExecuted(para);
}
private void EditImageExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.EditImageExecuted(DiagramsViewModel.DiagramViewModel.SelectedItems?.FirstOrDefault());
DiagramsViewModel?.EditImageExecuted(DiagramsViewModel.DiagramViewModel.SelectedItems?.FirstOrDefault());
}
private void ResizeImageExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.ResizeImageExecuted(DiagramsViewModel.DiagramViewModel.SelectedItems?.FirstOrDefault());
DiagramsViewModel?.ResizeImageExecuted(DiagramsViewModel.DiagramViewModel.SelectedItems?.FirstOrDefault());
}
private void ResetImageExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.ResetImageExecuted(DiagramsViewModel.DiagramViewModel.SelectedItems?.FirstOrDefault());
DiagramsViewModel?.ResetImageExecuted(DiagramsViewModel.DiagramViewModel.SelectedItems?.FirstOrDefault());
}
private void AddVideoExectued(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.AddVideoExecuted(null);
DiagramsViewModel?.AddVideoExecuted(para);
}
private void AddOutLineTextExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.AddOutLineTextExecuted(para);
DiagramsViewModel?.AddOutLineTextExecuted(para);
}
private void AddBarcodeExecuted(object para)
{
if (DiagramsViewModel == null) return;
DiagramsViewModel.AddBarcodeExecuted(para);
DiagramsViewModel?.AddBarcodeExecuted(para);
}
private void SelectedColorExecuted(object para)
{
if (DiagramsViewModel == null) return;
switch (ColorType)
{
case Models.ColorType.Text: DiagramsViewModel.SetFont(new FontViewModel() { FontColor = (Color)para }, "FontColor"); break;
case Models.ColorType.Fill: DiagramsViewModel.SetColor(new ColorViewModel() { FillColor = new ColorObject() { Color = (Color)para } }, "FillColor"); break;
case Models.ColorType.Line: DiagramsViewModel.SetColor(new ColorViewModel() { LineColor = new ColorObject() { Color = (Color)para } }, "LineColor"); break;
case Models.ColorType.Text: DiagramsViewModel?.SetFont(new FontViewModel() { FontColor = (Color)para }, "FontColor"); break;
case Models.ColorType.Fill: DiagramsViewModel?.SetColor(new ColorViewModel() { FillColor = new ColorObject() { Color = (Color)para } }, "FillColor"); break;
case Models.ColorType.Line: DiagramsViewModel?.SetColor(new ColorViewModel() { LineColor = new ColorObject() { Color = (Color)para } }, "LineColor"); break;
}
}

View File

@@ -40,6 +40,7 @@ namespace AIStudio.Wpf.DiagramApp
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
base.OnPreviewKeyDown(e);
e.Handled = MainWindowViewModel.KeyExecuted(e.KeyboardDevice.Modifiers == ModifierKeys.None ? e.Key.ToString() : e.KeyboardDevice.Modifiers.ToString() + "+" + e.Key.ToString());
}

View File

@@ -401,48 +401,8 @@ namespace AIStudio.Wpf.DiagramDesigner
{
base.OnPreviewKeyDown(e);
if (_viewModel.IsReadOnly) return;
if (e.Key == Key.Left)
{
if (_viewModel.SelectedItems != null)
{
foreach(var item in _viewModel.SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.Left -= 0.1;
}
}
}
else if (e.Key == Key.Right)
{
if (_viewModel.SelectedItems != null)
{
foreach (var item in _viewModel.SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.Left += 0.1;
}
}
}
else if (e.Key == Key.Up)
{
if (_viewModel.SelectedItems != null)
{
foreach (var item in _viewModel.SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.Top -= 0.1;
}
}
}
else if (e.Key == Key.Down)
{
if (_viewModel.SelectedItems != null)
{
foreach (var item in _viewModel.SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.Top += 0.1;
}
}
}
}
protected override Size MeasureOverride(Size constraint)

View File

@@ -5,7 +5,7 @@ using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace AIStudio.Wpf.DiagramHelper.Helpers
namespace AIStudio.Wpf.DiagramDesigner.Helpers
{
public class TypeHelper
{

View File

@@ -6,7 +6,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace AIStudio.Wpf.DiagramHelper.Helpers
namespace AIStudio.Wpf.DiagramDesigner.Helpers
{
public class XmlSerializeHelper
{

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
namespace AIStudio.Wpf.DiagramDesigner.Models
{
[Serializable]
[XmlInclude(typeof(SerializableItem))]
public class SerializableItem
{
[XmlIgnore]
public Type Type
{
get; set;
}
[XmlAttribute]
public string TypeName
{
get; set;
}
[XmlAttribute]
public string ObjectJson
{
get; set;
}
}
[Serializable]
[XmlInclude(typeof(SerializableObject))]
public class SerializableObject
{
[XmlArray]
public List<SerializableItem> DesignerItems { get; set; } = new List<SerializableItem>();
[XmlArray]
public List<SerializableItem> Connections { get; set; } = new List<SerializableItem>();
}
}

View File

@@ -6,6 +6,7 @@ using System.ComponentModel;
using System.Windows;
using System.Linq;
using System.Reactive.Linq;
using AIStudio.Wpf.DiagramDesigner.Models;
namespace AIStudio.Wpf.DiagramDesigner
{
@@ -19,6 +20,10 @@ namespace AIStudio.Wpf.DiagramDesigner
{
}
public DesignerItemViewModelBase(IDiagramViewModel parent, string json) : base(parent, json)
{
}
protected override void Init()
{
base.Init();
@@ -42,6 +47,16 @@ namespace AIStudio.Wpf.DiagramDesigner
this.Icon = designer.Icon;
}
public override SelectableDesignerItemBase ToXmlObject()
{
return new DesignerItemBase(this);
}
public override Type ToXmlType()
{
return typeof(DesignerItemBase);
}
protected virtual void InitConnector()
{
connectors.Add(new FullyCreatedConnectorInfo(this, ConnectorOrientation.Top));

View File

@@ -78,6 +78,20 @@ namespace AIStudio.Wpf.DiagramDesigner
BuildMenuOptions();
}
public LogicalGateItemViewModelBase(IDiagramViewModel parent, string json) : base(parent, json)
{
BuildMenuOptions();
}
public override SelectableDesignerItemBase ToXmlObject()
{
return new LogicalGateDesignerItemBase(this);
}
public override Type ToXmlType()
{
return typeof(LogicalGateDesignerItemBase);
}
protected override void Init()
{

View File

@@ -5,19 +5,30 @@ using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows.Media;
using AIStudio.Wpf.DiagramDesigner.Models;
using Newtonsoft.Json;
namespace AIStudio.Wpf.DiagramDesigner
{
public interface ISelectItems
{
SimpleCommand SelectItemCommand { get; }
SimpleCommand SelectItemCommand
{
get;
}
}
public abstract class SelectableDesignerItemViewModelBase : BindableBase, ISelectItems, ISelectable, IGroupable
{
private IDiagramServiceProvider _service { get { return DiagramServicesProvider.Instance.Provider; } }
private IDiagramServiceProvider _service
{
get
{
return DiagramServicesProvider.Instance.Provider;
}
}
public SelectableDesignerItemViewModelBase()
{
@@ -32,6 +43,37 @@ namespace AIStudio.Wpf.DiagramDesigner
(FontViewModel as FontViewModel).PropertyChanged += FontViewModel_PropertyChanged;
}
public SelectableDesignerItemViewModelBase(IDiagramViewModel parent, string json)
{
Init();
LoadDesignerItemViewModel(parent, JsonConvert.DeserializeObject(json, ToXmlType()) as SelectableDesignerItemBase);
(FontViewModel as FontViewModel).PropertyChanged += FontViewModel_PropertyChanged;
}
public virtual SelectableDesignerItemBase ToXmlObject()
{
return null;
}
public virtual SerializableItem ToSerializabObject()
{
var obj = ToXmlObject();
if (obj != null)
{
return new SerializableItem() { TypeName = this.GetType().FullName, ObjectJson = obj.ToJson() };
}
else
{
return null;
}
}
public virtual Type ToXmlType()
{
return null;
}
protected virtual void Init()
{
ColorViewModel = _service.CopyDefaultColorViewModel();
@@ -68,13 +110,28 @@ namespace AIStudio.Wpf.DiagramDesigner
public List<SelectableDesignerItemViewModelBase> SelectedItems
{
//todo
get { return Parent.SelectedItems; }
get
{
return Parent.SelectedItems;
}
}
public IDiagramViewModel Parent { get; set; }
public SimpleCommand SelectItemCommand { get; private set; }
public ICommand EditCommand { get; private set; }
public Guid Id { get; set; }
public IDiagramViewModel Parent
{
get; set;
}
public SimpleCommand SelectItemCommand
{
get; private set;
}
public ICommand EditCommand
{
get; private set;
}
public Guid Id
{
get; set;
}
private Guid _parentId;
public Guid ParentId
@@ -88,9 +145,15 @@ namespace AIStudio.Wpf.DiagramDesigner
SetProperty(ref _parentId, value);
}
}
public SelectableDesignerItemViewModelBase ParentItem { get; set; }
public SelectableDesignerItemViewModelBase ParentItem
{
get; set;
}
public bool IsGroup { get; set; }
public bool IsGroup
{
get; set;
}
private bool _isSelected;
[Browsable(false)]
@@ -203,7 +266,10 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
public ILockObjectViewModel LockObjectViewModel { get; set; }
public ILockObjectViewModel LockObjectViewModel
{
get; set;
}
private string _text;
@@ -275,7 +341,10 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
public SelectableDesignerItemViewModelBase OutTextItem { get; set; }
public DesignerItemViewModelBase OutTextItem
{
get; set;
}
private void ExecuteSelectItemCommand(object param)
{

View File

@@ -25,6 +25,42 @@ namespace AIStudio.Wpf.DiagramDesigner
Init(sourceConnectorInfo, sinkConnectorInfo);
}
public ConnectorViewModel( FullyCreatedConnectorInfo sourceConnectorInfo, ConnectorInfoBase sinkConnectorInfo, DrawMode vectorLineDrawMode):this(null, sourceConnectorInfo, sinkConnectorInfo, vectorLineDrawMode)
{
}
public override SelectableDesignerItemBase ToXmlObject()
{
if (SinkConnectorInfo is FullyCreatedConnectorInfo sinkConnector)
{
ConnectionItem connection = new ConnectionItem(
SourceConnectorInfo.DataItem.Id,
SourceConnectorInfo.Orientation,
SourceConnectorInfo.DataItem.GetType(),
GetXRatioFromConnector(SourceConnectorInfo),
GetYRatioFromConnector(SourceConnectorInfo),
SourceConnectorInfo.IsInnerPoint,
sinkConnector.DataItem.Id,
sinkConnector.Orientation,
sinkConnector.DataItem.GetType(),
GetXRatioFromConnector(sinkConnector),
GetYRatioFromConnector(sinkConnector),
sinkConnector.IsInnerPoint,
this);
return connection;
}
else
{
return null;
}
}
public override Type ToXmlType()
{
return typeof(ConnectionItem);
}
public IPathFinder PathFinder
{
@@ -207,6 +243,52 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
public double GetXRatioFromConnector(FullyCreatedConnectorInfo info)
{
if (info.IsInnerPoint)
{
return info.XRatio;
}
else
{
switch (info.Orientation)
{
case ConnectorOrientation.Top:
return 0.5;
case ConnectorOrientation.Left:
return 0;
case ConnectorOrientation.Bottom:
return 0.5;
case ConnectorOrientation.Right:
return 1;
default: return info.XRatio;
}
}
}
public double GetYRatioFromConnector(FullyCreatedConnectorInfo info)
{
if (info.IsInnerPoint)
{
return info.YRatio;
}
else
{
switch (info.Orientation)
{
case ConnectorOrientation.Top:
return 0;
case ConnectorOrientation.Left:
return 0.5;
case ConnectorOrientation.Bottom:
return 1;
case ConnectorOrientation.Right:
return 0.5;
default: return info.YRatio;
}
}
}
private void UpdateArea()
{
Area = new Rect(SourceA, SourceB);

View File

@@ -8,6 +8,9 @@ using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using AIStudio.Wpf.DiagramDesigner.Helpers;
using AIStudio.Wpf.DiagramDesigner.Models;
using Newtonsoft.Json;
namespace AIStudio.Wpf.DiagramDesigner
{
@@ -353,36 +356,61 @@ namespace AIStudio.Wpf.DiagramDesigner
/// 用于wpf大小与物理像素之间转换
/// </summary>
public double ScreenScale { get; set; } = 1;
private double OffsetX = 10;
private double OffsetY = 10;
#endregion
private DoCommandManager DoCommandManager = new DoCommandManager();
public DiagramViewModel()
{
CreateNewDiagramCommand = new SimpleCommand(ExecuteCreateNewDiagramCommand);
AddItemCommand = new SimpleCommand(ExecuteAddItemCommand);
DirectAddItemCommand = new SimpleCommand(ExecuteDirectAddItemCommand);
RemoveItemCommand = new SimpleCommand(ExecuteRemoveItemCommand);
DirectRemoveItemCommand = new SimpleCommand(ExecuteDirectRemoveItemCommand);
ClearSelectedItemsCommand = new SimpleCommand(ExecuteClearSelectedItemsCommand);
CreateNewDiagramCommand = new SimpleCommand(ExecuteEnable, ExecuteCreateNewDiagramCommand);
AddItemCommand = new SimpleCommand(ExecuteEnable, ExecuteAddItemCommand);
DirectAddItemCommand = new SimpleCommand(ExecuteEnable, ExecuteDirectAddItemCommand);
RemoveItemCommand = new SimpleCommand(ExecuteEnable, ExecuteRemoveItemCommand);
DirectRemoveItemCommand = new SimpleCommand(ExecuteEnable, ExecuteDirectRemoveItemCommand);
ClearSelectedItemsCommand = new SimpleCommand(ExecuteEnable, ExecuteClearSelectedItemsCommand);
AlignTopCommand = new SimpleCommand(ExecuteAlignTopCommand);
AlignVerticalCentersCommand = new SimpleCommand(ExecuteAlignVerticalCentersCommand);
AlignBottomCommand = new SimpleCommand(ExecuteAlignBottomCommand);
AlignLeftCommand = new SimpleCommand(ExecuteAlignLeftCommand);
AlignHorizontalCentersCommand = new SimpleCommand(ExecuteAlignHorizontalCentersCommand);
AlignRightCommand = new SimpleCommand(ExecuteAlignRightCommand);
BringForwardCommand = new SimpleCommand(ExecuteBringForwardCommand);
BringToFrontCommand = new SimpleCommand(ExecuteBringToFrontCommand);
SendBackwardCommand = new SimpleCommand(ExecuteSendBackwardCommand);
SendToBackCommand = new SimpleCommand(ExecuteSendToBackCommand);
DistributeHorizontalCommand = new SimpleCommand(ExecuteDistributeHorizontalCommand);
DistributeVerticalCommand = new SimpleCommand(ExecuteDistributeVerticalCommand);
SelectAllCommand = new SimpleCommand(ExecuteSelectAllCommand);
AlignTopCommand = new SimpleCommand(ExecuteEnable, ExecuteAlignTopCommand);
AlignVerticalCentersCommand = new SimpleCommand(ExecuteEnable, ExecuteAlignVerticalCentersCommand);
AlignBottomCommand = new SimpleCommand(ExecuteEnable, ExecuteAlignBottomCommand);
AlignLeftCommand = new SimpleCommand(ExecuteEnable, ExecuteAlignLeftCommand);
AlignHorizontalCentersCommand = new SimpleCommand(ExecuteEnable, ExecuteAlignHorizontalCentersCommand);
AlignRightCommand = new SimpleCommand(ExecuteEnable, ExecuteAlignRightCommand);
BringForwardCommand = new SimpleCommand(ExecuteEnable, ExecuteBringForwardCommand);
BringToFrontCommand = new SimpleCommand(ExecuteEnable, ExecuteBringToFrontCommand);
SendBackwardCommand = new SimpleCommand(ExecuteEnable, ExecuteSendBackwardCommand);
SendToBackCommand = new SimpleCommand(ExecuteEnable, ExecuteSendToBackCommand);
DistributeHorizontalCommand = new SimpleCommand(ExecuteEnable, ExecuteDistributeHorizontalCommand);
DistributeVerticalCommand = new SimpleCommand(ExecuteEnable, ExecuteDistributeVerticalCommand);
SelectAllCommand = new SimpleCommand(ExecuteEnable, ExecuteSelectAllCommand);
CopyCommand = new SimpleCommand(ExecuteEnable, ExecuteCopyCommand);
PasteCommand = new SimpleCommand(ExecuteEnable, ExecutePasteCommand);
CutCommand = new SimpleCommand(ExecuteEnable, ExecuteCutCommand);
DeleteCommand = new SimpleCommand(ExecuteEnable, ExecuteDeleteCommand);
LeftMoveCommand = new SimpleCommand(ExecuteEnable, ExecuteLeftMoveCommand);
RightMoveCommand = new SimpleCommand(ExecuteEnable, ExecuteRightMoveCommand);
UpMoveCommand = new SimpleCommand(ExecuteEnable, ExecuteUpMoveCommand);
DownMoveCommand = new SimpleCommand(ExecuteEnable, ExecuteDownMoveCommand);
CenterMoveCommand = new SimpleCommand(ExecuteEnable, ExecuteCenterMoveCommand);
SameSizeCommand = new SimpleCommand(ExecuteEnable, ExecuteSameSizeCommand);
SameWidthCommand = new SimpleCommand(ExecuteEnable, ExecuteSameWidthCommand);
SameHeightCommand = new SimpleCommand(ExecuteEnable, ExecuteSameHeightCommand);
SameAngleCommand = new SimpleCommand(ExecuteEnable, ExecuteSameAngleCommand);
GroupCommand = new SimpleCommand(ExecuteEnable, ExecuteGroupCommand);
UngroupCommand = new SimpleCommand(ExecuteEnable, ExecuteUngroupCommand);
LockCommand = new SimpleCommand(ExecuteEnable, ExecuteLockCommand);
UnlockCommand = new SimpleCommand(ExecuteEnable, ExecuteUnlockCommand);
Mediator.Instance.Register(this);
Items.CollectionChanged += Items_CollectionChanged;
}
public bool ExecuteEnable(object para)
{
return IsReadOnly == false;
}
#region UnDo ReDo
private void Do(object sender, string propertyName, object newvalue)
@@ -550,6 +578,83 @@ namespace AIStudio.Wpf.DiagramDesigner
get; private set;
}
public SimpleCommand CopyCommand
{
get; private set;
}
public SimpleCommand PasteCommand
{
get; private set;
}
public SimpleCommand CutCommand
{
get; private set;
}
public SimpleCommand DeleteCommand
{
get; private set;
}
public SimpleCommand LeftMoveCommand
{
get; private set;
}
public SimpleCommand RightMoveCommand
{
get; private set;
}
public SimpleCommand UpMoveCommand
{
get; private set;
}
public SimpleCommand DownMoveCommand
{
get; private set;
}
public SimpleCommand CenterMoveCommand
{
get; private set;
}
public SimpleCommand SameSizeCommand
{
get; private set;
}
public SimpleCommand SameWidthCommand
{
get; private set;
}
public SimpleCommand SameHeightCommand
{
get; private set;
}
public SimpleCommand SameAngleCommand
{
get; private set;
}
public SimpleCommand GroupCommand
{
get; private set;
}
public SimpleCommand UngroupCommand
{
get; private set;
}
public SimpleCommand LockCommand
{
get; private set;
}
public SimpleCommand UnlockCommand
{
get; private set;
}
private SimpleCommand _undoCommand;
public SimpleCommand UndoCommand
{
@@ -597,6 +702,7 @@ namespace AIStudio.Wpf.DiagramDesigner
get; set;
}
public bool AddVerify(SelectableDesignerItemViewModelBase item)
{
if (item.InitData() == false)
@@ -638,7 +744,10 @@ namespace AIStudio.Wpf.DiagramDesigner
{
item.Parent = this;
item.ZIndex = Items.Count;
item.Id = Guid.NewGuid();
if (item.Id == Guid.Empty)
{
item.Id = Guid.NewGuid();
}
//item.LineColor = this.LineColor;
//item.FillColor = this.FillColor;
var logical = item as LogicalGateItemViewModelBase;
@@ -1267,6 +1376,363 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
private void ExecuteCopyCommand(object parameter)
{
List<DesignerItemViewModelBase> selectedDesignerItems =
SelectedItems.OfType<DesignerItemViewModelBase>().ToList();
List<ConnectorViewModel> selectedConnections =
SelectedItems.OfType<ConnectorViewModel>().ToList();
foreach (ConnectorViewModel connection in Items.OfType<ConnectorViewModel>())
{
if (!selectedConnections.Contains(connection))
{
DesignerItemViewModelBase sourceItem = (from item in selectedDesignerItems
where item.Id == connection.SourceConnectorInfo.DataItem.Id
select item).FirstOrDefault();
DesignerItemViewModelBase sinkItem = (from item in selectedDesignerItems
where item.Id == ((connection.SinkConnectorInfo as FullyCreatedConnectorInfo).DataItem).Id
select item).FirstOrDefault();
if (sourceItem != null &&
sinkItem != null &&
BelongToSameGroup(sourceItem, sinkItem))
{
selectedConnections.Add(connection);
}
}
}
//连线上的文本
foreach (var selectedConnection in selectedConnections)
{
if (selectedConnection.OutTextItem != null)
{
selectedDesignerItems.Add(selectedConnection.OutTextItem);
}
}
string json = new SerializableObject
{
DesignerItems = selectedDesignerItems.Select(p => p.ToSerializabObject()).Where(p => p != null).ToList(),
Connections = selectedConnections.Select(p => p.ToSerializabObject()).Where(p => p != null).ToList(),
}.ToJson();
OffsetX = 10;
OffsetY = 10;
Clipboard.Clear();
Clipboard.SetData(DataFormats.Serializable, json);
}
private void ExecutePasteCommand(object parameter)
{
if (Clipboard.ContainsData(DataFormats.Serializable))
{
String clipboardData = Clipboard.GetData(DataFormats.Serializable) as String;
if (String.IsNullOrEmpty(clipboardData))
return;
try
{
List<SelectableDesignerItemViewModelBase> items = new List<SelectableDesignerItemViewModelBase>();
SerializableObject copyitem = JsonConvert.DeserializeObject<SerializableObject>(clipboardData);
Dictionary<Guid, Guid> mappingOldToNewIDs = new Dictionary<Guid, Guid>();
foreach (var diagramItemData in copyitem.DesignerItems)
{
DesignerItemViewModelBase newItem = null;
Type type = TypeHelper.GetType(diagramItemData.TypeName);
DesignerItemViewModelBase itemBase = (DesignerItemViewModelBase)Activator.CreateInstance(type, this, diagramItemData.ObjectJson);
Guid newID = Guid.NewGuid();
mappingOldToNewIDs.Add(itemBase.Id, newID);
itemBase.Id = newID;
itemBase.Left += OffsetX;
itemBase.Top += OffsetY;
newItem = itemBase;
if (newItem != null)
{
items.Add(newItem);
}
}
DirectAddItemCommand.Execute(items);
OffsetX += 10;
OffsetY += 10;
List<SelectableDesignerItemViewModelBase> connectors = new List<SelectableDesignerItemViewModelBase>();
foreach (var connection in copyitem.Connections)
{
var connectionItem = JsonConvert.DeserializeObject<ConnectionItem>(connection.ObjectJson);
Guid newID = Guid.NewGuid();
mappingOldToNewIDs.Add(connectionItem.Id, newID);
connectionItem.SourceId = mappingOldToNewIDs[connectionItem.SourceId];
connectionItem.SinkId = mappingOldToNewIDs[connectionItem.SinkId];
connectionItem.SourceType = System.Type.GetType(connectionItem.SourceTypeName);
connectionItem.SinkType = System.Type.GetType(connectionItem.SinkTypeName);
DesignerItemViewModelBase sourceItem = GetConnectorDataItem(this, connectionItem.SourceId, connectionItem.SourceType);
ConnectorOrientation sourceConnectorOrientation = connectionItem.SourceOrientation;
FullyCreatedConnectorInfo sourceConnectorInfo = GetFullConnectorInfo(connectionItem.Id, sourceItem, sourceConnectorOrientation, connectionItem.SourceXRatio, connectionItem.SourceYRatio, connectionItem.SourceInnerPoint);
DesignerItemViewModelBase sinkItem = GetConnectorDataItem(this, connectionItem.SinkId, connectionItem.SinkType);
ConnectorOrientation sinkConnectorOrientation = connectionItem.SinkOrientation;
FullyCreatedConnectorInfo sinkConnectorInfo = GetFullConnectorInfo(connectionItem.Id, sinkItem, sinkConnectorOrientation, connectionItem.SinkXRatio, connectionItem.SinkYRatio, connectionItem.SinkInnerPoint);
ConnectorViewModel connectionVM = new ConnectorViewModel(this, sourceConnectorInfo, sinkConnectorInfo, connectionItem, connectionItem.VectorLineDrawMode);
connectors.Add(connectionVM);
DesignerItemViewModelBase textItem = items.OfType<DesignerItemViewModelBase>().FirstOrDefault(x => x.ParentId == connectionItem.Id);
if (textItem != null)
{
connectionVM.OutTextItem = textItem;
}
}
DirectAddItemCommand.Execute(connectors);
//修复父级的引用
foreach (var item in items)
{
if (item.ParentId != Guid.Empty)
{
if (mappingOldToNewIDs.ContainsKey(item.ParentId))
item.ParentId = mappingOldToNewIDs[item.ParentId];
}
}
}
catch (Exception e)
{
MessageBox.Show(e.StackTrace, e.Message, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
private DesignerItemViewModelBase GetConnectorDataItem(IDiagramViewModel diagramViewModel, Guid conectorDataItemId, Type connectorDataItemType)
{
DesignerItemViewModelBase dataItem = diagramViewModel.Items.OfType<DesignerItemViewModelBase>().Single(x => x.Id == conectorDataItemId);
return dataItem;
}
private FullyCreatedConnectorInfo GetFullConnectorInfo(Guid connectorId, DesignerItemViewModelBase dataItem, ConnectorOrientation connectorOrientation, double xRatio, double yRatio, bool isInnerPoint)
{
if (isInnerPoint)
{
return dataItem.Connectors.Where(p => p.XRatio == xRatio && p.YRatio == yRatio).FirstOrDefault();
}
else
{
switch (connectorOrientation)
{
case ConnectorOrientation.Top:
return dataItem.TopConnector;
case ConnectorOrientation.Left:
return dataItem.LeftConnector;
case ConnectorOrientation.Right:
return dataItem.RightConnector;
case ConnectorOrientation.Bottom:
return dataItem.BottomConnector;
default:
throw new InvalidOperationException(
string.Format("Found invalid persisted Connector Orientation for Connector Id: {0}", connectorId));
}
}
}
private bool ItemsToDeleteHasConnector(List<SelectableDesignerItemViewModelBase> itemsToRemove, ConnectorInfoBase connector)
{
if (connector is FullyCreatedConnectorInfo fully)
{
return itemsToRemove.Contains(fully.DataItem);
}
return false;
}
private void ExecuteCutCommand(object parameter)
{
ExecutePasteCommand(null);
OffsetX = 0;
OffsetY = 0;
ExecuteDeleteCommand(null);
}
private void ExecuteDeleteCommand(object parameter)
{
List<SelectableDesignerItemViewModelBase> itemsToRemove = SelectedItems.OfType<SelectableDesignerItemViewModelBase>().ToList();
List<SelectableDesignerItemViewModelBase> connectionsToAlsoRemove = new List<SelectableDesignerItemViewModelBase>();
foreach (var connector in Items.OfType<ConnectorViewModel>())
{
if (ItemsToDeleteHasConnector(itemsToRemove, connector.SourceConnectorInfo))
{
connectionsToAlsoRemove.Add(connector);
}
if (ItemsToDeleteHasConnector(itemsToRemove, connector.SinkConnectorInfo))
{
connectionsToAlsoRemove.Add(connector);
}
}
itemsToRemove.AddRange(connectionsToAlsoRemove);
RemoveItemCommand.Execute(itemsToRemove);
}
private void ExecuteLeftMoveCommand(object parameter)
{
foreach (var item in SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.Left -= 0.5;
}
}
private void ExecuteRightMoveCommand(object parameter)
{
foreach (var item in SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.Left += 0.5;
}
}
private void ExecuteUpMoveCommand(object parameter)
{
foreach (var item in SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.Top -= 0.5;
}
}
private void ExecuteDownMoveCommand(object parameter)
{
foreach (var item in SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.Top += 0.5;
}
}
private void ExecuteCenterMoveCommand(object parameter)
{
foreach (var item in SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.Left = (PageSize.Width - item.ItemWidth) / 2;
item.Top = (PageSize.Height - item.ItemHeight) / 2;
}
}
private void ExecuteSameSizeCommand(object parameter)
{
if (parameter is DesignerItemViewModelBase designerItem)
{
foreach (var item in SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.ItemWidth = designerItem.ItemWidth;
item.ItemHeight = designerItem.ItemHeight;
}
}
}
private void ExecuteSameWidthCommand(object parameter)
{
if (parameter is DesignerItemViewModelBase designerItem)
{
foreach (var item in SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.ItemWidth = designerItem.ItemWidth;
}
}
}
private void ExecuteSameHeightCommand(object parameter)
{
if (parameter is DesignerItemViewModelBase designerItem)
{
foreach (var item in SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.ItemHeight = designerItem.ItemHeight;
}
}
}
private void ExecuteSameAngleCommand(object parameter)
{
if (parameter is DesignerItemViewModelBase designerItem)
{
foreach (var item in SelectedItems.OfType<DesignerItemViewModelBase>())
{
item.Angle = designerItem.Angle;
}
}
}
private void ExecuteGroupCommand(object parameter)
{
var items = from item in SelectedItems.OfType<DesignerItemViewModelBase>()
where item.ParentId == Guid.Empty
select item;
Rect rect = GetBoundingRectangle(items);
GroupDesignerItemViewModel groupItem = new GroupDesignerItemViewModel();
groupItem.IsGroup = true;
groupItem.ItemWidth = rect.Width;
groupItem.ItemHeight = rect.Height;
groupItem.Left = rect.Left;
groupItem.Top = rect.Top;
groupItem.ZIndex = Items.Count;
DirectAddItemCommand.Execute(groupItem);
foreach (DesignerItemViewModelBase item in items)
item.ParentId = groupItem.Id;
ClearSelectedItemsCommand.Execute(null);
//groupItem.IsSelected = true;
SelectionService.AddToSelection(groupItem);
}
private void ExecuteUngroupCommand(object parameter)
{
var groups = (from item in SelectedItems.OfType<DesignerItemViewModelBase>()
where item.IsGroup && item.ParentId == Guid.Empty
select item).ToArray();
foreach (DesignerItemViewModelBase groupRoot in groups)
{
var children = from child in SelectedItems.OfType<DesignerItemViewModelBase>()
where child.ParentId == groupRoot.Id
select child;
foreach (DesignerItemViewModelBase child in children)
child.ParentId = Guid.Empty;
RemoveItemCommand.Execute(groupRoot);
UpdateZIndex();
}
}
private void ExecuteLockCommand(object parameter)
{
}
private void ExecuteUnlockCommand(object parameter)
{
}
public bool BelongToSameGroup(IGroupable item1, IGroupable item2)
{
IGroupable root1 = SelectionService.GetGroupRoot(item1);

View File

@@ -105,6 +105,75 @@ namespace AIStudio.Wpf.DiagramDesigner
{
get;
}
SimpleCommand CopyCommand
{
get;
}
SimpleCommand PasteCommand
{
get;
}
SimpleCommand CutCommand
{
get;
}
SimpleCommand DeleteCommand
{
get;
}
SimpleCommand LeftMoveCommand
{
get;
}
SimpleCommand RightMoveCommand
{
get;
}
SimpleCommand UpMoveCommand
{
get;
}
SimpleCommand DownMoveCommand
{
get;
}
SimpleCommand CenterMoveCommand
{
get;
}
SimpleCommand SameSizeCommand
{
get;
}
SimpleCommand SameWidthCommand
{
get;
}
SimpleCommand SameHeightCommand
{
get;
}
SimpleCommand SameAngleCommand
{
get;
}
SimpleCommand GroupCommand
{
get;
}
SimpleCommand UngroupCommand
{
get;
}
SimpleCommand LockCommand
{
get;
}
SimpleCommand UnlockCommand
{
get;
}
SimpleCommand UndoCommand
{
get;

View File

@@ -30,6 +30,20 @@ namespace AIStudio.Wpf.DiagramDesigner
}
public GifImageItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
public override SelectableDesignerItemBase ToXmlObject()
{
return new MediaDesignerItem(this);
}
public override Type ToXmlType()
{
return typeof(MediaDesignerItem);
}
protected override void Init()
{

View File

@@ -25,6 +25,21 @@ namespace AIStudio.Wpf.DiagramDesigner
}
public ImageItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
public override SelectableDesignerItemBase ToXmlObject()
{
return new ImageDesignerItem(this);
}
public override Type ToXmlType()
{
return typeof(ImageDesignerItem);
}
protected override void Init()
{
base.Init();

View File

@@ -19,6 +19,21 @@ namespace AIStudio.Wpf.DiagramDesigner
}
public MediaItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
public override SelectableDesignerItemBase ToXmlObject()
{
return new MediaDesignerItem(this);
}
public override Type ToXmlType()
{
return typeof(MediaDesignerItem);
}
protected override void Init()
{
base.Init();

View File

@@ -5,17 +5,27 @@ namespace AIStudio.Wpf.DiagramDesigner
{
public class TextDesignerItemViewModel : DesignerItemViewModelBase
{
public TextDesignerItemViewModel()
{
}
public TextDesignerItemViewModel(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
{
}
public TextDesignerItemViewModel()
public TextDesignerItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
public override SelectableDesignerItemBase ToXmlObject()
{
return new TextDesignerItem(this);
}
protected override void Init()
{
base.Init();

View File

@@ -16,6 +16,12 @@ namespace AIStudio.Wpf.DiagramDesigner
public VideoItemViewModel(IDiagramViewModel parent, MediaDesignerItem designer) : base(parent, designer)
{
}
}
public VideoItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
}

View File

@@ -19,6 +19,15 @@ namespace AIStudio.Wpf.DiagramHelper.Extensions.ViewModels
}
public BarcodeDesignerItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
public override SelectableDesignerItemBase ToXmlObject()
{
return new DesignerItemBase(this, Format.ToString());
}
protected override void Init()
{
base.Init();

View File

@@ -9,13 +9,17 @@ namespace AIStudio.Wpf.DiagramHelper.Extensions.ViewModels
public class OutLineTextDesignerItemViewModel : TextDesignerItemViewModel
{
private IUIVisualizerService visualiserService;
public OutLineTextDesignerItemViewModel() : base()
{
}
public OutLineTextDesignerItemViewModel(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
{
}
public OutLineTextDesignerItemViewModel() : base()
public OutLineTextDesignerItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}

View File

@@ -1,4 +1,6 @@
using AIStudio.Wpf.DiagramDesigner;
using System;
using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.DiagramHelper.Extensions.Models;
namespace AIStudio.Wpf.DiagramHelper.Extensions.ViewModels
{
@@ -9,11 +11,27 @@ namespace AIStudio.Wpf.DiagramHelper.Extensions.ViewModels
}
public PathItemViewModel(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
public PathItemViewModel(IDiagramViewModel parent, PathDesignerItem designer) : base(parent, designer)
{
}
public PathItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
public override SelectableDesignerItemBase ToXmlObject()
{
return new PathDesignerItem(this);
}
public override Type ToXmlType()
{
return typeof(PathDesignerItem);
}
protected override void Init()
{
base.Init();

View File

@@ -1,6 +1,7 @@
using AIStudio.Wpf.DiagramHelper.Services;
using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.DiagramHelper.Extensions.Models;
using System;
namespace AIStudio.Wpf.DiagramHelper.Extensions.ViewModels
{
@@ -8,16 +9,32 @@ namespace AIStudio.Wpf.DiagramHelper.Extensions.ViewModels
{
private IUIVisualizerService visualiserService;
public PersistDesignerItemViewModel() : base()
{
}
public PersistDesignerItemViewModel(IDiagramViewModel parent, PersistDesignerItem designer) : base(parent, designer)
{
}
public PersistDesignerItemViewModel() : base()
public PersistDesignerItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
public override SelectableDesignerItemBase ToXmlObject()
{
return new PersistDesignerItem(this);
}
public override Type ToXmlType()
{
return typeof(PersistDesignerItem);
}
protected override void Init()
{
base.Init();

View File

@@ -9,16 +9,31 @@ namespace AIStudio.Wpf.DiagramHelper.Extensions.ViewModels
{
private IUIVisualizerService visualiserService;
public SettingsDesignerItemViewModel() : base()
{
}
public SettingsDesignerItemViewModel(IDiagramViewModel parent, SettingsDesignerItem designer) : base(parent, designer)
{
}
public SettingsDesignerItemViewModel() : base()
public SettingsDesignerItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
public override SelectableDesignerItemBase ToXmlObject()
{
return new SettingsDesignerItem(this);
}
public override Type ToXmlType()
{
return typeof(SettingsDesignerItem);
}
protected override void Init()
{
base.Init();

View File

@@ -14,5 +14,10 @@ namespace AIStudio.Wpf.DiagramHelper.Extensions.ViewModels
{
}
public SvgDesignerItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
}

View File

@@ -1,10 +1,12 @@
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.Flowchart.Models;
@@ -246,5 +248,30 @@ namespace AIStudio.Wpf.Flowchart.Controls
}
#endregion
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
base.OnPreviewKeyDown(e);
bool executed = true;
var para = e.KeyboardDevice.Modifiers == ModifierKeys.None ? e.Key.ToString() : e.KeyboardDevice.Modifiers.ToString() + "+" + e.Key.ToString();
switch (para)
{
case "Control+A": _diagramViewModel.SelectAllCommand.Execute(null); break;
case "Control+C": _diagramViewModel.CopyCommand.Execute(null); break;
case "Control+V": _diagramViewModel.PasteCommand.Execute(null); break;
case "Control+X": _diagramViewModel.CutCommand.Execute(null); break;
case "Control+Z": _diagramViewModel.UndoCommand.Execute(null); break;
case "Control+Y": _diagramViewModel.RedoCommand.Execute(null); break;
case "Delete": _diagramViewModel.DeleteCommand.Execute(null); break;
case "Left": _diagramViewModel.LeftMoveCommand.Execute(null); break;
case "Right": _diagramViewModel.RightMoveCommand.Execute(null); break;
case "Up": _diagramViewModel.UpMoveCommand.Execute(null); break;
case "Down": _diagramViewModel.DownMoveCommand.Execute(null); break;
default: executed = false; break;
}
e.Handled = executed;
}
}
}

View File

@@ -49,7 +49,7 @@ namespace AIStudio.Wpf.Flowchart.Models
}
diagramNode.Id = nodeModel.Id.ToString();
if (nodeModel.ParentId != new Guid())
if (nodeModel.ParentId != Guid.Empty)
{
diagramNode.ParentId = nodeModel.ParentId.ToString();
}

View File

@@ -4,6 +4,7 @@ using AIStudio.Wpf.Flowchart.Models;
using System.Collections.Generic;
using System.ComponentModel;
using AIStudio.Wpf.DiagramDesigner;
using System;
namespace AIStudio.Wpf.Flowchart.ViewModels
{
@@ -22,6 +23,21 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
}
public FlowNode(IDiagramViewModel parent, string json) : base(parent, json)
{
}
public override SelectableDesignerItemBase ToXmlObject()
{
return new FlowNodeDesignerItem(this);
}
public override Type ToXmlType()
{
return typeof(FlowNodeDesignerItem);
}
protected override void Init()
{
base.Init();
@@ -121,6 +137,11 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
{
}
public StartFlowNode(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class EndFlowNode : FlowNode
@@ -134,6 +155,11 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
{
}
public EndFlowNode(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class DecideFlowNode : FlowNode
@@ -147,6 +173,11 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
{
}
public DecideFlowNode(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class COBeginFlowNode : FlowNode
@@ -160,6 +191,11 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
{
}
public COBeginFlowNode(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class COEndFlowNode : FlowNode
@@ -173,5 +209,10 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
{
}
public COEndFlowNode(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
}

View File

@@ -18,6 +18,11 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
}
public MiddleFlowNode(IDiagramViewModel parent, string json) : base(parent, json)
{
}
private List<string> _userIds = new List<string>();
[Browsable(true)]
[StyleName("UserIdsStyle")]

View File

@@ -21,6 +21,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
}
public LogicalGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
protected override void Init()
{
base.Init();
@@ -67,6 +72,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
public AddGateItemViewModel(IDiagramViewModel parent, LogicalGateDesignerItemBase designer) : base(parent, designer)
{
}
public AddGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class SubtractGateItemViewModel : LogicalGateItemViewModel
@@ -78,6 +88,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
public SubtractGateItemViewModel(IDiagramViewModel parent, LogicalGateDesignerItemBase designer) : base(parent, designer)
{
}
public SubtractGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class MultiplyGateItemViewModel : LogicalGateItemViewModel
@@ -89,6 +104,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
public MultiplyGateItemViewModel(IDiagramViewModel parent, LogicalGateDesignerItemBase designer) : base(parent, designer)
{
}
public MultiplyGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class DivideGateItemViewModel : LogicalGateItemViewModel
@@ -101,6 +121,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
public DivideGateItemViewModel(IDiagramViewModel parent, LogicalGateDesignerItemBase designer) : base(parent, designer)
{
}
public DivideGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class AverageGateItemViewModel : LogicalGateItemViewModel
@@ -114,6 +139,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public AverageGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class MODGateItemViewModel : LogicalGateItemViewModel
@@ -127,6 +157,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public MODGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class ANDGateItemViewModel : LogicalGateItemViewModel
@@ -140,6 +175,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public ANDGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class ORGateItemViewModel : LogicalGateItemViewModel
@@ -153,6 +193,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public ORGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class XORGateItemViewModel : LogicalGateItemViewModel
@@ -166,6 +211,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public XORGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class NOTGateItemViewModel : LogicalGateItemViewModel
@@ -179,6 +229,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public NOTGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class SHLGateItemViewModel : LogicalGateItemViewModel
@@ -192,6 +247,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public SHLGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class SHRGateItemViewModel : LogicalGateItemViewModel
@@ -205,6 +265,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public SHRGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class ROLGateItemViewModel : LogicalGateItemViewModel
@@ -218,6 +283,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public ROLGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class RORGateItemViewModel : LogicalGateItemViewModel
@@ -231,6 +301,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public RORGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class SELGateItemViewModel : LogicalGateItemViewModel
@@ -244,6 +319,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public SELGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class MAXGateItemViewModel : LogicalGateItemViewModel
@@ -257,6 +337,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public MAXGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class MINGateItemViewModel : LogicalGateItemViewModel
@@ -270,6 +355,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public MINGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class LIMITGateItemViewModel : LogicalGateItemViewModel
@@ -283,6 +373,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public LIMITGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class GTGateItemViewModel : LogicalGateItemViewModel
@@ -296,6 +391,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public GTGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class LTGateItemViewModel : LogicalGateItemViewModel
@@ -309,6 +409,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public LTGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class GEGateItemViewModel : LogicalGateItemViewModel
@@ -322,6 +427,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public GEGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class LEGateItemViewModel : LogicalGateItemViewModel
@@ -335,6 +445,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public LEGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class EQGateItemViewModel : LogicalGateItemViewModel
@@ -348,6 +463,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public EQGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class NEGateItemViewModel : LogicalGateItemViewModel
@@ -361,6 +481,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public NEGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class ABSGateItemViewModel : LogicalGateItemViewModel
@@ -374,6 +499,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public ABSGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class SQRTGateItemViewModel : LogicalGateItemViewModel
@@ -387,6 +517,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public SQRTGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class LNGateItemViewModel : LogicalGateItemViewModel
@@ -400,6 +535,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public LNGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class LOGGateItemViewModel : LogicalGateItemViewModel
@@ -413,6 +553,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public LOGGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class EXPGateItemViewModel : LogicalGateItemViewModel
@@ -426,6 +571,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public EXPGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class SINGateItemViewModel : LogicalGateItemViewModel
@@ -439,6 +589,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public SINGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class COSGateItemViewModel : LogicalGateItemViewModel
@@ -452,6 +607,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public COSGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class TANGateItemViewModel : LogicalGateItemViewModel
@@ -465,6 +625,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public TANGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class ASINGateItemViewModel : LogicalGateItemViewModel
@@ -478,6 +643,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public ASINGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class ACOSGateItemViewModel : LogicalGateItemViewModel
@@ -491,6 +661,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public ACOSGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class ATANGateItemViewModel : LogicalGateItemViewModel
@@ -504,6 +679,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public ATANGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class EXPTGateItemViewModel : LogicalGateItemViewModel
@@ -517,6 +697,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
{
}
public EXPTGateItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class ConstantDesignerItemViewModel : LogicalGateItemViewModel
@@ -531,6 +716,10 @@ namespace AIStudio.Wpf.Logical.ViewModels
}
public ConstantDesignerItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
public class InputItemViewModel : LogicalGateItemViewModel
@@ -545,6 +734,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
}
public InputItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
protected override void LoadDesignerItemViewModel(IDiagramViewModel parent, SelectableDesignerItemBase designerbase)
{
base.LoadDesignerItemViewModel(parent, designerbase);
@@ -594,6 +788,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
}
public OutputItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
protected override void LoadDesignerItemViewModel(IDiagramViewModel parent, SelectableDesignerItemBase designerbase)
{
base.LoadDesignerItemViewModel(parent, designerbase);
@@ -650,6 +849,11 @@ namespace AIStudio.Wpf.Logical.ViewModels
BuildMenuOptions();
}
public TimerDesignerItemViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
BuildMenuOptions();
}
protected override void Init()
{
MenuItemCommand = new SimpleCommand(ExecuteMenuItemCommand);

View File

@@ -21,6 +21,11 @@ namespace AIStudio.Wpf.SFC.ViewModels
}
public SFCActionNode(IDiagramViewModel parent, string json) : base(parent, json)
{
}
private LinkPoint _linkPoint;
public LinkPoint LinkPoint
{

View File

@@ -21,6 +21,11 @@ namespace AIStudio.Wpf.SFC.ViewModels
{
}
public SFCCOBeginNode(IDiagramViewModel parent, string json) : base(parent, json)
{
}
public override void ExecuteAddTopInput(object parameter)
{
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Top, true);

View File

@@ -21,6 +21,11 @@ namespace AIStudio.Wpf.SFC.ViewModels
{
}
public SFCCOEndNode(IDiagramViewModel parent, string json) : base(parent, json)
{
}
public override void ExecuteAddTopInput(object parameter)
{
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Top, true);

View File

@@ -24,6 +24,11 @@ namespace AIStudio.Wpf.SFC.ViewModels
{
}
public SFCConditionNode(IDiagramViewModel parent, string json) : base(parent, json)
{
}
protected override void Init()
{
base.Init();

View File

@@ -1,13 +1,12 @@
using AIStudio.Wpf.DiagramHelper;
using AIStudio.Wpf.DiagramHelper.Services;
using AIStudio.Wpf.SFC.Models;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Media;
using AIStudio.Wpf.DiagramDesigner;
using AIStudio.Wpf.DiagramHelper;
using AIStudio.Wpf.DiagramHelper.Services;
using AIStudio.Wpf.SFC.Models;
namespace AIStudio.Wpf.SFC.ViewModels
{
@@ -28,6 +27,21 @@ namespace AIStudio.Wpf.SFC.ViewModels
}
public SFCNode(IDiagramViewModel parent, string json) : base(parent, json)
{
}
public override SelectableDesignerItemBase ToXmlObject()
{
return new SFCNodeDesignerItem(this);
}
public override Type ToXmlType()
{
return typeof(SFCNodeDesignerItem);
}
protected override void Init()
{
IsInnerConnector = true;

View File

@@ -18,5 +18,10 @@ namespace AIStudio.Wpf.SFC.ViewModels
{
}
public SFCNodeNode(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
}

View File

@@ -16,5 +16,10 @@ namespace AIStudio.Wpf.SFC.ViewModels
public SFCStartNode(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
{
}
public SFCStartNode(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
}

View File

@@ -17,6 +17,11 @@ namespace AIStudio.Wpf.SFC.ViewModels
public Simulate_ListViewModel(IDiagramViewModel parent, DesignerItemBase designer) : base(parent, designer)
{
}
public Simulate_ListViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
}
}

View File

@@ -23,6 +23,11 @@ namespace AIStudio.Wpf.SFC.ViewModels
{
}
public Simulate_SolenoidViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
protected override void Init()
{
base.Init();

View File

@@ -20,6 +20,11 @@ namespace AIStudio.Wpf.SFC.ViewModels
{
}
public Simulate_StartViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
private LinkPoint linkPoint;
public LinkPoint LinkPoint
{

View File

@@ -23,6 +23,11 @@ namespace AIStudio.Wpf.SFC.ViewModels
{
}
public Simulate_TankViewModel(IDiagramViewModel parent, string json) : base(parent, json)
{
}
public override void ExecuteAddLeftInput(object parameter)
{
FullyCreatedConnectorInfo connector = new FullyCreatedConnectorInfo(this, ConnectorOrientation.Left, true);