Blame view

sources/RoboforkApp/Controls/DesignerCanvas.cs 144 KB
fd7150b8b   doan   Update Task 2062
1
  using RoboforkApp.DataModel;
01c8c8f49   doan   Update Task 2068
2
3
  //using RoboforkApp.Entities;
  //using RoboforkApp.Services;
fd7150b8b   doan   Update Task 2062
4
  using System;
729be9a6d   doan   New Project
5
6
7
8
9
10
11
12
13
14
  using System.Collections.Generic;
  using System.Linq;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Markup;
  using System.Windows.Media;
  using System.Windows.Shapes;
  using System.Xml;
01c8c8f49   doan   Update Task 2068
15
16
  using System.Data;
  using RoboforkApp.View;
e3ae88363   toan   RM2077: Commit so...
17
18
  using RoboforkApp.Services;
  using RoboforkApp.Entities;
d7d5faa7d   nguyen_nam   Task 2100
19
  using System.Windows.Media.Animation;
729be9a6d   doan   New Project
20
21
22
23
24
  
  namespace RoboforkApp
  {
      public class DesignerCanvas : Canvas
      {
b338e1ff5   nguyen_nam   no message
25
          const double RADIUS_NODE = 25d; //8d;
729be9a6d   doan   New Project
26
27
28
29
30
31
32
33
34
          const double RADIUS_CURVER_LINE = 130d;
          const double DISTANCE_AUTO_NODES = 100d;
          const double DISTANCE_START_NODES = 30d;
          const double DISTANCE_END_NODES = 30d;
          const double DISTANCE_FREE_NODES = 40d;
          const double STROKE_ROOT_LINE = 6d;
          const double STROKE_LINE = 4d;
          const double STROKE_NODE = 1d;
          const double DISTANCE_RATIO = 100;
d96c9e481   doan   Update Source Code
35
36
37
38
          const double UCNODE_SETLEFT = 17;
          const double UCNODE_SETTOP = 17;
          const double UCNODE_WIDTH = 34;
          const double UCNODE_HEIGHT = 34;
80ae927f4   doan   no message
39
40
41
42
          const double UCSCHEDULENODE_SETLEFT = 12;
          const double UCSCHEDULENODE_SETTOP = 12;
          const double UCSCHEDULENODE_WIDTH = 24;
          const double UCSCHEDULENODE_HEIGHT = 24;
886851415   toan   RM2101 : Commit s...
43
44
          
          public static bool isReloadDB = false;
80ae927f4   doan   no message
45

729be9a6d   doan   New Project
46
47
48
49
50
          private List<Rectangle> shapeList = new List<Rectangle>();
          private TextBlock shapePosIndicator;
          private TextBlock shapeSizeIndicator;
          private int currentLine;
          private ucStartEndButton _startPoint;
a47f478f0   doan   開発 #2045 : node の...
51
          private ucNode _ucNodeFree;
729be9a6d   doan   New Project
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
          private ucStartEndButton _goalPoint;
          private ucDisplayCoordinate _displayAxiPosition;
  
          // Add variable for draw route
          public Path pLine = new Path();
          public Path pRootLine = new Path();
          public Path pCurverLine = new Path();
          public Path pRedNode = new Path();
          public Path pYellowNode = new Path();
          public GeometryGroup gGrpLine = new GeometryGroup();
          public GeometryGroup gGrpRootLine = new GeometryGroup();
          public GeometryGroup gGrpCurverLine = new GeometryGroup();
          public GeometryGroup gGrpRedNode = new GeometryGroup();
          public GeometryGroup gGrpYellowNode = new GeometryGroup();
          public int currentShape;
          public static bool isStartDrawRoute = false;
          public static bool isGoalDrawRoute = false;
01c8c8f49   doan   Update Task 2068
69
          public static bool readMapFan = true;
80ae927f4   doan   no message
70
71
72
          public static double CanvasScheduleWidth = 0;
          public static double CanvasScheduleHeight = 0;
          public const double NodeSchedule_X = 50;
47aa77821   doan   Update task 2095
73
74
75
76
77
          public double PointMapStart_X = 127.85783428698775;
          public double PointMapStart_Y = 26.336094486866543;
  
          public double PointMapEnd_X = 128.85783428698775;
          public double PointMapEnd_Y = 27.336094486866543;
5db801240   doan   update 2099
78

47aa77821   doan   Update task 2095
79
80
81
82
          const double DISTANCEMAPDISPLAY = 1000;
  
          public double Scale_X = 0;
          public double Scale_Y = 0;
729be9a6d   doan   New Project
83
84
85
86
87
88
89
90
91
          public struct NodeInfo
          {
              public double X;
              public double Y;
              public String Mode1;
              public String Mode2;
              public String Mode3;
          }
          List<NodeInfo> NodeInfo_List = new List<NodeInfo>();
b338e1ff5   nguyen_nam   no message
92
93
94
95
96
          // Add variable for Set Schedule
          public Path pScheduleNode = new Path();
          public Path pScheduleLine = new Path();
          public GeometryGroup gGrpScheduleNode = new GeometryGroup();
          public GeometryGroup gGrpScheduleLine = new GeometryGroup();
a47f478f0   doan   開発 #2045 : node の...
97
98
          public static bool EditNodeFlag = false;
          public static bool DragDeltaFlag = false;
6df37ad27   doan   no message
99
          public static int UcNode_Index = 0;
e3ae88363   toan   RM2077: Commit so...
100
          public static bool LoadDBFlag = false;
b338e1ff5   nguyen_nam   no message
101

fd7150b8b   doan   Update Task 2062
102
103
          //Add variable for Vehicle Item click
          public string VehicleItem = "FK_15";
5a5c5239e   nguyen_nam   Task: 2095
104

fd7150b8b   doan   Update Task 2062
105
          public int VehicleIndex = 0;
6312cbd86   doan   Task 2062
106
107
          public string ColorNode_Add = "Blue";
          public string ColorNode_Insert = "Brown";
fd7150b8b   doan   Update Task 2062
108

5a5c5239e   nguyen_nam   Task: 2095
109
110
111
          public int ProjectIndex = 0;
          public string ProjectItem = "ProjectAAA";
          public ProjectModel ProjectModel = new ProjectModel();
b338e1ff5   nguyen_nam   no message
112
113
          //2017/03/04 NAM ADD START
          public static bool isDrawingNode = false;
a47f478f0   doan   開発 #2045 : node の...
114
          public static bool isDragNode = false;
b338e1ff5   nguyen_nam   no message
115
116
117
118
119
120
121
122
123
124
          public Path pNewLine = new Path();
          public GeometryGroup gGrpNewLine = new GeometryGroup();
  
          public struct NewNodeInfo
          {
              public double X;
              public double Y;
              public String Mode;
          }
          List<NewNodeInfo> NewNodeInfo_List = new List<NewNodeInfo>();
6312cbd86   doan   Task 2062
125
126
127
  
          //List Node's Info
          List<Node_tmp> Lst_Node_tmp = new List<Node_tmp>();
b338e1ff5   nguyen_nam   no message
128
129
          List<TextBlock> NodeNo = new List<TextBlock>();
          List<ucNode> ucNode_Lst = new List<ucNode>();
4bed9f746   toan   2063 : Update source
130
          public List<ucNode> ucScheduleNode_Lst = new List<ucNode>();
b338e1ff5   nguyen_nam   no message
131
132
          int stt = 1;
          //2017/03/04 NAM ADD END
6312cbd86   doan   Task 2062
133
134
135
136
137
138
          public struct ListIndexNodeInsert
          {
              public double X;
              public double Y;
          }
          List<ListIndexNodeInsert> IndexNodeInsert_List = new List<ListIndexNodeInsert>();
b338e1ff5   nguyen_nam   no message
139

01c8c8f49   doan   Update Task 2068
140
141
142
143
144
145
146
          public struct ListNameNode
          {
              public double X;
              public double Y;
              public string nameNode;
          }
          List<ListNameNode> NameNode_List = new List<ListNameNode>();
b338e1ff5   nguyen_nam   no message
147

867826ac5   doan   Update Task 2046
148
          public ScheduleCanvas scheduleCanvas = new ScheduleCanvas();
b338e1ff5   nguyen_nam   no message
149

729be9a6d   doan   New Project
150
151
152
          // Add variable for Set Auto Nodes
          public Path pBlueNode = new Path();
          private GeometryGroup gGrpBlueNode = new GeometryGroup();
47aa77821   doan   Update task 2095
153
154
155
          // Add variable for Actual Nodes
          public Path pActualNode = new Path();
          private GeometryGroup gGrpActualNode = new GeometryGroup();
729be9a6d   doan   New Project
156
157
158
159
160
161
162
163
164
165
166
          // Add variable for Set Free Nodes
          public Path pFreeNode = new Path();
          //private GeometryGroup gGrpFreeNode = new GeometryGroup();
  
          // The part of the rectangle the mouse is over.
          private enum HitType
          {
              None, Body, UL, UR, LR, LL, L, R, T, B
          };
          public enum OperationState
          {
b338e1ff5   nguyen_nam   no message
167
              None, DrawObstract, DrawRoute, DrawSetFreeNode, EditNode, NewDrawSetFreeNode
729be9a6d   doan   New Project
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
          };
          public enum MouseState
          {
              None, Draw, Drag,
          }
          public OperationState Operation = OperationState.None;
          public MouseState mouseState = MouseState.None;
  
          // The draw start point.
          private Point StartDrawPoint;
  
          // The drag's last point.
          private Point LastPoint;
  
          // The part of the rectangle under the mouse.
          HitType MouseHitType = HitType.None;
6312cbd86   doan   Task 2062
184
185
          public void Init()
          {
729be9a6d   doan   New Project
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
              if (shapePosIndicator == null)
              {
                  shapePosIndicator = new TextBlock()
                  {
                      Foreground = Brushes.Black,
                      Background = Brushes.Transparent,
                      FontSize = 20,
                  };
              }
              if (shapeSizeIndicator == null)
              {
                  shapeSizeIndicator = new TextBlock()
                  {
                      Foreground = Brushes.Black,
                      Background = Brushes.Transparent,
                      FontSize = 20,
                  };
              }
          }
  
          // Return a HitType value to indicate what is at the point.
          private HitType SetHitType(Point point)
          {
              if (shapeList.Count == 0)
              {
                  currentShape = 0;
                  return HitType.None;
              }
              for (int i = 0; i < shapeList.Count; i++)
              {
                  Rectangle rect = shapeList[i];
                  double left = Canvas.GetLeft(rect);
                  double top = Canvas.GetTop(rect);
                  double right = left + rect.Width;
                  double bottom = top + rect.Height;
                  if (point.X < left) continue;
                  if (point.X > right) continue;
                  if (point.Y < top) continue;
                  if (point.Y > bottom) continue;
                  currentShape = i;
  
                  const double GAP = 10;
                  if (point.X - left < GAP)
                  {
                      // Left edge.
                      if (point.Y - top < GAP) return HitType.UL;
                      if (bottom - point.Y < GAP) return HitType.LL;
                      return HitType.L;
                  }
                  if (right - point.X < GAP)
                  {
                      // Right edge.
                      if (point.Y - top < GAP) return HitType.UR;
                      if (bottom - point.Y < GAP) return HitType.LR;
                      return HitType.R;
                  }
                  if (point.Y - top < GAP) return HitType.T;
                  if (bottom - point.Y < GAP) return HitType.B;
                  return HitType.Body;
              }
              currentShape = 0;
              return HitType.None;
          }
  
          // Set a mouse cursor appropriate for the current hit type.
          private void SetMouseCursor()
          {
              // See what cursor we should display.
              Cursor desired_cursor = Cursors.Arrow;
              switch (MouseHitType)
              {
                  case HitType.None:
                      desired_cursor = Cursors.Arrow;
                      break;
                  case HitType.Body:
                      desired_cursor = Cursors.ScrollAll;
                      break;
                  case HitType.UL:
                  case HitType.LR:
                      desired_cursor = Cursors.SizeNWSE;
                      break;
                  case HitType.LL:
                  case HitType.UR:
                      desired_cursor = Cursors.SizeNESW;
                      break;
                  case HitType.T:
                  case HitType.B:
                      desired_cursor = Cursors.SizeNS;
                      break;
                  case HitType.L:
                  case HitType.R:
                      desired_cursor = Cursors.SizeWE;
                      break;
              }
  
              // Display the desired cursor.
              if (Cursor != desired_cursor) Cursor = desired_cursor;
          }
  
          // constance
          int indicatorAligment = 2;
  
          /*
          private Point? dragStartPoint = null;
          
          */
          public IEnumerable<DesignerItem> SelectedItems
          {
              get
              {
                  var selectedItems = from item in this.Children.OfType<DesignerItem>()
                                      where item.IsSelected == true
                                      select item;
  
                  return selectedItems;
              }
          }
  
          public void DeselectAll()
          {
              /*
              foreach (DesignerItem item in this.SelectedItems)
              {
                  item.IsSelected = false;
              }*/
          }
  
          protected override void OnMouseDown(MouseButtonEventArgs e)
          {
              base.OnMouseDown(e);
  
              MouseHitType = SetHitType(Mouse.GetPosition(this));
              SetMouseCursor();
b338e1ff5   nguyen_nam   no message
319

729be9a6d   doan   New Project
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
              if (Operation == OperationState.DrawRoute && isStartDrawRoute)
              {
                  if (isGoalDrawRoute)
                  {
                      return;
                  }
  
                  // Check state draw
                  if (MouseHitType == HitType.None)
                  {
                      if (gGrpLine.Children.Count == 1)
                      {
                          LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[0];
                          lineGeometry.EndPoint = LastPoint;
  
                          // Check end route
                          if (IsEndRoute(_goalPoint, lineGeometry))
                          {
                              isGoalDrawRoute = true;
                              ProcessEndRoute();
                              return;
                          }
                      }
                      else if (IsCurverNode((LineGeometry)gGrpLine.Children[currentLine - 1]
                                          , (LineGeometry)gGrpLine.Children[currentLine]))
                      {
                          // Set end point to finish draw line
                          LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine];
                          lineGeometry.EndPoint = LastPoint;
93688872e   toan   2036 : Update dra...
349
350
                          // Add node to curver postion
                          AddNode(lineGeometry.StartPoint, gGrpRedNode);
729be9a6d   doan   New Project
351
352
353
354
355
356
357
                          // Check end route
                          if (IsEndRoute(_goalPoint, lineGeometry))
                          {
                              isGoalDrawRoute = true;
                              ProcessEndRoute();
                              return;
                          }
729be9a6d   doan   New Project
358
359
360
361
362
                      }
                      else
                      {
                          // Remove current line
                          gGrpLine.Children.RemoveAt(currentLine);
729be9a6d   doan   New Project
363
364
365
366
367
368
369
370
371
372
373
374
  
                          // Set end point to finish draw line
                          LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine - 1];
                          lineGeometry.EndPoint = LastPoint;
  
                          // Check end route
                          if (IsEndRoute(_goalPoint, lineGeometry))
                          {
                              isGoalDrawRoute = true;
                              ProcessEndRoute();
                              return;
                          }
729be9a6d   doan   New Project
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
                      }
  
                      // Draw new line
                      DrawLine(LastPoint, LastPoint, gGrpLine);
                      // Setting start point for new line
                      StartDrawPoint = LastPoint;
  
                      mouseState = MouseState.Draw;
                      currentLine = gGrpLine.Children.Count - 1;
                      return;
                  }
              }
              else if (Operation == OperationState.DrawSetFreeNode)
              {
                  bool RightClick = false;
                  if (IsStopDrawRoute(e))
                      RightClick = true;
  
                  StartDrawPoint = e.MouseDevice.GetPosition(this);
b338e1ff5   nguyen_nam   no message
394

729be9a6d   doan   New Project
395
396
                  SetFreeNodes(StartDrawPoint, RightClick);
              }
b338e1ff5   nguyen_nam   no message
397

729be9a6d   doan   New Project
398
399
400
401
402
              else if (Operation == OperationState.EditNode)
              {
                  Point node_edited = e.MouseDevice.GetPosition(this);
  
                  // start Edit Node Infor
01c8c8f49   doan   Update Task 2068
403
                  //EditNode(node_edited);
729be9a6d   doan   New Project
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
  
              }
              else if (Operation == OperationState.DrawObstract)
              {
                  if (MouseHitType == HitType.None)
                  {
                      Rectangle shape = new Rectangle();
                      shape.Width = 1;
                      shape.Height = 1;
                      // Create a SolidColorBrush and use it to
                      // paint the rectangle.
                      shape.Stroke = Brushes.Blue;
                      shape.StrokeThickness = 1;
                      shape.Fill = new SolidColorBrush(Colors.LightCyan);
                      StartDrawPoint = e.MouseDevice.GetPosition(this);
                      shape.SetValue(Canvas.LeftProperty, StartDrawPoint.X);
                      shape.SetValue(Canvas.TopProperty, StartDrawPoint.Y);
                      this.Children.Add(shape);
                      shapeList.Add(shape);
  
                      mouseState = MouseState.Draw;
                      currentShape = shapeList.Count() - 1;
  
                      double shapeX = Canvas.GetLeft(shapeList[currentShape]);
                      double shapeY = Canvas.GetTop(shapeList[currentShape]);
                      shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")";
                      shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment);
                      shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment);
  
                      double width = (int)shapeList[currentShape].Width;
                      double height = (int)shapeList[currentShape].Height;
                      shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")";
                      shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width);
                      shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height);
  
                      this.Children.Add(shapePosIndicator);
                      this.Children.Add(shapeSizeIndicator);
  
  
                      return;
                  }
                  else
                  {
                      if (shapeList.Count() != 0)
                          shapeList[currentShape].Fill = new SolidColorBrush(Colors.LightCyan);
  
                      double shapeX = Canvas.GetLeft(shapeList[currentShape]);
                      double shapeY = Canvas.GetTop(shapeList[currentShape]);
                      shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")";
                      shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment);
                      shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment);
  
                      double width = (int)shapeList[currentShape].Width;
                      double height = (int)shapeList[currentShape].Height;
                      shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")";
                      shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width);
                      shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height);
  
                      this.Children.Add(shapePosIndicator);
                      this.Children.Add(shapeSizeIndicator);
                  }
  
                  LastPoint = Mouse.GetPosition(this);
                  mouseState = MouseState.Drag;
              }
              e.Handled = true;
          }
  
          protected override void OnMouseMove(MouseEventArgs e)
          {
              base.OnMouseMove(e);
  
              if (mouseState == MouseState.None)
              {
                  MouseHitType = SetHitType(Mouse.GetPosition(this));
                  SetMouseCursor();
              }
              else if (Operation == OperationState.DrawRoute && isStartDrawRoute)
              {
                  LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine];
  
                  // See how much the mouse has moved.
                  Point point = Mouse.GetPosition(this);
                  double offset_x = point.X - StartDrawPoint.X;
                  double offset_y = point.Y - StartDrawPoint.Y;
  
                  // Get the line's current position.
                  double new_x = lineGeometry.StartPoint.X;
                  double new_y = lineGeometry.StartPoint.Y;
  
                  if (offset_x != 0 || offset_y != 0)
                  {
                      if (Math.Abs(offset_x) >= Math.Abs(offset_y))
                      {
                          new_x = point.X;
                      }
                      else
                      {
                          new_y = point.Y;
                      }
                  }
  
                  // Set end point of current line
                  LastPoint = new Point(new_x, new_y);
                  lineGeometry.EndPoint = LastPoint;
                  DisplayCoordinate(LastPoint);
              }
              else if (Operation == OperationState.DrawObstract)
              {
                  if (mouseState == MouseState.Drag)
                  {
                      // See how much the mouse has moved.
                      Point point = Mouse.GetPosition(this);
                      double offset_x = point.X - LastPoint.X;
                      double offset_y = point.Y - LastPoint.Y;
  
                      // Get the rectangle's current position.
                      double new_x = Canvas.GetLeft(shapeList[currentShape]);
                      double new_y = Canvas.GetTop(shapeList[currentShape]);
                      double new_width = shapeList[currentShape].Width;
                      double new_height = shapeList[currentShape].Height;
  
                      // Update the rectangle.
                      switch (MouseHitType)
                      {
                          case HitType.Body:
                              new_x += offset_x;
                              new_y += offset_y;
                              break;
                          case HitType.UL:
                              new_x += offset_x;
                              new_y += offset_y;
                              new_width -= offset_x;
                              new_height -= offset_y;
                              break;
                          case HitType.UR:
                              new_y += offset_y;
                              new_width += offset_x;
                              new_height -= offset_y;
                              break;
                          case HitType.LR:
                              new_width += offset_x;
                              new_height += offset_y;
                              break;
                          case HitType.LL:
                              new_x += offset_x;
                              new_width -= offset_x;
                              new_height += offset_y;
                              break;
                          case HitType.L:
                              new_x += offset_x;
                              new_width -= offset_x;
                              break;
                          case HitType.R:
                              new_width += offset_x;
                              break;
                          case HitType.B:
                              new_height += offset_y;
                              break;
                          case HitType.T:
                              new_y += offset_y;
                              new_height -= offset_y;
                              break;
                      }
                      // Don't use negative width or height.
                      if ((new_width > 0) && (new_height > 0))
                      {
                          // Update the rectangle.
                          Canvas.SetLeft(shapeList[currentShape], new_x);
                          Canvas.SetTop(shapeList[currentShape], new_y);
                          shapeList[currentShape].Width = new_width;
                          shapeList[currentShape].Height = new_height;
  
                          // Save the mouse's new location.
                          LastPoint = point;
  
                      }
                  }
                  else if (mouseState == MouseState.Draw)
                  {
  
                      // See how much the mouse has moved.
                      Point point = Mouse.GetPosition(this);
  
  
                      double offset_x = point.X - StartDrawPoint.X;
                      double offset_y = point.Y - StartDrawPoint.Y;
  
                      // Get the rectangle's current position.
                      double start_x = Canvas.GetLeft(shapeList[currentShape]);
                      double start_y = Canvas.GetTop(shapeList[currentShape]);
                      double new_x = Canvas.GetLeft(shapeList[currentShape]);
                      double new_y = Canvas.GetTop(shapeList[currentShape]);
                      double new_width = offset_x;
                      double new_height = offset_y;
                      if (offset_x < 0)
                      {
                          new_x = point.X;
                          new_width = -offset_x;
                      }
                      if (offset_y < 0)
                      {
                          new_y = point.Y;
                          new_height = -offset_y;
                      }
                      Canvas.SetLeft(shapeList[currentShape], new_x);
                      Canvas.SetTop(shapeList[currentShape], new_y);
                      shapeList[currentShape].Width = new_width;
                      shapeList[currentShape].Height = new_height;
  
                  }
  
                  double shapeX = Canvas.GetLeft(shapeList[currentShape]);
                  double shapeY = Canvas.GetTop(shapeList[currentShape]);
                  shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")";
                  shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment);
                  shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment);
  
                  double width = (int)shapeList[currentShape].Width;
                  double height = (int)shapeList[currentShape].Height;
                  shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")";
                  shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width);
                  shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height);
              }
              e.Handled = true;
          }
  
          protected override void OnMouseUp(MouseButtonEventArgs e)
          {
              base.OnMouseUp(e);
              if (Operation == OperationState.DrawObstract)
              {
                  if (shapeList.Count() != 0)
                      shapeList[currentShape].Fill = new SolidColorBrush(Colors.Blue);
                  shapePosIndicator.Text = "";
                  shapeSizeIndicator.Text = "";
                  this.Children.Remove(shapePosIndicator);
                  this.Children.Remove(shapeSizeIndicator);
  
                  mouseState = MouseState.None;
                  currentShape = 0;
              }
              e.Handled = true;
          }
