Commit 57fdd8bb89a2ef94ba5b32f1de5d16a8639413e9

Authored by toan
1 parent 1fe3e8a873
Exists in master

RM2063 : Commit demo

Showing 3 changed files with 62 additions and 18 deletions Inline Diff

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