Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUITriggerBuilder.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2023 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>
29#include <guisim/GUINet.h>
31#include <guisim/GUIBusStop.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).registerRenderedObject(lst);
55 return lst;
56}
57
58
60GUITriggerBuilder::buildRerouter(MSNet& net, const std::string& id,
61 MSEdgeVector& edges, double prob, bool off,
62 SUMOTime timeThreshold, const std::string& vTypes) {
63 GUITriggeredRerouter* rr = new GUITriggeredRerouter(id, edges, prob, off, timeThreshold, vTypes,
64 dynamic_cast<GUINet&>(net).getVisualisationSpeedUp());
65 return rr;
66}
67
68
69void
70GUITriggerBuilder::buildStoppingPlace(MSNet& net, std::string id, std::vector<std::string> lines, MSLane* lane,
71 double frompos, double topos, const SumoXMLTag element, std::string name,
72 int personCapacity, double parkingLength, RGBColor& color) {
73 myCurrentStop = new GUIBusStop(id, element, lines, *lane, frompos, topos, name, personCapacity, parkingLength, color);
74 if (!net.addStoppingPlace(element, myCurrentStop)) {
75 delete myCurrentStop;
76 myCurrentStop = nullptr;
77 throw InvalidArgument("Could not build " + toString(element) + " '" + id + "'; probably declared twice.");
78 }
79}
80
81
82void
83GUITriggerBuilder::beginParkingArea(MSNet& net, const std::string& id,
84 const std::vector<std::string>& lines,
85 MSLane* lane,
86 double frompos, double topos,
87 unsigned int capacity,
88 double width, double length, double angle, const std::string& name,
89 bool onRoad,
90 const std::string& departPos,
91 bool lefthand) {
92 assert(myParkingArea == 0);
93 GUIParkingArea* stop = new GUIParkingArea(id, lines, *lane, frompos, topos, capacity, width, length, angle, name, onRoad, departPos, lefthand);
95 delete stop;
96 throw InvalidArgument("Could not build parking area '" + id + "'; probably declared twice.");
97 } else {
98 myParkingArea = stop;
99 }
100}
101
102
103void
104GUITriggerBuilder::buildChargingStation(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos, const std::string& name,
105 double chargingPower, double efficiency, bool chargeInTransit, SUMOTime chargeDelay) {
106 GUIChargingStation* chargingStation = new GUIChargingStation(id, *lane, frompos, topos, name, chargingPower, efficiency, chargeInTransit, chargeDelay);
107 if (!net.addStoppingPlace(SUMO_TAG_CHARGING_STATION, chargingStation)) {
108 delete chargingStation;
109 throw InvalidArgument("Could not build charging station '" + id + "'; probably declared twice.");
110 }
111 myCurrentStop = chargingStation;
112 static_cast<GUINet&>(net).registerRenderedObject(chargingStation);
113}
114
115
116void
117GUITriggerBuilder::buildOverheadWireSegment(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos,
118 bool voltageSource) {
119 GUIOverheadWire* overheadWire = new GUIOverheadWire(id, *lane, frompos, topos, voltageSource);
120 if (!net.addStoppingPlace(SUMO_TAG_OVERHEAD_WIRE_SEGMENT, overheadWire)) {
121 delete overheadWire;
122 throw InvalidArgument("Could not build overheadWireSegment '" + id + "'; probably declared twice.");
123 }
124 static_cast<GUINet&>(net).registerRenderedObject(overheadWire);
125}
126
127void
128GUITriggerBuilder::buildOverheadWireClamp(MSNet& net, const std::string& id, MSLane* lane_start, MSLane* lane_end) {
129 GUIOverheadWireClamp* overheadWireClamp = new GUIOverheadWireClamp(id, *lane_start, *lane_end);
130 static_cast<GUINet&>(net).registerRenderedObject(overheadWireClamp);
131}
132
133
134void
136 if (myParkingArea != nullptr) {
137 static_cast<GUINet*>(MSNet::getInstance())->registerRenderedObject(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
145void
147 if (myCurrentStop != nullptr) {
148 static_cast<GUINet*>(MSNet::getInstance())->registerRenderedObject(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/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< MSEdge * > MSEdgeVector
Definition MSEdge.h:73
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:82
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 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 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, bool lefthand) override
Builds a parking area.
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.
virtual MSTriggeredRerouter * buildRerouter(MSNet &net, const std::string &id, MSEdgeVector &edges, double prob, bool off, SUMOTime timeThreshold, const std::string &vTypes) override
builds an rerouter
GUITriggerBuilder()
Constructor.
~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:84
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:1347
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:183
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.