Commit 160b9bec85381381f5d8e0199102d7517151f5f4

Authored by nguyen_nam
1 parent b338e1ff57
Exists in master

Tbl Node info

Showing 1 changed file with 57 additions and 16 deletions Inline Diff

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