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-2026 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
30#ifdef _MSC_VER
31#pragma warning(push)
32#pragma warning(disable: 4355) // mask warning about "this" in initializers
33#endif
38
39
41 const SUMOTime time, const double speed) :
42 GNEAdditional(variableSpeedSign, SUMO_TAG_STEP, ""),
44 myTime(time),
45 mySpeed(speed) {
46 // set parents
47 setParent<GNEAdditional*>(variableSpeedSign);
48 // update boundary of rerouter parent
49 variableSpeedSign->updateCenteringBoundary(true);
50}
51#ifdef _MSC_VER
52#pragma warning(pop)
53#endif
54
55
57
58
61 return nullptr;
62}
63
64
67 return nullptr;
68}
69
70
71const Parameterised*
73 return nullptr;
74}
75
76
77void
79 device.openTag(SUMO_TAG_STEP);
80 // write common additional attributes
82 // write specific attributes
85 device.closeTag();
86}
87
88
89bool
91 return true;
92}
93
94
95std::string
99
100
101void
105
106
107bool
109 return false;
110}
111
112
115 return myTime;
116}
117
118
119void
123
124
129
130
131void
133 // nothing to do
134}
135
136
137void
138GNEVariableSpeedSignStep::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
139 // geometry of this element cannot be splitted
140}
141
142
143std::string
145 return getParentAdditionals().at(0)->getID();
146}
147
148
149void
155
156
157std::string
159 switch (key) {
160 case SUMO_ATTR_ID:
161 return getMicrosimID();
162 case SUMO_ATTR_TIME:
163 return time2string(myTime);
164 case SUMO_ATTR_SPEED:
165 return toString(mySpeed);
166 case GNE_ATTR_PARENT:
167 return getParentAdditionals().at(0)->getID();
168 default:
169 return getCommonAttribute(key);
170 }
171}
172
173
174double
176 switch (key) {
177 case SUMO_ATTR_TIME:
178 return (double)myTime;
179 default:
180 return getCommonAttributeDouble(key);
181 }
182}
183
184
189
190
195
196
197void
198GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
199 if (value == getAttribute(key)) {
200 return; //avoid needless changes, later logic relies on the fact that attributes have changed
201 }
202 switch (key) {
203 case SUMO_ATTR_TIME:
204 case SUMO_ATTR_SPEED:
205 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
206 break;
207 default:
208 setCommonAttribute(key, value, undoList);
209 break;
210 }
211}
212
213
214bool
215GNEVariableSpeedSignStep::isValid(SumoXMLAttr key, const std::string& value) {
216 switch (key) {
217 case SUMO_ATTR_TIME:
218 if (canParse<double>(value)) {
219 // Check that
220 double newTime = parse<double>(value);
221 // Only allowed positiv times
222 if (newTime < 0) {
223 return false;
224 }
225 // check that there isn't duplicate times
226 int counter = 0;
227 for (const auto& VSSChild : getParentAdditionals().at(0)->getChildAdditionals()) {
228 if (!VSSChild->getTagProperty()->isSymbol() && VSSChild->getAttributeDouble(SUMO_ATTR_TIME) == newTime) {
229 counter++;
230 }
231 }
232 return (counter <= 1);
233 } else {
234 return false;
235 }
236 case SUMO_ATTR_SPEED:
237 if (value.empty()) {
238 return true;
239 } else {
240 return canParse<double>(value);
241 }
242 default:
243 return isCommonAttributeValid(key, value);
244 }
245}
246
247
248std::string
252
253
254std::string
258
259// ===========================================================================
260// private
261// ===========================================================================
262
263void
265 switch (key) {
266 case SUMO_ATTR_TIME:
267 myTime = string2time(value);
268 break;
269 case SUMO_ATTR_SPEED:
270 mySpeed = parse<double>(value);
271 break;
272 default:
273 setCommonAttribute(key, value);
274 break;
275 }
276}
277
278/****************************************************************************/
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:49
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
void fixAdditionalProblem() override
fix additional problem
bool isAdditionalValid() const override
check if current additional is valid to be written into XML
std::string getParentName() const override
Returns the name of the parent object.
GNEVariableSpeedSignStep(GNENet *net)
default constructor
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this variableSpeedSignStep
bool checkDrawMoveContour() const override
check if draw move contour (red)
double mySpeed
speed in this timeStep
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
double getAttributeDouble(SumoXMLAttr key) const override
Position getPositionInView() const override
Returns position of additional in view.
Parameterised * getParameters() override
get parameters associated with this variableSpeedSignStep
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
bool isValid(SumoXMLAttr key, const std::string &value) override
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 drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
std::string getAdditionalProblem() const override
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
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:199
static const RGBColor BLACK
Definition RGBColor.h:200