a47f478f0   doan   開発 #2045 : node の...
648
649
650
651
652
653
654
655
          protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
          {
              base.OnPreviewMouseUp(e);
  
              EllipseGeometry ellipseGeometry;
              bool flag = false;
  
              StartDrawPoint = e.MouseDevice.GetPosition(this);
fd7150b8b   doan   Update Task 2062
656
657
  
              if (EditNodeFlag == true)
a47f478f0   doan   開発 #2045 : node の...
658
659
660
661
662
663
664
665
666
667
              {
                  execEditNode(StartDrawPoint);
                  EditNodeFlag = false;
                  return;
              }
  
              if (DragDeltaFlag == true)
              {
                  for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
                  {
6df37ad27   doan   no message
668
669
670
671
672
673
674
675
676
677
                      //int aa = UcNode_Index;
                      //for (int j = 0; j < ucNode_Lst.Count; j++)
                      //{
                      //    if (j == i)
                      //    {
                      //        _ucNodeFree = ucNode_Lst[j];
                      //        flag = true;
                      //    }
                      //}
                      if (i == UcNode_Index - 1)
a47f478f0   doan   開発 #2045 : node の...
678
                      {
6df37ad27   doan   no message
679
                          _ucNodeFree = ucNode_Lst[i];
a47f478f0   doan   開発 #2045 : node の...
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
                          if (gGrpNewLine.Children.Count > 0)
                          {
                              for (int k = 0; k < gGrpNewLine.Children.Count; k++)
                              {
                                  LineGeometry lineGeometry = (LineGeometry)gGrpNewLine.Children[k];
                                  Point p1 = lineGeometry.StartPoint;
                                  Point p2 = lineGeometry.EndPoint;
  
                                  //bool pInL = PointInLine(StartDrawPoint, p1, p2, 25);
  
                                  //if (pInL)
                                  //{
  
                                  //    //this.Children.Remove(_ucNodeFree);
                                  //    //this.Children.Add(_ucNodeFree);
                                  //    return;
                                  //}
                              }
                          }
  
                          ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
  
                          ellipseGeometry.Center = new Point(StartDrawPoint.X, StartDrawPoint.Y);
  
                          double centerY = Canvas.GetTop(_ucNodeFree);
                          double centerX = Canvas.GetLeft(_ucNodeFree);
  
                          mouseState = MouseState.Draw;
d96c9e481   doan   Update Source Code
708
709
                          StartDrawPoint = new Point(centerX + UCNODE_SETLEFT, centerY + UCNODE_SETTOP);
                          ellipseGeometry.Center = new Point(centerX + UCNODE_SETLEFT, centerY + UCNODE_SETTOP);
a47f478f0   doan   開発 #2045 : node の...
710
711
712
  
                          this.Children.Remove(_ucNodeFree);
                          this.Children.Add(_ucNodeFree);
47aa77821   doan   Update task 2095
713
714
                          Lst_Node_tmp[i].pointMap_X = ConvertPointDisplayToActual(StartDrawPoint.X, Scale_X, PointMapStart_X);
                          Lst_Node_tmp[i].pointMap_Y = ConvertPointDisplayToActual(StartDrawPoint.Y, Scale_X, PointMapStart_Y);
5db801240   doan   update 2099
715

abaa8d900   doan   Update Task 2099
716
717
718
719
720
721
722
723
724
                          //Update Location for List NameNode_List -> Compare Location to get Name
                          ListNameNode nmNode = new ListNameNode();
                          ListNameNode nmNode_old = new ListNameNode();
                          nmNode_old = NameNode_List[i];
  
                          nmNode.X = StartDrawPoint.X;
                          nmNode.Y = StartDrawPoint.Y;
                          nmNode.nameNode = nmNode_old.nameNode;
                          NameNode_List[i] = nmNode;
a47f478f0   doan   開発 #2045 : node の...
725
726
727
728
                      }
                  }
  
                  ReDrawAllNode();
47aa77821   doan   Update task 2095
729
                  NewDspRouteInfo();
a47f478f0   doan   開発 #2045 : node の...
730
731
732
733
  
                  SetScheduleRoute();
                  DragDeltaFlag = false;
              }
fd7150b8b   doan   Update Task 2062
734

a47f478f0   doan   開発 #2045 : node の...
735
736
737
  
              return;
          }
5db801240   doan   update 2099
738

729be9a6d   doan   New Project
739
740
741
742
743
744
745
          /// <summary>
          /// On Preview Mouse Down
          /// </summary>
          /// <param name="e"></param>
          protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
          {
              base.OnPreviewMouseDown(e);
e3ae88363   toan   RM2077: Commit so...
746
747
748
  
              if (DesignerCanvas.LoadDBFlag)
                  return;
b338e1ff5   nguyen_nam   no message
749
              if (Operation != OperationState.NewDrawSetFreeNode)
729be9a6d   doan   New Project
750
751
752
753
754
              {
                  return;
              }
  
              Point currentPoint = e.MouseDevice.GetPosition(this);
729be9a6d   doan   New Project
755

b338e1ff5   nguyen_nam   no message
756
              if (isDrawingNode == false)
729be9a6d   doan   New Project
757
              {
729be9a6d   doan   New Project
758

b338e1ff5   nguyen_nam   no message
759
                  isDrawingNode = true;
867826ac5   doan   Update Task 2046
760
                  //InitDrawRoute();
729be9a6d   doan   New Project
761
                  mouseState = MouseState.Draw;
ebf4e3eed   nguyen_nam   Update Task 2045
762
763
  
                  StartDrawPoint = e.MouseDevice.GetPosition(this);
ebf4e3eed   nguyen_nam   Update Task 2045
764

6312cbd86   doan   Task 2062
765

fd7150b8b   doan   Update Task 2062
766
                  execCreateNode(StartDrawPoint);
63b4f0fd3   nguyen_nam   2062: Update
767
768
769
  
                  //backup DB
                  CreateVehicleNode();
6312cbd86   doan   Task 2062
770

729be9a6d   doan   New Project
771
772
                  return;
              }
160b9bec8   nguyen_nam   Tbl Node info
773
774
775
776
777
778
779
780
781
782
783
784
785
              else
              {
  
                  bool RightClick = false;
                  bool LeftClick = false;
  
  
                  if (IsMouseLeftClick(e))
                      LeftClick = true;
                  if (IsStopDrawRoute(e))
                      RightClick = true;
  
                  StartDrawPoint = e.MouseDevice.GetPosition(this);
d96c9e481   doan   Update Source Code
786

fd7150b8b   doan   Update Task 2062
787
788
789
                  if (RightClick)
                  {
                      execDeleteNode(StartDrawPoint);
63b4f0fd3   nguyen_nam   2062: Update
790
791
792
  
                      //backup DB
                      CreateVehicleNode();
fd7150b8b   doan   Update Task 2062
793
794
795
                  }
                  else if (LeftClick)
                  {
63b4f0fd3   nguyen_nam   2062: Update
796
                      //check click to exist node
fd7150b8b   doan   Update Task 2062
797
798
799
800
801
802
803
804
805
806
807
                      for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
                      {
                          EllipseGeometry ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
                          Point node = ellipseGeometry.Center;
                          bool isEditNode = CheckIsNode(StartDrawPoint, node, RADIUS_NODE);
  
                          if (isEditNode)
                          {
                              return;
                          }
                      }
a47f478f0   doan   開発 #2045 : node の...
808

fd7150b8b   doan   Update Task 2062
809
                      execCreateNode(StartDrawPoint);
63b4f0fd3   nguyen_nam   2062: Update
810
811
812
  
                      //backup DB
                      CreateVehicleNode();
fd7150b8b   doan   Update Task 2062
813
                  }
729be9a6d   doan   New Project
814

729be9a6d   doan   New Project
815
816
817
818
819
820
821
822
823
824
825
826
827
              }
          }
  
          #region Functions for draw route
  
          /// <summary>
          /// Check start or end draw route
          /// </summary>
          /// <param name="_ucStartEndButton">Button start</param>
          /// <param name="currentPoint">Position for check</param>
          /// <returns>true: start, false: not start</returns>
          private bool IsStartEndRoute(ucStartEndButton _ucStartEndButton, Point currentPoint)
          {
fd7150b8b   doan   Update Task 2062
828
              if (_ucStartEndButton == null)
729be9a6d   doan   New Project
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
              {
                  return false;
              }
  
              double centerX = Canvas.GetLeft(_ucStartEndButton);
              double centerY = Canvas.GetTop(_ucStartEndButton);
  
              if (currentPoint.X < centerX + 50 && currentPoint.X > centerX
                  && currentPoint.Y < centerY + 50 && currentPoint.Y > centerY)
              {
                  return true;
              }
              return false;
          }
  
          /// <summary>
          /// Process when end draw route
          /// </summary>
          private void ProcessEndRoute()
          {
              Operation = OperationState.None;
              AutoEditLine();
              this.Children.Remove(_displayAxiPosition);
              this.Children.Remove(_goalPoint);
              this.Children.Add(_goalPoint);
          }
  
          /// <summary>
          /// Check end draw route
          /// </summary>
          /// <param name="_ucStartEndButton">Button end</param>
          /// <param name="currentPoint">Position for check</param>
          /// <returns>true: end, false: not end</returns>
          private bool IsEndRoute(ucStartEndButton _ucStartEndButton, LineGeometry lineGeometry)
          {
              if (_ucStartEndButton == null)
              {
                  return false;
              }
  
              double centerX = Canvas.GetLeft(_ucStartEndButton);
              double centerY = Canvas.GetTop(_ucStartEndButton);
              Point startPoint = lineGeometry.StartPoint;
              Point endPoint = lineGeometry.EndPoint;
fd7150b8b   doan   Update Task 2062
873
              if (IsVerticalLine(lineGeometry))
729be9a6d   doan   New Project
874
              {
fd7150b8b   doan   Update Task 2062
875
                  if (endPoint.X < centerX || endPoint.X > centerX + 50)
729be9a6d   doan   New Project
876
877
878
879
880
881
882
                      return false;
  
                  if (startPoint.Y > centerY + 50 && endPoint.Y > centerY + 50)
                      return false;
  
                  if (startPoint.Y < centerY && endPoint.Y < centerY)
                      return false;
6312cbd86   doan   Task 2062
883
884
              }
              else
729be9a6d   doan   New Project
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
              {
                  if (endPoint.Y < centerY || endPoint.Y > centerY + 50)
                      return false;
  
                  if (startPoint.X > centerX + 50 && endPoint.X > centerX + 50)
                      return false;
  
                  if (startPoint.X < centerX && endPoint.X < centerX)
                      return false;
              }
  
              return true;
          }
  
          /// <summary>
          /// Make root
          /// </summary>
          public void MakeRoot()
          {
729be9a6d   doan   New Project
904
905
906
              // If still not route
              if (gGrpLine.Children.Count == 0)
                  return;
fa577fd8d   toan   2036: Update foll...
907
908
              pLine.Stroke = new SolidColorBrush(Colors.Red);
              pLine.StrokeThickness = STROKE_ROOT_LINE;
729be9a6d   doan   New Project
909
910
911
912
913
914
915
916
917
918
919
920
921
          }
  
          /// <summary>
          /// Auto edit leght of line
          /// </summary>
          private void AutoEditLine()
          {
              double temp;
              int index = gGrpLine.Children.Count - 1;
              double centerY = Canvas.GetTop(_goalPoint) + 25;
              double centerX = Canvas.GetLeft(_goalPoint) + 25;
              LineGeometry lastLine = (LineGeometry)gGrpLine.Children[index];
              LineGeometry beforeLastLine = (LineGeometry)gGrpLine.Children[index];
fd7150b8b   doan   Update Task 2062
922
              if (gGrpLine.Children.Count > 1)
729be9a6d   doan   New Project
923
924
925
926
927
928
929
              {
                  beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1];
  
                  if (!IsCurverNode(beforeLastLine, lastLine))
                  {
                      beforeLastLine.EndPoint = lastLine.EndPoint;
                      gGrpLine.Children.RemoveAt(index);
729be9a6d   doan   New Project
930
931
932
933
                      index = index - 1;
                      lastLine = (LineGeometry)gGrpLine.Children[index];
                  }
              }
93688872e   toan   2036 : Update dra...
934
935
936
937
              if (index == gGrpRedNode.Children.Count + 1)
              {
                  AddNode(lastLine.StartPoint, gGrpRedNode);
              }
729be9a6d   doan   New Project
938
939
              if (lastLine.EndPoint.X == centerX && lastLine.EndPoint.Y == centerY)
                  return;
fd7150b8b   doan   Update Task 2062
940
              if (IsVerticalLine(lastLine))
729be9a6d   doan   New Project
941
942
943
944
              {
                  temp = lastLine.StartPoint.Y;
                  lastLine.StartPoint = new Point(centerX, temp);
                  lastLine.EndPoint = new Point(centerX, centerY);
6312cbd86   doan   Task 2062
945
946
                  if (gGrpLine.Children.Count > 1)
                  {
729be9a6d   doan   New Project
947
948
949
950
                      beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1];
                      temp = beforeLastLine.EndPoint.Y;
                      beforeLastLine.EndPoint = new Point(centerX, temp);
                  }
6312cbd86   doan   Task 2062
951
952
              }
              else
729be9a6d   doan   New Project
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
              {
                  temp = lastLine.StartPoint.X;
                  lastLine.StartPoint = new Point(temp, centerY);
                  lastLine.EndPoint = new Point(centerX, centerY);
                  if (gGrpLine.Children.Count > 1)
                  {
                      beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1];
                      temp = beforeLastLine.EndPoint.X;
                      beforeLastLine.EndPoint = new Point(temp, centerY);
                  }
              }
  
              // Draw curver line
              if (IsCurverNode(beforeLastLine, lastLine))
              {
93688872e   toan   2036 : Update dra...
968
969
                  EllipseGeometry ellipseGeometry = (EllipseGeometry)gGrpRedNode.Children[gGrpRedNode.Children.Count - 1];
                  ellipseGeometry.Center = lastLine.StartPoint;
729be9a6d   doan   New Project
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
              }
          }
  
          /// <summary>
          /// Check draw curver node
          /// </summary>
          /// <param name="oldLine">Old line</param>
          /// <param name="newLine">New line</param>
          /// <returns>true:is curver, fasle: not curver</returns>
          private bool IsCurverNode(LineGeometry oldLine, LineGeometry newLine)
          {
              if (oldLine.StartPoint.Y == oldLine.EndPoint.Y && oldLine.StartPoint.Y == newLine.EndPoint.Y)
              {
                  return false;
              }
  
              if (oldLine.StartPoint.X == oldLine.EndPoint.X && oldLine.StartPoint.X == newLine.EndPoint.X)
              {
                  return false;
              }
  
              return true;
          }
  
          /// <summary>
          /// Check timming to stop draw route
          /// </summary>
          /// <param name="e"></param>
          /// <returns>true:stop; false:continue</returns>
          private bool IsStopDrawRoute(MouseEventArgs e)
          {
fd7150b8b   doan   Update Task 2062
1001
              if (e.RightButton == MouseButtonState.Pressed)
729be9a6d   doan   New Project
1002
1003
1004
1005
1006
1007
              {
                  return true;
              }
  
              return false;
          }
160b9bec8   nguyen_nam   Tbl Node info
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
          //2017/03/05 NAM ADD START
          private bool IsMouseLeftClick(MouseEventArgs e)
          {
              if (e.LeftButton == MouseButtonState.Pressed)
              {
                  return true;
              }
  
              return false;
          }
          //2017/03/05 NAM ADD END
