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 /****************************************************************************/
16 // Builds trigger objects for guisim
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <string>
26 #include <fstream>
28 #include <guisim/GUINet.h>
30 #include <guisim/GUIBusStop.h>
32 #include <guisim/GUIParkingArea.h>
33 #include <guisim/GUICalibrator.h>
35 #include "GUITriggerBuilder.h"
36 
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
43 
44 
46 
47 
50  const std::string& id, const std::vector<MSLane*>& destLanes,
51  const std::string& file) {
52  GUILaneSpeedTrigger* lst = new GUILaneSpeedTrigger(id, destLanes, file);
53  static_cast<GUINet&>(net).getVisualisationSpeedUp().addAdditionalGLObject(lst);
54  return lst;
55 }
56 
57 
59 GUITriggerBuilder::buildRerouter(MSNet& net, const std::string& id,
60  MSEdgeVector& edges,
61  double prob, const std::string& file, bool off,
62  SUMOTime timeThreshold,
63  const std::string& vTypes) {
64  GUITriggeredRerouter* rr = new GUITriggeredRerouter(id, edges, prob, file, off, timeThreshold, vTypes,
65  dynamic_cast<GUINet&>(net).getVisualisationSpeedUp());
66  return rr;
67 }
68 
69 
70 void
71 GUITriggerBuilder::buildStoppingPlace(MSNet& net, std::string id, std::vector<std::string> lines, MSLane* lane,
72  double frompos, double topos, const SumoXMLTag element, std::string name, int personCapacity) {
73  if (element == SUMO_TAG_CONTAINER_STOP) {
74  //TODO: shall we also allow names for container stops? might make sense [GL March '17]
75  myCurrentStop = new GUIContainerStop(id, lines, *lane, frompos, topos, name, personCapacity);
76  } else {
77  myCurrentStop = new GUIBusStop(id, lines, *lane, frompos, topos, name, personCapacity);
78  }
79  if (!net.addStoppingPlace(element, myCurrentStop)) {
80  delete myCurrentStop;
81  myCurrentStop = nullptr;
82  throw InvalidArgument("Could not build " + toString(element) + " '" + id + "'; probably declared twice.");
83  }
84 }
85 
86 
87 void
88 GUITriggerBuilder::beginParkingArea(MSNet& net, const std::string& id,
89  const std::vector<std::string>& lines,
90  MSLane* lane,
91  double frompos, double topos,
92  unsigned int capacity,
93  double width, double length, double angle, const std::string& name,
94  bool onRoad) {
95  assert(myParkingArea == 0);
96  GUIParkingArea* stop = new GUIParkingArea(id, lines, *lane, frompos, topos, capacity, width, length, angle, name, onRoad);
97  if (!net.addStoppingPlace(SUMO_TAG_PARKING_AREA, stop)) {
98  delete stop;
99  throw InvalidArgument("Could not build parking area '" + id + "'; probably declared twice.");
100  } else {
101  myParkingArea = stop;
102  }
103 }
104 
105 
106 void
107 GUITriggerBuilder::buildChargingStation(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos, const std::string& name,
108  double chargingPower, double efficiency, bool chargeInTransit, double chargeDelay) {
109  GUIChargingStation* chargingStation = new GUIChargingStation(id, *lane, frompos, topos, name, chargingPower, efficiency, chargeInTransit, chargeDelay);
110  if (!net.addStoppingPlace(SUMO_TAG_CHARGING_STATION, chargingStation)) {
111  delete chargingStation;
112  throw InvalidArgument("Could not build charging station '" + id + "'; probably declared twice.");
113  }
114  myCurrentStop = chargingStation;
115  static_cast<GUINet&>(net).getVisualisationSpeedUp().addAdditionalGLObject(chargingStation);
116 }
117 
118 
120 GUITriggerBuilder::buildCalibrator(MSNet& net, const std::string& id,
121  MSEdge* edge, MSLane* lane, double pos,
122  const std::string& file,
123  const std::string& outfile,
124  const SUMOTime freq,
125  const MSRouteProbe* probe,
126  const std::string& vTypes) {
127  GUICalibrator* cali = new GUICalibrator(id, edge, lane, pos, file, outfile, freq, probe, vTypes);
128  static_cast<GUINet&>(net).getVisualisationSpeedUp().addAdditionalGLObject(cali);
129  return cali;
130 }
131 
132 
133 void
135  if (myParkingArea != nullptr) {
136  static_cast<GUINet*>(MSNet::getInstance())->getVisualisationSpeedUp().addAdditionalGLObject(static_cast<GUIParkingArea*>(myParkingArea));
137  myParkingArea = nullptr;
138  } else {
139  throw InvalidArgument("Could not end a parking area that is not opened.");
140  }
141 }
142 
143 
144 void
146  if (myCurrentStop != nullptr) {
147  static_cast<GUINet*>(MSNet::getInstance())->getVisualisationSpeedUp().addAdditionalGLObject(dynamic_cast<GUIGlObject*>(myCurrentStop));
148  myCurrentStop = nullptr;
149  } else {
150  throw InvalidArgument("Could not end a stopping place that is not opened.");
151  }
152 }
153 
154 /****************************************************************************/
155 
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:134
GUITriggerBuilder::endStoppingPlace
virtual void endStoppingPlace()
End a stopping place.
Definition: GUITriggerBuilder.cpp:145
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
GUITriggerBuilder.h
GUIParkingArea
A lane area vehicles can halt at (gui-version)
Definition: GUIParkingArea.h:60
MSRouteProbe
Writes routes of vehicles passing a certain edge.
Definition: MSRouteProbe.h:60
GUICalibrator
Changes the speed allowed on a set of lanes (gui version)
Definition: GUICalibrator.h:44
MSNet
The simulated network and simulation perfomer.
Definition: MSNet.h:91
SUMO_TAG_CONTAINER_STOP
A container stop.
Definition: SUMOXMLDefinitions.h:105
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
NLTriggerBuilder::myCurrentStop
MSStoppingPlace * myCurrentStop
The currently parsed stop to add access points to.
Definition: NLTriggerBuilder.h:412
GUIChargingStation.h
NLTriggerBuilder::myParkingArea
MSParkingArea * myParkingArea
definition of the currently parsed parking area
Definition: NLTriggerBuilder.h:410
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:71
MSLaneSpeedTrigger
Changes the speed allowed on a set of lanes.
Definition: MSLaneSpeedTrigger.h:53
MSTriggeredRerouter
Reroutes vehicles passing an edge.
Definition: MSTriggeredRerouter.h:61
GUINet.h
SumoXMLTag
SumoXMLTag
Numbers representing SUMO-XML - element names.
Definition: SUMOXMLDefinitions.h:41
GUITriggeredRerouter
Reroutes vehicles passing an edge One rerouter can be active on multiple edges. To reduce drawing loa...
Definition: GUITriggeredRerouter.h:50
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:49
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:59
SUMO_TAG_CHARGING_STATION
A Charging Station.
Definition: SUMOXMLDefinitions.h:111
GUIContainerStop
A lane area vehicles can halt at (gui-version)
Definition: GUIContainerStop.h:61
SUMO_TAG_PARKING_AREA
A parking area.
Definition: SUMOXMLDefinitions.h:107
GUIContainerStop.h
MSNet::addStoppingPlace
bool addStoppingPlace(const SumoXMLTag category, MSStoppingPlace *stop)
Adds a stopping place.
Definition: MSNet.cpp:905
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:88
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
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:107
GUILaneSpeedTrigger
Changes the speed allowed on a set of lanes (gui version)
Definition: GUILaneSpeedTrigger.h:44
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:120
GUIParkingArea.h
GUICalibrator.h
GUILaneSpeedTrigger.h
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
GUIChargingStation
A lane area vehicles can halt at (gui-version)
Definition: GUIChargingStation.h:65
InvalidArgument
Definition: UtilExceptions.h:56
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:74
GUITriggerBuilder::~GUITriggerBuilder
~GUITriggerBuilder()
Destructor.
Definition: GUITriggerBuilder.cpp:45
config.h
GUITriggeredRerouter.h
GUIBusStop
A lane area vehicles can halt at (gui-version)
Definition: GUIBusStop.h:62
MSCalibrator
Calibrates the flow on a segment to a specified one.
Definition: MSCalibrator.h:50
GUIBusStop.h
GUITriggerBuilder::GUITriggerBuilder
GUITriggerBuilder()
Constructor.
Definition: GUITriggerBuilder.cpp:42