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  // avoid write rerouters without edges
71  if (getAttribute(SUMO_ATTR_EDGES).size() > 0) {
72  device.openTag(SUMO_TAG_REROUTER);
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) {
89  device.writeAttr(SUMO_ATTR_OFF, 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 
109 bool
111  return true;
112 }
113 
114 
116  return "";
117 }
118 
119 
120 void
122  // nothing to fix
123 }
124 
125 
126 bool
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 
149 void
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 
163 Position
165  return myPosition;
166 }
167 
168 
169 void
170 GNERerouter::updateCenteringBoundary(const bool updateGrid) {
171  // remove additional from grid
172  if (updateGrid) {
174  }
175  // now update geometry
176  updateGeometry();
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) {
196  myNet->addGLObjectIntoGrid(this);
197  }
198 }
199 
200 
201 void
202 GNERerouter::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
203  // geometry of this element cannot be splitted
204 }
205 
206 
207 void
209  // Open rerouter dialog
210  GNERerouterDialog(this);
211 }
212 
213 
214 std::string
216  return myNet->getMicrosimID();
217 }
218 
219 
220 void
222  // first check if additional has to be drawn
224  // draw parent and child lines
226  // draw Rerouter
228  // iterate over additionals and check if drawn
229  for (const auto& interval : getChildAdditionals()) {
230  // if rerouter or their intevals are selected, then draw
233  interval->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(interval) ||
234  (myNet->getViewNet()->getFrontAttributeCarrier() == interval)) {
235  interval->drawGL(s);
236  } else {
237  // if rerouterElements are inspected or selected, then draw
238  for (const auto& rerouterElement : interval->getChildAdditionals()) {
239  if (rerouterElement->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(rerouterElement) ||
240  (myNet->getViewNet()->getFrontAttributeCarrier() == rerouterElement)) {
241  interval->drawGL(s);
242  }
243  }
244  }
245  }
246  }
247 }
248 
249 
250 std::string
252  switch (key) {
253  case SUMO_ATTR_ID:
254  return getMicrosimID();
255  case SUMO_ATTR_EDGES: {
256  std::vector<std::string> edges;
257  for (const auto& rerouterSymbol : getChildAdditionals()) {
258  if (rerouterSymbol->getTagProperty().isSymbol()) {
259  edges.push_back(rerouterSymbol->getAttribute(SUMO_ATTR_EDGE));
260  }
261  }
262  return toString(edges);
263  }
264  case SUMO_ATTR_POSITION:
265  return toString(myPosition);
266  case SUMO_ATTR_NAME:
267  return myAdditionalName;
268  case SUMO_ATTR_PROB:
269  return toString(myProbability);
272  case SUMO_ATTR_VTYPES:
273  return toString(myVTypes);
274  case SUMO_ATTR_OFF:
275  return toString(myOff);
276  case SUMO_ATTR_OPTIONAL:
277  return toString(myOptional);
278  case GNE_ATTR_SELECTED:
280  case GNE_ATTR_PARAMETERS:
281  return getParametersStr();
282  default:
283  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
284  }
285 }
286 
287 
288 double
290  switch (key) {
291  case SUMO_ATTR_PROB:
292  return myProbability;
293  default:
294  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
295  }
296 }
297 
298 
299 const Parameterised::Map&
301  return getParametersMap();
302 }
303 
304 
305 void
306 GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
307  if (value == getAttribute(key)) {
308  return; //avoid needless changes, later logic relies on the fact that attributes have changed
309  }
310  switch (key) {
311  // special case for lanes due rerouter Symbols
312  case SUMO_ATTR_EDGES:
313  // rebuild rerouter Symbols
314  rebuildRerouterSymbols(value, undoList);
315  break;
316  case SUMO_ATTR_ID:
317  case SUMO_ATTR_POSITION:
318  case SUMO_ATTR_NAME:
319  case SUMO_ATTR_PROB:
321  case SUMO_ATTR_VTYPES:
322  case SUMO_ATTR_OFF:
323  case SUMO_ATTR_OPTIONAL:
324  case GNE_ATTR_SELECTED:
325  case GNE_ATTR_PARAMETERS:
326  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
327  break;
328  default:
329  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
330  }
331 }
332 
333 
334 bool
335 GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
336  switch (key) {
337  case SUMO_ATTR_ID:
338  return isValidAdditionalID(value);
339  case SUMO_ATTR_EDGES:
340  return canParse<std::vector<GNEEdge*> >(myNet, value, false);
341  case SUMO_ATTR_POSITION:
342  return canParse<Position>(value);
343  case SUMO_ATTR_NAME:
345  case SUMO_ATTR_PROB:
346  return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
348  return canParse<SUMOTime>(value);
349  case SUMO_ATTR_VTYPES:
350  if (value.empty()) {
351  return true;
352  } else {
354  }
355  case SUMO_ATTR_OFF:
356  return canParse<bool>(value);
357  case SUMO_ATTR_OPTIONAL:
358  return canParse<bool>(value);
359  case GNE_ATTR_SELECTED:
360  return canParse<bool>(value);
361  case GNE_ATTR_PARAMETERS:
362  return areParametersValid(value);
363  default:
364  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
365  }
366 }
367 
368 
369 std::string
371  return getTagStr() + ": " + getID();
372 }
373 
374 
375 std::string
377  return getTagStr();
378 }
379 
380 // ===========================================================================
381 // private
382 // ===========================================================================
383 
384 void
385 GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
386  switch (key) {
387  case SUMO_ATTR_EDGES:
388  throw InvalidArgument(getTagStr() + " cannot be edited");
389  case SUMO_ATTR_ID:
390  // update microsimID
391  setAdditionalID(value);
392  break;
393  case SUMO_ATTR_POSITION:
394  myPosition = parse<Position>(value);
395  // update boundary (except for template)
396  if (getID().size() > 0) {
398  }
399  break;
400  case SUMO_ATTR_NAME:
401  myAdditionalName = value;
402  break;
403  case SUMO_ATTR_PROB:
404  myProbability = parse<double>(value);
405  break;
407  myTimeThreshold = parse<SUMOTime>(value);
408  break;
409  case SUMO_ATTR_VTYPES:
410  myVTypes = parse<std::vector<std::string> >(value);
411  break;
412  case SUMO_ATTR_OFF:
413  myOff = parse<bool>(value);
414  break;
415  case SUMO_ATTR_OPTIONAL:
416  myOptional = parse<bool>(value);
417  break;
418  case GNE_ATTR_SELECTED:
419  if (parse<bool>(value)) {
421  } else {
423  }
424  break;
425  case GNE_ATTR_PARAMETERS:
426  setParametersStr(value);
427  break;
428  default:
429  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
430  }
431 }
432 
433 
434 void
436  // update position
437  myPosition = moveResult.shapeToUpdate.front();
438  // update geometry
439  updateGeometry();
440 }
441 
442 
443 void
445  undoList->begin(this, "position of " + getTagStr());
447  undoList->end();
448 }
449 
450 
451 void
452 GNERerouter::rebuildRerouterSymbols(const std::string& value, GNEUndoList* undoList) {
453  undoList->begin(this, ("change " + getTagStr() + " attribute").c_str());
454  // drop all additional children
455  while (getChildAdditionals().size() > 0) {
456  undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
457  }
458  // get edge vector
459  const std::vector<GNEEdge*> edges = parse<std::vector<GNEEdge*> >(myNet, value);
460  // create new VSS Symbols
461  for (const auto& edge : edges) {
462  // create VSS Symbol
463  GNEAdditional* VSSSymbol = new GNERerouterSymbol(this, edge);
464  // add it using GNEChange_Additional
465  myNet->getViewNet()->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
466  }
467  undoList->end();
468 }
469 
470 
471 /****************************************************************************/
@ 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
#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: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:1368
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1378
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2136
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
bool isCurrentlyMovingElements() const
check if an element is being moved
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:747
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:723
const GNEViewNetHelper::EditNetworkElementShapes & getEditNetworkElementShapes() const
get Edit Shape module
Definition: GNEViewNet.cpp:759
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:735
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:477
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 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