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