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.org/sumo
3 // Copyright (C) 2001-2022 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 std::map<std::string, std::string>()),
39  myProbability(0),
40  myOff(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  const std::string& filename, double probability, bool off, SUMOTime timeThreshold, const std::vector<std::string>& vTypes,
49  const std::map<std::string, std::string>& parameters) :
51 {}, {}, {}, {}, {}, {}, {}, {},
52 parameters),
53 myPosition(pos),
54 myFilename(filename),
55 myProbability(probability),
56 myOff(off),
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 (!myFilename.empty()) {
79  }
80  if (myProbability != 1.0) {
82  }
83  if (time2string(myTimeThreshold) != "0.00") {
85  }
86  if (!myVTypes.empty()) {
88  }
89  if (myOff) {
90  device.writeAttr(SUMO_ATTR_OFF, myOff);
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 
106  // return move operation for additional placed in view
107  return new GNEMoveOperation(this, myPosition);
108 }
109 
110 
111 void
113  // update additional geometry
115  // update geometries (boundaries of all children)
116  for (const auto& additionalChildren : getChildAdditionals()) {
117  additionalChildren->updateGeometry();
118  for (const auto& rerouterElement : additionalChildren->getChildAdditionals()) {
119  rerouterElement->updateGeometry();
120  }
121  }
122 }
123 
124 
125 Position
127  return myPosition;
128 }
129 
130 
131 void
132 GNERerouter::updateCenteringBoundary(const bool updateGrid) {
133  // remove additional from grid
134  if (updateGrid) {
136  }
137  // now update geometry
138  updateGeometry();
139  // add shape boundary
141  // add positions of all childrens (intervals and symbols)
142  for (const auto& additionalChildren : getChildAdditionals()) {
143  myAdditionalBoundary.add(additionalChildren->getPositionInView());
144  for (const auto& rerouterElement : additionalChildren->getChildAdditionals()) {
145  myAdditionalBoundary.add(rerouterElement->getPositionInView());
146  // special case for parking area rerouter
147  if (rerouterElement->getTagProperty().getTag() == SUMO_TAG_PARKING_AREA_REROUTE) {
148  myAdditionalBoundary.add(rerouterElement->getParentAdditionals().at(1)->getPositionInView());
149  }
150  }
151  }
152  // grow
154  // add additional into RTREE again
155  if (updateGrid) {
156  myNet->addGLObjectIntoGrid(this);
157  }
158 }
159 
160 
161 void
162 GNERerouter::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
163  // geometry of this element cannot be splitted
164 }
165 
166 
167 void
169  // Open rerouter dialog
170  GNERerouterDialog(this);
171 }
172 
173 
174 std::string
176  return myNet->getMicrosimID();
177 }
178 
179 
180 void
182  // draw parent and child lines
184  // draw Rerouter
186  // iterate over additionals and check if drawn
187  for (const auto& interval : getChildAdditionals()) {
188  // if rerouter or their intevals are selected, then draw
191  interval->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(interval) ||
192  (myNet->getViewNet()->getFrontAttributeCarrier() == interval)) {
193  interval->drawGL(s);
194  } else {
195  // if rerouterElements are inspected or selected, then draw
196  for (const auto& rerouterElement : interval->getChildAdditionals()) {
197  if (rerouterElement->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(rerouterElement) ||
198  (myNet->getViewNet()->getFrontAttributeCarrier() == rerouterElement)) {
199  interval->drawGL(s);
200  }
201  }
202  }
203  }
204 }
205 
206 
207 std::string
209  switch (key) {
210  case SUMO_ATTR_ID:
211  return getID();
212  case SUMO_ATTR_EDGES: {
213  std::vector<std::string> edges;
214  for (const auto& rerouterSymbol : getChildAdditionals()) {
215  if (rerouterSymbol->getTagProperty().isSymbol()) {
216  edges.push_back(rerouterSymbol->getAttribute(SUMO_ATTR_EDGE));
217  }
218  }
219  return toString(edges);
220  }
221  case SUMO_ATTR_POSITION:
222  return toString(myPosition);
223  case SUMO_ATTR_NAME:
224  return myAdditionalName;
225  case SUMO_ATTR_FILE:
226  return myFilename;
227  case SUMO_ATTR_PROB:
228  return toString(myProbability);
231  case SUMO_ATTR_VTYPES:
232  return toString(myVTypes);
233  case SUMO_ATTR_OFF:
234  return toString(myOff);
235  case GNE_ATTR_SELECTED:
237  case GNE_ATTR_PARAMETERS:
238  return getParametersStr();
239  default:
240  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
241  }
242 }
243 
244 
245 double
247  switch (key) {
248  case SUMO_ATTR_PROB:
249  return myProbability;
250  default:
251  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
252  }
253 }
254 
255 
256 void
257 GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
258  if (value == getAttribute(key)) {
259  return; //avoid needless changes, later logic relies on the fact that attributes have changed
260  }
261  switch (key) {
262  // special case for lanes due rerouter Symbols
263  case SUMO_ATTR_EDGES:
264  // rebuild rerouter Symbols
265  rebuildRerouterSymbols(value, undoList);
266  break;
267  case SUMO_ATTR_ID:
268  case SUMO_ATTR_POSITION:
269  case SUMO_ATTR_NAME:
270  case SUMO_ATTR_FILE:
271  case SUMO_ATTR_PROB:
273  case SUMO_ATTR_VTYPES:
274  case SUMO_ATTR_OFF:
275  case GNE_ATTR_SELECTED:
276  case GNE_ATTR_PARAMETERS:
277  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
278  break;
279  default:
280  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
281  }
282 }
283 
284 
285 bool
286 GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
287  switch (key) {
288  case SUMO_ATTR_ID:
289  return isValidAdditionalID(value);
290  case SUMO_ATTR_EDGES:
291  return canParse<std::vector<GNEEdge*> >(myNet, value, false);
292  case SUMO_ATTR_POSITION:
293  return canParse<Position>(value);
294  case SUMO_ATTR_NAME:
296  case SUMO_ATTR_FILE:
298  case SUMO_ATTR_PROB:
299  return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
301  return canParse<SUMOTime>(value);
302  case SUMO_ATTR_VTYPES:
303  if (value.empty()) {
304  return true;
305  } else {
307  }
308  case SUMO_ATTR_OFF:
309  return canParse<bool>(value);
310  case GNE_ATTR_SELECTED:
311  return canParse<bool>(value);
312  case GNE_ATTR_PARAMETERS:
313  return Parameterised::areParametersValid(value);
314  default:
315  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
316  }
317 }
318 
319 
320 bool
322  return true;
323 }
324 
325 
326 std::string
328  return getTagStr() + ": " + getID();
329 }
330 
331 
332 std::string
334  return getTagStr();
335 }
336 
337 // ===========================================================================
338 // private
339 // ===========================================================================
340 
341 void
342 GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
343  switch (key) {
344  case SUMO_ATTR_EDGES:
345  throw InvalidArgument(getTagStr() + " cannot be edited");
346  case SUMO_ATTR_ID:
347  // update microsimID
348  setMicrosimID(value);
349  break;
350  case SUMO_ATTR_POSITION:
351  myPosition = parse<Position>(value);
352  // update boundary (except for template)
353  if (getID().size() > 0) {
355  }
356  break;
357  case SUMO_ATTR_NAME:
358  myAdditionalName = value;
359  break;
360  case SUMO_ATTR_FILE:
361  myFilename = value;
362  break;
363  case SUMO_ATTR_PROB:
364  myProbability = parse<double>(value);
365  break;
367  myTimeThreshold = parse<SUMOTime>(value);
368  break;
369  case SUMO_ATTR_VTYPES:
370  myVTypes = parse<std::vector<std::string> >(value);
371  break;
372  case SUMO_ATTR_OFF:
373  myOff = parse<bool>(value);
374  break;
375  case GNE_ATTR_SELECTED:
376  if (parse<bool>(value)) {
378  } else {
380  }
381  break;
382  case GNE_ATTR_PARAMETERS:
383  setParametersStr(value);
384  break;
385  default:
386  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
387  }
388 }
389 
390 
391 void
393  // update position
394  myPosition = moveResult.shapeToUpdate.front();
395  // update geometry
396  updateGeometry();
397 }
398 
399 
400 void
402  undoList->begin(GUIIcon::REROUTER, "position of " + getTagStr());
403  undoList->changeAttribute(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front())));
404  undoList->end();
405 }
406 
407 
408 void
409 GNERerouter::rebuildRerouterSymbols(const std::string& value, GNEUndoList* undoList) {
410  undoList->begin(GUIIcon::REROUTER, ("change " + getTagStr() + " attribute").c_str());
411  // drop all additional children
412  while (getChildAdditionals().size() > 0) {
413  undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
414  }
415  // get edge vector
416  const std::vector<GNEEdge*> edges = parse<std::vector<GNEEdge*> >(myNet, value);
417  // create new VSS Symbols
418  for (const auto& edge : edges) {
419  // create VSS Symbol
420  GNEAdditional* VSSSymbol = new GNERerouterSymbol(this, edge);
421  // add it using GNEChange_Additional
422  myNet->getViewNet()->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
423  }
424  undoList->end();
425 }
426 
427 
428 /****************************************************************************/
@ GLO_REROUTER
a Rerouter
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
long long int SUMOTime
Definition: SUMOTime.h:32
@ SUMO_TAG_REROUTER
A rerouter.
@ SUMO_TAG_PARKING_AREA_REROUTE
entry for an alternative parking zone
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_FILE
@ 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_PROB
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:77
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
const std::string & getID() const
get 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.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
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
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:1210
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1222
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
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:155
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
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:158
Position myPosition
position of rerouter in view
Definition: GNERerouter.h:143
bool myOff
attribute to enable or disable inactive initially
Definition: GNERerouter.h:152
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
writte 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 conrrespond attribute are valids
double myProbability
probability of rerouter
Definition: GNERerouter.h:149
std::string getParentName() const
Returns the name of the parent object (if any)
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 isAttributeEnabled(SumoXMLAttr key) const
GNEMoveOperation * getMoveOperation()
get move operation
std::string myFilename
filename of rerouter
Definition: GNERerouter.h:146
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...
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:525
GNEUndoList * getUndoList() const
get the undoList object
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.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
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:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
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|....
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"
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 isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name)
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