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
22
26#include <netedit/GNENet.h>
27#include <netedit/GNEUndoList.h>
28
29#include "GNERerouter.h"
30#include "GNERerouterSymbol.h"
31
32// ===========================================================================
33// member method definitions
34// ===========================================================================
35
36#ifdef _MSC_VER
37#pragma warning(push)
38#pragma warning(disable: 4355) // mask warning about "this" in initializers
39#endif
44
45
46GNERerouter::GNERerouter(const std::string& id, GNENet* net, FileBucket* fileBucket, const Position& pos, const std::string& name,
47 double probability, bool off, bool optional, SUMOTime timeThreshold, const std::vector<std::string>& vTypes,
48 const Parameterised::Map& parameters) :
49 GNEAdditional(id, net, SUMO_TAG_REROUTER, fileBucket, name),
50 GNEAdditionalSquared(this, pos),
51 Parameterised(parameters),
52 myProbability(probability),
53 myOff(off),
54 myOptional(optional),
55 myTimeThreshold(timeThreshold),
56 myVTypes(vTypes) {
57 // update centering boundary without updating grid
59}
60#ifdef _MSC_VER
61#pragma warning(pop)
62#endif
63
64
67
68
73
74
77 return this;
78}
79
80
81const Parameterised*
83 return this;
84}
85
86
87void
89 // avoid write rerouters without edges
90 if (getAttribute(SUMO_ATTR_EDGES).size() > 0) {
92 // write common additional attributes
94 // write move atributes
96 // write specific attributes
98 if (myProbability != 1.0) {
100 }
101 if (time2string(myTimeThreshold) != "0.00") {
103 }
104 if (!myVTypes.empty()) {
106 }
107 if (myOff) {
109 }
110 if (myOptional) {
112 }
113 // write all rerouter interval
114 for (const auto& rerouterInterval : getChildAdditionals()) {
115 if (!rerouterInterval->getTagProperty()->isSymbol()) {
116 rerouterInterval->writeAdditional(device);
117 }
118 }
119 // write parameters (Always after children to avoid problems with additionals.xsd)
120 XMLHelpers::writeParams(device, *this);
121 device.closeTag();
122 } else {
123 WRITE_WARNING("Rerouter '" + getID() + TL("' needs at least one edge"));
124 }
125}
126
127
128bool
130 return true;
131}
132
133
135 return "";
136}
137
138
139void
141 // nothing to fix
142}
143
144
145bool
147 // get edit modes
148 const auto& editModes = myNet->getViewNet()->getEditModes();
149 // check if we're in move mode
150 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
152 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
153 // only move the first element
155 } else {
156 return false;
157 }
158}
159
160
161void
165
166
171
172
173void
176}
177
178
179void
180GNERerouter::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
181 // geometry of this element cannot be splitted
182}
183
184
185void
186GNERerouter::openAdditionalDialog(FXWindow* restoringFocusWindow) {
187 // Open rerouter dialog
188 UNUSED_PARAMETER(restoringFocusWindow);
189 GNERerouterDialog(this);
190}
191
192
193std::string
195 return myNet->getMicrosimID();
196}
197
198
199void
201 const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
202 // first check if additional has to be drawn
204 // draw parent and child lines
206 // draw Rerouter
208 // iterate over additionals and check if drawn
209 for (const auto& interval : getChildAdditionals()) {
210 // if rerouter or their intevals are selected, then draw
212 isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
213 interval->isAttributeCarrierSelected() || inspectedElements.isACInspected(interval) ||
214 interval->isMarkedForDrawingFront()) {
215 interval->drawGL(s);
216 } else {
217 // if rerouterElements are inspected or selected, then draw
218 for (const auto& rerouterElement : interval->getChildAdditionals()) {
219 if (rerouterElement->isAttributeCarrierSelected() || inspectedElements.isACInspected(rerouterElement) ||
220 rerouterElement->isMarkedForDrawingFront()) {
221 interval->drawGL(s);
222 }
223 }
224 }
225 }
226 }
227}
228
229
230std::string
232 switch (key) {
233 case SUMO_ATTR_ID:
234 return getMicrosimID();
235 case SUMO_ATTR_EDGES: {
236 std::vector<std::string> edges;
237 for (const auto& rerouterSymbol : getChildAdditionals()) {
238 if (rerouterSymbol->getTagProperty()->isSymbol()) {
239 edges.push_back(rerouterSymbol->getAttribute(SUMO_ATTR_EDGE));
240 }
241 }
242 return toString(edges);
243 }
244 case SUMO_ATTR_NAME:
245 return myAdditionalName;
246 case SUMO_ATTR_PROB:
247 return toString(myProbability);
250 case SUMO_ATTR_VTYPES:
251 return toString(myVTypes);
252 case SUMO_ATTR_OFF:
253 return toString(myOff);
255 return toString(myOptional);
256 default:
258 }
259}
260
261
262double
264 switch (key) {
265 case SUMO_ATTR_PROB:
266 return myProbability;
267 default:
269 }
270}
271
272
277
278
283
284
285void
286GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
287 if (value == getAttribute(key)) {
288 return; //avoid needless changes, later logic relies on the fact that attributes have changed
289 }
290 switch (key) {
291 // special case for lanes due rerouter Symbols
292 case SUMO_ATTR_EDGES:
293 // rebuild rerouter Symbols
294 rebuildRerouterSymbols(value, undoList);
295 break;
296 case SUMO_ATTR_ID:
297 case SUMO_ATTR_NAME:
298 case SUMO_ATTR_PROB:
300 case SUMO_ATTR_VTYPES:
301 case SUMO_ATTR_OFF:
303 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
304 break;
305 default:
306 myMoveElementView->setMovingAttribute(key, value, undoList);
307 break;
308 }
309}
310
311
312bool
313GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
314 switch (key) {
315 case SUMO_ATTR_ID:
316 return isValidAdditionalID(value);
317 case SUMO_ATTR_EDGES:
318 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
319 case SUMO_ATTR_NAME:
320 return StringUtils::isValidAttribute(value);
321 case SUMO_ATTR_PROB:
322 return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
324 return canParse<SUMOTime>(value);
325 case SUMO_ATTR_VTYPES:
326 if (value.empty()) {
327 return true;
328 } else {
330 }
331 case SUMO_ATTR_OFF:
332 return canParse<bool>(value);
334 return canParse<bool>(value);
335 default:
336 return myMoveElementView->isMovingAttributeValid(key, value);
337 }
338}
339
340
341std::string
343 return getTagStr() + ": " + getID();
344}
345
346
347std::string
349 return getTagStr();
350}
351
352// ===========================================================================
353// private
354// ===========================================================================
355
356void
357GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
358 switch (key) {
359 case SUMO_ATTR_EDGES:
360 throw InvalidArgument(getTagStr() + " cannot be edited");
361 case SUMO_ATTR_ID:
362 // update microsimID
363 setAdditionalID(value);
364 break;
365 case SUMO_ATTR_NAME:
366 myAdditionalName = value;
367 break;
368 case SUMO_ATTR_PROB:
369 myProbability = parse<double>(value);
370 break;
372 myTimeThreshold = parse<SUMOTime>(value);
373 break;
374 case SUMO_ATTR_VTYPES:
375 myVTypes = parse<std::vector<std::string> >(value);
376 break;
377 case SUMO_ATTR_OFF:
378 myOff = parse<bool>(value);
379 break;
381 myOptional = parse<bool>(value);
382 break;
383 default:
385 break;
386 }
387 // update boundary (except for template)
388 if (getID().size() > 0) {
390 }
391}
392
393
394void
395GNERerouter::rebuildRerouterSymbols(const std::string& value, GNEUndoList* undoList) {
396 undoList->begin(this, ("change " + getTagStr() + " attribute").c_str());
397 // drop all additional symbol children
398 std::vector<GNEAdditional*> symbols;
399 for (const auto symbol : getChildAdditionals()) {
400 if (symbol->getTagProperty()->isSymbol()) {
401 symbols.push_back(symbol);
402 }
403 }
404 for (const auto symbol : symbols) {
405 undoList->add(new GNEChange_Additional(symbol, false), true);
406 }
407 // get edge vector
408 const std::vector<GNEEdge*> edges = parse<std::vector<GNEEdge*> >(myNet, value);
409 // create new Rerouter Symbols
410 for (const auto& edge : edges) {
411 // create VSS Symbol
412 GNEAdditional* VSSSymbol = new GNERerouterSymbol(this, edge);
413 // add it using GNEChange_Additional
414 myNet->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
415 }
416 undoList->end();
417}
418
419
420/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNING(msg)
Definition MsgHandler.h:298
#define TL(string)
Definition MsgHandler.h:316
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:107
@ 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:57
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, const bool escape=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
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)
static OutputDevice & writeParams(OutputDevice &device, const Parameterised &params)
write the parameters of the given object as param tags
#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