Skip to content

Commit 6d01c86

Browse files
committed
fix for connect
1 parent 134042a commit 6d01c86

12 files changed

Lines changed: 57 additions & 143 deletions

SimpleStateMachineNodeEditor/Helpers/MyUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static void FindParents<TParent1, TParent2>(DependencyObject currentObjec
5454
} while ((parent1 == default(TParent1)) || (parent2 == default(TParent2)));
5555
}
5656

57-
public static bool Intersect(MyPoint a1, MyPoint a2, MyPoint b1, MyPoint b2)
57+
public static bool CheckIntersectTwoRectangles(MyPoint a1, MyPoint a2, MyPoint b1, MyPoint b2)
5858
{
5959
bool par1 = a1.X > b2.X; //второй перед первым
6060
bool par2 = b1.X > a2.X; //первый перед вторым
@@ -199,7 +199,7 @@ private static double[] cubicRoots(double a, double b, double c, double d)
199199
}
200200

201201
//Check on intersections curve Bezier and line
202-
public static bool ComputeIntersections(MyPoint bezierStartPoint, MyPoint bezierPoint1, MyPoint bezierPoint2, MyPoint bezierEndPoint, MyPoint lineStartPoint, MyPoint lineEndPoint)
202+
public static bool CheckIntersectCubicBezierCurveAndLine(MyPoint bezierStartPoint, MyPoint bezierPoint1, MyPoint bezierPoint2, MyPoint bezierEndPoint, MyPoint lineStartPoint, MyPoint lineEndPoint)
203203
{
204204
// coefficients of line
205205
double A = lineEndPoint.Y - lineStartPoint.Y;// A = y2 - y1

SimpleStateMachineNodeEditor/Styles/Colors.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
<!--#region -->
66
<!--#endregion-->
7-
<SolidColorBrush x:Key="ColorConnector" Color="White"/>
7+
<!--white-->
8+
<SolidColorBrush x:Key="ColorConnector" Color="White"/>
89

910
<!--#region Node-->
1011

SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@
1212
using System.Reactive.Linq;
1313

1414
using ReactiveUI;
15-
16-
using ReactiveUI;
17-
18-
using System.Windows.Input;
1915
using System.Windows.Markup;
20-
using System.Windows.Media;
21-
using System.Windows.Media.Imaging;
22-
using System.Windows.Navigation;
23-
using System.Windows.Shapes;
2416
using SimpleStateMachineNodeEditor.ViewModel;
2517
using SimpleStateMachineNodeEditor.Helpers.Enums;
2618
using System.Windows.Forms;

SimpleStateMachineNodeEditor/View/ViewConnect.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:local="clr-namespace:SimpleStateMachineNodeEditor.View"
77
mc:Ignorable="d"
8-
d:DesignHeight="450" d:DesignWidth="800">
8+
d:DesignHeight="450" d:DesignWidth="800" IsHitTestVisible="False">
99
<UserControl.RenderTransform>
1010
<TransformGroup>
1111
<ScaleTransform x:Name="Scale" ScaleX="1" ScaleY="1"/>

SimpleStateMachineNodeEditor/View/ViewConnect.xaml.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
using System.Reactive.Disposables;
22
using System.Windows;
33
using System.Windows.Controls;
4-
4+
using System.Windows.Input;
55
using ReactiveUI;
6-
6+
using System;
7+
using System.Windows.Data;
8+
using System.Windows.Documents;
9+
using System.Windows.Media;
10+
using System.Windows.Media.Imaging;
11+
using System.Windows.Navigation;
12+
using System.Windows.Controls.Primitives;
13+
using System.Reactive.Linq;
14+
using System.Windows.Markup;
715
using SimpleStateMachineNodeEditor.ViewModel;
16+
using SimpleStateMachineNodeEditor.Helpers;
817

918
namespace SimpleStateMachineNodeEditor.View
1019
{
@@ -31,6 +40,13 @@ object IViewFor.ViewModel
3140
public ViewConnect()
3241
{
3342
InitializeComponent();
43+
SetupBinding();
44+
SetupEvents();
45+
}
46+
47+
#region SetupBinding
48+
private void SetupBinding()
49+
{
3450
this.WhenActivated(disposable =>
3551
{
3652
// Цвет линии
@@ -54,5 +70,17 @@ public ViewConnect()
5470

5571
});
5672
}
73+
#endregion SetupBinding
74+
75+
#region SetupEvents
76+
private void SetupEvents()
77+
{
78+
this.WhenActivated(disposable =>
79+
{
80+
81+
});
82+
}
83+
84+
#endregion SetupEvents
5785
}
5886
}

