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-2025 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
38
39
40GNERerouter::GNERerouter(const std::string& id, GNENet* net, FileBucket* fileBucket, const Position& pos, const std::string& name,
41 double probability, bool off, bool optional, SUMOTime timeThreshold, const std::vector<std::string>& vTypes,
42 const Parameterised::Map& parameters) :
43 GNEAdditional(id, net, SUMO_TAG_REROUTER, fileBucket, name),
44 GNEAdditionalSquared(this, pos),
45 Parameterised(parameters),
46 myProbability(probability),
47 myOff(off),
48 myOptional(optional),
49 myTimeThreshold(timeThreshold),
50 myVTypes(vTypes) {
51 // update centering boundary without updating grid
53}
54
55
58
59
64
65
68 return this;
69}
70
71
72const Parameterised*
74 return this;
75}
76
77
78void
80 // avoid write rerouters without edges
81 if (getAttribute(SUMO_ATTR_EDGES).size() > 0) {
83 // write common additional attributes
85 // write move atributes
87 // write specific attributes
89 if (myProbability != 1.0) {
91 }
92 if (time2string(myTimeThreshold) != "0.00") {
94 }
95 if (!myVTypes.empty()) {
97 }
98 if (myOff) {
100 }
101 if (myOptional) {
103 }
104 // write all rerouter interval
105 for (const auto& rerouterInterval : getChildAdditionals()) {
106 if (!rerouterInterval->getTagProperty()->isSymbol()) {
107 rerouterInterval->writeAdditional(device);
108 }
109 }
110 // write parameters (Always after children to avoid problems with additionals.xsd)
111 writeParams(device);
112 device.closeTag();
113 } else {
114 WRITE_WARNING("Rerouter '" + getID() + TL("' needs at least one edge"));
115 }
116}
117
118
119bool
121 return true;
122}
123
124
126 return "";
127}
128
129
130void
132 // nothing to fix
133}
134
135
136bool
138 // get edit modes
139 const auto& editModes = myNet->getViewNet()->getEditModes();
140 // check if we're in move mode
141 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
143 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
144 // only move the first element
146 } else {
147 return false;
148 }
149}
150
151
152void
156
157
162
163
164void
167}
168
169
170void
171GNERerouter::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
172 // geometry of this element cannot be splitted
173}
174
175
176void
177GNERerouter::openAdditionalDialog(FXWindow* restoringFocusWindow) {
178 // Open rerouter dialog
179 UNUSED_PARAMETER(restoringFocusWindow);
180 GNERerouterDialog(this);
181}
182
183
184std::string
186 return myNet->getMicrosimID();
187}
188
189
190void
192 const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
193 // first check if additional has to be drawn
195 // draw parent and child lines
197 // draw Rerouter
199 // iterate over additionals and check if drawn
200 for (const auto& interval : getChildAdditionals()) {
201 // if rerouter or their intevals are selected, then draw
203 isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
204 interval->isAttributeCarrierSelected() || inspectedElements.isACInspected(interval) ||
205 interval->isMarkedForDrawingFront()) {
206 interval->drawGL(s);
207 } else {
208 // if rerouterElements are inspected or selected, then draw
209 for (const auto& rerouterElement : interval->getChildAdditionals()) {
210 if (rerouterElement->isAttributeCarrierSelected() || inspectedElements.isACInspected(rerouterElement) ||
211 rerouterElement->isMarkedForDrawingFront()) {
212 interval->drawGL(s);
213 }
214 }
215 }
216 }
217 }
218}
219
220
221std::string
223 switch (key) {
224 case SUMO_ATTR_ID:
225 return getMicrosimID();
226 case SUMO_ATTR_EDGES: {
227 std::vector<std::string> edges;
228 for (const auto& rerouterSymbol : getChildAdditionals()) {
229 if (rerouterSymbol->getTagProperty()->isSymbol()) {
230 edges.push_back(rerouterSymbol->getAttribute(SUMO_ATTR_EDGE));
231 }
232 }
233 return toString(edges);
234 }
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);
246 return toString(myOptional);
247 default:
249 }
250}
251
252
253double
255 switch (key) {
256 case SUMO_ATTR_PROB:
257 return myProbability;
258 default:
260 }
261}
262
263
268
269
274
275
276void
277GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
278 if (value == getAttribute(key)) {
279 return; //avoid needless changes, later logic relies on the fact that attributes have changed
280 }
281 switch (key) {
282 // special case for lanes due rerouter Symbols
283 case SUMO_ATTR_EDGES:
284 // rebuild rerouter Symbols
285 rebuildRerouterSymbols(value, undoList);
286 break;
287 case SUMO_ATTR_ID:
288 case SUMO_ATTR_NAME:
289 case SUMO_ATTR_PROB:
291 case SUMO_ATTR_VTYPES:
292 case SUMO_ATTR_OFF:
294 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
295 break;
296 default:
297 myMoveElementView->setMovingAttribute(key, value, undoList);
298 break;
299 }
300}
301
302
303bool
304GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
305 switch (key) {
306 case SUMO_ATTR_ID:
307 return isValidAdditionalID(value);
308 case SUMO_ATTR_EDGES:
309 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
310 case SUMO_ATTR_NAME:
312 case SUMO_ATTR_PROB:
313 return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
315 return canParse<SUMOTime>(value);
316 case SUMO_ATTR_VTYPES:
317 if (value.empty()) {
318 return true;
319 } else {
321 }
322 case SUMO_ATTR_OFF:
323 return canParse<bool>(value);
325 return canParse<bool>(value);
326 default:
327 return myMoveElementView->isMovingAttributeValid(key, value);
328 }
329}
330
331
332std::string
334 return getTagStr() + ": " + getID();
335}
336
337
338std::string
340 return getTagStr();
341}
342
343// ===========================================================================
344// private
345// ===========================================================================
346
347void
348GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
349 switch (key) {
350 case SUMO_ATTR_EDGES:
351 throw InvalidArgument(getTagStr() + " cannot be edited");
352 case SUMO_ATTR_ID:
353 // update microsimID
354 setAdditionalID(value);
355 break;
356 case SUMO_ATTR_NAME:
357 myAdditionalName = value;
358 break;
359 case SUMO_ATTR_PROB:
360 myProbability = parse<double>(value);
361 break;
363 myTimeThreshold = parse<SUMOTime>(value);
364 break;
365 case SUMO_ATTR_VTYPES:
366 myVTypes = parse<std::vector<std::string> >(value);
367 break;
368 case SUMO_ATTR_OFF:
369 myOff = parse<bool>(value);
370 break;
372 myOptional = parse<bool>(value);
373 break;
374 default:
376 break;
377 }
378 // update boundary (except for template)
379 if (getID().size() > 0) {
381 }
382}
383
384
385void
386GNERerouter::rebuildRerouterSymbols(const std::string& value, GNEUndoList* undoList) {
387 undoList->begin(this, ("change " + getTagStr() + " attribute").c_str());
388 // drop all additional children
389 while (getChildAdditionals().size() > 0) {
390 undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
391 }
392 // get edge vector
393 const std::vector<GNEEdge*> edges = parse<std::vector<GNEEdge*> >(myNet, value);
394 // create new VSS Symbols
395 for (const auto& edge : edges) {
396 // create VSS Symbol
397 GNEAdditional* VSSSymbol = new GNERerouterSymbol(this, edge);
398 // add it using GNEChange_Additional
399 myNet->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
400 }
401 undoList->end();
402}
403
404
405/****************************************************************************/
@ 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:46
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 & 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.
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