729be9a6d   doan   New Project
1019
1020
1021
1022
1023
1024
1025
1026
          /// <summary>
          /// Draw curver line and yellow node
          /// </summary>
          /// <param name="oldLine">Old line</param>
          /// <param name="newLine">New line</param>
          private void DrawCurver(LineGeometry oldLine, LineGeometry newLine)
          {
              double radius = RADIUS_CURVER_LINE;
fd7150b8b   doan   Update Task 2062
1027
1028
              Point startPoint;
              Point endPoint;
729be9a6d   doan   New Project
1029
1030
  
              // Get postion of yellow node on old line
fd7150b8b   doan   Update Task 2062
1031
              if (IsVerticalLine(oldLine))
729be9a6d   doan   New Project
1032
1033
1034
1035
1036
              {
                  if (oldLine.StartPoint.Y > oldLine.EndPoint.Y)
                      startPoint = new Point(oldLine.EndPoint.X, oldLine.EndPoint.Y + radius);
                  else
                      startPoint = new Point(oldLine.EndPoint.X, oldLine.EndPoint.Y - radius);
6312cbd86   doan   Task 2062
1037
1038
              }
              else
729be9a6d   doan   New Project
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
              {
                  if (oldLine.StartPoint.X > oldLine.EndPoint.X)
                      startPoint = new Point(oldLine.EndPoint.X + radius, oldLine.EndPoint.Y);
                  else
                      startPoint = new Point(oldLine.EndPoint.X - radius, oldLine.EndPoint.Y);
              }
  
              // Get postion of yellow node on new line
              if (IsVerticalLine(newLine))
              {
                  if (newLine.StartPoint.Y > newLine.EndPoint.Y)
                      endPoint = new Point(newLine.StartPoint.X, newLine.StartPoint.Y - radius);
                  else
                      endPoint = new Point(newLine.StartPoint.X, newLine.StartPoint.Y + radius);
              }
              else
              {
                  if (newLine.StartPoint.X > newLine.EndPoint.X)
                      endPoint = new Point(newLine.StartPoint.X - radius, newLine.StartPoint.Y);
                  else
                      endPoint = new Point(newLine.StartPoint.X + radius, newLine.StartPoint.Y);
              }
729be9a6d   doan   New Project
1061
              // Add node to postion distance 1300mm
93688872e   toan   2036 : Update dra...
1062
1063
1064
1065
1066
1067
1068
1069
1070
              if (GetDistance(oldLine.StartPoint, oldLine.EndPoint) > RADIUS_CURVER_LINE)
              {
                  AddNode(startPoint, gGrpYellowNode);
              }
  
              if (GetDistance(newLine.StartPoint, newLine.EndPoint) > RADIUS_CURVER_LINE)
              {
                  AddNode(endPoint, gGrpYellowNode);
              }
729be9a6d   doan   New Project
1071
1072
1073
1074
1075
          }
  
          /// <summary>
          /// Init data for draw route
          /// </summary>
867826ac5   doan   Update Task 2046
1076
          public void InitDrawRoute()
729be9a6d   doan   New Project
1077
          {
b338e1ff5   nguyen_nam   no message
1078
1079
1080
1081
1082
1083
1084
1085
1086
              //2017/03/04 NAM ADD START
              pNewLine.Stroke = new SolidColorBrush(Colors.Red);
              pNewLine.StrokeThickness = STROKE_LINE;
              pNewLine.Data = gGrpNewLine;
              //2017/03/04 NAM ADD END
  
              pScheduleLine.Stroke = new SolidColorBrush(Colors.Red);
              pScheduleLine.StrokeThickness = STROKE_LINE;
              pScheduleLine.Data = gGrpScheduleLine;
729be9a6d   doan   New Project
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
              // Setting for path line
              pLine.Stroke = new SolidColorBrush(Colors.Blue);
              pLine.StrokeThickness = STROKE_LINE;
              pLine.Data = gGrpLine;
  
              // Setting for path of curver line
              pCurverLine.Stroke = Brushes.Red;
              pCurverLine.StrokeThickness = STROKE_LINE;
              pCurverLine.Data = gGrpCurverLine;
  
              // Setting for path of red node
              pRedNode.Stroke = new SolidColorBrush(Colors.Blue);
              pRedNode.Fill = new SolidColorBrush(Colors.Red);
              pRedNode.StrokeThickness = STROKE_NODE;
              pRedNode.Data = gGrpRedNode;
  
              // Setting for path of yellow node
              pYellowNode.Stroke = new SolidColorBrush(Colors.Blue);
              pYellowNode.Fill = new SolidColorBrush(Colors.Yellow);
              pYellowNode.StrokeThickness = STROKE_NODE;
              pYellowNode.Data = gGrpYellowNode;
  
              // Setting for path of Blue node
              pBlueNode.Stroke = new SolidColorBrush(Colors.Blue);
              pBlueNode.Fill = new SolidColorBrush(Colors.LightBlue);
              pBlueNode.StrokeThickness = STROKE_NODE;
              pBlueNode.Data = gGrpBlueNode;
729be9a6d   doan   New Project
1114
1115
1116
1117
1118
              // Add paths to canvas
              this.Children.Add(pLine);
              this.Children.Add(pCurverLine);
              this.Children.Add(pRedNode);
              this.Children.Add(pYellowNode);
b338e1ff5   nguyen_nam   no message
1119

63b4f0fd3   nguyen_nam   2062: Update
1120
              //this.Children.Add(pNewLine);
a9f21e725   doan   Update Task 2046
1121
              //scheduleCanvas.Children.Add(pScheduleLine);
729be9a6d   doan   New Project
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
          }
  
          /// <summary>
          /// Clear all route
          /// </summary>
          public void ClearRoute()
          {
              isStartDrawRoute = false;
              isGoalDrawRoute = false;
  
              gGrpLine.Children.Clear();
              gGrpRootLine.Children.Clear();
              gGrpCurverLine.Children.Clear();
              gGrpRedNode.Children.Clear();
              gGrpYellowNode.Children.Clear();
              gGrpBlueNode.Children.Clear();
  
              this.Children.Remove(pLine);
              this.Children.Remove(pRootLine);
              this.Children.Remove(pCurverLine);
              this.Children.Remove(pRedNode);
              this.Children.Remove(pYellowNode);
              this.Children.Remove(pBlueNode);
          }
  
          /// <summary>
          /// Draw line for route
          /// </summary>
          /// <param name="startPoint">Start point</param>
          /// <param name="endPoint">End point</param>
          /// <param name="geometryGroup">Geometry Group</param>
          private void DrawLine(Point startPoint, Point endPoint, GeometryGroup geometryGroup)
          {
              LineGeometry lineGeometry = new LineGeometry();
              lineGeometry.StartPoint = startPoint;
              lineGeometry.EndPoint = endPoint;
              geometryGroup.Children.Add(lineGeometry);
          }
  
          /// <summary>
          /// Draw curver line
          /// </summary>
          /// <param name="startPoint">Point start curver line</param>
          /// <param name="endPoint">Point end curver line</param>
          /// <param name="radius">Radius</param>
          /// <param name="geometryGroup">Geometry Group</param>
          private void DrawCurverLine(Point startPoint, Point endPoint, SweepDirection sweepDirection, GeometryGroup geometryGroup)
          {
              PathGeometry pathGeometry = new PathGeometry();
              PathFigure figure = new PathFigure();
              figure.StartPoint = startPoint;
              figure.Segments.Add(new ArcSegment(endPoint, new Size(RADIUS_CURVER_LINE, RADIUS_CURVER_LINE), 90, false, sweepDirection, true));
              pathGeometry.Figures.Add(figure);
              geometryGroup.Children.Add(pathGeometry);
          }
  
          /// <summary>
          /// Setting node
          /// </summary>
          /// <param name="centerPoit">Position of center node</param>
          /// <param name="geometryGroup">Geometry Group</param>
          private void AddNode(Point centerPoit, GeometryGroup geometryGroup)
          {
              double radius = RADIUS_NODE;
              geometryGroup.Children.Add(new EllipseGeometry(centerPoit, radius, radius));
          }
  
          /// <summary>
          /// Check line is vertical or horizontal
          /// </summary>
          /// <param name="line"></param>
          /// <returns>true:Vertical, false:Horizontal</returns>
          private bool IsVerticalLine(LineGeometry line)
          {
              if (line.StartPoint.X == line.EndPoint.X)
              {
                  // Vertical line
                  return true;
              }
  
              // Horizontal line
              return false;
          }
  
          /// <summary>
          /// Get distance between two point
          /// </summary>
          /// <param name="point1">Point 1</param>
          /// <param name="point2">Point 2</param>
          /// <returns>Distance between two point</returns>
          private double GetDistance(Point point1, Point point2)
          {
              //pythagorean theorem c^2 = a^2 + b^2
              //thus c = square root(a^2 + b^2)
              double a = (double)(point2.X - point1.X);
              double b = (double)(point2.Y - point1.Y);
  
              return Math.Sqrt(a * a + b * b);
          }
  
          /// <summary>
          /// Check point is valid for draw
          /// </summary>
          /// <param name="point">Poit need check</param>
          /// <returns>true:Valid, false:Invalid</returns>
          private bool IsValidPoint(Point point)
          {
              return true;
          }
  
          /// <summary>
          /// Display coordinate position
          /// </summary>
          /// <param name="point">Position to display</param>
          private void DisplayCoordinate(Point point)
          {
              if (_displayAxiPosition == null)
              {
                  _displayAxiPosition = new ucDisplayCoordinate();
                  this.Children.Add(_displayAxiPosition);
              }
              _displayAxiPosition.Display(point);
          }
  
          #endregion
  
          #region Functions for Set Auto Nodes
  
          /// <summary>
          /// SetAutoNodes
          /// </summary>
          public void SetAutoNodes()
          {
              double radiusStart = DISTANCE_START_NODES;
              double radiusEnd = DISTANCE_END_NODES;
              double radiusCurver = RADIUS_CURVER_LINE;
  
              Point startNode;
              Point endNode;
  
              gGrpBlueNode.Children.Clear();
  
              if (gGrpLine.Children.Count == 1)
                  radiusCurver = radiusEnd;
  
              if (gGrpLine.Children.Count > 0)
              {
                  for (int i = 0; i < gGrpLine.Children.Count; i++)
                  {
                      LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[i];
                      if (i == 0)
                      {
                          startNode = lineGeometry.EndPoint;
                          endNode = lineGeometry.StartPoint;
                          DrawAutoNodes(startNode, endNode, radiusCurver, radiusStart);
                      }
                      else if (i == gGrpLine.Children.Count - 1 && i > 0)
                      {
                          startNode = lineGeometry.StartPoint;
                          endNode = lineGeometry.EndPoint;
                          DrawAutoNodes(startNode, endNode, radiusCurver, radiusEnd);
                      }
                      else
                      {
                          startNode = lineGeometry.StartPoint;
                          endNode = lineGeometry.EndPoint;
                          DrawAutoNodes(startNode, endNode, radiusCurver, radiusCurver);
                      }
                  }
              }
          }
fd7150b8b   doan   Update Task 2062
1293

729be9a6d   doan   New Project
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
          /// <summary>
          /// DrawAutoNodes
          /// </summary>
          /// <param name="startNode"></param>
          /// <param name="endNode"></param>
          /// <param name="radiusStart"></param>
          /// <param name="radiusEnd"></param>
          private void DrawAutoNodes(Point startNode, Point endNode, double radiusStart, double radiusEnd)
          {
              double distance = DISTANCE_AUTO_NODES;
              double i;
  
              Point node;
  
              // Get postion of blue node on line
              if (startNode.X == endNode.X)
              {
                  if (startNode.Y > endNode.Y)
                  {
                      i = startNode.Y - radiusStart;
                      if (i - distance > endNode.Y + radiusEnd)
                      {
                          do
                          {
                              i = i - distance;
                              node = new Point(endNode.X, i);
                              // Add node to postion distance 1000mm
                              AddNode(node, gGrpBlueNode);
  
                          } while (i > endNode.Y + radiusEnd + distance);
                      }
                  }
                  else
                  {
                      i = startNode.Y + radiusStart;
                      if (i + distance < endNode.Y - radiusEnd)
                      {
                          do
                          {
                              i = i + distance;
                              node = new Point(endNode.X, i);
                              // Add node to postion distance 1000mm
                              AddNode(node, gGrpBlueNode);
                          } while (i < endNode.Y - radiusEnd - distance);
                      }
                  }
              }
              else
              {
                  if (startNode.X > endNode.X)
                  {
                      i = startNode.X - radiusStart;
                      if (i - distance > endNode.X + radiusEnd)
                      {
                          do
                          {
                              i = i - distance;
                              node = new Point(i, endNode.Y);
                              // Add node to postion distance 1000mm
                              AddNode(node, gGrpBlueNode);
                          } while (i > endNode.X + radiusEnd + distance);
                      }
                  }
                  else
                  {
                      i = startNode.X + radiusStart;
                      if (i + distance < endNode.X - radiusEnd)
                      {
                          do
                          {
                              i = i + distance;
                              node = new Point(i, endNode.Y);
                              // Add node to postion distance 1000mm
                              AddNode(node, gGrpBlueNode);
                          } while (i < endNode.X - radiusEnd - distance);
                      }
                  }
              }
  
          }
  
          #endregion
  
          #region Functions for Set Free Nodes
          /// <summary>
          /// Draw Auto Blue node
          /// </summary>
fd7150b8b   doan   Update Task 2062
1381

729be9a6d   doan   New Project
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
          public void SetFreeNodes(Point FreeNode, bool RightClick)
          {
              double radiusStart = DISTANCE_START_NODES;
              double radiusEnd = DISTANCE_END_NODES;
              double radiusNode = RADIUS_NODE;
              double radiusCurver = RADIUS_CURVER_LINE + RADIUS_NODE;
  
              EllipseGeometry ellipseGeometry;
              Point node;
              bool deleteFlag = false;
fd7150b8b   doan   Update Task 2062
1392

729be9a6d   doan   New Project
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
  
              if (RightClick)
              {
                  if (gGrpBlueNode.Children.Count > 0)
                  {
                      for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
                      {
                          ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
                          node = ellipseGeometry.Center;
                          if (FreeNode.X == node.X)
                          {
                              if (CheckIsNode(FreeNode, node, radiusNode))
                              {
                                  deleteFlag = true;
                              }
                          }
                          else
                          {
                              if (CheckIsNode(FreeNode, node, radiusNode))
                              {
                                  deleteFlag = true;
                              }
                          }
                          if (deleteFlag)
                          {
                              MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel);
                              if (result == MessageBoxResult.OK)
                              {
                                  gGrpBlueNode.Children.RemoveAt(i);
b338e1ff5   nguyen_nam   no message
1422
1423
  
                                  this.Children.Remove(NodeNo[i]);
729be9a6d   doan   New Project
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
                                  return;
                              }
                              else
                              {
                                  return;
                              }
                          }
                      }
                  }
              }
b338e1ff5   nguyen_nam   no message
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
              else
              {
  
                  for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
                  {
                      ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
                      node = ellipseGeometry.Center;
                      bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE);
  
                      if (isEditNode)
                      {
01c8c8f49   doan   Update Task 2068
1445
                          //EditNode(node);
b338e1ff5   nguyen_nam   no message
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
                          return;
                      }
                  }
  
  
                  MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel);
                  if (result == MessageBoxResult.OK)
                  {
                      AddNode(FreeNode, gGrpBlueNode);
  
                      TextBlock textBlock = new TextBlock();
                      textBlock.Text = stt.ToString();
                      textBlock.FontSize = 17;
                      textBlock.Foreground = new SolidColorBrush(Colors.Red);
                      Canvas.SetLeft(textBlock, FreeNode.X - RADIUS_NODE / 2);
                      Canvas.SetTop(textBlock, FreeNode.Y - 1.5 * RADIUS_NODE);
  
                      this.Children.Add(textBlock);
                      NodeNo.Add(textBlock);
  
                      if (stt > 1)
                      {
                          int tmp = gGrpBlueNode.Children.Count;
  
                          EllipseGeometry elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 2];
                          Point node1 = elip.Center;
                          elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 1];
                          Point node2 = elip.Center;
                          DrawLine(node1, node2, gGrpCurverLine);
                      }
  
  
                      stt++;
                  }
              }
729be9a6d   doan   New Project
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
              if (gGrpLine.Children.Count > 0)
              {
                  for (int i = 0; i < gGrpLine.Children.Count; i++)
                  {
                      LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[i];
  
                      // Get postion of  node on line
                      if (IsVerticalLine(lineGeometry))
                      {
                          if (FreeNode.X < lineGeometry.EndPoint.X + radiusNode && FreeNode.X > lineGeometry.EndPoint.X - radiusNode)
                          {
                              FreeNode.X = lineGeometry.EndPoint.X;
  
                              if (i == 0)
                              {
                                  if (CheckFreeNodes(lineGeometry, FreeNode, radiusStart, radiusCurver))
                                  {
  
                                      AddNode(FreeNode, gGrpBlueNode);
                                  }
                              }
                              else if (i == gGrpLine.Children.Count - 1 && i > 0)
                              {
                                  if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusEnd))
                                  {
  
                                      AddNode(FreeNode, gGrpBlueNode);
                                  }
                              }
                              else
                              {
                                  if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusCurver))
                                  {
  
                                      AddNode(FreeNode, gGrpBlueNode);
                                  }
                              }
  
                          }
                      }
                      else
                      {
                          if (FreeNode.Y < lineGeometry.EndPoint.Y + radiusNode && FreeNode.Y > lineGeometry.EndPoint.Y - radiusNode)
                          {
                              FreeNode.Y = lineGeometry.EndPoint.Y;
                              if (i == 0)
                              {
                                  if (CheckFreeNodes(lineGeometry, FreeNode, radiusStart, radiusCurver))
                                  {
  
                                      AddNode(FreeNode, gGrpBlueNode);
                                  }
                              }
                              else if (i == gGrpLine.Children.Count - 1 && i > 0)
                              {
                                  if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusEnd))
                                  {
  
                                      AddNode(FreeNode, gGrpBlueNode);
                                  }
                              }
                              else
                              {
                                  if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusCurver))
                                  {
  
                                      AddNode(FreeNode, gGrpBlueNode);
                                  }
                              }
  
                          }
                      }
                  }
              }
          }
  
  
          public bool CheckFreeNodes(LineGeometry lineNode, Point Freenode, double radiusStart, double radiusEnd)
          {
  
              double distanceFreeNode = DISTANCE_FREE_NODES;
              double radiusNode = RADIUS_NODE;
              EllipseGeometry ellipseGeometry;
              Point node;
  
              if (IsVerticalLine(lineNode))
              {
                  if (lineNode.StartPoint.Y < lineNode.EndPoint.Y)
                  {
                      if (Freenode.Y < lineNode.StartPoint.Y + radiusStart || Freenode.Y > lineNode.EndPoint.Y - radiusEnd)
                      {
                          return false;
                      }
                  }
                  else
                  {
                      if (Freenode.Y > lineNode.StartPoint.Y - radiusStart || Freenode.Y < lineNode.EndPoint.Y + radiusEnd)
                      {
                          return false;
                      }
                  }
              }
              else
              {
                  if (lineNode.StartPoint.X < lineNode.EndPoint.X)
                  {
                      if (Freenode.X < lineNode.StartPoint.X + radiusStart || Freenode.X > lineNode.EndPoint.X - radiusEnd)
                      {
                          return false;
                      }
                  }
                  else
                  {
                      if (Freenode.X > lineNode.StartPoint.X - radiusStart || Freenode.X < lineNode.EndPoint.X + radiusEnd)
                      {
                          return false;
                      }
                  }
              }
  
              if (gGrpBlueNode.Children.Count > 0)
              {
                  for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
                  {
                      ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
                      node = ellipseGeometry.Center;
                      if (Freenode.X == node.X)
                      {
                          if (CheckIsNode(Freenode, node, radiusNode))
                          {
                              return false;
                          }
                          else if (Freenode.Y < node.Y + distanceFreeNode && Freenode.Y > node.Y - distanceFreeNode)
                          {
                              return false;
                          }
                      }
                      else if (Freenode.Y == node.Y)
                      {
                          if (CheckIsNode(Freenode, node, radiusNode))
                          {
                              return false;
                          }
                          else if (Freenode.X < node.X + distanceFreeNode && Freenode.X > node.X - distanceFreeNode)
                          {
                              return false;
                          }
                      }
                  }
              }
  
              return true;
          }
  
          public bool CheckIsNode(Point FreeNode, Point Node, double radiusNode)
          {
              if (FreeNode.X < Node.X + radiusNode && FreeNode.X > Node.X - radiusNode && FreeNode.Y < Node.Y + radiusNode && FreeNode.Y > Node.Y - radiusNode)
              {
                  return true;
              }
              return false;
          }
  
          #endregion
  
          #region Edit Node
fd7150b8b   doan   Update Task 2062
1647
          public void InitNodeInfo_List()
