diff --git a/sources/RoboforkApp/Controls/DesignerCanvas.cs b/sources/RoboforkApp/Controls/DesignerCanvas.cs index 9130581..ff14150 100644 --- a/sources/RoboforkApp/Controls/DesignerCanvas.cs +++ b/sources/RoboforkApp/Controls/DesignerCanvas.cs @@ -89,7 +89,7 @@ namespace RoboforkApp List NewNodeInfo_List = new List(); List NodeNo = new List(); List ucNode_Lst = new List(); - List ucScheduleNode_Lst = new List(); + public List ucScheduleNode_Lst = new List(); int stt = 1; //2017/03/04 NAM ADD END diff --git a/sources/RoboforkApp/Controls/ScheduleCanvas.cs b/sources/RoboforkApp/Controls/ScheduleCanvas.cs index 7d6ac2f..1e0df40 100644 --- a/sources/RoboforkApp/Controls/ScheduleCanvas.cs +++ b/sources/RoboforkApp/Controls/ScheduleCanvas.cs @@ -13,20 +13,69 @@ namespace RoboforkApp { public class ScheduleCanvas : Canvas { - //private simulationRobo simulation; + const double COOR_Y = 65; + const double RADIUS_NODE = 25; + private simulationRobo simulation; + private Point startPoint; + private Point endPoint; + private bool _isGoal = false; + private double _speed = 0.2; //Now _speed is fixed, but when update node + private int index; - public void CreateSimulation() + private List _lstNode; + + /// + /// Create simulation + /// + /// + public void CreateSimulation(List lstNode) { - //if(simulation != null || this.Children.Count < 2) - //{ - // return; - //} + //If node is less than 2 so return + if (this.Children.Count < 2) + { + return; + } + + this.Children.Remove(simulation); + //Init data + this._lstNode = lstNode; + this.startPoint = new Point(Canvas.GetLeft(_lstNode[index]) + RADIUS_NODE, COOR_Y); + this.endPoint = new Point(Canvas.GetLeft(_lstNode[index + 1]) + RADIUS_NODE, COOR_Y); + this.index += 1; + if (index == _lstNode.Count - 1) + { + _isGoal = true; + } + + // Start simulation + RoboSimulation(); + } + + /// + /// Create robo simulation on line + /// + private void RoboSimulation() + { + simulation = new simulationRobo(); + simulation.storyBoard = CreatPathAnimation(startPoint, endPoint, _speed); //pathAnimationStoryboard; + this.Children.Add(simulation); + } + + /// + /// Get storyboard + /// + /// Point start line + /// Point end line + /// speed on line + /// Storyboard + private Storyboard CreatPathAnimation(Point startPoint, Point endPoit, double speed) + { PathGeometry animationPath = new PathGeometry(); PathFigure pFigure = new PathFigure(); - pFigure.StartPoint = new Point(50, 65); + pFigure.StartPoint = startPoint; //new Point(50, 65); LineSegment lineSegment = new LineSegment(); - lineSegment.Point = new Point(1270, 65); + lineSegment.Point = endPoit; // new Point(800, 65); pFigure.Segments.Add(lineSegment); animationPath.Figures.Add(pFigure); @@ -34,14 +83,14 @@ namespace RoboforkApp animationPath.Freeze(); // Create a MatrixAnimationUsingPath to move the - // button along the path by animating + // simulation along the path by animating // its MatrixTransform. MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath(); matrixAnimation.PathGeometry = animationPath; - matrixAnimation.Duration = TimeSpan.FromSeconds(10); - //matrixAnimation.RepeatBehavior = RepeatBehavior.Forever; + 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". @@ -52,9 +101,36 @@ namespace RoboforkApp Storyboard pathAnimationStoryboard = new Storyboard(); pathAnimationStoryboard.Children.Add(matrixAnimation); - //simulation = new simulationRobo(); - //simulation.storyBoard = pathAnimationStoryboard; - //this.Children.Add(simulation); + return pathAnimationStoryboard; + } + + /// + /// Process when simulation is end line + /// + /// check is node end + private void AnimationCompleted(bool isGoal) + { + // If not end node + if (!isGoal) + { + this.index += 1; + this.Children.Remove(simulation); + this.startPoint = endPoint; + this.endPoint = new Point(Canvas.GetLeft(_lstNode[index]) + RADIUS_NODE, COOR_Y); + + if (this.index == this._lstNode.Count - 1) + { + this._isGoal = true; + } + this._speed += 0.2; + RoboSimulation(); + return; + } + + // Reset data when finish + this.index = 0; + this._speed = 0.2; + this._isGoal = false; } } } diff --git a/sources/RoboforkApp/RoboforkMenuView.xaml.cs b/sources/RoboforkApp/RoboforkMenuView.xaml.cs index 3ecc91d..f23595f 100644 --- a/sources/RoboforkApp/RoboforkMenuView.xaml.cs +++ b/sources/RoboforkApp/RoboforkMenuView.xaml.cs @@ -148,7 +148,7 @@ namespace RoboforkApp private void DoBeginTask() { - MyScheduleCanvas.CreateSimulation(); + MyScheduleCanvas.CreateSimulation(MyDesignerCanvas.ucScheduleNode_Lst); } private void DoBeginSetAutoNotes()