Commit 2a6e970981e1ecec572a83be5e46c8c6f6971d66

Authored by doan
Exists in master

Merge branch 'master' of http://timesfun.net/toan/robofork

Showing 3 changed files Side-by-side Diff

sources/RoboforkApp/Controls/DesignerCanvas.cs
... ... @@ -94,7 +94,7 @@
94 94 List<NewNodeInfo> NewNodeInfo_List = new List<NewNodeInfo>();
95 95 List<TextBlock> NodeNo = new List<TextBlock>();
96 96 List<ucNode> ucNode_Lst = new List<ucNode>();
97   - List<ucNode> ucScheduleNode_Lst = new List<ucNode>();
  97 + public List<ucNode> ucScheduleNode_Lst = new List<ucNode>();
98 98 int stt = 1;
99 99 //2017/03/04 NAM ADD END
100 100  
sources/RoboforkApp/Controls/ScheduleCanvas.cs
... ... @@ -13,20 +13,69 @@
13 13 {
14 14 public class ScheduleCanvas : Canvas
15 15 {
16   - //private simulationRobo simulation;
  16 + const double COOR_Y = 65;
  17 + const double RADIUS_NODE = 25;
  18 + private simulationRobo simulation;
  19 + private Point startPoint;
  20 + private Point endPoint;
  21 + private bool _isGoal = false;
  22 + private double _speed = 0.2; //Now _speed is fixed, but when update node
  23 + private int index;
17 24  
18   - public void CreateSimulation()
  25 + private List<ucNode> _lstNode;
  26 +
  27 + /// <summary>
  28 + /// Create simulation
  29 + /// </summary>
  30 + /// <param name="lstNode"></param>
  31 + public void CreateSimulation(List<ucNode> lstNode)
19 32 {
20   - //if(simulation != null || this.Children.Count < 2)
21   - //{
22   - // return;
23   - //}
  33 + //If node is less than 2 so return
  34 + if (this.Children.Count < 2)
  35 + {
  36 + return;
  37 + }
24 38  
  39 + this.Children.Remove(simulation);
  40 +
  41 + //Init data
  42 + this._lstNode = lstNode;
  43 + this.startPoint = new Point(Canvas.GetLeft(_lstNode[index]) + RADIUS_NODE, COOR_Y);
  44 + this.endPoint = new Point(Canvas.GetLeft(_lstNode[index + 1]) + RADIUS_NODE, COOR_Y);
  45 + this.index += 1;
  46 + if (index == _lstNode.Count - 1)
  47 + {
  48 + _isGoal = true;
  49 + }
  50 +
  51 + // Start simulation
  52 + RoboSimulation();
  53 + }
  54 +
  55 + /// <summary>
  56 + /// Create robo simulation on line
  57 + /// </summary>
  58 + private void RoboSimulation()
  59 + {
  60 + simulation = new simulationRobo();
  61 + simulation.storyBoard = CreatPathAnimation(startPoint, endPoint, _speed); //pathAnimationStoryboard;
  62 + this.Children.Add(simulation);
  63 + }
  64 +
  65 + /// <summary>
  66 + /// Get storyboard
  67 + /// </summary>
  68 + /// <param name="startPoint">Point start line</param>
  69 + /// <param name="endPoit">Point end line</param>
  70 + /// <param name="speed">speed on line</param>
  71 + /// <returns>Storyboard</returns>
  72 + private Storyboard CreatPathAnimation(Point startPoint, Point endPoit, double speed)
  73 + {
25 74 PathGeometry animationPath = new PathGeometry();
26 75 PathFigure pFigure = new PathFigure();
27   - pFigure.StartPoint = new Point(50, 65);
  76 + pFigure.StartPoint = startPoint; //new Point(50, 65);
28 77 LineSegment lineSegment = new LineSegment();
29   - lineSegment.Point = new Point(1270, 65);
  78 + lineSegment.Point = endPoit; // new Point(800, 65);
30 79 pFigure.Segments.Add(lineSegment);
31 80 animationPath.Figures.Add(pFigure);
32 81  
33 82  
34 83  
... ... @@ -34,14 +83,14 @@
34 83 animationPath.Freeze();
35 84  
36 85 // Create a MatrixAnimationUsingPath to move the
37   - // button along the path by animating
  86 + // simulation along the path by animating
38 87 // its MatrixTransform.
39 88 MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();
40 89 matrixAnimation.PathGeometry = animationPath;
41   - matrixAnimation.Duration = TimeSpan.FromSeconds(10);
42   - //matrixAnimation.RepeatBehavior = RepeatBehavior.Forever;
  90 + matrixAnimation.SpeedRatio = speed;
43 91 matrixAnimation.AutoReverse = false;
44 92 matrixAnimation.DoesRotateWithTangent = true;
  93 + matrixAnimation.Completed += delegate { AnimationCompleted(this._isGoal); };
45 94  
46 95 // Set the animation to target the Matrix property
47 96 // of the MatrixTransform named "ButtonMatrixTransform".
... ... @@ -52,9 +101,36 @@
52 101 Storyboard pathAnimationStoryboard = new Storyboard();
53 102 pathAnimationStoryboard.Children.Add(matrixAnimation);
54 103  
55   - //simulation = new simulationRobo();
56   - //simulation.storyBoard = pathAnimationStoryboard;
57   - //this.Children.Add(simulation);
  104 + return pathAnimationStoryboard;
  105 + }
  106 +
  107 + /// <summary>
  108 + /// Process when simulation is end line
  109 + /// </summary>
  110 + /// <param name="isGoal">check is node end</param>
  111 + private void AnimationCompleted(bool isGoal)
  112 + {
  113 + // If not end node
  114 + if (!isGoal)
  115 + {
  116 + this.index += 1;
  117 + this.Children.Remove(simulation);
  118 + this.startPoint = endPoint;
  119 + this.endPoint = new Point(Canvas.GetLeft(_lstNode[index]) + RADIUS_NODE, COOR_Y);
  120 +
  121 + if (this.index == this._lstNode.Count - 1)
  122 + {
  123 + this._isGoal = true;
  124 + }
  125 + this._speed += 0.2;
  126 + RoboSimulation();
  127 + return;
  128 + }
  129 +
  130 + // Reset data when finish
  131 + this.index = 0;
  132 + this._speed = 0.2;
  133 + this._isGoal = false;
58 134 }
59 135 }
60 136 }
sources/RoboforkApp/RoboforkMenuView.xaml.cs
... ... @@ -148,7 +148,7 @@
148 148  
149 149 private void DoBeginTask()
150 150 {
151   - MyScheduleCanvas.CreateSimulation();
  151 + MyScheduleCanvas.CreateSimulation(MyDesignerCanvas.ucScheduleNode_Lst);
152 152 }
153 153  
154 154 private void DoBeginSetAutoNotes()