729be9a6d   doan   New Project
1648
1649
1650
          {
              //Reset List
              NodeInfo_List = new List<NodeInfo>();
fd7150b8b   doan   Update Task 2062
1651
              if (gGrpBlueNode.Children.Count > 0)
729be9a6d   doan   New Project
1652
1653
              {
                  // Get start point
b338e1ff5   nguyen_nam   no message
1654
1655
                  LineGeometry lineGeometry = (LineGeometry)gGrpNewLine.Children[0];
                  Point startPoint = lineGeometry.StartPoint;
729be9a6d   doan   New Project
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
  
                  NodeInfo n1 = new NodeInfo();
                  n1.X = startPoint.X;
                  n1.Y = startPoint.Y;
                  n1.Mode1 = "";
                  n1.Mode2 = "";
                  n1.Mode3 = "";
                  NodeInfo_List.Add(n1);
  
                  for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
                  {
                      Point point;
                      EllipseGeometry eGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
                      point = eGeometry.Center;
fd7150b8b   doan   Update Task 2062
1670

729be9a6d   doan   New Project
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
                      NodeInfo Ninfo = new NodeInfo();
                      Ninfo.X = point.X;
                      Ninfo.Y = point.Y;
  
                      Ninfo.Mode1 = "";
                      Ninfo.Mode2 = "";
                      Ninfo.Mode3 = "";
  
                      NodeInfo_List.Add(Ninfo);
                  }
  
                  // Get end point
fd7150b8b   doan   Update Task 2062
1683
                  lineGeometry = (LineGeometry)gGrpLine.Children[gGrpLine.Children.Count - 1];
729be9a6d   doan   New Project
1684
                  Point endPoint = lineGeometry.EndPoint;
fd7150b8b   doan   Update Task 2062
1685

729be9a6d   doan   New Project
1686
1687
1688
1689
1690
1691
1692
                  NodeInfo n2 = new NodeInfo();
                  n2.X = startPoint.X;
                  n2.Y = startPoint.Y;
                  n2.Mode1 = "";
                  n2.Mode2 = "";
                  n2.Mode3 = "";
                  NodeInfo_List.Add(n2);
b338e1ff5   nguyen_nam   no message
1693
                  //Resort NodeInfo_List From Start to Goal
fd7150b8b   doan   Update Task 2062
1694
                  LineGeometry firstLine = (LineGeometry)gGrpLine.Children[0];
729be9a6d   doan   New Project
1695
1696
1697
1698
1699
1700
1701
                  Point startNode = firstLine.StartPoint;
                  Point endNode = firstLine.EndPoint;
  
  
                  List<NodeInfo> tmpLst = new List<NodeInfo>();
  
                  // Create temp List
fd7150b8b   doan   Update Task 2062
1702
                  if (startNode.X == endNode.X)
729be9a6d   doan   New Project
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
                  {
                      for (int i = 1; i < NodeInfo_List.Count; i++)
                      {
                          if (NodeInfo_List[i].X != endNode.X)
                          {
                              break;
                          }
                          else
                          {
                              tmpLst.Add(NodeInfo_List[i]);
                          }
                      }
                  }
  
                  if (startNode.Y == endNode.Y)
                  {
                      for (int i = 1; i < NodeInfo_List.Count; i++)
                      {
                          if (NodeInfo_List[i].Y != endNode.Y)
                          {
                              break;
                          }
                          else
                          {
                              tmpLst.Add(NodeInfo_List[i]);
                          }
                      }
                  }
  
                  // Sort NodeInfo_List
fd7150b8b   doan   Update Task 2062
1733
                  for (int i = 0; i < tmpLst.Count; i++)
729be9a6d   doan   New Project
1734
                  {
fd7150b8b   doan   Update Task 2062
1735
                      NodeInfo_List[i + 1] = tmpLst[tmpLst.Count - 1 - i];
729be9a6d   doan   New Project
1736
                  }
fd7150b8b   doan   Update Task 2062
1737

729be9a6d   doan   New Project
1738
1739
              }
          }
fd7150b8b   doan   Update Task 2062
1740

01c8c8f49   doan   Update Task 2068
1741
1742
1743
1744
1745
          //public void EditNode(Point node_edited)
          //{
          //    EllipseGeometry ellipseGeometry;
          //    Point node;
          //    double radiusNode = RADIUS_NODE;
729be9a6d   doan   New Project
1746

01c8c8f49   doan   Update Task 2068
1747
          //    bool flag = false;
fd7150b8b   doan   Update Task 2062
1748

01c8c8f49   doan   Update Task 2068
1749
1750
1751
1752
1753
1754
          //    if (gGrpBlueNode.Children.Count > 0)
          //    {
          //        for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
          //        {
          //            ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
          //            node = ellipseGeometry.Center;
fd7150b8b   doan   Update Task 2062
1755

01c8c8f49   doan   Update Task 2068
1756
1757
1758
1759
          //            if (CheckIsNode(node_edited, node, radiusNode))
          //            {
          //                flag = true;
          //            }
729be9a6d   doan   New Project
1760

01c8c8f49   doan   Update Task 2068
1761
1762
1763
1764
          //            if (flag)
          //            {
          //                node_edited.X = node.X;
          //                node_edited.Y = node.Y;
729be9a6d   doan   New Project
1765

01c8c8f49   doan   Update Task 2068
1766
1767
1768
          //                // show form edit node
          //                EditNodeWindow edtNodeWindow = new EditNodeWindow();
          //                edtNodeWindow.ShowDialog();
729be9a6d   doan   New Project
1769

01c8c8f49   doan   Update Task 2068
1770
1771
1772
1773
          //                string result1 = edtNodeWindow._txtMode1;
          //                string result2 = edtNodeWindow._txtMode2;
          //                string result3 = edtNodeWindow._txtMode3;
          //                bool exit = edtNodeWindow._ExitFlg;
729be9a6d   doan   New Project
1774

01c8c8f49   doan   Update Task 2068
1775
1776
1777
1778
          //                if (!exit)
          //                {
          //                    SaveChanged(node_edited.X, node_edited.Y, result1, result2, result3);
          //                }
fd7150b8b   doan   Update Task 2062
1779

01c8c8f49   doan   Update Task 2068
1780
1781
1782
1783
1784
          //                return;
          //            }
          //        }
          //    }
          //}
729be9a6d   doan   New Project
1785
1786
1787
  
          public void SaveChanged(double x, double y, string st1, string st2, string st3)
          {
fd7150b8b   doan   Update Task 2062
1788
              for (int i = 0; i < NodeInfo_List.Count; i++)
729be9a6d   doan   New Project
1789
1790
1791
1792
1793
1794
              {
                  NodeInfo ni = new NodeInfo();
                  ni = NodeInfo_List[i];
  
                  if (ni.X == x && ni.Y == y)
                  {
fd7150b8b   doan   Update Task 2062
1795

729be9a6d   doan   New Project
1796
1797
1798
1799
1800
1801
1802
1803
1804
                      ni.Mode1 = st1;
                      ni.Mode2 = st2;
                      ni.Mode3 = st3;
  
                      NodeInfo_List[i] = ni;
                      return;
                  }
              }
          }
b338e1ff5   nguyen_nam   no message
1805

fd7150b8b   doan   Update Task 2062
1806

729be9a6d   doan   New Project
1807
1808
1809
          #endregion
  
          #region Display RouteInfo
b338e1ff5   nguyen_nam   no message
1810

729be9a6d   doan   New Project
1811
1812
1813
          public void DspRouteInfo()
          {
              //Clear Route Info Table
b338e1ff5   nguyen_nam   no message
1814
1815
1816
1817
              ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Clear();
  
              if (NodeInfo_List.Count != 0)
              {
729be9a6d   doan   New Project
1818
1819
                  int _RowIdx = 0;
                  string _Content = "";
b338e1ff5   nguyen_nam   no message
1820
1821
                  for (int i = 0; i < NodeInfo_List.Count; i++)
                  {
729be9a6d   doan   New Project
1822
1823
1824
  
                      NodeInfo ni = new NodeInfo();
                      ni = NodeInfo_List[i];
b338e1ff5   nguyen_nam   no message
1825

729be9a6d   doan   New Project
1826
1827
                      //column 1
                      if (i == 0)
b338e1ff5   nguyen_nam   no message
1828
1829
1830
                      {
                          _Content = "S";
                      }
729be9a6d   doan   New Project
1831
                      else if (i == NodeInfo_List.Count - 1)
b338e1ff5   nguyen_nam   no message
1832
1833
1834
                      {
                          _Content = "G";
                      }
729be9a6d   doan   New Project
1835
                      else
b338e1ff5   nguyen_nam   no message
1836
1837
                      {
                          _Content = i.ToString();
729be9a6d   doan   New Project
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
                      }
                      AddLabeltoGrid(_RowIdx, 0, _Content);
  
                      //column 2
                      // Display Node's Position
                      _Content = ni.X + ", " + ni.Y;
                      AddLabeltoGrid(_RowIdx, 1, _Content);
  
                      // Display Node's Field
                      if (ni.Mode1 != "" && ni.Mode1 != null)
                      {
                          char delimiterChars = '_';
                          string[] tmp = ni.Mode1.Split(delimiterChars);
                          foreach (string s in tmp)
                          {
                              _RowIdx++;
                              delimiterChars = ':';
  
                              if (s.Split(delimiterChars)[0] == "Mode")
                              {
                                  double distance = 0;
                                  if (i == NodeInfo_List.Count - 1)
                                  {
                                      distance = 0;
                                  }
                                  else
                                  {
                                      distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y);
                                  }
                                  _Content = "MOVE " + distance.ToString() + "mm";
                              }
                              else
                              {
                                  _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1];
                              }
  
                              AddLabeltoGrid(_RowIdx, 1, _Content);
                          }
                      }
  
                      if (ni.Mode2 != "" && ni.Mode2 != null)
                      {
                          char delimiterChars = '_';
                          string[] tmp = ni.Mode2.Split(delimiterChars);
                          foreach (string s in tmp)
                          {
                              _RowIdx++;
                              delimiterChars = ':';
  
                              if (s.Split(delimiterChars)[0] == "Mode")
                              {
                                  double distance = 0;
                                  if (i == NodeInfo_List.Count - 1)
                                  {
                                      distance = 0;
                                  }
                                  else
                                  {
                                      distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y);
                                  }
                                  _Content = "MOVE " + distance.ToString() + "mm";
                              }
                              else
                              {
                                  _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1];
                              }
  
                              AddLabeltoGrid(_RowIdx, 1, _Content);
                          }
                      }
  
                      if (ni.Mode3 != "" && ni.Mode3 != null)
                      {
                          char delimiterChars = '_';
                          string[] tmp = ni.Mode3.Split(delimiterChars);
                          foreach (string s in tmp)
                          {
                              _RowIdx++;
                              delimiterChars = ':';
  
                              if (s.Split(delimiterChars)[0] == "Mode")
                              {
                                  double distance = 0;
                                  if (i == NodeInfo_List.Count - 1)
                                  {
                                      distance = 0;
                                  }
                                  else
                                  {
                                      distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y);
                                  }
                                  _Content = "MOVE " + distance.ToString() + "mm";
                              }
                              else
                              {
                                  _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1];
                              }
b338e1ff5   nguyen_nam   no message
1935

729be9a6d   doan   New Project
1936
1937
1938
                              AddLabeltoGrid(_RowIdx, 1, _Content);
                          }
                      }
b338e1ff5   nguyen_nam   no message
1939
                      _RowIdx++;
729be9a6d   doan   New Project
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
                  }
              }
          }
  
          public double DistanceCalculate(double _X1, double _Y1, double _X2, double _Y2)
          {
              double dist = 0;
  
              if (_X1 == _X2)
              {
                  dist = System.Math.Abs(_Y1 - _Y2) * DISTANCE_RATIO;
              }
              else if (_Y1 == _Y2)
              {
                  dist = System.Math.Abs(_X1 - _X2) * DISTANCE_RATIO;
              }
              return dist;
          }
  
          public void AddLabeltoGrid(int RowIdx, int ColIdx, string Content)
          {
              //Add Row to Grid
              RowDefinition _rd = new RowDefinition();
b338e1ff5   nguyen_nam   no message
1963
              ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.RowDefinitions.Add(_rd);
fd7150b8b   doan   Update Task 2062
1964

729be9a6d   doan   New Project
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
              // Add data to Grid
              Label dynamicLabel = new Label();
  
              dynamicLabel.Content = Content;
              dynamicLabel.Margin = new Thickness(0, 0, 0, 0);
              dynamicLabel.Foreground = new SolidColorBrush(Colors.Black);
              dynamicLabel.Background = new SolidColorBrush(Colors.White);
              dynamicLabel.BorderBrush = new SolidColorBrush(Colors.LightGray);
              dynamicLabel.BorderThickness = new Thickness(1);
  
              Grid.SetRow(dynamicLabel, RowIdx);
              Grid.SetColumn(dynamicLabel, ColIdx);
b338e1ff5   nguyen_nam   no message
1977
              ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Add(dynamicLabel);
729be9a6d   doan   New Project
1978
1979
1980
1981
1982
1983
          }
          #endregion
  
  
          public void CreateGoalPoint()
          {
93688872e   toan   2036 : Update dra...
1984
1985
1986
1987
              if (isGoalDrawRoute)
              {
                  return;
              }
729be9a6d   doan   New Project
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
              isStartDrawRoute = false;
              if (_goalPoint == null)
              {
                  _goalPoint = new ucStartEndButton();
                  _goalPoint.btnWidth = 50.0;
                  _goalPoint.btnHeight = 50.0;
                  _goalPoint.buttText = "G";
                  Canvas.SetLeft(_goalPoint, 675);
                  Canvas.SetTop(_goalPoint, 75);
                  this.Children.Add(_goalPoint);
              }
          }
  
          public void CreateStartPoint()
          {
93688872e   toan   2036 : Update dra...
2003
2004
2005
2006
              if (isGoalDrawRoute)
              {
                  return;
              }
729be9a6d   doan   New Project
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
              isStartDrawRoute = false;
              if (_startPoint == null)
              {
                  _startPoint = new ucStartEndButton();
                  _startPoint.btnWidth = 50.0;
                  _startPoint.btnHeight = 50.0;
                  _startPoint.buttText = "S";
                  Canvas.SetLeft(_startPoint, 75);
                  Canvas.SetTop(_startPoint, 675);
                  this.Children.Add(_startPoint);
              }
          }
b338e1ff5   nguyen_nam   no message
2019

b338e1ff5   nguyen_nam   no message
2020
2021
2022
2023
2024
          #region Draw New FreeNode
  
          /// <summary>
          /// Draw Auto Blue node
          /// </summary>
fd7150b8b   doan   Update Task 2062
2025

b338e1ff5   nguyen_nam   no message
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
          public void NewSetFreeNodes(Point FreeNode, bool RightClick)
          {
              double radiusNode = RADIUS_NODE;
  
              EllipseGeometry ellipseGeometry;
              Point node;
              bool deleteFlag = false;
  
  
              if (RightClick)
              {
                  if (gGrpBlueNode.Children.Count > 0)
                  {
                      for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
                      {
                          ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
                          node = ellipseGeometry.Center;
                          if (FreeNode.X == node.X)
                          {
                              if (CheckIsNode(FreeNode, node, radiusNode))
                              {
                                  deleteFlag = true;
                              }
                          }
                          else
                          {
                              if (CheckIsNode(FreeNode, node, radiusNode))
                              {
                                  deleteFlag = true;
                              }
                          }
                          if (deleteFlag)
                          {
                              MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel);
                              if (result == MessageBoxResult.OK)
                              {
b338e1ff5   nguyen_nam   no message
2062
2063
                                  //Call Function Delete Node
                                  DeleteNode(i);
b338e1ff5   nguyen_nam   no message
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
                                  return;
                              }
                              else
                              {
                                  return;
                              }
                          }
                      }
                  }
              }
              else
              {
                  //Check EditNode State
                  for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
                  {
                      ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
                      node = ellipseGeometry.Center;
                      bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE);
  
                      if (isEditNode)
                      {
                          NewEditNode(node);
                          NewDspRouteInfo();
                          return;
                      }
                  }
  
  
                  MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel);
                  if (result == MessageBoxResult.OK)
                  {
                      AddNode(FreeNode, gGrpBlueNode);
  
                      TextBlock textBlock = new TextBlock();
                      textBlock.Text = stt.ToString();
                      textBlock.FontSize = 35;
                      textBlock.VerticalAlignment = VerticalAlignment.Center;
                      textBlock.HorizontalAlignment = HorizontalAlignment.Center;
                      textBlock.Foreground = new SolidColorBrush(Colors.Red);
  
                      Canvas.SetLeft(textBlock, FreeNode.X - RADIUS_NODE / 2);
                      Canvas.SetTop(textBlock, FreeNode.Y - 1.5 * RADIUS_NODE);
  
  
                      this.Children.Add(textBlock);
                      NodeNo.Add(textBlock);
  
                      if (stt > 1)
                      {
                          int tmp = gGrpBlueNode.Children.Count;
  
                          EllipseGeometry elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 2];
                          Point node1 = elip.Center;
                          elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 1];
                          Point node2 = elip.Center;
                          DrawLine(node1, node2, gGrpNewLine);
  
  
                          this.Children.Remove(pBlueNode);
                          for (int i = 0; i < tmp; i++)
                          {
                              this.Children.Remove(NodeNo[i]);
                          }
  
                          this.Children.Add(pBlueNode);
                          for (int i = 0; i < tmp; i++)
                          {
                              this.Children.Add(NodeNo[i]);
                          }
                      }
  
                      stt++;
                      NewInitNodeInfo_List();
                      NewDspRouteInfo();
                  }
              }
          }
  
          public void DeleteNode(int i)
          {
a47f478f0   doan   開発 #2045 : node の...
2144
              //DrawLine(Point startPoint, Point endPoint, GeometryGroup geometryGroup)
b338e1ff5   nguyen_nam   no message
2145
2146
              LineGeometry lineGeometry = new LineGeometry();
              EllipseGeometry ellip;
a47f478f0   doan   開発 #2045 : node の...
2147

ebf4e3eed   nguyen_nam   Update Task 2045
2148
              //check delete last node
b338e1ff5   nguyen_nam   no message
2149
2150
              if (i == gGrpBlueNode.Children.Count - 1)
              {
160b9bec8   nguyen_nam   Tbl Node info
2151
                  // delete line
b338e1ff5   nguyen_nam   no message
2152
2153
                  if (gGrpNewLine.Children.Count > 0)
                  {
a47f478f0   doan   開発 #2045 : node の...
2154
                      gGrpNewLine.Children.RemoveAt(i - 1);
b338e1ff5   nguyen_nam   no message
2155
                  }
a47f478f0   doan   開発 #2045 : node の...
2156

160b9bec8   nguyen_nam   Tbl Node info
2157
                  // delete ucNode
b338e1ff5   nguyen_nam   no message
2158
2159
2160
2161
                  ucNode _ucNode = new ucNode();
                  _ucNode = ucNode_Lst[i];
                  this.Children.Remove(_ucNode);
                  ucNode_Lst.RemoveAt(i);
160b9bec8   nguyen_nam   Tbl Node info
2162
                  // delete node
b338e1ff5   nguyen_nam   no message
2163
                  gGrpBlueNode.Children.RemoveAt(i);
160b9bec8   nguyen_nam   Tbl Node info
2164
                  NewNodeInfo_List.RemoveAt(i);
b338e1ff5   nguyen_nam   no message
2165
2166
2167
2168
  
              }
              else
              {
ebf4e3eed   nguyen_nam   Update Task 2045
2169
2170
2171
2172
                  //delete all line and remove Point at 'i' 
                  gGrpNewLine.Children.Clear();
                  this.Children.Remove(pNewLine);
                  gGrpBlueNode.Children.RemoveAt(i);
b338e1ff5   nguyen_nam   no message
2173

ebf4e3eed   nguyen_nam   Update Task 2045
2174
                  //redraw line
a47f478f0   doan   開発 #2045 : node の...
2175
                  for (int j = 0; j < gGrpBlueNode.Children.Count - 1; j++)
ebf4e3eed   nguyen_nam   Update Task 2045
2176
2177
2178
                  {
                      ellip = (EllipseGeometry)gGrpBlueNode.Children[j];
                      Point node1 = ellip.Center;
a47f478f0   doan   開発 #2045 : node の...
2179
                      ellip = (EllipseGeometry)gGrpBlueNode.Children[j + 1];
ebf4e3eed   nguyen_nam   Update Task 2045
2180
2181
2182
                      Point node2 = ellip.Center;
                      DrawLine(node1, node2, gGrpNewLine);
                  }
b338e1ff5   nguyen_nam   no message
2183

ebf4e3eed   nguyen_nam   Update Task 2045
2184
                  this.Children.Add(pNewLine);
b338e1ff5   nguyen_nam   no message
2185

ebf4e3eed   nguyen_nam   Update Task 2045
2186
2187
2188
2189
2190
2191
2192
                  //remove ucNode
                  for (int j = ucNode_Lst.Count - 1; j > i; j--)
                  {
                      ucNode_Lst[j].txtNode = ucNode_Lst[j - 1].txtNode;
                  }
                  this.Children.Remove(ucNode_Lst[i]);
                  ucNode_Lst.RemoveAt(i);
b338e1ff5   nguyen_nam   no message
2193

ebf4e3eed   nguyen_nam   Update Task 2045
2194
2195
2196
2197
2198
2199
                  //redraw ucNode
                  for (int k = 0; k < ucNode_Lst.Count; k++)
                  {
                      this.Children.Remove(ucNode_Lst[k]);
                      this.Children.Add(ucNode_Lst[k]);
                  }
b338e1ff5   nguyen_nam   no message
2200
              }
160b9bec8   nguyen_nam   Tbl Node info
2201
              //NewInitNodeInfo_List();
6312cbd86   doan   Task 2062
2202
              Lst_Node_tmp.RemoveAt(i);
160b9bec8   nguyen_nam   Tbl Node info
2203
              NewDspRouteInfo();
b338e1ff5   nguyen_nam   no message
2204
              stt--;
a47f478f0   doan   開発 #2045 : node の...
2205

b338e1ff5   nguyen_nam   no message
2206
          }
