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-2023 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),
40myTimeThreshold(0) {
41 // reset default values
42 resetDefaultValues();
43}
44
45
46GNERerouter::GNERerouter(const std::string& id, GNENet* net, const Position& pos, const std::string& name,
47 double probability, bool off, SUMOTime timeThreshold, const std::vector<std::string>& vTypes,
48 const Parameterised::Map& parameters) :
50{}, {}, {}, {}, {}, {}),
51Parameterised(parameters),
52myPosition(pos),
53myProbability(probability),
54myOff(off),
55myTimeThreshold(timeThreshold),
56myVTypes(vTypes) {
57 // update centering boundary without updating grid
58 updateCenteringBoundary(false);
59}
60
61
64
65
66void
69 device.writeAttr(SUMO_ATTR_ID, getID());
72 if (!myAdditionalName.empty()) {
74 }
75 if (myProbability != 1.0) {
77 }
78 if (time2string(myTimeThreshold) != "0.00") {
80 }
81 if (!myVTypes.empty()) {
83 }
84 if (myOff) {
86 }
87 // write all rerouter interval
88 for (const auto& rerouterInterval : getChildAdditionals()) {
89 if (!rerouterInterval->getTagProperty().isSymbol()) {
90 rerouterInterval->writeAdditional(device);
91 }
92 }
93 // write parameters (Always after children to avoid problems with additionals.xsd)
94 writeParams(device);
95 device.closeTag();
96}
97
98
99bool
101 return true;
102}
103
104
106 return "";
107}
108
109
110void
112 // nothing to fix
113}
114
115
118 // return move operation for additional placed in view
119 return new GNEMoveOperation(this, myPosition);
120}
121
122
123void
125 // update additional geometry
127 // update geometries (boundaries of all children)
128 for (const auto& additionalChildren : getChildAdditionals()) {
129 additionalChildren->updateGeometry();
130 for (const auto& rerouterElement : additionalChildren->getChildAdditionals()) {
131 rerouterElement->updateGeometry();
132 }
133 }
134}
135
136
141
142
143void
145 // remove additional from grid
146 if (updateGrid) {
148 }
149 // now update geometry
151 // add shape boundary
153 // add positions of all childrens (intervals and symbols)
154 for (const auto& additionalChildren : getChildAdditionals()) {
155 myAdditionalBoundary.add(additionalChildren->getPositionInView());
156 for (const auto& rerouterElement : additionalChildren->getChildAdditionals()) {
157 myAdditionalBoundary.add(rerouterElement->getPositionInView());
158 // special case for parking area rerouter
159 if (rerouterElement->getTagProperty().getTag() == SUMO_TAG_PARKING_AREA_REROUTE) {
160 myAdditionalBoundary.add(rerouterElement->getParentAdditionals().at(1)->getPositionInView());
161 }
162 }
163 }
164 // grow
166 // add additional into RTREE again
167 if (updateGrid) {
169 }
170}
171
172
173void
174GNERerouter::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
175 // geometry of this element cannot be splitted
176}
177
178
179void
181 // Open rerouter dialog
182 GNERerouterDialog(this);
183}
184
185
186std::string
188 return myNet->getMicrosimID();
189}
190
191
192void
194 // draw parent and child lines
196 // draw Rerouter
198 // iterate over additionals and check if drawn
199 for (const auto& interval : getChildAdditionals()) {
200 // if rerouter or their intevals are selected, then draw
203 interval->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(interval) ||
204 (myNet->getViewNet()->getFrontAttributeCarrier() == interval)) {
205 interval->drawGL(s);
206 } else {
207 // if rerouterElements are inspected or selected, then draw
208 for (const auto& rerouterElement : interval->getChildAdditionals()) {
209 if (rerouterElement->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(rerouterElement) ||
210 (myNet->getViewNet()->getFrontAttributeCarrier() == rerouterElement)) {
211 interval->drawGL(s);
212 }
213 }
214 }
215 }
216}
217
218
219std::string
221 switch (key) {
222 case SUMO_ATTR_ID:
223 return getMicrosimID();
224 case SUMO_ATTR_EDGES: {
225 std::vector<std::string> edges;
226 for (const auto& rerouterSymbol : getChildAdditionals()) {
227 if (rerouterSymbol->getTagProperty().isSymbol()) {
228 edges.push_back(rerouterSymbol->getAttribute(SUMO_ATTR_EDGE));
229 }
230 }
231 return toString(edges);
232 }
234 return toString(myPosition);
235 case SUMO_ATTR_NAME:
236 return myAdditionalName;
237 case SUMO_ATTR_PROB:
238 return toString(myProbability);
241 case SUMO_ATTR_VTYPES:
242 return toString(myVTypes);
243 case SUMO_ATTR_OFF:
244 return toString(myOff);
248 return getParametersStr();
249 default:
250 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
251 }
252}
253
254
255double
257 switch (key) {
258 case SUMO_ATTR_PROB:
259 return myProbability;
260 default:
261 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
262 }
263}
264
265
270
271
272void
273GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
274 if (value == getAttribute(key)) {
275 return; //avoid needless changes, later logic relies on the fact that attributes have changed
276 }
277 switch (key) {
278 // special case for lanes due rerouter Symbols
279 case SUMO_ATTR_EDGES:
280 // rebuild rerouter Symbols
281 rebuildRerouterSymbols(value, undoList);
282 break;
283 case SUMO_ATTR_ID:
285 case SUMO_ATTR_NAME:
286 case SUMO_ATTR_PROB:
288 case SUMO_ATTR_VTYPES:
289 case SUMO_ATTR_OFF:
292 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
293 break;
294 default:
295 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
296 }
297}
298
299
300bool
301GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
302 switch (key) {
303 case SUMO_ATTR_ID:
304 return isValidAdditionalID(value);
305 case SUMO_ATTR_EDGES:
306 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
308 return canParse<Position>(value);
309 case SUMO_ATTR_NAME:
311 case SUMO_ATTR_PROB:
312 return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
314 return canParse<SUMOTime>(value);
315 case SUMO_ATTR_VTYPES:
316 if (value.empty()) {
317 return true;
318 } else {
320 }
321 case SUMO_ATTR_OFF:
322 return canParse<bool>(value);
324 return canParse<bool>(value);
326 return areParametersValid(value);
327 default:
328 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
329 }
330}
331
332
333std::string
335 return getTagStr() + ": " + getID();
336}
337
338
339std::string
341 return getTagStr();
342}
343
344// ===========================================================================
345// private
346// ===========================================================================
347
348void
349GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
350 switch (key) {
351 case SUMO_ATTR_EDGES:
352 throw InvalidArgument(getTagStr() + " cannot be edited");
353 case SUMO_ATTR_ID:
354 // update microsimID
355 setMicrosimID(value);
356 break;
358 myPosition = parse<Position>(value);
359 // update boundary (except for template)
360 if (getID().size() > 0) {
362 }
363 break;
364 case SUMO_ATTR_NAME:
365 myAdditionalName = value;
366 break;
367 case SUMO_ATTR_PROB:
368 myProbability = parse<double>(value);
369 break;
371 myTimeThreshold = parse<SUMOTime>(value);
372 break;
373 case SUMO_ATTR_VTYPES:
374 myVTypes = parse<std::vector<std::string> >(value);
375 break;
376 case SUMO_ATTR_OFF:
377 myOff = parse<bool>(value);
378 break;
380 if (parse<bool>(value)) {
382 } else {
384 }
385 break;
387 setParametersStr(value);
388 break;
389 default:
390 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
391 }
392}
393
394
395void
397 // update position
398 myPosition = moveResult.shapeToUpdate.front();
399 // update geometry
401}
402
403
404void
406 undoList->begin(GUIIcon::REROUTER, "position of " + getTagStr());
407 undoList->changeAttribute(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front())));
408 undoList->end();
409}
410
411
412void
413GNERerouter::rebuildRerouterSymbols(const std::string& value, GNEUndoList* undoList) {
414 undoList->begin(GUIIcon::REROUTER, ("change " + getTagStr() + " attribute").c_str());
415 // drop all additional children
416 while (getChildAdditionals().size() > 0) {
417 undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
418 }
419 // get edge vector
420 const std::vector<GNEEdge*> edges = parse<std::vector<GNEEdge*> >(myNet, value);
421 // create new VSS Symbols
422 for (const auto& edge : edges) {
423 // create VSS Symbol
424 GNEAdditional* VSSSymbol = new GNERerouterSymbol(this, edge);
425 // add it using GNEChange_Additional
426 myNet->getViewNet()->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
427 }
428 undoList->end();
429}
430
431
432/****************************************************************************/
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
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.
@ SUMO_TAG_PARKING_AREA_REROUTE
entry for an alternative parking zone
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_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:78
Boundary & grow(double by)
extends the boundary by the given amount
Definition Boundary.cpp:300
An Element which don't belong to GNENet but has influence in the simulation.
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
const std::string getID() const
get ID (all Attribute Carriers have one)
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:1248
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1260
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2030
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 writed into XML (must be reimplemented in all detector chi...
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)
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
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...
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
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.
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.
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 showSubAdditionals() const
check if show sub-additionals
static const double rerouterSize
rerouter size
static const RGBColor connectionColor
connection color