Eclipse SUMO - Simulation of Urban MObility
GNEVariableSpeedSignStep.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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 {}, {}, {}, {}, {}, {}, {}, {},
35 std::map<std::string, std::string>()),
36 myTime(0) {
37  // reset default values
39 }
40 
41 
42 GNEVariableSpeedSignStep::GNEVariableSpeedSignStep(GNEAdditional* variableSpeedSignParent, SUMOTime time, const std::string& speed) :
43  GNEAdditional(variableSpeedSignParent->getNet(), GLO_VSS_STEP, SUMO_TAG_STEP, "",
44 {}, {}, {}, {variableSpeedSignParent}, {}, {}, {}, {},
45 std::map<std::string, std::string>()),
46 myTime(time),
47 mySpeed(speed) {
48  // update boundary of rerouter parent
49  variableSpeedSignParent->updateCenteringBoundary(true);
50 }
51 
52 
54 
55 
56 void
58  device.openTag(SUMO_TAG_STEP);
61  device.closeTag();
62 }
63 
64 
67  // VSS Steps cannot be moved
68  return nullptr;
69 }
70 
71 
74  return myTime;
75 }
76 
77 
78 void
80  // update centering boundary (needed for centering)
82 }
83 
84 
87  // get rerouter parent position
88  Position signPosition = getParentAdditionals().front()->getPositionInView();
89  // set position depending of indexes
90  signPosition.add(4.5, (getDrawPositionIndex() * -1) + 1, 0);
91  // return signPosition
92  return signPosition;
93 }
94 
95 
96 void
101 }
102 
103 
104 void
105 GNEVariableSpeedSignStep::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
106  // geometry of this element cannot be splitted
107 }
108 
109 
110 std::string
112  return getParentAdditionals().at(0)->getID();
113 }
114 
115 
116 void
118  // draw rerouter interval as listed attribute
122 }
123 
124 
125 std::string
127  switch (key) {
128  case SUMO_ATTR_ID:
129  return getID();
130  case SUMO_ATTR_TIME:
131  return time2string(myTime);
132  case SUMO_ATTR_SPEED:
133  return mySpeed;
134  case GNE_ATTR_PARENT:
135  return getParentAdditionals().at(0)->getID();
136  case GNE_ATTR_SELECTED:
138  default:
139  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
140  }
141 }
142 
143 
144 double
146  switch (key) {
147  case SUMO_ATTR_TIME:
148  return (double)myTime;
149  default:
150  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
151  }
152 }
153 
154 
155 void
156 GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
157  if (value == getAttribute(key)) {
158  return; //avoid needless changes, later logic relies on the fact that attributes have changed
159  }
160  switch (key) {
161  case SUMO_ATTR_TIME:
162  case SUMO_ATTR_SPEED:
163  case GNE_ATTR_SELECTED:
164  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
165  break;
166  default:
167  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
168  }
169 }
170 
171 
172 bool
173 GNEVariableSpeedSignStep::isValid(SumoXMLAttr key, const std::string& value) {
174  switch (key) {
175  case SUMO_ATTR_TIME:
176  if (canParse<double>(value)) {
177  // Check that
178  double newTime = parse<double>(value);
179  // Only allowed positiv times
180  if (newTime < 0) {
181  return false;
182  }
183  // check that there isn't duplicate times
184  int counter = 0;
185  for (const auto& VSSChild : getParentAdditionals().at(0)->getChildAdditionals()) {
186  if (!VSSChild->getTagProperty().isSymbol() && VSSChild->getAttributeDouble(SUMO_ATTR_TIME) == newTime) {
187  counter++;
188  }
189  }
190  return (counter <= 1);
191  } else {
192  return false;
193  }
194  case SUMO_ATTR_SPEED:
195  if (value.empty()) {
196  return true;
197  } else {
198  return canParse<double>(value);
199  }
200  case GNE_ATTR_SELECTED:
201  return canParse<double>(value);
202  default:
203  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
204  }
205 }
206 
207 
208 bool
210  return true;
211 }
212 
213 
214 std::string
216  return getTagStr();
217 }
218 
219 
220 std::string
222  return getTagStr() + ": " + getAttribute(SUMO_ATTR_TIME);
223 }
224 
225 // ===========================================================================
226 // private
227 // ===========================================================================
228 
229 void
230 GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value) {
231  switch (key) {
232  case SUMO_ATTR_TIME:
233  myTime = string2time(value);
234  break;
235  case SUMO_ATTR_SPEED:
236  mySpeed = value;
237  break;
238  case GNE_ATTR_SELECTED:
239  if (parse<bool>(value)) {
241  } else {
243  }
244  break;
245  default:
246  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
247  }
248 }
249 
250 
251 void
253  // nothing to do
254 }
255 
256 
257 void
259  // nothing to do
260 }
261 
262 
263 /****************************************************************************/
@ GLO_VSS_STEP
a Variable Speed Sign step
@ VARIABLESPEEDSIGN_STEP
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:45
long long int SUMOTime
Definition: SUMOTime.h:32
@ 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:77
void reset()
Resets the boundary.
Definition: Boundary.cpp:65
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
virtual void updateCenteringBoundary(const bool updateGrid)=0
update centering boundary (implies change in RTREE)
const std::string & getID() const
get ID
void drawListedAddtional(const GUIVisualizationSettings &s, const Position &parentPosition, const int offsetX, const int 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
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
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child 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
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 conrrespond 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.
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
SUMOTime getTime() const
get time
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
bool isAttributeEnabled(SumoXMLAttr key) const
std::string getParentName() const
Returns the name of the parent object.
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
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
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
double getAttributeDouble(SumoXMLAttr key) const
Stores the information about how to visualize structures.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
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