Eclipse SUMO - Simulation of Urban MObility
GNERerouter.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/****************************************************************************/
18//
19/****************************************************************************/
20#include <netedit/GNENet.h>
21#include <netedit/GNEUndoList.h>
22#include <netedit/GNEViewNet.h>
26
27#include "GNERerouter.h"
28#include "GNERerouterSymbol.h"
29
30
31// ===========================================================================
32// member method definitions
33// ===========================================================================
34
37{}, {}, {}, {}, {}, {}),
38myProbability(0),
39myOff(false),
40myTimeThreshold(0) {
41 // reset default values
42 resetDefaultValues();
43}
44
45
46GNERerouter::GNERerouter(const std::string& id, GNENet* net, const Position& pos, const std::string& name,
47 double probability, bool off, SUMOTime timeThreshold, const std::vector<std::string>& vTypes,
48 const Parameterised::Map& parameters) :
50{}, {}, {}, {}, {}, {}),
51Parameterised(parameters),
52myPosition(pos),
53myProbability(probability),
54myOff(off),
55myTimeThreshold(timeThreshold),
56myVTypes(vTypes) {
57 // update centering boundary without updating grid
58 updateCenteringBoundary(false);
59}
60
61
63}
64
65
66void
69 device.writeAttr(SUMO_ATTR_ID, getID());
72 if (!myAdditionalName.empty()) {
74 }
75 if (myProbability != 1.0) {
77 }
78 if (time2string(myTimeThreshold) != "0.00") {
80 }
81 if (!myVTypes.empty()) {
83 }
84 if (myOff) {
86 }
87 // write all rerouter interval
88 for (const auto& rerouterInterval : getChildAdditionals()) {
89 if (!rerouterInterval->getTagProperty().isSymbol()) {
90 rerouterInterval->writeAdditional(device);
91 }
92 }
93 // write parameters (Always after children to avoid problems with additionals.xsd)
94 writeParams(device);
95 device.closeTag();
96}
97
98
101 // return move operation for additional placed in view
102 return new GNEMoveOperation(this, myPosition);
103}
104
105
106void
108 // update additional geometry
110 // update geometries (boundaries of all children)
111 for (const auto& additionalChildren : getChildAdditionals()) {
112 additionalChildren->updateGeometry();
113 for (const auto& rerouterElement : additionalChildren->getChildAdditionals()) {
114 rerouterElement->updateGeometry();
115 }
116 }
117}
118
119
122 return myPosition;
123}
124
125
126void
128 // remove additional from grid
129 if (updateGrid) {
131 }
132 // now update geometry
134 // add shape boundary
136 // add positions of all childrens (intervals and symbols)
137 for (const auto& additionalChildren : getChildAdditionals()) {
138 myAdditionalBoundary.add(additionalChildren->getPositionInView());
139 for (const auto& rerouterElement : additionalChildren->getChildAdditionals()) {
140 myAdditionalBoundary.add(rerouterElement->getPositionInView());
141 // special case for parking area rerouter
142 if (rerouterElement->getTagProperty().getTag() == SUMO_TAG_PARKING_AREA_REROUTE) {
143 myAdditionalBoundary.add(rerouterElement->getParentAdditionals().at(1)->getPositionInView());
144 }
145 }
146 }
147 // grow
149 // add additional into RTREE again
150 if (updateGrid) {
152 }
153}
154
155
156void
157GNERerouter::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
158 // geometry of this element cannot be splitted
159}
160
161
162void
164 // Open rerouter dialog
165 GNERerouterDialog(this);
166}
167
168
169std::string
171 return myNet->getMicrosimID();
172}
173
174
175void
177 // draw parent and child lines
179 // draw Rerouter
181 // iterate over additionals and check if drawn
182 for (const auto& interval : getChildAdditionals()) {
183 // if rerouter or their intevals are selected, then draw
186 interval->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(interval) ||
187 (myNet->getViewNet()->getFrontAttributeCarrier() == interval)) {
188 interval->drawGL(s);
189 } else {
190 // if rerouterElements are inspected or selected, then draw
191 for (const auto& rerouterElement : interval->getChildAdditionals()) {
192 if (rerouterElement->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(rerouterElement) ||
193 (myNet->getViewNet()->getFrontAttributeCarrier() == rerouterElement)) {
194 interval->drawGL(s);
195 }
196 }
197 }
198 }
199}
200
201
202std::string
204 switch (key) {
205 case SUMO_ATTR_ID:
206 return getMicrosimID();
207 case SUMO_ATTR_EDGES: {
208 std::vector<std::string> edges;
209 for (const auto& rerouterSymbol : getChildAdditionals()) {
210 if (rerouterSymbol->getTagProperty().isSymbol()) {
211 edges.push_back(rerouterSymbol->getAttribute(SUMO_ATTR_EDGE));
212 }
213 }
214 return toString(edges);
215 }
217 return toString(myPosition);
218 case SUMO_ATTR_NAME:
219 return myAdditionalName;
220 case SUMO_ATTR_PROB:
221 return toString(myProbability);
224 case SUMO_ATTR_VTYPES:
225 return toString(myVTypes);
226 case SUMO_ATTR_OFF:
227 return toString(myOff);
231 return getParametersStr();
232 default:
233 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
234 }
235}
236
237
238double
240 switch (key) {
241 case SUMO_ATTR_PROB:
242 return myProbability;
243 default:
244 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
245 }
246}
247
248
251 return getParametersMap();
252}
253
254
255void
256GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
257 if (value == getAttribute(key)) {
258 return; //avoid needless changes, later logic relies on the fact that attributes have changed
259 }
260 switch (key) {
261 // special case for lanes due rerouter Symbols
262 case SUMO_ATTR_EDGES:
263 // rebuild rerouter Symbols
264 rebuildRerouterSymbols(value, undoList);
265 break;
266 case SUMO_ATTR_ID:
268 case SUMO_ATTR_NAME:
269 case SUMO_ATTR_PROB:
271 case SUMO_ATTR_VTYPES:
272 case SUMO_ATTR_OFF:
275 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
276 break;
277 default:
278 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
279 }
280}
281
282
283bool
284GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
285 switch (key) {
286 case SUMO_ATTR_ID:
287 return isValidAdditionalID(value);
288 case SUMO_ATTR_EDGES:
289 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
291 return canParse<Position>(value);
292 case SUMO_ATTR_NAME:
294 case SUMO_ATTR_PROB:
295 return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
297 return canParse<SUMOTime>(value);
298 case SUMO_ATTR_VTYPES:
299 if (value.empty()) {
300 return true;
301 } else {
303 }
304 case SUMO_ATTR_OFF:
305 return canParse<bool>(value);
307 return canParse<bool>(value);
309 return areParametersValid(value);
310 default:
311 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
312 }
313}
314
315
316std::string
318 return getTagStr() + ": " + getID();
319}
320
321
322std::string
324 return getTagStr();
325}
326
327// ===========================================================================
328// private
329// ===========================================================================
330
331void
332GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
333 switch (key) {
334 case SUMO_ATTR_EDGES:
335 throw InvalidArgument(getTagStr() + " cannot be edited");
336 case SUMO_ATTR_ID:
337 // update microsimID
338 setMicrosimID(value);
339 break;
341 myPosition = parse<Position>(value);
342 // update boundary (except for template)
343 if (getID().size() > 0) {
345 }
346 break;
347 case SUMO_ATTR_NAME:
348 myAdditionalName = value;
349 break;
350 case SUMO_ATTR_PROB:
351 myProbability = parse<double>(value);
352 break;
354 myTimeThreshold = parse<SUMOTime>(value);
355 break;
356 case SUMO_ATTR_VTYPES:
357 myVTypes = parse<std::vector<std::string> >(value);
358 break;
359 case SUMO_ATTR_OFF:
360 myOff = parse<bool>(value);
361 break;
363 if (parse<bool>(value)) {
365 } else {
367 }
368 break;
370 setParametersStr(value);
371 break;
372 default:
373 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
374 }
375}
376
377
378void
380 // update position
381 myPosition = moveResult.shapeToUpdate.front();
382 // update geometry
384}
385
386
387void
389 undoList->begin(GUIIcon::REROUTER, "position of " + getTagStr());
390 undoList->changeAttribute(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front())));
391 undoList->end();
392}
393
394
395void
396GNERerouter::rebuildRerouterSymbols(const std::string& value, GNEUndoList* undoList) {
397 undoList->begin(GUIIcon::REROUTER, ("change " + getTagStr() + " attribute").c_str());
398 // drop all additional children
399 while (getChildAdditionals().size() > 0) {
400 undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
401 }
402 // get edge vector
403 const std::vector<GNEEdge*> edges = parse<std::vector<GNEEdge*> >(myNet, value);
404 // create new VSS Symbols
405 for (const auto& edge : edges) {
406 // create VSS Symbol
407 GNEAdditional* VSSSymbol = new GNERerouterSymbol(this, edge);
408 // add it using GNEChange_Additional
409 myNet->getViewNet()->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
410 }
411 undoList->end();
412}
413
414
415/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
@ GLO_REROUTER
a Rerouter
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
@ SUMO_TAG_REROUTER
A rerouter.
@ SUMO_TAG_PARKING_AREA_REROUTE
entry for an alternative parking zone
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_EDGE
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_OFF
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_HALTING_TIME_THRESHOLD
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_NAME
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:78
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:48
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
std::string myAdditionalName
name of additional
void drawSquaredAdditional(const GUIVisualizationSettings &s, const Position &pos, const double size, GUITexture texture, GUITexture selectedTexture) const
draw squared additional
Boundary myAdditionalBoundary
Additional Boundary.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
move operation
move result
PositionVector shapeToUpdate
shape to update (edited in moveElement)
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
void addGLObjectIntoGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1245
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1257
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
Dialog for edit rerouters.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
SUMOTime myTimeThreshold
attribute to configure activation time threshold
Definition: GNERerouter.h:149
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
double getAttributeDouble(SumoXMLAttr key) const
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
const Parameterised::Map & getACParametersMap() const
get parameters map
void rebuildRerouterSymbols(const std::string &value, GNEUndoList *undoList)
rebuild Rerouter Symbols
std::vector< std::string > myVTypes
optional vehicle types for restricting the rerouter
Definition: GNERerouter.h:152
Position myPosition
position of rerouter in view
Definition: GNERerouter.h:140
bool myOff
attribute to enable or disable inactive initially
Definition: GNERerouter.h:146
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Position getPositionInView() const
Returns position of additional in view.
GNERerouter(GNENet *net)
default Constructor
Definition: GNERerouter.cpp:35
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
Definition: GNERerouter.cpp:67
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
double myProbability
probability of rerouter
Definition: GNERerouter.h:143
std::string getParentName() const
Returns the name of the parent object (if any)
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void openAdditionalDialog()
open GNERerouterDialog
~GNERerouter()
Destructor.
Definition: GNERerouter.cpp:62
std::string getAttribute(SumoXMLAttr key) const
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
GNEMoveOperation * getMoveOperation()
get move operation
void updateGeometry()
update pre-computed geometry information
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
void add(GNEChange *command, bool doit=false, bool merge=true)
Add new command, executing it if desired. The new command will be merged with the previous command if...
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:644
GNEUndoList * getUndoList() const
get the undoList object
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void updateSinglePosGeometry(const Position &position, const double rotation)
update position and rotation
const PositionVector & getShape() const
The shape of the additional element.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:141
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
Stores the information about how to visualize structures.
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
An upper class for objects with additional parameters.
Definition: Parameterised.h:41
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
static bool isValidListOfTypeID(const std::string &value)
whether the given string is a valid list of ids for an edge or vehicle type (empty aren't allowed)
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
bool showSubAdditionals() const
check if show sub-additionals
static const double rerouterSize
rerouter size
static const RGBColor connectionColor
connection color