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 // draw rerouter interval as listed attribute
162 // iterate over additionals and check if drawn
163 for (const auto& rerouterElement : getChildAdditionals()) {
164 // if rerouter or their child is selected, then draw
166 rerouterElement->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(rerouterElement) ||
167 (myNet->getViewNet()->getFrontAttributeCarrier() == rerouterElement)) {
168 rerouterElement->drawGL(s);
169 }
170 }
171}
172
173
174std::string
176 switch (key) {
177 case SUMO_ATTR_ID:
178 return getParentAdditionals().front()->getID();
179 case SUMO_ATTR_BEGIN:
180 return time2string(myBegin);
181 case SUMO_ATTR_END:
182 return time2string(myEnd);
183 case GNE_ATTR_PARENT:
184 return getParentAdditionals().at(0)->getID();
187 default:
188 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
189 }
190}
191
192
193double
195 switch (key) {
196 case SUMO_ATTR_BEGIN:
197 return STEPS2TIME(myBegin);
198 case SUMO_ATTR_END:
199 return STEPS2TIME(myEnd);
200 default:
201 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
202 }
203}
204
205
210
211
212void
213GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
214 if (value == getAttribute(key)) {
215 return; //avoid needless changes, later logic relies on the fact that attributes have changed
216 }
217 switch (key) {
218 case SUMO_ATTR_BEGIN:
219 case SUMO_ATTR_END:
221 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
222 break;
223 default:
224 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
225 }
226}
227
228
229bool
230GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {
231 switch (key) {
232 case SUMO_ATTR_BEGIN:
233 return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) < myEnd);
234 case SUMO_ATTR_END:
235 return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) > myBegin);
237 return canParse<bool>(value);
238 default:
239 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
240 }
241}
242
243
244std::string
246 return getTagStr();
247}
248
249
250std::string
254
255// ===========================================================================
256// private
257// ===========================================================================
258
259void
260GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
261 switch (key) {
262 case SUMO_ATTR_BEGIN:
263 myBegin = parse<SUMOTime>(value);
264 break;
265 case SUMO_ATTR_END:
266 myEnd = parse<SUMOTime>(value);
267 break;
269 if (parse<bool>(value)) {
271 } else {
273 }
274 break;
275 default:
276 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
277 }
278}
279
280
281void
283 // nothing to do
284}
285
286
287void
289 // nothing to do
290}
291
292/****************************************************************************/
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
@ GNE_ATTR_SELECTED
element is selected
@ 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
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
static const Parameterised::Map PARAMETERS_EMPTY
empty parameter maps (used by ACs without parameters)
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
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:2147
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...
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
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