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-2023 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
105 // rerouter intervals cannot be moved
106 return nullptr;
107}
108
109
110void
112 // update centering boundary (needed for centering)
114 // update geometries (boundaries of all children)
115 for (const auto& rerouterElement : getChildAdditionals()) {
116 rerouterElement->updateGeometry();
117 }
118}
119
120
123 // get rerouter parent position
124 Position signPosition = getParentAdditionals().front()->getPositionInView();
125 // set position depending of indexes
126 signPosition.add(4.5, (getDrawPositionIndex() * -1) + 1, 0);
127 // return signPosition
128 return signPosition;
129}
130
131
132void
138
139
140void
141GNERerouterInterval::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
142 // geometry of this element cannot be splitted
143}
144
145
146std::string
148 return getParentAdditionals().at(0)->getID();
149}
150
151
152void
154 // draw rerouter interval as listed attribute
158 // iterate over additionals and check if drawn
159 for (const auto& rerouterElement : getChildAdditionals()) {
160 // if rerouter or their child is selected, then draw
162 rerouterElement->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(rerouterElement) ||
163 (myNet->getViewNet()->getFrontAttributeCarrier() == rerouterElement)) {
164 rerouterElement->drawGL(s);
165 }
166 }
167}
168
169
170std::string
172 switch (key) {
173 case SUMO_ATTR_ID:
174 return getParentAdditionals().front()->getID();
175 case SUMO_ATTR_BEGIN:
176 return time2string(myBegin);
177 case SUMO_ATTR_END:
178 return time2string(myEnd);
179 case GNE_ATTR_PARENT:
180 return getParentAdditionals().at(0)->getID();
183 default:
184 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
185 }
186}
187
188
189double
191 switch (key) {
192 case SUMO_ATTR_BEGIN:
193 return STEPS2TIME(myBegin);
194 case SUMO_ATTR_END:
195 return STEPS2TIME(myEnd);
196 default:
197 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
198 }
199}
200
201
206
207
208void
209GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
210 if (value == getAttribute(key)) {
211 return; //avoid needless changes, later logic relies on the fact that attributes have changed
212 }
213 switch (key) {
214 case SUMO_ATTR_BEGIN:
215 case SUMO_ATTR_END:
217 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
218 break;
219 default:
220 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
221 }
222}
223
224
225bool
226GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {
227 switch (key) {
228 case SUMO_ATTR_BEGIN:
229 return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) < myEnd);
230 case SUMO_ATTR_END:
231 return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) > myBegin);
233 return canParse<bool>(value);
234 default:
235 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
236 }
237}
238
239
240std::string
242 return getTagStr();
243}
244
245
246std::string
250
251// ===========================================================================
252// private
253// ===========================================================================
254
255void
256GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
257 switch (key) {
258 case SUMO_ATTR_BEGIN:
259 myBegin = parse<SUMOTime>(value);
260 break;
261 case SUMO_ATTR_END:
262 myEnd = parse<SUMOTime>(value);
263 break;
265 if (parse<bool>(value)) {
267 } else {
269 }
270 break;
271 default:
272 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
273 }
274}
275
276
277void
279 // nothing to do
280}
281
282
283void
285 // nothing to do
286}
287
288/****************************************************************************/
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
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.
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:2030
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
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 writed into XML (must be reimplemented in all detector chi...
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.
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:125
static const RGBColor YELLOW
Definition RGBColor.h:188
static const RGBColor RED
named colors
Definition RGBColor.h:185