Skip to content

Commit ff3a1df

Browse files
committed
for delete nodes and connects
1 parent c7f67ce commit ff3a1df

File tree

9 files changed

+305
-106
lines changed

9 files changed

+305
-106
lines changed

SimpleStateMachineNodeEditor/Helpers/Commands/Command.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public class Command<TParameter, TResult> : CommandUndoRedo, ICommand, ICloneabl
2525

2626
/// <summary>
2727
/// Результат выполнения команды
28-
/// </summary>
2928
/// Например здесь может храниться список объектов, которые были изменены
3029
public TResult Result { get; set; }
30+
/// </summary>
3131

3232
/// <summary>
3333
/// Флаг того, является ли команда отменяемой
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace SimpleStateMachineNodeEditor.Helpers.Enums
6+
{
7+
public enum DeleteMode
8+
{
9+
noCorrect = 0,
10+
DeleteNodes,
11+
DeleteConnects,
12+
DeleteAllSelected
13+
}
14+
}

SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void ExportToImage(ImageFormats format)
178178
}
179179
void New()
180180
{
181-
this.NodesCanvas.ViewModel.CommandNew.Execute();
181+
this.NodesCanvas.ViewModel.CommandNewScheme.Execute();
182182
}
183183
void WithoutSaving(Action action)
184184
{

SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
<KeyBinding x:Name="BindingSave" Key="S" Modifiers="Control" />
111111
<KeyBinding x:Name="BindingSelectAll" Key="A" Modifiers="Control" />
112112
<KeyBinding x:Name="BindingAddNode" Key="N" Modifiers="Control" />
113-
<KeyBinding x:Name="BindingDeleteNode" Key="Delete" />
113+
<KeyBinding x:Name="BindingDeleteSelectedElements" Key="Delete" />
114114
<MouseBinding x:Name="BindingSelect" Gesture="Ctrl+LeftClick"/>
115115
<MouseBinding x:Name="BindingCut" Gesture="Alt+LeftClick" />
116116
<MouseBinding x:Name="BindingZoom" Gesture="WheelClick"/>

SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ private void SetupBinding()
8080

8181
this.OneWayBind(this.ViewModel, x => x.Scale.Scales.Value.X, x => x.Scale.ScaleX).DisposeWith(disposable);
8282

83-
//Масштаб по оси Y
8483
this.OneWayBind(this.ViewModel, x => x.Scale.Scales.Value.Y, x => x.Scale.ScaleY).DisposeWith(disposable);
8584

8685
this.OneWayBind(this.ViewModel, x => x.Selector, x => x.Selector.ViewModel).DisposeWith(disposable);
@@ -101,11 +100,17 @@ private void SetupCommands()
101100
this.BindCommand(this.ViewModel, x => x.CommandRedo, x => x.BindingRedo).DisposeWith(disposable);
102101
this.BindCommand(this.ViewModel, x => x.CommandUndo, x => x.BindingUndo).DisposeWith(disposable);
103102
this.BindCommand(this.ViewModel, x => x.CommandSelectAll, x => x.BindingSelectAll).DisposeWith(disposable);
104-
this.BindCommand(this.ViewModel, x => x.CommandDeleteSelectedNodes, x => x.BindingDeleteNode).DisposeWith(disposable);
103+
104+
105+
this.BindCommand(this.ViewModel, x => x.CommandDeleteSelectedElements, x => x.BindingDeleteSelectedElements).DisposeWith(disposable);
106+
107+
//this.BindCommand(this.ViewModel, x => x.CommandDeleteSelectedNodes, x => x.BindingDeleteSelected).DisposeWith(disposable);
108+
//this.BindCommand(this.ViewModel, x => x.CommandDeleteSelectedConnectors, x => x.BindingDeleteSelected).DisposeWith(disposable);
109+
105110
this.BindCommand(this.ViewModel, x => x.CommandSelect, x => x.BindingSelect, positionLeftClickObservable).DisposeWith(disposable);
106111
this.BindCommand(this.ViewModel, x => x.CommandCut, x => x.BindingCut, positionLeftClickObservable).DisposeWith(disposable);
107-
this.BindCommand(this.ViewModel, x => x.CommandAddNode, x => x.BindingAddNode, positionLeftClickObservable).DisposeWith(disposable);
108-
this.BindCommand(this.ViewModel, x => x.CommandAddNode, x => x.ItemAddNode, positionRightClickObservable).DisposeWith(disposable);
112+
this.BindCommand(this.ViewModel, x => x.CommandAddNodeWithUndoRedo, x => x.BindingAddNode, positionLeftClickObservable).DisposeWith(disposable);
113+
this.BindCommand(this.ViewModel, x => x.CommandAddNodeWithUndoRedo, x => x.ItemAddNode, positionRightClickObservable).DisposeWith(disposable);
109114

110115
this.WhenAnyValue(x => x.ViewModel.Selector.Size).InvokeCommand(ViewModel.CommandSelectorIntersect).DisposeWith(disposable);
111116
this.WhenAnyValue(x => x.ViewModel.Cutter.EndPoint.Value).InvokeCommand(ViewModel.CommandCutterIntersect).DisposeWith(disposable);

SimpleStateMachineNodeEditor/ViewModel/ViewModelConnect.cs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using SimpleStateMachineNodeEditor.Helpers.Enums;
1212
using System.Xml.Linq;
1313
using SimpleStateMachineNodeEditor.Helpers.Extensions;
14+
using SimpleStateMachineNodeEditor.Helpers.Commands;
1415

1516
namespace SimpleStateMachineNodeEditor.ViewModel
1617
{
@@ -41,31 +42,23 @@ public class ViewModelConnect : ReactiveObject
4142
/// </summary>
4243
[Reactive] public Brush Stroke { get; set; } = Application.Current.Resources["ColorConnect"] as SolidColorBrush;
4344

44-
///// <summary>
45-
///// Флаг того, что соединение выбрано
46-
///// </summary>
47-
//[Reactive] public bool Selected { get; set; } = true;
48-
49-
/// <summary>
50-
/// Элемент, из которого выходит линия
51-
/// </summary>
5245
[Reactive] public ViewModelConnector FromConnector { get; set; }
5346

54-
/// <summary>
55-
/// Элемент, в который приходит линия
56-
/// </summary>
5747
[Reactive] public ViewModelConnector ToConnector { get; set; }
5848

49+
[Reactive] public ViewModelNodesCanvas NodesCanvas { get; set; }
50+
5951
[Reactive] public DoubleCollection StrokeDashArray { get; set; }
6052

6153
[Reactive] public double StrokeThickness { get; set; } = 1;
6254

63-
public ViewModelConnect(ViewModelConnector fromConnector)
55+
public ViewModelConnect(ViewModelNodesCanvas viewModelNodesCanvas, ViewModelConnector fromConnector)
6456
{
6557

6658
SetupSubscriptions();
6759
SetupCommands();
6860

61+
NodesCanvas = viewModelNodesCanvas;
6962
FromConnector = fromConnector;
7063
FromConnector.Connect = this;
7164
//SetupCommands();
@@ -118,11 +111,37 @@ private void UpdateMedium()
118111

119112
#region Setup Commands
120113

114+
//public SimpleCommand CommandDelete { get; set; }
115+
//public SimpleCommand CommandAdd { get; set; }
116+
//public SimpleCommand CommandDeleteWithConnector { get; set; }
117+
//public SimpleCommand CommandAddWithConnector { get; set; }
121118
private void SetupCommands()
122119
{
123-
120+
//CommandAdd = new SimpleCommand(Add, NotSaved);
121+
//CommandDelete = new SimpleCommand(Delete, NotSaved);
122+
//CommandAddWithConnector = new SimpleCommand(AddWithConnect, NotSaved);
123+
//CommandDeleteWithConnector = new SimpleCommand(DeleteWithConnects, NotSaved);
124124
}
125-
125+
private void NotSaved()
126+
{
127+
NodesCanvas.ItSaved = false;
128+
}
129+
//private void Add()
130+
//{
131+
// NodesCanvas.CommandAddConnect.Execute(this);
132+
//}
133+
//private void Delete()
134+
//{
135+
// NodesCanvas.CommandDeleteConnect.Execute(this);
136+
//}
137+
//private void AddWithConnect()
138+
//{
139+
// this.FromConnector.CommandAddWithConnect.Execute();
140+
//}
141+
//private void DeleteWithConnects()
142+
//{
143+
// this.FromConnector.CommandDeleteWithConnect.Execute();
144+
//}
126145
#endregion Setup Commands
127146

128147
}

SimpleStateMachineNodeEditor/ViewModel/ViewModelConnector.cs

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ private void SetupBinding()
9494
public SimpleCommand CommandConnectorDragEnter { get; set; }
9595
public SimpleCommand CommandConnectorDrop { get; set; }
9696
public SimpleCommand CommandSetAsLoop { get; set; }
97-
public SimpleCommand CommandAdd { get; set; }
98-
public SimpleCommand CommandDelete { get; set; }
97+
//public SimpleCommand CommandAdd { get; set; }
98+
//public SimpleCommand CommandDelete { get; set; }
99+
//public SimpleCommand CommandAddWithConnect { get; set; }
100+
//public SimpleCommand CommandDeleteWithConnect { get; set; }
99101
public SimpleCommandWithParameter<SelectMode> CommandSelect { get; set; }
100102
public SimpleCommandWithParameter<string> CommandValidateName { get; set; }
101103

@@ -111,8 +113,11 @@ private void SetupCommands()
111113
CommandConnectorDragEnter = new SimpleCommand(ConnectorDragEnter);
112114
CommandConnectorDrop = new SimpleCommand(ConnectorDrop);
113115

114-
CommandAdd = new SimpleCommand(Add);
115-
CommandDelete = new SimpleCommand(Delete);
116+
//CommandAdd = new SimpleCommand(Add);
117+
//CommandDelete = new SimpleCommand(Delete);
118+
//CommandAddWithConnect = new SimpleCommand(AddWithConnect);
119+
//CommandDeleteWithConnect = new SimpleCommand(DeleteWithConnect);
120+
116121
CommandValidateName = new SimpleCommandWithParameter<string>(ValidateName, NotSaved);
117122

118123
CommandSelect = new SimpleCommandWithParameter<SelectMode>(Select);
@@ -170,59 +175,67 @@ private void SetAsLoop()
170175

171176
Node.CommandAddEmptyConnector.Execute();
172177
}
173-
private void Add()
174-
{
175-
176-
Node.CommandAddConnector.Execute(this);
177-
}
178-
private void Delete()
179-
{
180-
Node.CommandDeleteConnector.Execute(this);
181-
}
178+
//private void Add()
179+
//{
180+
// Node.CommandAddConnector.Execute((0, this));
181+
//}
182+
//private void Delete()
183+
//{
184+
// Node.CommandDeleteConnector.Execute(this);
185+
//}
186+
//private void AddWithConnect()
187+
//{
188+
// this.Add();
189+
// this.Connect?.CommandAdd.Execute();
190+
//}
191+
//private void DeleteWithConnect()
192+
//{
193+
// this.Delete();
194+
// this.Connect?.CommandDelete.Execute();
195+
//}
182196
private void ConnectPointDrag()
183197
{
184-
Node.NodesCanvas.CommandAddFreeConnect.Execute(Node.CurrentConnector);
198+
NodesCanvas.CommandAddDraggedConnect.Execute(Node.CurrentConnector);
185199
}
186200
private void DragConnector(ViewModelConnector draggedConnector)
187201
{
188202

189203
}
190204

191205
private void ConnectPointDrop()
192-
{
193-
194-
if (Node.NodesCanvas.DraggedConnect.FromConnector.Node != this.Node)
206+
{
207+
if (NodesCanvas.DraggedConnect.FromConnector.Node != this.Node)
195208
{
196-
var connect = Node.NodesCanvas.DraggedConnect;
209+
var connect = NodesCanvas.DraggedConnect;
197210
connect.ToConnector = this;
198211
}
199212

200213
}
201214

202215
private void CheckConnectPointDrop()
203216
{
204-
if (Node.NodesCanvas.DraggedConnect.ToConnector == null)
217+
if (NodesCanvas.DraggedConnect.ToConnector == null)
205218
{
206-
Node.NodesCanvas.CommandDeleteFreeConnect.Execute();
219+
NodesCanvas.CommandDeleteDraggedConnect.Execute();
207220
}
208221
else
209222
{
210223
Node.CommandAddEmptyConnector.Execute();
211-
Node.NodesCanvas.CommandAddConnect.Execute(Node.NodesCanvas.DraggedConnect);
212-
Node.NodesCanvas.DraggedConnect = null;
224+
NodesCanvas.CommandAddConnectWithUndoRedo.Execute(Node.NodesCanvas.DraggedConnect);
225+
NodesCanvas.DraggedConnect = null;
213226
}
214227
}
215228

216229
private void ConnectorDrag()
217230
{
218-
this.NodesCanvas.ConnectorPreviewForDrop = this;
231+
NodesCanvas.ConnectorPreviewForDrop = this;
219232
}
220233
private void ConnectorDragEnter()
221234
{
222-
if (this.Node != this.NodesCanvas.ConnectorPreviewForDrop.Node)
235+
if (Node != NodesCanvas.ConnectorPreviewForDrop.Node)
223236
return;
224237

225-
int indexTo = this.Node.Transitions.IndexOf(this);
238+
int indexTo = Node.Transitions.IndexOf(this);
226239
if (indexTo == 0)
227240
return;
228241

@@ -317,7 +330,7 @@ public static ViewModelConnect FromXElement(ViewModelNodesCanvas nodesCanvas, XE
317330
}
318331
else
319332
{
320-
viewModelConnect = new ViewModelConnect(nodeFrom.CurrentConnector);
333+
viewModelConnect = new ViewModelConnect(nodeFrom.NodesCanvas, nodeFrom.CurrentConnector);
321334
viewModelConnect.ToConnector = nodeTo.Input;
322335
nodeFrom.CommandAddEmptyConnector.Execute();
323336
}

SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ private void SetupConnectors()
9393
public SimpleCommandWithParameter<SelectMode> CommandSelect { get; set; }
9494
public SimpleCommandWithParameter<MyPoint> CommandMove { get; set; }
9595
public SimpleCommandWithParameter<bool> CommandCollapse { get; set; }
96-
public SimpleCommandWithParameter<ViewModelConnector> CommandAddConnector { get; set; }
97-
public SimpleCommandWithParameter<ViewModelConnector> CommandDeleteConnector { get; set; }
98-
96+
//public SimpleCommandWithParameter<(int index, ViewModelConnector connector)> CommandAddConnector { get; set; }
97+
//public SimpleCommandWithParameter<ViewModelConnector> CommandDeleteConnector { get; set; }
98+
public SimpleCommandWithParameter<(int index, ViewModelConnector connector)> CommandAddConnectorWithConnect { get; set; }
99+
public SimpleCommandWithParameter<ViewModelConnector> CommandDeleteConnectorWithConnect { get; set; }
99100
public SimpleCommandWithParameter<string> CommandValidateName { get; set; }
100101

101102
public SimpleCommandWithParameter<ViewModelConnector> CommandSelectWithShiftForConnectors { get; set; }
@@ -129,8 +130,13 @@ private void SetupCommands()
129130
//CommandTransitionsDragOver = new SimpleCommand(TransitionsDragOver);
130131
//CommandConnectorDrag = new SimpleCommandWithParameter<ViewModelConnector>(this, ConnectorDrag);
131132

132-
CommandAddConnector = new SimpleCommandWithParameter<ViewModelConnector>(AddConnector, NotSaved);
133-
CommandDeleteConnector = new SimpleCommandWithParameter<ViewModelConnector>(DeleteConnector, NotSaved);
133+
//CommandAddConnector = new SimpleCommandWithParameter<(int index, ViewModelConnector connector)>(AddConnector, NotSaved);
134+
//CommandDeleteConnector = new SimpleCommandWithParameter<ViewModelConnector>(DeleteConnector, NotSaved);
135+
136+
CommandAddConnectorWithConnect = new SimpleCommandWithParameter<(int index, ViewModelConnector connector)>(AddConnectorWithConnect, NotSaved);
137+
CommandDeleteConnectorWithConnect = new SimpleCommandWithParameter<ViewModelConnector>(DeleteConnectorWithConnec, NotSaved);
138+
139+
134140
CommandValidateName = new SimpleCommandWithParameter<string>(ValidateName, NotSaved);
135141

136142

@@ -156,12 +162,34 @@ private void Collapse(bool value)
156162
UnSelectedAllConnectors();
157163
}
158164
}
159-
private void AddConnector(ViewModelConnector connector)
165+
public int GetConnectorIndex(ViewModelConnector connector)
160166
{
161-
Transitions.Add(connector);
167+
return Transitions.IndexOf(connector);
162168
}
163-
private void DeleteConnector(ViewModelConnector connector)
169+
170+
//private void AddConnector((int index, ViewModelConnector connector) element)
171+
//{
172+
// Transitions.Insert(element.index, element.connector);
173+
//}
174+
//private void DeleteConnector(ViewModelConnector connector)
175+
//{
176+
// Transitions.Remove(connector);
177+
// //connector.Connect?.Comma
178+
//}
179+
private void AddConnectorWithConnect((int index, ViewModelConnector connector) element)
164180
{
181+
Transitions.Insert(element.index, element.connector);
182+
if(element.connector.Connect!=null)
183+
{
184+
NodesCanvas.CommandAddConnect.Execute(element.connector.Connect);
185+
}
186+
}
187+
private void DeleteConnectorWithConnec(ViewModelConnector connector)
188+
{
189+
if (connector.Connect != null)
190+
{
191+
NodesCanvas.CommandDeleteConnect.Execute(connector.Connect);
192+
}
165193
Transitions.Remove(connector);
166194
}
167195
private void Select(SelectMode selectMode)

0 commit comments

Comments
 (0)