Eclipse SUMO - Simulation of Urban MObility
GNERerouterInterval.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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
87 // rerouter intervals cannot be moved
88 return nullptr;
89}
90
91
92void
94 // update centering boundary (needed for centering)
96 // update geometries (boundaries of all children)
97 for (const auto& rerouterElement : getChildAdditionals()) {
98 rerouterElement->updateGeometry();
99 }
100}
101
102
105 // get rerouter parent position
106 Position signPosition = getParentAdditionals().front()->getPositionInView();
107 // set position depending of indexes
108 signPosition.add(4.5, (getDrawPositionIndex() * -1) + 1, 0);
109 // return signPosition
110 return signPosition;
111}
112
113
114void
119}
120
121
122void
123GNERerouterInterval::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
124 // geometry of this element cannot be splitted
125}
126
127
128std::string
130 return getParentAdditionals().at(0)->getID();
131}
132
133
134void
136 // draw rerouter interval as listed attribute
140 // iterate over additionals and check if drawn
141 for (const auto& rerouterElement : getChildAdditionals()) {
142 // if rerouter or their child is selected, then draw
144 rerouterElement->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(rerouterElement) ||
145 (myNet->getViewNet()->getFrontAttributeCarrier() == rerouterElement)) {
146 rerouterElement->drawGL(s);
147 }
148 }
149}
150
151
152std::string
154 switch (key) {
155 case SUMO_ATTR_ID:
156 return getParentAdditionals().front()->getID();
157 case SUMO_ATTR_BEGIN:
158 return time2string(myBegin);
159 case SUMO_ATTR_END:
160 return time2string(myEnd);
161 case GNE_ATTR_PARENT:
162 return getParentAdditionals().at(0)->getID();
165 default:
166 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
167 }
168}
169
170
171double
173 switch (key) {
174 case SUMO_ATTR_BEGIN:
175 return STEPS2TIME(myBegin);
176 case SUMO_ATTR_END:
177 return STEPS2TIME(myEnd);
178 default:
179 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
180 }
181}
182
183
186 return PARAMETERS_EMPTY;
187}
188
189
190void
191GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
192 if (value == getAttribute(key)) {
193 return; //avoid needless changes, later logic relies on the fact that attributes have changed
194 }
195 switch (key) {
196 case SUMO_ATTR_BEGIN:
197 case SUMO_ATTR_END:
199 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
200 break;
201 default:
202 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
203 }
204}
205
206
207bool
208GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {
209 switch (key) {
210 case SUMO_ATTR_BEGIN:
211 return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) < myEnd);
212 case SUMO_ATTR_END:
213 return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) > myBegin);
215 return canParse<bool>(value);
216 default:
217 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
218 }
219}
220
221
222std::string
224 return getTagStr();
225}
226
227
228std::string
230 return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
231}
232
233// ===========================================================================
234// private
235// ===========================================================================
236
237void
238GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
239 switch (key) {
240 case SUMO_ATTR_BEGIN:
241 myBegin = parse<SUMOTime>(value);
242 break;
243 case SUMO_ATTR_END:
244 myEnd = parse<SUMOTime>(value);
245 break;
247 if (parse<bool>(value)) {
249 } else {
251 }
252 break;
253 default:
254 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
255 }
256}
257
258
259void
261 // nothing to do
262}
263
264
265void
267 // nothing to do
268}
269
270/****************************************************************************/
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)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:54
@ 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
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:78
void reset()
Resets the boundary.
Definition: Boundary.cpp:66
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:48
virtual void updateCenteringBoundary(const bool updateGrid)=0
update centering boundary (implies change in RTREE)
void drawListedAddtional(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)
Boundary myAdditionalBoundary
Additional Boundary.
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
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
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:1987
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)
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
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
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)
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
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.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
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
Definition: Parameterised.h:45
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:125
static const RGBColor YELLOW
Definition: RGBColor.h:188
static const RGBColor RED
named colors
Definition: RGBColor.h:185