24 internal class SwitchToConstructionModeMessage :
Message { }
48 public double SimulationSpeed
65 public int CustomSeed {
get;
set; }
70 public bool IsPreviousSeedAvailable
78 IsPreviousSeedUsed =
false;
80 OnPropertyChanged(
"IsPreviousSeedAvailable");
87 public bool IsPreviousSeedUsed
94 OnPropertyChanged(
"IsPreviousSeedUsed");
101 public bool IsSeedSettingAutomatic
114 public ulong SimulationSteps
122 public ulong SimulationStepsToPause
128 OnPropertyChanged(
"SimulationStepsToPause");
135 public ulong SimulationStepsToPauseToSet {
get;
set; }
140 public TimeSpan ModelTime
148 public TimeSpan ModelTimeToPause
154 OnPropertyChanged(
"ModelTimeToPause");
162 public TimeSpan ModelTimeToPauseToSet {
get;
set; }
167 private double customSimulationSpeed;
171 public double CustomSimulationSpeed
173 get {
return customSimulationSpeed; }
174 set { customSimulationSpeed = value; OnPropertyChanged(
"CustomSimulationSpeed"); }
180 private bool IsNotRunning
188 private bool CanPause
196 private bool SimulationStarted
208 private bool isMaxSimulationSpeed;
212 public bool IsMaxSimulationSpeed
214 get {
return isMaxSimulationSpeed; }
217 if (isMaxSimulationSpeed != value)
219 isMaxSimulationSpeed = value;
221 OnPropertyChanged(
"IsNotMaxSimulationSpeed");
228 public bool IsNotMaxSimulationSpeed {
get {
return !isMaxSimulationSpeed; } }
233 private ICommand switchToConstructionModeCommand;
237 public ICommand SwitchToConstructionModeCommand
241 if (switchToConstructionModeCommand == null)
244 i => SwitchToConstructionMode());
246 return switchToConstructionModeCommand;
253 private ICommand forwardCommand;
257 public ICommand ForwardCommand
261 if (forwardCommand == null)
265 return forwardCommand;
272 private ICommand forwardStepCommand;
276 public ICommand ForwardStepCommand
280 if (forwardStepCommand == null)
284 return forwardStepCommand;
291 private ICommand stopCommand;
295 public ICommand StopCommand
299 if (stopCommand == null)
310 private ICommand pauseCommand;
314 public ICommand PauseCommand
318 if (pauseCommand == null)
329 private ICommand fasterCommand;
333 public ICommand FasterCommand
337 if (fasterCommand == null)
341 SimulationSpeed *= 2.0;
342 OnPropertyChanged(
"SimulationSpeed");
344 }, i => IsNotMaxSimulationSpeed);
346 return fasterCommand;
353 private ICommand slowerCommand;
357 public ICommand SlowerCommand
361 if (slowerCommand == null)
365 SimulationSpeed /= 2.0;
366 OnPropertyChanged(
"SimulationSpeed");
368 }, i => IsNotMaxSimulationSpeed);
370 return slowerCommand;
377 private ICommand customSimulationSpeedCommand;
381 public ICommand CustomSimulationSpeedCommand
385 if (customSimulationSpeedCommand == null)
389 SimulationSpeed = customSimulationSpeed;
390 OnPropertyChanged(
"SimulationSpeed");
391 }, i => IsNotMaxSimulationSpeed);
393 return customSimulationSpeedCommand;
400 private ICommand restartCommand;
404 public ICommand RestartCommand
408 if (restartCommand == null)
414 }, i => SimulationStarted);
416 return restartCommand;
423 private ICommand applyTimeAlarmCommand;
427 public ICommand ApplyTimeAlarmCommand
431 if (applyTimeAlarmCommand == null)
434 i => ModelTimeToPause = ModelTimeToPauseToSet);
436 return applyTimeAlarmCommand;
443 private ICommand applySimulationStepsAlarmCommand;
447 public ICommand ApplySimulationStepsAlarmCommand
451 if (applySimulationStepsAlarmCommand == null)
454 i => SimulationStepsToPause = SimulationStepsToPauseToSet);
456 return applySimulationStepsAlarmCommand;
463 private ICommand resetModelTimeAlarmCommand;
467 public ICommand ResetModelTimeAlarmCommand
471 if (resetModelTimeAlarmCommand == null)
473 resetModelTimeAlarmCommand =
new RelayCommand(i => ModelTimeToPause = TimeSpan.MaxValue);
475 return resetModelTimeAlarmCommand;
482 private ICommand resetSimulationStepsAlarmCommand;
486 public ICommand ResetSimulationStepsAlarmCommand
490 if (resetSimulationStepsAlarmCommand == null)
492 resetSimulationStepsAlarmCommand =
new RelayCommand(i => SimulationStepsToPause = ulong.MaxValue);
494 return resetSimulationStepsAlarmCommand;
504 this.messenger = messenger;
505 this.interactions = interactions;
506 this.settings = settings;
508 (topology, parameters) => BuildCellularTopology(topology, parameters));
517 if (cellularTopology != null)
526 messenger.GetEvent<CellularTopologyMessage>().Publish(cellularTopology);
532 private void SwitchToConstructionMode()
539 messenger.GetEvent<SwitchToConstructionModeMessage>().Publish();
547 RunOrStepForward(cellularTopology.
Run);
562 private void RunOrStepForward(Action<int?> runOrStepForward)
564 int? seedToUse = null;
565 bool simulationIsInitialized =
false;
568 simulationIsInitialized =
true;
574 seedToUse = CustomSeed;
576 runOrStepForward(seedToUse);
577 if (simulationIsInitialized)
580 IsPreviousSeedAvailable =
true;
583 RefreshAlarmAndSeedProperties();
589 private void RefreshAlarmAndSeedProperties()
591 RefreshAlarmProperties();
592 OnPropertyChanged(
"Seed");
600 cellularTopology.
Stop();
601 RefreshAlarmProperties();
609 cellularTopology.
Pause();
617 void Simulation_ModelTimeChanged(
object sender, EventArgs e)
619 OnPropertyChanged(
"ModelTime");
627 void cellularTopology_SimulationStepsChanged(
object sender, EventArgs e)
629 OnPropertyChanged(
"SimulationSteps");
636 private void RefreshAlarmProperties()
638 OnPropertyChanged(
"ModelTimeToPause");
639 OnPropertyChanged(
"SimulationStepsToPause");
EventHandler ModelTimeChanged
An event informing about changing of model time.
Simulation Simulation
Simulation object which controls the simulation on the cellular topology.
Class representing geometric topology of road network.
Class containing all simulator parameters.
bool IsSeedSettingAutomatic
Determines whether the seed is initialized automatically.
GeneratorsManager GeneratorsManager
Generators manager reference.
Class representing message with payload.
Viewmodel for construction panel.
void Run(int?seed=null)
Runs simulation. Seed to be used in the simulation.
Interface of application settings.
Class representing messenger for communicating between viewmodels.
bool IsPreviousSeedUsed
Determines whether the seed from previous simulation run is used.
bool PreviousSeedNull
Determines whether there is any previous seed (whether any simulation was running in past)...
void Pause()
Pauses simulation.
Command class for binding UI commands with view models.
EventHandler SimulationStepsChanged
Event handler of change of number of simulation steps.
SimulationState
Current state of the simulation.
TimeSpan CurrentModelTime
Model time of last tick of simulation timer or last change of simulation run.
bool IsMaxSimulationSpeed
Indicates whether the simulation speed is maximal.
ulong SimulationSteps
Number of simulation steps performed.
Interface for interactions with user.
void DetachFromGeneratorEvents()
Detaches event handler ZeroToOneTicketsInGenerator from its publisher in generator.
SimulationState SimulationState
Current simulation status of simulation.
void StepForward(int?seed=null)
Perform step in simulation. Seed to be used in the simulation.
Message for sending geometric topology simulation control viewmodel to build cellular topology from i...
int UsedSeed
Seed which is used in the simulation.
Extended relay command class by adding event after executing command. Useful for performing additiona...
Class representing cellular topology.
Viewmodel for simulation control.
void Stop()
Stops simulation.
TimeSpan ModelTimeToPause
Simulation model time when the simulation will be paused.
double SimulationSpeed
Current simulation speed in model time speed divided by computer/user time speed
int PreviousSeed
Seed which was used in the last simulation.
void Save()
Saves application settings.
Class representing message without payload.
ulong SimulationStepsToPause
Number of simulation steps after which the simulation control pauses simulation.