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-2020 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 
32 GNEVariableSpeedSignStep::GNEVariableSpeedSignStep(GNEAdditional* variableSpeedSignParent, double time, double speed) :
33  GNEAdditional(variableSpeedSignParent->getNet(), GLO_VSS, SUMO_TAG_STEP, "", false,
34 {}, {}, {}, {variableSpeedSignParent}, {}, {}, {}, {}),
35 myTime(time),
36 mySpeed(speed) {
37  // update centering boundary without updating grid
38  updateCenteringBoundary(false);
39 }
40 
41 
43 
44 
46 GNEVariableSpeedSignStep::getMoveOperation(const double /*shapeOffset*/) {
47  // VSS Steps cannot be moved
48  return nullptr;
49 }
50 
51 
52 double
54  return myTime;
55 }
56 
57 
58 void
60  // This additional doesn't own a geometry
61 }
62 
63 
64 void
66  // use boundary of parent element
67  myBoundary = getParentAdditionals().front()->getCenteringBoundary();
68 }
69 
70 
71 void
72 GNEVariableSpeedSignStep::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
73  // geometry of this element cannot be splitted
74 }
75 
76 
77 std::string
79  return getParentAdditionals().at(0)->getID();
80 }
81 
82 
83 void
85  // Currently This additional isn't drawn
86 }
87 
88 
89 std::string
91  switch (key) {
92  case SUMO_ATTR_ID:
93  return getID();
94  case SUMO_ATTR_TIME:
95  return toString(myTime);
96  case SUMO_ATTR_SPEED:
97  return toString(mySpeed);
98  case GNE_ATTR_PARENT:
99  return getParentAdditionals().at(0)->getID();
100  case GNE_ATTR_PARAMETERS:
101  return getParametersStr();
102  default:
103  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
104  }
105 }
106 
107 
108 double
110  switch (key) {
111  case SUMO_ATTR_TIME:
112  return myTime;
113  default:
114  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
115  }
116 }
117 
118 
119 void
120 GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
121  if (value == getAttribute(key)) {
122  return; //avoid needless changes, later logic relies on the fact that attributes have changed
123  }
124  switch (key) {
125  case SUMO_ATTR_TIME:
126  case SUMO_ATTR_SPEED:
127  case GNE_ATTR_PARAMETERS:
128  undoList->p_add(new GNEChange_Attribute(this, key, value));
129  break;
130  default:
131  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
132  }
133 }
134 
135 
136 bool
137 GNEVariableSpeedSignStep::isValid(SumoXMLAttr key, const std::string& value) {
138  switch (key) {
139  case SUMO_ATTR_TIME:
140  if (canParse<double>(value)) {
141  // Check that
142  double newTime = parse<double>(value);
143  // Only allowed positiv times
144  if (newTime < 0) {
145  return false;
146  }
147  // check that there isn't duplicate times
148  int counter = 0;
149  for (const auto& VSSChild : getParentAdditionals().at(0)->getChildAdditionals()) {
150  if (!VSSChild->getTagProperty().isSymbol() && VSSChild->getAttributeDouble(SUMO_ATTR_TIME) == newTime) {
151  counter++;
152  }
153  }
154  return (counter <= 1);
155  } else {
156  return false;
157  }
158  case SUMO_ATTR_SPEED:
159  return canParse<double>(value);
160  case GNE_ATTR_PARAMETERS:
161  return Parameterised::areParametersValid(value);
162  default:
163  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
164  }
165 }
166 
167 
168 bool
170  return true;
171 }
172 
173 
174 std::string
176  return getTagStr();
177 }
178 
179 
180 std::string
182  return getTagStr() + ": " + getAttribute(SUMO_ATTR_TIME);
183 }
184 
185 // ===========================================================================
186 // private
187 // ===========================================================================
188 
189 void
190 GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value) {
191  switch (key) {
192  case SUMO_ATTR_TIME:
193  myTime = parse<double>(value);
194  break;
195  case SUMO_ATTR_SPEED:
196  mySpeed = parse<double>(value);
197  break;
198  case GNE_ATTR_PARAMETERS:
199  setParametersStr(value);
200  break;
201  default:
202  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
203  }
204 }
205 
206 
207 void
209  // nothing to do
210 }
211 
212 
213 void
215  // nothing to do
216 }
217 
218 
219 /****************************************************************************/
@ GLO_VSS
a Variable Speed Sign
@ 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_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ 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:44
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const std::string & getID() const
get ID
Boundary myBoundary
Additional Boundary.
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
move operation
move result
void p_add(GNEChange_Attribute *cmd)
special method, 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)
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
GNEVariableSpeedSignStep(GNEAdditional *variableSpeedSignParent, double time, double speed)
constructor
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double mySpeed
speed in this timeStep
void updateGeometry()
update pre-computed geometry information
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
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 bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".