a47f478f0   doan   開発 #2045 : node の...
2207
2208
2209
2210
2211
2212
2213
2214
2215
          public void ReDrawAllNode()
          {
              LineGeometry lineGeometry = new LineGeometry();
              EllipseGeometry ellip;
              //delete all line
              gGrpNewLine.Children.Clear();
              this.Children.Remove(pNewLine);
  
              //redraw line
fd7150b8b   doan   Update Task 2062
2216
              for (int j = 0; j < gGrpBlueNode.Children.Count - 1; j++)
a47f478f0   doan   開発 #2045 : node の...
2217
2218
2219
              {
                  ellip = (EllipseGeometry)gGrpBlueNode.Children[j];
                  Point node1 = ellip.Center;
fd7150b8b   doan   Update Task 2062
2220
                  ellip = (EllipseGeometry)gGrpBlueNode.Children[j + 1];
a47f478f0   doan   開発 #2045 : node の...
2221
2222
2223
2224
2225
                  Point node2 = ellip.Center;
                  DrawLine(node1, node2, gGrpNewLine);
              }
  
              this.Children.Add(pNewLine);
fd7150b8b   doan   Update Task 2062
2226

a47f478f0   doan   開発 #2045 : node の...
2227
2228
2229
2230
2231
2232
              //redraw ucNode
              for (int k = 0; k < ucNode_Lst.Count; k++)
              {
                  this.Children.Remove(ucNode_Lst[k]);
                  this.Children.Add(ucNode_Lst[k]);
              }
b338e1ff5   nguyen_nam   no message
2233

fd7150b8b   doan   Update Task 2062
2234
2235
2236
              //backup DB
              CreateVehicleNode();
          }
b338e1ff5   nguyen_nam   no message
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
  
  
          public void NewInitNodeInfo_List()
          {
              //Reset List
              //NewNodeInfo_List = new List<NewNodeInfo>();
  
              if (gGrpBlueNode.Children.Count > 0)
              {
                  //for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
                  //{
fd7150b8b   doan   Update Task 2062
2248
2249
2250
2251
                  int i = gGrpBlueNode.Children.Count - 1;
                  Point point;
                  EllipseGeometry eGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
                  point = eGeometry.Center;
b338e1ff5   nguyen_nam   no message
2252

fd7150b8b   doan   Update Task 2062
2253
2254
2255
                  NewNodeInfo Ninfo = new NewNodeInfo();
                  Ninfo.X = point.X;
                  Ninfo.Y = point.Y;
b338e1ff5   nguyen_nam   no message
2256

fd7150b8b   doan   Update Task 2062
2257
                  Ninfo.Mode = "";
b338e1ff5   nguyen_nam   no message
2258

fd7150b8b   doan   Update Task 2062
2259
                  NewNodeInfo_List.Add(Ninfo);
b338e1ff5   nguyen_nam   no message
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
                  //}
  
              }
          }
  
          public void NewEditNode(Point node_edited)
          {
              EllipseGeometry ellipseGeometry;
              Point node;
              double radiusNode = RADIUS_NODE;
  
              bool flag = false;
  
              if (gGrpBlueNode.Children.Count > 0)
              {
                  for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
                  {
                      ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
                      node = ellipseGeometry.Center;
  
                      if (CheckIsNode(node_edited, node, radiusNode))
                      {
                          flag = true;
                      }
  
                      if (flag)
                      {
                          node_edited.X = node.X;
                          node_edited.Y = node.Y;
  
                          // show form edit node
                          EditNodeWindow edtNodeWindow = new EditNodeWindow();
01c8c8f49   doan   Update Task 2068
2292
                          List<ListNodeInfo> lst_tmpdfd = new List<ListNodeInfo>();
b338e1ff5   nguyen_nam   no message
2293

5a5c5239e   nguyen_nam   Task: 2095
2294
                          if (ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList.Count > 0)
01c8c8f49   doan   Update Task 2068
2295
                          {
5a5c5239e   nguyen_nam   Task: 2095
2296
                              for (int k = 0; k < ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList.Count; k++)
01c8c8f49   doan   Update Task 2068
2297
                              {
5a5c5239e   nguyen_nam   Task: 2095
2298
2299
                                  double X = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].pointMap_X;
                                  double Y = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].pointMap_Y;
5db801240   doan   update 2099
2300
2301
2302
2303
2304
2305
2306
2307
2308
  
                                  Point node_editedActual = new Point();
  
                                  node_editedActual.X = ConvertPointDisplayToActual(node_edited.X, Scale_X, PointMapStart_X);
                                  node_editedActual.Y = ConvertPointDisplayToActual(node_edited.Y, Scale_Y, PointMapStart_Y);
  
  
                                  //if (node_edited.X == X && node_edited.Y == Y)
                                  if (node_editedActual.X == X && node_editedActual.Y == Y)
01c8c8f49   doan   Update Task 2068
2309
                                  {
5a5c5239e   nguyen_nam   Task: 2095
2310
                                      if (ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].ListNodeInfo.Count > 0)
01c8c8f49   doan   Update Task 2068
2311
                                      {
5a5c5239e   nguyen_nam   Task: 2095
2312
                                          for (int m = 0; m < ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].ListNodeInfo.Count; m++)
01c8c8f49   doan   Update Task 2068
2313
2314
                                          {
                                              ListNodeInfo InputNodeInfo = new ListNodeInfo();
5a5c5239e   nguyen_nam   Task: 2095
2315
2316
2317
2318
2319
                                              InputNodeInfo.Mode = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].ListNodeInfo[m].Mode;
                                              InputNodeInfo.Speed = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].ListNodeInfo[m].Speed;
                                              InputNodeInfo.Angle = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].ListNodeInfo[m].Angle;
                                              InputNodeInfo.Height = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].ListNodeInfo[m].Height;
                                              InputNodeInfo.ModeSelected = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].ListNodeInfo[m].ModeSelected;
01c8c8f49   doan   Update Task 2068
2320
2321
2322
2323
2324
2325
                                              lst_tmpdfd.Add(InputNodeInfo);
                                          }
  
                                          edtNodeWindow.NodeInf_List = lst_tmpdfd;
  
                                      }
abaa8d900   doan   Update Task 2099
2326
2327
2328
                                      edtNodeWindow.NameNode = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].nameNode;
                                      edtNodeWindow.LAT = X.ToString(); ;
                                      edtNodeWindow.LOC = Y.ToString();
6312cbd86   doan   Task 2062
2329

01c8c8f49   doan   Update Task 2068
2330
2331
2332
                                  }
                              }
                          }
6312cbd86   doan   Task 2062
2333

01c8c8f49   doan   Update Task 2068
2334
                          edtNodeWindow.ShowDialog();
6312cbd86   doan   Task 2062
2335

abaa8d900   doan   Update Task 2099
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
                          //Save NameNode
                          string strNameNode = edtNodeWindow.NameNode;
                          ListNameNode nmNode = new ListNameNode();
  
                          nmNode.X = node.X;
                          nmNode.Y = node.Y;
                          nmNode.nameNode = strNameNode;
  
                          NameNode_List[i] = nmNode;
  
  
                          ucNode _ucNode = new ucNode();
                          _ucNode = ucNode_Lst[i];
                          this.Children.Remove(_ucNode);
                          ucNode_Lst.RemoveAt(i);
  
                          string color = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[i].color;
                          CreateMapNode(node, i, color, strNameNode);
5db801240   doan   update 2099
2354

abaa8d900   doan   Update Task 2099
2355

01c8c8f49   doan   Update Task 2068
2356
                          string result = edtNodeWindow._txtMode;
6312cbd86   doan   Task 2062
2357

01c8c8f49   doan   Update Task 2068
2358
2359
                          List<ListNodeInfo> lst_tmp = edtNodeWindow.NodeInf_List;
                          Lst_Node_tmp[i].NodeInfo_tmp.Clear();
6312cbd86   doan   Task 2062
2360

01c8c8f49   doan   Update Task 2068
2361
2362
                          for (int j = 0; j < lst_tmp.Count; j++)
                          {
6312cbd86   doan   Task 2062
2363

01c8c8f49   doan   Update Task 2068
2364
2365
                              ListNodeInfo ni = new ListNodeInfo();
                              ni = lst_tmp[j];
6312cbd86   doan   Task 2062
2366

01c8c8f49   doan   Update Task 2068
2367
                              Lst_Node_tmp[i].NodeInfo_tmp.Add(ni);
6312cbd86   doan   Task 2062
2368
2369
2370
2371
2372
                          }
  
  
                          //backup DB
                          CreateVehicleNode();
b338e1ff5   nguyen_nam   no message
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
                          bool exit = edtNodeWindow._ExitFlg;
  
                          if (!exit)
                          {
                              NewSaveChanged(node_edited.X, node_edited.Y, result);
                          }
  
                          return;
                      }
                  }
              }
          }
  
          //Save Node's Data Edited
          public void NewSaveChanged(double x, double y, string st)
          {
              for (int i = 0; i < NewNodeInfo_List.Count; i++)
              {
                  NewNodeInfo ni = new NewNodeInfo();
                  ni = NewNodeInfo_List[i];
  
                  if (ni.X == x && ni.Y == y)
                  {
                      ni.Mode = st;
  
                      NewNodeInfo_List[i] = ni;
                      return;
                  }
              }
          }
  
          public void NewDspRouteInfo()
          {
              //Clear Route Info Table
              ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Clear();
6312cbd86   doan   Task 2062
2408
2409
              int _RowIdx = 0;
              string _Content = "";
b338e1ff5   nguyen_nam   no message
2410

6312cbd86   doan   Task 2062
2411
              if (Lst_Node_tmp.Count != 0)
b338e1ff5   nguyen_nam   no message
2412
              {
6312cbd86   doan   Task 2062
2413
                  for (int i = 0; i < Lst_Node_tmp.Count; i++)
b338e1ff5   nguyen_nam   no message
2414
                  {
6312cbd86   doan   Task 2062
2415
                      //column 1 : node index
fd7150b8b   doan   Update Task 2062
2416
                      _Content = (i + 1).ToString();
b338e1ff5   nguyen_nam   no message
2417
2418
2419
2420
                      AddLabeltoGrid(_RowIdx, 0, _Content);
  
                      //column 2
                      // Display Node's Position
6312cbd86   doan   Task 2062
2421
                      _Content = "LAT " + Lst_Node_tmp[i].pointMap_X;
b338e1ff5   nguyen_nam   no message
2422
2423
                      AddLabeltoGrid(_RowIdx, 1, _Content);
                      _RowIdx++;
6312cbd86   doan   Task 2062
2424
                      _Content = "LOC " + Lst_Node_tmp[i].pointMap_Y;
b338e1ff5   nguyen_nam   no message
2425
2426
2427
                      AddLabeltoGrid(_RowIdx, 1, _Content);
  
                      // Display Node's Field
b864d9729   doan   Commit Task 2085
2428

6312cbd86   doan   Task 2062
2429
                      if (Lst_Node_tmp[i].NodeInfo_tmp.Count != 0)
b338e1ff5   nguyen_nam   no message
2430
                      {
6312cbd86   doan   Task 2062
2431
                          foreach (ListNodeInfo ni in Lst_Node_tmp[i].NodeInfo_tmp)
b338e1ff5   nguyen_nam   no message
2432
                          {
b864d9729   doan   Commit Task 2085
2433
                              if (ni.Speed != 0 && ni.ModeSelected == 1)
b338e1ff5   nguyen_nam   no message
2434
                              {
6312cbd86   doan   Task 2062
2435
2436
                                  _RowIdx++;
                                  _Content = "SPD " + ni.Speed.ToString() + " Km/h";
b338e1ff5   nguyen_nam   no message
2437
2438
2439
                                  AddLabeltoGrid(_RowIdx, 1, _Content);
                              }
                          }
6312cbd86   doan   Task 2062
2440

b338e1ff5   nguyen_nam   no message
2441
2442
2443
                      }
                      _RowIdx++;
                  }
6312cbd86   doan   Task 2062
2444

b338e1ff5   nguyen_nam   no message
2445
              }
6312cbd86   doan   Task 2062
2446

b338e1ff5   nguyen_nam   no message
2447
          }
dae7878f9   nguyen_nam   Task 2100
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
          public void NewDspWorkLog()
          {
              //Clear Route Info Table
              ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdWorkLog.Children.Clear();
              int _RowIdx = 0;
              string _Content = "";
  
              if (Lst_Node_tmp.Count != 0)
              {
                  for (int i = Lst_Node_tmp.Count - 1; i > 0; i--)
                  {
                      //column 1 : node index
                      _Content = (Lst_Node_tmp.Count - i).ToString();
                      AddLabeltoWorkLog(_RowIdx, 0, _Content);
  
                      //column 2
                      //Fork Name
                      _Content = VehicleItem + " TIME " + Lst_Node_tmp[i].timeStamp;
                      AddLabeltoWorkLog(_RowIdx, 1, _Content);
                      _RowIdx++;
  
                      // Display Node's Position
                      _Content = "LAT " + Lst_Node_tmp[i].pointMap_X;
                      AddLabeltoWorkLog(_RowIdx, 1, _Content);
                      _RowIdx++;
  
                      _Content = "LOC " + Lst_Node_tmp[i].pointMap_Y;
                      AddLabeltoWorkLog(_RowIdx, 1, _Content);
  
                      // Display Node's Field
  
                      if (Lst_Node_tmp[i].NodeInfo_tmp.Count != 0)
                      {
                          foreach (ListNodeInfo ni in Lst_Node_tmp[i].NodeInfo_tmp)
                          {
                              if (ni.Speed != 0 && ni.ModeSelected == 1)
                              {
                                  _RowIdx++;
                                  _Content = "SPD " + ni.Speed.ToString() + " Km/h";
                                  AddLabeltoWorkLog(_RowIdx, 1, _Content);
                              }
                          }
  
                      }
                      _RowIdx++;
                  }
  
              }
  
          }
  
          public void AddLabeltoWorkLog(int RowIdx, int ColIdx, string Content)
          {
              //Add Row to Grid
              RowDefinition _rd = new RowDefinition();
              ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdWorkLog.RowDefinitions.Add(_rd);
  
              // Add data to Grid
              Label dynamicLabel = new Label();
  
              dynamicLabel.Content = Content;
              dynamicLabel.Margin = new Thickness(0, 0, 0, 0);
              dynamicLabel.Foreground = new SolidColorBrush(Colors.Black);
              dynamicLabel.Background = new SolidColorBrush(Colors.White);
              dynamicLabel.BorderBrush = new SolidColorBrush(Colors.LightGray);
              dynamicLabel.BorderThickness = new Thickness(1);
  
              Grid.SetRow(dynamicLabel, RowIdx);
              Grid.SetColumn(dynamicLabel, ColIdx);
              ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdWorkLog.Children.Add(dynamicLabel);
          }
b338e1ff5   nguyen_nam   no message
2519

