public void DoStartNewTrain2(int trainNumber, double[] x, double[] y) { if (!CheckAccess()) { Dispatcher.Invoke(delegate { ViewModel.TrainViewModel.TrainFactory2(trainNumber, 60, 30); ViewModel.TrainViewModel.SetTrainLocation2(trainNumber, 0, 0); ViewModel.TrainViewModel.StartTrain2(trainNumber, x, y); Train2 train = ViewModel.TrainViewModel.trainList2[trainNumber]; canTrain2.Children.Add(train); // usunięcie z animacji //canvas.Children.Remove(train); }); } else { ViewModel.TrainViewModel.TrainFactory2(trainNumber, 60, 30); ViewModel.TrainViewModel.SetTrainLocation2(trainNumber, 0, 0); ViewModel.TrainViewModel.StartTrain2(trainNumber, x, y); Train2 train = ViewModel.TrainViewModel.trainList2[trainNumber]; canTrain2.Children.Add(train); } }
public void MakeTrain2Move(int trainNumber, double[] x, double[] y) { newTrain = ViewModel.TrainViewModel.trainList2[trainNumber]; PathGeometry pathGeometry = new PathGeometry(); PathFigure figure = new PathFigure(); Model.ModbusProtocol.SetInputStatus(67, false); figure.StartPoint = new Point(x[0], y[0]); for (int i = 0; i <= x.Length - 1; i++) { figure.Segments.Add(new LineSegment() { Point = new Point(x[i], y[i]) }); } pathGeometry.Figures.Add(figure); storyboard = new Storyboard(); animation = new DoubleAnimationUsingPath(); animation.Duration = TimeSpan.FromSeconds(15); animation.PathGeometry = pathGeometry; animation.Source = PathAnimationSource.X; Storyboard.SetTarget(animation, newTrain); Storyboard.SetTargetProperty(animation, new PropertyPath(Canvas.LeftProperty)); storyboard.Children.Add(animation); storyboard.Begin(); animation = new DoubleAnimationUsingPath(); animation.Duration = TimeSpan.FromSeconds(15); animation.PathGeometry = pathGeometry; animation.Source = PathAnimationSource.Y; trainInMove = true; animation.Completed += Animation_Completed; timer.Tick += Timer_Tick; timer.Interval = TimeSpan.FromSeconds(.1); timer.Start(); Storyboard.SetTarget(animation, newTrain); Storyboard.SetTargetProperty(animation, new PropertyPath(Canvas.TopProperty)); storyboard.Children.Add(animation); storyboard.Begin(); }
public void DoRemoveTrain2(Train2 train) { canTrain2.Children.Remove(train); }