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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
25 #include <netedit/GNEUndoList.h>
26 
28 
29 
30 // ===========================================================================
31 // member method definitions
32 // ===========================================================================
33 
35  GNEAdditional(variableSpeedSignDialog->getEditedAdditional(), variableSpeedSignDialog->getEditedAdditional()->getViewNet(), GLO_VSS, SUMO_TAG_STEP, "", false) {
36  // fill VSS Step with default values
38  // set time Attribute manually
39  if (myFirstAdditionalParent->getAdditionalChilds().size() > 0) {
40  myTime = parse<double>(myFirstAdditionalParent->getAdditionalChilds().back()->getAttribute(SUMO_ATTR_TIME)) + 1;
41  } else {
42  myTime = 0;
43  }
44 }
45 
46 
47 GNEVariableSpeedSignStep::GNEVariableSpeedSignStep(GNEAdditional* variableSpeedSignParent, double time, double speed) :
48  GNEAdditional(variableSpeedSignParent, variableSpeedSignParent->getViewNet(), GLO_VSS, SUMO_TAG_STEP, "", false),
49  myTime(time),
50  mySpeed(speed) {
51 }
52 
53 
55 
56 
57 double
59  return myTime;
60 }
61 
62 
63 void
65  // This additional cannot be moved
66 }
67 
68 
69 void
71  // This additional cannot be moved
72 }
73 
74 
75 void
77  // Currently this additional doesn't own a Geometry
78 }
79 
80 
84 }
85 
86 
87 std::string
90 }
91 
92 
93 void
95  // Currently This additional isn't drawn
96 }
97 
98 
99 std::string
101  switch (key) {
102  case SUMO_ATTR_ID:
103  return getAdditionalID();
104  case SUMO_ATTR_TIME:
105  return toString(myTime);
106  case SUMO_ATTR_SPEED:
107  return toString(mySpeed);
108  case GNE_ATTR_PARENT:
109  return myFirstAdditionalParent->getID();
110  case GNE_ATTR_GENERIC:
111  return getGenericParametersStr();
112  default:
113  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
114  }
115 }
116 
117 
118 void
119 GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
120  if (value == getAttribute(key)) {
121  return; //avoid needless changes, later logic relies on the fact that attributes have changed
122  }
123  switch (key) {
124  case SUMO_ATTR_ID:
125  case SUMO_ATTR_TIME:
126  case SUMO_ATTR_SPEED:
127  case GNE_ATTR_GENERIC:
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_ID:
140  return isValidAdditionalID(value);
141  case SUMO_ATTR_TIME:
142  if (canParse<double>(value)) {
143  // Check that
144  double newTime = parse<double>(value);
145  // Only allowed positiv times
146  if (newTime < 0) {
147  return false;
148  }
149  // check that there isn't duplicate times
150  int counter = 0;
151  for (auto i : myFirstAdditionalParent->getAdditionalChilds()) {
152  if (parse<double>(i->getAttribute(SUMO_ATTR_TIME)) == newTime) {
153  counter++;
154  }
155  }
156  return (counter <= 1);
157  } else {
158  return false;
159  }
160  case SUMO_ATTR_SPEED:
161  return canParse<double>(value) && (parse<double>(value) >= 0);
162  case GNE_ATTR_GENERIC:
163  return isGenericParametersValid(value);
164  default:
165  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
166  }
167 }
168 
169 
170 std::string
172  return getTagStr();
173 }
174 
175 
176 std::string
178  return getTagStr() + ": " + getAttribute(SUMO_ATTR_TIME);
179 }
180 
181 // ===========================================================================
182 // private
183 // ===========================================================================
184 
185 void
186 GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value) {
187  switch (key) {
188  case SUMO_ATTR_ID:
189  changeAdditionalID(value);
190  break;
191  case SUMO_ATTR_TIME:
192  myTime = parse<double>(value);
193  break;
194  case SUMO_ATTR_SPEED:
195  mySpeed = parse<double>(value);
196  break;
197  case GNE_ATTR_GENERIC:
199  break;
200  default:
201  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
202  }
203 }
204 
205 
206 /****************************************************************************/
void updateGeometry(bool updateGrid)
update pre-computed geometry information
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
a Variable Speed Sign
const std::string & getAdditionalID() const
returns Additional ID
GNEVariableSpeedSignStep(GNEVariableSpeedSignDialog *variableSpeedSignDialog)
default constructor
Stores the information about how to visualize structures.
double getTime() const
get time
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void setDefaultValues()
change all attributes of additional with their default values (note: this cannot be undo) ...
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
Position getPositionInView() const
Returns position of additional in view.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
double mySpeed
speed in this timeStep
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
friend class GNEChange_Attribute
declare friend class
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
const std::string getID() const
function to support debugging
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
trigger: the time of the step
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
const std::string & getTagStr() const
get tag assigned to this object in string format
std::string getGenericParametersStr() const
return generic parameters in string format
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
parent of an additional element
std::string getParentName() const
Returns the name of the parent object.
const std::vector< GNEAdditional * > & getAdditionalChilds() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
GNEAdditional * myFirstAdditionalParent
pointer to first Additional parent
trigger: a step description
virtual Position getPositionInView() const =0
Returns position of additional in view.