a47f478f0   doan   開発 #2045 : node の...
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
          //2017/03/07 tach rieng CreateNode start
          private void execDeleteNode(Point FreeNode)
          {
  
              double radiusNode = RADIUS_NODE;
  
              EllipseGeometry ellipseGeometry;
              Point node;
              bool deleteFlag = false;
  
              if (gGrpBlueNode.Children.Count > 0)
              {
                  for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
                  {
                      ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
                      node = ellipseGeometry.Center;
                      if (FreeNode.X == node.X)
                      {
                          if (CheckIsNode(FreeNode, node, radiusNode))
                          {
                              deleteFlag = true;
                          }
                      }
                      else
                      {
                          if (CheckIsNode(FreeNode, node, radiusNode))
                          {
                              deleteFlag = true;
                          }
                      }
                      if (deleteFlag)
                      {
                          MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel);
                          if (result == MessageBoxResult.OK)
                          {
                              DeleteNode(i);
                              SetScheduleRoute();
  
                              return;
                          }
                          else
                          {
                              return;
                          }
                      }
                  }
              }
          }
  
  
          private void execEditNode(Point FreeNode)
          {
              EllipseGeometry ellipseGeometry;
              Point node;
              for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
              {
                  ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
                  node = ellipseGeometry.Center;
                  bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE);
  
                  if (isEditNode)
                  {
                      NewEditNode(node);
                      NewDspRouteInfo();
                      return;
                  }
              }
          }
  
  
          private void execCreateNode(Point FreeNode)
          {
01c8c8f49   doan   Update Task 2068
2592
2593
              bool createNodeFlag = false;
              string NameNode = "";
a47f478f0   doan   開発 #2045 : node の...
2594
2595
2596
2597
2598
2599
2600
2601
              //check new node in exist line
              if (gGrpNewLine.Children.Count > 0)
              {
                  for (int i = 0; i < gGrpNewLine.Children.Count; i++)
                  {
                      LineGeometry lineGeometry = (LineGeometry)gGrpNewLine.Children[i];
                      Point p1 = lineGeometry.StartPoint;
                      Point p2 = lineGeometry.EndPoint;
d96c9e481   doan   Update Source Code
2602
                      bool pInL = PointInLine(FreeNode, p1, p2, UCNODE_SETLEFT);
a47f478f0   doan   開発 #2045 : node の...
2603
2604
2605
  
                      if (pInL)
                      {
01c8c8f49   doan   Update Task 2068
2606
2607
2608
2609
2610
2611
2612
2613
2614
                          // show form create node
  
                          AddNodeView edtNodeWindow = new AddNodeView();
                          edtNodeWindow.ShowDialog();
                          createNodeFlag = edtNodeWindow.CreateNodeFlag;
                          NameNode = edtNodeWindow.NameNode;
  
                          //MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel);
                          if (createNodeFlag)
a47f478f0   doan   開発 #2045 : node の...
2615
2616
2617
                          {
                              Point tmpPoint = ConvertNodeinLine(FreeNode, p1, p2);
                              FreeNode = tmpPoint;
a47f478f0   doan   開発 #2045 : node の...
2618

01c8c8f49   doan   Update Task 2068
2619
                              CreateMapNode(FreeNode, i + 1, ColorNode_Insert, NameNode);
a47f478f0   doan   開発 #2045 : node の...
2620
                              gGrpBlueNode.Children.Insert(i + 1, new EllipseGeometry(FreeNode, RADIUS_NODE, RADIUS_NODE));
6312cbd86   doan   Task 2062
2621
2622
2623
2624
2625
2626
2627
2628
2629
                              //set location infor to table info
                              SetLoc_NodeInfoList(FreeNode, i + 1);
  
                              SetScheduleRoute();
  
                              ListIndexNodeInsert ListIndex = new ListIndexNodeInsert();
                              ListIndex.X = FreeNode.X;
                              ListIndex.Y = FreeNode.Y;
                              IndexNodeInsert_List.Add(ListIndex);
a47f478f0   doan   開発 #2045 : node の...
2630

01c8c8f49   doan   Update Task 2068
2631
2632
2633
2634
2635
                              ListNameNode ListNamenodde = new ListNameNode();
                              ListNamenodde.X = FreeNode.X;
                              ListNamenodde.Y = FreeNode.Y;
                              ListNamenodde.nameNode = NameNode;
                              NameNode_List.Add(ListNamenodde);
a47f478f0   doan   開発 #2045 : node の...
2636
2637
2638
2639
2640
2641
2642
                              //rename Point textName
                              for (int j = 0; j < ucNode_Lst.Count; j++)
                              {
                                  ucNode_Lst[j].txtNode = (j + 1).ToString();
                                  this.Children.Remove(ucNode_Lst[j]);
                                  this.Children.Add(ucNode_Lst[j]);
                              }
a47f478f0   doan   開発 #2045 : node の...
2643
2644
2645
2646
2647
2648
2649
2650
                              ReDrawAllNode();
  
                              stt++;
                              NewInitNodeInfo_List();
                              NewDspRouteInfo();
                              return;
                          }
                          else
fd7150b8b   doan   Update Task 2062
2651
2652
2653
                          {
                              return;
                          }
a47f478f0   doan   開発 #2045 : node の...
2654
2655
2656
                      }
                  }
              }
5db801240   doan   update 2099
2657
              if (readMapFan == true)
01c8c8f49   doan   Update Task 2068
2658
2659
              {
                  CreateMapNode(FreeNode, gGrpBlueNode.Children.Count, ColorNode_Add, NameNode);
a47f478f0   doan   開発 #2045 : node の...
2660

01c8c8f49   doan   Update Task 2068
2661
2662
2663
2664
2665
                  ListNameNode ListNamenodde = new ListNameNode();
                  ListNamenodde.X = FreeNode.X;
                  ListNamenodde.Y = FreeNode.Y;
                  ListNamenodde.nameNode = NameNode;
                  NameNode_List.Add(ListNamenodde);
a47f478f0   doan   開発 #2045 : node の...
2666

01c8c8f49   doan   Update Task 2068
2667
2668
2669
                  gGrpBlueNode.Children.Insert(gGrpBlueNode.Children.Count, new EllipseGeometry(FreeNode, RADIUS_NODE, RADIUS_NODE));
                  //set location infor to table info
                  SetLoc_NodeInfoList(FreeNode, gGrpBlueNode.Children.Count - 1);
a47f478f0   doan   開発 #2045 : node の...
2670

01c8c8f49   doan   Update Task 2068
2671
2672
2673
2674
                  SetScheduleRoute();
  
                  //draw line
                  if (stt > 1)
a47f478f0   doan   開発 #2045 : node の...
2675
                  {
01c8c8f49   doan   Update Task 2068
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
                      //delete all line
                      gGrpNewLine.Children.Clear();
                      this.Children.Remove(pNewLine);
                      //redraw line
                      for (int j = 0; j < gGrpBlueNode.Children.Count - 1; j++)
                      {
                          EllipseGeometry ellip = (EllipseGeometry)gGrpBlueNode.Children[j];
                          Point node1 = ellip.Center;
                          ellip = (EllipseGeometry)gGrpBlueNode.Children[j + 1];
                          Point node2 = ellip.Center;
                          DrawLine(node1, node2, gGrpNewLine);
                      }
  
                      this.Children.Add(pNewLine);
  
                      //rename Point textName
                      for (int j = 0; j < ucNode_Lst.Count; j++)
                      {
                          ucNode_Lst[j].txtNode = (j + 1).ToString();
                          this.Children.Remove(ucNode_Lst[j]);
                          this.Children.Add(ucNode_Lst[j]);
                      }
a47f478f0   doan   開発 #2045 : node の...
2698
                  }
01c8c8f49   doan   Update Task 2068
2699
2700
2701
2702
2703
2704
                  stt++;
                  NewInitNodeInfo_List();
                  NewDspRouteInfo();
              }
              else
              {
a47f478f0   doan   開発 #2045 : node の...
2705

01c8c8f49   doan   Update Task 2068
2706
2707
2708
2709
2710
                  AddNodeView createNodeWindow = new AddNodeView();
                  createNodeWindow.ShowDialog();
                  createNodeFlag = createNodeWindow.CreateNodeFlag;
                  NameNode = createNodeWindow.NameNode;
                  if (createNodeFlag)
a47f478f0   doan   開発 #2045 : node の...
2711
                  {
01c8c8f49   doan   Update Task 2068
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
                      CreateMapNode(FreeNode, gGrpBlueNode.Children.Count, ColorNode_Add, NameNode);
  
                      ListNameNode ListNamenodde = new ListNameNode();
                      ListNamenodde.X = FreeNode.X;
                      ListNamenodde.Y = FreeNode.Y;
                      ListNamenodde.nameNode = NameNode;
                      NameNode_List.Add(ListNamenodde);
  
                      gGrpBlueNode.Children.Insert(gGrpBlueNode.Children.Count, new EllipseGeometry(FreeNode, RADIUS_NODE, RADIUS_NODE));
                      //set location infor to table info
                      SetLoc_NodeInfoList(FreeNode, gGrpBlueNode.Children.Count - 1);
  
                      SetScheduleRoute();
  
                      //draw line
                      if (stt > 1)
                      {
                          //delete all line
                          gGrpNewLine.Children.Clear();
                          this.Children.Remove(pNewLine);
                          //redraw line
                          for (int j = 0; j < gGrpBlueNode.Children.Count - 1; j++)
                          {
                              EllipseGeometry ellip = (EllipseGeometry)gGrpBlueNode.Children[j];
                              Point node1 = ellip.Center;
                              ellip = (EllipseGeometry)gGrpBlueNode.Children[j + 1];
                              Point node2 = ellip.Center;
                              DrawLine(node1, node2, gGrpNewLine);
                          }
  
                          this.Children.Add(pNewLine);
  
                          //rename Point textName
                          for (int j = 0; j < ucNode_Lst.Count; j++)
                          {
                              ucNode_Lst[j].txtNode = (j + 1).ToString();
                              this.Children.Remove(ucNode_Lst[j]);
                              this.Children.Add(ucNode_Lst[j]);
                          }
                      }
  
                      stt++;
                      NewInitNodeInfo_List();
                      NewDspRouteInfo();
a47f478f0   doan   開発 #2045 : node の...
2756
2757
                  }
              }
5db801240   doan   update 2099
2758

a47f478f0   doan   開発 #2045 : node の...
2759
          }
01c8c8f49   doan   Update Task 2068
2760
          public void CreateMapNode(Point FreeNode, int stt, String Color, string NameNode)
fd7150b8b   doan   Update Task 2062
2761
2762
2763
2764
          {
              ucNode _ucNode = new ucNode();
              _ucNode.btnWidth = UCNODE_WIDTH;
              _ucNode.btnHeight = UCNODE_HEIGHT;
a47f478f0   doan   開発 #2045 : node の...
2765

6312cbd86   doan   Task 2062
2766
              _ucNode.txtNode = (stt + 1).ToString();
01c8c8f49   doan   Update Task 2068
2767
2768
              _ucNode.coordString = NameNode;
              _ucNode.NameNode = NameNode;
a47f478f0   doan   開発 #2045 : node の...
2769

fd7150b8b   doan   Update Task 2062
2770
2771
2772
2773
2774
2775
2776
              _ucNode.fillColor = Color;
              _ucNode.IsDragDelta = true;
              Canvas.SetLeft(_ucNode, FreeNode.X - UCNODE_SETLEFT);
              Canvas.SetTop(_ucNode, FreeNode.Y - UCNODE_SETTOP);
              this.Children.Add(_ucNode);
              //ucNode_Lst.Add(_ucNode);
              ucNode_Lst.Insert(stt, _ucNode);
a47f478f0   doan   開発 #2045 : node の...
2777

6312cbd86   doan   Task 2062
2778

fd7150b8b   doan   Update Task 2062
2779
2780
              //AddNode(FreeNode, gGrpBlueNode);
              //gGrpBlueNode.Children.Insert(stt, new EllipseGeometry(FreeNode, RADIUS_NODE, RADIUS_NODE));
a47f478f0   doan   開発 #2045 : node の...
2781

fd7150b8b   doan   Update Task 2062
2782
          }
a47f478f0   doan   開発 #2045 : node の...
2783

6312cbd86   doan   Task 2062
2784
2785
2786
2787
          public void SetLoc_NodeInfoList(Point FreeNode, int stt)
          {
              //add location for NodeInfoList
              Node_tmp nodetmp = new Node_tmp();
5db801240   doan   update 2099
2788
2789
              nodetmp.pointMap_X = ConvertPointDisplayToActual(FreeNode.X, Scale_X, PointMapStart_X);
              nodetmp.pointMap_Y = ConvertPointDisplayToActual(FreeNode.Y, Scale_Y, PointMapStart_Y);
6312cbd86   doan   Task 2062
2790
2791
2792
2793
  
              Lst_Node_tmp.Insert(stt, nodetmp);
  
          }
fd7150b8b   doan   Update Task 2062
2794
          public void BindBlueNode2ucNode()
b338e1ff5   nguyen_nam   no message
2795
          {
01c8c8f49   doan   Update Task 2068
2796
              string NameNode = "";
6312cbd86   doan   Task 2062
2797
              bool NodeIsInsert = false;
fd7150b8b   doan   Update Task 2062
2798
              if (gGrpBlueNode.Children.Count > 0)
b338e1ff5   nguyen_nam   no message
2799
              {
fd7150b8b   doan   Update Task 2062
2800
                  for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
b338e1ff5   nguyen_nam   no message
2801
                  {
6312cbd86   doan   Task 2062
2802
                      NodeIsInsert = false;
fd7150b8b   doan   Update Task 2062
2803
2804
                      EllipseGeometry ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
                      Point node = ellipseGeometry.Center;
b338e1ff5   nguyen_nam   no message
2805

01c8c8f49   doan   Update Task 2068
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
                      //Get Name Node
                      if (NameNode_List.Count > 0)
                      {
                          for (int k = 0; k < NameNode_List.Count; k++)
                          {
                              if (node.X == NameNode_List[k].X && node.Y == NameNode_List[k].Y)
                              {
                                  NameNode = NameNode_List[k].nameNode;
                              }
                          }
                      }
6312cbd86   doan   Task 2062
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
                      //Draw Node Insert Color is Brown
                      if (IndexNodeInsert_List.Count > 0)
                      {
                          for (int j = 0; j < IndexNodeInsert_List.Count; j++)
                          {
                              if (node.X == IndexNodeInsert_List[j].X && node.Y == IndexNodeInsert_List[j].Y)
                              {
                                  NodeIsInsert = true;
                              }
                          }
                      }
                      if (NodeIsInsert)
                      {
01c8c8f49   doan   Update Task 2068
2830
                          CreateMapNode(node, i, ColorNode_Insert, NameNode);
6312cbd86   doan   Task 2062
2831
2832
2833
                      }
                      else
                      {
01c8c8f49   doan   Update Task 2068
2834
                          CreateMapNode(node, i, ColorNode_Add, NameNode);
6312cbd86   doan   Task 2062
2835
                      }
b338e1ff5   nguyen_nam   no message
2836
2837
                  }
              }
fd7150b8b   doan   Update Task 2062
2838
          }
b338e1ff5   nguyen_nam   no message
2839

fd7150b8b   doan   Update Task 2062
2840
          //2017/03/07 tach CreateNode End
a47f478f0   doan   開発 #2045 : node の...
2841

ebf4e3eed   nguyen_nam   Update Task 2045
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
  
          public Point ConvertNodeinLine(Point point, Point l1, Point l2)
          {
              Point pointResult = new Point();
              double X = 0;
              double Y = 0;
  
              double distance_Line = 0;
              double distance_l1ToPoint = 0;
  
              distance_Line = DistanceTo(l1, l2);
              distance_l1ToPoint = DistanceTo(l1, point);
  
  
              if (l1.X == l2.X)
              {
                  X = l1.X;
                  Y = point.Y;
              }
              else if (l1.Y == l2.Y)
              {
                  X = point.X;
                  Y = l1.Y;
              }
              else
              {
                  if (l1.X < l2.X)
                  {
                      if (l1.Y < l2.Y)
                      {
                          Y = l1.Y + (distance_l1ToPoint * (l2.Y - l1.Y) / distance_Line);
                          X = l1.X + (distance_l1ToPoint * (l2.X - l1.X) / distance_Line);
                      }
                      else
                      {
                          Y = l1.Y - (distance_l1ToPoint * (l1.Y - l2.Y) / distance_Line);
                          X = l1.X + (distance_l1ToPoint * (l2.X - l1.X) / distance_Line);
                      }
                  }
                  else
                  {
                      if (l1.Y < l2.Y)
                      {
                          Y = l1.Y + (distance_l1ToPoint * (l2.Y - l1.Y) / distance_Line);
                          X = l1.X - (distance_l1ToPoint * (l1.X - l2.X) / distance_Line);
                      }
                      else
                      {
                          Y = l1.Y - (distance_l1ToPoint * (l1.Y - l2.Y) / distance_Line);
                          X = l1.X - (distance_l1ToPoint * (l1.X - l2.X) / distance_Line);
                      }
                  }
  
  
              }
  
              pointResult.X = X;
              pointResult.Y = Y;
              return pointResult;
          }
  
          public static double DistanceTo(Point point1, Point point2)
          {
              var a = (double)(point2.X - point1.X);
              var b = (double)(point2.Y - point1.Y);
fd7150b8b   doan   Update Task 2062
2907
              return Math.Sqrt(a * a + b * b);
ebf4e3eed   nguyen_nam   Update Task 2045
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
          }
  
          public bool PointInLine(Point point, Point l1, Point l2, double radius)
          {
              double distance = 0;
              bool falg = false;
  
              if (l1.X < l2.X)
              {
                  if (l1.Y < l2.Y)
                  {
0f3305e1d   doan   Update Task 2045
2919
                      if (point.X > l1.X - radius && point.X < l2.X + radius && point.Y > l1.Y - radius && point.Y < l2.Y + radius)
ebf4e3eed   nguyen_nam   Update Task 2045
2920
2921
2922
2923
2924
2925
                      {
                          falg = true;
                      }
                  }
                  else
                  {
0f3305e1d   doan   Update Task 2045
2926
                      if (point.X > l1.X - radius && point.X < l2.X + radius && point.Y < l1.Y + radius && point.Y > l2.Y - radius)
ebf4e3eed   nguyen_nam   Update Task 2045
2927
2928
2929
2930
2931
2932
2933
2934
2935
                      {
                          falg = true;
                      }
                  }
              }
              else
              {
                  if (l1.Y < l2.Y)
                  {
0f3305e1d   doan   Update Task 2045
2936
                      if (point.X < l1.X + radius && point.X > l2.X - radius && point.Y > l1.Y - radius && point.Y < l2.Y + radius)
ebf4e3eed   nguyen_nam   Update Task 2045
2937
2938
2939
2940
2941
2942
                      {
                          falg = true;
                      }
                  }
                  else
                  {
0f3305e1d   doan   Update Task 2045
2943
                      if (point.X < l1.X + radius && point.X > l2.X - radius && point.Y < l1.Y + radius && point.Y > l2.Y - radius)
ebf4e3eed   nguyen_nam   Update Task 2045
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
                      {
                          falg = true;
                      }
                  }
              }
              if (falg == false)
              {
                  return false;
              }
  
              distance = DistanceFromPointToLine(point, l1, l2);
  
              if (distance > radius)
              {
                  return false;
              }
              return true;
          }
  
          public static double DistanceFromPointToLine(Point point, Point l1, Point l2)
          {
fd7150b8b   doan   Update Task 2062
2965
              return Math.Abs((l2.X - l1.X) * (l1.Y - point.Y) - (l1.X - point.X) * (l2.Y - l1.Y)) /
ebf4e3eed   nguyen_nam   Update Task 2045
2966
2967
                      Math.Sqrt(Math.Pow(l2.X - l1.X, 2) + Math.Pow(l2.Y - l1.Y, 2));
          }
b338e1ff5   nguyen_nam   no message
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
          #endregion
  
          #region Schedule
  
          public void SetScheduleRoute()
          {
  
              EllipseGeometry ellipseGeometry_1;
              EllipseGeometry ellipseGeometry_2;
              Point node_1;
              Point node_2;
              Point node_Schedule = new Point();
80ae927f4   doan   no message
2980
2981
2982
2983
2984
2985
              //double x_1 = 50;
              //double y_1 = 80;
              //double Totaldistance = 1220;
              double x_1 = NodeSchedule_X;
              double y_1 = CanvasScheduleHeight / 2;
              double Totaldistance = CanvasScheduleWidth - NodeSchedule_X - NodeSchedule_X;
ef52277ed   doan   開発 #2045 : node の...
2986

b338e1ff5   nguyen_nam   no message
2987

ef52277ed   doan   開発 #2045 : node の...
2988
2989
2990
2991
              if (ucScheduleNode_Lst.Count > 0)
              {
                  for (int i = 0; i < ucScheduleNode_Lst.Count; i++)
                  {
a47f478f0   doan   開発 #2045 : node の...
2992
2993
2994
                      ucNode _ucScheduleNode = new ucNode();
                      _ucScheduleNode = ucScheduleNode_Lst[i];
                      scheduleCanvas.Children.Remove(_ucScheduleNode);
ef52277ed   doan   開発 #2045 : node の...
2995
2996
2997
2998
  
                  }
                  ucScheduleNode_Lst.Clear();
              }
b338e1ff5   nguyen_nam   no message
2999
3000
3001
  
              gGrpScheduleNode.Children.Clear();
              gGrpScheduleLine.Children.Clear();
5a5c5239e   nguyen_nam   Task: 2095
3002

1fe3e8a87   toan   RM2063 : Update s...
3003
              //Remove existed simulation
5db801240   doan   update 2099
3004
              if (scheduleCanvas.simulation != null)
1fe3e8a87   toan   RM2063 : Update s...
3005
3006
3007
              {
                  scheduleCanvas.Children.Remove(scheduleCanvas.simulation);
              }
b338e1ff5   nguyen_nam   no message
3008

b338e1ff5   nguyen_nam   no message
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
  
              List<double> distance = new List<double>();
              double addDistance;
  
              if (gGrpBlueNode.Children.Count > 0)
              {
                  for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
                  {
                      ellipseGeometry_2 = (EllipseGeometry)gGrpBlueNode.Children[i];
                      node_2 = ellipseGeometry_2.Center;
  
                      if (i >= 1)
                      {
                          ellipseGeometry_1 = (EllipseGeometry)gGrpBlueNode.Children[i - 1];
                          node_1 = ellipseGeometry_1.Center;
                          if (node_1.X == node_2.X)
                          {
                              addDistance = Math.Abs(node_1.Y - node_2.Y);
                              distance.Add(addDistance);
                          }
                          else if (node_1.Y == node_2.Y)
                          {
                              addDistance = Math.Abs(node_1.X - node_2.X);
                              distance.Add(addDistance);
                          }
                          else
                          {
                              var a = (double)(node_2.X - node_1.X);
                              var b = (double)(node_2.Y - node_1.Y);
                              addDistance = Math.Sqrt(a * a + b * b);
                              distance.Add(addDistance);
                          }
                      }
                  }
              }
              if (distance.Count > 0)
              {
                  double total = 0;
                  double distance_i;
  
                  for (int i = 0; i < distance.Count; i++)
                  {
                      total = total + distance[i];
                  }
  
                  for (int i = 0; i < distance.Count; i++)
                  {
                      distance_i = distance[i] * (Totaldistance / total);
                      distance[i] = distance_i;
                  }
              }
a47f478f0   doan   開発 #2045 : node の...
3060
3061
3062
3063
3064
3065
              if (gGrpBlueNode.Children.Count > 0)
              {
                  node_Schedule.X = x_1;
                  node_Schedule.Y = y_1;
                  AddNode(node_Schedule, gGrpScheduleNode);
              }
b338e1ff5   nguyen_nam   no message
3066

a9f21e725   doan   Update Task 2046
3067
              addDistance = x_1;
b338e1ff5   nguyen_nam   no message
3068
3069
              for (int i = 0; i < distance.Count; i++)
              {
ef52277ed   doan   開発 #2045 : node の...
3070
                  node_Schedule.Y = y_1;
b338e1ff5   nguyen_nam   no message
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
                  addDistance = addDistance + distance[i];
                  node_Schedule.X = addDistance;
                  AddNode(node_Schedule, gGrpScheduleNode);
              }
  
              if (gGrpScheduleNode.Children.Count > 0)
              {
                  for (int i = 0; i < gGrpScheduleNode.Children.Count; i++)
                  {
                      ellipseGeometry_1 = (EllipseGeometry)gGrpScheduleNode.Children[i];
                      node_1 = ellipseGeometry_1.Center;
                      if (i > 0)
                      {
fd7150b8b   doan   Update Task 2062
3084
                          ellipseGeometry_2 = (EllipseGeometry)gGrpScheduleNode.Children[i - 1];
b338e1ff5   nguyen_nam   no message
3085
3086
3087
                          node_2 = ellipseGeometry_2.Center;
                          DrawLine(node_1, node_2, gGrpScheduleLine);
                      }
d55d921a3   toan   2045: Draw Schedule
3088
                      CreateScheduleNode(node_1, i + 1);
b338e1ff5   nguyen_nam   no message
3089
3090
3091
                  }
              }
          }
