Eclipse SUMO - Simulation of Urban MObility
GUITriggerBuilder.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Builds trigger objects for guisim
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
27 #include <fstream>
29 #include <guisim/GUINet.h>
31 #include <guisim/GUIBusStop.h>
33 #include <guisim/GUIParkingArea.h>
34 #include <guisim/GUICalibrator.h>
36 #include "GUITriggerBuilder.h"
37 
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
44 
45 
47 
48 
51  const std::string& id, const std::vector<MSLane*>& destLanes,
52  const std::string& file) {
53  GUILaneSpeedTrigger* lst = new GUILaneSpeedTrigger(id, destLanes, file);
54  static_cast<GUINet&>(net).getVisualisationSpeedUp().addAdditionalGLObject(lst);
55  return lst;
56 }
57 
58 
60 GUITriggerBuilder::buildRerouter(MSNet& net, const std::string& id,
61  MSEdgeVector& edges,
62  double prob, const std::string& file, bool off,
63  SUMOTime timeThreshold,
64  const std::string& vTypes) {
65  GUITriggeredRerouter* rr = new GUITriggeredRerouter(id, edges, prob, file, off, timeThreshold, vTypes,
66  dynamic_cast<GUINet&>(net).getVisualisationSpeedUp());
67  return rr;
68 }
69 
70 
71 void
72 GUITriggerBuilder::buildStoppingPlace(MSNet& net, std::string id, std::vector<std::string> lines, MSLane* lane,
73  double frompos, double topos, const SumoXMLTag element, std::string name, int personCapacity) {
74  if (element == SUMO_TAG_CONTAINER_STOP) {
75  //TODO: shall we also allow names for container stops? might make sense [GL March '17]
76  myCurrentStop = new GUIContainerStop(id, lines, *lane, frompos, topos, name, personCapacity);
77  } else {
78  myCurrentStop = new GUIBusStop(id, lines, *lane, frompos, topos, name, personCapacity);
79  }
80  if (!net.addStoppingPlace(element, myCurrentStop)) {
81  delete myCurrentStop;
82  myCurrentStop = nullptr;
83  throw InvalidArgument("Could not build " + toString(element) + " '" + id + "'; probably declared twice.");
84  }
85 }
86 
87 
88 void
89 GUITriggerBuilder::beginParkingArea(MSNet& net, const std::string& id,
90  const std::vector<std::string>& lines,
91  MSLane* lane,
92  double frompos, double topos,
93  unsigned int capacity,
94  double width, double length, double angle, const std::string& name,
95  bool onRoad) {
96  assert(myParkingArea == 0);
97  GUIParkingArea* stop = new GUIParkingArea(id, lines, *lane, frompos, topos, capacity, width, length, angle, name, onRoad);
98  if (!net.addStoppingPlace(SUMO_TAG_PARKING_AREA, stop)) {
99  delete stop;
100  throw InvalidArgument("Could not build parking area '" + id + "'; probably declared twice.");
101  } else {
102  myParkingArea = stop;
103  }
104 }
105 
106 
107 void
108 GUITriggerBuilder::buildChargingStation(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos, const std::string& name,
109  double chargingPower, double efficiency, bool chargeInTransit, double chargeDelay) {
110  GUIChargingStation* chargingStation = new GUIChargingStation(id, *lane, frompos, topos, name, chargingPower, efficiency, chargeInTransit, chargeDelay);
111  if (!net.addStoppingPlace(SUMO_TAG_CHARGING_STATION, chargingStation)) {
112  delete chargingStation;
113  throw InvalidArgument("Could not build charging station '" + id + "'; probably declared twice.");
114  }
115  myCurrentStop = chargingStation;
116  static_cast<GUINet&>(net).getVisualisationSpeedUp().addAdditionalGLObject(chargingStation);
117 }
118 
119 
121 GUITriggerBuilder::buildCalibrator(MSNet& net, const std::string& id,
122  MSEdge* edge, MSLane* lane, double pos,
123  const std::string& file,
124  const std::string& outfile,
125  const SUMOTime freq,
126  const MSRouteProbe* probe,
127  const std::string& vTypes) {
128  GUICalibrator* cali = new GUICalibrator(id, edge, lane, pos, file, outfile, freq, probe, vTypes);
129  static_cast<GUINet&>(net).getVisualisationSpeedUp().addAdditionalGLObject(cali);
130  return cali;
131 }
132 
133 
134 void
136  if (myParkingArea != nullptr) {
137  static_cast<GUINet*>(MSNet::getInstance())->getVisualisationSpeedUp().addAdditionalGLObject(static_cast<GUIParkingArea*>(myParkingArea));
138  myParkingArea = nullptr;
139  } else {
140  throw InvalidArgument("Could not end a parking area that is not opened.");
141  }
142 }
143 
144 
145 void
147  if (myCurrentStop != nullptr) {
148  static_cast<GUINet*>(MSNet::getInstance())->getVisualisationSpeedUp().addAdditionalGLObject(dynamic_cast<GUIGlObject*>(myCurrentStop));
149  myCurrentStop = nullptr;
150  } else {
151  throw InvalidArgument("Could not end a stopping place that is not opened.");
152  }
153 }
154 
155 /****************************************************************************/
156 
GUITriggerBuilder::endParkingArea
virtual void endParkingArea()
End a parking area (it must be added to the SUMORTree after all parking spaces are loaded.
Definition: GUITriggerBuilder.cpp:135
GUITriggerBuilder::endStoppingPlace
virtual void endStoppingPlace()
End a stopping place.
Definition: GUITriggerBuilder.cpp:146
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
GUITriggerBuilder.h
GUIParkingArea
A lane area vehicles can halt at (gui-version)
Definition: GUIParkingArea.h:61
MSRouteProbe
Writes routes of vehicles passing a certain edge.
Definition: MSRouteProbe.h:61
GUICalibrator
Changes the speed allowed on a set of lanes (gui version)
Definition: GUICalibrator.h:45
MSNet
The simulated network and simulation perfomer.
Definition: MSNet.h:92
SUMO_TAG_CONTAINER_STOP
A container stop.
Definition: SUMOXMLDefinitions.h:106
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
NLTriggerBuilder::myCurrentStop
MSStoppingPlace * myCurrentStop
The currently parsed stop to add access points to.
Definition: NLTriggerBuilder.h:413
GUIChargingStation.h
NLTriggerBuilder::myParkingArea
MSParkingArea * myParkingArea
definition of the currently parsed parking area
Definition: NLTriggerBuilder.h:411
GUITriggerBuilder::buildStoppingPlace
virtual void buildStoppingPlace(MSNet &net, std::string id, std::vector< std::string > lines, MSLane *lane, double frompos, double topos, const SumoXMLTag element, std::string string, int personCapacity)
Builds a bus stop.
Definition: GUITriggerBuilder.cpp:72
MSLaneSpeedTrigger
Changes the speed allowed on a set of lanes.
Definition: MSLaneSpeedTrigger.h:54
MSTriggeredRerouter
Reroutes vehicles passing an edge.
Definition: MSTriggeredRerouter.h:62
GUINet.h
SumoXMLTag
SumoXMLTag
Numbers representing SUMO-XML - element names.
Definition: SUMOXMLDefinitions.h:42
GUITriggeredRerouter
Reroutes vehicles passing an edge One rerouter can be active on multiple edges. To reduce drawing loa...
Definition: GUITriggeredRerouter.h:51
GUITriggerBuilder::buildLaneSpeedTrigger
virtual MSLaneSpeedTrigger * buildLaneSpeedTrigger(MSNet &net, const std::string &id, const std::vector< MSLane * > &destLanes, const std::string &file)
Builds a lane speed trigger.
Definition: GUITriggerBuilder.cpp:50
GUITriggerBuilder::buildRerouter
virtual MSTriggeredRerouter * buildRerouter(MSNet &net, const std::string &id, MSEdgeVector &edges, double prob, const std::string &file, bool off, SUMOTime timeThreshold, const std::string &vTypes)
builds an rerouter
Definition: GUITriggerBuilder.cpp:60
SUMO_TAG_CHARGING_STATION
A Charging Station.
Definition: SUMOXMLDefinitions.h:112
GUIContainerStop
A lane area vehicles can halt at (gui-version)
Definition: GUIContainerStop.h:62
SUMO_TAG_PARKING_AREA
A parking area.
Definition: SUMOXMLDefinitions.h:108
GUIContainerStop.h
MSNet::addStoppingPlace
bool addStoppingPlace(const SumoXMLTag category, MSStoppingPlace *stop)
Adds a stopping place.
Definition: MSNet.cpp:893
GUITriggerBuilder::beginParkingArea
virtual void beginParkingArea(MSNet &net, const std::string &id, const std::vector< std::string > &lines, MSLane *lane, double frompos, double topos, unsigned int capacity, double width, double length, double angle, const std::string &name, bool onRoad)
Builds a parking area.
Definition: GUITriggerBuilder.cpp:89
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:76
GUITriggerBuilder::buildChargingStation
virtual void buildChargingStation(MSNet &net, const std::string &id, MSLane *lane, double frompos, double topos, const std::string &name, double chargingPower, double efficiency, bool chargeInTransit, double chargeDelay)
Builds a charging station.
Definition: GUITriggerBuilder.cpp:108
GUILaneSpeedTrigger
Changes the speed allowed on a set of lanes (gui version)
Definition: GUILaneSpeedTrigger.h:45
GUITriggerBuilder::buildCalibrator
virtual MSCalibrator * buildCalibrator(MSNet &net, const std::string &id, MSEdge *edge, MSLane *lane, double pos, const std::string &file, const std::string &outfile, const SUMOTime freq, const MSRouteProbe *probe, const std::string &vTypes)
builds a microscopic calibrator
Definition: GUITriggerBuilder.cpp:121
GUIParkingArea.h
GUICalibrator.h
GUILaneSpeedTrigger.h
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
GUIChargingStation
A lane area vehicles can halt at (gui-version)
Definition: GUIChargingStation.h:66
InvalidArgument
Definition: UtilExceptions.h:57
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:72
GUITriggerBuilder::~GUITriggerBuilder
~GUITriggerBuilder()
Destructor.
Definition: GUITriggerBuilder.cpp:46
config.h
GUITriggeredRerouter.h
GUIBusStop
A lane area vehicles can halt at (gui-version)
Definition: GUIBusStop.h:63
MSCalibrator
Calibrates the flow on a segment to a specified one.
Definition: MSCalibrator.h:51
GUIBusStop.h
GUITriggerBuilder::GUITriggerBuilder
GUITriggerBuilder()
Constructor.
Definition: GUITriggerBuilder.cpp:43