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-2026 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
24#include <netedit/GNENet.h>
25#include <netedit/GNEUndoList.h>
26
27#include "GNERerouter.h"
28#include "GNERerouterSymbol.h"
29
30// ===========================================================================
31// member method definitions
32// ===========================================================================
33
34#ifdef _MSC_VER
35#pragma warning(push)
36#pragma warning(disable: 4355) // mask warning about "this" in initializers
37#endif
42
43
44GNERerouter::GNERerouter(const std::string& id, GNENet* net, FileBucket* fileBucket, const Position& pos, const std::string& name,
45 double probability, bool off, bool optional, SUMOTime timeThreshold, const std::vector<std::string>& vTypes,
46 const Parameterised::Map& parameters) :
47 GNEAdditional(id, net, SUMO_TAG_REROUTER, fileBucket, name),
48 GNEAdditionalSquared(this, pos),
49 Parameterised(parameters),
50 myProbability(probability),
51 myOff(off),
52 myOptional(optional),
53 myTimeThreshold(timeThreshold),
54 myVTypes(vTypes) {
55 // update centering boundary without updating grid
57}
58#ifdef _MSC_VER
59#pragma warning(pop)
60#endif
61
62
65
66
71
72
75 return this;
76}
77
78
79const Parameterised*
81 return this;
82}
83
84
85void
87 // avoid write rerouters without edges
88 if (getAttribute(SUMO_ATTR_EDGES).size() > 0) {
90 // write common additional attributes
92 // write move atributes
94 // write specific attributes
96 if (myProbability != 1.0) {
98 }
99 if (time2string(myTimeThreshold) != "0.00") {
101 }
102 if (!myVTypes.empty()) {
104 }
105 if (myOff) {
107 }
108 if (myOptional) {
110 }
111 // write all rerouter interval
112 for (const auto& rerouterInterval : getChildAdditionals()) {
113 if (!rerouterInterval->getTagProperty()->isSymbol()) {
114 rerouterInterval->writeAdditional(device);
115 }
116 }
117 // write parameters (Always after children to avoid problems with additionals.xsd)
118 writeParams(device);
119 device.closeTag();
120 } else {
121 WRITE_WARNING("Rerouter '" + getID() + TL("' needs at least one edge"));
122 }
123}
124
125
126bool
128 return true;
129}
130
131
133 return "";
134}
135
136
137void
139 // nothing to fix
140}
141
142
143bool
145 // get edit modes
146 const auto& editModes = myNet->getViewNet()->getEditModes();
147 // check if we're in move mode
148 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
150 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
151 // only move the first element
153 } else {
154 return false;
155 }
156}
157
158
159void
163
164
169
170
171void
174}
175
176
177void
178GNERerouter::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
179 // geometry of this element cannot be splitted
180}
181
182
183void
184GNERerouter::openAdditionalDialog(FXWindow* restoringFocusWindow) {
185 // Open rerouter dialog
186 UNUSED_PARAMETER(restoringFocusWindow);
187 GNERerouterDialog(this);
188}
189
190
191std::string
193 return myNet->getMicrosimID();
194}
195
196
197void
199 const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
200 // first check if additional has to be drawn
202 // draw parent and child lines
204 // draw Rerouter
206 // iterate over additionals and check if drawn
207 for (const auto& interval : getChildAdditionals()) {
208 // if rerouter or their intevals are selected, then draw
210 isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
211 interval->isAttributeCarrierSelected() || inspectedElements.isACInspected(interval) ||
212 interval->isMarkedForDrawingFront()) {
213 interval->drawGL(s);
214 } else {
215 // if rerouterElements are inspected or selected, then draw
216 for (const auto& rerouterElement : interval->getChildAdditionals()) {
217 if (rerouterElement->isAttributeCarrierSelected() || inspectedElements.isACInspected(rerouterElement) ||
218 rerouterElement->isMarkedForDrawingFront()) {
219 interval->drawGL(s);
220 }
221 }
222 }
223 }
224 }
225}
226
227
228std::string
230 switch (key) {
231 case SUMO_ATTR_ID:
232 return getMicrosimID();
233 case SUMO_ATTR_EDGES: {
234 std::vector<std::string> edges;
235 for (const auto& rerouterSymbol : getChildAdditionals()) {
236 if (rerouterSymbol->getTagProperty()->isSymbol()) {
237 edges.push_back(rerouterSymbol->getAttribute(SUMO_ATTR_EDGE));
238 }
239 }
240 return toString(edges);
241 }
242 case SUMO_ATTR_NAME:
243 return myAdditionalName;
244 case SUMO_ATTR_PROB:
245 return toString(myProbability);
248 case SUMO_ATTR_VTYPES:
249 return toString(myVTypes);
250 case SUMO_ATTR_OFF:
251 return toString(myOff);
253 return toString(myOptional);
254 default:
256 }
257}
258
259
260double
262 switch (key) {
263 case SUMO_ATTR_PROB:
264 return myProbability;
265 default:
267 }
268}
269
270
275
276
281
282
283void
284GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
285 if (value == getAttribute(key)) {
286 return; //avoid needless changes, later logic relies on the fact that attributes have changed
287 }
288 switch (key) {
289 // special case for lanes due rerouter Symbols
290 case SUMO_ATTR_EDGES:
291 // rebuild rerouter Symbols
292 rebuildRerouterSymbols(value, undoList);
293 break;
294 case SUMO_ATTR_ID:
295 case SUMO_ATTR_NAME:
296 case SUMO_ATTR_PROB:
298 case SUMO_ATTR_VTYPES:
299 case SUMO_ATTR_OFF:
301 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
302 break;
303 default:
304 myMoveElementView->setMovingAttribute(key, value, undoList);
305 break;
306 }
307}
308
309
310bool
311GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
312 switch (key) {
313 case SUMO_ATTR_ID:
314 return isValidAdditionalID(value);
315 case SUMO_ATTR_EDGES:
316 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
317 case SUMO_ATTR_NAME:
319 case SUMO_ATTR_PROB:
320 return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
322 return canParse<SUMOTime>(value);
323 case SUMO_ATTR_VTYPES:
324 if (value.empty()) {
325 return true;
326 } else {
328 }
329 case SUMO_ATTR_OFF:
330 return canParse<bool>(value);
332 return canParse<bool>(value);
333 default:
334 return myMoveElementView->isMovingAttributeValid(key, value);
335 }
336}
337
338
339std::string
341 return getTagStr() + ": " + getID();
342}
343
344
345std::string
347 return getTagStr();
348}
349
350// ===========================================================================
351// private
352// ===========================================================================
353
354void
355GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
356 switch (key) {
357 case SUMO_ATTR_EDGES:
358 throw InvalidArgument(getTagStr() + " cannot be edited");
359 case SUMO_ATTR_ID:
360 // update microsimID
361 setAdditionalID(value);
362 break;
363 case SUMO_ATTR_NAME:
364 myAdditionalName = value;
365 break;
366 case SUMO_ATTR_PROB:
367 myProbability = parse<double>(value);
368 break;
370 myTimeThreshold = parse<SUMOTime>(value);
371 break;
372 case SUMO_ATTR_VTYPES:
373 myVTypes = parse<std::vector<std::string> >(value);
374 break;
375 case SUMO_ATTR_OFF:
376 myOff = parse<bool>(value);
377 break;
379 myOptional = parse<bool>(value);
380 break;
381 default:
383 break;
384 }
385 // update boundary (except for template)
386 if (getID().size() > 0) {
388 }
389}
390
391
392void
393GNERerouter::rebuildRerouterSymbols(const std::string& value, GNEUndoList* undoList) {
394 undoList->begin(this, ("change " + getTagStr() + " attribute").c_str());
395 // drop all additional symbol children
396 std::vector<GNEAdditional*> symbols;
397 for (const auto symbol : getChildAdditionals()) {
398 if (symbol->getTagProperty()->isSymbol()) {
399 symbols.push_back(symbol);
400 }
401 }
402 for (const auto symbol : symbols) {
403 undoList->add(new GNEChange_Additional(symbol, false), true);
404 }
405 // get edge vector
406 const std::vector<GNEEdge*> edges = parse<std::vector<GNEEdge*> >(myNet, value);
407 // create new Rerouter Symbols
408 for (const auto& edge : edges) {
409 // create VSS Symbol
410 GNEAdditional* VSSSymbol = new GNERerouterSymbol(this, edge);
411 // add it using GNEChange_Additional
412 myNet->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
413 }
414 undoList->end();
415}
416
417
418/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
#define TL(string)
Definition MsgHandler.h:304
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
@ 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
@ SUMO_ATTR_HALTING_TIME_THRESHOLD
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_NAME
@ SUMO_ATTR_OPTIONAL
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.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
std::string myAdditionalName
name of additional
void writeAdditionalAttributes(OutputDevice &device) const
write common additional attributes
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
void updatedSquaredGeometry()
updated squared geometry
Position myPosOverView
position over view
void updatedSquaredCenteringBoundary(const bool updateGrid)
updated squared centering boundary
GNEMoveElementView * myMoveElementView
move element over view
void drawSquaredAdditional(const GUIVisualizationSettings &s, const double size, GUITexture texture, GUITexture selectedTexture) const
draw squared additional
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
const std::string getID() const override
get ID (all Attribute Carriers have one)
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
const GNEHierarchicalContainerChildren< GNEAdditional * > & getChildAdditionals() const
return child additionals
Position getMovingAttributePosition(SumoXMLAttr key) const override
get moving attribute position
void writeMoveAttributes(OutputDevice &device) const
write move attributes
void setMovingAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
set moving attribute (using undo-list)
PositionVector getMovingAttributePositionVector(SumoXMLAttr key) const override
get moving attribute positionVector
double getMovingAttributeDouble(SumoXMLAttr key) const override
get moving attribute double
std::string getMovingAttribute(SumoXMLAttr key) const override
get moving attribute
bool isMovingAttributeValid(SumoXMLAttr key, const std::string &value) const override
check if the given moving attribute is valid
GNEUndoList * getUndoList() const
get undo list(used for simplify code)
Definition GNENet.cpp:156
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
SUMOTime myTimeThreshold
attribute to configure activation time threshold
Position getPositionInView() const override
Returns position of additional in view.
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
Position getAttributePosition(SumoXMLAttr key) const override
void rebuildRerouterSymbols(const std::string &value, GNEUndoList *undoList)
rebuild Rerouter Symbols
void openAdditionalDialog(FXWindow *restoringFocusWindow) override
open GNERerouterDialog
double getAttributeDouble(SumoXMLAttr key) const override
std::vector< std::string > myVTypes
optional vehicle types for restricting the rerouter
std::string getAttribute(SumoXMLAttr key) const override
std::string getAdditionalProblem() const override
return a string with the current additional problem (must be reimplemented in all detector children)
bool myOff
attribute to enable or disable inactive initially
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
GNERerouter(GNENet *net)
default Constructor
bool checkDrawMoveContour() const override
check if draw move contour (red)
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
double myProbability
probability of rerouter
void fixAdditionalProblem() override
fix additional problem (must be reimplemented in all detector children)
~GNERerouter()
Destructor.
Parameterised * getParameters() override
get parameters associated with this rerouter
void updateGeometry() override
update pre-computed geometry information
bool isAdditionalValid() const override
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
bool myOptional
attribute to enable or disable request trigger
bool isValid(SumoXMLAttr key, const std::string &value) override
std::string getParentName() const override
Returns the name of the parent object.
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this rerouter
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
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)
const GNEViewNetHelper::ViewObjectsSelector & getViewObjectsSelector() const
get objects under cursor
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
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.
std::map< std::string, std::string > Map
parameters map
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
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)
#define UNUSED_PARAMETER(x)
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