Microscopic Traffic Simulator
CanvasViewModel.cs
Go to the documentation of this file.
6 using System.Windows;
7 
8 namespace Microscopic_Traffic_Simulator.ViewModels
9 {
14  {
18  private GeometricTopology geometricTopology;
22  internal GeometricTopology GeometricTopology { get { return geometricTopology; } }
23 
27  private CellularTopology cellularTopology;
31  internal CellularTopology CellularTopology { get { return cellularTopology; } }
32 
33  private BuildingMode buildingMode;
34  internal BuildingMode BuildingMode { get { return buildingMode; } }
35 
39  private LaneType currentLaneType;
43  internal LaneType CurrentLaneType { get { return currentLaneType; } }
44 
49  internal CanvasViewModel(Messenger messenger)
50  {
51  this.messenger = messenger;
52  this.messenger.GetEvent<ConstructionViewModel.GeometricTopologyMessage>().Subscribe(
53  geometricTopology => this.geometricTopology = geometricTopology);
54  this.messenger.GetEvent<SimulationControlViewModel.CellularTopologyMessage>().Subscribe(
55  cellularTopology => this.cellularTopology = cellularTopology);
56  this.messenger.GetEvent<ConstructionViewModel.BuildCellularTopologyMessage>().Subscribe(
57  (geometricTopology, parameters) => buildingMode = BuildingMode.None);
58  this.messenger.GetEvent<ConstructionViewModel.LaneTypeChangedMessage>().Subscribe(i => currentLaneType = i);
59  this.messenger.GetEvent<ConstructionViewModel.IsConstructionModeChangedMessage>().Subscribe(
60  i => buildingMode = i);
61  }
62 
68  internal void BuildNewStraightLane(Point startPoint, Point endPoint)
69  {
70  geometricTopology.AddLane(new StraightLane(startPoint, endPoint));
71  messenger.GetEvent<ConstructionViewModel.GeometricTopologyModifiedMessage>().Publish();
72  }
73 
81  internal void BuildNewBezierLaneLane(Point startPoint, Point firstControlPoint, Point secondControlPoint,
82  Point endPoint)
83  {
84  geometricTopology.AddLane(new BezierLane(startPoint, firstControlPoint, secondControlPoint, endPoint));
85  messenger.GetEvent<ConstructionViewModel.GeometricTopologyModifiedMessage>().Publish();
86  }
87 
88  internal static void CreateGeneratorForLane(Lane laneWhereGeneratorToAdd)
89  {
90  laneWhereGeneratorToAdd.StartNode.Generator = new Generator();
91  }
92  }
93 }
Class representing geometric topology of road network.
Class representing messenger for communicating between viewmodels.
Definition: Messenger.cs:9
StartNode StartNode
Node on the input end of lane.
Definition: Lane.cs:23
Contains information about change of lane type and actual current lane type.
Message for sending information about modification of geometric topology.
void AddLane(Lane newLane)
Adds new lane to geometric topology.
Message for sending geometric topology to other viewmodels after creating or opening geomtric topolog...
Message about change of the CurrentBuildingMode containing new value as parameter ...
Message for sending geometric topology simulation control viewmodel to build cellular topology from i...