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.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 {}, {}, {}, {}, {}, {}),
38 myProbability(0),
39 myOff(false),
40 myOptional(false),
41 myTimeThreshold(0) {
42  // reset default values
43  resetDefaultValues();
44 }
45 
46 
47 GNERerouter::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 {}, {}, {}, {}, {}, {}),
52 Parameterised(parameters),
53 myPosition(pos),
54 myProbability(probability),
55 myOff(off),
56 myOptional(optional),
57 myTimeThreshold(timeThreshold),
58 myVTypes(vTypes) {
59  // update centering boundary without updating grid
60  updateCenteringBoundary(false);
61 }
62 
63 
65 }
66 
67 
68 void
70  device.openTag(SUMO_TAG_REROUTER);
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) {
87  device.writeAttr(SUMO_ATTR_OFF, 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 }
102 
103 
104 bool
106  return true;
107 }
108 
109 
111  return "";
112 }
113 
114 
115 void
117  // nothing to fix
118 }
119 
120 
121 bool
123  // get edit modes
124  const auto& editModes = myNet->getViewNet()->getEditModes();
125  // check if we're in move mode
126  if (!myNet->getViewNet()->isMovingElement() && editModes.isCurrentSupermodeNetwork() &&
127  (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
128  // only move the first element
130  } else {
131  return false;
132  }
133 }
134 
135 
138  // return move operation for additional placed in view
139  return new GNEMoveOperation(this, myPosition);
140 }
141 
142 
143 void
145  // update additional geometry
147  // update geometries (boundaries of all children)
148  for (const auto& additionalChildren : getChildAdditionals()) {
149  additionalChildren->updateGeometry();
150  for (const auto& rerouterElement : additionalChildren->getChildAdditionals()) {
151  rerouterElement->updateGeometry();
152  }
153  }
154 }
155 
156 
157 Position
159  return myPosition;
160 }
161 
162 
163 void
164 GNERerouter::updateCenteringBoundary(const bool updateGrid) {
165  // remove additional from grid
166  if (updateGrid) {
168  }
169  // now update geometry
170  updateGeometry();
171  // add shape boundary
173  /*
174  // add positions of all childrens (intervals and symbols)
175  for (const auto& additionalChildren : getChildAdditionals()) {
176  myAdditionalBoundary.add(additionalChildren->getPositionInView());
177  for (const auto& rerouterElement : additionalChildren->getChildAdditionals()) {
178  myAdditionalBoundary.add(rerouterElement->getPositionInView());
179  // special case for parking area rerouter
180  if (rerouterElement->getTagProperty().getTag() == SUMO_TAG_PARKING_AREA_REROUTE) {
181  myAdditionalBoundary.add(rerouterElement->getParentAdditionals().at(1)->getCenteringBoundary());
182  }
183  }
184  }
185  */
186  // grow
188  // add additional into RTREE again
189  if (updateGrid) {
190  myNet->addGLObjectIntoGrid(this);
191  }
192 }
193 
194 
195 void
196 GNERerouter::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
197  // geometry of this element cannot be splitted
198 }
199 
200 
201 void
203  // Open rerouter dialog
204  GNERerouterDialog(this);
205 }
206 
207 
208 std::string
210  return myNet->getMicrosimID();
211 }
212 
213 
214 void
216  // draw parent and child lines
218  // draw Rerouter
220  // iterate over additionals and check if drawn
221  for (const auto& interval : getChildAdditionals()) {
222  // if rerouter or their intevals are selected, then draw
225  interval->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(interval) ||
226  (myNet->getViewNet()->getFrontAttributeCarrier() == interval)) {
227  interval->drawGL(s);
228  } else {
229  // if rerouterElements are inspected or selected, then draw
230  for (const auto& rerouterElement : interval->getChildAdditionals()) {
231  if (rerouterElement->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(rerouterElement) ||
232  (myNet->getViewNet()->getFrontAttributeCarrier() == rerouterElement)) {
233  interval->drawGL(s);
234  }
235  }
236  }
237  }
238 }
239 
240 
241 std::string
243  switch (key) {
244  case SUMO_ATTR_ID:
245  return getMicrosimID();
246  case SUMO_ATTR_EDGES: {
247  std::vector<std::string> edges;
248  for (const auto& rerouterSymbol : getChildAdditionals()) {
249  if (rerouterSymbol->getTagProperty().isSymbol()) {
250  edges.push_back(rerouterSymbol->getAttribute(SUMO_ATTR_EDGE));
251  }
252  }
253  return toString(edges);
254  }
255  case SUMO_ATTR_POSITION:
256  return toString(myPosition);
257  case SUMO_ATTR_NAME:
258  return myAdditionalName;
259  case SUMO_ATTR_PROB:
260  return toString(myProbability);
263  case SUMO_ATTR_VTYPES:
264  return toString(myVTypes);
265  case SUMO_ATTR_OFF:
266  return toString(myOff);
267  case SUMO_ATTR_OPTIONAL:
268  return toString(myOptional);
269  case GNE_ATTR_SELECTED:
271  case GNE_ATTR_PARAMETERS:
272  return getParametersStr();
273  default:
274  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
275  }
276 }
277 
278 
279 double
281  switch (key) {
282  case SUMO_ATTR_PROB:
283  return myProbability;
284  default:
285  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
286  }
287 }
288 
289 
290 const Parameterised::Map&
292  return getParametersMap();
293 }
294 
295 
296 void
297 GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
298  if (value == getAttribute(key)) {
299  return; //avoid needless changes, later logic relies on the fact that attributes have changed
300  }
301  switch (key) {
302  // special case for lanes due rerouter Symbols
303  case SUMO_ATTR_EDGES:
304  // rebuild rerouter Symbols
305  rebuildRerouterSymbols(value, undoList);
306  break;
307  case SUMO_ATTR_ID:
308  case SUMO_ATTR_POSITION:
309  case SUMO_ATTR_NAME:
310  case SUMO_ATTR_PROB:
312  case SUMO_ATTR_VTYPES:
313  case SUMO_ATTR_OFF:
314  case SUMO_ATTR_OPTIONAL:
315  case GNE_ATTR_SELECTED:
316  case GNE_ATTR_PARAMETERS:
317  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
318  break;
319  default:
320  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
321  }
322 }
323 
324 
325 bool
326 GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
327  switch (key) {
328  case SUMO_ATTR_ID:
329  return isValidAdditionalID(value);
330  case SUMO_ATTR_EDGES:
331  return canParse<std::vector<GNEEdge*> >(myNet, value, false);
332  case SUMO_ATTR_POSITION:
333  return canParse<Position>(value);
334  case SUMO_ATTR_NAME:
336  case SUMO_ATTR_PROB:
337  return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
339  return canParse<SUMOTime>(value);
340  case SUMO_ATTR_VTYPES:
341  if (value.empty()) {
342  return true;
343  } else {
345  }
346  case SUMO_ATTR_OFF:
347  return canParse<bool>(value);
348  case SUMO_ATTR_OPTIONAL:
349  return canParse<bool>(value);
350  case GNE_ATTR_SELECTED:
351  return canParse<bool>(value);
352  case GNE_ATTR_PARAMETERS:
353  return areParametersValid(value);
354  default:
355  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
356  }
357 }
358 
359 
360 std::string
362  return getTagStr() + ": " + getID();
363 }
364 
365 
366 std::string
368  return getTagStr();
369 }
370 
371 // ===========================================================================
372 // private
373 // ===========================================================================
374 
375 void
376 GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
377  switch (key) {
378  case SUMO_ATTR_EDGES:
379  throw InvalidArgument(getTagStr() + " cannot be edited");
380  case SUMO_ATTR_ID:
381  // update microsimID
382  setAdditionalID(value);
383  break;
384  case SUMO_ATTR_POSITION:
385  myPosition = parse<Position>(value);
386  // update boundary (except for template)
387  if (getID().size() > 0) {
389  }
390  break;
391  case SUMO_ATTR_NAME:
392  myAdditionalName = value;
393  break;
394  case SUMO_ATTR_PROB:
395  myProbability = parse<double>(value);
396  break;
398  myTimeThreshold = parse<SUMOTime>(value);
399  break;
400  case SUMO_ATTR_VTYPES:
401  myVTypes = parse<std::vector<std::string> >(value);
402  break;
403  case SUMO_ATTR_OFF:
404  myOff = parse<bool>(value);
405  break;
406  case SUMO_ATTR_OPTIONAL:
407  myOptional = parse<bool>(value);
408  break;
409  case GNE_ATTR_SELECTED:
410  if (parse<bool>(value)) {
412  } else {
414  }
415  break;
416  case GNE_ATTR_PARAMETERS:
417  setParametersStr(value);
418  break;
419  default:
420  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
421  }
422 }
423 
424 
425 void
427  // update position
428  myPosition = moveResult.shapeToUpdate.front();
429  // update geometry
430  updateGeometry();
431 }
432 
433 
434 void
436  undoList->begin(this, "position of " + getTagStr());
438  undoList->end();
439 }
440 
441 
442 void
443 GNERerouter::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:35
@ GLO_REROUTER
a Rerouter
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
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:319
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:49
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:1247
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1256
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2022
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:180
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:183
Position myPosition
position of rerouter in view
Definition: GNERerouter.h:168
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
Definition: GNERerouter.h:174
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:69
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:171
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.
Definition: GNERerouter.cpp:64
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
Definition: GNERerouter.h:177
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 attribute carrier or a pointer to nullptr
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:703
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:715
bool isMovingElement() const
check if an element is being moved
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
Definition: GNEViewNet.cpp:468
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:143
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
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