Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEVariableSpeedSignStep.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-2025 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
23
25
26// ===========================================================================
27// member method definitions
28// ===========================================================================
29
34
35
37 const SUMOTime time, const double speed) :
38 GNEAdditional(variableSpeedSign, SUMO_TAG_STEP, ""),
40 myTime(time),
41 mySpeed(speed) {
42 // set parents
43 setParent<GNEAdditional*>(variableSpeedSign);
44 // update boundary of rerouter parent
45 variableSpeedSign->updateCenteringBoundary(true);
46}
47
48
50
51
54 return nullptr;
55}
56
57
60 return nullptr;
61}
62
63
64const Parameterised*
66 return nullptr;
67}
68
69
70void
72 device.openTag(SUMO_TAG_STEP);
73 // write common additional attributes
75 // write specific attributes
78 device.closeTag();
79}
80
81
82bool
84 return true;
85}
86
87
88std::string
92
93
94void
98
99
100bool
102 return false;
103}
104
105
108 return myTime;
109}
110
111
112void
116
117
122
123
124void
126 // nothing to do
127}
128
129
130void
131GNEVariableSpeedSignStep::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
132 // geometry of this element cannot be splitted
133}
134
135
136std::string
138 return getParentAdditionals().at(0)->getID();
139}
140
141
142void
148
149
150std::string
152 switch (key) {
153 case SUMO_ATTR_ID:
154 return getMicrosimID();
155 case SUMO_ATTR_TIME:
156 return time2string(myTime);
157 case SUMO_ATTR_SPEED:
158 return toString(mySpeed);
159 case GNE_ATTR_PARENT:
160 return getParentAdditionals().at(0)->getID();
161 default:
162 return getCommonAttribute(key);
163 }
164}
165
166
167double
169 switch (key) {
170 case SUMO_ATTR_TIME:
171 return (double)myTime;
172 default:
173 return getCommonAttributeDouble(key);
174 }
175}
176
177
182
183
188
189
190void
191GNEVariableSpeedSignStep::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_TIME:
197 case SUMO_ATTR_SPEED:
198 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
199 break;
200 default:
201 setCommonAttribute(key, value, undoList);
202 break;
203 }
204}
205
206
207bool
208GNEVariableSpeedSignStep::isValid(SumoXMLAttr key, const std::string& value) {
209 switch (key) {
210 case SUMO_ATTR_TIME:
211 if (canParse<double>(value)) {
212 // Check that
213 double newTime = parse<double>(value);
214 // Only allowed positiv times
215 if (newTime < 0) {
216 return false;
217 }
218 // check that there isn't duplicate times
219 int counter = 0;
220 for (const auto& VSSChild : getParentAdditionals().at(0)->getChildAdditionals()) {
221 if (!VSSChild->getTagProperty()->isSymbol() && VSSChild->getAttributeDouble(SUMO_ATTR_TIME) == newTime) {
222 counter++;
223 }
224 }
225 return (counter <= 1);
226 } else {
227 return false;
228 }
229 case SUMO_ATTR_SPEED:
230 if (value.empty()) {
231 return true;
232 } else {
233 return canParse<double>(value);
234 }
235 default:
236 return isCommonAttributeValid(key, value);
237 }
238}
239
240
241std::string
245
246
247std::string
251
252// ===========================================================================
253// private
254// ===========================================================================
255
256void
258 switch (key) {
259 case SUMO_ATTR_TIME:
260 myTime = string2time(value);
261 break;
262 case SUMO_ATTR_SPEED:
263 mySpeed = parse<double>(value);
264 break;
265 default:
266 setCommonAttribute(key, value);
267 break;
268 }
269}
270
271/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ VARIABLESPEEDSIGN_STEP
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
@ SUMO_TAG_STEP
trigger: a step description
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_SPEED
@ GNE_ATTR_PARENT
parent of an additional element
@ 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
virtual void updateCenteringBoundary(const bool updateGrid)=0
update centering boundary (implies change in RTREE)
void writeAdditionalAttributes(OutputDevice &device) const
write common additional attributes
void drawListedAdditional(const GUIVisualizationSettings &s, const RGBColor baseCol, const RGBColor textCol, GUITexture texture, const std::string text) const
draw listed additional
Position getListedPositionInView() const
get listed position in view
void updateGeometryListedAdditional()
update geometry of listed additional
double getCommonAttributeDouble(SumoXMLAttr key) const
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
Position getCommonAttributePosition(SumoXMLAttr key) const
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
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 GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
bool isAdditionalValid() const
check if current additional is valid to be written into XML
GNEVariableSpeedSignStep(GNENet *net)
default constructor
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this variableSpeedSignStep
bool checkDrawMoveContour() const override
check if draw move contour (red)
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double mySpeed
speed in this timeStep
Position getPositionInView() const
Returns position of additional in view.
double getAttributeDouble(SumoXMLAttr key) const override
Parameterised * getParameters() override
get parameters associated with this variableSpeedSignStep
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
bool isValid(SumoXMLAttr key, const std::string &value) override
std::string getParentName() const
Returns the name of the parent object.
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
void updateGeometry() override
update pre-computed geometry information
std::string getAttribute(SumoXMLAttr key) const override
inherited from GNEAttributeCarrier
void fixAdditionalProblem()
fix additional problem
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
std::string getAdditionalProblem() const
return a string with the current additional problem
Position getAttributePosition(SumoXMLAttr key) const override
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
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.
An upper class for objects with additional parameters.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
static const RGBColor WHITE
Definition RGBColor.h:195
static const RGBColor BLACK
Definition RGBColor.h:196