Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GNERerouter.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-2025 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 <config.h>
21
22#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
25#include <netedit/GNEViewNet.h>
29
30#include "GNERerouter.h"
31#include "GNERerouterSymbol.h"
32
33// ===========================================================================
34// member method definitions
35// ===========================================================================
36
38 GNEAdditional("", net, "", SUMO_TAG_REROUTER, ""),
39 myProbability(0),
40 myOff(false),
41 myOptional(false),
42 myTimeThreshold(0) {
43}
44
45
46GNERerouter::GNERerouter(const std::string& id, GNENet* net, const std::string& filename, const Position& pos, const std::string& name,
47 double probability, bool off, bool optional, SUMOTime timeThreshold, const std::vector<std::string>& vTypes,
48 const Parameterised::Map& parameters) :
49 GNEAdditional(id, net, filename, SUMO_TAG_REROUTER, name),
50 Parameterised(parameters),
51 myPosition(pos),
52 myProbability(probability),
53 myOff(off),
54 myOptional(optional),
55 myTimeThreshold(timeThreshold),
56 myVTypes(vTypes) {
57 // update centering boundary without updating grid
59}
60
61
64
65
66void
68 // avoid write rerouters without edges
69 if (getAttribute(SUMO_ATTR_EDGES).size() > 0) {
71 device.writeAttr(SUMO_ATTR_ID, getID());
74 if (!myAdditionalName.empty()) {
76 }
77 if (myProbability != 1.0) {
79 }
80 if (time2string(myTimeThreshold) != "0.00") {
82 }
83 if (!myVTypes.empty()) {
85 }
86 if (myOff) {
88 }
89 if (myOptional) {
91 }
92 // write all rerouter interval
93 for (const auto& rerouterInterval : getChildAdditionals()) {
94 if (!rerouterInterval->getTagProperty()->isSymbol()) {
95 rerouterInterval->writeAdditional(device);
96 }
97 }
98 // write parameters (Always after children to avoid problems with additionals.xsd)
99 writeParams(device);
100 device.closeTag();
101 } else {
102 WRITE_WARNING("Rerouter '" + getID() + TL("' needs at least one edge"));
103 }
104}
105
106
107bool
109 return true;
110}
111
112
114 return "";
115}
116
117
118void
120 // nothing to fix
121}
122
123
124bool
126 // get edit modes
127 const auto& editModes = myNet->getViewNet()->getEditModes();
128 // check if we're in move mode
129 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
131 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
132 // only move the first element
134 } else {
135 return false;
136 }
137}
138
139
142 // return move operation for additional placed in view
143 return new GNEMoveOperation(this, myPosition);
144}
145
146
147void
149 // update additional geometry
151 // update geometries (boundaries of all children)
152 for (const auto& additionalChildren : getChildAdditionals()) {
153 additionalChildren->updateGeometry();
154 for (const auto& rerouterElement : additionalChildren->getChildAdditionals()) {
155 rerouterElement->updateGeometry();
156 }
157 }
158}
159
160
165
166
167void
169 // remove additional from grid
170 if (updateGrid) {
172 }
173 // now update geometry
175 // add shape boundary
177 /*
178 // add positions of all childrens (intervals and symbols)
179 for (const auto& additionalChildren : getChildAdditionals()) {
180 myAdditionalBoundary.add(additionalChildren->getPositionInView());
181 for (const auto& rerouterElement : additionalChildren->getChildAdditionals()) {
182 myAdditionalBoundary.add(rerouterElement->getPositionInView());
183 // special case for parking area rerouter
184 if (rerouterElement->getTagProperty()->getTag() == SUMO_TAG_PARKING_AREA_REROUTE) {
185 myAdditionalBoundary.add(rerouterElement->getParentAdditionals().at(1)->getCenteringBoundary());
186 }
187 }
188 }
189 */
190 // grow
192 // add additional into RTREE again
193 if (updateGrid) {
195 }
196}
197
198
199void
200GNERerouter::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
201 // geometry of this element cannot be splitted
202}
203
204
205void
207 // Open rerouter dialog
208 GNERerouterDialog(this);
209}
210
211
212std::string
214 return myNet->getMicrosimID();
215}
216
217
218void
220 const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
221 // first check if additional has to be drawn
223 // draw parent and child lines
225 // draw Rerouter
227 // iterate over additionals and check if drawn
228 for (const auto& interval : getChildAdditionals()) {
229 // if rerouter or their intevals are selected, then draw
231 isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
232 interval->isAttributeCarrierSelected() || inspectedElements.isACInspected(interval) ||
233 interval->isMarkedForDrawingFront()) {
234 interval->drawGL(s);
235 } else {
236 // if rerouterElements are inspected or selected, then draw
237 for (const auto& rerouterElement : interval->getChildAdditionals()) {
238 if (rerouterElement->isAttributeCarrierSelected() || inspectedElements.isACInspected(rerouterElement) ||
239 rerouterElement->isMarkedForDrawingFront()) {
240 interval->drawGL(s);
241 }
242 }
243 }
244 }
245 }
246}
247
248
249std::string
251 switch (key) {
252 case SUMO_ATTR_ID:
253 return getMicrosimID();
254 case SUMO_ATTR_EDGES: {
255 std::vector<std::string> edges;
256 for (const auto& rerouterSymbol : getChildAdditionals()) {
257 if (rerouterSymbol->getTagProperty()->isSymbol()) {
258 edges.push_back(rerouterSymbol->getAttribute(SUMO_ATTR_EDGE));
259 }
260 }
261 return toString(edges);
262 }
264 return toString(myPosition);
265 case SUMO_ATTR_NAME:
266 return myAdditionalName;
267 case SUMO_ATTR_PROB:
268 return toString(myProbability);
271 case SUMO_ATTR_VTYPES:
272 return toString(myVTypes);
273 case SUMO_ATTR_OFF:
274 return toString(myOff);
276 return toString(myOptional);
277 default:
278 return getCommonAttribute(this, key);
279 }
280}
281
282
283double
285 switch (key) {
286 case SUMO_ATTR_PROB:
287 return myProbability;
288 default:
289 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
290 }
291}
292
293
298
299
300void
301GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
302 if (value == getAttribute(key)) {
303 return; //avoid needless changes, later logic relies on the fact that attributes have changed
304 }
305 switch (key) {
306 // special case for lanes due rerouter Symbols
307 case SUMO_ATTR_EDGES:
308 // rebuild rerouter Symbols
309 rebuildRerouterSymbols(value, undoList);
310 break;
311 case SUMO_ATTR_ID:
313 case SUMO_ATTR_NAME:
314 case SUMO_ATTR_PROB:
316 case SUMO_ATTR_VTYPES:
317 case SUMO_ATTR_OFF:
319 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
320 break;
321 default:
322 setCommonAttribute(key, value, undoList);
323 break;
324 }
325}
326
327
328bool
329GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
330 switch (key) {
331 case SUMO_ATTR_ID:
332 return isValidAdditionalID(value);
333 case SUMO_ATTR_EDGES:
334 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
336 return canParse<Position>(value);
337 case SUMO_ATTR_NAME:
339 case SUMO_ATTR_PROB:
340 return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
342 return canParse<SUMOTime>(value);
343 case SUMO_ATTR_VTYPES:
344 if (value.empty()) {
345 return true;
346 } else {
348 }
349 case SUMO_ATTR_OFF:
350 return canParse<bool>(value);
352 return canParse<bool>(value);
353 default:
354 return isCommonValid(key, value);
355 }
356}
357
358
359std::string
361 return getTagStr() + ": " + getID();
362}
363
364
365std::string
367 return getTagStr();
368}
369
370// ===========================================================================
371// private
372// ===========================================================================
373
374void
375GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
376 switch (key) {
377 case SUMO_ATTR_EDGES:
378 throw InvalidArgument(getTagStr() + " cannot be edited");
379 case SUMO_ATTR_ID:
380 // update microsimID
381 setAdditionalID(value);
382 break;
384 myPosition = parse<Position>(value);
385 // update boundary (except for template)
386 if (getID().size() > 0) {
388 }
389 break;
390 case SUMO_ATTR_NAME:
391 myAdditionalName = value;
392 break;
393 case SUMO_ATTR_PROB:
394 myProbability = parse<double>(value);
395 break;
397 myTimeThreshold = parse<SUMOTime>(value);
398 break;
399 case SUMO_ATTR_VTYPES:
400 myVTypes = parse<std::vector<std::string> >(value);
401 break;
402 case SUMO_ATTR_OFF:
403 myOff = parse<bool>(value);
404 break;
406 myOptional = parse<bool>(value);
407 break;
408 default:
409 setCommonAttribute(this, key, value);
410 break;
411 }
412}
413
414
415void
417 // update position
418 myPosition = moveResult.shapeToUpdate.front();
419 // update geometry
421}
422
423
424void
426 undoList->begin(this, "position of " + getTagStr());
428 undoList->end();
429}
430
431
432void
433GNERerouter::rebuildRerouterSymbols(const std::string& value, GNEUndoList* undoList) {
434 undoList->begin(this, ("change " + getTagStr() + " attribute").c_str());
435 // drop all additional children
436 while (getChildAdditionals().size() > 0) {
437 undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
438 }
439 // get edge vector
440 const std::vector<GNEEdge*> edges = parse<std::vector<GNEEdge*> >(myNet, value);
441 // create new VSS Symbols
442 for (const auto& edge : edges) {
443 // create VSS Symbol
444 GNEAdditional* VSSSymbol = new GNERerouterSymbol(this, edge);
445 // add it using GNEChange_Additional
446 myNet->getViewNet()->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
447 }
448 undoList->end();
449}
450
451
452/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNING(msg)
Definition MsgHandler.h:287
#define TL(string)
Definition MsgHandler.h:305
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
@ SUMO_TAG_REROUTER
A rerouter.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_OFF
@ SUMO_ATTR_HALTING_TIME_THRESHOLD
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_NAME
@ SUMO_ATTR_OPTIONAL
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
Boundary & grow(double by)
extends the boundary by the given amount
Definition Boundary.cpp:340
bool isValidAdditionalID(const std::string &value) const
check if a new additional ID is valid
void setAdditionalID(const std::string &newID)
set additional ID
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 (used only by additionals placed over grid)
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
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
std::string getCommonAttribute(const Parameterised *parameterised, SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
bool isCommonValid(SumoXMLAttr key, const std::string &value) const
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
const GNEHierarchicalContainerChildren< 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:1442
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1452
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2194
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
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
Position myPosition
position of rerouter in view
bool isAdditionalValid() const
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
bool myOff
attribute to enable or disable inactive initially
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Position getPositionInView() const
Returns position of additional in view.
GNERerouter(GNENet *net)
default Constructor
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
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
std::string getParentName() const
Returns the name of the parent object.
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void openAdditionalDialog()
open GNERerouterDialog
~GNERerouter()
Destructor.
std::string getAttribute(SumoXMLAttr key) const
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
bool myOptional
attribute to enable or disable request trigger
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
bool checkDrawMoveContour() const
check if draw move contour (red)
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...
const GUIGlObject * getGUIGlObjectFront() const
get front GUIGLObject or a pointer to nullptr
bool isCurrentlyMovingElements() const
check if an element is being moved
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
const GNEViewNetHelper::EditNetworkElementShapes & getEditNetworkElementShapes() const
get Edit Shape module
GNEViewNetHelper::InspectedElements & getInspectedElements()
get inspected elements
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
bool checkOverLockedElement(const GUIGlObject *GLObject, const bool isSelected) const
check if given element is locked (used for drawing select and delete contour)
GNEUndoList * getUndoList() const
get the undoList object
const GNEViewNetHelper::ViewObjectsSelector & getViewObjectsSelector() const
get objects under cursor
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.
Stores the information about how to visualize structures.
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
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.
std::map< std::string, std::string > Map
parameters map
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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 showAdditionals() const
check if additionals has to be drawn
GNENetworkElement * getEditedNetworkElement() const
pointer to edited network element
bool showSubAdditionals() const
check if show sub-additionals
static const double rerouterSize
rerouter size
static const RGBColor connectionColor
connection color