Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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>
27
28#include "GNERerouterInterval.h"
29
30// ===========================================================================
31// member method definitions
32// ===========================================================================
33
37
38
40 GNEAdditional(rerouterDialog->getEditedAdditional(), SUMO_TAG_INTERVAL, "") {
41 // set parents
42 setParent<GNEAdditional*>(rerouterDialog->getEditedAdditional());
43 // update boundary of rerouter parent
44 rerouterDialog->getEditedAdditional()->updateCenteringBoundary(true);
45}
46
47
49 GNEAdditional(rerouterParent, SUMO_TAG_INTERVAL, ""),
50 myBegin(begin),
51 myEnd(end) {
52 // set parents
53 setParent<GNEAdditional*>(rerouterParent);
54 // update boundary of rerouter parent
55 rerouterParent->updateCenteringBoundary(true);
56}
57
58
60
61
62void
64 // avoid write empty intervals
65 if (getChildAdditionals().size() > 0) {
69 // write all rerouter interval
70 for (const auto& rerouterElement : getChildAdditionals()) {
71 rerouterElement->writeAdditional(device);
72 }
73 device.closeTag();
74 }
75}
76
77
78bool
80 return true;
81}
82
83
84std::string
88
89
90void
92 // nothing to fix
93}
94
95
96bool
98 return false;
99}
100
101
104 // rerouter intervals cannot be moved
105 return nullptr;
106}
107
108
109void
111 // update centering boundary (needed for centering)
113 // update geometries (boundaries of all children)
114 for (const auto& rerouterElement : getChildAdditionals()) {
115 rerouterElement->updateGeometry();
116 }
117}
118
119
122 // get rerouter parent position
123 Position signPosition = getParentAdditionals().front()->getPositionInView();
124 // set position depending of indexes
125 signPosition.add(4.5, (getDrawPositionIndex() * -1) + 1, 0);
126 // return signPosition
127 return signPosition;
128}
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 const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
152 // draw rerouter interval as listed attribute
156 // iterate over additionals and check if drawn
157 for (const auto& rerouterElement : getChildAdditionals()) {
158 // if rerouter or their child is selected, then draw
159 if (isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
160 rerouterElement->isAttributeCarrierSelected() || inspectedElements.isACInspected(rerouterElement) ||
161 rerouterElement->isMarkedForDrawingFront()) {
162 rerouterElement->drawGL(s);
163 }
164 }
165}
166
167
168std::string
170 switch (key) {
171 case SUMO_ATTR_ID:
172 return getParentAdditionals().front()->getID();
173 case SUMO_ATTR_BEGIN:
174 return time2string(myBegin);
175 case SUMO_ATTR_END:
176 return time2string(myEnd);
177 case GNE_ATTR_PARENT:
178 return getParentAdditionals().at(0)->getID();
179 default:
180 return getCommonAttribute(this, key);
181 }
182}
183
184
185double
187 switch (key) {
188 case SUMO_ATTR_BEGIN:
189 return STEPS2TIME(myBegin);
190 case SUMO_ATTR_END:
191 return STEPS2TIME(myEnd);
192 default:
193 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
194 }
195}
196
197
202
203
204void
205GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
206 if (value == getAttribute(key)) {
207 return; //avoid needless changes, later logic relies on the fact that attributes have changed
208 }
209 switch (key) {
210 case SUMO_ATTR_BEGIN:
211 case SUMO_ATTR_END:
212 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
213 break;
214 default:
215 setCommonAttribute(key, value, undoList);
216 break;
217 }
218}
219
220
221bool
222GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {
223 switch (key) {
224 case SUMO_ATTR_BEGIN:
225 return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) < myEnd);
226 case SUMO_ATTR_END:
227 return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) > myBegin);
228 default:
229 return isCommonValid(key, value);
230 }
231}
232
233
234std::string
236 return getTagStr();
237}
238
239
240std::string
244
245// ===========================================================================
246// private
247// ===========================================================================
248
249void
250GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
251 switch (key) {
252 case SUMO_ATTR_BEGIN:
253 myBegin = parse<SUMOTime>(value);
254 break;
255 case SUMO_ATTR_END:
256 myEnd = parse<SUMOTime>(value);
257 break;
258 default:
259 setCommonAttribute(this, key, value);
260 break;
261 }
262}
263
264
265void
267 // nothing to do
268}
269
270
271void
273 // nothing to do
274}
275
276/****************************************************************************/
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
GNEAdditional * getEditedAdditional() const
get edited Additional
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:2194
Dialog for edit rerouters.
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