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-2022 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 /****************************************************************************/
21 // Builds trigger objects for guisim
22 /****************************************************************************/
23 #include <config.h>
24 
25 #include <string>
26 #include <fstream>
27 #include <utils/common/RGBColor.h>
29 #include <guisim/GUINet.h>
31 #include <guisim/GUIBusStop.h>
32 #include <guisim/GUIParkingArea.h>
33 #include <guisim/GUICalibrator.h>
35 #include <guisim/GUIOverheadWire.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,
74  int personCapacity, double parkingLength, RGBColor& color) {
75  myCurrentStop = new GUIBusStop(id, element, lines, *lane, frompos, topos, name, personCapacity, parkingLength, color);
76  if (!net.addStoppingPlace(element, myCurrentStop)) {
77  delete myCurrentStop;
78  myCurrentStop = nullptr;
79  throw InvalidArgument("Could not build " + toString(element) + " '" + id + "'; probably declared twice.");
80  }
81 }
82 
83 
84 void
85 GUITriggerBuilder::beginParkingArea(MSNet& net, const std::string& id,
86  const std::vector<std::string>& lines,
87  MSLane* lane,
88  double frompos, double topos,
89  unsigned int capacity,
90  double width, double length, double angle, const std::string& name,
91  bool onRoad,
92  const std::string& departPos) {
93  assert(myParkingArea == 0);
94  GUIParkingArea* stop = new GUIParkingArea(id, lines, *lane, frompos, topos, capacity, width, length, angle, name, onRoad, departPos);
95  if (!net.addStoppingPlace(SUMO_TAG_PARKING_AREA, stop)) {
96  delete stop;
97  throw InvalidArgument("Could not build parking area '" + id + "'; probably declared twice.");
98  } else {
99  myParkingArea = stop;
100  }
101 }
102 
103 
104 void
105 GUITriggerBuilder::buildChargingStation(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos, const std::string& name,
106  double chargingPower, double efficiency, bool chargeInTransit, SUMOTime chargeDelay) {
107  GUIChargingStation* chargingStation = new GUIChargingStation(id, *lane, frompos, topos, name, chargingPower, efficiency, chargeInTransit, chargeDelay);
108  if (!net.addStoppingPlace(SUMO_TAG_CHARGING_STATION, chargingStation)) {
109  delete chargingStation;
110  throw InvalidArgument("Could not build charging station '" + id + "'; probably declared twice.");
111  }
112  myCurrentStop = chargingStation;
113  static_cast<GUINet&>(net).getVisualisationSpeedUp().addAdditionalGLObject(chargingStation);
114 }
115 
116 
117 void
118 GUITriggerBuilder::buildOverheadWireSegment(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos,
119  bool voltageSource) {
120  GUIOverheadWire* overheadWire = new GUIOverheadWire(id, *lane, frompos, topos, voltageSource);
121  if (!net.addStoppingPlace(SUMO_TAG_OVERHEAD_WIRE_SEGMENT, overheadWire)) {
122  delete overheadWire;
123  throw InvalidArgument("Could not build overheadWireSegment '" + id + "'; probably declared twice.");
124  }
125  static_cast<GUINet&>(net).getVisualisationSpeedUp().addAdditionalGLObject(overheadWire);
126 }
127 
128 void
129 GUITriggerBuilder::buildOverheadWireClamp(MSNet& net, const std::string& id, MSLane* lane_start, MSLane* lane_end) {
130  GUIOverheadWireClamp* overheadWireClamp = new GUIOverheadWireClamp(id, *lane_start, *lane_end);
131  static_cast<GUINet&>(net).getVisualisationSpeedUp().addAdditionalGLObject(overheadWireClamp);
132 }
133 
134 
135 void
137  if (myParkingArea != nullptr) {
138  static_cast<GUINet*>(MSNet::getInstance())->getVisualisationSpeedUp().addAdditionalGLObject(static_cast<GUIParkingArea*>(myParkingArea));
139  myParkingArea = nullptr;
140  } else {
141  throw InvalidArgument("Could not end a parking area that is not opened.");
142  }
143 }
144 
145 
146 void
148  if (myCurrentStop != nullptr) {
149  static_cast<GUINet*>(MSNet::getInstance())->getVisualisationSpeedUp().addAdditionalGLObject(dynamic_cast<GUIGlObject*>(myCurrentStop));
150  myCurrentStop = nullptr;
151  } else {
152  throw InvalidArgument("Could not end a stopping place that is not opened.");
153  }
154 }
155 
156 
157 /****************************************************************************/
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
long long int SUMOTime
Definition: SUMOTime.h:32
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
@ 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:46
A lane area vehicles can halt at (gui-version)
Definition: GUIBusStop.h:62
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 buildOverheadWireClamp(MSNet &net, const std::string &id, MSLane *lane_start, MSLane *lane_end) override
Builds an overhead wire clamp.
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) override
builds an rerouter
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, SUMOTime chargeDelay) override
Builds a charging station.
virtual void endParkingArea() override
End a parking area (it must be added to the SUMORTree after all parking spaces are loaded.
virtual MSLaneSpeedTrigger * buildLaneSpeedTrigger(MSNet &net, const std::string &id, const std::vector< MSLane * > &destLanes, const std::string &file) override
Builds a lane speed trigger.
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, RGBColor &color) override
Builds a bus stop.
virtual void endStoppingPlace() override
End a stopping place.
GUITriggerBuilder()
Constructor.
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, const std::string &departPos) override
Builds a parking area.
~GUITriggerBuilder()
Destructor.
virtual void buildOverheadWireSegment(MSNet &net, const std::string &id, MSLane *lane, double frompos, double topos, bool voltageSource) override
Builds an overhead wire segment.
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:88
bool addStoppingPlace(const SumoXMLTag category, MSStoppingPlace *stop)
Adds a stopping place.
Definition: MSNet.cpp:1234
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:174
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.