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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // Builds trigger objects for guisim
21 /****************************************************************************/
22 #include <config.h>
23 
24 #include <string>
25 #include <fstream>
27 #include <guisim/GUINet.h>
29 #include <guisim/GUIBusStop.h>
31 #include <guisim/GUIParkingArea.h>
32 #include <guisim/GUICalibrator.h>
34 #include <guisim/GUIOverheadWire.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,
73  int personCapacity, double parkingLength) {
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, parkingLength);
77  } else {
78  myCurrentStop = new GUIBusStop(id, lines, *lane, frompos, topos, name, personCapacity, parkingLength);
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 
120 void
121 GUITriggerBuilder::buildOverheadWireSegment(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos,
122  bool voltageSource) {
123  GUIOverheadWire* overheadWire = new GUIOverheadWire(id, *lane, frompos, topos, voltageSource);
124  if (!net.addStoppingPlace(SUMO_TAG_OVERHEAD_WIRE_SEGMENT, overheadWire)) {
125  delete overheadWire;
126  throw InvalidArgument("Could not build overheadWireSegment '" + id + "'; probably declared twice.");
127  }
128  static_cast<GUINet&>(net).getVisualisationSpeedUp().addAdditionalGLObject(overheadWire);
129 }
130 
131 void
132 GUITriggerBuilder::buildOverheadWireClamp(MSNet& net, const std::string& id, MSLane* lane_start, MSLane* lane_end) {
133  GUIOverheadWireClamp* overheadWireClamp = new GUIOverheadWireClamp(id, *lane_start, *lane_end);
134  static_cast<GUINet&>(net).getVisualisationSpeedUp().addAdditionalGLObject(overheadWireClamp);
135 }
136 
137 
138 void
140  if (myParkingArea != nullptr) {
141  static_cast<GUINet*>(MSNet::getInstance())->getVisualisationSpeedUp().addAdditionalGLObject(static_cast<GUIParkingArea*>(myParkingArea));
142  myParkingArea = nullptr;
143  } else {
144  throw InvalidArgument("Could not end a parking area that is not opened.");
145  }
146 }
147 
148 
149 void
151  if (myCurrentStop != nullptr) {
152  static_cast<GUINet*>(MSNet::getInstance())->getVisualisationSpeedUp().addAdditionalGLObject(dynamic_cast<GUIGlObject*>(myCurrentStop));
153  myCurrentStop = nullptr;
154  } else {
155  throw InvalidArgument("Could not end a stopping place that is not opened.");
156  }
157 }
158 
159 
160 /****************************************************************************/
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
long long int SUMOTime
Definition: SUMOTime.h:31
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_OVERHEAD_WIRE_SEGMENT
An overhead wire segment.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
A lane area vehicles can halt at (gui-version)
Definition: GUIBusStop.h:60
A lane area vehicles can halt at (gui-version)
A lane area vehicles can halt at (gui-version)
Changes the speed allowed on a set of lanes (gui version)
A MSNet extended by some values for usage within the gui.
Definition: GUINet.h:81
GUI for the overhead wire system.
A lane area vehicles can halt at (gui-version)
virtual void endStoppingPlace()
End a stopping place.
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.
virtual MSLaneSpeedTrigger * buildLaneSpeedTrigger(MSNet &net, const std::string &id, const std::vector< MSLane * > &destLanes, const std::string &file)
Builds a lane speed trigger.
virtual void buildOverheadWireSegment(MSNet &net, const std::string &id, MSLane *lane, double frompos, double topos, bool voltageSource)
Builds an overhead wire segment.
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
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.
virtual void buildOverheadWireClamp(MSNet &net, const std::string &id, MSLane *lane_start, MSLane *lane_end)
Builds an overhead wire clamp.
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, double parkingLength)
Builds a bus stop.
GUITriggerBuilder()
Constructor.
virtual void endParkingArea()
End a parking area (it must be added to the SUMORTree after all parking spaces are loaded.
~GUITriggerBuilder()
Destructor.
Reroutes vehicles passing an edge One rerouter can be active on multiple edges. To reduce drawing loa...
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
Changes the speed allowed on a set of lanes.
The simulated network and simulation perfomer.
Definition: MSNet.h:89
bool addStoppingPlace(const SumoXMLTag category, MSStoppingPlace *stop)
Adds a stopping place.
Definition: MSNet.cpp:1082
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:171
Reroutes vehicles passing an edge.
MSParkingArea * myParkingArea
definition of the currently parsed parking area
MSStoppingPlace * myCurrentStop
The currently parsed stop to add access points to.