d55d921a3   toan   2045: Draw Schedule
3092
3093
3094
          private void CreateScheduleNode(Point point, int indexNode)
          {
              ucNode _ucNode = new ucNode();
80ae927f4   doan   no message
3095
3096
              _ucNode.btnWidth = UCSCHEDULENODE_WIDTH;
              _ucNode.btnHeight = UCSCHEDULENODE_HEIGHT;
d55d921a3   toan   2045: Draw Schedule
3097
              _ucNode.txtNode = indexNode.ToString();
a47f478f0   doan   開発 #2045 : node の...
3098
              _ucNode.IsDragDelta = false;
80ae927f4   doan   no message
3099
3100
              Canvas.SetLeft(_ucNode, point.X - UCSCHEDULENODE_SETLEFT);
              Canvas.SetTop(_ucNode, point.Y - UCSCHEDULENODE_SETTOP);
d55d921a3   toan   2045: Draw Schedule
3101
              scheduleCanvas.Children.Add(_ucNode);
ef52277ed   doan   開発 #2045 : node の...
3102
              ucScheduleNode_Lst.Add(_ucNode);
d55d921a3   toan   2045: Draw Schedule
3103
          }
b338e1ff5   nguyen_nam   no message
3104
          #endregion
fd7150b8b   doan   Update Task 2062
3105
          #region Add Vehicle
5a5c5239e   nguyen_nam   Task: 2095
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
  
          public void GetIndexProject()
          {
              bool flag = false;
              if (ProjectModel.ProjectModelList.Count > 0)
              {
                  for (int i = 0; i < ProjectModel.ProjectModelList.Count; i++)
                  {
                      if (ProjectItem == ProjectModel.ProjectModelList[i].ProjectName)
                      {
                          ProjectIndex = i;
                          flag = true;
                      }
                  }
                  if (!flag)
                  {
                      ProjectIndex = ProjectModel.ProjectModelList.Count;
                  }
              }
              else
              {
                  ProjectIndex = 0;
              }
          }
fd7150b8b   doan   Update Task 2062
3130
3131
3132
          public void GetIndexVehicle()
          {
              bool flag = false;
5a5c5239e   nguyen_nam   Task: 2095
3133
3134
  
              if (ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList.Count > 0)
fd7150b8b   doan   Update Task 2062
3135
              {
5a5c5239e   nguyen_nam   Task: 2095
3136
                  for (int i = 0; i < ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList.Count; i++)
fd7150b8b   doan   Update Task 2062
3137
                  {
5a5c5239e   nguyen_nam   Task: 2095
3138
                      if (VehicleItem == ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[i].VehicleName)
fd7150b8b   doan   Update Task 2062
3139
3140
3141
3142
3143
                      {
                          VehicleIndex = i;
                          flag = true;
                      }
                  }
6312cbd86   doan   Task 2062
3144
                  if (!flag)
fd7150b8b   doan   Update Task 2062
3145
                  {
5a5c5239e   nguyen_nam   Task: 2095
3146
                      VehicleIndex = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList.Count;
fd7150b8b   doan   Update Task 2062
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
                  }
              }
              else
              {
                  VehicleIndex = 0;
              }
          }
  
          public void GetdataVehicle()
          {
01c8c8f49   doan   Update Task 2068
3157
              string NameNode = "";
fd7150b8b   doan   Update Task 2062
3158

5a5c5239e   nguyen_nam   Task: 2095
3159
              GetIndexProject();
fd7150b8b   doan   Update Task 2062
3160
              GetIndexVehicle();
5a5c5239e   nguyen_nam   Task: 2095
3161
              if (ProjectModel.ProjectModelList.Count > 0)
fd7150b8b   doan   Update Task 2062
3162
              {
fd7150b8b   doan   Update Task 2062
3163
3164
3165
3166
                  for (int i = 0; i < ucNode_Lst.Count; i++)
                  {
                      this.Children.Remove(ucNode_Lst[i]);
                  }
47aa77821   doan   Update task 2095
3167

fd7150b8b   doan   Update Task 2062
3168
3169
3170
                  gGrpNewLine.Children.Clear();
                  this.Children.Remove(pNewLine);
                  ucNode_Lst.Clear();
6312cbd86   doan   Task 2062
3171
                  Lst_Node_tmp.Clear();
fd7150b8b   doan   Update Task 2062
3172
3173
3174
3175
  
  
                  gGrpBlueNode.Children.Clear();
                  gGrpScheduleNode.Children.Clear();
6312cbd86   doan   Task 2062
3176
                  IndexNodeInsert_List.Clear();
01c8c8f49   doan   Update Task 2068
3177
                  NameNode_List.Clear();
fd7150b8b   doan   Update Task 2062
3178

5a5c5239e   nguyen_nam   Task: 2095
3179
                  if (VehicleIndex < ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList.Count)
fd7150b8b   doan   Update Task 2062
3180
                  {
47aa77821   doan   Update task 2095
3181
3182
3183
3184
3185
  
                      PointMapStart_X = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapStart_X;
                      PointMapStart_Y = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapStart_Y;
                      PointMapEnd_X = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapEnd_X;
                      PointMapEnd_Y = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapEnd_Y;
5a5c5239e   nguyen_nam   Task: 2095
3186
                      if (ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList.Count > 0)
fd7150b8b   doan   Update Task 2062
3187
                      {
5a5c5239e   nguyen_nam   Task: 2095
3188
                          for (int k = 0; k < ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList.Count; k++)
fd7150b8b   doan   Update Task 2062
3189
                          {
5db801240   doan   update 2099
3190
3191
                              double X = ConvertPointActualToDisplay(ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].pointMap_X, Scale_X, PointMapStart_X);
                              double Y = ConvertPointActualToDisplay(ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].pointMap_Y, Scale_Y, PointMapStart_Y);
5a5c5239e   nguyen_nam   Task: 2095
3192
                              NameNode = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].nameNode;
fd7150b8b   doan   Update Task 2062
3193
3194
3195
  
                              Point node = new Point(X, Y);
                              AddNode(node, gGrpBlueNode);
fd7150b8b   doan   Update Task 2062
3196

6312cbd86   doan   Task 2062
3197
                              //Get list Node Insert
5a5c5239e   nguyen_nam   Task: 2095
3198
                              if (ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].color == ColorNode_Insert)
6312cbd86   doan   Task 2062
3199
3200
3201
3202
3203
3204
                              {
                                  ListIndexNodeInsert ListIndex = new ListIndexNodeInsert();
                                  ListIndex.X = X;
                                  ListIndex.Y = Y;
                                  IndexNodeInsert_List.Add(ListIndex);
                              }
fd7150b8b   doan   Update Task 2062
3205

01c8c8f49   doan   Update Task 2068
3206
3207
3208
3209
3210
3211
                              //Get List Name Node
                              ListNameNode ListNamenode = new ListNameNode();
                              ListNamenode.X = X;
                              ListNamenode.Y = Y;
                              ListNamenode.nameNode = NameNode;
                              NameNode_List.Add(ListNamenode);
6312cbd86   doan   Task 2062
3212
3213
                              //Bind VehicleModel's NodeInfo to List Node Info temp
                              Node_tmp node_tmp = new Node_tmp();
5db801240   doan   update 2099
3214
                              node_tmp.pointMap_X = ConvertPointDisplayToActual(X, Scale_X, PointMapStart_X);
47aa77821   doan   Update task 2095
3215
                              node_tmp.pointMap_Y = ConvertPointDisplayToActual(Y, Scale_Y, PointMapStart_Y);
6312cbd86   doan   Task 2062
3216

5a5c5239e   nguyen_nam   Task: 2095
3217
                              foreach (ListNodeInfo tmp in ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].ListNodeInfo)
6312cbd86   doan   Task 2062
3218
3219
3220
3221
                              {
                                  node_tmp.NodeInfo_tmp.Add(tmp);
                              }
                              Lst_Node_tmp.Add(node_tmp);
5a5c5239e   nguyen_nam   Task: 2095
3222
3223
                              X = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].pointSchedule_X;
                              Y = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].pointSchedule_Y;
6312cbd86   doan   Task 2062
3224
                              node = new Point(X, Y);
fd7150b8b   doan   Update Task 2062
3225
                              AddNode(node, gGrpScheduleNode);
6312cbd86   doan   Task 2062
3226

5a5c5239e   nguyen_nam   Task: 2095
3227
                              NameNode = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[k].nameNode;
01c8c8f49   doan   Update Task 2068
3228

fd7150b8b   doan   Update Task 2062
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
                          }
                      }
                  }
              }
  
              BindBlueNode2ucNode();
  
              ReDrawAllNode();
  
              SetScheduleRoute();
6312cbd86   doan   Task 2062
3239
3240
3241
3242
3243
  
              NewDspRouteInfo();
  
              //Clear Route Info Table
              //((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Clear();
fd7150b8b   doan   Update Task 2062
3244
3245
3246
3247
3248
3249
3250
3251
          }
  
          public void CreateVehicleNode()
          {
              EllipseGeometry ellipseGeometry;
              Point node;
              ListNodeInfo ListNodeInfo = new ListNodeInfo();
              VehicleModelList VehicleModelList = new VehicleModelList();
6312cbd86   doan   Task 2062
3252
              bool NodeISInsert = false;
01c8c8f49   doan   Update Task 2068
3253
              string NameNode = "";
6312cbd86   doan   Task 2062
3254

5a5c5239e   nguyen_nam   Task: 2095
3255
              if (ProjectModel.ProjectModelList.Count == 0)
fd7150b8b   doan   Update Task 2062
3256
              {
5a5c5239e   nguyen_nam   Task: 2095
3257
3258
3259
3260
                  ProjectModelList ProjectModelList = new ProjectModelList();
                  ProjectModelList.ProjectName = ProjectItem;
                  ProjectModel.ProjectModelList.Add(ProjectModelList);
              }
5db801240   doan   update 2099
3261

5a5c5239e   nguyen_nam   Task: 2095
3262
3263
              if (ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList.Count > 0 && VehicleIndex < ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList.Count)
              {
47aa77821   doan   Update task 2095
3264
3265
3266
3267
3268
  
                  ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapStart_X = PointMapStart_X;
                  ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapStart_Y = PointMapStart_Y;
                  ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapEnd_X = PointMapEnd_X;
                  ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapEnd_Y = PointMapEnd_Y;
5a5c5239e   nguyen_nam   Task: 2095
3269
                  if (ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList.Count > 0)
fd7150b8b   doan   Update Task 2062
3270
                  {
5a5c5239e   nguyen_nam   Task: 2095
3271
                      ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList.Clear();
fd7150b8b   doan   Update Task 2062
3272
                  }
6312cbd86   doan   Task 2062
3273
3274
  
                  //back up
fd7150b8b   doan   Update Task 2062
3275
3276
3277
3278
                  if (gGrpBlueNode.Children.Count > 0)
                  {
                      for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
                      {
6312cbd86   doan   Task 2062
3279
                          NodeISInsert = false;
fd7150b8b   doan   Update Task 2062
3280
3281
3282
3283
                          ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
                          node = ellipseGeometry.Center;
  
                          PointMap pMap = new PointMap();
5db801240   doan   update 2099
3284
3285
                          pMap.pointMap_X = ConvertPointDisplayToActual(node.X, Scale_X, PointMapStart_X);
                          pMap.pointMap_Y = ConvertPointDisplayToActual(node.Y, Scale_Y, PointMapStart_Y);
57fdd8bb8   toan   RM2063 : Commit demo
3286
                          pMap.speed_Map = 1;
fd7150b8b   doan   Update Task 2062
3287

6312cbd86   doan   Task 2062
3288
                          //Backup List Node Insert of fork
5a5c5239e   nguyen_nam   Task: 2095
3289
                          if (IndexNodeInsert_List.Count > 0)
6312cbd86   doan   Task 2062
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
                          {
                              for (int j = 0; j < IndexNodeInsert_List.Count; j++)
                              {
                                  if (node.X == IndexNodeInsert_List[j].X && node.Y == IndexNodeInsert_List[j].Y) NodeISInsert = true;
                              }
                          }
                          if (NodeISInsert)
                          {
                              pMap.color = ColorNode_Insert;
                          }
                          else
                          {
                              pMap.color = ColorNode_Add;
                          }
01c8c8f49   doan   Update Task 2068
3304
3305
3306
3307
3308
3309
3310
3311
3312
                          //Backup Name Node for fork
                          if (NameNode_List.Count > 0)
                          {
                              for (int j = 0; j < NameNode_List.Count; j++)
                              {
                                  if (node.X == NameNode_List[j].X && node.Y == NameNode_List[j].Y) NameNode = NameNode_List[j].nameNode;
                              }
                          }
                          pMap.nameNode = NameNode;
fd7150b8b   doan   Update Task 2062
3313
3314
                          ellipseGeometry = (EllipseGeometry)gGrpScheduleNode.Children[i];
                          node = ellipseGeometry.Center;
6312cbd86   doan   Task 2062
3315
3316
                          pMap.pointSchedule_X = node.X;
                          pMap.pointSchedule_Y = node.Y;
1fe3e8a87   toan   RM2063 : Update s...
3317
                          pMap.speed_Schedule = 0.2; //Hard code
6312cbd86   doan   Task 2062
3318
3319
3320
3321
3322
  
                          //Node info
                          foreach (ListNodeInfo temp in Lst_Node_tmp[i].NodeInfo_tmp)
                          {
                              pMap.ListNodeInfo.Add(temp);
99c770eb8   nguyen_nam   Task 2062: Update
3323
3324
3325
  
                              //set tam
                              pMap.speed_Map = Lst_Node_tmp[i].NodeInfo_tmp[0].Speed;
6312cbd86   doan   Task 2062
3326
                          }
5a5c5239e   nguyen_nam   Task: 2095
3327
                          ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList.Add(pMap);
fd7150b8b   doan   Update Task 2062
3328

fd7150b8b   doan   Update Task 2062
3329
3330
                      }
                  }
fd7150b8b   doan   Update Task 2062
3331
              }
6312cbd86   doan   Task 2062
3332
              // create new
fd7150b8b   doan   Update Task 2062
3333
3334
3335
              else
              {
                  VehicleModelList.VehicleName = VehicleItem;
47aa77821   doan   Update task 2095
3336
3337
3338
3339
                  VehicleModelList.pointMapStart_X = PointMapStart_X;
                  VehicleModelList.pointMapStart_Y = PointMapStart_Y;
                  VehicleModelList.pointMapEnd_X = PointMapEnd_X;
                  VehicleModelList.pointMapEnd_Y = PointMapEnd_Y;
fd7150b8b   doan   Update Task 2062
3340
3341
3342
3343
3344
  
                  if (gGrpBlueNode.Children.Count > 0)
                  {
                      for (int i = 0; i < gGrpBlueNode.Children.Count; i++)
                      {
6312cbd86   doan   Task 2062
3345
                          NodeISInsert = false;
fd7150b8b   doan   Update Task 2062
3346
3347
3348
3349
                          ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i];
                          node = ellipseGeometry.Center;
  
                          PointMap pMap = new PointMap();
47aa77821   doan   Update task 2095
3350
3351
                          pMap.pointMap_X = ConvertPointDisplayToActual(node.X, Scale_X, PointMapStart_X);
                          pMap.pointMap_Y = ConvertPointDisplayToActual(node.Y, Scale_Y, PointMapStart_Y);
57fdd8bb8   toan   RM2063 : Commit demo
3352
                          pMap.speed_Map = 1;
fd7150b8b   doan   Update Task 2062
3353

01c8c8f49   doan   Update Task 2068
3354
                          //Backup List Node Insert of fork
6312cbd86   doan   Task 2062
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
                          if (IndexNodeInsert_List.Count > 0)
                          {
                              for (int j = 0; j < IndexNodeInsert_List.Count; j++)
                              {
                                  if (node.X == IndexNodeInsert_List[j].X && node.Y == IndexNodeInsert_List[j].Y) NodeISInsert = true;
                              }
                          }
                          if (NodeISInsert)
                          {
                              pMap.color = ColorNode_Insert;
                          }
                          else
                          {
                              pMap.color = ColorNode_Add;
                          }
01c8c8f49   doan   Update Task 2068
3370
3371
3372
3373
3374
3375
3376
3377
3378
                          //Backup Name Node for fork
                          if (NameNode_List.Count > 0)
                          {
                              for (int j = 0; j < NameNode_List.Count; j++)
                              {
                                  if (node.X == NameNode_List[j].X && node.Y == NameNode_List[j].Y) NameNode = NameNode_List[j].nameNode;
                              }
                          }
                          pMap.nameNode = NameNode;
6312cbd86   doan   Task 2062
3379
3380
3381
3382
3383
                          //Node info
                          foreach (ListNodeInfo temp in Lst_Node_tmp[i].NodeInfo_tmp)
                          {
                              pMap.ListNodeInfo.Add(temp);
                          }
fd7150b8b   doan   Update Task 2062
3384
3385
                          ellipseGeometry = (EllipseGeometry)gGrpScheduleNode.Children[i];
                          node = ellipseGeometry.Center;
6312cbd86   doan   Task 2062
3386
3387
                          pMap.pointSchedule_X = node.X;
                          pMap.pointSchedule_Y = node.Y;
1fe3e8a87   toan   RM2063 : Update s...
3388
                          pMap.speed_Schedule = 0.2; //Hard code
fd7150b8b   doan   Update Task 2062
3389

6312cbd86   doan   Task 2062
3390
                          VehicleModelList.pointMapList.Add(pMap);
fd7150b8b   doan   Update Task 2062
3391
3392
                      }
                  }
5a5c5239e   nguyen_nam   Task: 2095
3393
                  ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList.Add(VehicleModelList);
fd7150b8b   doan   Update Task 2062
3394
3395
3396
              }
          }
          #endregion
