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();
158 default:
159 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
160 }
161}
162
163
164double
166 switch (key) {
167 case SUMO_ATTR_TIME:
168 return (double)myTime;
169 default:
170 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
171 }
172}
173
174
179
180
181void
182GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
183 if (value == getAttribute(key)) {
184 return; //avoid needless changes, later logic relies on the fact that attributes have changed
185 }
186 switch (key) {
187 case SUMO_ATTR_TIME:
188 case SUMO_ATTR_SPEED:
190 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
191 break;
192 default:
193 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
194 }
195}
196
197
198bool
199GNEVariableSpeedSignStep::isValid(SumoXMLAttr key, const std::string& value) {
200 switch (key) {
201 case SUMO_ATTR_TIME:
202 if (canParse<double>(value)) {
203 // Check that
204 double newTime = parse<double>(value);
205 // Only allowed positiv times
206 if (newTime < 0) {
207 return false;
208 }
209 // check that there isn't duplicate times
210 int counter = 0;
211 for (const auto& VSSChild : getParentAdditionals().at(0)->getChildAdditionals()) {
212 if (!VSSChild->getTagProperty().isSymbol() && VSSChild->getAttributeDouble(SUMO_ATTR_TIME) == newTime) {
213 counter++;
214 }
215 }
216 return (counter <= 1);
217 } else {
218 return false;
219 }
220 case SUMO_ATTR_SPEED:
221 if (value.empty()) {
222 return true;
223 } else {
224 return canParse<double>(value);
225 }
227 return canParse<double>(value);
228 default:
229 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
230 }
231}
232
233
234std::string
238
239
240std::string
244
245// ===========================================================================
246// private
247// ===========================================================================
248
249void
251 switch (key) {
252 case SUMO_ATTR_TIME:
253 myTime = string2time(value);
254 break;
255 case SUMO_ATTR_SPEED:
256 mySpeed = value;
257 break;
259 if (parse<bool>(value)) {
261 } else {
263 }
264 break;
265 default:
266 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
267 }
268}
269
270
271void
273 // nothing to do
274}
275
276
277void
279 // nothing to do
280}
281
282
283/****************************************************************************/
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
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)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
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
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