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-2023 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
92
93
94void
96 // update centering boundary (needed for centering)
98}
99
100
103 // get rerouter parent position
104 Position signPosition = getParentAdditionals().front()->getPositionInView();
105 // set position depending of indexes
106 signPosition.add(4.5, (getDrawPositionIndex() * -1) + 1, 0);
107 // return signPosition
108 return signPosition;
109}
110
111
112void
118
119
120void
121GNEVariableSpeedSignStep::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
122 // geometry of this element cannot be splitted
123}
124
125
126std::string
128 return getParentAdditionals().at(0)->getID();
129}
130
131
132void
139
140
141std::string
143 switch (key) {
144 case SUMO_ATTR_ID:
145 return getMicrosimID();
146 case SUMO_ATTR_TIME:
147 return time2string(myTime);
148 case SUMO_ATTR_SPEED:
149 return mySpeed;
150 case GNE_ATTR_PARENT:
151 return getParentAdditionals().at(0)->getID();
154 default:
155 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
156 }
157}
158
159
160double
162 switch (key) {
163 case SUMO_ATTR_TIME:
164 return (double)myTime;
165 default:
166 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
167 }
168}
169
170
175
176
177void
178GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
179 if (value == getAttribute(key)) {
180 return; //avoid needless changes, later logic relies on the fact that attributes have changed
181 }
182 switch (key) {
183 case SUMO_ATTR_TIME:
184 case SUMO_ATTR_SPEED:
186 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
187 break;
188 default:
189 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
190 }
191}
192
193
194bool
195GNEVariableSpeedSignStep::isValid(SumoXMLAttr key, const std::string& value) {
196 switch (key) {
197 case SUMO_ATTR_TIME:
198 if (canParse<double>(value)) {
199 // Check that
200 double newTime = parse<double>(value);
201 // Only allowed positiv times
202 if (newTime < 0) {
203 return false;
204 }
205 // check that there isn't duplicate times
206 int counter = 0;
207 for (const auto& VSSChild : getParentAdditionals().at(0)->getChildAdditionals()) {
208 if (!VSSChild->getTagProperty().isSymbol() && VSSChild->getAttributeDouble(SUMO_ATTR_TIME) == newTime) {
209 counter++;
210 }
211 }
212 return (counter <= 1);
213 } else {
214 return false;
215 }
216 case SUMO_ATTR_SPEED:
217 if (value.empty()) {
218 return true;
219 } else {
220 return canParse<double>(value);
221 }
223 return canParse<double>(value);
224 default:
225 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
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;
255 if (parse<bool>(value)) {
257 } else {
259 }
260 break;
261 default:
262 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
263 }
264}
265
266
267void
269 // nothing to do
270}
271
272
273void
275 // nothing to do
276}
277
278
279/****************************************************************************/
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
@ 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.
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
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
bool isAdditionalValid() const
check if current additional is valid to be writed into XML (must be reimplemented in all detector chi...
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
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:125
static const RGBColor WHITE
Definition RGBColor.h:192
static const RGBColor BLACK
Definition RGBColor.h:193