5 using System.Windows.Controls;
7 using System.Windows.Threading;
14 public partial class SimulationControlUserControl : UserControl
19 private DispatcherTimer timer;
31 InitializeComponent();
39 private void timer_Tick(
object sender, EventArgs e)
41 (Window.GetWindow(
this) as
MainWindow).canvasUserControl
51 private void UserControl_Loaded(
object sender, RoutedEventArgs e)
55 .CommandExecuted += SimulationControlUserControl_StartTimer;
57 .CommandExecuted += SimulationControlUserControl_StopCommandExecuted;
59 .CommandExecuted += SimulationControlUserControl_PauseCommandExecuted;
61 .CommandExecuted += SimulationControlUserControl_StopCommandExecuted;
63 SimulationControlUserControl_RestartCommandExecuted;
64 viewModel.CellularTopology.Simulation.SimulationPaused += Simulation_SimulationPaused;
65 timer =
new DispatcherTimer(DispatcherPriority.Render);
66 timer.Tick += timer_Tick;
67 timer.Interval = TimeSpan.FromMilliseconds(1000.0 / sliderGraphicsTimer.Value);
76 private void UserControl_Unloaded(
object sender, RoutedEventArgs e)
79 .CommandExecuted -= SimulationControlUserControl_StartTimer;
81 .CommandExecuted -= SimulationControlUserControl_StopCommandExecuted;
83 .CommandExecuted -= SimulationControlUserControl_PauseCommandExecuted;
85 .CommandExecuted -= SimulationControlUserControl_StopCommandExecuted;
87 SimulationControlUserControl_RestartCommandExecuted;
88 viewModel.CellularTopology.Simulation.SimulationPaused -= Simulation_SimulationPaused;
89 timer.Tick -= timer_Tick;
97 private void Simulation_SimulationPaused(
object sender, EventArgs e)
100 Application.Current.Dispatcher.Invoke(() => CommandManager.InvalidateRequerySuggested(),
101 DispatcherPriority.Render);
110 private void SimulationControlUserControl_StartTimer(
object sender, EventArgs e)
122 private void SimulationControlUserControl_PauseCommandExecuted(
object sender, EventArgs e)
125 (Window.GetWindow(
this) as
MainWindow).canvasUserControl.SimulationTrafficRenderer.Pause();
133 private void SimulationControlUserControl_StopCommandExecuted(
object sender, EventArgs e)
136 (Window.GetWindow(
this) as
MainWindow).canvasUserControl.SimulationTrafficRenderer.Stop();
144 private void sliderGraphicsTimer_ValueChanged(
object sender, RoutedPropertyChangedEventArgs<double> e)
149 timer.Interval = TimeSpan.FromMilliseconds(1000.0 / sliderGraphicsTimer.Value);
159 private void ApplyAlarmButton_Click(
object sender, RoutedEventArgs e)
161 btnAlarm.IsChecked =
false;
170 private void SwitchToConstructionModeButton_Click(
object sender, RoutedEventArgs e)
172 (Window.GetWindow(
this) as
MainWindow).canvasUserControl.SimulationTrafficRenderer
173 .DetachEventHandlerFromCellularTopology();
181 private void ForwardButton_Click(
object sender, RoutedEventArgs e)
183 (Window.GetWindow(
this) as
MainWindow).canvasUserControl.SimulationTrafficRenderer.Run();
191 private void ForwardStepButton_Click(
object sender, RoutedEventArgs e)
193 (Window.GetWindow(
this) as
MainWindow).canvasUserControl.SimulationTrafficRenderer.StepForward();
201 private void SimulationControlUserControl_RestartCommandExecuted(
object sender, EventArgs e)
204 (Window.GetWindow(
this) as
MainWindow).canvasUserControl.SimulationTrafficRenderer;
207 if (!timer.IsEnabled)
ICommand SwitchToConstructionModeCommand
Command to switch to construction mode.
ICommand RestartCommand
Command for restarting simulation.
SimulationControlUserControl()
Initialize control.
Simulation traffic renderer.
ICommand ForwardCommand
Command to run simulation.
ICommand StopCommand
Command to stop simulation.
ICommand PauseCommand
Command to pause simulation.
Extended relay command class by adding event after executing command. Useful for performing additiona...
Rendering
Enumeration type containing values representing rendering of one single simulation step and rendering...
Viewmodel for simulation control.