867826ac5   doan   Update Task 2046
3397
3398
3399
3400
          #region Read file Mapfan
  
          public void ReadFile()
          {
47aa77821   doan   Update task 2095
3401
3402
              //Point node;
              bool line1 = true;
867826ac5   doan   Update Task 2046
3403
3404
3405
3406
3407
3408
              string[] lines = System.IO.File.ReadAllLines(@"Mapfan\MapFan.index");
  
              foreach (string line in lines)
              {
                  // Use a tab to indent each line of the file.
                  string[] tmp = line.Split('\t');
47aa77821   doan   Update task 2095
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
                  if (line1)
                  {
                      PointMapStart_X = Double.Parse(tmp[1]);
                      PointMapStart_Y = Double.Parse(tmp[3]);
                      line1 = false;
                  }
                  else
                  {
                      PointMapEnd_X = Double.Parse(tmp[1]);
                      PointMapEnd_Y = Double.Parse(tmp[3]);
                  }
                  //double lat = ConvertPointActualToDisplay(Double.Parse(tmp[1]),Scale_X,PointMapStart_X);
                  //double log = ConvertPointActualToDisplay(Double.Parse(tmp[3]),Scale_Y,PointMapStart_Y);
867826ac5   doan   Update Task 2046
3422

47aa77821   doan   Update task 2095
3423
                  //node = new Point(lat, log);
867826ac5   doan   Update Task 2046
3424

47aa77821   doan   Update task 2095
3425
3426
                  //execCreateNode(node);
                  ////AddNode(node, gGrpBlueNode);
867826ac5   doan   Update Task 2046
3427
3428
3429
  
  
              }
47aa77821   doan   Update task 2095
3430
              getScaleMap();
867826ac5   doan   Update Task 2046
3431

47aa77821   doan   Update task 2095
3432
              //SetScheduleRoute();
a9f21e725   doan   Update Task 2046
3433
              ReDrawAllNode2();
01c8c8f49   doan   Update Task 2068
3434
3435
  
              readMapFan = false;
47aa77821   doan   Update task 2095
3436
3437
              ////backup DB
              //CreateVehicleNode();
867826ac5   doan   Update Task 2046
3438
          }
a9f21e725   doan   Update Task 2046
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
          public void ReDrawAllNode2()
          {
              LineGeometry lineGeometry = new LineGeometry();
              EllipseGeometry ellip;
              //delete all line
              gGrpScheduleLine.Children.Clear();
              scheduleCanvas.Children.Remove(pScheduleLine);
  
              //redraw line
              for (int j = 0; j < gGrpScheduleNode.Children.Count - 1; j++)
              {
                  ellip = (EllipseGeometry)gGrpScheduleNode.Children[j];
                  Point node1 = ellip.Center;
                  ellip = (EllipseGeometry)gGrpScheduleNode.Children[j + 1];
                  Point node2 = ellip.Center;
                  DrawLine(node1, node2, gGrpScheduleLine);
              }
  
              scheduleCanvas.Children.Add(pScheduleLine);
  
  
              //redraw ucNode
              for (int k = 0; k < ucScheduleNode_Lst.Count; k++)
              {
                  scheduleCanvas.Children.Remove(ucScheduleNode_Lst[k]);
                  scheduleCanvas.Children.Add(ucScheduleNode_Lst[k]);
              }
  
              ////backup DB
              //CreateVehicleNode();
          }
867826ac5   doan   Update Task 2046
3470
          #endregion
de8826297   toan   RM2077: Edit source
3471
          #region Get data from AWS
e3ae88363   toan   RM2077: Commit so...
3472
3473
3474
3475
3476
3477
3478
3479
3480
          // Get info fork
          public void GetInfoFork()
          {
              var service = new Fork2PCTableService();
              /*Read*/
              IEnumerable<Fork2PC> fork2PCs = service.GetAllFork2PCs().Where(x => x.ForkID == 1);
              if (fork2PCs.Count() == 0)
                  return;
              var fork2PC = fork2PCs.ElementAt(0);
01c8c8f49   doan   Update Task 2068
3481

e3ae88363   toan   RM2077: Commit so...
3482
3483
              //Clear Route Info Table
              ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Clear();
01c8c8f49   doan   Update Task 2068
3484

d7d5faa7d   nguyen_nam   Task 2100
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
  //int _RowIdx = 0;
              //AddLabeltoGrid(_RowIdx, 0, "ID");
              //AddLabeltoGrid(_RowIdx, 1, fork2PC.ForkID.ToString());
              //_RowIdx++;
              //AddLabeltoGrid(_RowIdx, 0, "LAT");
              //AddLabeltoGrid(_RowIdx, 1, fork2PC.ForkPos_x.ToString());
              //_RowIdx++;
              //AddLabeltoGrid(_RowIdx, 0, "LOC");
              //AddLabeltoGrid(_RowIdx, 1, fork2PC.ForkPos_y.ToString());
              //_RowIdx++;
              //AddLabeltoGrid(_RowIdx, 0, "SPD");
              //AddLabeltoGrid(_RowIdx, 1, fork2PC.spd_veh.ToString() + "Km/h");
              //_RowIdx++;
              //AddLabeltoGrid(_RowIdx, 0, "GPS");
              //AddLabeltoGrid(_RowIdx, 1, fork2PC.GPS_data);
e3ae88363   toan   RM2077: Commit so...
3500
              int _RowIdx = 0;
d7d5faa7d   nguyen_nam   Task 2100
3501
              AddLabeltoViewer(_RowIdx, 0, "LAT " + fork2PC.ForkPos_x.ToString());
e3ae88363   toan   RM2077: Commit so...
3502
              _RowIdx++;
d7d5faa7d   nguyen_nam   Task 2100
3503
              AddLabeltoViewer(_RowIdx, 0, "LOC " + fork2PC.ForkPos_y.ToString());
e3ae88363   toan   RM2077: Commit so...
3504
              _RowIdx++;
d7d5faa7d   nguyen_nam   Task 2100
3505
              AddLabeltoViewer(_RowIdx, 0, "SPD " + fork2PC.spd_veh.ToString() + "Km/h");
e3ae88363   toan   RM2077: Commit so...
3506
              _RowIdx++;
d7d5faa7d   nguyen_nam   Task 2100
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
  
              //Point point = new Point();
              //point.X = fork2PC.ForkPos_x;
              //point.Y = fork2PC.ForkPos_y;
  
              //RoboSimulation(point, point);
              
              //this.Children.Remove(pRedNode);
              //gGrpRedNode.Children.Clear();
  
  
              double d_X, d_Y;
              //d_X = ConvertPointActualToDisplay(127.8580065145, Scale_X, PointMapStart_X);
              //d_Y = ConvertPointActualToDisplay(26.33570065464, Scale_X, PointMapStart_Y);
              d_X = ConvertPointActualToDisplay(fork2PC.ForkPos_x, Scale_X, PointMapStart_X);
              d_Y = ConvertPointActualToDisplay(fork2PC.ForkPos_y, Scale_X, PointMapStart_Y);
              AddNode(new Point(d_X, d_Y), gGrpRedNode);
              //this.Children.Remove(pRedNode);
  
              NewDspWorkLog();
  
              //column 1 : node index
              //string _Content = "";
              //int _Row = 0;
              //_Content = (Lst_Node_tmp.Count - i).ToString();
              //AddLabeltoWorkLog(_Row, 0, _Content);
  
              //column 2
              //Fork Name
              //_Content = VehicleItem + " TIME " + Lst_Node_tmp[i].timeStamp;
              //AddLabeltoWorkLog(_Row, 1, _Content);
              //_Row++;
  
              // Display Node's Position
              //_Content = "LAT " + Lst_Node_tmp[i].pointMap_X;
              //AddLabeltoWorkLog(_Row, 1, _Content);
              //_Row++;
  
              //_Content = "LOC " + Lst_Node_tmp[i].pointMap_Y;
              //AddLabeltoWorkLog(_Row, 1, _Content);
  
              // Display Node's Field
  
              //if (Lst_Node_tmp[i].NodeInfo_tmp.Count != 0)
              //{
              //    foreach (ListNodeInfo ni in Lst_Node_tmp[i].NodeInfo_tmp)
              //    {
              //        if (ni.Speed != 0 && ni.ModeSelected == 1)
              //        {
              //            _Row++;
              //            _Content = "SPD " + ni.Speed.ToString() + " Km/h";
              //            AddLabeltoWorkLog(_RowIdx, 1, _Content);
              //        }
              //    }
  
              //}
              //_RowIdx++;
          }
  
  
         /// <summary>
          /// Create robo simulation on line
          /// </summary>
          public simulationRobo simulation;
          private void RoboSimulation(Point start, Point end)
          {
             
              simulation = new simulationRobo();
              simulation.storyBoard = CreatPathAnimation(start, end, 1);
              this.Children.Add(simulation);
e3ae88363   toan   RM2077: Commit so...
3577
3578
3579
          }
  
          /// <summary>
d7d5faa7d   nguyen_nam   Task 2100
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
          /// Get storyboard
          /// </summary>
          /// <param name="startPoint">Point start line</param>
          /// <param name="endPoit">Point end line</param>
          /// <param name="speed">speed on line</param>
          /// <returns>Storyboard</returns>
          private Storyboard CreatPathAnimation(Point startPoint, Point endPoit, double speed)
          {
              PathGeometry animationPath = new PathGeometry();
              PathFigure pFigure = new PathFigure();
              pFigure.StartPoint = startPoint; //new Point(50, 65);
              LineSegment lineSegment = new LineSegment();
              lineSegment.Point = endPoit; // new Point(800, 65);
              pFigure.Segments.Add(lineSegment);
              animationPath.Figures.Add(pFigure);
  
              // Freeze the PathGeometry for performance benefits.
              animationPath.Freeze();
  
              // Create a MatrixAnimationUsingPath to move the
              // simulation along the path by animating
              // its MatrixTransform.
              MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();
              matrixAnimation.PathGeometry = animationPath;
              matrixAnimation.SpeedRatio = speed;
              matrixAnimation.AutoReverse = false;
              matrixAnimation.DoesRotateWithTangent = true;
              //matrixAnimation.Completed += delegate { AnimationCompleted(this._isGoal); };
  
              // Set the animation to target the Matrix property
              // of the MatrixTransform named "ButtonMatrixTransform".
              Storyboard.SetTargetName(matrixAnimation, "fl");
              Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty));
  
              // Create a Storyboard to contain and apply the animation.
              Storyboard pathAnimationStoryboard = new Storyboard();
              pathAnimationStoryboard.Children.Add(matrixAnimation);
  
              return pathAnimationStoryboard;
          }
  
  
          
  
  
  
  
          /// <summary>
e3ae88363   toan   RM2077: Commit so...
3628
3629
          /// Get infor node
          /// </summary>
e658bdccd   toan   RM2101 comit source
3630
3631
3632
3633
3634
3635
3636
3637
          public void UploadData()
          {
              if (ucNode_Lst.Count < 1)
                  return;
  
              Robofork15DemoService service = new Robofork15DemoService();
              for (int i = 0; i < ucNode_Lst.Count; i++)
              {
886851415   toan   RM2101 : Commit s...
3638
3639
3640
3641
3642
3643
                  ListNodeInfo InputNodeInfo = new ListNodeInfo();
                  for (int m = 0; m < ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[i].ListNodeInfo.Count; m++)
                  {
                      if (ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[i].ListNodeInfo[m].ModeSelected == 1)
                          InputNodeInfo = ProjectModel.ProjectModelList[ProjectIndex].VehicleModelList[VehicleIndex].pointMapList[i].ListNodeInfo[m];
                  }
e658bdccd   toan   RM2101 comit source
3644
3645
3646
3647
3648
                  Robofork15Demo node = new Robofork15Demo();
                  ucNode _ucScheduleNode = new ucNode();
                  _ucScheduleNode = ucNode_Lst[i];
                  node.NodeID = i + 1;
                  node.ForkNo = 1;
886851415   toan   RM2101 : Commit s...
3649
3650
3651
3652
3653
                  node.NodePos_x = ConvertPointDisplayToActual(Canvas.GetLeft(_ucScheduleNode) + UCNODE_SETLEFT, Scale_X, PointMapStart_X);
                  node.NodePos_y = ConvertPointDisplayToActual(Canvas.GetTop(_ucScheduleNode) + UCNODE_SETTOP, Scale_X, PointMapStart_Y);
                  node.NodeLftHeight = InputNodeInfo.Height;
                  node.NodeVehAng = InputNodeInfo.Angle;
                  node.NodeVehSpd = InputNodeInfo.Speed;
e658bdccd   toan   RM2101 comit source
3654
                  service.AddRobofork15Demo(node);
dae7878f9   nguyen_nam   Task 2100
3655
3656
3657
3658
3659
3660
3661
  
                  DateTime dt = DateTime.Now;
  
                  string format = "M:dd HH:mm:ss";   // Use this format.
                  string _timeStamp = dt.ToString(format);
  
                  Lst_Node_tmp[i].timeStamp = _timeStamp;
e658bdccd   toan   RM2101 comit source
3662
              }
d7d5faa7d   nguyen_nam   Task 2100
3663
3664
              //NewDspWorkLog();
              //NewDspViewer();
dae7878f9   nguyen_nam   Task 2100
3665

e658bdccd   toan   RM2101 comit source
3666
3667
3668
3669
3670
              IEnumerable<Robofork15Demo> nodes = service.GetAllRobofork15Demos().Where(x => x.ForkNo == 1).OrderBy(x => x.NodeID);
  
              // Delete node
              if (ucNode_Lst.Count() == nodes.Count())
              {
886851415   toan   RM2101 : Commit s...
3671
                  //GetInfoNode();
e658bdccd   toan   RM2101 comit source
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
                  return;
              }
  
              for (int i = ucNode_Lst.Count(); i < nodes.Count(); i++)
              {
                  Robofork15Demo node = new Robofork15Demo();
                  node = nodes.ElementAt(i);
                  service.DeleteRobofork15Demo(node);
              }
          }
  
          /// <summary>
          /// Get infor node
          /// </summary>
e3ae88363   toan   RM2077: Commit so...
3686
3687
3688
          public void GetInfoNode()
          {
              var service = new Robofork15DemoService();
e658bdccd   toan   RM2101 comit source
3689
3690
  
              readMapFan = true;
e3ae88363   toan   RM2077: Commit so...
3691
              /*Read*/
e658bdccd   toan   RM2101 comit source
3692
              IEnumerable<Robofork15Demo> nodes = service.GetAllRobofork15Demos().Where(x => x.ForkNo == 1).OrderBy(x => x.NodeID);
e3ae88363   toan   RM2077: Commit so...
3693
3694
  
              //Clear Route Info Table
886851415   toan   RM2101 : Commit s...
3695
              //((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Clear();
e3ae88363   toan   RM2077: Commit so...
3696
3697
3698
  
              // Process clear canvas
              ClearCanvas();
e658bdccd   toan   RM2101 comit source
3699
3700
              //int _RowIdx = 0;
              foreach (var node in nodes)
e3ae88363   toan   RM2077: Commit so...
3701
              {
886851415   toan   RM2101 : Commit s...
3702
                  execCreateNode(new Point(ConvertPointActualToDisplay(node.NodePos_x, Scale_X, PointMapStart_X)
5f640f9b1   doan   Update Task 2095
3703
                                          , ConvertPointActualToDisplay(node.NodePos_y, Scale_Y, PointMapStart_Y)));
e658bdccd   toan   RM2101 comit source
3704

886851415   toan   RM2101 : Commit s...
3705
                  //execCreateNode(new Point(node.NodePos_x, node.NodePos_y));
e3ae88363   toan   RM2077: Commit so...
3706
              }
e658bdccd   toan   RM2101 comit source
3707

886851415   toan   RM2101 : Commit s...
3708
3709
              if (!isReloadDB)
                  CreateVehicleNode();
e3ae88363   toan   RM2077: Commit so...
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
          }
  
          /// <summary>
          /// Clear all data on canvas
          /// </summary>
          public void ClearCanvas()
          {
              // Clear data on designer canvas
              for (int i = 0; i < ucNode_Lst.Count; i++)
              {
                  this.Children.Remove(ucNode_Lst[i]);
              }
  
              gGrpNewLine.Children.Clear();
              this.Children.Remove(pNewLine);
              ucNode_Lst.Clear();
              Lst_Node_tmp.Clear();
  
              gGrpBlueNode.Children.Clear();
              gGrpScheduleNode.Children.Clear();
              IndexNodeInsert_List.Clear();
  
              // Clear data on schedule canvas
              if (ucScheduleNode_Lst.Count > 0)
              {
                  for (int i = 0; i < ucScheduleNode_Lst.Count; i++)
                  {
                      ucNode _ucScheduleNode = new ucNode();
                      _ucScheduleNode = ucScheduleNode_Lst[i];
                      scheduleCanvas.Children.Remove(_ucScheduleNode);
  
                  }
                  ucScheduleNode_Lst.Clear();
              }
              gGrpScheduleNode.Children.Clear();
              gGrpScheduleLine.Children.Clear();
          }
de8826297   toan   RM2077: Edit source
3747
          #endregion
5a5c5239e   nguyen_nam   Task: 2095
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
  
          #region Add new Project
          public void AddNewProjectItem()
          {
              ProjectModelList ProjectModelList = new ProjectModelList();
              ProjectModelList.ProjectName = ProjectItem;
  
              ProjectModel.ProjectModelList.Add(ProjectModelList);
          }
  
          #endregion
47aa77821   doan   Update task 2095
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
  
          #region get scale map
  
          public void getScaleMap()
          {
              Scale_X = ConvertScaleMap(PointMapEnd_X - PointMapStart_X, DISTANCEMAPDISPLAY);
              Scale_Y = ConvertScaleMap(PointMapEnd_Y - PointMapStart_Y, DISTANCEMAPDISPLAY);
          }
  
          public double ConvertScaleMap(double distance, double const1000)
          {
              return distance / const1000;
          }
  
          public double ConvertPointDisplayToActual(double x, double scale, double pointStart)
          {
              return pointStart + x * scale;
          }
  
          public double ConvertPointActualToDisplay(double x, double scale, double pointStart)
          {
5db801240   doan   update 2099
3780
              return (x - pointStart) / scale;
47aa77821   doan   Update task 2095
3781
3782
          }
          #endregion
d7d5faa7d   nguyen_nam   Task 2100
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
          
  
  
          #region Viewer
          public void NewDspViewer()
          {
              //Clear Route Info Table
              ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdViewer.Children.Clear();
              int _RowIdx = 0;
              string _Content = "";
  
              if (Lst_Node_tmp.Count != 0)
              {
                  //for (int i = Lst_Node_tmp.Count - 1; i > 0; i--)
                  //{
                  int i=0;
                      // Display Node's Position
                      _Content = "LAT " + Lst_Node_tmp[i].pointMap_X;
                      AddLabeltoViewer(_RowIdx, 0, _Content);
                      _RowIdx++;
  
                      _Content = "LOC " + Lst_Node_tmp[i].pointMap_Y;
                      AddLabeltoViewer(_RowIdx, 0, _Content);
  
                      // Display Node's Field
  
                      if (Lst_Node_tmp[i].NodeInfo_tmp.Count != 0)
                      {
                          foreach (ListNodeInfo ni in Lst_Node_tmp[i].NodeInfo_tmp)
                          {
                              if (ni.Speed != 0 && ni.ModeSelected == 1)
                              {
                                  _RowIdx++;
                                  _Content = "SPEED " + ni.Speed.ToString() + " Km/h";
                                  AddLabeltoViewer(_RowIdx, 1, _Content);
                              }
                              if (ni.Angle != 0 )
                              {
                                  _RowIdx++;
                                  _Content = "ANGLE " + ni.Angle.ToString();
                                  AddLabeltoViewer(_RowIdx, 1, _Content);
                              }
                              if (ni.Height != 0 )
                              {
                                  _RowIdx++;
                                  _Content = "HEIGHT " + ni.Height.ToString() + " mm";
                                  AddLabeltoViewer(_RowIdx, 1, _Content);
                              }
                          }
  
                      }
                      _RowIdx++;
                  //}
  
              }
  
          }
  
          public void AddLabeltoViewer(int RowIdx, int ColIdx, string Content)
          {
              //Add Row to Grid
              RowDefinition _rd = new RowDefinition();
              ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdViewer.RowDefinitions.Add(_rd);
  
              // Add data to Grid
              Label dynamicLabel = new Label();
  
              dynamicLabel.Content = Content;
              dynamicLabel.Margin = new Thickness(0, 0, 0, 0);
              dynamicLabel.Foreground = new SolidColorBrush(Colors.Black);
              dynamicLabel.Background = new SolidColorBrush(Colors.White);
              dynamicLabel.BorderBrush = new SolidColorBrush(Colors.LightGray);
              dynamicLabel.BorderThickness = new Thickness(1);
  
              Grid.SetRow(dynamicLabel, RowIdx);
              Grid.SetColumn(dynamicLabel, ColIdx);
              ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdViewer.Children.Add(dynamicLabel);
          }
  
  
          #endregion
729be9a6d   doan   New Project
3864
3865
      }
  }