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.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  "", {}, {}, {}, {}, {}, {}),
35 myTime(0) {
36  // reset default values
38 }
39 
40 
41 GNEVariableSpeedSignStep::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}, {}, {}),
44 myTime(time),
45 mySpeed(speed) {
46  // update boundary of rerouter parent
47  variableSpeedSignParent->updateCenteringBoundary(true);
48 }
49 
50 
52 
53 
54 void
56  device.openTag(SUMO_TAG_STEP);
59  device.closeTag();
60 }
61 
62 
63 bool
65  return true;
66 }
67 
68 
69 std::string
71  return "";
72 }
73 
74 
75 void
77  // nothing to fix
78 }
79 
80 
83  // VSS Steps cannot be moved
84  return nullptr;
85 }
86 
87 
88 bool
90  return false;
91 }
92 
93 
96  return myTime;
97 }
98 
99 
100 void
102  // update centering boundary (needed for centering)
104 }
105 
106 
107 Position
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 
118 void
120  // nothing to do
121 }
122 
123 
124 void
125 GNEVariableSpeedSignStep::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
126  // geometry of this element cannot be splitted
127 }
128 
129 
130 std::string
132  return getParentAdditionals().at(0)->getID();
133 }
134 
135 
136 void
138  // draw rerouter interval as listed attribute
142 }
143 
144 
145 std::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  case GNE_ATTR_SELECTED:
158  default:
159  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
160  }
161 }
162 
163 
164 double
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 
175 const Parameterised::Map&
177  return PARAMETERS_EMPTY;
178 }
179 
180 
181 void
182 GNEVariableSpeedSignStep::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:
189  case GNE_ATTR_SELECTED:
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 
198 bool
199 GNEVariableSpeedSignStep::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  }
226  case GNE_ATTR_SELECTED:
227  return canParse<double>(value);
228  default:
229  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
230  }
231 }
232 
233 
234 std::string
236  return getTagStr();
237 }
238 
239 
240 std::string
242  return getTagStr() + ": " + getAttribute(SUMO_ATTR_TIME);
243 }
244 
245 // ===========================================================================
246 // private
247 // ===========================================================================
248 
249 void
250 GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value) {
251  switch (key) {
252  case SUMO_ATTR_TIME:
253  myTime = string2time(value);
254  break;
255  case SUMO_ATTR_SPEED:
256  mySpeed = value;
257  break;
258  case GNE_ATTR_SELECTED:
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 
271 void
273  // nothing to do
274 }
275 
276 
277 void
279  // nothing to do
280 }
281 
282 
283 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
@ 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.
Definition: GNEAdditional.h:49
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
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
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.
Definition: GUIGlObject.h:143
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:254
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
Definition: Parameterised.h:45
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