Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2024 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),
40myOptional(false),
41myTimeThreshold(0) {
42 // reset default values
43 resetDefaultValues();
44}
45
46
47GNERerouter::GNERerouter(const std::string& id, GNENet* net, const Position& pos, const std::string& name,
48 double probability, bool off, bool optional, SUMOTime timeThreshold, const std::vector<std::string>& vTypes,
49 const Parameterised::Map& parameters) :
51{}, {}, {}, {}, {}, {}),
52Parameterised(parameters),
53myPosition(pos),
54myProbability(probability),
55myOff(off),
56myOptional(optional),
57myTimeThreshold(timeThreshold),
58myVTypes(vTypes) {
59 // update centering boundary without updating grid
60 updateCenteringBoundary(false);
61}
62
63
66
67
68void
70 // avoid write rerouters without edges
71 if (getAttribute(SUMO_ATTR_EDGES).size() > 0) {
73 device.writeAttr(SUMO_ATTR_ID, getID());
76 if (!myAdditionalName.empty()) {
78 }
79 if (myProbability != 1.0) {
81 }
82 if (time2string(myTimeThreshold) != "0.00") {
84 }
85 if (!myVTypes.empty()) {
87 }
88 if (myOff) {
90 }
91 if (myOptional) {
93 }
94 // write all rerouter interval
95 for (const auto& rerouterInterval : getChildAdditionals()) {
96 if (!rerouterInterval->getTagProperty().isSymbol()) {
97 rerouterInterval->writeAdditional(device);
98 }
99 }
100 // write parameters (Always after children to avoid problems with additionals.xsd)
101 writeParams(device);
102 device.closeTag();
103 } else {
104 WRITE_WARNING("Rerouter '" + getID() + TL("' needs at least one edge"));
105 }
106}
107
108
109bool
111 return true;
112}
113
114
116 return "";
117}
118
119
120void
122 // nothing to fix
123}
124
125
126bool
128 // get edit modes
129 const auto& editModes = myNet->getViewNet()->getEditModes();
130 // check if we're in move mode
131 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
133 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
134 // only move the first element
136 } else {
137 return false;
138 }
139}
140
141
144 // return move operation for additional placed in view
145 return new GNEMoveOperation(this, myPosition);
146}
147
148
149void
151 // update additional geometry
153 // update geometries (boundaries of all children)
154 for (const auto& additionalChildren : getChildAdditionals()) {
155 additionalChildren->updateGeometry();
156 for (const auto& rerouterElement : additionalChildren->getChildAdditionals()) {
157 rerouterElement->updateGeometry();
158 }
159 }
160}
161
162
167
168
169void
171 // remove additional from grid
172 if (updateGrid) {
174 }
175 // now update geometry
177 // add shape boundary
179 /*
180 // add positions of all childrens (intervals and symbols)
181 for (const auto& additionalChildren : getChildAdditionals()) {
182 myAdditionalBoundary.add(additionalChildren->getPositionInView());
183 for (const auto& rerouterElement : additionalChildren->getChildAdditionals()) {
184 myAdditionalBoundary.add(rerouterElement->getPositionInView());
185 // special case for parking area rerouter
186 if (rerouterElement->getTagProperty().getTag() == SUMO_TAG_PARKING_AREA_REROUTE) {
187 myAdditionalBoundary.add(rerouterElement->getParentAdditionals().at(1)->getCenteringBoundary());
188 }
189 }
190 }
191 */
192 // grow
194 // add additional into RTREE again
195 if (updateGrid) {
197 }
198}
199
200
201void
202GNERerouter::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
203 // geometry of this element cannot be splitted
204}
205
206
207void
209 // Open rerouter dialog
210 GNERerouterDialog(this);
211}
212
213
214std::string
216 return myNet->getMicrosimID();
217}
218
219
220void
222 const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
223 // first check if additional has to be drawn
225 // draw parent and child lines
227 // draw Rerouter
229 // iterate over additionals and check if drawn
230 for (const auto& interval : getChildAdditionals()) {
231 // if rerouter or their intevals are selected, then draw
233 isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
234 interval->isAttributeCarrierSelected() || inspectedElements.isACInspected(interval) ||
235 (myNet->getViewNet()->getFrontAttributeCarrier() == interval)) {
236 interval->drawGL(s);
237 } else {
238 // if rerouterElements are inspected or selected, then draw
239 for (const auto& rerouterElement : interval->getChildAdditionals()) {
240 if (rerouterElement->isAttributeCarrierSelected() || inspectedElements.isACInspected(rerouterElement) ||
241 (myNet->getViewNet()->getFrontAttributeCarrier() == rerouterElement)) {
242 interval->drawGL(s);
243 }
244 }
245 }
246 }
247 }
248}
249
250
251std::string
253 switch (key) {
254 case SUMO_ATTR_ID:
255 return getMicrosimID();
256 case SUMO_ATTR_EDGES: {
257 std::vector<std::string> edges;
258 for (const auto& rerouterSymbol : getChildAdditionals()) {
259 if (rerouterSymbol->getTagProperty().isSymbol()) {
260 edges.push_back(rerouterSymbol->getAttribute(SUMO_ATTR_EDGE));
261 }
262 }
263 return toString(edges);
264 }
266 return toString(myPosition);
267 case SUMO_ATTR_NAME:
268 return myAdditionalName;
269 case SUMO_ATTR_PROB:
270 return toString(myProbability);
273 case SUMO_ATTR_VTYPES:
274 return toString(myVTypes);
275 case SUMO_ATTR_OFF:
276 return toString(myOff);
278 return toString(myOptional);
282 return getParametersStr();
283 default:
284 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
285 }
286}
287
288
289double
291 switch (key) {
292 case SUMO_ATTR_PROB:
293 return myProbability;
294 default:
295 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
296 }
297}
298
299
304
305
306void
307GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
308 if (value == getAttribute(key)) {
309 return; //avoid needless changes, later logic relies on the fact that attributes have changed
310 }
311 switch (key) {
312 // special case for lanes due rerouter Symbols
313 case SUMO_ATTR_EDGES:
314 // rebuild rerouter Symbols
315 rebuildRerouterSymbols(value, undoList);
316 break;
317 case SUMO_ATTR_ID:
319 case SUMO_ATTR_NAME:
320 case SUMO_ATTR_PROB:
322 case SUMO_ATTR_VTYPES:
323 case SUMO_ATTR_OFF:
327 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
328 break;
329 default:
330 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
331 }
332}
333
334
335bool
336GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
337 switch (key) {
338 case SUMO_ATTR_ID:
339 return isValidAdditionalID(value);
340 case SUMO_ATTR_EDGES:
341 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
343 return canParse<Position>(value);
344 case SUMO_ATTR_NAME:
346 case SUMO_ATTR_PROB:
347 return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
349 return canParse<SUMOTime>(value);
350 case SUMO_ATTR_VTYPES:
351 if (value.empty()) {
352 return true;
353 } else {
355 }
356 case SUMO_ATTR_OFF:
357 return canParse<bool>(value);
359 return canParse<bool>(value);
361 return canParse<bool>(value);
363 return areParametersValid(value);
364 default:
365 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
366 }
367}
368
369
370std::string
372 return getTagStr() + ": " + getID();
373}
374
375
376std::string
378 return getTagStr();
379}
380
381// ===========================================================================
382// private
383// ===========================================================================
384
385void
386GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
387 switch (key) {
388 case SUMO_ATTR_EDGES:
389 throw InvalidArgument(getTagStr() + " cannot be edited");
390 case SUMO_ATTR_ID:
391 // update microsimID
392 setAdditionalID(value);
393 break;
395 myPosition = parse<Position>(value);
396 // update boundary (except for template)
397 if (getID().size() > 0) {
399 }
400 break;
401 case SUMO_ATTR_NAME:
402 myAdditionalName = value;
403 break;
404 case SUMO_ATTR_PROB:
405 myProbability = parse<double>(value);
406 break;
408 myTimeThreshold = parse<SUMOTime>(value);
409 break;
410 case SUMO_ATTR_VTYPES:
411 myVTypes = parse<std::vector<std::string> >(value);
412 break;
413 case SUMO_ATTR_OFF:
414 myOff = parse<bool>(value);
415 break;
417 myOptional = parse<bool>(value);
418 break;
420 if (parse<bool>(value)) {
422 } else {
424 }
425 break;
427 setParametersStr(value);
428 break;
429 default:
430 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
431 }
432}
433
434
435void
437 // update position
438 myPosition = moveResult.shapeToUpdate.front();
439 // update geometry
441}
442
443
444void
446 undoList->begin(this, "position of " + getTagStr());
448 undoList->end();
449}
450
451
452void
453GNERerouter::rebuildRerouterSymbols(const std::string& value, GNEUndoList* undoList) {
454 undoList->begin(this, ("change " + getTagStr() + " attribute").c_str());
455 // drop all additional children
456 while (getChildAdditionals().size() > 0) {
457 undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
458 }
459 // get edge vector
460 const std::vector<GNEEdge*> edges = parse<std::vector<GNEEdge*> >(myNet, value);
461 // create new VSS Symbols
462 for (const auto& edge : edges) {
463 // create VSS Symbol
464 GNEAdditional* VSSSymbol = new GNERerouterSymbol(this, edge);
465 // add it using GNEChange_Additional
466 myNet->getViewNet()->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
467 }
468 undoList->end();
469}
470
471
472/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
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
#define WRITE_WARNING(msg)
Definition MsgHandler.h:295
#define TL(string)
Definition MsgHandler.h:315
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:69
@ SUMO_TAG_REROUTER
A rerouter.
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_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:343
An Element which don't belong to GNENet but has influence in the simulation.
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 (instead of GUIGlObjectStorage)
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
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
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:1386
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1396
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2155
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 GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
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.
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
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 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