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 interval->isMarkedForDrawingFront()) {
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 rerouterElement->isMarkedForDrawingFront()) {
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);
280 return getParametersStr();
281 default:
282 return getCommonAttribute(key);
283 }
284}
285
286
287double
289 switch (key) {
290 case SUMO_ATTR_PROB:
291 return myProbability;
292 default:
293 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
294 }
295}
296
297
302
303
304void
305GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
306 if (value == getAttribute(key)) {
307 return; //avoid needless changes, later logic relies on the fact that attributes have changed
308 }
309 switch (key) {
310 // special case for lanes due rerouter Symbols
311 case SUMO_ATTR_EDGES:
312 // rebuild rerouter Symbols
313 rebuildRerouterSymbols(value, undoList);
314 break;
315 case SUMO_ATTR_ID:
317 case SUMO_ATTR_NAME:
318 case SUMO_ATTR_PROB:
320 case SUMO_ATTR_VTYPES:
321 case SUMO_ATTR_OFF:
324 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
325 break;
326 default:
327 setCommonAttribute(key, value, undoList);
328 break;
329 }
330}
331
332
333bool
334GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
335 switch (key) {
336 case SUMO_ATTR_ID:
337 return isValidAdditionalID(value);
338 case SUMO_ATTR_EDGES:
339 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
341 return canParse<Position>(value);
342 case SUMO_ATTR_NAME:
344 case SUMO_ATTR_PROB:
345 return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
347 return canParse<SUMOTime>(value);
348 case SUMO_ATTR_VTYPES:
349 if (value.empty()) {
350 return true;
351 } else {
353 }
354 case SUMO_ATTR_OFF:
355 return canParse<bool>(value);
357 return canParse<bool>(value);
359 return areParametersValid(value);
360 default:
361 return isCommonValid(key, value);
362 }
363}
364
365
366std::string
368 return getTagStr() + ": " + getID();
369}
370
371
372std::string
374 return getTagStr();
375}
376
377// ===========================================================================
378// private
379// ===========================================================================
380
381void
382GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
383 switch (key) {
384 case SUMO_ATTR_EDGES:
385 throw InvalidArgument(getTagStr() + " cannot be edited");
386 case SUMO_ATTR_ID:
387 // update microsimID
388 setAdditionalID(value);
389 break;
391 myPosition = parse<Position>(value);
392 // update boundary (except for template)
393 if (getID().size() > 0) {
395 }
396 break;
397 case SUMO_ATTR_NAME:
398 myAdditionalName = value;
399 break;
400 case SUMO_ATTR_PROB:
401 myProbability = parse<double>(value);
402 break;
404 myTimeThreshold = parse<SUMOTime>(value);
405 break;
406 case SUMO_ATTR_VTYPES:
407 myVTypes = parse<std::vector<std::string> >(value);
408 break;
409 case SUMO_ATTR_OFF:
410 myOff = parse<bool>(value);
411 break;
413 myOptional = parse<bool>(value);
414 break;
416 setParametersStr(value);
417 break;
418 default:
419 setCommonAttribute(key, value);
420 break;
421 }
422}
423
424
425void
427 // update position
428 myPosition = moveResult.shapeToUpdate.front();
429 // update geometry
431}
432
433
434void
436 undoList->begin(this, "position of " + getTagStr());
438 undoList->end();
439}
440
441
442void
443GNERerouter::rebuildRerouterSymbols(const std::string& value, GNEUndoList* undoList) {
444 undoList->begin(this, ("change " + getTagStr() + " attribute").c_str());
445 // drop all additional children
446 while (getChildAdditionals().size() > 0) {
447 undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
448 }
449 // get edge vector
450 const std::vector<GNEEdge*> edges = parse<std::vector<GNEEdge*> >(myNet, value);
451 // create new VSS Symbols
452 for (const auto& edge : edges) {
453 // create VSS Symbol
454 GNEAdditional* VSSSymbol = new GNERerouterSymbol(this, edge);
455 // add it using GNEChange_Additional
456 myNet->getViewNet()->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
457 }
458 undoList->end();
459}
460
461
462/****************************************************************************/
@ 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
@ 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 (more quickly as checking GUIGlObjectStorage)
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
bool isCommonValid(SumoXMLAttr key, const std::string &value)
GNENet * myNet
pointer to net
std::string getCommonAttribute(SumoXMLAttr key) const
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:1390
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1400
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2163
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.
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