Eclipse SUMO - Simulation of Urban MObility
GNEVariableSpeedSignStep.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
23#include <netedit/GNEUndoList.h>
24
26
27
28// ===========================================================================
29// member method definitions
30// ===========================================================================
31
34 "", {}, {}, {}, {}, {}, {}),
35myTime(0) {
36 // reset default values
38}
39
40
41GNEVariableSpeedSignStep::GNEVariableSpeedSignStep(GNEAdditional* variableSpeedSignParent, SUMOTime time, const std::string& speed) :
42 GNEAdditional(variableSpeedSignParent->getNet(), GLO_VSS_STEP, SUMO_TAG_STEP, GUIIconSubSys::getIcon(GUIIcon::VSSSTEP),
43 "", {}, {}, {}, {variableSpeedSignParent}, {}, {}),
44myTime(time),
45mySpeed(speed) {
46 // update boundary of rerouter parent
47 variableSpeedSignParent->updateCenteringBoundary(true);
48}
49
50
52
53
54void
56 device.openTag(SUMO_TAG_STEP);
59 device.closeTag();
60}
61
62
65 // VSS Steps cannot be moved
66 return nullptr;
67}
68
69
72 return myTime;
73}
74
75
76void
78 // update centering boundary (needed for centering)
80}
81
82
85 // get rerouter parent position
86 Position signPosition = getParentAdditionals().front()->getPositionInView();
87 // set position depending of indexes
88 signPosition.add(4.5, (getDrawPositionIndex() * -1) + 1, 0);
89 // return signPosition
90 return signPosition;
91}
92
93
94void
99}
100
101
102void
103GNEVariableSpeedSignStep::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
104 // geometry of this element cannot be splitted
105}
106
107
108std::string
110 return getParentAdditionals().at(0)->getID();
111}
112
113
114void
116 // draw rerouter interval as listed attribute
120}
121
122
123std::string
125 switch (key) {
126 case SUMO_ATTR_ID:
127 return getMicrosimID();
128 case SUMO_ATTR_TIME:
129 return time2string(myTime);
130 case SUMO_ATTR_SPEED:
131 return mySpeed;
132 case GNE_ATTR_PARENT:
133 return getParentAdditionals().at(0)->getID();
136 default:
137 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
138 }
139}
140
141
142double
144 switch (key) {
145 case SUMO_ATTR_TIME:
146 return (double)myTime;
147 default:
148 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
149 }
150}
151
152
155 return PARAMETERS_EMPTY;
156}
157
158
159void
160GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
161 if (value == getAttribute(key)) {
162 return; //avoid needless changes, later logic relies on the fact that attributes have changed
163 }
164 switch (key) {
165 case SUMO_ATTR_TIME:
166 case SUMO_ATTR_SPEED:
168 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
169 break;
170 default:
171 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
172 }
173}
174
175
176bool
177GNEVariableSpeedSignStep::isValid(SumoXMLAttr key, const std::string& value) {
178 switch (key) {
179 case SUMO_ATTR_TIME:
180 if (canParse<double>(value)) {
181 // Check that
182 double newTime = parse<double>(value);
183 // Only allowed positiv times
184 if (newTime < 0) {
185 return false;
186 }
187 // check that there isn't duplicate times
188 int counter = 0;
189 for (const auto& VSSChild : getParentAdditionals().at(0)->getChildAdditionals()) {
190 if (!VSSChild->getTagProperty().isSymbol() && VSSChild->getAttributeDouble(SUMO_ATTR_TIME) == newTime) {
191 counter++;
192 }
193 }
194 return (counter <= 1);
195 } else {
196 return false;
197 }
198 case SUMO_ATTR_SPEED:
199 if (value.empty()) {
200 return true;
201 } else {
202 return canParse<double>(value);
203 }
205 return canParse<double>(value);
206 default:
207 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
208 }
209}
210
211
212std::string
214 return getTagStr();
215}
216
217
218std::string
220 return getTagStr() + ": " + getAttribute(SUMO_ATTR_TIME);
221}
222
223// ===========================================================================
224// private
225// ===========================================================================
226
227void
229 switch (key) {
230 case SUMO_ATTR_TIME:
231 myTime = string2time(value);
232 break;
233 case SUMO_ATTR_SPEED:
234 mySpeed = value;
235 break;
237 if (parse<bool>(value)) {
239 } else {
241 }
242 break;
243 default:
244 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
245 }
246}
247
248
249void
251 // nothing to do
252}
253
254
255void
257 // nothing to do
258}
259
260
261/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
@ GLO_VSS_STEP
a Variable Speed Sign step
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ VARIABLESPEEDSIGN_STEP
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:45
@ SUMO_TAG_STEP
trigger: a step description
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_SPEED
@ GNE_ATTR_PARENT
parent of an additional element
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_ID
@ SUMO_ATTR_TIME
trigger: the time of the step
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)
void resetDefaultValues()
reset attribute carrier to their default values
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
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
GNEMoveOperation * getMoveOperation()
get move operation
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
GNEVariableSpeedSignStep(GNENet *net)
default constructor
std::string mySpeed
speed in this timeStep
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void updateGeometry()
update pre-computed geometry information
Position getPositionInView() const
Returns position of additional in view.
const Parameterised::Map & getACParametersMap() const
get parameters map
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
SUMOTime getTime() const
get time
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
std::string getParentName() const
Returns the name of the parent object.
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
double getAttributeDouble(SumoXMLAttr key) const
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:141
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 WHITE
Definition: RGBColor.h:192
static const RGBColor BLACK
Definition: RGBColor.h:193