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#include <config.h>
21
23#include <netedit/GNEUndoList.h>
25
27
28// ===========================================================================
29// member method definitions
30// ===========================================================================
31
35
36
37GNEVariableSpeedSignStep::GNEVariableSpeedSignStep(GNEAdditional* variableSpeedSignParent, SUMOTime time, const std::string& speed) :
38 GNEAdditional(variableSpeedSignParent, SUMO_TAG_STEP, ""),
39 myTime(time),
40 mySpeed(speed) {
41 // set parents
42 setParent<GNEAdditional*>(variableSpeedSignParent);
43 // update boundary of rerouter parent
44 variableSpeedSignParent->updateCenteringBoundary(true);
45}
46
47
49
50
51void
58
59
60bool
62 return true;
63}
64
65
66std::string
70
71
72void
76
77
80 // VSS Steps cannot be moved
81 return nullptr;
82}
83
84
85bool
89
90
95
96
97void
99 // update centering boundary (needed for centering)
101}
102
103
106 // get rerouter parent position
107 Position signPosition = getParentAdditionals().front()->getPositionInView();
108 // set position depending of indexes
109 signPosition.add(4.5, (getDrawPositionIndex() * -1) + 1, 0);
110 // return signPosition
111 return signPosition;
112}
113
114
115void
117 // nothing to do
118}
119
120
121void
122GNEVariableSpeedSignStep::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
123 // geometry of this element cannot be splitted
124}
125
126
127std::string
129 return getParentAdditionals().at(0)->getID();
130}
131
132
133void
140
141
142std::string
144 switch (key) {
145 case SUMO_ATTR_ID:
146 return getMicrosimID();
147 case SUMO_ATTR_TIME:
148 return time2string(myTime);
149 case SUMO_ATTR_SPEED:
150 return mySpeed;
151 case GNE_ATTR_PARENT:
152 return getParentAdditionals().at(0)->getID();
153 default:
154 return getCommonAttribute(this, key);
155 }
156}
157
158
159double
161 switch (key) {
162 case SUMO_ATTR_TIME:
163 return (double)myTime;
164 default:
165 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
166 }
167}
168
169
174
175
176void
177GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
178 if (value == getAttribute(key)) {
179 return; //avoid needless changes, later logic relies on the fact that attributes have changed
180 }
181 switch (key) {
182 case SUMO_ATTR_TIME:
183 case SUMO_ATTR_SPEED:
184 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
185 break;
186 default:
187 setCommonAttribute(key, value, undoList);
188 break;
189 }
190}
191
192
193bool
194GNEVariableSpeedSignStep::isValid(SumoXMLAttr key, const std::string& value) {
195 switch (key) {
196 case SUMO_ATTR_TIME:
197 if (canParse<double>(value)) {
198 // Check that
199 double newTime = parse<double>(value);
200 // Only allowed positiv times
201 if (newTime < 0) {
202 return false;
203 }
204 // check that there isn't duplicate times
205 int counter = 0;
206 for (const auto& VSSChild : getParentAdditionals().at(0)->getChildAdditionals()) {
207 if (!VSSChild->getTagProperty()->isSymbol() && VSSChild->getAttributeDouble(SUMO_ATTR_TIME) == newTime) {
208 counter++;
209 }
210 }
211 return (counter <= 1);
212 } else {
213 return false;
214 }
215 case SUMO_ATTR_SPEED:
216 if (value.empty()) {
217 return true;
218 } else {
219 return canParse<double>(value);
220 }
221 default:
222 return isCommonValid(key, value);
223 }
224}
225
226
227std::string
231
232
233std::string
237
238// ===========================================================================
239// private
240// ===========================================================================
241
242void
244 switch (key) {
245 case SUMO_ATTR_TIME:
246 myTime = string2time(value);
247 break;
248 case SUMO_ATTR_SPEED:
249 mySpeed = value;
250 break;
251 default:
252 setCommonAttribute(this, key, value);
253 break;
254 }
255}
256
257
258void
260 // nothing to do
261}
262
263
264void
266 // nothing to do
267}
268
269
270/****************************************************************************/
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 drawListedAdditional(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)
std::string getCommonAttribute(const Parameterised *parameterised, 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
bool isCommonValid(SumoXMLAttr key, const std::string &value) 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
move operation
move result
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 (must be reimplemented in all detector ch...
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 fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
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
bool checkDrawMoveContour() const
check if draw move contour (red)
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
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.
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
const Parameterised::Map & getParametersMap() const
Returns the inner key/value 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:129
static const RGBColor WHITE
Definition RGBColor.h:195
static const RGBColor BLACK
Definition RGBColor.h:196