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, const std::string& filename, 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, filename, SUMO_TAG_REROUTER, 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
178 // Open rerouter dialog
179 GNERerouterDialog(this);
180}
181
182
183std::string
185 return myNet->getMicrosimID();
186}
187
188
189void
191 const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
192 // first check if additional has to be drawn
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
202 isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
203 interval->isAttributeCarrierSelected() || inspectedElements.isACInspected(interval) ||
204 interval->isMarkedForDrawingFront()) {
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() || inspectedElements.isACInspected(rerouterElement) ||
210 rerouterElement->isMarkedForDrawingFront()) {
211 interval->drawGL(s);
212 }
213 }
214 }
215 }
216 }
217}
218
219
220std::string
222 switch (key) {
223 case SUMO_ATTR_ID:
224 return getMicrosimID();
225 case SUMO_ATTR_EDGES: {
226 std::vector<std::string> edges;
227 for (const auto& rerouterSymbol : getChildAdditionals()) {
228 if (rerouterSymbol->getTagProperty()->isSymbol()) {
229 edges.push_back(rerouterSymbol->getAttribute(SUMO_ATTR_EDGE));
230 }
231 }
232 return toString(edges);
233 }
234 case SUMO_ATTR_NAME:
235 return myAdditionalName;
236 case SUMO_ATTR_PROB:
237 return toString(myProbability);
240 case SUMO_ATTR_VTYPES:
241 return toString(myVTypes);
242 case SUMO_ATTR_OFF:
243 return toString(myOff);
245 return toString(myOptional);
246 default:
248 }
249}
250
251
252double
254 switch (key) {
255 case SUMO_ATTR_PROB:
256 return myProbability;
257 default:
259 }
260}
261
262
267
268
273
274
275void
276GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
277 if (value == getAttribute(key)) {
278 return; //avoid needless changes, later logic relies on the fact that attributes have changed
279 }
280 switch (key) {
281 // special case for lanes due rerouter Symbols
282 case SUMO_ATTR_EDGES:
283 // rebuild rerouter Symbols
284 rebuildRerouterSymbols(value, undoList);
285 break;
286 case SUMO_ATTR_ID:
287 case SUMO_ATTR_NAME:
288 case SUMO_ATTR_PROB:
290 case SUMO_ATTR_VTYPES:
291 case SUMO_ATTR_OFF:
293 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
294 break;
295 default:
296 myMoveElementView->setMovingAttribute(key, value, undoList);
297 break;
298 }
299}
300
301
302bool
303GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
304 switch (key) {
305 case SUMO_ATTR_ID:
306 return isValidAdditionalID(value);
307 case SUMO_ATTR_EDGES:
308 return canParse<std::vector<GNEEdge*> >(myNet, value, false);
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);
325 default:
326 return myMoveElementView->isMovingAttributeValid(key, value);
327 }
328}
329
330
331std::string
333 return getTagStr() + ": " + getID();
334}
335
336
337std::string
339 return getTagStr();
340}
341
342// ===========================================================================
343// private
344// ===========================================================================
345
346void
347GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
348 switch (key) {
349 case SUMO_ATTR_EDGES:
350 throw InvalidArgument(getTagStr() + " cannot be edited");
351 case SUMO_ATTR_ID:
352 // update microsimID
353 setAdditionalID(value);
354 break;
355 case SUMO_ATTR_NAME:
356 myAdditionalName = value;
357 break;
358 case SUMO_ATTR_PROB:
359 myProbability = parse<double>(value);
360 break;
362 myTimeThreshold = parse<SUMOTime>(value);
363 break;
364 case SUMO_ATTR_VTYPES:
365 myVTypes = parse<std::vector<std::string> >(value);
366 break;
367 case SUMO_ATTR_OFF:
368 myOff = parse<bool>(value);
369 break;
371 myOptional = parse<bool>(value);
372 break;
373 default:
375 break;
376 }
377 // update boundary (except for template)
378 if (getID().size() > 0) {
380 }
381}
382
383
384void
385GNERerouter::rebuildRerouterSymbols(const std::string& value, GNEUndoList* undoList) {
386 undoList->begin(this, ("change " + getTagStr() + " attribute").c_str());
387 // drop all additional children
388 while (getChildAdditionals().size() > 0) {
389 undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
390 }
391 // get edge vector
392 const std::vector<GNEEdge*> edges = parse<std::vector<GNEEdge*> >(myNet, value);
393 // create new VSS Symbols
394 for (const auto& edge : edges) {
395 // create VSS Symbol
396 GNEAdditional* VSSSymbol = new GNERerouterSymbol(this, edge);
397 // add it using GNEChange_Additional
398 myNet->getViewNet()->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
399 }
400 undoList->end();
401}
402
403
404/****************************************************************************/
@ 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
const std::string getID() const
get ID (all Attribute Carriers have one)
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 & 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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
SUMOTime myTimeThreshold
attribute to configure activation time threshold
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Position getAttributePosition(SumoXMLAttr key) const override
void rebuildRerouterSymbols(const std::string &value, GNEUndoList *undoList)
rebuild Rerouter Symbols
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
bool isAdditionalValid() const
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
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.
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)
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
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)
void openAdditionalDialog()
open GNERerouterDialog
~GNERerouter()
Destructor.
Parameterised * getParameters() override
get parameters associated with this rerouter
void updateGeometry() override
update pre-computed geometry information
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
bool myOptional
attribute to enable or disable request trigger
bool isValid(SumoXMLAttr key, const std::string &value) override
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
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 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)
GNEUndoList * getUndoList() const
get the undoList object
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)
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