Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNERerouterInterval.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#include <config.h>
21
22#include <netedit/GNENet.h>
23#include <netedit/GNEUndoList.h>
24#include <netedit/GNEViewNet.h>
26
27#include "GNERerouterInterval.h"
28
29// ===========================================================================
30// member method definitions
31// ===========================================================================
32
36
37
39 GNEAdditional(rerouterParent, SUMO_TAG_INTERVAL, ""),
40 myBegin(begin),
41 myEnd(end) {
42 // set parents
43 setParent<GNEAdditional*>(rerouterParent);
44 // update boundary of rerouter parent
45 rerouterParent->updateCenteringBoundary(true);
46}
47
48
50
51
52void
54 // avoid write empty intervals
55 if (getChildAdditionals().size() > 0) {
59 // write all rerouter interval
60 for (const auto& rerouterElement : getChildAdditionals()) {
61 rerouterElement->writeAdditional(device);
62 }
63 device.closeTag();
64 }
65}
66
67
68bool
70 return true;
71}
72
73
74std::string
78
79
80void
82 // nothing to fix
83}
84
85
86bool
88 return false;
89}
90
91
94 // rerouter intervals cannot be moved
95 return nullptr;
96}
97
98
99void
101 // update centering boundary (needed for centering)
103 // update geometries (boundaries of all children)
104 for (const auto& rerouterElement : getChildAdditionals()) {
105 rerouterElement->updateGeometry();
106 }
107}
108
109
112 // get rerouter parent position
113 Position signPosition = getParentAdditionals().front()->getPositionInView();
114 // set position depending of indexes
115 signPosition.add(4.5, (getDrawPositionIndex() * -1) + 1, 0);
116 // return signPosition
117 return signPosition;
118}
119
120
121void
123 // nothing to do
124}
125
126
127void
128GNERerouterInterval::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
129 // geometry of this element cannot be splitted
130}
131
132
133std::string
135 return getParentAdditionals().at(0)->getID();
136}
137
138
139void
141 const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
142 // draw rerouter interval as listed attribute
146 // iterate over additionals and check if drawn
147 for (const auto& rerouterElement : getChildAdditionals()) {
148 // if rerouter or their child is selected, then draw
149 if (isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
150 rerouterElement->isAttributeCarrierSelected() || inspectedElements.isACInspected(rerouterElement) ||
151 rerouterElement->isMarkedForDrawingFront()) {
152 rerouterElement->drawGL(s);
153 }
154 }
155}
156
157
158std::string
160 switch (key) {
161 case SUMO_ATTR_ID:
162 return getParentAdditionals().front()->getID();
163 case SUMO_ATTR_BEGIN:
164 return time2string(myBegin);
165 case SUMO_ATTR_END:
166 return time2string(myEnd);
167 case GNE_ATTR_PARENT:
168 return getParentAdditionals().at(0)->getID();
169 default:
170 return getCommonAttribute(this, key);
171 }
172}
173
174
175double
177 switch (key) {
178 case SUMO_ATTR_BEGIN:
179 return STEPS2TIME(myBegin);
180 case SUMO_ATTR_END:
181 return STEPS2TIME(myEnd);
182 default:
183 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
184 }
185}
186
187
192
193
194void
195GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
196 if (value == getAttribute(key)) {
197 return; //avoid needless changes, later logic relies on the fact that attributes have changed
198 }
199 switch (key) {
200 case SUMO_ATTR_BEGIN:
201 case SUMO_ATTR_END:
202 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
203 break;
204 default:
205 setCommonAttribute(key, value, undoList);
206 break;
207 }
208}
209
210
211bool
212GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {
213 switch (key) {
214 case SUMO_ATTR_BEGIN:
215 if (canParse<SUMOTime>(value)) {
216 const auto begin = parse<SUMOTime>(value);
217 if (begin < 0) {
218 return false;
219 } else {
220 return (begin <= myEnd);
221 }
222 } else {
223 return false;
224 }
225 case SUMO_ATTR_END:
226 if (canParse<SUMOTime>(value)) {
227 const auto end = parse<SUMOTime>(value);
228 if (end < 0) {
229 return false;
230 } else {
231 return (myBegin <= end);
232 }
233 } else {
234 return false;
235 }
236 default:
237 return isCommonValid(key, value);
238 }
239}
240
241
242std::string
244 return getTagStr();
245}
246
247
248std::string
252
253// ===========================================================================
254// private
255// ===========================================================================
256
257void
258GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
259 switch (key) {
260 case SUMO_ATTR_BEGIN:
261 myBegin = parse<SUMOTime>(value);
262 break;
263 case SUMO_ATTR_END:
264 myEnd = parse<SUMOTime>(value);
265 break;
266 default:
267 setCommonAttribute(this, key, value);
268 break;
269 }
270}
271
272
273void
275 // nothing to do
276}
277
278
279void
281 // nothing to do
282}
283
284/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
#define STEPS2TIME(x)
Definition SUMOTime.h:55
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_PARENT
parent of an additional element
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
virtual void updateCenteringBoundary(const bool updateGrid)=0
update centering boundary (implies change in RTREE)
void drawListedAdditional(const GUIVisualizationSettings &s, const Position &parentPosition, const double offsetX, const double extraOffsetY, const RGBColor baseCol, const RGBColor textCol, GUITexture texture, const std::string text) const
draw listed additional
int getDrawPositionIndex() const
get draw position index (used in rerouters and VSS)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
std::string getCommonAttribute(const Parameterised *parameterised, SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
bool isCommonValid(SumoXMLAttr key, const std::string &value) const
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const GNEHierarchicalContainerChildren< GNEAdditional * > & getChildAdditionals() const
return child additionals
move operation
move result
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
Position getPositionInView() const
Returns position of additional in view.
GNEMoveOperation * getMoveOperation()
get move operation
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
bool checkDrawMoveContour() const
check if draw move contour (red)
std::string getParentName() const
Returns the name of the parent object.
std::string getAttribute(SumoXMLAttr key) const
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
double getAttributeDouble(SumoXMLAttr key) const
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
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)
method for setting the attribute and letting the object perform additional changes
SUMOTime myEnd
end timeStep
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
SUMOTime myBegin
begin timeStep
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void updateGeometry()
update pre-computed geometry information
const Parameterised::Map & getACParametersMap() const
get parameters map
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
GNERerouterInterval(GNENet *net)
default constructor
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
bool isAdditionalValid() const
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
GNEViewNetHelper::InspectedElements & getInspectedElements()
get inspected elements
Stores the information about how to visualize structures.
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.
std::map< std::string, std::string > Map
parameters map
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
void add(const Position &pos)
Adds the given position to this one.
Definition Position.h:129
static const RGBColor YELLOW
Definition RGBColor.h:191
static const RGBColor RED
named colors
Definition RGBColor.h:188