Commit 4bed9f746a959844a7a4923ababae045b9727795

Authored by toan
1 parent d96c9e481b
Exists in master

2063 : Update source

Showing 3 changed files with 92 additions and 16 deletions Inline Diff

sources/RoboforkApp/Controls/DesignerCanvas.cs
1 using System; 1 using System;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.Linq; 3 using System.Linq;
4 using System.Windows; 4 using System.Windows;
5 using System.Windows.Controls; 5 using System.Windows.Controls;
6 using System.Windows.Documents; 6 using System.Windows.Documents;
7 using System.Windows.Input; 7 using System.Windows.Input;
8 using System.Windows.Markup; 8 using System.Windows.Markup;
9 using System.Windows.Media; 9 using System.Windows.Media;
10 using System.Windows.Shapes; 10 using System.Windows.Shapes;
11 using System.Xml; 11 using System.Xml;
12 12
13 namespace RoboforkApp 13 namespace RoboforkApp
14 { 14 {
15 public class DesignerCanvas : Canvas 15 public class DesignerCanvas : Canvas
16 { 16 {
17 const double RADIUS_NODE = 25d; //8d; 17 const double RADIUS_NODE = 25d; //8d;
18 const double RADIUS_CURVER_LINE = 130d; 18 const double RADIUS_CURVER_LINE = 130d;
19 const double DISTANCE_AUTO_NODES = 100d; 19 const double DISTANCE_AUTO_NODES = 100d;
20 const double DISTANCE_START_NODES = 30d; 20 const double DISTANCE_START_NODES = 30d;
21 const double DISTANCE_END_NODES = 30d; 21 const double DISTANCE_END_NODES = 30d;
22 const double DISTANCE_FREE_NODES = 40d; 22 const double DISTANCE_FREE_NODES = 40d;
23 const double STROKE_ROOT_LINE = 6d; 23 const double STROKE_ROOT_LINE = 6d;
24 const double STROKE_LINE = 4d; 24 const double STROKE_LINE = 4d;
25 const double STROKE_NODE = 1d; 25 const double STROKE_NODE = 1d;
26 const double DISTANCE_RATIO = 100; 26 const double DISTANCE_RATIO = 100;
27 27
28 const double UCNODE_SETLEFT = 17; 28 const double UCNODE_SETLEFT = 17;
29 const double UCNODE_SETTOP = 17; 29 const double UCNODE_SETTOP = 17;
30 const double UCNODE_WIDTH = 34; 30 const double UCNODE_WIDTH = 34;
31 const double UCNODE_HEIGHT = 34; 31 const double UCNODE_HEIGHT = 34;
32 32
33 private List<Rectangle> shapeList = new List<Rectangle>(); 33 private List<Rectangle> shapeList = new List<Rectangle>();
34 private TextBlock shapePosIndicator; 34 private TextBlock shapePosIndicator;
35 private TextBlock shapeSizeIndicator; 35 private TextBlock shapeSizeIndicator;
36 private int currentLine; 36 private int currentLine;
37 private ucStartEndButton _startPoint; 37 private ucStartEndButton _startPoint;
38 private ucNode _ucNodeFree; 38 private ucNode _ucNodeFree;
39 private ucStartEndButton _goalPoint; 39 private ucStartEndButton _goalPoint;
40 private ucDisplayCoordinate _displayAxiPosition; 40 private ucDisplayCoordinate _displayAxiPosition;
41 41
42 // Add variable for draw route 42 // Add variable for draw route
43 public Path pLine = new Path(); 43 public Path pLine = new Path();
44 public Path pRootLine = new Path(); 44 public Path pRootLine = new Path();
45 public Path pCurverLine = new Path(); 45 public Path pCurverLine = new Path();
46 public Path pRedNode = new Path(); 46 public Path pRedNode = new Path();
47 public Path pYellowNode = new Path(); 47 public Path pYellowNode = new Path();
48 public GeometryGroup gGrpLine = new GeometryGroup(); 48 public GeometryGroup gGrpLine = new GeometryGroup();
49 public GeometryGroup gGrpRootLine = new GeometryGroup(); 49 public GeometryGroup gGrpRootLine = new GeometryGroup();
50 public GeometryGroup gGrpCurverLine = new GeometryGroup(); 50 public GeometryGroup gGrpCurverLine = new GeometryGroup();
51 public GeometryGroup gGrpRedNode = new GeometryGroup(); 51 public GeometryGroup gGrpRedNode = new GeometryGroup();
52 public GeometryGroup gGrpYellowNode = new GeometryGroup(); 52 public GeometryGroup gGrpYellowNode = new GeometryGroup();
53 public int currentShape; 53 public int currentShape;
54 public static bool isStartDrawRoute = false; 54 public static bool isStartDrawRoute = false;
55 public static bool isGoalDrawRoute = false; 55 public static bool isGoalDrawRoute = false;
56 56
57 public struct NodeInfo 57 public struct NodeInfo
58 { 58 {
59 public double X; 59 public double X;
60 public double Y; 60 public double Y;
61 public String Mode1; 61 public String Mode1;
62 public String Mode2; 62 public String Mode2;
63 public String Mode3; 63 public String Mode3;
64 } 64 }
65 List<NodeInfo> NodeInfo_List = new List<NodeInfo>(); 65 List<NodeInfo> NodeInfo_List = new List<NodeInfo>();
66 66
67 // Add variable for Set Schedule 67 // Add variable for Set Schedule
68 public Path pScheduleNode = new Path(); 68 public Path pScheduleNode = new Path();
69 public Path pScheduleLine = new Path(); 69 public Path pScheduleLine = new Path();
70 public GeometryGroup gGrpScheduleNode = new GeometryGroup(); 70 public GeometryGroup gGrpScheduleNode = new GeometryGroup();
71 public GeometryGroup gGrpScheduleLine = new GeometryGroup(); 71 public GeometryGroup gGrpScheduleLine = new GeometryGroup();
72 72
73 73
74 public static bool EditNodeFlag = false; 74 public static bool EditNodeFlag = false;
75 public static bool DragDeltaFlag = false; 75 public static bool DragDeltaFlag = false;
76 76
77 //2017/03/04 NAM ADD START 77 //2017/03/04 NAM ADD START
78 public static bool isDrawingNode = false; 78 public static bool isDrawingNode = false;
79 public static bool isDragNode = false; 79 public static bool isDragNode = false;
80 public Path pNewLine = new Path(); 80 public Path pNewLine = new Path();
81 public GeometryGroup gGrpNewLine = new GeometryGroup(); 81 public GeometryGroup gGrpNewLine = new GeometryGroup();
82 82
83 public struct NewNodeInfo 83 public struct NewNodeInfo
84 { 84 {
85 public double X; 85 public double X;
86 public double Y; 86 public double Y;
87 public String Mode; 87 public String Mode;
88 } 88 }
89 List<NewNodeInfo> NewNodeInfo_List = new List<NewNodeInfo>(); 89 List<NewNodeInfo> NewNodeInfo_List = new List<NewNodeInfo>();
90 List<TextBlock> NodeNo = new List<TextBlock>(); 90 List<TextBlock> NodeNo = new List<TextBlock>();
91 List<ucNode> ucNode_Lst = new List<ucNode>(); 91 List<ucNode> ucNode_Lst = new List<ucNode>();
92 List<ucNode> ucScheduleNode_Lst = new List<ucNode>(); 92 public List<ucNode> ucScheduleNode_Lst = new List<ucNode>();
93 int stt = 1; 93 int stt = 1;
94 //2017/03/04 NAM ADD END 94 //2017/03/04 NAM ADD END
95 95
96 96
97 public ScheduleCanvas scheduleCanvas; 97 public ScheduleCanvas scheduleCanvas;
98 98
99 99
100 // Add variable for Set Auto Nodes 100 // Add variable for Set Auto Nodes
101 public Path pBlueNode = new Path(); 101 public Path pBlueNode = new Path();
102 private GeometryGroup gGrpBlueNode = new GeometryGroup(); 102 private GeometryGroup gGrpBlueNode = new GeometryGroup();
103 103
104 // Add variable for Set Free Nodes 104 // Add variable for Set Free Nodes
105 public Path pFreeNode = new Path(); 105 public Path pFreeNode = new Path();
106 //private GeometryGroup gGrpFreeNode = new GeometryGroup(); 106 //private GeometryGroup gGrpFreeNode = new GeometryGroup();
107 107
108 // The part of the rectangle the mouse is over. 108 // The part of the rectangle the mouse is over.
109 private enum HitType 109 private enum HitType
110 { 110 {
111 None, Body, UL, UR, LR, LL, L, R, T, B 111 None, Body, UL, UR, LR, LL, L, R, T, B
112 }; 112 };
113 public enum OperationState 113 public enum OperationState
114 { 114 {
115 None, DrawObstract, DrawRoute, DrawSetFreeNode, EditNode, NewDrawSetFreeNode 115 None, DrawObstract, DrawRoute, DrawSetFreeNode, EditNode, NewDrawSetFreeNode
116 }; 116 };
117 public enum MouseState 117 public enum MouseState
118 { 118 {
119 None, Draw, Drag, 119 None, Draw, Drag,
120 } 120 }
121 public OperationState Operation = OperationState.None; 121 public OperationState Operation = OperationState.None;
122 public MouseState mouseState = MouseState.None; 122 public MouseState mouseState = MouseState.None;
123 123
124 // The draw start point. 124 // The draw start point.
125 private Point StartDrawPoint; 125 private Point StartDrawPoint;
126 126
127 // The drag's last point. 127 // The drag's last point.
128 private Point LastPoint; 128 private Point LastPoint;
129 129
130 // The part of the rectangle under the mouse. 130 // The part of the rectangle under the mouse.
131 HitType MouseHitType = HitType.None; 131 HitType MouseHitType = HitType.None;
132 132
133 public void Init() { 133 public void Init() {
134 if (shapePosIndicator == null) 134 if (shapePosIndicator == null)
135 { 135 {
136 shapePosIndicator = new TextBlock() 136 shapePosIndicator = new TextBlock()
137 { 137 {
138 Foreground = Brushes.Black, 138 Foreground = Brushes.Black,
139 Background = Brushes.Transparent, 139 Background = Brushes.Transparent,
140 FontSize = 20, 140 FontSize = 20,
141 }; 141 };
142 } 142 }
143 if (shapeSizeIndicator == null) 143 if (shapeSizeIndicator == null)
144 { 144 {
145 shapeSizeIndicator = new TextBlock() 145 shapeSizeIndicator = new TextBlock()
146 { 146 {
147 Foreground = Brushes.Black, 147 Foreground = Brushes.Black,
148 Background = Brushes.Transparent, 148 Background = Brushes.Transparent,
149 FontSize = 20, 149 FontSize = 20,
150 }; 150 };
151 } 151 }
152 } 152 }
153 153
154 // Return a HitType value to indicate what is at the point. 154 // Return a HitType value to indicate what is at the point.
155 private HitType SetHitType(Point point) 155 private HitType SetHitType(Point point)
156 { 156 {
157 if (shapeList.Count == 0) 157 if (shapeList.Count == 0)
158 { 158 {
159 currentShape = 0; 159 currentShape = 0;
160 return HitType.None; 160 return HitType.None;
161 } 161 }
162 for (int i = 0; i < shapeList.Count; i++) 162 for (int i = 0; i < shapeList.Count; i++)
163 { 163 {
164 Rectangle rect = shapeList[i]; 164 Rectangle rect = shapeList[i];
165 double left = Canvas.GetLeft(rect); 165 double left = Canvas.GetLeft(rect);
166 double top = Canvas.GetTop(rect); 166 double top = Canvas.GetTop(rect);
167 double right = left + rect.Width; 167 double right = left + rect.Width;
168 double bottom = top + rect.Height; 168 double bottom = top + rect.Height;
169 if (point.X < left) continue; 169 if (point.X < left) continue;
170 if (point.X > right) continue; 170 if (point.X > right) continue;
171 if (point.Y < top) continue; 171 if (point.Y < top) continue;
172 if (point.Y > bottom) continue; 172 if (point.Y > bottom) continue;
173 currentShape = i; 173 currentShape = i;
174 174
175 const double GAP = 10; 175 const double GAP = 10;
176 if (point.X - left < GAP) 176 if (point.X - left < GAP)
177 { 177 {
178 // Left edge. 178 // Left edge.
179 if (point.Y - top < GAP) return HitType.UL; 179 if (point.Y - top < GAP) return HitType.UL;
180 if (bottom - point.Y < GAP) return HitType.LL; 180 if (bottom - point.Y < GAP) return HitType.LL;
181 return HitType.L; 181 return HitType.L;
182 } 182 }
183 if (right - point.X < GAP) 183 if (right - point.X < GAP)
184 { 184 {
185 // Right edge. 185 // Right edge.
186 if (point.Y - top < GAP) return HitType.UR; 186 if (point.Y - top < GAP) return HitType.UR;
187 if (bottom - point.Y < GAP) return HitType.LR; 187 if (bottom - point.Y < GAP) return HitType.LR;
188 return HitType.R; 188 return HitType.R;
189 } 189 }
190 if (point.Y - top < GAP) return HitType.T; 190 if (point.Y - top < GAP) return HitType.T;
191 if (bottom - point.Y < GAP) return HitType.B; 191 if (bottom - point.Y < GAP) return HitType.B;
192 return HitType.Body; 192 return HitType.Body;
193 } 193 }
194 currentShape = 0; 194 currentShape = 0;
195 return HitType.None; 195 return HitType.None;
196 } 196 }
197 197
198 // Set a mouse cursor appropriate for the current hit type. 198 // Set a mouse cursor appropriate for the current hit type.
199 private void SetMouseCursor() 199 private void SetMouseCursor()
200 { 200 {
201 // See what cursor we should display. 201 // See what cursor we should display.
202 Cursor desired_cursor = Cursors.Arrow; 202 Cursor desired_cursor = Cursors.Arrow;
203 switch (MouseHitType) 203 switch (MouseHitType)
204 { 204 {
205 case HitType.None: 205 case HitType.None:
206 desired_cursor = Cursors.Arrow; 206 desired_cursor = Cursors.Arrow;
207 break; 207 break;
208 case HitType.Body: 208 case HitType.Body:
209 desired_cursor = Cursors.ScrollAll; 209 desired_cursor = Cursors.ScrollAll;
210 break; 210 break;
211 case HitType.UL: 211 case HitType.UL:
212 case HitType.LR: 212 case HitType.LR:
213 desired_cursor = Cursors.SizeNWSE; 213 desired_cursor = Cursors.SizeNWSE;
214 break; 214 break;
215 case HitType.LL: 215 case HitType.LL:
216 case HitType.UR: 216 case HitType.UR:
217 desired_cursor = Cursors.SizeNESW; 217 desired_cursor = Cursors.SizeNESW;
218 break; 218 break;
219 case HitType.T: 219 case HitType.T:
220 case HitType.B: 220 case HitType.B:
221 desired_cursor = Cursors.SizeNS; 221 desired_cursor = Cursors.SizeNS;
222 break; 222 break;
223 case HitType.L: 223 case HitType.L:
224 case HitType.R: 224 case HitType.R:
225 desired_cursor = Cursors.SizeWE; 225 desired_cursor = Cursors.SizeWE;
226 break; 226 break;
227 } 227 }
228 228
229 // Display the desired cursor. 229 // Display the desired cursor.
230 if (Cursor != desired_cursor) Cursor = desired_cursor; 230 if (Cursor != desired_cursor) Cursor = desired_cursor;
231 } 231 }
232 232
233 // constance 233 // constance
234 int indicatorAligment = 2; 234 int indicatorAligment = 2;
235 235
236 /* 236 /*
237 private Point? dragStartPoint = null; 237 private Point? dragStartPoint = null;
238 238
239 */ 239 */
240 public IEnumerable<DesignerItem> SelectedItems 240 public IEnumerable<DesignerItem> SelectedItems
241 { 241 {
242 get 242 get
243 { 243 {
244 var selectedItems = from item in this.Children.OfType<DesignerItem>() 244 var selectedItems = from item in this.Children.OfType<DesignerItem>()
245 where item.IsSelected == true 245 where item.IsSelected == true
246 select item; 246 select item;
247 247
248 return selectedItems; 248 return selectedItems;
249 } 249 }
250 } 250 }
251 251
252 public void DeselectAll() 252 public void DeselectAll()
253 { 253 {
254 /* 254 /*
255 foreach (DesignerItem item in this.SelectedItems) 255 foreach (DesignerItem item in this.SelectedItems)
256 { 256 {
257 item.IsSelected = false; 257 item.IsSelected = false;
258 }*/ 258 }*/
259 } 259 }
260 260
261 protected override void OnMouseDown(MouseButtonEventArgs e) 261 protected override void OnMouseDown(MouseButtonEventArgs e)
262 { 262 {
263 base.OnMouseDown(e); 263 base.OnMouseDown(e);
264 264
265 MouseHitType = SetHitType(Mouse.GetPosition(this)); 265 MouseHitType = SetHitType(Mouse.GetPosition(this));
266 SetMouseCursor(); 266 SetMouseCursor();
267 267
268 if (Operation == OperationState.DrawRoute && isStartDrawRoute) 268 if (Operation == OperationState.DrawRoute && isStartDrawRoute)
269 { 269 {
270 if (isGoalDrawRoute) 270 if (isGoalDrawRoute)
271 { 271 {
272 return; 272 return;
273 } 273 }
274 274
275 // Check state draw 275 // Check state draw
276 if (MouseHitType == HitType.None) 276 if (MouseHitType == HitType.None)
277 { 277 {
278 if (gGrpLine.Children.Count == 1) 278 if (gGrpLine.Children.Count == 1)
279 { 279 {
280 LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[0]; 280 LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[0];
281 lineGeometry.EndPoint = LastPoint; 281 lineGeometry.EndPoint = LastPoint;
282 282
283 // Check end route 283 // Check end route
284 if (IsEndRoute(_goalPoint, lineGeometry)) 284 if (IsEndRoute(_goalPoint, lineGeometry))
285 { 285 {
286 isGoalDrawRoute = true; 286 isGoalDrawRoute = true;
287 ProcessEndRoute(); 287 ProcessEndRoute();
288 return; 288 return;
289 } 289 }
290 } 290 }
291 else if (IsCurverNode((LineGeometry)gGrpLine.Children[currentLine - 1] 291 else if (IsCurverNode((LineGeometry)gGrpLine.Children[currentLine - 1]
292 , (LineGeometry)gGrpLine.Children[currentLine])) 292 , (LineGeometry)gGrpLine.Children[currentLine]))
293 { 293 {
294 // Set end point to finish draw line 294 // Set end point to finish draw line
295 LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine]; 295 LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine];
296 lineGeometry.EndPoint = LastPoint; 296 lineGeometry.EndPoint = LastPoint;
297 297
298 // Add node to curver postion 298 // Add node to curver postion
299 AddNode(lineGeometry.StartPoint, gGrpRedNode); 299 AddNode(lineGeometry.StartPoint, gGrpRedNode);
300 300
301 // Check end route 301 // Check end route
302 if (IsEndRoute(_goalPoint, lineGeometry)) 302 if (IsEndRoute(_goalPoint, lineGeometry))
303 { 303 {
304 isGoalDrawRoute = true; 304 isGoalDrawRoute = true;
305 ProcessEndRoute(); 305 ProcessEndRoute();
306 return; 306 return;
307 } 307 }
308 } 308 }
309 else 309 else
310 { 310 {
311 // Remove current line 311 // Remove current line
312 gGrpLine.Children.RemoveAt(currentLine); 312 gGrpLine.Children.RemoveAt(currentLine);
313 313
314 // Set end point to finish draw line 314 // Set end point to finish draw line
315 LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine - 1]; 315 LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine - 1];
316 lineGeometry.EndPoint = LastPoint; 316 lineGeometry.EndPoint = LastPoint;
317 317
318 // Check end route 318 // Check end route
319 if (IsEndRoute(_goalPoint, lineGeometry)) 319 if (IsEndRoute(_goalPoint, lineGeometry))
320 { 320 {
321 isGoalDrawRoute = true; 321 isGoalDrawRoute = true;
322 ProcessEndRoute(); 322 ProcessEndRoute();
323 return; 323 return;
324 } 324 }
325 } 325 }
326 326
327 // Draw new line 327 // Draw new line
328 DrawLine(LastPoint, LastPoint, gGrpLine); 328 DrawLine(LastPoint, LastPoint, gGrpLine);
329 // Setting start point for new line 329 // Setting start point for new line
330 StartDrawPoint = LastPoint; 330 StartDrawPoint = LastPoint;
331 331
332 mouseState = MouseState.Draw; 332 mouseState = MouseState.Draw;
333 currentLine = gGrpLine.Children.Count - 1; 333 currentLine = gGrpLine.Children.Count - 1;
334 return; 334 return;
335 } 335 }
336 } 336 }
337 else if (Operation == OperationState.DrawSetFreeNode) 337 else if (Operation == OperationState.DrawSetFreeNode)
338 { 338 {
339 bool RightClick = false; 339 bool RightClick = false;
340 if (IsStopDrawRoute(e)) 340 if (IsStopDrawRoute(e))
341 RightClick = true; 341 RightClick = true;
342 342
343 StartDrawPoint = e.MouseDevice.GetPosition(this); 343 StartDrawPoint = e.MouseDevice.GetPosition(this);
344 344
345 SetFreeNodes(StartDrawPoint, RightClick); 345 SetFreeNodes(StartDrawPoint, RightClick);
346 } 346 }
347 ////2017/03/04 NAM EDT START 347 ////2017/03/04 NAM EDT START
348 //else if (Operation == OperationState.NewDrawSetFreeNode) 348 //else if (Operation == OperationState.NewDrawSetFreeNode)
349 //{ 349 //{
350 // bool RightClick = false; 350 // bool RightClick = false;
351 // bool LeftClick = false; 351 // bool LeftClick = false;
352 // if (IsStopDrawRoute(e)) 352 // if (IsStopDrawRoute(e))
353 // RightClick = true; 353 // RightClick = true;
354 354
355 // StartDrawPoint = e.MouseDevice.GetPosition(this); 355 // StartDrawPoint = e.MouseDevice.GetPosition(this);
356 // CreateNode(StartDrawPoint,LeftClick, RightClick); 356 // CreateNode(StartDrawPoint,LeftClick, RightClick);
357 // //NewSetFreeNodes(StartDrawPoint, RightClick); 357 // //NewSetFreeNodes(StartDrawPoint, RightClick);
358 //} 358 //}
359 ////2017/03/04 NAM EDT END 359 ////2017/03/04 NAM EDT END
360 360
361 else if (Operation == OperationState.EditNode) 361 else if (Operation == OperationState.EditNode)
362 { 362 {
363 Point node_edited = e.MouseDevice.GetPosition(this); 363 Point node_edited = e.MouseDevice.GetPosition(this);
364 364
365 // start Edit Node Infor 365 // start Edit Node Infor
366 EditNode(node_edited); 366 EditNode(node_edited);
367 367
368 } 368 }
369 else if (Operation == OperationState.DrawObstract) 369 else if (Operation == OperationState.DrawObstract)
370 { 370 {
371 if (MouseHitType == HitType.None) 371 if (MouseHitType == HitType.None)
372 { 372 {
373 Rectangle shape = new Rectangle(); 373 Rectangle shape = new Rectangle();
374 shape.Width = 1; 374 shape.Width = 1;
375 shape.Height = 1; 375 shape.Height = 1;
376 // Create a SolidColorBrush and use it to 376 // Create a SolidColorBrush and use it to
377 // paint the rectangle. 377 // paint the rectangle.
378 shape.Stroke = Brushes.Blue; 378 shape.Stroke = Brushes.Blue;
379 shape.StrokeThickness = 1; 379 shape.StrokeThickness = 1;
380 shape.Fill = new SolidColorBrush(Colors.LightCyan); 380 shape.Fill = new SolidColorBrush(Colors.LightCyan);
381 StartDrawPoint = e.MouseDevice.GetPosition(this); 381 StartDrawPoint = e.MouseDevice.GetPosition(this);
382 shape.SetValue(Canvas.LeftProperty, StartDrawPoint.X); 382 shape.SetValue(Canvas.LeftProperty, StartDrawPoint.X);
383 shape.SetValue(Canvas.TopProperty, StartDrawPoint.Y); 383 shape.SetValue(Canvas.TopProperty, StartDrawPoint.Y);
384 this.Children.Add(shape); 384 this.Children.Add(shape);
385 shapeList.Add(shape); 385 shapeList.Add(shape);
386 386
387 mouseState = MouseState.Draw; 387 mouseState = MouseState.Draw;
388 currentShape = shapeList.Count() - 1; 388 currentShape = shapeList.Count() - 1;
389 389
390 double shapeX = Canvas.GetLeft(shapeList[currentShape]); 390 double shapeX = Canvas.GetLeft(shapeList[currentShape]);
391 double shapeY = Canvas.GetTop(shapeList[currentShape]); 391 double shapeY = Canvas.GetTop(shapeList[currentShape]);
392 shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")"; 392 shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")";
393 shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment); 393 shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment);
394 shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment); 394 shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment);
395 395
396 double width = (int)shapeList[currentShape].Width; 396 double width = (int)shapeList[currentShape].Width;
397 double height = (int)shapeList[currentShape].Height; 397 double height = (int)shapeList[currentShape].Height;
398 shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")"; 398 shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")";
399 shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width); 399 shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width);
400 shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height); 400 shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height);
401 401
402 this.Children.Add(shapePosIndicator); 402 this.Children.Add(shapePosIndicator);
403 this.Children.Add(shapeSizeIndicator); 403 this.Children.Add(shapeSizeIndicator);
404 404
405 405
406 return; 406 return;
407 } 407 }
408 else 408 else
409 { 409 {
410 if (shapeList.Count() != 0) 410 if (shapeList.Count() != 0)
411 shapeList[currentShape].Fill = new SolidColorBrush(Colors.LightCyan); 411 shapeList[currentShape].Fill = new SolidColorBrush(Colors.LightCyan);
412 412
413 double shapeX = Canvas.GetLeft(shapeList[currentShape]); 413 double shapeX = Canvas.GetLeft(shapeList[currentShape]);
414 double shapeY = Canvas.GetTop(shapeList[currentShape]); 414 double shapeY = Canvas.GetTop(shapeList[currentShape]);
415 shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")"; 415 shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")";
416 shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment); 416 shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment);
417 shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment); 417 shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment);
418 418
419 double width = (int)shapeList[currentShape].Width; 419 double width = (int)shapeList[currentShape].Width;
420 double height = (int)shapeList[currentShape].Height; 420 double height = (int)shapeList[currentShape].Height;
421 shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")"; 421 shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")";
422 shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width); 422 shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width);
423 shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height); 423 shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height);
424 424
425 this.Children.Add(shapePosIndicator); 425 this.Children.Add(shapePosIndicator);
426 this.Children.Add(shapeSizeIndicator); 426 this.Children.Add(shapeSizeIndicator);
427 } 427 }
428 428
429 LastPoint = Mouse.GetPosition(this); 429 LastPoint = Mouse.GetPosition(this);
430 mouseState = MouseState.Drag; 430 mouseState = MouseState.Drag;
431 } 431 }
432 e.Handled = true; 432 e.Handled = true;
433 } 433 }
434 434
435 protected override void OnMouseMove(MouseEventArgs e) 435 protected override void OnMouseMove(MouseEventArgs e)
436 { 436 {
437 base.OnMouseMove(e); 437 base.OnMouseMove(e);
438 438
439 if (mouseState == MouseState.None) 439 if (mouseState == MouseState.None)
440 { 440 {
441 MouseHitType = SetHitType(Mouse.GetPosition(this)); 441 MouseHitType = SetHitType(Mouse.GetPosition(this));
442 SetMouseCursor(); 442 SetMouseCursor();
443 } 443 }
444 else if (Operation == OperationState.DrawRoute && isStartDrawRoute) 444 else if (Operation == OperationState.DrawRoute && isStartDrawRoute)
445 { 445 {
446 LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine]; 446 LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine];
447 447
448 // See how much the mouse has moved. 448 // See how much the mouse has moved.
449 Point point = Mouse.GetPosition(this); 449 Point point = Mouse.GetPosition(this);
450 double offset_x = point.X - StartDrawPoint.X; 450 double offset_x = point.X - StartDrawPoint.X;
451 double offset_y = point.Y - StartDrawPoint.Y; 451 double offset_y = point.Y - StartDrawPoint.Y;
452 452
453 // Get the line's current position. 453 // Get the line's current position.
454 double new_x = lineGeometry.StartPoint.X; 454 double new_x = lineGeometry.StartPoint.X;
455 double new_y = lineGeometry.StartPoint.Y; 455 double new_y = lineGeometry.StartPoint.Y;
456 456
457 if (offset_x != 0 || offset_y != 0) 457 if (offset_x != 0 || offset_y != 0)
458 { 458 {
459 if (Math.Abs(offset_x) >= Math.Abs(offset_y)) 459 if (Math.Abs(offset_x) >= Math.Abs(offset_y))
460 { 460 {
461 new_x = point.X; 461 new_x = point.X;
462 } 462 }
463 else 463 else
464 { 464 {
465 new_y = point.Y; 465 new_y = point.Y;
466 } 466 }
467 } 467 }
468 468
469 // Set end point of current line 469 // Set end point of current line
470 LastPoint = new Point(new_x, new_y); 470 LastPoint = new Point(new_x, new_y);
471 lineGeometry.EndPoint = LastPoint; 471 lineGeometry.EndPoint = LastPoint;
472 DisplayCoordinate(LastPoint); 472 DisplayCoordinate(LastPoint);
473 } 473 }
474 else if (Operation == OperationState.DrawObstract) 474 else if (Operation == OperationState.DrawObstract)
475 { 475 {
476 if (mouseState == MouseState.Drag) 476 if (mouseState == MouseState.Drag)
477 { 477 {
478 // See how much the mouse has moved. 478 // See how much the mouse has moved.
479 Point point = Mouse.GetPosition(this); 479 Point point = Mouse.GetPosition(this);
480 double offset_x = point.X - LastPoint.X; 480 double offset_x = point.X - LastPoint.X;
481 double offset_y = point.Y - LastPoint.Y; 481 double offset_y = point.Y - LastPoint.Y;
482 482
483 // Get the rectangle's current position. 483 // Get the rectangle's current position.
484 double new_x = Canvas.GetLeft(shapeList[currentShape]); 484 double new_x = Canvas.GetLeft(shapeList[currentShape]);
485 double new_y = Canvas.GetTop(shapeList[currentShape]); 485 double new_y = Canvas.GetTop(shapeList[currentShape]);
486 double new_width = shapeList[currentShape].Width; 486 double new_width = shapeList[currentShape].Width;
487 double new_height = shapeList[currentShape].Height; 487 double new_height = shapeList[currentShape].Height;
488 488
489 // Update the rectangle. 489 // Update the rectangle.
490 switch (MouseHitType) 490 switch (MouseHitType)
491 { 491 {
492 case HitType.Body: 492 case HitType.Body:
493 new_x += offset_x; 493 new_x += offset_x;
494 new_y += offset_y; 494 new_y += offset_y;
495 break; 495 break;
496 case HitType.UL: 496 case HitType.UL:
497 new_x += offset_x; 497 new_x += offset_x;
498 new_y += offset_y; 498 new_y += offset_y;
499 new_width -= offset_x; 499 new_width -= offset_x;
500 new_height -= offset_y; 500 new_height -= offset_y;
501 break; 501 break;
502 case HitType.UR: 502 case HitType.UR:
503 new_y += offset_y; 503 new_y += offset_y;
504 new_width += offset_x; 504 new_width += offset_x;
505 new_height -= offset_y; 505 new_height -= offset_y;
506 break; 506 break;
507 case HitType.LR: 507 case HitType.LR:
508 new_width += offset_x; 508 new_width += offset_x;
509 new_height += offset_y; 509 new_height += offset_y;
510 break; 510 break;
511 case HitType.LL: 511 case HitType.LL:
512 new_x += offset_x; 512 new_x += offset_x;
513 new_width -= offset_x; 513 new_width -= offset_x;
514 new_height += offset_y; 514 new_height += offset_y;
515 break; 515 break;
516 case HitType.L: 516 case HitType.L:
517 new_x += offset_x; 517 new_x += offset_x;
518 new_width -= offset_x; 518 new_width -= offset_x;
519 break; 519 break;
520 case HitType.R: 520 case HitType.R:
521 new_width += offset_x; 521 new_width += offset_x;
522 break; 522 break;
523 case HitType.B: 523 case HitType.B:
524 new_height += offset_y; 524 new_height += offset_y;
525 break; 525 break;
526 case HitType.T: 526 case HitType.T:
527 new_y += offset_y; 527 new_y += offset_y;
528 new_height -= offset_y; 528 new_height -= offset_y;
529 break; 529 break;
530 } 530 }
531 // Don't use negative width or height. 531 // Don't use negative width or height.
532 if ((new_width > 0) && (new_height > 0)) 532 if ((new_width > 0) && (new_height > 0))
533 { 533 {
534 // Update the rectangle. 534 // Update the rectangle.
535 Canvas.SetLeft(shapeList[currentShape], new_x); 535 Canvas.SetLeft(shapeList[currentShape], new_x);
536 Canvas.SetTop(shapeList[currentShape], new_y); 536 Canvas.SetTop(shapeList[currentShape], new_y);
537 shapeList[currentShape].Width = new_width; 537 shapeList[currentShape].Width = new_width;
538 shapeList[currentShape].Height = new_height; 538 shapeList[currentShape].Height = new_height;
539 539
540 // Save the mouse's new location. 540 // Save the mouse's new location.
541 LastPoint = point; 541 LastPoint = point;
542 542
543 } 543 }
544 } 544 }
545 else if (mouseState == MouseState.Draw) 545 else if (mouseState == MouseState.Draw)
546 { 546 {
547 547
548 // See how much the mouse has moved. 548 // See how much the mouse has moved.
549 Point point = Mouse.GetPosition(this); 549 Point point = Mouse.GetPosition(this);
550 550
551 551
552 double offset_x = point.X - StartDrawPoint.X; 552 double offset_x = point.X - StartDrawPoint.X;
553 double offset_y = point.Y - StartDrawPoint.Y; 553 double offset_y = point.Y - StartDrawPoint.Y;
554 554
555 // Get the rectangle's current position. 555 // Get the rectangle's current position.
556 double start_x = Canvas.GetLeft(shapeList[currentShape]); 556 double start_x = Canvas.GetLeft(shapeList[currentShape]);
557 double start_y = Canvas.GetTop(shapeList[currentShape]); 557 double start_y = Canvas.GetTop(shapeList[currentShape]);
558 double new_x = Canvas.GetLeft(shapeList[currentShape]); 558 double new_x = Canvas.GetLeft(shapeList[currentShape]);
559 double new_y = Canvas.GetTop(shapeList[currentShape]); 559 double new_y = Canvas.GetTop(shapeList[currentShape]);
560 double new_width = offset_x; 560 double new_width = offset_x;
561 double new_height = offset_y; 561 double new_height = offset_y;
562 if (offset_x < 0) 562 if (offset_x < 0)
563 { 563 {
564 new_x = point.X; 564 new_x = point.X;
565 new_width = -offset_x; 565 new_width = -offset_x;
566 } 566 }
567 if (offset_y < 0) 567 if (offset_y < 0)
568 { 568 {
569 new_y = point.Y; 569 new_y = point.Y;
570 new_height = -offset_y; 570 new_height = -offset_y;
571 } 571 }
572 Canvas.SetLeft(shapeList[currentShape], new_x); 572 Canvas.SetLeft(shapeList[currentShape], new_x);
573 Canvas.SetTop(shapeList[currentShape], new_y); 573 Canvas.SetTop(shapeList[currentShape], new_y);
574 shapeList[currentShape].Width = new_width; 574 shapeList[currentShape].Width = new_width;
575 shapeList[currentShape].Height = new_height; 575 shapeList[currentShape].Height = new_height;
576 576
577 } 577 }
578 578
579 double shapeX = Canvas.GetLeft(shapeList[currentShape]); 579 double shapeX = Canvas.GetLeft(shapeList[currentShape]);
580 double shapeY = Canvas.GetTop(shapeList[currentShape]); 580 double shapeY = Canvas.GetTop(shapeList[currentShape]);
581 shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")"; 581 shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")";
582 shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment); 582 shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment);
583 shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment); 583 shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment);
584 584
585 double width = (int)shapeList[currentShape].Width; 585 double width = (int)shapeList[currentShape].Width;
586 double height = (int)shapeList[currentShape].Height; 586 double height = (int)shapeList[currentShape].Height;
587 shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")"; 587 shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")";
588 shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width); 588 shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width);
589 shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height); 589 shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height);
590 } 590 }
591 e.Handled = true; 591 e.Handled = true;
592 } 592 }
593 593
594 protected override void OnMouseUp(MouseButtonEventArgs e) 594 protected override void OnMouseUp(MouseButtonEventArgs e)
595 { 595 {
596 base.OnMouseUp(e); 596 base.OnMouseUp(e);
597 if (Operation == OperationState.DrawObstract) 597 if (Operation == OperationState.DrawObstract)
598 { 598 {
599 if (shapeList.Count() != 0) 599 if (shapeList.Count() != 0)
600 shapeList[currentShape].Fill = new SolidColorBrush(Colors.Blue); 600 shapeList[currentShape].Fill = new SolidColorBrush(Colors.Blue);
601 shapePosIndicator.Text = ""; 601 shapePosIndicator.Text = "";
602 shapeSizeIndicator.Text = ""; 602 shapeSizeIndicator.Text = "";
603 this.Children.Remove(shapePosIndicator); 603 this.Children.Remove(shapePosIndicator);
604 this.Children.Remove(shapeSizeIndicator); 604 this.Children.Remove(shapeSizeIndicator);
605 605
606 mouseState = MouseState.None; 606 mouseState = MouseState.None;
607 currentShape = 0; 607 currentShape = 0;
608 } 608 }
609 e.Handled = true; 609 e.Handled = true;
610 } 610 }
611 611
612 protected override void OnPreviewMouseUp(MouseButtonEventArgs e) 612 protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
613 { 613 {
614 base.OnPreviewMouseUp(e); 614 base.OnPreviewMouseUp(e);
615 615
616 EllipseGeometry ellipseGeometry; 616 EllipseGeometry ellipseGeometry;
617 bool flag = false; 617 bool flag = false;
618 618
619 StartDrawPoint = e.MouseDevice.GetPosition(this); 619 StartDrawPoint = e.MouseDevice.GetPosition(this);
620 620
621 if (EditNodeFlag == true ) 621 if (EditNodeFlag == true )
622 { 622 {
623 execEditNode(StartDrawPoint); 623 execEditNode(StartDrawPoint);
624 EditNodeFlag = false; 624 EditNodeFlag = false;
625 return; 625 return;
626 } 626 }
627 627
628 if (DragDeltaFlag == true) 628 if (DragDeltaFlag == true)
629 { 629 {
630 for (int i = 0; i < gGrpBlueNode.Children.Count; i++) 630 for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
631 { 631 {
632 632
633 for (int j = 0; j < ucNode_Lst.Count; j++) 633 for (int j = 0; j < ucNode_Lst.Count; j++)
634 { 634 {
635 if (j == i) 635 if (j == i)
636 { 636 {
637 _ucNodeFree = ucNode_Lst[j]; 637 _ucNodeFree = ucNode_Lst[j];
638 flag = true; 638 flag = true;
639 } 639 }
640 } 640 }
641 if (flag) 641 if (flag)
642 { 642 {
643 if (gGrpNewLine.Children.Count > 0) 643 if (gGrpNewLine.Children.Count > 0)
644 { 644 {
645 for (int k = 0; k < gGrpNewLine.Children.Count; k++) 645 for (int k = 0; k < gGrpNewLine.Children.Count; k++)
646 { 646 {
647 LineGeometry lineGeometry = (LineGeometry)gGrpNewLine.Children[k]; 647 LineGeometry lineGeometry = (LineGeometry)gGrpNewLine.Children[k];
648 Point p1 = lineGeometry.StartPoint; 648 Point p1 = lineGeometry.StartPoint;
649 Point p2 = lineGeometry.EndPoint; 649 Point p2 = lineGeometry.EndPoint;
650 650
651 //bool pInL = PointInLine(StartDrawPoint, p1, p2, 25); 651 //bool pInL = PointInLine(StartDrawPoint, p1, p2, 25);
652 652
653 //if (pInL) 653 //if (pInL)
654 //{ 654 //{
655 655
656 // //this.Children.Remove(_ucNodeFree); 656 // //this.Children.Remove(_ucNodeFree);
657 // //this.Children.Add(_ucNodeFree); 657 // //this.Children.Add(_ucNodeFree);
658 // return; 658 // return;
659 //} 659 //}
660 } 660 }
661 } 661 }
662 662
663 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; 663 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
664 664
665 ellipseGeometry.Center = new Point(StartDrawPoint.X, StartDrawPoint.Y); 665 ellipseGeometry.Center = new Point(StartDrawPoint.X, StartDrawPoint.Y);
666 666
667 double centerY = Canvas.GetTop(_ucNodeFree); 667 double centerY = Canvas.GetTop(_ucNodeFree);
668 double centerX = Canvas.GetLeft(_ucNodeFree); 668 double centerX = Canvas.GetLeft(_ucNodeFree);
669 669
670 mouseState = MouseState.Draw; 670 mouseState = MouseState.Draw;
671 671
672 672
673 StartDrawPoint = new Point(centerX + UCNODE_SETLEFT, centerY + UCNODE_SETTOP); 673 StartDrawPoint = new Point(centerX + UCNODE_SETLEFT, centerY + UCNODE_SETTOP);
674 ellipseGeometry.Center = new Point(centerX + UCNODE_SETLEFT, centerY + UCNODE_SETTOP); 674 ellipseGeometry.Center = new Point(centerX + UCNODE_SETLEFT, centerY + UCNODE_SETTOP);
675 675
676 this.Children.Remove(_ucNodeFree); 676 this.Children.Remove(_ucNodeFree);
677 this.Children.Add(_ucNodeFree); 677 this.Children.Add(_ucNodeFree);
678 } 678 }
679 } 679 }
680 680
681 ReDrawAllNode(); 681 ReDrawAllNode();
682 682
683 SetScheduleRoute(); 683 SetScheduleRoute();
684 DragDeltaFlag = false; 684 DragDeltaFlag = false;
685 } 685 }
686 686
687 687
688 688
689 return; 689 return;
690 } 690 }
691 691
692 /// <summary> 692 /// <summary>
693 /// On Preview Mouse Down 693 /// On Preview Mouse Down
694 /// </summary> 694 /// </summary>
695 /// <param name="e"></param> 695 /// <param name="e"></param>
696 protected override void OnPreviewMouseDown(MouseButtonEventArgs e) 696 protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
697 { 697 {
698 base.OnPreviewMouseDown(e); 698 base.OnPreviewMouseDown(e);
699 if (Operation != OperationState.NewDrawSetFreeNode) 699 if (Operation != OperationState.NewDrawSetFreeNode)
700 { 700 {
701 return; 701 return;
702 } 702 }
703 703
704 Point currentPoint = e.MouseDevice.GetPosition(this); 704 Point currentPoint = e.MouseDevice.GetPosition(this);
705 //bool _isStart = IsStartEndRoute(_startPoint, currentPoint); 705 //bool _isStart = IsStartEndRoute(_startPoint, currentPoint);
706 706
707 if (isDrawingNode == false) 707 if (isDrawingNode == false)
708 { 708 {
709 //double centerY = Canvas.GetTop(_startPoint); 709 //double centerY = Canvas.GetTop(_startPoint);
710 //double centerX = Canvas.GetLeft(_startPoint); 710 //double centerX = Canvas.GetLeft(_startPoint);
711 711
712 isDrawingNode = true; 712 isDrawingNode = true;
713 InitDrawRoute(); 713 InitDrawRoute();
714 //DrawLine(new Point(centerX + 25, centerY + 25), new Point(centerX + 25, centerY + 25), gGrpLine); 714 //DrawLine(new Point(centerX + 25, centerY + 25), new Point(centerX + 25, centerY + 25), gGrpLine);
715 mouseState = MouseState.Draw; 715 mouseState = MouseState.Draw;
716 //currentLine = gGrpLine.Children.Count - 1; 716 //currentLine = gGrpLine.Children.Count - 1;
717 //StartDrawPoint = new Point(centerX + 25, centerY + 25); 717 //StartDrawPoint = new Point(centerX + 25, centerY + 25);
718 718
719 //this.Children.Remove(_startPoint); 719 //this.Children.Remove(_startPoint);
720 //this.Children.Add(_startPoint); 720 //this.Children.Add(_startPoint);
721 721
722 722
723 //test 723 //test
724 bool RightClick = false; 724 bool RightClick = false;
725 bool LeftClick = false; 725 bool LeftClick = false;
726 726
727 727
728 if (IsMouseLeftClick(e)) 728 if (IsMouseLeftClick(e))
729 LeftClick = false; 729 LeftClick = false;
730 if (IsStopDrawRoute(e)) 730 if (IsStopDrawRoute(e))
731 RightClick = true; 731 RightClick = true;
732 732
733 StartDrawPoint = e.MouseDevice.GetPosition(this); 733 StartDrawPoint = e.MouseDevice.GetPosition(this);
734 //CreateNode(StartDrawPoint, LeftClick, RightClick); 734 //CreateNode(StartDrawPoint, LeftClick, RightClick);
735 execCreateNode(StartDrawPoint); 735 execCreateNode(StartDrawPoint);
736 //test 736 //test
737 737
738 738
739 return; 739 return;
740 } 740 }
741 //2017/03/04 NAM EDT START 741 //2017/03/04 NAM EDT START
742 else 742 else
743 { 743 {
744 744
745 bool RightClick = false; 745 bool RightClick = false;
746 bool LeftClick = false; 746 bool LeftClick = false;
747 747
748 748
749 if (IsMouseLeftClick(e)) 749 if (IsMouseLeftClick(e))
750 LeftClick = true; 750 LeftClick = true;
751 if (IsStopDrawRoute(e)) 751 if (IsStopDrawRoute(e))
752 RightClick = true; 752 RightClick = true;
753 753
754 StartDrawPoint = e.MouseDevice.GetPosition(this); 754 StartDrawPoint = e.MouseDevice.GetPosition(this);
755 755
756 //Nam can sua 756 //Nam can sua
757 //if (RightClick) 757 //if (RightClick)
758 //{ 758 //{
759 // execCreateNode(StartDrawPoint); 759 // execCreateNode(StartDrawPoint);
760 //} 760 //}
761 CreateNode(StartDrawPoint, LeftClick, RightClick); 761 CreateNode(StartDrawPoint, LeftClick, RightClick);
762 } 762 }
763 //2017/03/04 NAM EDT END 763 //2017/03/04 NAM EDT END
764 764
765 765
766 bool _isgoal = IsStartEndRoute(_goalPoint, LastPoint); 766 bool _isgoal = IsStartEndRoute(_goalPoint, LastPoint);
767 if (_isgoal && isGoalDrawRoute == false) 767 if (_isgoal && isGoalDrawRoute == false)
768 { 768 {
769 isGoalDrawRoute = true; 769 isGoalDrawRoute = true;
770 ProcessEndRoute(); 770 ProcessEndRoute();
771 } 771 }
772 } 772 }
773 773
774 #region Functions for draw route 774 #region Functions for draw route
775 775
776 /// <summary> 776 /// <summary>
777 /// Check start or end draw route 777 /// Check start or end draw route
778 /// </summary> 778 /// </summary>
779 /// <param name="_ucStartEndButton">Button start</param> 779 /// <param name="_ucStartEndButton">Button start</param>
780 /// <param name="currentPoint">Position for check</param> 780 /// <param name="currentPoint">Position for check</param>
781 /// <returns>true: start, false: not start</returns> 781 /// <returns>true: start, false: not start</returns>
782 private bool IsStartEndRoute(ucStartEndButton _ucStartEndButton, Point currentPoint) 782 private bool IsStartEndRoute(ucStartEndButton _ucStartEndButton, Point currentPoint)
783 { 783 {
784 if(_ucStartEndButton == null) 784 if(_ucStartEndButton == null)
785 { 785 {
786 return false; 786 return false;
787 } 787 }
788 788
789 double centerX = Canvas.GetLeft(_ucStartEndButton); 789 double centerX = Canvas.GetLeft(_ucStartEndButton);
790 double centerY = Canvas.GetTop(_ucStartEndButton); 790 double centerY = Canvas.GetTop(_ucStartEndButton);
791 791
792 if (currentPoint.X < centerX + 50 && currentPoint.X > centerX 792 if (currentPoint.X < centerX + 50 && currentPoint.X > centerX
793 && currentPoint.Y < centerY + 50 && currentPoint.Y > centerY) 793 && currentPoint.Y < centerY + 50 && currentPoint.Y > centerY)
794 { 794 {
795 return true; 795 return true;
796 } 796 }
797 return false; 797 return false;
798 } 798 }
799 799
800 /// <summary> 800 /// <summary>
801 /// Process when end draw route 801 /// Process when end draw route
802 /// </summary> 802 /// </summary>
803 private void ProcessEndRoute() 803 private void ProcessEndRoute()
804 { 804 {
805 Operation = OperationState.None; 805 Operation = OperationState.None;
806 AutoEditLine(); 806 AutoEditLine();
807 this.Children.Remove(_displayAxiPosition); 807 this.Children.Remove(_displayAxiPosition);
808 this.Children.Remove(_goalPoint); 808 this.Children.Remove(_goalPoint);
809 this.Children.Add(_goalPoint); 809 this.Children.Add(_goalPoint);
810 } 810 }
811 811
812 /// <summary> 812 /// <summary>
813 /// Check end draw route 813 /// Check end draw route
814 /// </summary> 814 /// </summary>
815 /// <param name="_ucStartEndButton">Button end</param> 815 /// <param name="_ucStartEndButton">Button end</param>
816 /// <param name="currentPoint">Position for check</param> 816 /// <param name="currentPoint">Position for check</param>
817 /// <returns>true: end, false: not end</returns> 817 /// <returns>true: end, false: not end</returns>
818 private bool IsEndRoute(ucStartEndButton _ucStartEndButton, LineGeometry lineGeometry) 818 private bool IsEndRoute(ucStartEndButton _ucStartEndButton, LineGeometry lineGeometry)
819 { 819 {
820 if (_ucStartEndButton == null) 820 if (_ucStartEndButton == null)
821 { 821 {
822 return false; 822 return false;
823 } 823 }
824 824
825 double centerX = Canvas.GetLeft(_ucStartEndButton); 825 double centerX = Canvas.GetLeft(_ucStartEndButton);
826 double centerY = Canvas.GetTop(_ucStartEndButton); 826 double centerY = Canvas.GetTop(_ucStartEndButton);
827 Point startPoint = lineGeometry.StartPoint; 827 Point startPoint = lineGeometry.StartPoint;
828 Point endPoint = lineGeometry.EndPoint; 828 Point endPoint = lineGeometry.EndPoint;
829 829
830 if(IsVerticalLine(lineGeometry)) 830 if(IsVerticalLine(lineGeometry))
831 { 831 {
832 if(endPoint.X < centerX || endPoint.X > centerX + 50) 832 if(endPoint.X < centerX || endPoint.X > centerX + 50)
833 return false; 833 return false;
834 834
835 if (startPoint.Y > centerY + 50 && endPoint.Y > centerY + 50) 835 if (startPoint.Y > centerY + 50 && endPoint.Y > centerY + 50)
836 return false; 836 return false;
837 837
838 if (startPoint.Y < centerY && endPoint.Y < centerY) 838 if (startPoint.Y < centerY && endPoint.Y < centerY)
839 return false; 839 return false;
840 }else 840 }else
841 { 841 {
842 if (endPoint.Y < centerY || endPoint.Y > centerY + 50) 842 if (endPoint.Y < centerY || endPoint.Y > centerY + 50)
843 return false; 843 return false;
844 844
845 if (startPoint.X > centerX + 50 && endPoint.X > centerX + 50) 845 if (startPoint.X > centerX + 50 && endPoint.X > centerX + 50)
846 return false; 846 return false;
847 847
848 if (startPoint.X < centerX && endPoint.X < centerX) 848 if (startPoint.X < centerX && endPoint.X < centerX)
849 return false; 849 return false;
850 } 850 }
851 851
852 return true; 852 return true;
853 } 853 }
854 854
855 /// <summary> 855 /// <summary>
856 /// Make root 856 /// Make root
857 /// </summary> 857 /// </summary>
858 public void MakeRoot() 858 public void MakeRoot()
859 { 859 {
860 //LineGeometry lineGeometry; 860 //LineGeometry lineGeometry;
861 //EllipseGeometry ellipseGeometry; 861 //EllipseGeometry ellipseGeometry;
862 //Point startPoint; 862 //Point startPoint;
863 //Point endPoint; 863 //Point endPoint;
864 864
865 // If still not route 865 // If still not route
866 if (gGrpLine.Children.Count == 0) 866 if (gGrpLine.Children.Count == 0)
867 return; 867 return;
868 868
869 pLine.Stroke = new SolidColorBrush(Colors.Red); 869 pLine.Stroke = new SolidColorBrush(Colors.Red);
870 pLine.StrokeThickness = STROKE_ROOT_LINE; 870 pLine.StrokeThickness = STROKE_ROOT_LINE;
871 871
872 //// Setting for path line 872 //// Setting for path line
873 //pRootLine.Stroke = new SolidColorBrush(Colors.Red); 873 //pRootLine.Stroke = new SolidColorBrush(Colors.Red);
874 //pRootLine.StrokeThickness = STROKE_ROOT_LINE; 874 //pRootLine.StrokeThickness = STROKE_ROOT_LINE;
875 //pRootLine.Data = gGrpRootLine; 875 //pRootLine.Data = gGrpRootLine;
876 //this.Children.Add(pRootLine); 876 //this.Children.Add(pRootLine);
877 877
878 // Setting for path curver line 878 // Setting for path curver line
879 //pCurverLine.StrokeThickness = STROKE_ROOT_LINE; 879 //pCurverLine.StrokeThickness = STROKE_ROOT_LINE;
880 880
881 //// Get start point 881 //// Get start point
882 //lineGeometry = (LineGeometry)gGrpLine.Children[0]; 882 //lineGeometry = (LineGeometry)gGrpLine.Children[0];
883 //startPoint = lineGeometry.StartPoint; 883 //startPoint = lineGeometry.StartPoint;
884 884
885 //for (int i = 0; i < gGrpYellowNode.Children.Count; i = i + 2) 885 //for (int i = 0; i < gGrpYellowNode.Children.Count; i = i + 2)
886 //{ 886 //{
887 // ellipseGeometry = (EllipseGeometry)gGrpYellowNode.Children[i]; 887 // ellipseGeometry = (EllipseGeometry)gGrpYellowNode.Children[i];
888 // endPoint = ellipseGeometry.Center; 888 // endPoint = ellipseGeometry.Center;
889 889
890 // DrawLine(startPoint, endPoint, gGrpRootLine); 890 // DrawLine(startPoint, endPoint, gGrpRootLine);
891 891
892 // ellipseGeometry = (EllipseGeometry)gGrpYellowNode.Children[i + 1]; 892 // ellipseGeometry = (EllipseGeometry)gGrpYellowNode.Children[i + 1];
893 // startPoint = ellipseGeometry.Center; 893 // startPoint = ellipseGeometry.Center;
894 //} 894 //}
895 895
896 //lineGeometry = (LineGeometry)gGrpLine.Children[gGrpLine.Children.Count - 1]; 896 //lineGeometry = (LineGeometry)gGrpLine.Children[gGrpLine.Children.Count - 1];
897 //endPoint = lineGeometry.EndPoint; 897 //endPoint = lineGeometry.EndPoint;
898 898
899 //DrawLine(startPoint, endPoint, gGrpRootLine); 899 //DrawLine(startPoint, endPoint, gGrpRootLine);
900 900
901 //this.Children.Remove(pYellowNode); 901 //this.Children.Remove(pYellowNode);
902 //this.Children.Remove(pBlueNode); 902 //this.Children.Remove(pBlueNode);
903 //this.Children.Remove(_startPoint); 903 //this.Children.Remove(_startPoint);
904 //this.Children.Remove(_goalPoint); 904 //this.Children.Remove(_goalPoint);
905 //this.Children.Add(pYellowNode); 905 //this.Children.Add(pYellowNode);
906 //this.Children.Add(pBlueNode); 906 //this.Children.Add(pBlueNode);
907 //this.Children.Add(_startPoint); 907 //this.Children.Add(_startPoint);
908 //this.Children.Add(_goalPoint); 908 //this.Children.Add(_goalPoint);
909 } 909 }
910 910
911 /// <summary> 911 /// <summary>
912 /// Auto edit leght of line 912 /// Auto edit leght of line
913 /// </summary> 913 /// </summary>
914 private void AutoEditLine() 914 private void AutoEditLine()
915 { 915 {
916 double temp; 916 double temp;
917 int index = gGrpLine.Children.Count - 1; 917 int index = gGrpLine.Children.Count - 1;
918 double centerY = Canvas.GetTop(_goalPoint) + 25; 918 double centerY = Canvas.GetTop(_goalPoint) + 25;
919 double centerX = Canvas.GetLeft(_goalPoint) + 25; 919 double centerX = Canvas.GetLeft(_goalPoint) + 25;
920 LineGeometry lastLine = (LineGeometry)gGrpLine.Children[index]; 920 LineGeometry lastLine = (LineGeometry)gGrpLine.Children[index];
921 LineGeometry beforeLastLine = (LineGeometry)gGrpLine.Children[index]; 921 LineGeometry beforeLastLine = (LineGeometry)gGrpLine.Children[index];
922 922
923 if(gGrpLine.Children.Count > 1) 923 if(gGrpLine.Children.Count > 1)
924 { 924 {
925 beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1]; 925 beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1];
926 926
927 if (!IsCurverNode(beforeLastLine, lastLine)) 927 if (!IsCurverNode(beforeLastLine, lastLine))
928 { 928 {
929 beforeLastLine.EndPoint = lastLine.EndPoint; 929 beforeLastLine.EndPoint = lastLine.EndPoint;
930 gGrpLine.Children.RemoveAt(index); 930 gGrpLine.Children.RemoveAt(index);
931 //// Remove yellow node 931 //// Remove yellow node
932 //if (gGrpYellowNode.Children.Count > 0) 932 //if (gGrpYellowNode.Children.Count > 0)
933 //{ 933 //{
934 // gGrpYellowNode.Children.RemoveAt(gGrpYellowNode.Children.Count - 1); 934 // gGrpYellowNode.Children.RemoveAt(gGrpYellowNode.Children.Count - 1);
935 // gGrpYellowNode.Children.RemoveAt(gGrpYellowNode.Children.Count - 1); 935 // gGrpYellowNode.Children.RemoveAt(gGrpYellowNode.Children.Count - 1);
936 //} 936 //}
937 //// Remove curver line 937 //// Remove curver line
938 //if (gGrpCurverLine.Children.Count > 0) 938 //if (gGrpCurverLine.Children.Count > 0)
939 //{ 939 //{
940 // gGrpCurverLine.Children.RemoveAt(gGrpCurverLine.Children.Count - 1); 940 // gGrpCurverLine.Children.RemoveAt(gGrpCurverLine.Children.Count - 1);
941 //} 941 //}
942 index = index - 1; 942 index = index - 1;
943 lastLine = (LineGeometry)gGrpLine.Children[index]; 943 lastLine = (LineGeometry)gGrpLine.Children[index];
944 } 944 }
945 } 945 }
946 946
947 if (index == gGrpRedNode.Children.Count + 1) 947 if (index == gGrpRedNode.Children.Count + 1)
948 { 948 {
949 AddNode(lastLine.StartPoint, gGrpRedNode); 949 AddNode(lastLine.StartPoint, gGrpRedNode);
950 } 950 }
951 951
952 if (lastLine.EndPoint.X == centerX && lastLine.EndPoint.Y == centerY) 952 if (lastLine.EndPoint.X == centerX && lastLine.EndPoint.Y == centerY)
953 return; 953 return;
954 954
955 if(IsVerticalLine(lastLine)) 955 if(IsVerticalLine(lastLine))
956 { 956 {
957 temp = lastLine.StartPoint.Y; 957 temp = lastLine.StartPoint.Y;
958 lastLine.StartPoint = new Point(centerX, temp); 958 lastLine.StartPoint = new Point(centerX, temp);
959 lastLine.EndPoint = new Point(centerX, centerY); 959 lastLine.EndPoint = new Point(centerX, centerY);
960 960
961 if(gGrpLine.Children.Count > 1){ 961 if(gGrpLine.Children.Count > 1){
962 beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1]; 962 beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1];
963 temp = beforeLastLine.EndPoint.Y; 963 temp = beforeLastLine.EndPoint.Y;
964 beforeLastLine.EndPoint = new Point(centerX, temp); 964 beforeLastLine.EndPoint = new Point(centerX, temp);
965 } 965 }
966 }else 966 }else
967 { 967 {
968 temp = lastLine.StartPoint.X; 968 temp = lastLine.StartPoint.X;
969 lastLine.StartPoint = new Point(temp, centerY); 969 lastLine.StartPoint = new Point(temp, centerY);
970 lastLine.EndPoint = new Point(centerX, centerY); 970 lastLine.EndPoint = new Point(centerX, centerY);
971 if (gGrpLine.Children.Count > 1) 971 if (gGrpLine.Children.Count > 1)
972 { 972 {
973 beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1]; 973 beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1];
974 temp = beforeLastLine.EndPoint.X; 974 temp = beforeLastLine.EndPoint.X;
975 beforeLastLine.EndPoint = new Point(temp, centerY); 975 beforeLastLine.EndPoint = new Point(temp, centerY);
976 } 976 }
977 } 977 }
978 978
979 // Draw curver line 979 // Draw curver line
980 if (IsCurverNode(beforeLastLine, lastLine)) 980 if (IsCurverNode(beforeLastLine, lastLine))
981 { 981 {
982 EllipseGeometry ellipseGeometry = (EllipseGeometry)gGrpRedNode.Children[gGrpRedNode.Children.Count - 1]; 982 EllipseGeometry ellipseGeometry = (EllipseGeometry)gGrpRedNode.Children[gGrpRedNode.Children.Count - 1];
983 ellipseGeometry.Center = lastLine.StartPoint; 983 ellipseGeometry.Center = lastLine.StartPoint;
984 // 984 //
985 //if (GetDistance(lastLine.StartPoint, lastLine.EndPoint) > RADIUS_CURVER_LINE + 25) 985 //if (GetDistance(lastLine.StartPoint, lastLine.EndPoint) > RADIUS_CURVER_LINE + 25)
986 //{ 986 //{
987 //DrawCurver(beforeLastLine, lastLine); 987 //DrawCurver(beforeLastLine, lastLine);
988 //} 988 //}
989 } 989 }
990 } 990 }
991 991
992 /// <summary> 992 /// <summary>
993 /// Check draw curver node 993 /// Check draw curver node
994 /// </summary> 994 /// </summary>
995 /// <param name="oldLine">Old line</param> 995 /// <param name="oldLine">Old line</param>
996 /// <param name="newLine">New line</param> 996 /// <param name="newLine">New line</param>
997 /// <returns>true:is curver, fasle: not curver</returns> 997 /// <returns>true:is curver, fasle: not curver</returns>
998 private bool IsCurverNode(LineGeometry oldLine, LineGeometry newLine) 998 private bool IsCurverNode(LineGeometry oldLine, LineGeometry newLine)
999 { 999 {
1000 if (oldLine.StartPoint.Y == oldLine.EndPoint.Y && oldLine.StartPoint.Y == newLine.EndPoint.Y) 1000 if (oldLine.StartPoint.Y == oldLine.EndPoint.Y && oldLine.StartPoint.Y == newLine.EndPoint.Y)
1001 { 1001 {
1002 return false; 1002 return false;
1003 } 1003 }
1004 1004
1005 if (oldLine.StartPoint.X == oldLine.EndPoint.X && oldLine.StartPoint.X == newLine.EndPoint.X) 1005 if (oldLine.StartPoint.X == oldLine.EndPoint.X && oldLine.StartPoint.X == newLine.EndPoint.X)
1006 { 1006 {
1007 return false; 1007 return false;
1008 } 1008 }
1009 1009
1010 return true; 1010 return true;
1011 } 1011 }
1012 1012
1013 /// <summary> 1013 /// <summary>
1014 /// Check timming to stop draw route 1014 /// Check timming to stop draw route
1015 /// </summary> 1015 /// </summary>
1016 /// <param name="e"></param> 1016 /// <param name="e"></param>
1017 /// <returns>true:stop; false:continue</returns> 1017 /// <returns>true:stop; false:continue</returns>
1018 private bool IsStopDrawRoute(MouseEventArgs e) 1018 private bool IsStopDrawRoute(MouseEventArgs e)
1019 { 1019 {
1020 if(e.RightButton == MouseButtonState.Pressed) 1020 if(e.RightButton == MouseButtonState.Pressed)
1021 { 1021 {
1022 return true; 1022 return true;
1023 } 1023 }
1024 1024
1025 return false; 1025 return false;
1026 } 1026 }
1027 1027
1028 //2017/03/05 NAM ADD START 1028 //2017/03/05 NAM ADD START
1029 private bool IsMouseLeftClick(MouseEventArgs e) 1029 private bool IsMouseLeftClick(MouseEventArgs e)
1030 { 1030 {
1031 if (e.LeftButton == MouseButtonState.Pressed) 1031 if (e.LeftButton == MouseButtonState.Pressed)
1032 { 1032 {
1033 return true; 1033 return true;
1034 } 1034 }
1035 1035
1036 return false; 1036 return false;
1037 } 1037 }
1038 //2017/03/05 NAM ADD END 1038 //2017/03/05 NAM ADD END
1039 1039
1040 /// <summary> 1040 /// <summary>
1041 /// Draw curver line and yellow node 1041 /// Draw curver line and yellow node
1042 /// </summary> 1042 /// </summary>
1043 /// <param name="oldLine">Old line</param> 1043 /// <param name="oldLine">Old line</param>
1044 /// <param name="newLine">New line</param> 1044 /// <param name="newLine">New line</param>
1045 private void DrawCurver(LineGeometry oldLine, LineGeometry newLine) 1045 private void DrawCurver(LineGeometry oldLine, LineGeometry newLine)
1046 { 1046 {
1047 double radius = RADIUS_CURVER_LINE; 1047 double radius = RADIUS_CURVER_LINE;
1048 1048
1049 Point startPoint ; 1049 Point startPoint ;
1050 Point endPoint ; 1050 Point endPoint ;
1051 1051
1052 // Get postion of yellow node on old line 1052 // Get postion of yellow node on old line
1053 if(IsVerticalLine(oldLine)) 1053 if(IsVerticalLine(oldLine))
1054 { 1054 {
1055 if (oldLine.StartPoint.Y > oldLine.EndPoint.Y) 1055 if (oldLine.StartPoint.Y > oldLine.EndPoint.Y)
1056 startPoint = new Point(oldLine.EndPoint.X, oldLine.EndPoint.Y + radius); 1056 startPoint = new Point(oldLine.EndPoint.X, oldLine.EndPoint.Y + radius);
1057 else 1057 else
1058 startPoint = new Point(oldLine.EndPoint.X, oldLine.EndPoint.Y - radius); 1058 startPoint = new Point(oldLine.EndPoint.X, oldLine.EndPoint.Y - radius);
1059 }else 1059 }else
1060 { 1060 {
1061 if (oldLine.StartPoint.X > oldLine.EndPoint.X) 1061 if (oldLine.StartPoint.X > oldLine.EndPoint.X)
1062 startPoint = new Point(oldLine.EndPoint.X + radius, oldLine.EndPoint.Y); 1062 startPoint = new Point(oldLine.EndPoint.X + radius, oldLine.EndPoint.Y);
1063 else 1063 else
1064 startPoint = new Point(oldLine.EndPoint.X - radius, oldLine.EndPoint.Y); 1064 startPoint = new Point(oldLine.EndPoint.X - radius, oldLine.EndPoint.Y);
1065 } 1065 }
1066 1066
1067 // Get postion of yellow node on new line 1067 // Get postion of yellow node on new line
1068 if (IsVerticalLine(newLine)) 1068 if (IsVerticalLine(newLine))
1069 { 1069 {
1070 if (newLine.StartPoint.Y > newLine.EndPoint.Y) 1070 if (newLine.StartPoint.Y > newLine.EndPoint.Y)
1071 endPoint = new Point(newLine.StartPoint.X, newLine.StartPoint.Y - radius); 1071 endPoint = new Point(newLine.StartPoint.X, newLine.StartPoint.Y - radius);
1072 else 1072 else
1073 endPoint = new Point(newLine.StartPoint.X, newLine.StartPoint.Y + radius); 1073 endPoint = new Point(newLine.StartPoint.X, newLine.StartPoint.Y + radius);
1074 } 1074 }
1075 else 1075 else
1076 { 1076 {
1077 if (newLine.StartPoint.X > newLine.EndPoint.X) 1077 if (newLine.StartPoint.X > newLine.EndPoint.X)
1078 endPoint = new Point(newLine.StartPoint.X - radius, newLine.StartPoint.Y); 1078 endPoint = new Point(newLine.StartPoint.X - radius, newLine.StartPoint.Y);
1079 else 1079 else
1080 endPoint = new Point(newLine.StartPoint.X + radius, newLine.StartPoint.Y); 1080 endPoint = new Point(newLine.StartPoint.X + radius, newLine.StartPoint.Y);
1081 } 1081 }
1082 1082
1083 //// Setting sweep direction 1083 //// Setting sweep direction
1084 //SweepDirection sweepDirection = SweepDirection.Clockwise; 1084 //SweepDirection sweepDirection = SweepDirection.Clockwise;
1085 //if (IsVerticalLine(oldLine) && ((startPoint.Y - endPoint.Y) * (startPoint.X - endPoint.X)) > 0) 1085 //if (IsVerticalLine(oldLine) && ((startPoint.Y - endPoint.Y) * (startPoint.X - endPoint.X)) > 0)
1086 //{ 1086 //{
1087 // sweepDirection = SweepDirection.Counterclockwise; 1087 // sweepDirection = SweepDirection.Counterclockwise;
1088 //} 1088 //}
1089 1089
1090 //if (!IsVerticalLine(oldLine) && ((startPoint.Y - endPoint.Y) * (startPoint.X - endPoint.X)) < 0) 1090 //if (!IsVerticalLine(oldLine) && ((startPoint.Y - endPoint.Y) * (startPoint.X - endPoint.X)) < 0)
1091 //{ 1091 //{
1092 // sweepDirection = SweepDirection.Counterclockwise; 1092 // sweepDirection = SweepDirection.Counterclockwise;
1093 //} 1093 //}
1094 1094
1095 //// Add curver line 1095 //// Add curver line
1096 //DrawCurverLine(startPoint, endPoint, sweepDirection, gGrpCurverLine); 1096 //DrawCurverLine(startPoint, endPoint, sweepDirection, gGrpCurverLine);
1097 1097
1098 // Add node to postion distance 1300mm 1098 // Add node to postion distance 1300mm
1099 if (GetDistance(oldLine.StartPoint, oldLine.EndPoint) > RADIUS_CURVER_LINE) 1099 if (GetDistance(oldLine.StartPoint, oldLine.EndPoint) > RADIUS_CURVER_LINE)
1100 { 1100 {
1101 AddNode(startPoint, gGrpYellowNode); 1101 AddNode(startPoint, gGrpYellowNode);
1102 } 1102 }
1103 1103
1104 if (GetDistance(newLine.StartPoint, newLine.EndPoint) > RADIUS_CURVER_LINE) 1104 if (GetDistance(newLine.StartPoint, newLine.EndPoint) > RADIUS_CURVER_LINE)
1105 { 1105 {
1106 AddNode(endPoint, gGrpYellowNode); 1106 AddNode(endPoint, gGrpYellowNode);
1107 } 1107 }
1108 } 1108 }
1109 1109
1110 /// <summary> 1110 /// <summary>
1111 /// Init data for draw route 1111 /// Init data for draw route
1112 /// </summary> 1112 /// </summary>
1113 private void InitDrawRoute() 1113 private void InitDrawRoute()
1114 { 1114 {
1115 //2017/03/04 NAM ADD START 1115 //2017/03/04 NAM ADD START
1116 pNewLine.Stroke = new SolidColorBrush(Colors.Red); 1116 pNewLine.Stroke = new SolidColorBrush(Colors.Red);
1117 pNewLine.StrokeThickness = STROKE_LINE; 1117 pNewLine.StrokeThickness = STROKE_LINE;
1118 pNewLine.Data = gGrpNewLine; 1118 pNewLine.Data = gGrpNewLine;
1119 //2017/03/04 NAM ADD END 1119 //2017/03/04 NAM ADD END
1120 1120
1121 pScheduleLine.Stroke = new SolidColorBrush(Colors.Red); 1121 pScheduleLine.Stroke = new SolidColorBrush(Colors.Red);
1122 pScheduleLine.StrokeThickness = STROKE_LINE; 1122 pScheduleLine.StrokeThickness = STROKE_LINE;
1123 pScheduleLine.Data = gGrpScheduleLine; 1123 pScheduleLine.Data = gGrpScheduleLine;
1124 1124
1125 // Setting for path line 1125 // Setting for path line
1126 pLine.Stroke = new SolidColorBrush(Colors.Blue); 1126 pLine.Stroke = new SolidColorBrush(Colors.Blue);
1127 pLine.StrokeThickness = STROKE_LINE; 1127 pLine.StrokeThickness = STROKE_LINE;
1128 pLine.Data = gGrpLine; 1128 pLine.Data = gGrpLine;
1129 1129
1130 // Setting for path of curver line 1130 // Setting for path of curver line
1131 pCurverLine.Stroke = Brushes.Red; 1131 pCurverLine.Stroke = Brushes.Red;
1132 pCurverLine.StrokeThickness = STROKE_LINE; 1132 pCurverLine.StrokeThickness = STROKE_LINE;
1133 pCurverLine.Data = gGrpCurverLine; 1133 pCurverLine.Data = gGrpCurverLine;
1134 1134
1135 // Setting for path of red node 1135 // Setting for path of red node
1136 pRedNode.Stroke = new SolidColorBrush(Colors.Blue); 1136 pRedNode.Stroke = new SolidColorBrush(Colors.Blue);
1137 pRedNode.Fill = new SolidColorBrush(Colors.Red); 1137 pRedNode.Fill = new SolidColorBrush(Colors.Red);
1138 pRedNode.StrokeThickness = STROKE_NODE; 1138 pRedNode.StrokeThickness = STROKE_NODE;
1139 pRedNode.Data = gGrpRedNode; 1139 pRedNode.Data = gGrpRedNode;
1140 1140
1141 // Setting for path of yellow node 1141 // Setting for path of yellow node
1142 pYellowNode.Stroke = new SolidColorBrush(Colors.Blue); 1142 pYellowNode.Stroke = new SolidColorBrush(Colors.Blue);
1143 pYellowNode.Fill = new SolidColorBrush(Colors.Yellow); 1143 pYellowNode.Fill = new SolidColorBrush(Colors.Yellow);
1144 pYellowNode.StrokeThickness = STROKE_NODE; 1144 pYellowNode.StrokeThickness = STROKE_NODE;
1145 pYellowNode.Data = gGrpYellowNode; 1145 pYellowNode.Data = gGrpYellowNode;
1146 1146
1147 // Setting for path of Blue node 1147 // Setting for path of Blue node
1148 pBlueNode.Stroke = new SolidColorBrush(Colors.Blue); 1148 pBlueNode.Stroke = new SolidColorBrush(Colors.Blue);
1149 pBlueNode.Fill = new SolidColorBrush(Colors.LightBlue); 1149 pBlueNode.Fill = new SolidColorBrush(Colors.LightBlue);
1150 pBlueNode.StrokeThickness = STROKE_NODE; 1150 pBlueNode.StrokeThickness = STROKE_NODE;
1151 pBlueNode.Data = gGrpBlueNode; 1151 pBlueNode.Data = gGrpBlueNode;
1152 1152
1153 // Add paths to canvas 1153 // Add paths to canvas
1154 this.Children.Add(pLine); 1154 this.Children.Add(pLine);
1155 this.Children.Add(pCurverLine); 1155 this.Children.Add(pCurverLine);
1156 this.Children.Add(pRedNode); 1156 this.Children.Add(pRedNode);
1157 this.Children.Add(pYellowNode); 1157 this.Children.Add(pYellowNode);
1158 1158
1159 this.Children.Add(pNewLine); 1159 this.Children.Add(pNewLine);
1160 scheduleCanvas.Children.Add(pScheduleLine); 1160 scheduleCanvas.Children.Add(pScheduleLine);
1161 } 1161 }
1162 1162
1163 /// <summary> 1163 /// <summary>
1164 /// Clear all route 1164 /// Clear all route
1165 /// </summary> 1165 /// </summary>
1166 public void ClearRoute() 1166 public void ClearRoute()
1167 { 1167 {
1168 isStartDrawRoute = false; 1168 isStartDrawRoute = false;
1169 isGoalDrawRoute = false; 1169 isGoalDrawRoute = false;
1170 1170
1171 gGrpLine.Children.Clear(); 1171 gGrpLine.Children.Clear();
1172 gGrpRootLine.Children.Clear(); 1172 gGrpRootLine.Children.Clear();
1173 gGrpCurverLine.Children.Clear(); 1173 gGrpCurverLine.Children.Clear();
1174 gGrpRedNode.Children.Clear(); 1174 gGrpRedNode.Children.Clear();
1175 gGrpYellowNode.Children.Clear(); 1175 gGrpYellowNode.Children.Clear();
1176 gGrpBlueNode.Children.Clear(); 1176 gGrpBlueNode.Children.Clear();
1177 1177
1178 this.Children.Remove(pLine); 1178 this.Children.Remove(pLine);
1179 this.Children.Remove(pRootLine); 1179 this.Children.Remove(pRootLine);
1180 this.Children.Remove(pCurverLine); 1180 this.Children.Remove(pCurverLine);
1181 this.Children.Remove(pRedNode); 1181 this.Children.Remove(pRedNode);
1182 this.Children.Remove(pYellowNode); 1182 this.Children.Remove(pYellowNode);
1183 this.Children.Remove(pBlueNode); 1183 this.Children.Remove(pBlueNode);
1184 } 1184 }
1185 1185
1186 /// <summary> 1186 /// <summary>
1187 /// Draw line for route 1187 /// Draw line for route
1188 /// </summary> 1188 /// </summary>
1189 /// <param name="startPoint">Start point</param> 1189 /// <param name="startPoint">Start point</param>
1190 /// <param name="endPoint">End point</param> 1190 /// <param name="endPoint">End point</param>
1191 /// <param name="geometryGroup">Geometry Group</param> 1191 /// <param name="geometryGroup">Geometry Group</param>
1192 private void DrawLine(Point startPoint, Point endPoint, GeometryGroup geometryGroup) 1192 private void DrawLine(Point startPoint, Point endPoint, GeometryGroup geometryGroup)
1193 { 1193 {
1194 LineGeometry lineGeometry = new LineGeometry(); 1194 LineGeometry lineGeometry = new LineGeometry();
1195 lineGeometry.StartPoint = startPoint; 1195 lineGeometry.StartPoint = startPoint;
1196 lineGeometry.EndPoint = endPoint; 1196 lineGeometry.EndPoint = endPoint;
1197 geometryGroup.Children.Add(lineGeometry); 1197 geometryGroup.Children.Add(lineGeometry);
1198 } 1198 }
1199 1199
1200 /// <summary> 1200 /// <summary>
1201 /// Draw curver line 1201 /// Draw curver line
1202 /// </summary> 1202 /// </summary>
1203 /// <param name="startPoint">Point start curver line</param> 1203 /// <param name="startPoint">Point start curver line</param>
1204 /// <param name="endPoint">Point end curver line</param> 1204 /// <param name="endPoint">Point end curver line</param>
1205 /// <param name="radius">Radius</param> 1205 /// <param name="radius">Radius</param>
1206 /// <param name="geometryGroup">Geometry Group</param> 1206 /// <param name="geometryGroup">Geometry Group</param>
1207 private void DrawCurverLine(Point startPoint, Point endPoint, SweepDirection sweepDirection, GeometryGroup geometryGroup) 1207 private void DrawCurverLine(Point startPoint, Point endPoint, SweepDirection sweepDirection, GeometryGroup geometryGroup)
1208 { 1208 {
1209 PathGeometry pathGeometry = new PathGeometry(); 1209 PathGeometry pathGeometry = new PathGeometry();
1210 PathFigure figure = new PathFigure(); 1210 PathFigure figure = new PathFigure();
1211 figure.StartPoint = startPoint; 1211 figure.StartPoint = startPoint;
1212 figure.Segments.Add(new ArcSegment(endPoint, new Size(RADIUS_CURVER_LINE, RADIUS_CURVER_LINE), 90, false, sweepDirection, true)); 1212 figure.Segments.Add(new ArcSegment(endPoint, new Size(RADIUS_CURVER_LINE, RADIUS_CURVER_LINE), 90, false, sweepDirection, true));
1213 pathGeometry.Figures.Add(figure); 1213 pathGeometry.Figures.Add(figure);
1214 geometryGroup.Children.Add(pathGeometry); 1214 geometryGroup.Children.Add(pathGeometry);
1215 } 1215 }
1216 1216
1217 /// <summary> 1217 /// <summary>
1218 /// Setting node 1218 /// Setting node
1219 /// </summary> 1219 /// </summary>
1220 /// <param name="centerPoit">Position of center node</param> 1220 /// <param name="centerPoit">Position of center node</param>
1221 /// <param name="geometryGroup">Geometry Group</param> 1221 /// <param name="geometryGroup">Geometry Group</param>
1222 private void AddNode(Point centerPoit, GeometryGroup geometryGroup) 1222 private void AddNode(Point centerPoit, GeometryGroup geometryGroup)
1223 { 1223 {
1224 double radius = RADIUS_NODE; 1224 double radius = RADIUS_NODE;
1225 geometryGroup.Children.Add(new EllipseGeometry(centerPoit, radius, radius)); 1225 geometryGroup.Children.Add(new EllipseGeometry(centerPoit, radius, radius));
1226 } 1226 }
1227 1227
1228 /// <summary> 1228 /// <summary>
1229 /// Check line is vertical or horizontal 1229 /// Check line is vertical or horizontal
1230 /// </summary> 1230 /// </summary>
1231 /// <param name="line"></param> 1231 /// <param name="line"></param>
1232 /// <returns>true:Vertical, false:Horizontal</returns> 1232 /// <returns>true:Vertical, false:Horizontal</returns>
1233 private bool IsVerticalLine(LineGeometry line) 1233 private bool IsVerticalLine(LineGeometry line)
1234 { 1234 {
1235 if (line.StartPoint.X == line.EndPoint.X) 1235 if (line.StartPoint.X == line.EndPoint.X)
1236 { 1236 {
1237 // Vertical line 1237 // Vertical line
1238 return true; 1238 return true;
1239 } 1239 }
1240 1240
1241 // Horizontal line 1241 // Horizontal line
1242 return false; 1242 return false;
1243 } 1243 }
1244 1244
1245 /// <summary> 1245 /// <summary>
1246 /// Get distance between two point 1246 /// Get distance between two point
1247 /// </summary> 1247 /// </summary>
1248 /// <param name="point1">Point 1</param> 1248 /// <param name="point1">Point 1</param>
1249 /// <param name="point2">Point 2</param> 1249 /// <param name="point2">Point 2</param>
1250 /// <returns>Distance between two point</returns> 1250 /// <returns>Distance between two point</returns>
1251 private double GetDistance(Point point1, Point point2) 1251 private double GetDistance(Point point1, Point point2)
1252 { 1252 {
1253 //pythagorean theorem c^2 = a^2 + b^2 1253 //pythagorean theorem c^2 = a^2 + b^2
1254 //thus c = square root(a^2 + b^2) 1254 //thus c = square root(a^2 + b^2)
1255 double a = (double)(point2.X - point1.X); 1255 double a = (double)(point2.X - point1.X);
1256 double b = (double)(point2.Y - point1.Y); 1256 double b = (double)(point2.Y - point1.Y);
1257 1257
1258 return Math.Sqrt(a * a + b * b); 1258 return Math.Sqrt(a * a + b * b);
1259 } 1259 }
1260 1260
1261 /// <summary> 1261 /// <summary>
1262 /// Check point is valid for draw 1262 /// Check point is valid for draw
1263 /// </summary> 1263 /// </summary>
1264 /// <param name="point">Poit need check</param> 1264 /// <param name="point">Poit need check</param>
1265 /// <returns>true:Valid, false:Invalid</returns> 1265 /// <returns>true:Valid, false:Invalid</returns>
1266 private bool IsValidPoint(Point point) 1266 private bool IsValidPoint(Point point)
1267 { 1267 {
1268 return true; 1268 return true;
1269 } 1269 }
1270 1270
1271 /// <summary> 1271 /// <summary>
1272 /// Display coordinate position 1272 /// Display coordinate position
1273 /// </summary> 1273 /// </summary>
1274 /// <param name="point">Position to display</param> 1274 /// <param name="point">Position to display</param>
1275 private void DisplayCoordinate(Point point) 1275 private void DisplayCoordinate(Point point)
1276 { 1276 {
1277 if (_displayAxiPosition == null) 1277 if (_displayAxiPosition == null)
1278 { 1278 {
1279 _displayAxiPosition = new ucDisplayCoordinate(); 1279 _displayAxiPosition = new ucDisplayCoordinate();
1280 this.Children.Add(_displayAxiPosition); 1280 this.Children.Add(_displayAxiPosition);
1281 } 1281 }
1282 _displayAxiPosition.Display(point); 1282 _displayAxiPosition.Display(point);
1283 } 1283 }
1284 1284
1285 #endregion 1285 #endregion
1286 1286
1287 #region Functions for Set Auto Nodes 1287 #region Functions for Set Auto Nodes
1288 1288
1289 /// <summary> 1289 /// <summary>
1290 /// SetAutoNodes 1290 /// SetAutoNodes
1291 /// </summary> 1291 /// </summary>
1292 public void SetAutoNodes() 1292 public void SetAutoNodes()
1293 { 1293 {
1294 double radiusStart = DISTANCE_START_NODES; 1294 double radiusStart = DISTANCE_START_NODES;
1295 double radiusEnd = DISTANCE_END_NODES; 1295 double radiusEnd = DISTANCE_END_NODES;
1296 double radiusCurver = RADIUS_CURVER_LINE; 1296 double radiusCurver = RADIUS_CURVER_LINE;
1297 1297
1298 Point startNode; 1298 Point startNode;
1299 Point endNode; 1299 Point endNode;
1300 1300
1301 gGrpBlueNode.Children.Clear(); 1301 gGrpBlueNode.Children.Clear();
1302 1302
1303 if (gGrpLine.Children.Count == 1) 1303 if (gGrpLine.Children.Count == 1)
1304 radiusCurver = radiusEnd; 1304 radiusCurver = radiusEnd;
1305 1305
1306 if (gGrpLine.Children.Count > 0) 1306 if (gGrpLine.Children.Count > 0)
1307 { 1307 {
1308 for (int i = 0; i < gGrpLine.Children.Count; i++) 1308 for (int i = 0; i < gGrpLine.Children.Count; i++)
1309 { 1309 {
1310 LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[i]; 1310 LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[i];
1311 if (i == 0) 1311 if (i == 0)
1312 { 1312 {
1313 startNode = lineGeometry.EndPoint; 1313 startNode = lineGeometry.EndPoint;
1314 endNode = lineGeometry.StartPoint; 1314 endNode = lineGeometry.StartPoint;
1315 DrawAutoNodes(startNode, endNode, radiusCurver, radiusStart); 1315 DrawAutoNodes(startNode, endNode, radiusCurver, radiusStart);
1316 } 1316 }
1317 else if (i == gGrpLine.Children.Count - 1 && i > 0) 1317 else if (i == gGrpLine.Children.Count - 1 && i > 0)
1318 { 1318 {
1319 startNode = lineGeometry.StartPoint; 1319 startNode = lineGeometry.StartPoint;
1320 endNode = lineGeometry.EndPoint; 1320 endNode = lineGeometry.EndPoint;
1321 DrawAutoNodes(startNode, endNode, radiusCurver, radiusEnd); 1321 DrawAutoNodes(startNode, endNode, radiusCurver, radiusEnd);
1322 } 1322 }
1323 else 1323 else
1324 { 1324 {
1325 startNode = lineGeometry.StartPoint; 1325 startNode = lineGeometry.StartPoint;
1326 endNode = lineGeometry.EndPoint; 1326 endNode = lineGeometry.EndPoint;
1327 DrawAutoNodes(startNode, endNode, radiusCurver, radiusCurver); 1327 DrawAutoNodes(startNode, endNode, radiusCurver, radiusCurver);
1328 } 1328 }
1329 } 1329 }
1330 } 1330 }
1331 } 1331 }
1332 1332
1333 1333
1334 /// <summary> 1334 /// <summary>
1335 /// DrawAutoNodes 1335 /// DrawAutoNodes
1336 /// </summary> 1336 /// </summary>
1337 /// <param name="startNode"></param> 1337 /// <param name="startNode"></param>
1338 /// <param name="endNode"></param> 1338 /// <param name="endNode"></param>
1339 /// <param name="radiusStart"></param> 1339 /// <param name="radiusStart"></param>
1340 /// <param name="radiusEnd"></param> 1340 /// <param name="radiusEnd"></param>
1341 private void DrawAutoNodes(Point startNode, Point endNode, double radiusStart, double radiusEnd) 1341 private void DrawAutoNodes(Point startNode, Point endNode, double radiusStart, double radiusEnd)
1342 { 1342 {
1343 double distance = DISTANCE_AUTO_NODES; 1343 double distance = DISTANCE_AUTO_NODES;
1344 double i; 1344 double i;
1345 1345
1346 Point node; 1346 Point node;
1347 1347
1348 // Get postion of blue node on line 1348 // Get postion of blue node on line
1349 if (startNode.X == endNode.X) 1349 if (startNode.X == endNode.X)
1350 { 1350 {
1351 if (startNode.Y > endNode.Y) 1351 if (startNode.Y > endNode.Y)
1352 { 1352 {
1353 i = startNode.Y - radiusStart; 1353 i = startNode.Y - radiusStart;
1354 if (i - distance > endNode.Y + radiusEnd) 1354 if (i - distance > endNode.Y + radiusEnd)
1355 { 1355 {
1356 do 1356 do
1357 { 1357 {
1358 i = i - distance; 1358 i = i - distance;
1359 node = new Point(endNode.X, i); 1359 node = new Point(endNode.X, i);
1360 // Add node to postion distance 1000mm 1360 // Add node to postion distance 1000mm
1361 AddNode(node, gGrpBlueNode); 1361 AddNode(node, gGrpBlueNode);
1362 1362
1363 } while (i > endNode.Y + radiusEnd + distance); 1363 } while (i > endNode.Y + radiusEnd + distance);
1364 } 1364 }
1365 } 1365 }
1366 else 1366 else
1367 { 1367 {
1368 i = startNode.Y + radiusStart; 1368 i = startNode.Y + radiusStart;
1369 if (i + distance < endNode.Y - radiusEnd) 1369 if (i + distance < endNode.Y - radiusEnd)
1370 { 1370 {
1371 do 1371 do
1372 { 1372 {
1373 i = i + distance; 1373 i = i + distance;
1374 node = new Point(endNode.X, i); 1374 node = new Point(endNode.X, i);
1375 // Add node to postion distance 1000mm 1375 // Add node to postion distance 1000mm
1376 AddNode(node, gGrpBlueNode); 1376 AddNode(node, gGrpBlueNode);
1377 } while (i < endNode.Y - radiusEnd - distance); 1377 } while (i < endNode.Y - radiusEnd - distance);
1378 } 1378 }
1379 } 1379 }
1380 } 1380 }
1381 else 1381 else
1382 { 1382 {
1383 if (startNode.X > endNode.X) 1383 if (startNode.X > endNode.X)
1384 { 1384 {
1385 i = startNode.X - radiusStart; 1385 i = startNode.X - radiusStart;
1386 if (i - distance > endNode.X + radiusEnd) 1386 if (i - distance > endNode.X + radiusEnd)
1387 { 1387 {
1388 do 1388 do
1389 { 1389 {
1390 i = i - distance; 1390 i = i - distance;
1391 node = new Point(i, endNode.Y); 1391 node = new Point(i, endNode.Y);
1392 // Add node to postion distance 1000mm 1392 // Add node to postion distance 1000mm
1393 AddNode(node, gGrpBlueNode); 1393 AddNode(node, gGrpBlueNode);
1394 } while (i > endNode.X + radiusEnd + distance); 1394 } while (i > endNode.X + radiusEnd + distance);
1395 } 1395 }
1396 } 1396 }
1397 else 1397 else
1398 { 1398 {
1399 i = startNode.X + radiusStart; 1399 i = startNode.X + radiusStart;
1400 if (i + distance < endNode.X - radiusEnd) 1400 if (i + distance < endNode.X - radiusEnd)
1401 { 1401 {
1402 do 1402 do
1403 { 1403 {
1404 i = i + distance; 1404 i = i + distance;
1405 node = new Point(i, endNode.Y); 1405 node = new Point(i, endNode.Y);
1406 // Add node to postion distance 1000mm 1406 // Add node to postion distance 1000mm
1407 AddNode(node, gGrpBlueNode); 1407 AddNode(node, gGrpBlueNode);
1408 } while (i < endNode.X - radiusEnd - distance); 1408 } while (i < endNode.X - radiusEnd - distance);
1409 } 1409 }
1410 } 1410 }
1411 } 1411 }
1412 1412
1413 } 1413 }
1414 1414
1415 #endregion 1415 #endregion
1416 1416
1417 #region Functions for Set Free Nodes 1417 #region Functions for Set Free Nodes
1418 /// <summary> 1418 /// <summary>
1419 /// Draw Auto Blue node 1419 /// Draw Auto Blue node
1420 /// </summary> 1420 /// </summary>
1421 1421
1422 public void SetFreeNodes(Point FreeNode, bool RightClick) 1422 public void SetFreeNodes(Point FreeNode, bool RightClick)
1423 { 1423 {
1424 double radiusStart = DISTANCE_START_NODES; 1424 double radiusStart = DISTANCE_START_NODES;
1425 double radiusEnd = DISTANCE_END_NODES; 1425 double radiusEnd = DISTANCE_END_NODES;
1426 double radiusNode = RADIUS_NODE; 1426 double radiusNode = RADIUS_NODE;
1427 double radiusCurver = RADIUS_CURVER_LINE + RADIUS_NODE; 1427 double radiusCurver = RADIUS_CURVER_LINE + RADIUS_NODE;
1428 1428
1429 EllipseGeometry ellipseGeometry; 1429 EllipseGeometry ellipseGeometry;
1430 Point node; 1430 Point node;
1431 bool deleteFlag = false; 1431 bool deleteFlag = false;
1432 1432
1433 1433
1434 if (RightClick) 1434 if (RightClick)
1435 { 1435 {
1436 if (gGrpBlueNode.Children.Count > 0) 1436 if (gGrpBlueNode.Children.Count > 0)
1437 { 1437 {
1438 for (int i = 0; i < gGrpBlueNode.Children.Count; i++) 1438 for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
1439 { 1439 {
1440 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; 1440 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
1441 node = ellipseGeometry.Center; 1441 node = ellipseGeometry.Center;
1442 if (FreeNode.X == node.X) 1442 if (FreeNode.X == node.X)
1443 { 1443 {
1444 if (CheckIsNode(FreeNode, node, radiusNode)) 1444 if (CheckIsNode(FreeNode, node, radiusNode))
1445 { 1445 {
1446 deleteFlag = true; 1446 deleteFlag = true;
1447 } 1447 }
1448 } 1448 }
1449 else 1449 else
1450 { 1450 {
1451 if (CheckIsNode(FreeNode, node, radiusNode)) 1451 if (CheckIsNode(FreeNode, node, radiusNode))
1452 { 1452 {
1453 deleteFlag = true; 1453 deleteFlag = true;
1454 } 1454 }
1455 } 1455 }
1456 if (deleteFlag) 1456 if (deleteFlag)
1457 { 1457 {
1458 MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel); 1458 MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel);
1459 if (result == MessageBoxResult.OK) 1459 if (result == MessageBoxResult.OK)
1460 { 1460 {
1461 gGrpBlueNode.Children.RemoveAt(i); 1461 gGrpBlueNode.Children.RemoveAt(i);
1462 1462
1463 this.Children.Remove(NodeNo[i]); 1463 this.Children.Remove(NodeNo[i]);
1464 return; 1464 return;
1465 } 1465 }
1466 else 1466 else
1467 { 1467 {
1468 return; 1468 return;
1469 } 1469 }
1470 } 1470 }
1471 } 1471 }
1472 } 1472 }
1473 } 1473 }
1474 else 1474 else
1475 { 1475 {
1476 1476
1477 for (int i = 0; i < gGrpBlueNode.Children.Count; i++) 1477 for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
1478 { 1478 {
1479 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; 1479 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
1480 node = ellipseGeometry.Center; 1480 node = ellipseGeometry.Center;
1481 bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE); 1481 bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE);
1482 1482
1483 if (isEditNode) 1483 if (isEditNode)
1484 { 1484 {
1485 EditNode(node); 1485 EditNode(node);
1486 return; 1486 return;
1487 } 1487 }
1488 } 1488 }
1489 1489
1490 1490
1491 MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel); 1491 MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel);
1492 if (result == MessageBoxResult.OK) 1492 if (result == MessageBoxResult.OK)
1493 { 1493 {
1494 AddNode(FreeNode, gGrpBlueNode); 1494 AddNode(FreeNode, gGrpBlueNode);
1495 1495
1496 TextBlock textBlock = new TextBlock(); 1496 TextBlock textBlock = new TextBlock();
1497 textBlock.Text = stt.ToString(); 1497 textBlock.Text = stt.ToString();
1498 textBlock.FontSize = 17; 1498 textBlock.FontSize = 17;
1499 textBlock.Foreground = new SolidColorBrush(Colors.Red); 1499 textBlock.Foreground = new SolidColorBrush(Colors.Red);
1500 Canvas.SetLeft(textBlock, FreeNode.X - RADIUS_NODE / 2); 1500 Canvas.SetLeft(textBlock, FreeNode.X - RADIUS_NODE / 2);
1501 Canvas.SetTop(textBlock, FreeNode.Y - 1.5 * RADIUS_NODE); 1501 Canvas.SetTop(textBlock, FreeNode.Y - 1.5 * RADIUS_NODE);
1502 1502
1503 this.Children.Add(textBlock); 1503 this.Children.Add(textBlock);
1504 NodeNo.Add(textBlock); 1504 NodeNo.Add(textBlock);
1505 1505
1506 if (stt > 1) 1506 if (stt > 1)
1507 { 1507 {
1508 int tmp = gGrpBlueNode.Children.Count; 1508 int tmp = gGrpBlueNode.Children.Count;
1509 1509
1510 EllipseGeometry elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 2]; 1510 EllipseGeometry elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 2];
1511 Point node1 = elip.Center; 1511 Point node1 = elip.Center;
1512 elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 1]; 1512 elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 1];
1513 Point node2 = elip.Center; 1513 Point node2 = elip.Center;
1514 DrawLine(node1, node2, gGrpCurverLine); 1514 DrawLine(node1, node2, gGrpCurverLine);
1515 } 1515 }
1516 1516
1517 1517
1518 stt++; 1518 stt++;
1519 } 1519 }
1520 } 1520 }
1521 1521
1522 if (gGrpLine.Children.Count > 0) 1522 if (gGrpLine.Children.Count > 0)
1523 { 1523 {
1524 for (int i = 0; i < gGrpLine.Children.Count; i++) 1524 for (int i = 0; i < gGrpLine.Children.Count; i++)
1525 { 1525 {
1526 LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[i]; 1526 LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[i];
1527 1527
1528 // Get postion of node on line 1528 // Get postion of node on line
1529 if (IsVerticalLine(lineGeometry)) 1529 if (IsVerticalLine(lineGeometry))
1530 { 1530 {
1531 if (FreeNode.X < lineGeometry.EndPoint.X + radiusNode && FreeNode.X > lineGeometry.EndPoint.X - radiusNode) 1531 if (FreeNode.X < lineGeometry.EndPoint.X + radiusNode && FreeNode.X > lineGeometry.EndPoint.X - radiusNode)
1532 { 1532 {
1533 FreeNode.X = lineGeometry.EndPoint.X; 1533 FreeNode.X = lineGeometry.EndPoint.X;
1534 1534
1535 if (i == 0) 1535 if (i == 0)
1536 { 1536 {
1537 if (CheckFreeNodes(lineGeometry, FreeNode, radiusStart, radiusCurver)) 1537 if (CheckFreeNodes(lineGeometry, FreeNode, radiusStart, radiusCurver))
1538 { 1538 {
1539 1539
1540 AddNode(FreeNode, gGrpBlueNode); 1540 AddNode(FreeNode, gGrpBlueNode);
1541 } 1541 }
1542 } 1542 }
1543 else if (i == gGrpLine.Children.Count - 1 && i > 0) 1543 else if (i == gGrpLine.Children.Count - 1 && i > 0)
1544 { 1544 {
1545 if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusEnd)) 1545 if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusEnd))
1546 { 1546 {
1547 1547
1548 AddNode(FreeNode, gGrpBlueNode); 1548 AddNode(FreeNode, gGrpBlueNode);
1549 } 1549 }
1550 } 1550 }
1551 else 1551 else
1552 { 1552 {
1553 if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusCurver)) 1553 if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusCurver))
1554 { 1554 {
1555 1555
1556 AddNode(FreeNode, gGrpBlueNode); 1556 AddNode(FreeNode, gGrpBlueNode);
1557 } 1557 }
1558 } 1558 }
1559 1559
1560 } 1560 }
1561 } 1561 }
1562 else 1562 else
1563 { 1563 {
1564 if (FreeNode.Y < lineGeometry.EndPoint.Y + radiusNode && FreeNode.Y > lineGeometry.EndPoint.Y - radiusNode) 1564 if (FreeNode.Y < lineGeometry.EndPoint.Y + radiusNode && FreeNode.Y > lineGeometry.EndPoint.Y - radiusNode)
1565 { 1565 {
1566 FreeNode.Y = lineGeometry.EndPoint.Y; 1566 FreeNode.Y = lineGeometry.EndPoint.Y;
1567 if (i == 0) 1567 if (i == 0)
1568 { 1568 {
1569 if (CheckFreeNodes(lineGeometry, FreeNode, radiusStart, radiusCurver)) 1569 if (CheckFreeNodes(lineGeometry, FreeNode, radiusStart, radiusCurver))
1570 { 1570 {
1571 1571
1572 AddNode(FreeNode, gGrpBlueNode); 1572 AddNode(FreeNode, gGrpBlueNode);
1573 } 1573 }
1574 } 1574 }
1575 else if (i == gGrpLine.Children.Count - 1 && i > 0) 1575 else if (i == gGrpLine.Children.Count - 1 && i > 0)
1576 { 1576 {
1577 if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusEnd)) 1577 if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusEnd))
1578 { 1578 {
1579 1579
1580 AddNode(FreeNode, gGrpBlueNode); 1580 AddNode(FreeNode, gGrpBlueNode);
1581 } 1581 }
1582 } 1582 }
1583 else 1583 else
1584 { 1584 {
1585 if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusCurver)) 1585 if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusCurver))
1586 { 1586 {
1587 1587
1588 AddNode(FreeNode, gGrpBlueNode); 1588 AddNode(FreeNode, gGrpBlueNode);
1589 } 1589 }
1590 } 1590 }
1591 1591
1592 } 1592 }
1593 } 1593 }
1594 } 1594 }
1595 } 1595 }
1596 } 1596 }
1597 1597
1598 1598
1599 public bool CheckFreeNodes(LineGeometry lineNode, Point Freenode, double radiusStart, double radiusEnd) 1599 public bool CheckFreeNodes(LineGeometry lineNode, Point Freenode, double radiusStart, double radiusEnd)
1600 { 1600 {
1601 1601
1602 double distanceFreeNode = DISTANCE_FREE_NODES; 1602 double distanceFreeNode = DISTANCE_FREE_NODES;
1603 double radiusNode = RADIUS_NODE; 1603 double radiusNode = RADIUS_NODE;
1604 EllipseGeometry ellipseGeometry; 1604 EllipseGeometry ellipseGeometry;
1605 Point node; 1605 Point node;
1606 1606
1607 if (IsVerticalLine(lineNode)) 1607 if (IsVerticalLine(lineNode))
1608 { 1608 {
1609 if (lineNode.StartPoint.Y < lineNode.EndPoint.Y) 1609 if (lineNode.StartPoint.Y < lineNode.EndPoint.Y)
1610 { 1610 {
1611 if (Freenode.Y < lineNode.StartPoint.Y + radiusStart || Freenode.Y > lineNode.EndPoint.Y - radiusEnd) 1611 if (Freenode.Y < lineNode.StartPoint.Y + radiusStart || Freenode.Y > lineNode.EndPoint.Y - radiusEnd)
1612 { 1612 {
1613 return false; 1613 return false;
1614 } 1614 }
1615 } 1615 }
1616 else 1616 else
1617 { 1617 {
1618 if (Freenode.Y > lineNode.StartPoint.Y - radiusStart || Freenode.Y < lineNode.EndPoint.Y + radiusEnd) 1618 if (Freenode.Y > lineNode.StartPoint.Y - radiusStart || Freenode.Y < lineNode.EndPoint.Y + radiusEnd)
1619 { 1619 {
1620 return false; 1620 return false;
1621 } 1621 }
1622 } 1622 }
1623 } 1623 }
1624 else 1624 else
1625 { 1625 {
1626 if (lineNode.StartPoint.X < lineNode.EndPoint.X) 1626 if (lineNode.StartPoint.X < lineNode.EndPoint.X)
1627 { 1627 {
1628 if (Freenode.X < lineNode.StartPoint.X + radiusStart || Freenode.X > lineNode.EndPoint.X - radiusEnd) 1628 if (Freenode.X < lineNode.StartPoint.X + radiusStart || Freenode.X > lineNode.EndPoint.X - radiusEnd)
1629 { 1629 {
1630 return false; 1630 return false;
1631 } 1631 }
1632 } 1632 }
1633 else 1633 else
1634 { 1634 {
1635 if (Freenode.X > lineNode.StartPoint.X - radiusStart || Freenode.X < lineNode.EndPoint.X + radiusEnd) 1635 if (Freenode.X > lineNode.StartPoint.X - radiusStart || Freenode.X < lineNode.EndPoint.X + radiusEnd)
1636 { 1636 {
1637 return false; 1637 return false;
1638 } 1638 }
1639 } 1639 }
1640 } 1640 }
1641 1641
1642 if (gGrpBlueNode.Children.Count > 0) 1642 if (gGrpBlueNode.Children.Count > 0)
1643 { 1643 {
1644 for (int i = 0; i < gGrpBlueNode.Children.Count; i++) 1644 for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
1645 { 1645 {
1646 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; 1646 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
1647 node = ellipseGeometry.Center; 1647 node = ellipseGeometry.Center;
1648 if (Freenode.X == node.X) 1648 if (Freenode.X == node.X)
1649 { 1649 {
1650 if (CheckIsNode(Freenode, node, radiusNode)) 1650 if (CheckIsNode(Freenode, node, radiusNode))
1651 { 1651 {
1652 return false; 1652 return false;
1653 } 1653 }
1654 else if (Freenode.Y < node.Y + distanceFreeNode && Freenode.Y > node.Y - distanceFreeNode) 1654 else if (Freenode.Y < node.Y + distanceFreeNode && Freenode.Y > node.Y - distanceFreeNode)
1655 { 1655 {
1656 return false; 1656 return false;
1657 } 1657 }
1658 } 1658 }
1659 else if (Freenode.Y == node.Y) 1659 else if (Freenode.Y == node.Y)
1660 { 1660 {
1661 if (CheckIsNode(Freenode, node, radiusNode)) 1661 if (CheckIsNode(Freenode, node, radiusNode))
1662 { 1662 {
1663 return false; 1663 return false;
1664 } 1664 }
1665 else if (Freenode.X < node.X + distanceFreeNode && Freenode.X > node.X - distanceFreeNode) 1665 else if (Freenode.X < node.X + distanceFreeNode && Freenode.X > node.X - distanceFreeNode)
1666 { 1666 {
1667 return false; 1667 return false;
1668 } 1668 }
1669 } 1669 }
1670 } 1670 }
1671 } 1671 }
1672 1672
1673 return true; 1673 return true;
1674 } 1674 }
1675 1675
1676 public bool CheckIsNode(Point FreeNode, Point Node, double radiusNode) 1676 public bool CheckIsNode(Point FreeNode, Point Node, double radiusNode)
1677 { 1677 {
1678 if (FreeNode.X < Node.X + radiusNode && FreeNode.X > Node.X - radiusNode && FreeNode.Y < Node.Y + radiusNode && FreeNode.Y > Node.Y - radiusNode) 1678 if (FreeNode.X < Node.X + radiusNode && FreeNode.X > Node.X - radiusNode && FreeNode.Y < Node.Y + radiusNode && FreeNode.Y > Node.Y - radiusNode)
1679 { 1679 {
1680 return true; 1680 return true;
1681 } 1681 }
1682 return false; 1682 return false;
1683 } 1683 }
1684 1684
1685 #endregion 1685 #endregion
1686 1686
1687 #region Edit Node 1687 #region Edit Node
1688 public void InitNodeInfo_List() 1688 public void InitNodeInfo_List()
1689 { 1689 {
1690 //Reset List 1690 //Reset List
1691 NodeInfo_List = new List<NodeInfo>(); 1691 NodeInfo_List = new List<NodeInfo>();
1692 1692
1693 if (gGrpBlueNode.Children.Count > 0) 1693 if (gGrpBlueNode.Children.Count > 0)
1694 { 1694 {
1695 // Get start point 1695 // Get start point
1696 LineGeometry lineGeometry = (LineGeometry)gGrpNewLine.Children[0]; 1696 LineGeometry lineGeometry = (LineGeometry)gGrpNewLine.Children[0];
1697 Point startPoint = lineGeometry.StartPoint; 1697 Point startPoint = lineGeometry.StartPoint;
1698 1698
1699 NodeInfo n1 = new NodeInfo(); 1699 NodeInfo n1 = new NodeInfo();
1700 n1.X = startPoint.X; 1700 n1.X = startPoint.X;
1701 n1.Y = startPoint.Y; 1701 n1.Y = startPoint.Y;
1702 n1.Mode1 = ""; 1702 n1.Mode1 = "";
1703 n1.Mode2 = ""; 1703 n1.Mode2 = "";
1704 n1.Mode3 = ""; 1704 n1.Mode3 = "";
1705 NodeInfo_List.Add(n1); 1705 NodeInfo_List.Add(n1);
1706 1706
1707 for (int i = 0; i < gGrpBlueNode.Children.Count; i++) 1707 for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
1708 { 1708 {
1709 Point point; 1709 Point point;
1710 EllipseGeometry eGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; 1710 EllipseGeometry eGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
1711 point = eGeometry.Center; 1711 point = eGeometry.Center;
1712 1712
1713 NodeInfo Ninfo = new NodeInfo(); 1713 NodeInfo Ninfo = new NodeInfo();
1714 Ninfo.X = point.X; 1714 Ninfo.X = point.X;
1715 Ninfo.Y = point.Y; 1715 Ninfo.Y = point.Y;
1716 1716
1717 Ninfo.Mode1 = ""; 1717 Ninfo.Mode1 = "";
1718 Ninfo.Mode2 = ""; 1718 Ninfo.Mode2 = "";
1719 Ninfo.Mode3 = ""; 1719 Ninfo.Mode3 = "";
1720 1720
1721 NodeInfo_List.Add(Ninfo); 1721 NodeInfo_List.Add(Ninfo);
1722 } 1722 }
1723 1723
1724 // Get end point 1724 // Get end point
1725 lineGeometry = (LineGeometry)gGrpLine.Children[gGrpLine.Children.Count -1]; 1725 lineGeometry = (LineGeometry)gGrpLine.Children[gGrpLine.Children.Count -1];
1726 Point endPoint = lineGeometry.EndPoint; 1726 Point endPoint = lineGeometry.EndPoint;
1727 1727
1728 NodeInfo n2 = new NodeInfo(); 1728 NodeInfo n2 = new NodeInfo();
1729 n2.X = startPoint.X; 1729 n2.X = startPoint.X;
1730 n2.Y = startPoint.Y; 1730 n2.Y = startPoint.Y;
1731 n2.Mode1 = ""; 1731 n2.Mode1 = "";
1732 n2.Mode2 = ""; 1732 n2.Mode2 = "";
1733 n2.Mode3 = ""; 1733 n2.Mode3 = "";
1734 NodeInfo_List.Add(n2); 1734 NodeInfo_List.Add(n2);
1735 1735
1736 //Resort NodeInfo_List From Start to Goal 1736 //Resort NodeInfo_List From Start to Goal
1737 LineGeometry firstLine = (LineGeometry)gGrpLine.Children[0]; 1737 LineGeometry firstLine = (LineGeometry)gGrpLine.Children[0];
1738 Point startNode = firstLine.StartPoint; 1738 Point startNode = firstLine.StartPoint;
1739 Point endNode = firstLine.EndPoint; 1739 Point endNode = firstLine.EndPoint;
1740 1740
1741 1741
1742 List<NodeInfo> tmpLst = new List<NodeInfo>(); 1742 List<NodeInfo> tmpLst = new List<NodeInfo>();
1743 1743
1744 // Create temp List 1744 // Create temp List
1745 if(startNode.X == endNode.X) 1745 if(startNode.X == endNode.X)
1746 { 1746 {
1747 for (int i = 1; i < NodeInfo_List.Count; i++) 1747 for (int i = 1; i < NodeInfo_List.Count; i++)
1748 { 1748 {
1749 if (NodeInfo_List[i].X != endNode.X) 1749 if (NodeInfo_List[i].X != endNode.X)
1750 { 1750 {
1751 break; 1751 break;
1752 } 1752 }
1753 else 1753 else
1754 { 1754 {
1755 tmpLst.Add(NodeInfo_List[i]); 1755 tmpLst.Add(NodeInfo_List[i]);
1756 } 1756 }
1757 } 1757 }
1758 } 1758 }
1759 1759
1760 if (startNode.Y == endNode.Y) 1760 if (startNode.Y == endNode.Y)
1761 { 1761 {
1762 for (int i = 1; i < NodeInfo_List.Count; i++) 1762 for (int i = 1; i < NodeInfo_List.Count; i++)
1763 { 1763 {
1764 if (NodeInfo_List[i].Y != endNode.Y) 1764 if (NodeInfo_List[i].Y != endNode.Y)
1765 { 1765 {
1766 break; 1766 break;
1767 } 1767 }
1768 else 1768 else
1769 { 1769 {
1770 tmpLst.Add(NodeInfo_List[i]); 1770 tmpLst.Add(NodeInfo_List[i]);
1771 } 1771 }
1772 } 1772 }
1773 } 1773 }
1774 1774
1775 // Sort NodeInfo_List 1775 // Sort NodeInfo_List
1776 for (int i = 0; i < tmpLst.Count; i++) 1776 for (int i = 0; i < tmpLst.Count; i++)
1777 { 1777 {
1778 NodeInfo_List[i + 1] = tmpLst[tmpLst.Count -1 - i]; 1778 NodeInfo_List[i + 1] = tmpLst[tmpLst.Count -1 - i];
1779 } 1779 }
1780 1780
1781 } 1781 }
1782 } 1782 }
1783 1783
1784 1784
1785 public void EditNode(Point node_edited) 1785 public void EditNode(Point node_edited)
1786 { 1786 {
1787 EllipseGeometry ellipseGeometry; 1787 EllipseGeometry ellipseGeometry;
1788 Point node; 1788 Point node;
1789 double radiusNode = RADIUS_NODE; 1789 double radiusNode = RADIUS_NODE;
1790 1790
1791 bool flag = false; 1791 bool flag = false;
1792 1792
1793 if (gGrpBlueNode.Children.Count > 0) 1793 if (gGrpBlueNode.Children.Count > 0)
1794 { 1794 {
1795 for (int i = 0; i < gGrpBlueNode.Children.Count; i++) 1795 for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
1796 { 1796 {
1797 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; 1797 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
1798 node = ellipseGeometry.Center; 1798 node = ellipseGeometry.Center;
1799 1799
1800 if (CheckIsNode(node_edited, node, radiusNode)) 1800 if (CheckIsNode(node_edited, node, radiusNode))
1801 { 1801 {
1802 flag = true; 1802 flag = true;
1803 } 1803 }
1804 1804
1805 if (flag) 1805 if (flag)
1806 { 1806 {
1807 node_edited.X = node.X; 1807 node_edited.X = node.X;
1808 node_edited.Y = node.Y; 1808 node_edited.Y = node.Y;
1809 1809
1810 // show form edit node 1810 // show form edit node
1811 EditNodeWindow edtNodeWindow = new EditNodeWindow(); 1811 EditNodeWindow edtNodeWindow = new EditNodeWindow();
1812 edtNodeWindow.ShowDialog(); 1812 edtNodeWindow.ShowDialog();
1813 1813
1814 string result1 = edtNodeWindow._txtMode1; 1814 string result1 = edtNodeWindow._txtMode1;
1815 string result2 = edtNodeWindow._txtMode2; 1815 string result2 = edtNodeWindow._txtMode2;
1816 string result3 = edtNodeWindow._txtMode3; 1816 string result3 = edtNodeWindow._txtMode3;
1817 bool exit = edtNodeWindow._ExitFlg; 1817 bool exit = edtNodeWindow._ExitFlg;
1818 1818
1819 if (!exit) { 1819 if (!exit) {
1820 SaveChanged(node_edited.X, node_edited.Y, result1, result2, result3); 1820 SaveChanged(node_edited.X, node_edited.Y, result1, result2, result3);
1821 } 1821 }
1822 1822
1823 return; 1823 return;
1824 } 1824 }
1825 } 1825 }
1826 } 1826 }
1827 } 1827 }
1828 1828
1829 public void SaveChanged(double x, double y, string st1, string st2, string st3) 1829 public void SaveChanged(double x, double y, string st1, string st2, string st3)
1830 { 1830 {
1831 for (int i = 0; i < NodeInfo_List.Count; i++) 1831 for (int i = 0; i < NodeInfo_List.Count; i++)
1832 { 1832 {
1833 NodeInfo ni = new NodeInfo(); 1833 NodeInfo ni = new NodeInfo();
1834 ni = NodeInfo_List[i]; 1834 ni = NodeInfo_List[i];
1835 1835
1836 if (ni.X == x && ni.Y == y) 1836 if (ni.X == x && ni.Y == y)
1837 { 1837 {
1838 1838
1839 ni.Mode1 = st1; 1839 ni.Mode1 = st1;
1840 ni.Mode2 = st2; 1840 ni.Mode2 = st2;
1841 ni.Mode3 = st3; 1841 ni.Mode3 = st3;
1842 1842
1843 NodeInfo_List[i] = ni; 1843 NodeInfo_List[i] = ni;
1844 return; 1844 return;
1845 } 1845 }
1846 } 1846 }
1847 } 1847 }
1848 1848
1849 1849
1850 #endregion 1850 #endregion
1851 1851
1852 #region Display RouteInfo 1852 #region Display RouteInfo
1853 1853
1854 public void DspRouteInfo() 1854 public void DspRouteInfo()
1855 { 1855 {
1856 //Clear Route Info Table 1856 //Clear Route Info Table
1857 ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Clear(); 1857 ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Clear();
1858 1858
1859 if (NodeInfo_List.Count != 0) 1859 if (NodeInfo_List.Count != 0)
1860 { 1860 {
1861 int _RowIdx = 0; 1861 int _RowIdx = 0;
1862 string _Content = ""; 1862 string _Content = "";
1863 1863
1864 for (int i = 0; i < NodeInfo_List.Count; i++) 1864 for (int i = 0; i < NodeInfo_List.Count; i++)
1865 { 1865 {
1866 1866
1867 NodeInfo ni = new NodeInfo(); 1867 NodeInfo ni = new NodeInfo();
1868 ni = NodeInfo_List[i]; 1868 ni = NodeInfo_List[i];
1869 1869
1870 //column 1 1870 //column 1
1871 if (i == 0) 1871 if (i == 0)
1872 { 1872 {
1873 _Content = "S"; 1873 _Content = "S";
1874 } 1874 }
1875 else if (i == NodeInfo_List.Count - 1) 1875 else if (i == NodeInfo_List.Count - 1)
1876 { 1876 {
1877 _Content = "G"; 1877 _Content = "G";
1878 } 1878 }
1879 else 1879 else
1880 { 1880 {
1881 _Content = i.ToString(); 1881 _Content = i.ToString();
1882 } 1882 }
1883 AddLabeltoGrid(_RowIdx, 0, _Content); 1883 AddLabeltoGrid(_RowIdx, 0, _Content);
1884 1884
1885 //column 2 1885 //column 2
1886 // Display Node's Position 1886 // Display Node's Position
1887 _Content = ni.X + ", " + ni.Y; 1887 _Content = ni.X + ", " + ni.Y;
1888 AddLabeltoGrid(_RowIdx, 1, _Content); 1888 AddLabeltoGrid(_RowIdx, 1, _Content);
1889 1889
1890 // Display Node's Field 1890 // Display Node's Field
1891 if (ni.Mode1 != "" && ni.Mode1 != null) 1891 if (ni.Mode1 != "" && ni.Mode1 != null)
1892 { 1892 {
1893 char delimiterChars = '_'; 1893 char delimiterChars = '_';
1894 string[] tmp = ni.Mode1.Split(delimiterChars); 1894 string[] tmp = ni.Mode1.Split(delimiterChars);
1895 foreach (string s in tmp) 1895 foreach (string s in tmp)
1896 { 1896 {
1897 _RowIdx++; 1897 _RowIdx++;
1898 delimiterChars = ':'; 1898 delimiterChars = ':';
1899 1899
1900 if (s.Split(delimiterChars)[0] == "Mode") 1900 if (s.Split(delimiterChars)[0] == "Mode")
1901 { 1901 {
1902 double distance = 0; 1902 double distance = 0;
1903 if (i == NodeInfo_List.Count - 1) 1903 if (i == NodeInfo_List.Count - 1)
1904 { 1904 {
1905 distance = 0; 1905 distance = 0;
1906 } 1906 }
1907 else 1907 else
1908 { 1908 {
1909 distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y); 1909 distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y);
1910 } 1910 }
1911 _Content = "MOVE " + distance.ToString() + "mm"; 1911 _Content = "MOVE " + distance.ToString() + "mm";
1912 } 1912 }
1913 else 1913 else
1914 { 1914 {
1915 _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1]; 1915 _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1];
1916 } 1916 }
1917 1917
1918 AddLabeltoGrid(_RowIdx, 1, _Content); 1918 AddLabeltoGrid(_RowIdx, 1, _Content);
1919 } 1919 }
1920 } 1920 }
1921 1921
1922 if (ni.Mode2 != "" && ni.Mode2 != null) 1922 if (ni.Mode2 != "" && ni.Mode2 != null)
1923 { 1923 {
1924 char delimiterChars = '_'; 1924 char delimiterChars = '_';
1925 string[] tmp = ni.Mode2.Split(delimiterChars); 1925 string[] tmp = ni.Mode2.Split(delimiterChars);
1926 foreach (string s in tmp) 1926 foreach (string s in tmp)
1927 { 1927 {
1928 _RowIdx++; 1928 _RowIdx++;
1929 delimiterChars = ':'; 1929 delimiterChars = ':';
1930 1930
1931 if (s.Split(delimiterChars)[0] == "Mode") 1931 if (s.Split(delimiterChars)[0] == "Mode")
1932 { 1932 {
1933 double distance = 0; 1933 double distance = 0;
1934 if (i == NodeInfo_List.Count - 1) 1934 if (i == NodeInfo_List.Count - 1)
1935 { 1935 {
1936 distance = 0; 1936 distance = 0;
1937 } 1937 }
1938 else 1938 else
1939 { 1939 {
1940 distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y); 1940 distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y);
1941 } 1941 }
1942 _Content = "MOVE " + distance.ToString() + "mm"; 1942 _Content = "MOVE " + distance.ToString() + "mm";
1943 } 1943 }
1944 else 1944 else
1945 { 1945 {
1946 _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1]; 1946 _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1];
1947 } 1947 }
1948 1948
1949 AddLabeltoGrid(_RowIdx, 1, _Content); 1949 AddLabeltoGrid(_RowIdx, 1, _Content);
1950 } 1950 }
1951 } 1951 }
1952 1952
1953 if (ni.Mode3 != "" && ni.Mode3 != null) 1953 if (ni.Mode3 != "" && ni.Mode3 != null)
1954 { 1954 {
1955 char delimiterChars = '_'; 1955 char delimiterChars = '_';
1956 string[] tmp = ni.Mode3.Split(delimiterChars); 1956 string[] tmp = ni.Mode3.Split(delimiterChars);
1957 foreach (string s in tmp) 1957 foreach (string s in tmp)
1958 { 1958 {
1959 _RowIdx++; 1959 _RowIdx++;
1960 delimiterChars = ':'; 1960 delimiterChars = ':';
1961 1961
1962 if (s.Split(delimiterChars)[0] == "Mode") 1962 if (s.Split(delimiterChars)[0] == "Mode")
1963 { 1963 {
1964 double distance = 0; 1964 double distance = 0;
1965 if (i == NodeInfo_List.Count - 1) 1965 if (i == NodeInfo_List.Count - 1)
1966 { 1966 {
1967 distance = 0; 1967 distance = 0;
1968 } 1968 }
1969 else 1969 else
1970 { 1970 {
1971 distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y); 1971 distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y);
1972 } 1972 }
1973 _Content = "MOVE " + distance.ToString() + "mm"; 1973 _Content = "MOVE " + distance.ToString() + "mm";
1974 } 1974 }
1975 else 1975 else
1976 { 1976 {
1977 _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1]; 1977 _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1];
1978 } 1978 }
1979 1979
1980 AddLabeltoGrid(_RowIdx, 1, _Content); 1980 AddLabeltoGrid(_RowIdx, 1, _Content);
1981 } 1981 }
1982 } 1982 }
1983 _RowIdx++; 1983 _RowIdx++;
1984 } 1984 }
1985 } 1985 }
1986 } 1986 }
1987 1987
1988 public double DistanceCalculate(double _X1, double _Y1, double _X2, double _Y2) 1988 public double DistanceCalculate(double _X1, double _Y1, double _X2, double _Y2)
1989 { 1989 {
1990 double dist = 0; 1990 double dist = 0;
1991 1991
1992 if (_X1 == _X2) 1992 if (_X1 == _X2)
1993 { 1993 {
1994 dist = System.Math.Abs(_Y1 - _Y2) * DISTANCE_RATIO; 1994 dist = System.Math.Abs(_Y1 - _Y2) * DISTANCE_RATIO;
1995 } 1995 }
1996 else if (_Y1 == _Y2) 1996 else if (_Y1 == _Y2)
1997 { 1997 {
1998 dist = System.Math.Abs(_X1 - _X2) * DISTANCE_RATIO; 1998 dist = System.Math.Abs(_X1 - _X2) * DISTANCE_RATIO;
1999 } 1999 }
2000 return dist; 2000 return dist;
2001 } 2001 }
2002 2002
2003 public void AddLabeltoGrid(int RowIdx, int ColIdx, string Content) 2003 public void AddLabeltoGrid(int RowIdx, int ColIdx, string Content)
2004 { 2004 {
2005 //Add Row to Grid 2005 //Add Row to Grid
2006 RowDefinition _rd = new RowDefinition(); 2006 RowDefinition _rd = new RowDefinition();
2007 ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.RowDefinitions.Add(_rd); 2007 ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.RowDefinitions.Add(_rd);
2008 2008
2009 // Add data to Grid 2009 // Add data to Grid
2010 Label dynamicLabel = new Label(); 2010 Label dynamicLabel = new Label();
2011 2011
2012 dynamicLabel.Content = Content; 2012 dynamicLabel.Content = Content;
2013 dynamicLabel.Margin = new Thickness(0, 0, 0, 0); 2013 dynamicLabel.Margin = new Thickness(0, 0, 0, 0);
2014 dynamicLabel.Foreground = new SolidColorBrush(Colors.Black); 2014 dynamicLabel.Foreground = new SolidColorBrush(Colors.Black);
2015 dynamicLabel.Background = new SolidColorBrush(Colors.White); 2015 dynamicLabel.Background = new SolidColorBrush(Colors.White);
2016 dynamicLabel.BorderBrush = new SolidColorBrush(Colors.LightGray); 2016 dynamicLabel.BorderBrush = new SolidColorBrush(Colors.LightGray);
2017 dynamicLabel.BorderThickness = new Thickness(1); 2017 dynamicLabel.BorderThickness = new Thickness(1);
2018 2018
2019 Grid.SetRow(dynamicLabel, RowIdx); 2019 Grid.SetRow(dynamicLabel, RowIdx);
2020 Grid.SetColumn(dynamicLabel, ColIdx); 2020 Grid.SetColumn(dynamicLabel, ColIdx);
2021 ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Add(dynamicLabel); 2021 ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Add(dynamicLabel);
2022 } 2022 }
2023 #endregion 2023 #endregion
2024 2024
2025 2025
2026 public void CreateGoalPoint() 2026 public void CreateGoalPoint()
2027 { 2027 {
2028 if (isGoalDrawRoute) 2028 if (isGoalDrawRoute)
2029 { 2029 {
2030 return; 2030 return;
2031 } 2031 }
2032 2032
2033 isStartDrawRoute = false; 2033 isStartDrawRoute = false;
2034 if (_goalPoint == null) 2034 if (_goalPoint == null)
2035 { 2035 {
2036 _goalPoint = new ucStartEndButton(); 2036 _goalPoint = new ucStartEndButton();
2037 _goalPoint.btnWidth = 50.0; 2037 _goalPoint.btnWidth = 50.0;
2038 _goalPoint.btnHeight = 50.0; 2038 _goalPoint.btnHeight = 50.0;
2039 _goalPoint.buttText = "G"; 2039 _goalPoint.buttText = "G";
2040 Canvas.SetLeft(_goalPoint, 675); 2040 Canvas.SetLeft(_goalPoint, 675);
2041 Canvas.SetTop(_goalPoint, 75); 2041 Canvas.SetTop(_goalPoint, 75);
2042 this.Children.Add(_goalPoint); 2042 this.Children.Add(_goalPoint);
2043 } 2043 }
2044 } 2044 }
2045 2045
2046 public void CreateStartPoint() 2046 public void CreateStartPoint()
2047 { 2047 {
2048 if (isGoalDrawRoute) 2048 if (isGoalDrawRoute)
2049 { 2049 {
2050 return; 2050 return;
2051 } 2051 }
2052 2052
2053 isStartDrawRoute = false; 2053 isStartDrawRoute = false;
2054 if (_startPoint == null) 2054 if (_startPoint == null)
2055 { 2055 {
2056 _startPoint = new ucStartEndButton(); 2056 _startPoint = new ucStartEndButton();
2057 _startPoint.btnWidth = 50.0; 2057 _startPoint.btnWidth = 50.0;
2058 _startPoint.btnHeight = 50.0; 2058 _startPoint.btnHeight = 50.0;
2059 _startPoint.buttText = "S"; 2059 _startPoint.buttText = "S";
2060 Canvas.SetLeft(_startPoint, 75); 2060 Canvas.SetLeft(_startPoint, 75);
2061 Canvas.SetTop(_startPoint, 675); 2061 Canvas.SetTop(_startPoint, 675);
2062 this.Children.Add(_startPoint); 2062 this.Children.Add(_startPoint);
2063 } 2063 }
2064 } 2064 }
2065 2065
2066 2066
2067 #region Draw New FreeNode 2067 #region Draw New FreeNode
2068 2068
2069 /// <summary> 2069 /// <summary>
2070 /// Draw Auto Blue node 2070 /// Draw Auto Blue node
2071 /// </summary> 2071 /// </summary>
2072 2072
2073 2073
2074 public void NewSetFreeNodes(Point FreeNode, bool RightClick) 2074 public void NewSetFreeNodes(Point FreeNode, bool RightClick)
2075 { 2075 {
2076 double radiusNode = RADIUS_NODE; 2076 double radiusNode = RADIUS_NODE;
2077 2077
2078 EllipseGeometry ellipseGeometry; 2078 EllipseGeometry ellipseGeometry;
2079 Point node; 2079 Point node;
2080 bool deleteFlag = false; 2080 bool deleteFlag = false;
2081 2081
2082 2082
2083 if (RightClick) 2083 if (RightClick)
2084 { 2084 {
2085 if (gGrpBlueNode.Children.Count > 0) 2085 if (gGrpBlueNode.Children.Count > 0)
2086 { 2086 {
2087 for (int i = 0; i < gGrpBlueNode.Children.Count; i++) 2087 for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
2088 { 2088 {
2089 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; 2089 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
2090 node = ellipseGeometry.Center; 2090 node = ellipseGeometry.Center;
2091 if (FreeNode.X == node.X) 2091 if (FreeNode.X == node.X)
2092 { 2092 {
2093 if (CheckIsNode(FreeNode, node, radiusNode)) 2093 if (CheckIsNode(FreeNode, node, radiusNode))
2094 { 2094 {
2095 deleteFlag = true; 2095 deleteFlag = true;
2096 } 2096 }
2097 } 2097 }
2098 else 2098 else
2099 { 2099 {
2100 if (CheckIsNode(FreeNode, node, radiusNode)) 2100 if (CheckIsNode(FreeNode, node, radiusNode))
2101 { 2101 {
2102 deleteFlag = true; 2102 deleteFlag = true;
2103 } 2103 }
2104 } 2104 }
2105 if (deleteFlag) 2105 if (deleteFlag)
2106 { 2106 {
2107 MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel); 2107 MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel);
2108 if (result == MessageBoxResult.OK) 2108 if (result == MessageBoxResult.OK)
2109 { 2109 {
2110 //Call Function Delete Node 2110 //Call Function Delete Node
2111 DeleteNode(i); 2111 DeleteNode(i);
2112 2112
2113 return; 2113 return;
2114 } 2114 }
2115 else 2115 else
2116 { 2116 {
2117 return; 2117 return;
2118 } 2118 }
2119 } 2119 }
2120 } 2120 }
2121 } 2121 }
2122 } 2122 }
2123 else 2123 else
2124 { 2124 {
2125 //Check EditNode State 2125 //Check EditNode State
2126 for (int i = 0; i < gGrpBlueNode.Children.Count; i++) 2126 for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
2127 { 2127 {
2128 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; 2128 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
2129 node = ellipseGeometry.Center; 2129 node = ellipseGeometry.Center;
2130 bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE); 2130 bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE);
2131 2131
2132 if (isEditNode) 2132 if (isEditNode)
2133 { 2133 {
2134 NewEditNode(node); 2134 NewEditNode(node);
2135 NewDspRouteInfo(); 2135 NewDspRouteInfo();
2136 return; 2136 return;
2137 } 2137 }
2138 } 2138 }
2139 2139
2140 2140
2141 MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel); 2141 MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel);
2142 if (result == MessageBoxResult.OK) 2142 if (result == MessageBoxResult.OK)
2143 { 2143 {
2144 AddNode(FreeNode, gGrpBlueNode); 2144 AddNode(FreeNode, gGrpBlueNode);
2145 2145
2146 TextBlock textBlock = new TextBlock(); 2146 TextBlock textBlock = new TextBlock();
2147 textBlock.Text = stt.ToString(); 2147 textBlock.Text = stt.ToString();
2148 textBlock.FontSize = 35; 2148 textBlock.FontSize = 35;
2149 textBlock.VerticalAlignment = VerticalAlignment.Center; 2149 textBlock.VerticalAlignment = VerticalAlignment.Center;
2150 textBlock.HorizontalAlignment = HorizontalAlignment.Center; 2150 textBlock.HorizontalAlignment = HorizontalAlignment.Center;
2151 textBlock.Foreground = new SolidColorBrush(Colors.Red); 2151 textBlock.Foreground = new SolidColorBrush(Colors.Red);
2152 2152
2153 Canvas.SetLeft(textBlock, FreeNode.X - RADIUS_NODE / 2); 2153 Canvas.SetLeft(textBlock, FreeNode.X - RADIUS_NODE / 2);
2154 Canvas.SetTop(textBlock, FreeNode.Y - 1.5 * RADIUS_NODE); 2154 Canvas.SetTop(textBlock, FreeNode.Y - 1.5 * RADIUS_NODE);
2155 2155
2156 2156
2157 this.Children.Add(textBlock); 2157 this.Children.Add(textBlock);
2158 NodeNo.Add(textBlock); 2158 NodeNo.Add(textBlock);
2159 2159
2160 if (stt > 1) 2160 if (stt > 1)
2161 { 2161 {
2162 int tmp = gGrpBlueNode.Children.Count; 2162 int tmp = gGrpBlueNode.Children.Count;
2163 2163
2164 EllipseGeometry elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 2]; 2164 EllipseGeometry elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 2];
2165 Point node1 = elip.Center; 2165 Point node1 = elip.Center;
2166 elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 1]; 2166 elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 1];
2167 Point node2 = elip.Center; 2167 Point node2 = elip.Center;
2168 DrawLine(node1, node2, gGrpNewLine); 2168 DrawLine(node1, node2, gGrpNewLine);
2169 2169
2170 2170
2171 this.Children.Remove(pBlueNode); 2171 this.Children.Remove(pBlueNode);
2172 for (int i = 0; i < tmp; i++) 2172 for (int i = 0; i < tmp; i++)
2173 { 2173 {
2174 this.Children.Remove(NodeNo[i]); 2174 this.Children.Remove(NodeNo[i]);
2175 } 2175 }
2176 2176
2177 this.Children.Add(pBlueNode); 2177 this.Children.Add(pBlueNode);
2178 for (int i = 0; i < tmp; i++) 2178 for (int i = 0; i < tmp; i++)
2179 { 2179 {
2180 this.Children.Add(NodeNo[i]); 2180 this.Children.Add(NodeNo[i]);
2181 } 2181 }
2182 } 2182 }
2183 2183
2184 stt++; 2184 stt++;
2185 NewInitNodeInfo_List(); 2185 NewInitNodeInfo_List();
2186 NewDspRouteInfo(); 2186 NewDspRouteInfo();
2187 } 2187 }
2188 } 2188 }
2189 } 2189 }
2190 2190
2191 public void DeleteNode(int i) 2191 public void DeleteNode(int i)
2192 { 2192 {
2193 //DrawLine(Point startPoint, Point endPoint, GeometryGroup geometryGroup) 2193 //DrawLine(Point startPoint, Point endPoint, GeometryGroup geometryGroup)
2194 2194
2195 LineGeometry lineGeometry = new LineGeometry(); 2195 LineGeometry lineGeometry = new LineGeometry();
2196 EllipseGeometry ellip; 2196 EllipseGeometry ellip;
2197 2197
2198 //check delete last node 2198 //check delete last node
2199 if (i == gGrpBlueNode.Children.Count - 1) 2199 if (i == gGrpBlueNode.Children.Count - 1)
2200 { 2200 {
2201 // delete line 2201 // delete line
2202 if (gGrpNewLine.Children.Count > 0) 2202 if (gGrpNewLine.Children.Count > 0)
2203 { 2203 {
2204 gGrpNewLine.Children.RemoveAt(i - 1); 2204 gGrpNewLine.Children.RemoveAt(i - 1);
2205 } 2205 }
2206 2206
2207 // delete ucNode 2207 // delete ucNode
2208 ucNode _ucNode = new ucNode(); 2208 ucNode _ucNode = new ucNode();
2209 _ucNode = ucNode_Lst[i]; 2209 _ucNode = ucNode_Lst[i];
2210 this.Children.Remove(_ucNode); 2210 this.Children.Remove(_ucNode);
2211 ucNode_Lst.RemoveAt(i); 2211 ucNode_Lst.RemoveAt(i);
2212 2212
2213 // delete node 2213 // delete node
2214 gGrpBlueNode.Children.RemoveAt(i); 2214 gGrpBlueNode.Children.RemoveAt(i);
2215 NewNodeInfo_List.RemoveAt(i); 2215 NewNodeInfo_List.RemoveAt(i);
2216 2216
2217 } 2217 }
2218 else 2218 else
2219 { 2219 {
2220 //delete all line and remove Point at 'i' 2220 //delete all line and remove Point at 'i'
2221 gGrpNewLine.Children.Clear(); 2221 gGrpNewLine.Children.Clear();
2222 this.Children.Remove(pNewLine); 2222 this.Children.Remove(pNewLine);
2223 gGrpBlueNode.Children.RemoveAt(i); 2223 gGrpBlueNode.Children.RemoveAt(i);
2224 2224
2225 //redraw line 2225 //redraw line
2226 for (int j = 0; j < gGrpBlueNode.Children.Count - 1; j++) 2226 for (int j = 0; j < gGrpBlueNode.Children.Count - 1; j++)
2227 { 2227 {
2228 ellip = (EllipseGeometry)gGrpBlueNode.Children[j]; 2228 ellip = (EllipseGeometry)gGrpBlueNode.Children[j];
2229 Point node1 = ellip.Center; 2229 Point node1 = ellip.Center;
2230 ellip = (EllipseGeometry)gGrpBlueNode.Children[j + 1]; 2230 ellip = (EllipseGeometry)gGrpBlueNode.Children[j + 1];
2231 Point node2 = ellip.Center; 2231 Point node2 = ellip.Center;
2232 DrawLine(node1, node2, gGrpNewLine); 2232 DrawLine(node1, node2, gGrpNewLine);
2233 } 2233 }
2234 2234
2235 this.Children.Add(pNewLine); 2235 this.Children.Add(pNewLine);
2236 2236
2237 //remove ucNode 2237 //remove ucNode
2238 for (int j = ucNode_Lst.Count - 1; j > i; j--) 2238 for (int j = ucNode_Lst.Count - 1; j > i; j--)
2239 { 2239 {
2240 ucNode_Lst[j].txtNode = ucNode_Lst[j - 1].txtNode; 2240 ucNode_Lst[j].txtNode = ucNode_Lst[j - 1].txtNode;
2241 } 2241 }
2242 this.Children.Remove(ucNode_Lst[i]); 2242 this.Children.Remove(ucNode_Lst[i]);
2243 ucNode_Lst.RemoveAt(i); 2243 ucNode_Lst.RemoveAt(i);
2244 2244
2245 //redraw ucNode 2245 //redraw ucNode
2246 for (int k = 0; k < ucNode_Lst.Count; k++) 2246 for (int k = 0; k < ucNode_Lst.Count; k++)
2247 { 2247 {
2248 this.Children.Remove(ucNode_Lst[k]); 2248 this.Children.Remove(ucNode_Lst[k]);
2249 this.Children.Add(ucNode_Lst[k]); 2249 this.Children.Add(ucNode_Lst[k]);
2250 } 2250 }
2251 } 2251 }
2252 2252
2253 //NewInitNodeInfo_List(); 2253 //NewInitNodeInfo_List();
2254 2254
2255 NewDspRouteInfo(); 2255 NewDspRouteInfo();
2256 stt--; 2256 stt--;
2257 2257
2258 } 2258 }
2259 2259
2260 public void ReDrawAllNode() 2260 public void ReDrawAllNode()
2261 { 2261 {
2262 LineGeometry lineGeometry = new LineGeometry(); 2262 LineGeometry lineGeometry = new LineGeometry();
2263 EllipseGeometry ellip; 2263 EllipseGeometry ellip;
2264 //delete all line 2264 //delete all line
2265 gGrpNewLine.Children.Clear(); 2265 gGrpNewLine.Children.Clear();
2266 this.Children.Remove(pNewLine); 2266 this.Children.Remove(pNewLine);
2267 2267
2268 //redraw line 2268 //redraw line
2269 for (int j = 0; j < gGrpBlueNode.Children.Count-1; j++) 2269 for (int j = 0; j < gGrpBlueNode.Children.Count-1; j++)
2270 { 2270 {
2271 ellip = (EllipseGeometry)gGrpBlueNode.Children[j]; 2271 ellip = (EllipseGeometry)gGrpBlueNode.Children[j];
2272 Point node1 = ellip.Center; 2272 Point node1 = ellip.Center;
2273 ellip = (EllipseGeometry)gGrpBlueNode.Children[j+1]; 2273 ellip = (EllipseGeometry)gGrpBlueNode.Children[j+1];
2274 Point node2 = ellip.Center; 2274 Point node2 = ellip.Center;
2275 DrawLine(node1, node2, gGrpNewLine); 2275 DrawLine(node1, node2, gGrpNewLine);
2276 } 2276 }
2277 2277
2278 this.Children.Add(pNewLine); 2278 this.Children.Add(pNewLine);
2279 2279
2280 2280
2281 //redraw ucNode 2281 //redraw ucNode
2282 for (int k = 0; k < ucNode_Lst.Count; k++) 2282 for (int k = 0; k < ucNode_Lst.Count; k++)
2283 { 2283 {
2284 this.Children.Remove(ucNode_Lst[k]); 2284 this.Children.Remove(ucNode_Lst[k]);
2285 this.Children.Add(ucNode_Lst[k]); 2285 this.Children.Add(ucNode_Lst[k]);
2286 } 2286 }
2287 } 2287 }
2288 2288
2289 2289
2290 2290
2291 public void NewInitNodeInfo_List() 2291 public void NewInitNodeInfo_List()
2292 { 2292 {
2293 //Reset List 2293 //Reset List
2294 //NewNodeInfo_List = new List<NewNodeInfo>(); 2294 //NewNodeInfo_List = new List<NewNodeInfo>();
2295 2295
2296 if (gGrpBlueNode.Children.Count > 0) 2296 if (gGrpBlueNode.Children.Count > 0)
2297 { 2297 {
2298 //for (int i = 0; i < gGrpBlueNode.Children.Count; i++) 2298 //for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
2299 //{ 2299 //{
2300 int i = gGrpBlueNode.Children.Count - 1; 2300 int i = gGrpBlueNode.Children.Count - 1;
2301 Point point; 2301 Point point;
2302 EllipseGeometry eGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; 2302 EllipseGeometry eGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
2303 point = eGeometry.Center; 2303 point = eGeometry.Center;
2304 2304
2305 NewNodeInfo Ninfo = new NewNodeInfo(); 2305 NewNodeInfo Ninfo = new NewNodeInfo();
2306 Ninfo.X = point.X; 2306 Ninfo.X = point.X;
2307 Ninfo.Y = point.Y; 2307 Ninfo.Y = point.Y;
2308 2308
2309 Ninfo.Mode = ""; 2309 Ninfo.Mode = "";
2310 2310
2311 NewNodeInfo_List.Add(Ninfo); 2311 NewNodeInfo_List.Add(Ninfo);
2312 //} 2312 //}
2313 2313
2314 } 2314 }
2315 } 2315 }
2316 2316
2317 public void NewEditNode(Point node_edited) 2317 public void NewEditNode(Point node_edited)
2318 { 2318 {
2319 EllipseGeometry ellipseGeometry; 2319 EllipseGeometry ellipseGeometry;
2320 Point node; 2320 Point node;
2321 double radiusNode = RADIUS_NODE; 2321 double radiusNode = RADIUS_NODE;
2322 2322
2323 bool flag = false; 2323 bool flag = false;
2324 2324
2325 if (gGrpBlueNode.Children.Count > 0) 2325 if (gGrpBlueNode.Children.Count > 0)
2326 { 2326 {
2327 for (int i = 0; i < gGrpBlueNode.Children.Count; i++) 2327 for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
2328 { 2328 {
2329 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; 2329 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
2330 node = ellipseGeometry.Center; 2330 node = ellipseGeometry.Center;
2331 2331
2332 if (CheckIsNode(node_edited, node, radiusNode)) 2332 if (CheckIsNode(node_edited, node, radiusNode))
2333 { 2333 {
2334 flag = true; 2334 flag = true;
2335 } 2335 }
2336 2336
2337 if (flag) 2337 if (flag)
2338 { 2338 {
2339 node_edited.X = node.X; 2339 node_edited.X = node.X;
2340 node_edited.Y = node.Y; 2340 node_edited.Y = node.Y;
2341 2341
2342 // show form edit node 2342 // show form edit node
2343 EditNodeWindow edtNodeWindow = new EditNodeWindow(); 2343 EditNodeWindow edtNodeWindow = new EditNodeWindow();
2344 edtNodeWindow.ShowDialog(); 2344 edtNodeWindow.ShowDialog();
2345 2345
2346 string result = edtNodeWindow._txtMode; 2346 string result = edtNodeWindow._txtMode;
2347 bool exit = edtNodeWindow._ExitFlg; 2347 bool exit = edtNodeWindow._ExitFlg;
2348 2348
2349 if (!exit) 2349 if (!exit)
2350 { 2350 {
2351 NewSaveChanged(node_edited.X, node_edited.Y, result); 2351 NewSaveChanged(node_edited.X, node_edited.Y, result);
2352 } 2352 }
2353 2353
2354 return; 2354 return;
2355 } 2355 }
2356 } 2356 }
2357 } 2357 }
2358 } 2358 }
2359 2359
2360 //Save Node's Data Edited 2360 //Save Node's Data Edited
2361 public void NewSaveChanged(double x, double y, string st) 2361 public void NewSaveChanged(double x, double y, string st)
2362 { 2362 {
2363 for (int i = 0; i < NewNodeInfo_List.Count; i++) 2363 for (int i = 0; i < NewNodeInfo_List.Count; i++)
2364 { 2364 {
2365 NewNodeInfo ni = new NewNodeInfo(); 2365 NewNodeInfo ni = new NewNodeInfo();
2366 ni = NewNodeInfo_List[i]; 2366 ni = NewNodeInfo_List[i];
2367 2367
2368 if (ni.X == x && ni.Y == y) 2368 if (ni.X == x && ni.Y == y)
2369 { 2369 {
2370 ni.Mode = st; 2370 ni.Mode = st;
2371 2371
2372 NewNodeInfo_List[i] = ni; 2372 NewNodeInfo_List[i] = ni;
2373 return; 2373 return;
2374 } 2374 }
2375 } 2375 }
2376 } 2376 }
2377 2377
2378 public void NewDspRouteInfo() 2378 public void NewDspRouteInfo()
2379 { 2379 {
2380 //Clear Route Info Table 2380 //Clear Route Info Table
2381 ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Clear(); 2381 ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Clear();
2382 2382
2383 if (NewNodeInfo_List.Count != 0) 2383 if (NewNodeInfo_List.Count != 0)
2384 { 2384 {
2385 int _RowIdx = 0; 2385 int _RowIdx = 0;
2386 string _Content = ""; 2386 string _Content = "";
2387 2387
2388 for (int i = 0; i < NewNodeInfo_List.Count; i++) 2388 for (int i = 0; i < NewNodeInfo_List.Count; i++)
2389 { 2389 {
2390 2390
2391 NewNodeInfo ni = new NewNodeInfo(); 2391 NewNodeInfo ni = new NewNodeInfo();
2392 ni = NewNodeInfo_List[i]; 2392 ni = NewNodeInfo_List[i];
2393 2393
2394 //column 1 2394 //column 1
2395 _Content = (i +1).ToString(); 2395 _Content = (i +1).ToString();
2396 AddLabeltoGrid(_RowIdx, 0, _Content); 2396 AddLabeltoGrid(_RowIdx, 0, _Content);
2397 2397
2398 //column 2 2398 //column 2
2399 // Display Node's Position 2399 // Display Node's Position
2400 _Content = "LAT " + ni.X; 2400 _Content = "LAT " + ni.X;
2401 AddLabeltoGrid(_RowIdx, 1, _Content); 2401 AddLabeltoGrid(_RowIdx, 1, _Content);
2402 _RowIdx++; 2402 _RowIdx++;
2403 2403
2404 _Content = "LOC " + ni.Y; 2404 _Content = "LOC " + ni.Y;
2405 AddLabeltoGrid(_RowIdx, 1, _Content); 2405 AddLabeltoGrid(_RowIdx, 1, _Content);
2406 2406
2407 // Display Node's Field 2407 // Display Node's Field
2408 if (ni.Mode != "" && ni.Mode != null) 2408 if (ni.Mode != "" && ni.Mode != null)
2409 { 2409 {
2410 char delimiterChars = '_'; 2410 char delimiterChars = '_';
2411 string[] tmp = ni.Mode.Split(delimiterChars); 2411 string[] tmp = ni.Mode.Split(delimiterChars);
2412 foreach (string s in tmp) 2412 foreach (string s in tmp)
2413 { 2413 {
2414 _RowIdx++; 2414 _RowIdx++;
2415 delimiterChars = ':'; 2415 delimiterChars = ':';
2416 2416
2417 if (s.Split(delimiterChars)[0] == "Speed") 2417 if (s.Split(delimiterChars)[0] == "Speed")
2418 { 2418 {
2419 _Content = "SPD " + s.Split(delimiterChars)[1]; 2419 _Content = "SPD " + s.Split(delimiterChars)[1];
2420 AddLabeltoGrid(_RowIdx, 1, _Content); 2420 AddLabeltoGrid(_RowIdx, 1, _Content);
2421 } 2421 }
2422 } 2422 }
2423 } 2423 }
2424 _RowIdx++; 2424 _RowIdx++;
2425 } 2425 }
2426 } 2426 }
2427 } 2427 }
2428 2428
2429 2429
2430 2430
2431 //2017/03/07 tach rieng CreateNode start 2431 //2017/03/07 tach rieng CreateNode start
2432 private void execDeleteNode(Point FreeNode) 2432 private void execDeleteNode(Point FreeNode)
2433 { 2433 {
2434 2434
2435 double radiusNode = RADIUS_NODE; 2435 double radiusNode = RADIUS_NODE;
2436 2436
2437 EllipseGeometry ellipseGeometry; 2437 EllipseGeometry ellipseGeometry;
2438 Point node; 2438 Point node;
2439 bool deleteFlag = false; 2439 bool deleteFlag = false;
2440 2440
2441 if (gGrpBlueNode.Children.Count > 0) 2441 if (gGrpBlueNode.Children.Count > 0)
2442 { 2442 {
2443 for (int i = 0; i < gGrpBlueNode.Children.Count; i++) 2443 for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
2444 { 2444 {
2445 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; 2445 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
2446 node = ellipseGeometry.Center; 2446 node = ellipseGeometry.Center;
2447 if (FreeNode.X == node.X) 2447 if (FreeNode.X == node.X)
2448 { 2448 {
2449 if (CheckIsNode(FreeNode, node, radiusNode)) 2449 if (CheckIsNode(FreeNode, node, radiusNode))
2450 { 2450 {
2451 deleteFlag = true; 2451 deleteFlag = true;
2452 } 2452 }
2453 } 2453 }
2454 else 2454 else
2455 { 2455 {
2456 if (CheckIsNode(FreeNode, node, radiusNode)) 2456 if (CheckIsNode(FreeNode, node, radiusNode))
2457 { 2457 {
2458 deleteFlag = true; 2458 deleteFlag = true;
2459 } 2459 }
2460 } 2460 }
2461 if (deleteFlag) 2461 if (deleteFlag)
2462 { 2462 {
2463 MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel); 2463 MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel);
2464 if (result == MessageBoxResult.OK) 2464 if (result == MessageBoxResult.OK)
2465 { 2465 {
2466 DeleteNode(i); 2466 DeleteNode(i);
2467 SetScheduleRoute(); 2467 SetScheduleRoute();
2468 2468
2469 return; 2469 return;
2470 } 2470 }
2471 else 2471 else
2472 { 2472 {
2473 return; 2473 return;
2474 } 2474 }
2475 } 2475 }
2476 } 2476 }
2477 } 2477 }
2478 } 2478 }
2479 2479
2480 2480
2481 private void execEditNode(Point FreeNode) 2481 private void execEditNode(Point FreeNode)
2482 { 2482 {
2483 EllipseGeometry ellipseGeometry; 2483 EllipseGeometry ellipseGeometry;
2484 Point node; 2484 Point node;
2485 for (int i = 0; i < gGrpBlueNode.Children.Count; i++) 2485 for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
2486 { 2486 {
2487 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; 2487 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
2488 node = ellipseGeometry.Center; 2488 node = ellipseGeometry.Center;
2489 bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE); 2489 bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE);
2490 2490
2491 if (isEditNode) 2491 if (isEditNode)
2492 { 2492 {
2493 NewEditNode(node); 2493 NewEditNode(node);
2494 NewDspRouteInfo(); 2494 NewDspRouteInfo();
2495 return; 2495 return;
2496 } 2496 }
2497 } 2497 }
2498 } 2498 }
2499 2499
2500 2500
2501 private void execCreateNode(Point FreeNode) 2501 private void execCreateNode(Point FreeNode)
2502 { 2502 {
2503 //check new node in exist line 2503 //check new node in exist line
2504 if (gGrpNewLine.Children.Count > 0) 2504 if (gGrpNewLine.Children.Count > 0)
2505 { 2505 {
2506 for (int i = 0; i < gGrpNewLine.Children.Count; i++) 2506 for (int i = 0; i < gGrpNewLine.Children.Count; i++)
2507 { 2507 {
2508 LineGeometry lineGeometry = (LineGeometry)gGrpNewLine.Children[i]; 2508 LineGeometry lineGeometry = (LineGeometry)gGrpNewLine.Children[i];
2509 Point p1 = lineGeometry.StartPoint; 2509 Point p1 = lineGeometry.StartPoint;
2510 Point p2 = lineGeometry.EndPoint; 2510 Point p2 = lineGeometry.EndPoint;
2511 2511
2512 bool pInL = PointInLine(FreeNode, p1, p2, UCNODE_SETLEFT); 2512 bool pInL = PointInLine(FreeNode, p1, p2, UCNODE_SETLEFT);
2513 2513
2514 if (pInL) 2514 if (pInL)
2515 { 2515 {
2516 MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel); 2516 MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel);
2517 if (result == MessageBoxResult.OK) 2517 if (result == MessageBoxResult.OK)
2518 { 2518 {
2519 Point tmpPoint = ConvertNodeinLine(FreeNode, p1, p2); 2519 Point tmpPoint = ConvertNodeinLine(FreeNode, p1, p2);
2520 FreeNode = tmpPoint; 2520 FreeNode = tmpPoint;
2521 2521
2522 ucNode _ucNode1 = new ucNode(); 2522 ucNode _ucNode1 = new ucNode();
2523 _ucNode1.btnWidth = UCNODE_WIDTH; 2523 _ucNode1.btnWidth = UCNODE_WIDTH;
2524 _ucNode1.btnHeight = UCNODE_HEIGHT; 2524 _ucNode1.btnHeight = UCNODE_HEIGHT;
2525 _ucNode1.txtNode = (i + 2).ToString(); 2525 _ucNode1.txtNode = (i + 2).ToString();
2526 _ucNode1.fillColor = "Brown"; 2526 _ucNode1.fillColor = "Brown";
2527 _ucNode1.IsDragDelta = true; 2527 _ucNode1.IsDragDelta = true;
2528 Canvas.SetLeft(_ucNode1, FreeNode.X - UCNODE_SETLEFT); 2528 Canvas.SetLeft(_ucNode1, FreeNode.X - UCNODE_SETLEFT);
2529 Canvas.SetTop(_ucNode1, FreeNode.Y - UCNODE_SETTOP); 2529 Canvas.SetTop(_ucNode1, FreeNode.Y - UCNODE_SETTOP);
2530 //this.Children.Add(_ucNode1); 2530 //this.Children.Add(_ucNode1);
2531 2531
2532 ucNode_Lst.Insert(i + 1, _ucNode1); 2532 ucNode_Lst.Insert(i + 1, _ucNode1);
2533 //ucNode_Lst.Add(_ucNode1); 2533 //ucNode_Lst.Add(_ucNode1);
2534 2534
2535 gGrpBlueNode.Children.Insert(i + 1, new EllipseGeometry(FreeNode, RADIUS_NODE, RADIUS_NODE)); 2535 gGrpBlueNode.Children.Insert(i + 1, new EllipseGeometry(FreeNode, RADIUS_NODE, RADIUS_NODE));
2536 //AddNode(FreeNode, gGrpBlueNode); 2536 //AddNode(FreeNode, gGrpBlueNode);
2537 2537
2538 2538
2539 ////delete all line 2539 ////delete all line
2540 //gGrpNewLine.Children.Clear(); 2540 //gGrpNewLine.Children.Clear();
2541 //this.Children.Remove(pNewLine); 2541 //this.Children.Remove(pNewLine);
2542 ////redraw line 2542 ////redraw line
2543 //for (int j = 0; j < gGrpBlueNode.Children.Count - 1; j++) 2543 //for (int j = 0; j < gGrpBlueNode.Children.Count - 1; j++)
2544 //{ 2544 //{
2545 // EllipseGeometry ellip = (EllipseGeometry)gGrpBlueNode.Children[j]; 2545 // EllipseGeometry ellip = (EllipseGeometry)gGrpBlueNode.Children[j];
2546 // Point node1 = ellip.Center; 2546 // Point node1 = ellip.Center;
2547 // ellip = (EllipseGeometry)gGrpBlueNode.Children[j + 1]; 2547 // ellip = (EllipseGeometry)gGrpBlueNode.Children[j + 1];
2548 // Point node2 = ellip.Center; 2548 // Point node2 = ellip.Center;
2549 // DrawLine(node1, node2, gGrpNewLine); 2549 // DrawLine(node1, node2, gGrpNewLine);
2550 //} 2550 //}
2551 2551
2552 //this.Children.Add(pNewLine); 2552 //this.Children.Add(pNewLine);
2553 2553
2554 2554
2555 //rename Point textName 2555 //rename Point textName
2556 for (int j = 0; j < ucNode_Lst.Count; j++) 2556 for (int j = 0; j < ucNode_Lst.Count; j++)
2557 { 2557 {
2558 ucNode_Lst[j].txtNode = (j + 1).ToString(); 2558 ucNode_Lst[j].txtNode = (j + 1).ToString();
2559 this.Children.Remove(ucNode_Lst[j]); 2559 this.Children.Remove(ucNode_Lst[j]);
2560 this.Children.Add(ucNode_Lst[j]); 2560 this.Children.Add(ucNode_Lst[j]);
2561 } 2561 }
2562 2562
2563 2563
2564 ReDrawAllNode(); 2564 ReDrawAllNode();
2565 2565
2566 stt++; 2566 stt++;
2567 NewInitNodeInfo_List(); 2567 NewInitNodeInfo_List();
2568 NewDspRouteInfo(); 2568 NewDspRouteInfo();
2569 return; 2569 return;
2570 } 2570 }
2571 else 2571 else
2572 { return; } 2572 { return; }
2573 } 2573 }
2574 } 2574 }
2575 } 2575 }
2576 2576
2577 2577
2578 ucNode _ucNode = new ucNode(); 2578 ucNode _ucNode = new ucNode();
2579 _ucNode.btnWidth = UCNODE_WIDTH; 2579 _ucNode.btnWidth = UCNODE_WIDTH;
2580 _ucNode.btnHeight = UCNODE_HEIGHT; 2580 _ucNode.btnHeight = UCNODE_HEIGHT;
2581 _ucNode.txtNode = stt.ToString(); 2581 _ucNode.txtNode = stt.ToString();
2582 _ucNode.IsDragDelta = true; 2582 _ucNode.IsDragDelta = true;
2583 Canvas.SetLeft(_ucNode, FreeNode.X - UCNODE_SETLEFT); 2583 Canvas.SetLeft(_ucNode, FreeNode.X - UCNODE_SETLEFT);
2584 Canvas.SetTop(_ucNode, FreeNode.Y - UCNODE_SETTOP); 2584 Canvas.SetTop(_ucNode, FreeNode.Y - UCNODE_SETTOP);
2585 this.Children.Add(_ucNode); 2585 this.Children.Add(_ucNode);
2586 ucNode_Lst.Add(_ucNode); 2586 ucNode_Lst.Add(_ucNode);
2587 2587
2588 AddNode(FreeNode, gGrpBlueNode); 2588 AddNode(FreeNode, gGrpBlueNode);
2589 2589
2590 SetScheduleRoute(); 2590 SetScheduleRoute();
2591 2591
2592 //draw line 2592 //draw line
2593 if (stt > 1) 2593 if (stt > 1)
2594 { 2594 {
2595 //delete all line 2595 //delete all line
2596 gGrpNewLine.Children.Clear(); 2596 gGrpNewLine.Children.Clear();
2597 this.Children.Remove(pNewLine); 2597 this.Children.Remove(pNewLine);
2598 //redraw line 2598 //redraw line
2599 for (int j = 0; j < gGrpBlueNode.Children.Count - 1; j++) 2599 for (int j = 0; j < gGrpBlueNode.Children.Count - 1; j++)
2600 { 2600 {
2601 EllipseGeometry ellip = (EllipseGeometry)gGrpBlueNode.Children[j]; 2601 EllipseGeometry ellip = (EllipseGeometry)gGrpBlueNode.Children[j];
2602 Point node1 = ellip.Center; 2602 Point node1 = ellip.Center;
2603 ellip = (EllipseGeometry)gGrpBlueNode.Children[j + 1]; 2603 ellip = (EllipseGeometry)gGrpBlueNode.Children[j + 1];
2604 Point node2 = ellip.Center; 2604 Point node2 = ellip.Center;
2605 DrawLine(node1, node2, gGrpNewLine); 2605 DrawLine(node1, node2, gGrpNewLine);
2606 } 2606 }
2607 2607
2608 this.Children.Add(pNewLine); 2608 this.Children.Add(pNewLine);
2609 2609
2610 //rename Point textName 2610 //rename Point textName
2611 for (int j = 0; j < ucNode_Lst.Count; j++) 2611 for (int j = 0; j < ucNode_Lst.Count; j++)
2612 { 2612 {
2613 ucNode_Lst[j].txtNode = (j + 1).ToString(); 2613 ucNode_Lst[j].txtNode = (j + 1).ToString();
2614 this.Children.Remove(ucNode_Lst[j]); 2614 this.Children.Remove(ucNode_Lst[j]);
2615 this.Children.Add(ucNode_Lst[j]); 2615 this.Children.Add(ucNode_Lst[j]);
2616 } 2616 }
2617 } 2617 }
2618 2618
2619 stt++; 2619 stt++;
2620 NewInitNodeInfo_List(); 2620 NewInitNodeInfo_List();
2621 NewDspRouteInfo(); 2621 NewDspRouteInfo();
2622 } 2622 }
2623 2623
2624 //2017/03/07 tach CreateNode End 2624 //2017/03/07 tach CreateNode End
2625 2625
2626 2626
2627 2627
2628 2628
2629 2629
2630 2630
2631 private void CreateNode(Point FreeNode, bool LeftClick, bool RightClick) 2631 private void CreateNode(Point FreeNode, bool LeftClick, bool RightClick)
2632 { 2632 {
2633 double radiusNode = RADIUS_NODE; 2633 double radiusNode = RADIUS_NODE;
2634 2634
2635 EllipseGeometry ellipseGeometry; 2635 EllipseGeometry ellipseGeometry;
2636 Point node; 2636 Point node;
2637 bool deleteFlag = false; 2637 bool deleteFlag = false;
2638 2638
2639 //Su kien bam chuot phai 2639 //Su kien bam chuot phai
2640 if (RightClick) 2640 if (RightClick)
2641 { 2641 {
2642 if (gGrpBlueNode.Children.Count > 0) 2642 if (gGrpBlueNode.Children.Count > 0)
2643 { 2643 {
2644 for (int i = 0; i < gGrpBlueNode.Children.Count; i++) 2644 for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
2645 { 2645 {
2646 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; 2646 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
2647 node = ellipseGeometry.Center; 2647 node = ellipseGeometry.Center;
2648 if (FreeNode.X == node.X) 2648 if (FreeNode.X == node.X)
2649 { 2649 {
2650 if (CheckIsNode(FreeNode, node, radiusNode)) 2650 if (CheckIsNode(FreeNode, node, radiusNode))
2651 { 2651 {
2652 deleteFlag = true; 2652 deleteFlag = true;
2653 } 2653 }
2654 } 2654 }
2655 else 2655 else
2656 { 2656 {
2657 if (CheckIsNode(FreeNode, node, radiusNode)) 2657 if (CheckIsNode(FreeNode, node, radiusNode))
2658 { 2658 {
2659 deleteFlag = true; 2659 deleteFlag = true;
2660 } 2660 }
2661 } 2661 }
2662 if (deleteFlag) 2662 if (deleteFlag)
2663 { 2663 {
2664 MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel); 2664 MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel);
2665 if (result == MessageBoxResult.OK) 2665 if (result == MessageBoxResult.OK)
2666 { 2666 {
2667 2667
2668 DeleteNode(i); 2668 DeleteNode(i);
2669 2669
2670 SetScheduleRoute(); 2670 SetScheduleRoute();
2671 2671
2672 return; 2672 return;
2673 } 2673 }
2674 else 2674 else
2675 { 2675 {
2676 return; 2676 return;
2677 } 2677 }
2678 } 2678 }
2679 } 2679 }
2680 } 2680 }
2681 } 2681 }
2682 2682
2683 // them nut 2683 // them nut
2684 else 2684 else
2685 { 2685 {
2686 //Check EditNode State 2686 //Check EditNode State
2687 if(LeftClick) 2687 if(LeftClick)
2688 { 2688 {
2689 for (int i = 0; i < gGrpBlueNode.Children.Count; i++) 2689 for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
2690 { 2690 {
2691 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; 2691 ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
2692 node = ellipseGeometry.Center; 2692 node = ellipseGeometry.Center;
2693 bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE); 2693 bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE);
2694 2694
2695 if (isEditNode) 2695 if (isEditNode)
2696 { 2696 {
2697 2697
2698 //NewEditNode(node); 2698 //NewEditNode(node);
2699 //NewDspRouteInfo(); 2699 //NewDspRouteInfo();
2700 return; 2700 return;
2701 } 2701 }
2702 } 2702 }
2703 } 2703 }
2704 2704
2705 // starting add node 2705 // starting add node
2706 //check new node in exist line 2706 //check new node in exist line
2707 if(gGrpNewLine.Children.Count > 0) 2707 if(gGrpNewLine.Children.Count > 0)
2708 { 2708 {
2709 for (int i = 0; i < gGrpNewLine.Children.Count; i++) 2709 for (int i = 0; i < gGrpNewLine.Children.Count; i++)
2710 { 2710 {
2711 LineGeometry lineGeometry = (LineGeometry)gGrpNewLine.Children[i]; 2711 LineGeometry lineGeometry = (LineGeometry)gGrpNewLine.Children[i];
2712 Point p1 = lineGeometry.StartPoint; 2712 Point p1 = lineGeometry.StartPoint;
2713 Point p2 = lineGeometry.EndPoint; 2713 Point p2 = lineGeometry.EndPoint;
2714 2714
2715 bool pInL = PointInLine(FreeNode, p1, p2, UCNODE_SETLEFT); 2715 bool pInL = PointInLine(FreeNode, p1, p2, UCNODE_SETLEFT);
2716 2716
2717 if (pInL) 2717 if (pInL)
2718 { 2718 {
2719 MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel); 2719 MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel);
2720 if (result == MessageBoxResult.OK) 2720 if (result == MessageBoxResult.OK)
2721 { 2721 {
2722 Point tmpPoint = ConvertNodeinLine(FreeNode, p1, p2); 2722 Point tmpPoint = ConvertNodeinLine(FreeNode, p1, p2);
2723 FreeNode = tmpPoint; 2723 FreeNode = tmpPoint;
2724 2724
2725 ucNode _ucNode1 = new ucNode(); 2725 ucNode _ucNode1 = new ucNode();
2726 _ucNode1.btnWidth = UCNODE_WIDTH; 2726 _ucNode1.btnWidth = UCNODE_WIDTH;
2727 _ucNode1.btnHeight = UCNODE_HEIGHT; 2727 _ucNode1.btnHeight = UCNODE_HEIGHT;
2728 _ucNode1.txtNode = (i + 2).ToString(); 2728 _ucNode1.txtNode = (i + 2).ToString();
2729 _ucNode1.fillColor = "Brown"; 2729 _ucNode1.fillColor = "Brown";
2730 _ucNode1.IsDragDelta = true; 2730 _ucNode1.IsDragDelta = true;
2731 Canvas.SetLeft(_ucNode1, FreeNode.X - UCNODE_SETLEFT); 2731 Canvas.SetLeft(_ucNode1, FreeNode.X - UCNODE_SETLEFT);
2732 Canvas.SetTop(_ucNode1, FreeNode.Y - UCNODE_SETTOP); 2732 Canvas.SetTop(_ucNode1, FreeNode.Y - UCNODE_SETTOP);
2733 //this.Children.Add(_ucNode1); 2733 //this.Children.Add(_ucNode1);
2734 2734
2735 ucNode_Lst.Insert(i + 1, _ucNode1); 2735 ucNode_Lst.Insert(i + 1, _ucNode1);
2736 //ucNode_Lst.Add(_ucNode1); 2736 //ucNode_Lst.Add(_ucNode1);
2737 2737
2738 gGrpBlueNode.Children.Insert(i + 1, new EllipseGeometry(FreeNode, RADIUS_NODE, RADIUS_NODE)); 2738 gGrpBlueNode.Children.Insert(i + 1, new EllipseGeometry(FreeNode, RADIUS_NODE, RADIUS_NODE));
2739 //AddNode(FreeNode, gGrpBlueNode); 2739 //AddNode(FreeNode, gGrpBlueNode);
2740 2740
2741 2741
2742 //delete all line 2742 //delete all line
2743 gGrpNewLine.Children.Clear(); 2743 gGrpNewLine.Children.Clear();
2744 this.Children.Remove(pNewLine); 2744 this.Children.Remove(pNewLine);
2745 //redraw line 2745 //redraw line
2746 for (int j = 0; j < gGrpBlueNode.Children.Count - 1; j++) 2746 for (int j = 0; j < gGrpBlueNode.Children.Count - 1; j++)
2747 { 2747 {
2748 EllipseGeometry ellip = (EllipseGeometry)gGrpBlueNode.Children[j]; 2748 EllipseGeometry ellip = (EllipseGeometry)gGrpBlueNode.Children[j];
2749 Point node1 = ellip.Center; 2749 Point node1 = ellip.Center;
2750 ellip = (EllipseGeometry)gGrpBlueNode.Children[j + 1]; 2750 ellip = (EllipseGeometry)gGrpBlueNode.Children[j + 1];
2751 Point node2 = ellip.Center; 2751 Point node2 = ellip.Center;
2752 DrawLine(node1, node2, gGrpNewLine); 2752 DrawLine(node1, node2, gGrpNewLine);
2753 } 2753 }
2754 2754
2755 this.Children.Add(pNewLine); 2755 this.Children.Add(pNewLine);
2756 2756
2757 2757
2758 //rename Point textName 2758 //rename Point textName
2759 for (int j = 0; j < ucNode_Lst.Count; j++) 2759 for (int j = 0; j < ucNode_Lst.Count; j++)
2760 { 2760 {
2761 ucNode_Lst[j].txtNode = (j + 1).ToString(); 2761 ucNode_Lst[j].txtNode = (j + 1).ToString();
2762 this.Children.Remove(ucNode_Lst[j]); 2762 this.Children.Remove(ucNode_Lst[j]);
2763 this.Children.Add(ucNode_Lst[j]); 2763 this.Children.Add(ucNode_Lst[j]);
2764 } 2764 }
2765 stt++; 2765 stt++;
2766 NewInitNodeInfo_List(); 2766 NewInitNodeInfo_List();
2767 NewDspRouteInfo(); 2767 NewDspRouteInfo();
2768 2768
2769 SetScheduleRoute(); 2769 SetScheduleRoute();
2770 2770
2771 return; 2771 return;
2772 } 2772 }
2773 else 2773 else
2774 { return; } 2774 { return; }
2775 } 2775 }
2776 } 2776 }
2777 } 2777 }
2778 2778
2779 ucNode _ucNode = new ucNode(); 2779 ucNode _ucNode = new ucNode();
2780 _ucNode.btnWidth = UCNODE_WIDTH; 2780 _ucNode.btnWidth = UCNODE_WIDTH;
2781 _ucNode.btnHeight = UCNODE_HEIGHT; 2781 _ucNode.btnHeight = UCNODE_HEIGHT;
2782 _ucNode.txtNode = stt.ToString(); 2782 _ucNode.txtNode = stt.ToString();
2783 _ucNode.IsDragDelta = true; 2783 _ucNode.IsDragDelta = true;
2784 //_ucNode.selectedColor = System.Windows.Media.Brushes.Black; 2784 //_ucNode.selectedColor = System.Windows.Media.Brushes.Black;
2785 Canvas.SetLeft(_ucNode, FreeNode.X - UCNODE_SETLEFT); 2785 Canvas.SetLeft(_ucNode, FreeNode.X - UCNODE_SETLEFT);
2786 Canvas.SetTop(_ucNode, FreeNode.Y - UCNODE_SETTOP); 2786 Canvas.SetTop(_ucNode, FreeNode.Y - UCNODE_SETTOP);
2787 this.Children.Add(_ucNode); 2787 this.Children.Add(_ucNode);
2788 ucNode_Lst.Add(_ucNode); 2788 ucNode_Lst.Add(_ucNode);
2789 2789
2790 AddNode(FreeNode, gGrpBlueNode); 2790 AddNode(FreeNode, gGrpBlueNode);
2791 2791
2792 SetScheduleRoute(); 2792 SetScheduleRoute();
2793 2793
2794 //draw line 2794 //draw line
2795 if (stt > 1) 2795 if (stt > 1)
2796 { 2796 {
2797 //delete all line 2797 //delete all line
2798 gGrpNewLine.Children.Clear(); 2798 gGrpNewLine.Children.Clear();
2799 this.Children.Remove(pNewLine); 2799 this.Children.Remove(pNewLine);
2800 //redraw line 2800 //redraw line
2801 for (int j = 0; j < gGrpBlueNode.Children.Count - 1; j++) 2801 for (int j = 0; j < gGrpBlueNode.Children.Count - 1; j++)
2802 { 2802 {
2803 EllipseGeometry ellip = (EllipseGeometry)gGrpBlueNode.Children[j]; 2803 EllipseGeometry ellip = (EllipseGeometry)gGrpBlueNode.Children[j];
2804 Point node1 = ellip.Center; 2804 Point node1 = ellip.Center;
2805 ellip = (EllipseGeometry)gGrpBlueNode.Children[j + 1]; 2805 ellip = (EllipseGeometry)gGrpBlueNode.Children[j + 1];
2806 Point node2 = ellip.Center; 2806 Point node2 = ellip.Center;
2807 DrawLine(node1, node2, gGrpNewLine); 2807 DrawLine(node1, node2, gGrpNewLine);
2808 } 2808 }
2809 2809
2810 this.Children.Add(pNewLine); 2810 this.Children.Add(pNewLine);
2811 2811
2812 //rename Point textName 2812 //rename Point textName
2813 for (int j = 0; j < ucNode_Lst.Count; j++) 2813 for (int j = 0; j < ucNode_Lst.Count; j++)
2814 { 2814 {
2815 ucNode_Lst[j].txtNode = (j + 1).ToString(); 2815 ucNode_Lst[j].txtNode = (j + 1).ToString();
2816 this.Children.Remove(ucNode_Lst[j]); 2816 this.Children.Remove(ucNode_Lst[j]);
2817 this.Children.Add(ucNode_Lst[j]); 2817 this.Children.Add(ucNode_Lst[j]);
2818 } 2818 }
2819 2819
2820 } 2820 }
2821 2821
2822 stt++; 2822 stt++;
2823 NewInitNodeInfo_List(); 2823 NewInitNodeInfo_List();
2824 NewDspRouteInfo(); 2824 NewDspRouteInfo();
2825 } 2825 }
2826 2826
2827 } 2827 }
2828 2828
2829 public Point ConvertNodeinLine(Point point, Point l1, Point l2) 2829 public Point ConvertNodeinLine(Point point, Point l1, Point l2)
2830 { 2830 {
2831 Point pointResult = new Point(); 2831 Point pointResult = new Point();
2832 double X = 0; 2832 double X = 0;
2833 double Y = 0; 2833 double Y = 0;
2834 2834
2835 double distance_Line = 0; 2835 double distance_Line = 0;
2836 double distance_l1ToPoint = 0; 2836 double distance_l1ToPoint = 0;
2837 2837
2838 distance_Line = DistanceTo(l1, l2); 2838 distance_Line = DistanceTo(l1, l2);
2839 distance_l1ToPoint = DistanceTo(l1, point); 2839 distance_l1ToPoint = DistanceTo(l1, point);
2840 2840
2841 2841
2842 if (l1.X == l2.X) 2842 if (l1.X == l2.X)
2843 { 2843 {
2844 X = l1.X; 2844 X = l1.X;
2845 Y = point.Y; 2845 Y = point.Y;
2846 } 2846 }
2847 else if (l1.Y == l2.Y) 2847 else if (l1.Y == l2.Y)
2848 { 2848 {
2849 X = point.X; 2849 X = point.X;
2850 Y = l1.Y; 2850 Y = l1.Y;
2851 } 2851 }
2852 else 2852 else
2853 { 2853 {
2854 if (l1.X < l2.X) 2854 if (l1.X < l2.X)
2855 { 2855 {
2856 if (l1.Y < l2.Y) 2856 if (l1.Y < l2.Y)
2857 { 2857 {
2858 Y = l1.Y + (distance_l1ToPoint * (l2.Y - l1.Y) / distance_Line); 2858 Y = l1.Y + (distance_l1ToPoint * (l2.Y - l1.Y) / distance_Line);
2859 X = l1.X + (distance_l1ToPoint * (l2.X - l1.X) / distance_Line); 2859 X = l1.X + (distance_l1ToPoint * (l2.X - l1.X) / distance_Line);
2860 } 2860 }
2861 else 2861 else
2862 { 2862 {
2863 Y = l1.Y - (distance_l1ToPoint * (l1.Y - l2.Y) / distance_Line); 2863 Y = l1.Y - (distance_l1ToPoint * (l1.Y - l2.Y) / distance_Line);
2864 X = l1.X + (distance_l1ToPoint * (l2.X - l1.X) / distance_Line); 2864 X = l1.X + (distance_l1ToPoint * (l2.X - l1.X) / distance_Line);
2865 } 2865 }
2866 } 2866 }
2867 else 2867 else
2868 { 2868 {
2869 if (l1.Y < l2.Y) 2869 if (l1.Y < l2.Y)
2870 { 2870 {
2871 Y = l1.Y + (distance_l1ToPoint * (l2.Y - l1.Y) / distance_Line); 2871 Y = l1.Y + (distance_l1ToPoint * (l2.Y - l1.Y) / distance_Line);
2872 X = l1.X - (distance_l1ToPoint * (l1.X - l2.X) / distance_Line); 2872 X = l1.X - (distance_l1ToPoint * (l1.X - l2.X) / distance_Line);
2873 } 2873 }
2874 else 2874 else
2875 { 2875 {
2876 Y = l1.Y - (distance_l1ToPoint * (l1.Y - l2.Y) / distance_Line); 2876 Y = l1.Y - (distance_l1ToPoint * (l1.Y - l2.Y) / distance_Line);
2877 X = l1.X - (distance_l1ToPoint * (l1.X - l2.X) / distance_Line); 2877 X = l1.X - (distance_l1ToPoint * (l1.X - l2.X) / distance_Line);
2878 } 2878 }
2879 } 2879 }
2880 2880
2881 2881
2882 } 2882 }
2883 2883
2884 pointResult.X = X; 2884 pointResult.X = X;
2885 pointResult.Y = Y; 2885 pointResult.Y = Y;
2886 return pointResult; 2886 return pointResult;
2887 } 2887 }
2888 2888
2889 public static double DistanceTo(Point point1, Point point2) 2889 public static double DistanceTo(Point point1, Point point2)
2890 { 2890 {
2891 var a = (double)(point2.X - point1.X); 2891 var a = (double)(point2.X - point1.X);
2892 var b = (double)(point2.Y - point1.Y); 2892 var b = (double)(point2.Y - point1.Y);
2893 2893
2894 return Math.Sqrt(a *a + b * b); 2894 return Math.Sqrt(a *a + b * b);
2895 } 2895 }
2896 2896
2897 public bool PointInLine(Point point, Point l1, Point l2, double radius) 2897 public bool PointInLine(Point point, Point l1, Point l2, double radius)
2898 { 2898 {
2899 double distance = 0; 2899 double distance = 0;
2900 bool falg = false; 2900 bool falg = false;
2901 2901
2902 if (l1.X < l2.X) 2902 if (l1.X < l2.X)
2903 { 2903 {
2904 if (l1.Y < l2.Y) 2904 if (l1.Y < l2.Y)
2905 { 2905 {
2906 if (point.X > l1.X - radius && point.X < l2.X + radius && point.Y > l1.Y - radius && point.Y < l2.Y + radius) 2906 if (point.X > l1.X - radius && point.X < l2.X + radius && point.Y > l1.Y - radius && point.Y < l2.Y + radius)
2907 { 2907 {
2908 falg = true; 2908 falg = true;
2909 } 2909 }
2910 } 2910 }
2911 else 2911 else
2912 { 2912 {
2913 if (point.X > l1.X - radius && point.X < l2.X + radius && point.Y < l1.Y + radius && point.Y > l2.Y - radius) 2913 if (point.X > l1.X - radius && point.X < l2.X + radius && point.Y < l1.Y + radius && point.Y > l2.Y - radius)
2914 { 2914 {
2915 falg = true; 2915 falg = true;
2916 } 2916 }
2917 } 2917 }
2918 } 2918 }
2919 else 2919 else
2920 { 2920 {
2921 if (l1.Y < l2.Y) 2921 if (l1.Y < l2.Y)
2922 { 2922 {
2923 if (point.X < l1.X + radius && point.X > l2.X - radius && point.Y > l1.Y - radius && point.Y < l2.Y + radius) 2923 if (point.X < l1.X + radius && point.X > l2.X - radius && point.Y > l1.Y - radius && point.Y < l2.Y + radius)
2924 { 2924 {
2925 falg = true; 2925 falg = true;
2926 } 2926 }
2927 } 2927 }
2928 else 2928 else
2929 { 2929 {
2930 if (point.X < l1.X + radius && point.X > l2.X - radius && point.Y < l1.Y + radius && point.Y > l2.Y - radius) 2930 if (point.X < l1.X + radius && point.X > l2.X - radius && point.Y < l1.Y + radius && point.Y > l2.Y - radius)
2931 { 2931 {
2932 falg = true; 2932 falg = true;
2933 } 2933 }
2934 } 2934 }
2935 } 2935 }
2936 if (falg == false) 2936 if (falg == false)
2937 { 2937 {
2938 return false; 2938 return false;
2939 } 2939 }
2940 2940
2941 distance = DistanceFromPointToLine(point, l1, l2); 2941 distance = DistanceFromPointToLine(point, l1, l2);
2942 2942
2943 if (distance > radius) 2943 if (distance > radius)
2944 { 2944 {
2945 return false; 2945 return false;
2946 } 2946 }
2947 return true; 2947 return true;
2948 } 2948 }
2949 2949
2950 public static double DistanceFromPointToLine(Point point, Point l1, Point l2) 2950 public static double DistanceFromPointToLine(Point point, Point l1, Point l2)
2951 { 2951 {
2952 2952
2953 return Math.Abs((l2.X - l1.X)*(l1.Y - point.Y) - (l1.X - point.X)*(l2.Y - l1.Y)) / 2953 return Math.Abs((l2.X - l1.X)*(l1.Y - point.Y) - (l1.X - point.X)*(l2.Y - l1.Y)) /
2954 Math.Sqrt(Math.Pow(l2.X - l1.X, 2) + Math.Pow(l2.Y - l1.Y, 2)); 2954 Math.Sqrt(Math.Pow(l2.X - l1.X, 2) + Math.Pow(l2.Y - l1.Y, 2));
2955 } 2955 }
2956 2956
2957 #endregion 2957 #endregion
2958 2958
2959 #region Schedule 2959 #region Schedule
2960 2960
2961 public void SetScheduleRoute() 2961 public void SetScheduleRoute()
2962 { 2962 {
2963 2963
2964 EllipseGeometry ellipseGeometry_1; 2964 EllipseGeometry ellipseGeometry_1;
2965 EllipseGeometry ellipseGeometry_2; 2965 EllipseGeometry ellipseGeometry_2;
2966 Point node_1; 2966 Point node_1;
2967 Point node_2; 2967 Point node_2;
2968 Point node_Schedule = new Point(); 2968 Point node_Schedule = new Point();
2969 double x_1 = 50; 2969 double x_1 = 50;
2970 double y_1 = 80; 2970 double y_1 = 80;
2971 double Totaldistance = 1270; 2971 double Totaldistance = 1270;
2972 2972
2973 2973
2974 if (ucScheduleNode_Lst.Count > 0) 2974 if (ucScheduleNode_Lst.Count > 0)
2975 { 2975 {
2976 for (int i = 0; i < ucScheduleNode_Lst.Count; i++) 2976 for (int i = 0; i < ucScheduleNode_Lst.Count; i++)
2977 { 2977 {
2978 ucNode _ucScheduleNode = new ucNode(); 2978 ucNode _ucScheduleNode = new ucNode();
2979 _ucScheduleNode = ucScheduleNode_Lst[i]; 2979 _ucScheduleNode = ucScheduleNode_Lst[i];
2980 scheduleCanvas.Children.Remove(_ucScheduleNode); 2980 scheduleCanvas.Children.Remove(_ucScheduleNode);
2981 2981
2982 } 2982 }
2983 ucScheduleNode_Lst.Clear(); 2983 ucScheduleNode_Lst.Clear();
2984 } 2984 }
2985 2985
2986 gGrpScheduleNode.Children.Clear(); 2986 gGrpScheduleNode.Children.Clear();
2987 gGrpScheduleLine.Children.Clear(); 2987 gGrpScheduleLine.Children.Clear();
2988 2988
2989 2989
2990 List<double> distance = new List<double>(); 2990 List<double> distance = new List<double>();
2991 double addDistance; 2991 double addDistance;
2992 2992
2993 if (gGrpBlueNode.Children.Count > 0) 2993 if (gGrpBlueNode.Children.Count > 0)
2994 { 2994 {
2995 for (int i = 0; i < gGrpBlueNode.Children.Count; i++) 2995 for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
2996 { 2996 {
2997 ellipseGeometry_2 = (EllipseGeometry)gGrpBlueNode.Children[i]; 2997 ellipseGeometry_2 = (EllipseGeometry)gGrpBlueNode.Children[i];
2998 node_2 = ellipseGeometry_2.Center; 2998 node_2 = ellipseGeometry_2.Center;
2999 2999
3000 if (i >= 1) 3000 if (i >= 1)
3001 { 3001 {
3002 ellipseGeometry_1 = (EllipseGeometry)gGrpBlueNode.Children[i - 1]; 3002 ellipseGeometry_1 = (EllipseGeometry)gGrpBlueNode.Children[i - 1];
3003 node_1 = ellipseGeometry_1.Center; 3003 node_1 = ellipseGeometry_1.Center;
3004 if (node_1.X == node_2.X) 3004 if (node_1.X == node_2.X)
3005 { 3005 {
3006 addDistance = Math.Abs(node_1.Y - node_2.Y); 3006 addDistance = Math.Abs(node_1.Y - node_2.Y);
3007 distance.Add(addDistance); 3007 distance.Add(addDistance);
3008 } 3008 }
3009 else if (node_1.Y == node_2.Y) 3009 else if (node_1.Y == node_2.Y)
3010 { 3010 {
3011 addDistance = Math.Abs(node_1.X - node_2.X); 3011 addDistance = Math.Abs(node_1.X - node_2.X);
3012 distance.Add(addDistance); 3012 distance.Add(addDistance);
3013 } 3013 }
3014 else 3014 else
3015 { 3015 {
3016 var a = (double)(node_2.X - node_1.X); 3016 var a = (double)(node_2.X - node_1.X);
3017 var b = (double)(node_2.Y - node_1.Y); 3017 var b = (double)(node_2.Y - node_1.Y);
3018 addDistance = Math.Sqrt(a * a + b * b); 3018 addDistance = Math.Sqrt(a * a + b * b);
3019 distance.Add(addDistance); 3019 distance.Add(addDistance);
3020 } 3020 }
3021 } 3021 }
3022 } 3022 }
3023 } 3023 }
3024 if (distance.Count > 0) 3024 if (distance.Count > 0)
3025 { 3025 {
3026 double total = 0; 3026 double total = 0;
3027 double distance_i; 3027 double distance_i;
3028 3028
3029 for (int i = 0; i < distance.Count; i++) 3029 for (int i = 0; i < distance.Count; i++)
3030 { 3030 {
3031 total = total + distance[i]; 3031 total = total + distance[i];
3032 } 3032 }
3033 3033
3034 for (int i = 0; i < distance.Count; i++) 3034 for (int i = 0; i < distance.Count; i++)
3035 { 3035 {
3036 distance_i = distance[i] * (Totaldistance / total); 3036 distance_i = distance[i] * (Totaldistance / total);
3037 distance[i] = distance_i; 3037 distance[i] = distance_i;
3038 } 3038 }
3039 } 3039 }
3040 3040
3041 if (gGrpBlueNode.Children.Count > 0) 3041 if (gGrpBlueNode.Children.Count > 0)
3042 { 3042 {
3043 node_Schedule.X = x_1; 3043 node_Schedule.X = x_1;
3044 node_Schedule.Y = y_1; 3044 node_Schedule.Y = y_1;
3045 AddNode(node_Schedule, gGrpScheduleNode); 3045 AddNode(node_Schedule, gGrpScheduleNode);
3046 } 3046 }
3047 3047
3048 addDistance = 0; 3048 addDistance = 0;
3049 for (int i = 0; i < distance.Count; i++) 3049 for (int i = 0; i < distance.Count; i++)
3050 { 3050 {
3051 3051
3052 node_Schedule.Y = y_1; 3052 node_Schedule.Y = y_1;
3053 addDistance = addDistance + distance[i]; 3053 addDistance = addDistance + distance[i];
3054 node_Schedule.X = addDistance; 3054 node_Schedule.X = addDistance;
3055 AddNode(node_Schedule, gGrpScheduleNode); 3055 AddNode(node_Schedule, gGrpScheduleNode);
3056 } 3056 }
3057 3057
3058 if (gGrpScheduleNode.Children.Count > 0) 3058 if (gGrpScheduleNode.Children.Count > 0)
3059 { 3059 {
3060 for (int i = 0; i < gGrpScheduleNode.Children.Count; i++) 3060 for (int i = 0; i < gGrpScheduleNode.Children.Count; i++)
3061 { 3061 {
3062 ellipseGeometry_1 = (EllipseGeometry)gGrpScheduleNode.Children[i]; 3062 ellipseGeometry_1 = (EllipseGeometry)gGrpScheduleNode.Children[i];
3063 node_1 = ellipseGeometry_1.Center; 3063 node_1 = ellipseGeometry_1.Center;
3064 if (i > 0) 3064 if (i > 0)
3065 { 3065 {
3066 ellipseGeometry_2 = (EllipseGeometry)gGrpScheduleNode.Children[i -1]; 3066 ellipseGeometry_2 = (EllipseGeometry)gGrpScheduleNode.Children[i -1];
3067 node_2 = ellipseGeometry_2.Center; 3067 node_2 = ellipseGeometry_2.Center;
3068 DrawLine(node_1, node_2, gGrpScheduleLine); 3068 DrawLine(node_1, node_2, gGrpScheduleLine);
3069 } 3069 }
3070 CreateScheduleNode(node_1, i + 1); 3070 CreateScheduleNode(node_1, i + 1);
3071 } 3071 }
3072 } 3072 }
3073 } 3073 }
3074 3074
3075 private void CreateScheduleNode(Point point, int indexNode) 3075 private void CreateScheduleNode(Point point, int indexNode)
3076 { 3076 {
3077 ucNode _ucNode = new ucNode(); 3077 ucNode _ucNode = new ucNode();
3078 _ucNode.btnWidth = UCNODE_WIDTH; 3078 _ucNode.btnWidth = UCNODE_WIDTH;
3079 _ucNode.btnHeight = UCNODE_HEIGHT; 3079 _ucNode.btnHeight = UCNODE_HEIGHT;
3080 _ucNode.txtNode = indexNode.ToString(); 3080 _ucNode.txtNode = indexNode.ToString();
3081 _ucNode.IsDragDelta = false; 3081 _ucNode.IsDragDelta = false;
3082 Canvas.SetLeft(_ucNode, point.X - UCNODE_SETLEFT); 3082 Canvas.SetLeft(_ucNode, point.X - UCNODE_SETLEFT);
3083 Canvas.SetTop(_ucNode, point.Y - UCNODE_SETTOP); 3083 Canvas.SetTop(_ucNode, point.Y - UCNODE_SETTOP);
3084 scheduleCanvas.Children.Add(_ucNode); 3084 scheduleCanvas.Children.Add(_ucNode);
3085 ucScheduleNode_Lst.Add(_ucNode); 3085 ucScheduleNode_Lst.Add(_ucNode);
3086 } 3086 }
3087 3087
3088 #endregion 3088 #endregion
3089 3089
3090 } 3090 }
3091 } 3091 }
3092 3092
sources/RoboforkApp/Controls/ScheduleCanvas.cs
1 using System; 1 using System;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.Linq; 3 using System.Linq;
4 using System.Text; 4 using System.Text;
5 using System.Threading.Tasks; 5 using System.Threading.Tasks;
6 using System.Windows; 6 using System.Windows;
7 using System.Windows.Controls; 7 using System.Windows.Controls;
8 using System.Windows.Media; 8 using System.Windows.Media;
9 using System.Windows.Media.Animation; 9 using System.Windows.Media.Animation;
10 using System.Windows.Shapes; 10 using System.Windows.Shapes;
11 11
12 namespace RoboforkApp 12 namespace RoboforkApp
13 { 13 {
14 public class ScheduleCanvas : Canvas 14 public class ScheduleCanvas : Canvas
15 { 15 {
16 //private simulationRobo simulation; 16 const double COOR_Y = 65;
17 const double RADIUS_NODE = 25;
18 private simulationRobo simulation;
19 private Point startPoint;
20 private Point endPoint;
21 private bool _isGoal = false;
22 private double _speed = 0.2; //Now _speed is fixed, but when update node
23 private int index;
17 24
18 public void CreateSimulation() 25 private List<ucNode> _lstNode;
26
27 /// <summary>
28 /// Create simulation
29 /// </summary>
30 /// <param name="lstNode"></param>
31 public void CreateSimulation(List<ucNode> lstNode)
19 { 32 {
20 //if(simulation != null || this.Children.Count < 2) 33 //If node is less than 2 so return
21 //{ 34 if (this.Children.Count < 2)
22 // return; 35 {
23 //} 36 return;
37 }
24 38
39 this.Children.Remove(simulation);
40
41 //Init data
42 this._lstNode = lstNode;
43 this.startPoint = new Point(Canvas.GetLeft(_lstNode[index]) + RADIUS_NODE, COOR_Y);
44 this.endPoint = new Point(Canvas.GetLeft(_lstNode[index + 1]) + RADIUS_NODE, COOR_Y);
45 this.index += 1;
46 if (index == _lstNode.Count - 1)
47 {
48 _isGoal = true;
49 }
50
51 // Start simulation
52 RoboSimulation();
53 }
54
55 /// <summary>
56 /// Create robo simulation on line
57 /// </summary>
58 private void RoboSimulation()
59 {
60 simulation = new simulationRobo();
61 simulation.storyBoard = CreatPathAnimation(startPoint, endPoint, _speed); //pathAnimationStoryboard;
62 this.Children.Add(simulation);
63 }
64
65 /// <summary>
66 /// Get storyboard
67 /// </summary>
68 /// <param name="startPoint">Point start line</param>
69 /// <param name="endPoit">Point end line</param>
70 /// <param name="speed">speed on line</param>
71 /// <returns>Storyboard</returns>
72 private Storyboard CreatPathAnimation(Point startPoint, Point endPoit, double speed)
73 {
25 PathGeometry animationPath = new PathGeometry(); 74 PathGeometry animationPath = new PathGeometry();
26 PathFigure pFigure = new PathFigure(); 75 PathFigure pFigure = new PathFigure();
27 pFigure.StartPoint = new Point(50, 65); 76 pFigure.StartPoint = startPoint; //new Point(50, 65);
28 LineSegment lineSegment = new LineSegment(); 77 LineSegment lineSegment = new LineSegment();
29 lineSegment.Point = new Point(1270, 65); 78 lineSegment.Point = endPoit; // new Point(800, 65);
30 pFigure.Segments.Add(lineSegment); 79 pFigure.Segments.Add(lineSegment);
31 animationPath.Figures.Add(pFigure); 80 animationPath.Figures.Add(pFigure);
32 81
33 // Freeze the PathGeometry for performance benefits. 82 // Freeze the PathGeometry for performance benefits.
34 animationPath.Freeze(); 83 animationPath.Freeze();
35 84
36 // Create a MatrixAnimationUsingPath to move the 85 // Create a MatrixAnimationUsingPath to move the
37 // button along the path by animating 86 // simulation along the path by animating
38 // its MatrixTransform. 87 // its MatrixTransform.
39 MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath(); 88 MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();
40 matrixAnimation.PathGeometry = animationPath; 89 matrixAnimation.PathGeometry = animationPath;
41 matrixAnimation.Duration = TimeSpan.FromSeconds(10); 90 matrixAnimation.SpeedRatio = speed;
42 //matrixAnimation.RepeatBehavior = RepeatBehavior.Forever;
43 matrixAnimation.AutoReverse = false; 91 matrixAnimation.AutoReverse = false;
44 matrixAnimation.DoesRotateWithTangent = true; 92 matrixAnimation.DoesRotateWithTangent = true;
93 matrixAnimation.Completed += delegate { AnimationCompleted(this._isGoal); };
45 94
46 // Set the animation to target the Matrix property 95 // Set the animation to target the Matrix property
47 // of the MatrixTransform named "ButtonMatrixTransform". 96 // of the MatrixTransform named "ButtonMatrixTransform".
48 Storyboard.SetTargetName(matrixAnimation, "fl"); 97 Storyboard.SetTargetName(matrixAnimation, "fl");
49 Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty)); 98 Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty));
50 99
51 // Create a Storyboard to contain and apply the animation. 100 // Create a Storyboard to contain and apply the animation.
52 Storyboard pathAnimationStoryboard = new Storyboard(); 101 Storyboard pathAnimationStoryboard = new Storyboard();
53 pathAnimationStoryboard.Children.Add(matrixAnimation); 102 pathAnimationStoryboard.Children.Add(matrixAnimation);
54 103
55 //simulation = new simulationRobo(); 104 return pathAnimationStoryboard;
56 //simulation.storyBoard = pathAnimationStoryboard; 105 }
57 //this.Children.Add(simulation); 106
107 /// <summary>
108 /// Process when simulation is end line
109 /// </summary>
110 /// <param name="isGoal">check is node end</param>
111 private void AnimationCompleted(bool isGoal)
112 {
113 // If not end node
114 if (!isGoal)
115 {
116 this.index += 1;
117 this.Children.Remove(simulation);
118 this.startPoint = endPoint;
119 this.endPoint = new Point(Canvas.GetLeft(_lstNode[index]) + RADIUS_NODE, COOR_Y);
120
121 if (this.index == this._lstNode.Count - 1)
122 {
123 this._isGoal = true;
124 }
125 this._speed += 0.2;
126 RoboSimulation();
127 return;
128 }
129
130 // Reset data when finish
131 this.index = 0;
132 this._speed = 0.2;
133 this._isGoal = false;
58 } 134 }
59 } 135 }
60 } 136 }
sources/RoboforkApp/RoboforkMenuView.xaml.cs
1 using System; 1 using System;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.Linq; 3 using System.Linq;
4 using System.Text; 4 using System.Text;
5 using System.Threading.Tasks; 5 using System.Threading.Tasks;
6 using System.Windows; 6 using System.Windows;
7 using System.Windows.Controls; 7 using System.Windows.Controls;
8 using System.Windows.Data; 8 using System.Windows.Data;
9 using System.Windows.Documents; 9 using System.Windows.Documents;
10 using System.Windows.Input; 10 using System.Windows.Input;
11 using System.Windows.Media; 11 using System.Windows.Media;
12 using System.Windows.Media.Imaging; 12 using System.Windows.Media.Imaging;
13 using System.Windows.Shapes; 13 using System.Windows.Shapes;
14 14
15 namespace RoboforkApp 15 namespace RoboforkApp
16 { 16 {
17 /// <summary> 17 /// <summary>
18 /// Interaction logic for RoboforkMenu.xaml 18 /// Interaction logic for RoboforkMenu.xaml
19 /// </summary> 19 /// </summary>
20 public partial class RoboforkMenu : Window 20 public partial class RoboforkMenu : Window
21 { 21 {
22 public int IndexVehicle = 15; 22 public int IndexVehicle = 15;
23 public RoboforkMenu() 23 public RoboforkMenu()
24 { 24 {
25 InitializeComponent(); 25 InitializeComponent();
26 Load_Form(); 26 Load_Form();
27 } 27 }
28 28
29 private void Load_Form() 29 private void Load_Form()
30 { 30 {
31 //PassplanTree.IsEnabled = false; 31 //PassplanTree.IsEnabled = false;
32 //NodeTree.IsEnabled = false; 32 //NodeTree.IsEnabled = false;
33 33
34 } 34 }
35 35
36 private void btnMenu_Selected(object sender, RoutedEventArgs e) 36 private void btnMenu_Selected(object sender, RoutedEventArgs e)
37 { 37 {
38 if (((TreeViewItem)sender) == null) 38 if (((TreeViewItem)sender) == null)
39 { 39 {
40 return; 40 return;
41 } 41 }
42 42
43 string tag = ((TreeViewItem)sender).Tag.ToString(); 43 string tag = ((TreeViewItem)sender).Tag.ToString();
44 switch (tag) 44 switch (tag)
45 { 45 {
46 //2017/03/04 NAM ADD START1 46 //2017/03/04 NAM ADD START1
47 case "NodeTree": 47 case "NodeTree":
48 NewDoBeginSetFreeNotes(); 48 NewDoBeginSetFreeNotes();
49 break; 49 break;
50 //2017/03/04 NAM ADD END 50 //2017/03/04 NAM ADD END
51 51
52 case "SetupRestriction": 52 case "SetupRestriction":
53 DoBeginSetupRestriction(); 53 DoBeginSetupRestriction();
54 break; 54 break;
55 55
56 case "SetStart": 56 case "SetStart":
57 DoBeginSetStart(); 57 DoBeginSetStart();
58 break; 58 break;
59 59
60 case "SetGoal": 60 case "SetGoal":
61 DoBeginSetGoal(); 61 DoBeginSetGoal();
62 break; 62 break;
63 63
64 case "SetupRoute": 64 case "SetupRoute":
65 DoBeginSetupRoute(); 65 DoBeginSetupRoute();
66 break; 66 break;
67 67
68 case "MakeRoot": 68 case "MakeRoot":
69 DoBeginMakeRoot(); 69 DoBeginMakeRoot();
70 break; 70 break;
71 71
72 case "DeleteRoute": 72 case "DeleteRoute":
73 DoBeginDeleteRoute(); 73 DoBeginDeleteRoute();
74 break; 74 break;
75 75
76 case "SetAutoNodes": 76 case "SetAutoNodes":
77 DoBeginSetAutoNotes(); 77 DoBeginSetAutoNotes();
78 break; 78 break;
79 79
80 case "SetFreeNodes": 80 case "SetFreeNodes":
81 DoBeginSetFreeNotes(); 81 DoBeginSetFreeNotes();
82 break; 82 break;
83 83
84 case "ScheduleRoute": 84 case "ScheduleRoute":
85 85
86 DoBeginSetSchedule(); 86 DoBeginSetSchedule();
87 break; 87 break;
88 case "TaskpattermTree": 88 case "TaskpattermTree":
89 DoBeginTask(); 89 DoBeginTask();
90 break; 90 break;
91 default: 91 default:
92 break; 92 break;
93 } 93 }
94 } 94 }
95 95
96 private void DoBeginSetSchedule() 96 private void DoBeginSetSchedule()
97 { 97 {
98 98
99 MyDesignerCanvas.SetScheduleRoute(); 99 MyDesignerCanvas.SetScheduleRoute();
100 } 100 }
101 101
102 private void NewDoBeginSetFreeNotes() 102 private void NewDoBeginSetFreeNotes()
103 { 103 {
104 MyDesignerCanvas.Init(); 104 MyDesignerCanvas.Init();
105 MyDesignerCanvas.Operation = DesignerCanvas.OperationState.NewDrawSetFreeNode; 105 MyDesignerCanvas.Operation = DesignerCanvas.OperationState.NewDrawSetFreeNode;
106 MyDesignerCanvas.scheduleCanvas = MyScheduleCanvas; 106 MyDesignerCanvas.scheduleCanvas = MyScheduleCanvas;
107 107
108 } 108 }
109 109
110 private void btnMenu_UnselectedSet(object sender, RoutedEventArgs e) 110 private void btnMenu_UnselectedSet(object sender, RoutedEventArgs e)
111 { 111 {
112 if (((TreeViewItem)sender) == null) 112 if (((TreeViewItem)sender) == null)
113 { 113 {
114 return; 114 return;
115 } 115 }
116 116
117 string tag = ((TreeViewItem)sender).Tag.ToString(); 117 string tag = ((TreeViewItem)sender).Tag.ToString();
118 switch (tag) 118 switch (tag)
119 { 119 {
120 case "SetupRestriction": 120 case "SetupRestriction":
121 //DoBeginSetStart(); 121 //DoBeginSetStart();
122 break; 122 break;
123 123
124 case "SetStart": 124 case "SetStart":
125 //DoBeginSetStart(); 125 //DoBeginSetStart();
126 break; 126 break;
127 127
128 case "SetGoal": 128 case "SetGoal":
129 //DoBeginSetGoal(); 129 //DoBeginSetGoal();
130 break; 130 break;
131 131
132 case "DeleteRoute": 132 case "DeleteRoute":
133 //DoBeginDeleteRoute(); 133 //DoBeginDeleteRoute();
134 break; 134 break;
135 135
136 case "SetupRoute": 136 case "SetupRoute":
137 //DoBeginSetupRoute(); 137 //DoBeginSetupRoute();
138 break; 138 break;
139 139
140 case "MakeRoot": 140 case "MakeRoot":
141 //DoBeginMakeRoot(); 141 //DoBeginMakeRoot();
142 break; 142 break;
143 143
144 default: 144 default:
145 break; 145 break;
146 } 146 }
147 } 147 }
148 148
149 private void DoBeginTask() 149 private void DoBeginTask()
150 { 150 {
151 MyScheduleCanvas.CreateSimulation(); 151 MyScheduleCanvas.CreateSimulation(MyDesignerCanvas.ucScheduleNode_Lst);
152 } 152 }
153 153
154 private void DoBeginSetAutoNotes() 154 private void DoBeginSetAutoNotes()
155 { 155 {
156 MyDesignerCanvas.SetAutoNodes(); 156 MyDesignerCanvas.SetAutoNodes();
157 } 157 }
158 158
159 private void DoBeginSetFreeNotes() 159 private void DoBeginSetFreeNotes()
160 { 160 {
161 MyDesignerCanvas.Init(); 161 MyDesignerCanvas.Init();
162 MyDesignerCanvas.Operation = DesignerCanvas.OperationState.DrawSetFreeNode; 162 MyDesignerCanvas.Operation = DesignerCanvas.OperationState.DrawSetFreeNode;
163 } 163 }
164 164
165 private void DoBeginSetupRestriction() 165 private void DoBeginSetupRestriction()
166 { 166 {
167 MyDesignerCanvas.Init(); 167 MyDesignerCanvas.Init();
168 MyDesignerCanvas.Operation = DesignerCanvas.OperationState.DrawObstract; 168 MyDesignerCanvas.Operation = DesignerCanvas.OperationState.DrawObstract;
169 MyDesignerCanvas.mouseState = DesignerCanvas.MouseState.None; 169 MyDesignerCanvas.mouseState = DesignerCanvas.MouseState.None;
170 } 170 }
171 171
172 private void DoBeginSetStart() 172 private void DoBeginSetStart()
173 { 173 {
174 MyDesignerCanvas.CreateStartPoint(); 174 MyDesignerCanvas.CreateStartPoint();
175 } 175 }
176 176
177 private void DoBeginSetGoal() 177 private void DoBeginSetGoal()
178 { 178 {
179 MyDesignerCanvas.CreateGoalPoint(); 179 MyDesignerCanvas.CreateGoalPoint();
180 } 180 }
181 181
182 private void DoBeginSetupRoute() 182 private void DoBeginSetupRoute()
183 { 183 {
184 MyDesignerCanvas.Operation = DesignerCanvas.OperationState.DrawRoute; 184 MyDesignerCanvas.Operation = DesignerCanvas.OperationState.DrawRoute;
185 } 185 }
186 186
187 private void DoBeginMakeRoot() 187 private void DoBeginMakeRoot()
188 { 188 {
189 MyDesignerCanvas.Children.Remove(MyDesignerCanvas.pRootLine); 189 MyDesignerCanvas.Children.Remove(MyDesignerCanvas.pRootLine);
190 MyDesignerCanvas.MakeRoot(); 190 MyDesignerCanvas.MakeRoot();
191 } 191 }
192 192
193 private void DoBeginDeleteRoute() 193 private void DoBeginDeleteRoute()
194 { 194 {
195 MessageBoxResult result = MessageBox.Show("Do you want delete route?", "Delete route", MessageBoxButton.OKCancel); 195 MessageBoxResult result = MessageBox.Show("Do you want delete route?", "Delete route", MessageBoxButton.OKCancel);
196 if (result == MessageBoxResult.OK) 196 if (result == MessageBoxResult.OK)
197 { 197 {
198 MyDesignerCanvas.ClearRoute(); 198 MyDesignerCanvas.ClearRoute();
199 } 199 }
200 } 200 }
201 201
202 private void GetPassplanTree(object sender, RoutedEventArgs e) 202 private void GetPassplanTree(object sender, RoutedEventArgs e)
203 { 203 {
204 MessageBoxResult result = MessageBox.Show("Selected PassplanTree", "", MessageBoxButton.OKCancel); 204 MessageBoxResult result = MessageBox.Show("Selected PassplanTree", "", MessageBoxButton.OKCancel);
205 } 205 }
206 206
207 private void SetPassplanTree(object sender, RoutedEventArgs e) 207 private void SetPassplanTree(object sender, RoutedEventArgs e)
208 { 208 {
209 209
210 } 210 }
211 211
212 private void GetNodeTree(object sender, RoutedEventArgs e) 212 private void GetNodeTree(object sender, RoutedEventArgs e)
213 { 213 {
214 MessageBoxResult result = MessageBox.Show("Selected NodeTree", "", MessageBoxButton.OKCancel); 214 MessageBoxResult result = MessageBox.Show("Selected NodeTree", "", MessageBoxButton.OKCancel);
215 } 215 }
216 216
217 private void SetNodeTree(object sender, RoutedEventArgs e) 217 private void SetNodeTree(object sender, RoutedEventArgs e)
218 { 218 {
219 219
220 } 220 }
221 221
222 private void GetFK15Tree(object sender, RoutedEventArgs e) 222 private void GetFK15Tree(object sender, RoutedEventArgs e)
223 { 223 {
224 MessageBoxResult result = MessageBox.Show("Selected FK15Tree", "", MessageBoxButton.OKCancel); 224 MessageBoxResult result = MessageBox.Show("Selected FK15Tree", "", MessageBoxButton.OKCancel);
225 } 225 }
226 226
227 private void SetFK15Tree(object sender, RoutedEventArgs e) 227 private void SetFK15Tree(object sender, RoutedEventArgs e)
228 { 228 {
229 229
230 } 230 }
231 231
232 private void GetVehicleAddTree(object sender, RoutedEventArgs e) 232 private void GetVehicleAddTree(object sender, RoutedEventArgs e)
233 { 233 {
234 MessageBoxResult result = MessageBox.Show("Selected VehicleAddTree", "", MessageBoxButton.OKCancel); 234 MessageBoxResult result = MessageBox.Show("Selected VehicleAddTree", "", MessageBoxButton.OKCancel);
235 } 235 }
236 236
237 #region Add new Vehicle Item 237 #region Add new Vehicle Item
238 238
239 private void btnVehicleItem_Selected(object sender, RoutedEventArgs e) 239 private void btnVehicleItem_Selected(object sender, RoutedEventArgs e)
240 { 240 {
241 if (((TreeViewItem)sender) == null) 241 if (((TreeViewItem)sender) == null)
242 { 242 {
243 return; 243 return;
244 } 244 }
245 245
246 string tag = ((TreeViewItem)sender).Tag.ToString(); 246 string tag = ((TreeViewItem)sender).Tag.ToString();
247 switch (tag) 247 switch (tag)
248 { 248 {
249 case "VehicleAddTree": 249 case "VehicleAddTree":
250 AddNewVehicleItem(); 250 AddNewVehicleItem();
251 break; 251 break;
252 252
253 case "VehicleItem": 253 case "VehicleItem":
254 GetDataVehicle(); 254 GetDataVehicle();
255 break; 255 break;
256 256
257 default: 257 default:
258 break; 258 break;
259 } 259 }
260 } 260 }
261 261
262 262
263 private void AddNewVehicleItem() 263 private void AddNewVehicleItem()
264 { 264 {
265 IndexVehicle += 1; 265 IndexVehicle += 1;
266 266
267 Vehicle.Items.RemoveAt(Vehicle.Items.Count - 1); 267 Vehicle.Items.RemoveAt(Vehicle.Items.Count - 1);
268 Vehicle.Items.RemoveAt(Vehicle.Items.Count - 1); 268 Vehicle.Items.RemoveAt(Vehicle.Items.Count - 1);
269 269
270 TreeViewItem item = new TreeViewItem(); 270 TreeViewItem item = new TreeViewItem();
271 item.Header = "FK"+ IndexVehicle.ToString()+"_#1"; 271 item.Header = "FK"+ IndexVehicle.ToString()+"_#1";
272 item.Tag = "VehicleItem"; 272 item.Tag = "VehicleItem";
273 item.FontSize = 17; 273 item.FontSize = 17;
274 item.Selected += new RoutedEventHandler(btnVehicleItem_Selected); 274 item.Selected += new RoutedEventHandler(btnVehicleItem_Selected);
275 item.Name = "FK_" + IndexVehicle.ToString(); 275 item.Name = "FK_" + IndexVehicle.ToString();
276 Vehicle.Items.Add(item); 276 Vehicle.Items.Add(item);
277 277
278 TreeViewItem item2 = new TreeViewItem(); 278 TreeViewItem item2 = new TreeViewItem();
279 item2.Header = "[+]"; 279 item2.Header = "[+]";
280 item2.Tag = "VehicleAddTree"; 280 item2.Tag = "VehicleAddTree";
281 item2.FontSize = 17; 281 item2.FontSize = 17;
282 item2.Selected += new RoutedEventHandler(btnVehicleItem_Selected); 282 item2.Selected += new RoutedEventHandler(btnVehicleItem_Selected);
283 item2.Name = "VehicleAdd"; 283 item2.Name = "VehicleAdd";
284 Vehicle.Items.Add(item2); 284 Vehicle.Items.Add(item2);
285 285
286 TreeViewItem item3 = new TreeViewItem(); 286 TreeViewItem item3 = new TreeViewItem();
287 item3.Header = "--------------------"; 287 item3.Header = "--------------------";
288 item3.FontSize = 17; 288 item3.FontSize = 17;
289 item3.Name = "UnderLine"; 289 item3.Name = "UnderLine";
290 Vehicle.Items.Add(item3); 290 Vehicle.Items.Add(item3);
291 291
292 } 292 }
293 293
294 294
295 private void GetDataVehicle() 295 private void GetDataVehicle()
296 { 296 {
297 297
298 } 298 }
299 299
300 #endregion 300 #endregion
301 301
302 302
303 303
304 304
305 private void SetVehicleAddTree(object sender, RoutedEventArgs e) 305 private void SetVehicleAddTree(object sender, RoutedEventArgs e)
306 { 306 {
307 307
308 } 308 }
309 309
310 private void GetTaskpattermTree(object sender, RoutedEventArgs e) 310 private void GetTaskpattermTree(object sender, RoutedEventArgs e)
311 { 311 {
312 312
313 } 313 }
314 314
315 private void SetTaskpattermTree(object sender, RoutedEventArgs e) 315 private void SetTaskpattermTree(object sender, RoutedEventArgs e)
316 { 316 {
317 317
318 } 318 }
319 319
320 private void GetWorkAddTree(object sender, RoutedEventArgs e) 320 private void GetWorkAddTree(object sender, RoutedEventArgs e)
321 { 321 {
322 322
323 } 323 }
324 324
325 private void SetWorkAddTree(object sender, RoutedEventArgs e) 325 private void SetWorkAddTree(object sender, RoutedEventArgs e)
326 { 326 {
327 327
328 } 328 }
329 329
330 private void GetConnectTree(object sender, RoutedEventArgs e) 330 private void GetConnectTree(object sender, RoutedEventArgs e)
331 { 331 {
332 332
333 } 333 }
334 334
335 private void SetConnectTree(object sender, RoutedEventArgs e) 335 private void SetConnectTree(object sender, RoutedEventArgs e)
336 { 336 {
337 337
338 } 338 }
339 339
340 private void GetParameterTree(object sender, RoutedEventArgs e) 340 private void GetParameterTree(object sender, RoutedEventArgs e)
341 { 341 {
342 342
343 } 343 }
344 344
345 private void SetParameterTree(object sender, RoutedEventArgs e) 345 private void SetParameterTree(object sender, RoutedEventArgs e)
346 { 346 {
347 347
348 } 348 }
349 349
350 private void GetScheduleTree(object sender, RoutedEventArgs e) 350 private void GetScheduleTree(object sender, RoutedEventArgs e)
351 { 351 {
352 352
353 } 353 }
354 354
355 private void SetScheduleTree(object sender, RoutedEventArgs e) 355 private void SetScheduleTree(object sender, RoutedEventArgs e)
356 { 356 {
357 357
358 } 358 }
359 359
360 private void GetLoggingTree(object sender, RoutedEventArgs e) 360 private void GetLoggingTree(object sender, RoutedEventArgs e)
361 { 361 {
362 362
363 } 363 }
364 364
365 private void SetLoggingTree(object sender, RoutedEventArgs e) 365 private void SetLoggingTree(object sender, RoutedEventArgs e)
366 { 366 {
367 367
368 } 368 }
369 369
370 private void GetAlertTree(object sender, RoutedEventArgs e) 370 private void GetAlertTree(object sender, RoutedEventArgs e)
371 { 371 {
372 372
373 } 373 }
374 374
375 private void SetAlertTree(object sender, RoutedEventArgs e) 375 private void SetAlertTree(object sender, RoutedEventArgs e)
376 { 376 {
377 377
378 } 378 }
379 379
380 private void GetHelpTree(object sender, RoutedEventArgs e) 380 private void GetHelpTree(object sender, RoutedEventArgs e)
381 { 381 {
382 382
383 } 383 }
384 384
385 private void SetHelpTree(object sender, RoutedEventArgs e) 385 private void SetHelpTree(object sender, RoutedEventArgs e)
386 { 386 {
387 387
388 } 388 }
389 389
390 private void GetNewProjectTree(object sender, RoutedEventArgs e) 390 private void GetNewProjectTree(object sender, RoutedEventArgs e)
391 { 391 {
392 392
393 } 393 }
394 394
395 private void SetNewProjectTree(object sender, RoutedEventArgs e) 395 private void SetNewProjectTree(object sender, RoutedEventArgs e)
396 { 396 {
397 397
398 } 398 }
399 399
400 400
401 } 401 }
402 } 402 }
403 403