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
114 // rerouter intervals cannot be moved
115 return nullptr;
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: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
bool checkDrawMoveContour() const override
check if draw move contour (red)
bool isValid(SumoXMLAttr key, const std::string &value) override
Position getPositionInView() const
Returns position of additional in view.
GNEMoveOperation * getMoveOperation()
get move operation
void updateGeometry() override
update pre-computed geometry information
std::string getAttribute(SumoXMLAttr key) const override
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this rerouterInterval
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
std::string getParentName() const
Returns the name of the parent object.
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
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
Parameterised * getParameters() override
get parameters associated with this rerouterInterval
double getAttributeDouble(SumoXMLAttr key) const override
SUMOTime myBegin
begin timeStep
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
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.
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