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-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
21#include <netedit/GNENet.h>
23
24#include "GNERerouterInterval.h"
25
26// ===========================================================================
27// member method definitions
28// ===========================================================================
29
30#ifdef _MSC_VER
31#pragma warning(push)
32#pragma warning(disable: 4355) // mask warning about "this" in initializers
33#endif
38
39
41 GNEAdditional(rerouterParent, SUMO_TAG_INTERVAL, ""),
43 myBegin(begin),
44 myEnd(end) {
45 // set parents
46 setParent<GNEAdditional*>(rerouterParent);
47 // update boundary of rerouter parent
48 rerouterParent->updateCenteringBoundary(true);
49}
50#ifdef _MSC_VER
51#pragma warning(pop)
52#endif
53
54
56
57
60 return nullptr;
61}
62
63
66 return nullptr;
67}
68
69
70const Parameterised*
72 return nullptr;
73}
74
75
76void
78 // avoid write empty intervals
79 if (getChildAdditionals().size() > 0) {
81 // write common additional attributes
83 // write specific attributes
86 // write all rerouter interval
87 for (const auto& rerouterElement : getChildAdditionals()) {
88 rerouterElement->writeAdditional(device);
89 }
90 device.closeTag();
91 }
92}
93
94
95bool
97 return true;
98}
99
100
101std::string
103 return "";
104}
105
106
107void
109 // nothing to fix
110}
111
112
113bool
115 return false;
116}
117
118
119void
123
124
129
130
131void
133 // nothing to do
134}
135
136
137void
138GNERerouterInterval::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
139 // geometry of this element cannot be splitted
140}
141
142
143std::string
145 return getParentAdditionals().at(0)->getID();
146}
147
148
149void
151 // draw rerouter interval as listed attribute
154 const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
155 // iterate over additionals and check if drawn
156 for (const auto& rerouterElement : getChildAdditionals()) {
157 // if rerouter or their child is selected, then draw
158 if (isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
159 rerouterElement->isAttributeCarrierSelected() || inspectedElements.isACInspected(rerouterElement) ||
160 rerouterElement->isMarkedForDrawingFront()) {
161 rerouterElement->drawGL(s);
162 }
163 }
164}
165
166
167std::string
169 switch (key) {
170 case SUMO_ATTR_ID:
171 return getParentAdditionals().front()->getID();
172 case SUMO_ATTR_BEGIN:
173 return time2string(myBegin);
174 case SUMO_ATTR_END:
175 return time2string(myEnd);
176 case GNE_ATTR_PARENT:
177 return getParentAdditionals().at(0)->getID();
178 default:
179 return getCommonAttribute(key);
180 }
181}
182
183
184double
186 switch (key) {
187 case SUMO_ATTR_BEGIN:
188 return STEPS2TIME(myBegin);
189 case SUMO_ATTR_END:
190 return STEPS2TIME(myEnd);
191 default:
192 return getCommonAttributeDouble(key);
193 }
194}
195
196
201
202
207
208
209void
210GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
211 if (value == getAttribute(key)) {
212 return; //avoid needless changes, later logic relies on the fact that attributes have changed
213 }
214 switch (key) {
215 case SUMO_ATTR_BEGIN:
216 case SUMO_ATTR_END:
217 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
218 break;
219 default:
220 setCommonAttribute(key, value, undoList);
221 break;
222 }
223}
224
225
226bool
227GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {
228 switch (key) {
229 case SUMO_ATTR_BEGIN:
230 if (canParse<SUMOTime>(value)) {
231 const auto begin = parse<SUMOTime>(value);
232 if (begin < 0) {
233 return false;
234 } else {
235 return (begin <= myEnd);
236 }
237 } else {
238 return false;
239 }
240 case SUMO_ATTR_END:
241 if (canParse<SUMOTime>(value)) {
242 const auto end = parse<SUMOTime>(value);
243 if (end < 0) {
244 return false;
245 } else {
246 return (myBegin <= end);
247 }
248 } else {
249 return false;
250 }
251 default:
252 return isCommonAttributeValid(key, value);
253 }
254}
255
256
257std::string
259 return getTagStr();
260}
261
262
263std::string
267
268// ===========================================================================
269// private
270// ===========================================================================
271
272void
273GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
274 switch (key) {
275 case SUMO_ATTR_BEGIN:
276 myBegin = parse<SUMOTime>(value);
277 break;
278 case SUMO_ATTR_END:
279 myEnd = parse<SUMOTime>(value);
280 break;
281 default:
282 setCommonAttribute(key, value);
283 break;
284 }
285}
286
287/****************************************************************************/
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:58
@ 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
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=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.
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:195
static const RGBColor RED
named colors
Definition RGBColor.h:192