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-2024 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
61
62
63bool
65 return true;
66}
67
68
69std::string
73
74
75void
79
80
83 // VSS Steps cannot be moved
84 return nullptr;
85}
86
87
88bool
92
93
98
99
100void
102 // update centering boundary (needed for centering)
104}
105
106
109 // get rerouter parent position
110 Position signPosition = getParentAdditionals().front()->getPositionInView();
111 // set position depending of indexes
112 signPosition.add(4.5, (getDrawPositionIndex() * -1) + 1, 0);
113 // return signPosition
114 return signPosition;
115}
116
117
118void
120 // nothing to do
121}
122
123
124void
125GNEVariableSpeedSignStep::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
126 // geometry of this element cannot be splitted
127}
128
129
130std::string
132 return getParentAdditionals().at(0)->getID();
133}
134
135
136void
143
144
145std::string
147 switch (key) {
148 case SUMO_ATTR_ID:
149 return getMicrosimID();
150 case SUMO_ATTR_TIME:
151 return time2string(myTime);
152 case SUMO_ATTR_SPEED:
153 return mySpeed;
154 case GNE_ATTR_PARENT:
155 return getParentAdditionals().at(0)->getID();
156 default:
157 return getCommonAttribute(key);
158 }
159}
160
161
162double
164 switch (key) {
165 case SUMO_ATTR_TIME:
166 return (double)myTime;
167 default:
168 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
169 }
170}
171
172
177
178
179void
180GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
181 if (value == getAttribute(key)) {
182 return; //avoid needless changes, later logic relies on the fact that attributes have changed
183 }
184 switch (key) {
185 case SUMO_ATTR_TIME:
186 case SUMO_ATTR_SPEED:
187 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
188 break;
189 default:
190 setCommonAttribute(key, value, undoList);
191 break;
192 }
193}
194
195
196bool
197GNEVariableSpeedSignStep::isValid(SumoXMLAttr key, const std::string& value) {
198 switch (key) {
199 case SUMO_ATTR_TIME:
200 if (canParse<double>(value)) {
201 // Check that
202 double newTime = parse<double>(value);
203 // Only allowed positiv times
204 if (newTime < 0) {
205 return false;
206 }
207 // check that there isn't duplicate times
208 int counter = 0;
209 for (const auto& VSSChild : getParentAdditionals().at(0)->getChildAdditionals()) {
210 if (!VSSChild->getTagProperty().isSymbol() && VSSChild->getAttributeDouble(SUMO_ATTR_TIME) == newTime) {
211 counter++;
212 }
213 }
214 return (counter <= 1);
215 } else {
216 return false;
217 }
218 case SUMO_ATTR_SPEED:
219 if (value.empty()) {
220 return true;
221 } else {
222 return canParse<double>(value);
223 }
224 default:
225 return isCommonValid(key, value);
226 }
227}
228
229
230std::string
234
235
236std::string
240
241// ===========================================================================
242// private
243// ===========================================================================
244
245void
247 switch (key) {
248 case SUMO_ATTR_TIME:
249 myTime = string2time(value);
250 break;
251 case SUMO_ATTR_SPEED:
252 mySpeed = value;
253 break;
254 default:
255 setCommonAttribute(key, value);
256 break;
257 }
258}
259
260
261void
263 // nothing to do
264}
265
266
267void
269 // nothing to do
270}
271
272
273/****************************************************************************/
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
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:69
@ 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
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 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)
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)
static const Parameterised::Map PARAMETERS_EMPTY
empty parameter maps (used by ACs without parameters)
void resetDefaultValues()
reset attribute carrier to their default values
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 std::vector< 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
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:132
static const RGBColor WHITE
Definition RGBColor.h:192
static const RGBColor BLACK
Definition RGBColor.h:193