SimpleStateMachineNodeEditor/View/ViewLeftConnector.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ private void SetupEvents()
9090
this.Form.Events().Drop.Subscribe(e => OnEventDrop(e)).DisposeWith(disposable);
9191
});
9292
}
93+
9394
#endregion SetupEvents
9495

9596
private void OnEventDrop(DragEventArgs e)
@@ -100,7 +101,7 @@ private void OnEventDrop(DragEventArgs e)
100101
void UpdatePosition()
101102
{
102103
// Координата центра
103-
Point InputCenter = Form.TranslatePoint(new Point(1, Form.Height / 2), this);
104+
Point InputCenter = Form.TranslatePoint(new Point(Form.Width/2, Form.Height / 2), this);
104105

105106
//Ищем Canvas
106107
ViewNodesCanvas NodesCanvas = MyUtils.FindParent<ViewNodesCanvas>(this);

SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ private void SetupCommands()
100100
this.BindCommand(this.ViewModel, x => x.CommandSelectAll, x => x.BindingSelectAll).DisposeWith(disposable);
101101
this.BindCommand(this.ViewModel, x => x.CommandDeleteSelectedNodes, x => x.BindingDeleteNode).DisposeWith(disposable);
102102

103+
103104
this.BindCommand(this.ViewModel, x => x.CommandSelect, x => x.BindingSelect, positionLeftClickObservable).DisposeWith(disposable);
104105
this.BindCommand(this.ViewModel, x => x.CommandCut, x => x.BindingCut, positionLeftClickObservable).DisposeWith(disposable);
105106

SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs

Lines changed: 5 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,9 @@ private void SetupEvents()
9292
this.WhenActivated(disposable =>
9393
{
9494
this.Form.Events().MouseLeftButtonDown.Subscribe(e => ConnectDrag(e)).DisposeWith(disposable);
95-
9695
this.Text.Events().LostFocus.Subscribe(e => Validate(e)).DisposeWith(disposable);
97-
98-
this.Text.Events().PreviewMouseLeftButtonDown.Subscribe(e => TextDrag(e)).DisposeWith(disposable);
99-
this.Text.Events().PreviewDrop.Subscribe(e => TextDrop(e)).DisposeWith(disposable);
100-
this.Text.Events().PreviewDragOver.Subscribe(e => TextDragOver(e)).DisposeWith(disposable);
101-
this.Text.Events().PreviewDragEnter.Subscribe(e => TextDragEnter(e)).DisposeWith(disposable);
102-
this.Text.Events().PreviewDragLeave.Subscribe(e => TextDragLeave(e)).DisposeWith(disposable);
103-
10496
this.Grid.Events().PreviewMouseLeftButtonDown.Subscribe(e => ConnectorDrag(e)).DisposeWith(disposable);
10597
this.Grid.Events().PreviewDragEnter.Subscribe(e => ConnectorDragEnter(e)).DisposeWith(disposable);
106-
this.Grid.Events().PreviewDragOver.Subscribe(e => ConnectorDragOver(e)).DisposeWith(disposable);
107-
this.Grid.Events().PreviewDragLeave.Subscribe(e => ConnectorDragLeave(e)).DisposeWith(disposable);
10898
this.Grid.Events().PreviewDrop.Subscribe(e => ConnectorDrop(e)).DisposeWith(disposable);
10999

110100

@@ -118,7 +108,7 @@ private void Validate(RoutedEventArgs e)
118108
}
119109

120110
private void ConnectDrag(MouseButtonEventArgs e)
121-
{
111+
{
122112
this.ViewModel.CommandConnectPointDrag.Execute();
123113
DataObject data = new DataObject();
124114
data.SetData("Node", this.ViewModel.Node);
@@ -127,70 +117,20 @@ private void ConnectDrag(MouseButtonEventArgs e)
127117
e.Handled = true;
128118
}
129119

130-
private void TextDrag(MouseButtonEventArgs e)
131-
{
132-
ConnectorDrag(e);
133-
e.Handled = true;
134-
}
135-
136-
private void TextDragOver(DragEventArgs e)
137-
{
138-
ConnectorDragOver(e);
139-
e.Handled = true;
140-
}
141-
142-
private void TextDragEnter(DragEventArgs e)
143-
{
144-
ConnectorDragEnter(e);
145-
e.Handled = true;
146-
}
147-
148-
private void TextDragLeave(DragEventArgs e)
149-
{
150-
ConnectorDragLeave(e);
151-
e.Handled = true;
152-
}
153-
154-
private void TextDrop(DragEventArgs e)
155-
{
156-
ConnectorDrop(e);
157-
e.Handled = true;
158-
}
159-
160120
private void ConnectorDrag(MouseButtonEventArgs e)
161121
{
122+
162123
if (!this.ViewModel.TextEnable)
163124
return;
164-
125+
if (!Keyboard.IsKeyDown(Key.LeftShift))
126+
return;
165127
this.ViewModel.CommandConnectorDrag.Execute();
166128
DataObject data = new DataObject();
167129
data.SetData("Connector", this.ViewModel);
168130
DragDrop.DoDragDrop(this, data, DragDropEffects.Link);
169-
this.ViewModel?.CommandCheckConnectorDrop.Execute();
170131
e.Handled = true;
171132
}
172133

173-
private void ConnectorDragOver(DragEventArgs e)
174-
{
175-
176-
177-
//if (this.ViewModel.NodesCanvas.ConnectorPreviewForDrop != this.ViewModel)
178-
//{
179-
// this.ViewModel.Node.Point1 += 0.0001;
180-
181-
182-
// return;
183-
//}
184-
//e.Handled = true;
185-
//this.UpdatePosition();
186-
187-
//this.ViewModel.CommandConnectorDragOver.Execute();
188-
189-
190-
191-
return;
192-
}
193-
194134
private void ConnectorDragEnter(DragEventArgs e)
195135
{
196136
if (this.ViewModel.NodesCanvas.ConnectorPreviewForDrop == null)
@@ -203,17 +143,6 @@ private void ConnectorDragEnter(DragEventArgs e)
203143

204144
e.Handled = true;
205145
}
206-
207-
private void ConnectorDragLeave(DragEventArgs e)
208-
{
209-
if (this.ViewModel.NodesCanvas.ConnectorPreviewForDrop != null)
210-
return;
211-
212-
this.ViewModel.CommandConnectorDragLeave.Execute();
213-
214-
e.Handled = true;
215-
}
216-
217146
private void ConnectorDrop(DragEventArgs e)
218147
{
219148
if (this.ViewModel.NodesCanvas.ConnectorPreviewForDrop == null)
@@ -237,7 +166,7 @@ void UpdatePositionConnectPoin()
237166
if (this.IsVisible)
238167
{
239168
// Координата центра
240-
positionConnectPoint = Form.TranslatePoint(new Point(Form.Width-1, Form.Height/2), this);
169+
positionConnectPoint = Form.TranslatePoint(new Point(Form.Width/2, Form.Height / 2), this);
241170

242171
//Ищем Canvas
243172
ViewNodesCanvas NodesCanvas = MyUtils.FindParent<ViewNodesCanvas>(this);

SimpleStateMachineNodeEditor/ViewModel/ViewModelConnect.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public ViewModelConnect(ViewModelConnector fromConnector)
7272
//this.WhenAnyValue(x => x.FromConnector).Where(x => x == null).Subscribe(_ => { StartPoint.Clear(); });
7373
//this.WhenAnyValue(x => x.ToConnector).Where(x => x == null).Subscribe(_ => { EndPoint.Clear(); SetupCommands(); });
7474
FromConnector = fromConnector;
75+
FromConnector.Connect = this;
7576
//SetupCommands();
7677
}
7778
#region Setup Commands

SimpleStateMachineNodeEditor/ViewModel/ViewModelConnector.cs

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,8 @@ public ViewModelConnector(ViewModelNodesCanvas nodesCanvas, ViewModelNode viewMo
8989

9090
public SimpleCommand CommandConnectorDrag { get; set; }
9191
public SimpleCommand CommandConnectorDragEnter { get; set; }
92-
public SimpleCommand CommandConnectorDragOver { get; set; }
93-
public SimpleCommand CommandConnectorDragLeave { get; set; }
9492
public SimpleCommand CommandConnectorDrop { get; set; }
9593

96-
public SimpleCommand CommandCheckConnectorDrop { get; set; }
9794

9895

9996
public SimpleCommand CommandAdd { get; set; }
@@ -110,11 +107,7 @@ private void SetupCommands()
110107

111108
CommandConnectorDrag = new SimpleCommand(this, ConnectorDrag);
112109
CommandConnectorDragEnter = new SimpleCommand(this, ConnectorDragEnter);
113-
CommandConnectorDragOver = new SimpleCommand(this, ConnectorDragOver);
114-
CommandConnectorDragLeave = new SimpleCommand(this, ConnectorDragLeave);
115-
116110
CommandConnectorDrop = new SimpleCommand(this, ConnectorDrop);
117-
CommandCheckConnectorDrop = new SimpleCommand(this, CheckConnectorDrop);
118111

119112
CommandAdd = new SimpleCommand(this, Add);
120113
CommandDelete = new SimpleCommand(this, Delete);
@@ -145,10 +138,10 @@ private void DragConnector(ViewModelConnector draggedConnector)
145138

146139
private void ConnectPointDrop()
147140
{
148-
if (Node.NodesCanvas.DraggedConnect.FromConnector.Node != this.Node)
149-
{
141+
//if (Node.NodesCanvas.DraggedConnect.FromConnector.Node != this.Node)
142+
//{
150143
Node.NodesCanvas.DraggedConnect.ToConnector = this;
151-
}
144+
//}
152145
}
153146

154147
private void CheckConnectPointDrop()
@@ -206,32 +199,11 @@ private void ConnectorDragEnter()
206199
this.Node.Transitions[indexFrom].PositionConnectPoint.Set(positionTo);
207200
this.Node.Transitions.Move(indexFrom, indexTo);
208201
}
209-
}
210-
private void ConnectorDragLeave()
211-
{
212-
213-
}
214-
private void ConnectorDragOver()
215-
{
216-
217202
}
218203
private void ConnectorDrop()
219204
{
220205
this.NodesCanvas.ConnectorPreviewForDrop = null;
221206
}
222-
private void CheckConnectorDrop()
223-
{
224-
//if (Node.NodesCanvas.CurrentConnect.ToConnector == null)
225-
//{
226-
// Node.NodesCanvas.CommandDeleteFreeConnect.Execute();
227-
//}
228-
//else
229-
//{
230-
// Node.CommandAddEmptyConnector.Execute();
231-
// Node.NodesCanvas.CommandAddConnect.Execute(Node.NodesCanvas.CurrentConnect);
232-
// Node.NodesCanvas.CurrentConnect = null;
233-
//}
234-
}
235207
private void ValidateName(string newName)
236208
{
237209
NodesCanvas.CommandValidateConnectName.Execute(new ValidateObjectProperty<ViewModelConnector, string>(this, newName));

0 commit comments

Comments
 (0)