mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
添加block快,不需要连接线,直接吸附。
This commit is contained in:
@@ -738,7 +738,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (this.Root is IDiagramViewModel)
|
||||
{
|
||||
var diagramVM = this.Root as IDiagramViewModel;
|
||||
diagramVM.RemoveItemCommand.Execute(this);
|
||||
diagramVM.DeleteCommand.Execute(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class BlockConnectorInfo : FullyCreatedConnectorInfo
|
||||
{
|
||||
public BlockConnectorInfo(DesignerItemViewModelBase dataItem, ConnectorOrientation orientation) : this(null, dataItem, orientation)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public BlockConnectorInfo(IDiagramViewModel root, DesignerItemViewModelBase dataItem, ConnectorOrientation orientation) : base(root, dataItem, orientation)
|
||||
{
|
||||
if (Orientation == ConnectorOrientation.Left || Orientation == ConnectorOrientation.Right)
|
||||
{
|
||||
ConnectorWidth = 4;
|
||||
ConnectorHeight = double.NaN;
|
||||
}
|
||||
else if (Orientation == ConnectorOrientation.Top || Orientation == ConnectorOrientation.Bottom)
|
||||
{
|
||||
ConnectorWidth = double.NaN;
|
||||
ConnectorHeight = 4;
|
||||
}
|
||||
}
|
||||
|
||||
public BlockConnectorInfo(IDiagramViewModel root, DesignerItemViewModelBase dataItem, SerializableItem serializableItem, string serializableType) : base(root, dataItem, serializableItem, serializableType)
|
||||
{
|
||||
}
|
||||
|
||||
public BlockConnectorInfo(IDiagramViewModel root, DesignerItemViewModelBase dataItem, SelectableItemBase designer) : base(root, dataItem, designer)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
base.InitNew();
|
||||
ColorViewModel.LineColor.Color = Colors.Transparent;
|
||||
ColorViewModel.FillColor.Color = Colors.Transparent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
return connectors?.FirstOrDefault();
|
||||
return Connectors?.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
return connectors?.FirstOrDefault(p => p.Orientation == ConnectorOrientation.Top);
|
||||
return Connectors?.FirstOrDefault(p => p.Orientation == ConnectorOrientation.Top);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
return connectors?.FirstOrDefault(p => p.Orientation == ConnectorOrientation.Bottom);
|
||||
return Connectors?.FirstOrDefault(p => p.Orientation == ConnectorOrientation.Bottom);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
return connectors?.FirstOrDefault(p => p.Orientation == ConnectorOrientation.Left);
|
||||
return Connectors?.FirstOrDefault(p => p.Orientation == ConnectorOrientation.Left);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
return connectors?.FirstOrDefault(p => p.Orientation == ConnectorOrientation.Right);
|
||||
return Connectors?.FirstOrDefault(p => p.Orientation == ConnectorOrientation.Right);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
return connectors?.FirstOrDefault(p => p.Orientation == ConnectorOrientation.TopLeft);
|
||||
return Connectors?.FirstOrDefault(p => p.Orientation == ConnectorOrientation.TopLeft);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
return connectors?.FirstOrDefault(p => p.Orientation == ConnectorOrientation.TopRight);
|
||||
return Connectors?.FirstOrDefault(p => p.Orientation == ConnectorOrientation.TopRight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
return connectors?.FirstOrDefault(p => p.Orientation == ConnectorOrientation.BottomLeft);
|
||||
return Connectors?.FirstOrDefault(p => p.Orientation == ConnectorOrientation.BottomLeft);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
return connectors?.FirstOrDefault(p => p.Orientation == ConnectorOrientation.BottomRight);
|
||||
return Connectors?.FirstOrDefault(p => p.Orientation == ConnectorOrientation.BottomRight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,7 +294,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
if (SetProperty(ref _showConnectors, value))
|
||||
{
|
||||
foreach (var connector in connectors)
|
||||
foreach (var connector in Connectors)
|
||||
{
|
||||
connector.ShowConnectors = value;
|
||||
}
|
||||
@@ -566,7 +566,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
|
||||
protected ObservableCollection<FullyCreatedConnectorInfo> connectors = new ObservableCollection<FullyCreatedConnectorInfo>();
|
||||
public IEnumerable<FullyCreatedConnectorInfo> Connectors
|
||||
public ObservableCollection<FullyCreatedConnectorInfo> Connectors
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -600,8 +600,8 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
return Observable
|
||||
.FromEventPattern<NotifyCollectionChangedEventHandler, NotifyCollectionChangedEventArgs>(
|
||||
h => this.connectors.CollectionChanged += h,
|
||||
h => this.connectors.CollectionChanged -= h)
|
||||
h => this.Connectors.CollectionChanged += h,
|
||||
h => this.Connectors.CollectionChanged -= h)
|
||||
.Select(x => x.EventArgs);
|
||||
}
|
||||
}
|
||||
@@ -611,24 +611,24 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
#region 方法
|
||||
public void AddConnector(FullyCreatedConnectorInfo connector)
|
||||
{
|
||||
if (!connectors.Contains(connector))
|
||||
if (!Connectors.Contains(connector))
|
||||
{
|
||||
connectors.Add(connector);
|
||||
Connectors.Add(connector);
|
||||
ConnectorMargin = 0 - connector.ConnectorWidth / 2;
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveConnector(FullyCreatedConnectorInfo connector)
|
||||
{
|
||||
if (connectors.Contains(connector))
|
||||
if (Connectors.Contains(connector))
|
||||
{
|
||||
connectors.Remove(connector);
|
||||
Connectors.Remove(connector);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ClearConnectors()
|
||||
{
|
||||
connectors.Clear();
|
||||
Connectors.Clear();
|
||||
}
|
||||
|
||||
public void SetCellAlignment()
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private bool _isEditName;
|
||||
[Browsable(false)]
|
||||
@@ -373,24 +373,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _addItemCommand;
|
||||
public ICommand AddItemCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._addItemCommand ?? (this._addItemCommand = new SimpleCommand(ExecuteEnable, ExecuteAddItemCommand));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _removeItemCommand;
|
||||
public ICommand RemoveItemCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._removeItemCommand ?? (this._removeItemCommand = new SimpleCommand(ExecuteEnable, ExecuteRemoveItemCommand));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _clearSelectedItemsCommand;
|
||||
public ICommand ClearSelectedItemsCommand
|
||||
{
|
||||
@@ -544,6 +526,24 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _addCommand;
|
||||
public ICommand AddCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._addCommand ?? (this._addCommand = new SimpleCommand(ExecuteEnable, ExecuteAddCommand));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _deleteCommand;
|
||||
public virtual ICommand DeleteCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._deleteCommand ?? (this._deleteCommand = new SimpleCommand(ExecuteEnable, ExecuteDeleteCommand));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _copyCommand;
|
||||
public ICommand CopyCommand
|
||||
{
|
||||
@@ -571,15 +571,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _deleteCommand;
|
||||
public virtual ICommand DeleteCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._deleteCommand ?? (this._deleteCommand = new SimpleCommand(ExecuteEnable, ExecuteDeleteCommand));
|
||||
}
|
||||
}
|
||||
|
||||
private ICommand _leftMoveCommand;
|
||||
public ICommand LeftMoveCommand
|
||||
{
|
||||
@@ -1004,143 +995,13 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
var items = this.Items.ToList();
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
this.Items.Clear();
|
||||
Delete(items);
|
||||
},
|
||||
() => {
|
||||
foreach (var item in items)
|
||||
{
|
||||
Add(item);
|
||||
}
|
||||
Add(items);
|
||||
});
|
||||
}
|
||||
|
||||
private void ExecuteAddItemCommand(object parameter)
|
||||
{
|
||||
List<SelectableDesignerItemViewModelBase> newitems = new List<SelectableDesignerItemViewModelBase>();
|
||||
if (parameter is SelectableDesignerItemViewModelBase ite)
|
||||
{
|
||||
newitems.Add(ite);
|
||||
}
|
||||
else if (parameter is IEnumerable<SelectableDesignerItemViewModelBase> items)
|
||||
{
|
||||
newitems.AddRange(items);
|
||||
}
|
||||
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
ClearSelectedItems();
|
||||
Add(newitems, true);
|
||||
},
|
||||
() => {
|
||||
foreach (var item in newitems)
|
||||
{
|
||||
Items.Remove(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public bool AddVerify(SelectableDesignerItemViewModelBase item)
|
||||
{
|
||||
if (item.Verify() == false)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//使用程序添加对象,比如Demo初始化
|
||||
public void Add(object parameter, bool? isSelected = false)
|
||||
{
|
||||
if (parameter is SelectableDesignerItemViewModelBase ite)
|
||||
{
|
||||
if (AddVerify(ite) != true) return;
|
||||
|
||||
Add(ite, isSelected);
|
||||
}
|
||||
else if (parameter is IEnumerable<SelectableDesignerItemViewModelBase> items)
|
||||
{
|
||||
if (items.Select(p => AddVerify(p)).Any() != true) return;
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
Add(item, isSelected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Add(SelectableDesignerItemViewModelBase item, bool? isSelected = true)
|
||||
{
|
||||
item.Root = this;
|
||||
item.ZIndex = Items.Any() ? Items.Max(p => p.ZIndex) + 1 : 0;
|
||||
if (item.Id == Guid.Empty)
|
||||
{
|
||||
item.Id = Guid.NewGuid();
|
||||
}
|
||||
|
||||
var logical = item as LogicalGateItemViewModelBase;
|
||||
if (logical != null)
|
||||
{
|
||||
logical.OrderNumber = Items.OfType<LogicalGateItemViewModelBase>().Count() + 1;
|
||||
}
|
||||
|
||||
var designerItemViewModelBase = item as DesignerItemViewModelBase;
|
||||
if (designerItemViewModelBase != null)
|
||||
{
|
||||
designerItemViewModelBase.SetCellAlignment();
|
||||
}
|
||||
Items.Add(item);
|
||||
if (isSelected != null)
|
||||
{
|
||||
item.IsSelected = isSelected.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(object parameter)
|
||||
{
|
||||
if (parameter is SelectableDesignerItemViewModelBase ite)
|
||||
{
|
||||
ite.IsSelected = false;
|
||||
ite.Dispose();
|
||||
Items.Remove(ite);
|
||||
}
|
||||
else if (parameter is IEnumerable<SelectableDesignerItemViewModelBase> items)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
item.IsSelected = false;
|
||||
item.Dispose();
|
||||
Items.Remove(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteRemoveItemCommand(object parameter)
|
||||
{
|
||||
List<SelectableDesignerItemViewModelBase> olditems = new List<SelectableDesignerItemViewModelBase>();
|
||||
if (parameter is SelectableDesignerItemViewModelBase node)
|
||||
{
|
||||
olditems.Add(node);
|
||||
}
|
||||
else if (parameter is IEnumerable<SelectableDesignerItemViewModelBase> para)
|
||||
{
|
||||
olditems.AddRange(para);
|
||||
}
|
||||
else
|
||||
{
|
||||
olditems.AddRange(SelectedItems);
|
||||
}
|
||||
|
||||
if (olditems.Any())
|
||||
{
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
Remove(olditems);
|
||||
},
|
||||
() => {
|
||||
Add(olditems);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteClearSelectedItemsCommand(object parameter)
|
||||
{
|
||||
List<SelectableDesignerItemViewModelBase> selectedItems = new List<SelectableDesignerItemViewModelBase>();
|
||||
@@ -1187,7 +1048,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public virtual void ExecuteNextCommand(object parameter)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void ExecuteSelectAllCommand(object parameter)
|
||||
@@ -1284,7 +1145,84 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 复制,粘贴
|
||||
#region 新增,删除 复制,粘贴
|
||||
private void ExecuteAddCommand(object parameter)
|
||||
{
|
||||
List<SelectableDesignerItemViewModelBase> newitems = new List<SelectableDesignerItemViewModelBase>();
|
||||
if (parameter is SelectableDesignerItemViewModelBase ite)
|
||||
{
|
||||
newitems.Add(ite);
|
||||
}
|
||||
else if (parameter is IEnumerable<SelectableDesignerItemViewModelBase> items)
|
||||
{
|
||||
newitems.AddRange(items);
|
||||
}
|
||||
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
ClearSelectedItems();
|
||||
Add(newitems, true);
|
||||
},
|
||||
() => {
|
||||
Delete(newitems);
|
||||
});
|
||||
}
|
||||
|
||||
public bool AddVerify(SelectableDesignerItemViewModelBase item)
|
||||
{
|
||||
if (item.Verify() == false)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//使用程序添加对象,比如Demo初始化
|
||||
public void Add(object parameter, bool? isSelected = false)
|
||||
{
|
||||
if (parameter is SelectableDesignerItemViewModelBase ite)
|
||||
{
|
||||
if (AddVerify(ite) != true) return;
|
||||
|
||||
Add(ite, isSelected);
|
||||
}
|
||||
else if (parameter is IEnumerable<SelectableDesignerItemViewModelBase> items)
|
||||
{
|
||||
if (items.Select(p => AddVerify(p)).Any() != true) return;
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
Add(item, isSelected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Add(SelectableDesignerItemViewModelBase item, bool? isSelected = true)
|
||||
{
|
||||
item.Root = this;
|
||||
item.ZIndex = Items.Any() ? Items.Max(p => p.ZIndex) + 1 : 0;
|
||||
if (item.Id == Guid.Empty)
|
||||
{
|
||||
item.Id = Guid.NewGuid();
|
||||
}
|
||||
|
||||
var logical = item as LogicalGateItemViewModelBase;
|
||||
if (logical != null)
|
||||
{
|
||||
logical.OrderNumber = Items.OfType<LogicalGateItemViewModelBase>().Count() + 1;
|
||||
}
|
||||
|
||||
var designerItemViewModelBase = item as DesignerItemViewModelBase;
|
||||
if (designerItemViewModelBase != null)
|
||||
{
|
||||
designerItemViewModelBase.SetCellAlignment();
|
||||
}
|
||||
Items.Add(item);
|
||||
if (isSelected != null)
|
||||
{
|
||||
item.IsSelected = isSelected.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteCopyCommand(object parameter)
|
||||
{
|
||||
Copy(parameter);
|
||||
@@ -1436,10 +1374,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
FixOtherInfo(items);
|
||||
},
|
||||
() => {
|
||||
foreach (var item in items)
|
||||
{
|
||||
Items.Remove(item);
|
||||
}
|
||||
Delete(items);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1484,16 +1419,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
foreach (var item in items)
|
||||
{
|
||||
Items.Remove(item);
|
||||
}
|
||||
Delete(items);
|
||||
},
|
||||
() => {
|
||||
foreach (var item in items)
|
||||
{
|
||||
Items.Add(item);
|
||||
}
|
||||
Add(items);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1508,21 +1437,20 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
foreach (var item in items)
|
||||
{
|
||||
Items.Remove(item);
|
||||
}
|
||||
Delete(items);
|
||||
},
|
||||
() => {
|
||||
foreach (var item in items)
|
||||
{
|
||||
Items.Add(item);
|
||||
}
|
||||
Add(items);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual List<SelectableDesignerItemViewModelBase> Delete(object parameter, bool delete = true)
|
||||
public void Delete(object parameter)
|
||||
{
|
||||
Delete(parameter, true, true);
|
||||
}
|
||||
|
||||
protected virtual List<SelectableDesignerItemViewModelBase> Delete(object parameter, bool delete = true, bool direct = false)
|
||||
{
|
||||
List<SelectableDesignerItemViewModelBase> itemsToRemove = new List<SelectableDesignerItemViewModelBase>();
|
||||
if (parameter is SelectableDesignerItemViewModelBase node)
|
||||
@@ -1538,22 +1466,25 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
itemsToRemove.AddRange(SelectedItems);
|
||||
}
|
||||
|
||||
List<SelectableDesignerItemViewModelBase> connectionsToAlsoRemove = new List<SelectableDesignerItemViewModelBase>();
|
||||
|
||||
foreach (var connector in Items.OfType<ConnectionViewModel>())
|
||||
if (direct == false)
|
||||
{
|
||||
if (ItemsToDeleteHasConnector(itemsToRemove, connector.SourceConnectorInfo))
|
||||
{
|
||||
connectionsToAlsoRemove.Add(connector);
|
||||
}
|
||||
List<SelectableDesignerItemViewModelBase> connectionsToAlsoRemove = new List<SelectableDesignerItemViewModelBase>();
|
||||
|
||||
if (ItemsToDeleteHasConnector(itemsToRemove, connector.SinkConnectorInfo))
|
||||
foreach (var connector in Items.OfType<ConnectionViewModel>())
|
||||
{
|
||||
connectionsToAlsoRemove.Add(connector);
|
||||
}
|
||||
if (ItemsToDeleteHasConnector(itemsToRemove, connector.SourceConnectorInfo))
|
||||
{
|
||||
connectionsToAlsoRemove.Add(connector);
|
||||
}
|
||||
|
||||
if (ItemsToDeleteHasConnector(itemsToRemove, connector.SinkConnectorInfo))
|
||||
{
|
||||
connectionsToAlsoRemove.Add(connector);
|
||||
}
|
||||
|
||||
}
|
||||
itemsToRemove.AddRange(connectionsToAlsoRemove);
|
||||
}
|
||||
itemsToRemove.AddRange(connectionsToAlsoRemove);
|
||||
|
||||
if (itemsToRemove.Any())
|
||||
{
|
||||
@@ -1561,6 +1492,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
foreach (var item in itemsToRemove)
|
||||
{
|
||||
item.Dispose();
|
||||
Items.Remove(item);
|
||||
}
|
||||
}
|
||||
@@ -2501,7 +2433,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
groupItem.AddToSelection(true, true);
|
||||
},
|
||||
() => {
|
||||
Remove(groupItem);
|
||||
Delete(groupItem);
|
||||
foreach (DesignerItemViewModelBase item in items)
|
||||
{
|
||||
item.IsSelected = true;
|
||||
@@ -2533,10 +2465,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
DoCommandManager.DoNewCommand(this.ToString(),
|
||||
() => {
|
||||
foreach (DesignerItemViewModelBase groupRoot in groups)
|
||||
{
|
||||
Remove(groupRoot);
|
||||
}
|
||||
Delete(groups);
|
||||
foreach (var item in items)
|
||||
{
|
||||
item.Key.ParentId = Guid.Empty;
|
||||
@@ -2544,10 +2473,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
UpdateZIndex();
|
||||
},
|
||||
() => {
|
||||
foreach (DesignerItemViewModelBase groupRoot in groups)
|
||||
{
|
||||
Add(groupRoot);
|
||||
}
|
||||
Add(groups);
|
||||
foreach (var item in items)
|
||||
{
|
||||
item.Key.ParentId = item.Value.Item1;
|
||||
@@ -3105,13 +3031,101 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
port.DisableAttachTo = true;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// type=0最近且没有依附;=1
|
||||
/// </summary>
|
||||
/// <param name="blockDesignerItemViewModel"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo> FindNearPortToAttachTo(BlockDesignerItemViewModel blockDesignerItemViewModel, bool isExist)
|
||||
{
|
||||
if (blockDesignerItemViewModel == null)
|
||||
return new Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo>(null, null);
|
||||
|
||||
List<BlockDesignerItemViewModel> items;
|
||||
if (isExist == false)
|
||||
{
|
||||
items = Items.OfType<BlockDesignerItemViewModel>().
|
||||
Where(p => p != blockDesignerItemViewModel && p != blockDesignerItemViewModel.Parent && p != blockDesignerItemViewModel.Next)
|
||||
.ToList();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
items = Items.OfType<BlockDesignerItemViewModel>().
|
||||
Where(p => p != blockDesignerItemViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
FullyCreatedConnectorInfo parent = null;
|
||||
FullyCreatedConnectorInfo next = null;
|
||||
|
||||
foreach (var port in items.SelectMany(n => n.Connectors))
|
||||
{
|
||||
foreach (var port2 in blockDesignerItemViewModel.Connectors)
|
||||
{
|
||||
//parent
|
||||
if (parent == null)
|
||||
{
|
||||
if ((port.Orientation == ConnectorOrientation.Right && port2.Orientation == ConnectorOrientation.Left)
|
||||
|| (port.Orientation == ConnectorOrientation.Bottom && port2.Orientation == ConnectorOrientation.Top))
|
||||
{
|
||||
|
||||
if (port.Position.DistanceTo(port2.Position) < DiagramOption.SnappingOption.SnappingRadius)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port2.CanAttachTo(port) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
parent = port;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DisableAttachTo = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//next
|
||||
if (next == null)
|
||||
{
|
||||
if ((port.Orientation == ConnectorOrientation.Left && port2.Orientation == ConnectorOrientation.Right)
|
||||
|| (port.Orientation == ConnectorOrientation.Top && port2.Orientation == ConnectorOrientation.Bottom))
|
||||
{
|
||||
|
||||
if (port.Position.DistanceTo(port2.Position) < DiagramOption.SnappingOption.SnappingRadius)
|
||||
{
|
||||
port.DataItem.ShowConnectors = true;
|
||||
if (port2.CanAttachTo(port) == true)
|
||||
{
|
||||
port.BeAttachTo = true;
|
||||
next = port;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
port.DisableAttachTo = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo>(parent, next);
|
||||
}
|
||||
|
||||
public void ClearNearPort()
|
||||
{
|
||||
Items.OfType<DesignerItemViewModelBase>().ToList().SelectMany(n => n.Connectors).Where(p => p.BeAttachTo == true || p.DisableAttachTo == true).ToList()
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class BlockDesignerItemViewModel : DesignerItemViewModelBase
|
||||
{
|
||||
public BlockDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public BlockDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public BlockDesignerItemViewModel(IDiagramViewModel root, SelectableItemBase designer) : base(root, designer)
|
||||
{
|
||||
}
|
||||
|
||||
public BlockDesignerItemViewModel(IDiagramViewModel root, SerializableItem serializableItem, string serializableType) : base(root, serializableItem, serializableType)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
AddConnector(new BlockConnectorInfo(this.Root, this, ConnectorOrientation.Top));
|
||||
AddConnector(new BlockConnectorInfo(this.Root, this, ConnectorOrientation.Bottom));
|
||||
}
|
||||
|
||||
public BlockDesignerItemViewModel Next
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
|
||||
public void AddNext(BlockDesignerItemViewModel next)
|
||||
{
|
||||
next.Left = this.Left;
|
||||
next.Top = this.Top + this.ItemHeight;
|
||||
next.ParentId = this.Id;
|
||||
next.Parent = this;
|
||||
this.Next = next;
|
||||
if (next.Next != null)
|
||||
{
|
||||
next.AddNext(next.Next);
|
||||
}
|
||||
}
|
||||
|
||||
public override void AddToSelection(bool selected, bool clearother)
|
||||
{
|
||||
if (clearother)
|
||||
{
|
||||
foreach (SelectableDesignerItemViewModelBase item in Root.SelectedItems.ToList())
|
||||
{
|
||||
if (item != this)
|
||||
{
|
||||
item.RemoveFromSelection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IsSelected = selected;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
//propertyChangedSubscription = WhenPropertyChanged.Where(o => o.ToString() == "Left" || o.ToString() == "Top" || o.ToString() == "ItemWidth" || o.ToString() == "ItemHeight").Subscribe(ChangeImageElement);
|
||||
//connectorsChangedSubscription = WhenConnectorsChanged.Subscribe(OnConnectorsChanged);
|
||||
|
||||
AddItemCommand = new SimpleCommand(Command_Enable, ExecuteAddItemCommand);
|
||||
AddCommand = new SimpleCommand(Command_Enable, ExecuteAddItemCommand);
|
||||
ImageSwitchCommand = new SimpleCommand(Command_Enable, ExecuteImageSwitchCommand);
|
||||
BuildMenuOptions();
|
||||
}
|
||||
@@ -82,7 +82,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand AddItemCommand
|
||||
public ICommand AddCommand
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
@@ -143,7 +143,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if (args.Action == NotifyCollectionChangedAction.Remove)
|
||||
// else if (args.Action == NotifyCollectionChangedAction.Delete)
|
||||
// {
|
||||
// if (args.OldItems.Count > 0)
|
||||
// {
|
||||
|
||||
@@ -72,7 +72,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
base.InitNew();
|
||||
ExecuteAddInput(null);
|
||||
ExecuteAddInput(null);
|
||||
ExecuteAddOutput(null);
|
||||
}
|
||||
|
||||
private void BuildMenuOptions()
|
||||
@@ -182,7 +184,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public override void ClearConnectors()
|
||||
{
|
||||
connectors.Clear();
|
||||
Connectors.Clear();
|
||||
Input.Clear();
|
||||
Output.Clear();
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
protected override void ClearText()
|
||||
{
|
||||
Root.RemoveItemCommand.Execute(this);
|
||||
Root.DeleteCommand.Execute(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
foreach (var g in deleteDrawGeometries)
|
||||
{
|
||||
this.Root.Remove(g);
|
||||
this.Root.Delete(g);
|
||||
}
|
||||
|
||||
return empty;
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
foreach (var g in deleteDrawGeometries)
|
||||
{
|
||||
this.Root.Remove(g);
|
||||
this.Root.Delete(g);
|
||||
}
|
||||
|
||||
return empty;
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
if (e.PropertyName == nameof(IsEditing) && _previewTextDesign.IsEditing == false)
|
||||
{
|
||||
_previewTextDesign.PropertyChanged -= _previewTextDesign_PropertyChanged;
|
||||
Root?.Remove(_previewTextDesign);
|
||||
Root?.Delete(_previewTextDesign);
|
||||
|
||||
Text = _previewTextDesign?.Text;
|
||||
if (!string.IsNullOrEmpty(Text))
|
||||
@@ -118,7 +118,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
this.ItemHeight = _previewTextDesign.ItemHeight;
|
||||
this.Left = _previewTextDesign.Left + 2 + Geometry.Bounds.Left;
|
||||
this.Top = _previewTextDesign.Top + 2 + Geometry.Bounds.Top;
|
||||
this.Root?.AddItemCommand.Execute(this);
|
||||
this.Root?.AddCommand.Execute(this);
|
||||
IsLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,14 +36,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get;
|
||||
}
|
||||
ICommand AddItemCommand
|
||||
{
|
||||
get;
|
||||
}
|
||||
ICommand RemoveItemCommand
|
||||
{
|
||||
get;
|
||||
}
|
||||
ICommand ClearSelectedItemsCommand
|
||||
{
|
||||
get;
|
||||
@@ -113,6 +105,14 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get;
|
||||
}
|
||||
ICommand AddCommand
|
||||
{
|
||||
get;
|
||||
}
|
||||
ICommand DeleteCommand
|
||||
{
|
||||
get;
|
||||
}
|
||||
ICommand CopyCommand
|
||||
{
|
||||
get;
|
||||
@@ -125,10 +125,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get;
|
||||
}
|
||||
ICommand DeleteCommand
|
||||
{
|
||||
get;
|
||||
}
|
||||
ICommand LeftMoveCommand
|
||||
{
|
||||
get;
|
||||
@@ -340,7 +336,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
void Add(object parameter, bool? isSelected = false);
|
||||
|
||||
void Remove(object parameter);
|
||||
void Delete(object parameter);
|
||||
|
||||
void ClearSelectedItems();
|
||||
|
||||
@@ -366,6 +362,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
#region 公共方法
|
||||
FullyCreatedConnectorInfo FindNearPortToAttachTo(ConnectionViewModel partialConnection, ConnectorVertexType connectorVertexType);
|
||||
FullyCreatedConnectorInfo FindNearPortToAttachTo(ConnectionViewModel partialConnection);
|
||||
Tuple<FullyCreatedConnectorInfo, FullyCreatedConnectorInfo> FindNearPortToAttachTo(BlockDesignerItemViewModel blockDesignerItemViewModel, bool isExist);
|
||||
void ClearNearPort();
|
||||
#endregion
|
||||
event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
Reference in New Issue
Block a user