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-2024 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
36 GUIIconSubSys::getIcon(GUIIcon::REROUTERINTERVAL), "", {}, {}, {}, {}, {}, {}),
37 myBegin(0),
38myEnd(0) {
39 // reset default values
40 resetDefaultValues();
41}
42
43
45 GNEAdditional(rerouterDialog->getEditedAdditional()->getNet(), GLO_REROUTER_INTERVAL, SUMO_TAG_INTERVAL,
46 GUIIconSubSys::getIcon(GUIIcon::REROUTERINTERVAL), "", {}, {}, {}, {rerouterDialog->getEditedAdditional()}, {}, {}),
47myBegin(0),
48myEnd(0) {
49 // reset default values
50 resetDefaultValues();
51 // update boundary of rerouter parent
52 rerouterDialog->getEditedAdditional()->updateCenteringBoundary(true);
53}
54
55
57 GNEAdditional(rerouterParent->getNet(), GLO_REROUTER, SUMO_TAG_INTERVAL,
58 GUIIconSubSys::getIcon(GUIIcon::REROUTERINTERVAL), "", {}, {}, {}, {rerouterParent}, {}, {}),
59myBegin(begin),
60myEnd(end) {
61 // update boundary of rerouter parent
62 rerouterParent->updateCenteringBoundary(true);
63}
64
65
67
68
69void
71 // avoid write empty intervals
72 if (getChildAdditionals().size() > 0) {
76 // write all rerouter interval
77 for (const auto& rerouterElement : getChildAdditionals()) {
78 rerouterElement->writeAdditional(device);
79 }
80 device.closeTag();
81 }
82}
83
84
85bool
87 return true;
88}
89
90
91std::string
95
96
97void
99 // nothing to fix
100}
101
102
103bool
105 return false;
106}
107
108
111 // rerouter intervals cannot be moved
112 return nullptr;
113}
114
115
116void
118 // update centering boundary (needed for centering)
120 // update geometries (boundaries of all children)
121 for (const auto& rerouterElement : getChildAdditionals()) {
122 rerouterElement->updateGeometry();
123 }
124}
125
126
129 // get rerouter parent position
130 Position signPosition = getParentAdditionals().front()->getPositionInView();
131 // set position depending of indexes
132 signPosition.add(4.5, (getDrawPositionIndex() * -1) + 1, 0);
133 // return signPosition
134 return signPosition;
135}
136
137
138void
140 // nothing to do
141}
142
143
144void
145GNERerouterInterval::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
146 // geometry of this element cannot be splitted
147}
148
149
150std::string
152 return getParentAdditionals().at(0)->getID();
153}
154
155
156void
158 const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
159 // draw rerouter interval as listed attribute
163 // iterate over additionals and check if drawn
164 for (const auto& rerouterElement : getChildAdditionals()) {
165 // if rerouter or their child is selected, then draw
166 if (isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
167 rerouterElement->isAttributeCarrierSelected() || inspectedElements.isACInspected(rerouterElement) ||
168 rerouterElement->isMarkedForDrawingFront()) {
169 rerouterElement->drawGL(s);
170 }
171 }
172}
173
174
175std::string
177 switch (key) {
178 case SUMO_ATTR_ID:
179 return getParentAdditionals().front()->getID();
180 case SUMO_ATTR_BEGIN:
181 return time2string(myBegin);
182 case SUMO_ATTR_END:
183 return time2string(myEnd);
184 case GNE_ATTR_PARENT:
185 return getParentAdditionals().at(0)->getID();
186 default:
187 return getCommonAttribute(key);
188 }
189}
190
191
192double
194 switch (key) {
195 case SUMO_ATTR_BEGIN:
196 return STEPS2TIME(myBegin);
197 case SUMO_ATTR_END:
198 return STEPS2TIME(myEnd);
199 default:
200 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
201 }
202}
203
204
209
210
211void
212GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
213 if (value == getAttribute(key)) {
214 return; //avoid needless changes, later logic relies on the fact that attributes have changed
215 }
216 switch (key) {
217 case SUMO_ATTR_BEGIN:
218 case SUMO_ATTR_END:
219 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
220 break;
221 default:
222 setCommonAttribute(key, value, undoList);
223 break;
224 }
225}
226
227
228bool
229GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {
230 switch (key) {
231 case SUMO_ATTR_BEGIN:
232 return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) < myEnd);
233 case SUMO_ATTR_END:
234 return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) > myBegin);
235 default:
236 return isCommonValid(key, value);
237 }
238}
239
240
241std::string
243 return getTagStr();
244}
245
246
247std::string
251
252// ===========================================================================
253// private
254// ===========================================================================
255
256void
257GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
258 switch (key) {
259 case SUMO_ATTR_BEGIN:
260 myBegin = parse<SUMOTime>(value);
261 break;
262 case SUMO_ATTR_END:
263 myEnd = parse<SUMOTime>(value);
264 break;
265 default:
266 setCommonAttribute(key, value);
267 break;
268 }
269}
270
271
272void
274 // nothing to do
275}
276
277
278void
280 // nothing to do
281}
282
283/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ GLO_REROUTER
a Rerouter
@ GLO_REROUTER_INTERVAL
a rerouter interval
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ REROUTERINTERVAL
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:69
#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
An Element which don't belong to GNENet but has influence in the simulation.
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
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
bool isCommonValid(SumoXMLAttr key, const std::string &value)
static const Parameterised::Map PARAMETERS_EMPTY
empty parameter maps (used by ACs without parameters)
GNENet * myNet
pointer to net
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 std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const std::vector< 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:2163
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
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:132
static const RGBColor YELLOW
Definition RGBColor.h:188
static const RGBColor RED
named colors
Definition RGBColor.h:185