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
21#include <netedit/GNENet.h>
23
24#include "GNERerouterInterval.h"
25
26// ===========================================================================
27// member method definitions
28// ===========================================================================
29
34
35
37 GNEAdditional(rerouterParent, SUMO_TAG_INTERVAL, ""),
39 myBegin(begin),
40 myEnd(end) {
41 // set parents
42 setParent<GNEAdditional*>(rerouterParent);
43 // update boundary of rerouter parent
44 rerouterParent->updateCenteringBoundary(true);
45}
46
47
49
50
53 return nullptr;
54}
55
56
59 return nullptr;
60}
61
62
63const Parameterised*
65 return nullptr;
66}
67
68
69void
71 // avoid write empty intervals
72 if (getChildAdditionals().size() > 0) {
74 // write common additional attributes
76 // write specific attributes
79 // write all rerouter interval
80 for (const auto& rerouterElement : getChildAdditionals()) {
81 rerouterElement->writeAdditional(device);
82 }
83 device.closeTag();
84 }
85}
86
87
88bool
90 return true;
91}
92
93
94std::string
98
99
100void
102 // nothing to fix
103}
104
105
106bool
108 return false;
109}
110
111
112void
116
117
122
123
124void
126 // nothing to do
127}
128
129
130void
131GNERerouterInterval::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
132 // geometry of this element cannot be splitted
133}
134
135
136std::string
138 return getParentAdditionals().at(0)->getID();
139}
140
141
142void
144 // draw rerouter interval as listed attribute
147 const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
148 // iterate over additionals and check if drawn
149 for (const auto& rerouterElement : getChildAdditionals()) {
150 // if rerouter or their child is selected, then draw
151 if (isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
152 rerouterElement->isAttributeCarrierSelected() || inspectedElements.isACInspected(rerouterElement) ||
153 rerouterElement->isMarkedForDrawingFront()) {
154 rerouterElement->drawGL(s);
155 }
156 }
157}
158
159
160std::string
162 switch (key) {
163 case SUMO_ATTR_ID:
164 return getParentAdditionals().front()->getID();
165 case SUMO_ATTR_BEGIN:
166 return time2string(myBegin);
167 case SUMO_ATTR_END:
168 return time2string(myEnd);
169 case GNE_ATTR_PARENT:
170 return getParentAdditionals().at(0)->getID();
171 default:
172 return getCommonAttribute(key);
173 }
174}
175
176
177double
179 switch (key) {
180 case SUMO_ATTR_BEGIN:
181 return STEPS2TIME(myBegin);
182 case SUMO_ATTR_END:
183 return STEPS2TIME(myEnd);
184 default:
185 return getCommonAttributeDouble(key);
186 }
187}
188
189
194
195
200
201
202void
203GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
204 if (value == getAttribute(key)) {
205 return; //avoid needless changes, later logic relies on the fact that attributes have changed
206 }
207 switch (key) {
208 case SUMO_ATTR_BEGIN:
209 case SUMO_ATTR_END:
210 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
211 break;
212 default:
213 setCommonAttribute(key, value, undoList);
214 break;
215 }
216}
217
218
219bool
220GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {
221 switch (key) {
222 case SUMO_ATTR_BEGIN:
223 if (canParse<SUMOTime>(value)) {
224 const auto begin = parse<SUMOTime>(value);
225 if (begin < 0) {
226 return false;
227 } else {
228 return (begin <= myEnd);
229 }
230 } else {
231 return false;
232 }
233 case SUMO_ATTR_END:
234 if (canParse<SUMOTime>(value)) {
235 const auto end = parse<SUMOTime>(value);
236 if (end < 0) {
237 return false;
238 } else {
239 return (myBegin <= end);
240 }
241 } else {
242 return false;
243 }
244 default:
245 return isCommonAttributeValid(key, value);
246 }
247}
248
249
250std::string
252 return getTagStr();
253}
254
255
256std::string
260
261// ===========================================================================
262// private
263// ===========================================================================
264
265void
266GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
267 switch (key) {
268 case SUMO_ATTR_BEGIN:
269 myBegin = parse<SUMOTime>(value);
270 break;
271 case SUMO_ATTR_END:
272 myEnd = parse<SUMOTime>(value);
273 break;
274 default:
275 setCommonAttribute(key, value);
276 break;
277 }
278}
279
280/****************************************************************************/
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
virtual void updateCenteringBoundary(const bool updateGrid)=0
update centering boundary (implies change in RTREE)
void writeAdditionalAttributes(OutputDevice &device) const
write common additional attributes
void drawListedAdditional(const GUIVisualizationSettings &s, const RGBColor baseCol, const RGBColor textCol, GUITexture texture, const std::string text) const
draw listed additional
Position getListedPositionInView() const
get listed position in view
void updateGeometryListedAdditional()
update geometry of listed additional
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
double getCommonAttributeDouble(SumoXMLAttr key) const
PositionVector getCommonAttributePositionVector(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
Position getCommonAttributePosition(SumoXMLAttr key) const
GNENet * myNet
pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
std::string getCommonAttribute(SumoXMLAttr key) 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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
bool checkDrawMoveContour() const override
check if draw move contour (red)
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
bool isValid(SumoXMLAttr key, const std::string &value) override
Position getPositionInView() const override
Returns position of additional in view.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
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...
std::string getParentName() const override
Returns the name of the parent object.
std::string getAttribute(SumoXMLAttr key) const override
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this rerouterInterval
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
std::string getAdditionalProblem() const override
return a string with the current additional problem (must be reimplemented in all detector children)
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
Position getAttributePosition(SumoXMLAttr key) const override
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
SUMOTime myEnd
end timeStep
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
void fixAdditionalProblem() override
fix additional problem (must be reimplemented in all detector children)
Parameterised * getParameters() override
get parameters associated with this rerouterInterval
double getAttributeDouble(SumoXMLAttr key) const override
SUMOTime myBegin
begin timeStep
GNERerouterInterval(GNENet *net)
default constructor
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.
An upper class for objects with additional parameters.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
static const RGBColor YELLOW
Definition RGBColor.h:191
static const RGBColor RED
named colors
Definition RGBColor.h:188