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 
23 #include <utils/common/ToString.h>
27 #include <netedit/GNEUndoList.h>
28 
30 #include "GNEVariableSpeedSign.h"
31 
32 
33 // ===========================================================================
34 // member method definitions
35 // ===========================================================================
36 
38  GNEAdditional(variableSpeedSignDialog->getEditedAdditional(), variableSpeedSignDialog->getEditedAdditional()->getViewNet(), GLO_VSS, SUMO_TAG_STEP, "", false) {
39  // fill VSS Step with default values
41  // set time Attribute manually
42  if (myFirstAdditionalParent->getAdditionalChilds().size() > 0) {
43  myTime = parse<double>(myFirstAdditionalParent->getAdditionalChilds().back()->getAttribute(SUMO_ATTR_TIME)) + 1;
44  } else {
45  myTime = 0;
46  }
47 }
48 
49 
50 GNEVariableSpeedSignStep::GNEVariableSpeedSignStep(GNEAdditional* variableSpeedSignParent, double time, double speed) :
51  GNEAdditional(variableSpeedSignParent, variableSpeedSignParent->getViewNet(), GLO_VSS, SUMO_TAG_STEP, "", false),
52  myTime(time),
53  mySpeed(speed) {
54 }
55 
56 
58 
59 
60 double
62  return myTime;
63 }
64 
65 
66 void
68  // This additional cannot be moved
69 }
70 
71 
72 void
74  // This additional cannot be moved
75 }
76 
77 
78 void
80  // Currently this additional doesn't own a Geometry
81 }
82 
83 
87 }
88 
89 
90 std::string
93 }
94 
95 
96 void
98  // Currently This additional isn't drawn
99 }
100 
101 
102 std::string
104  switch (key) {
105  case SUMO_ATTR_ID:
106  return getAdditionalID();
107  case SUMO_ATTR_TIME:
108  return toString(myTime);
109  case SUMO_ATTR_SPEED:
110  return toString(mySpeed);
111  case GNE_ATTR_PARENT:
112  return myFirstAdditionalParent->getID();
113  case GNE_ATTR_GENERIC:
114  return getGenericParametersStr();
115  default:
116  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
117  }
118 }
119 
120 
121 void
122 GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
123  if (value == getAttribute(key)) {
124  return; //avoid needless changes, later logic relies on the fact that attributes have changed
125  }
126  switch (key) {
127  case SUMO_ATTR_ID:
128  case SUMO_ATTR_TIME:
129  case SUMO_ATTR_SPEED:
130  case GNE_ATTR_GENERIC:
131  undoList->p_add(new GNEChange_Attribute(this, key, value));
132  break;
133  default:
134  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
135  }
136 }
137 
138 
139 bool
140 GNEVariableSpeedSignStep::isValid(SumoXMLAttr key, const std::string& value) {
141  switch (key) {
142  case SUMO_ATTR_ID:
143  return isValidAdditionalID(value);
144  case SUMO_ATTR_TIME:
145  if (canParse<double>(value)) {
146  // Check that
147  double newTime = parse<double>(value);
148  // Only allowed positiv times
149  if (newTime < 0) {
150  return false;
151  }
152  // check that there isn't duplicate times
153  int counter = 0;
154  for (auto i : myFirstAdditionalParent->getAdditionalChilds()) {
155  if (parse<double>(i->getAttribute(SUMO_ATTR_TIME)) == newTime) {
156  counter++;
157  }
158  }
159  return (counter <= 1);
160  } else {
161  return false;
162  }
163  case SUMO_ATTR_SPEED:
164  return canParse<double>(value) && (parse<double>(value) >= 0);
165  case GNE_ATTR_GENERIC:
166  return isGenericParametersValid(value);
167  default:
168  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
169  }
170 }
171 
172 
173 std::string
175  return toString(getTag());
176 }
177 
178 
179 std::string
181  return toString(getTag()) + ": " + getAttribute(SUMO_ATTR_TIME);
182 }
183 
184 // ===========================================================================
185 // private
186 // ===========================================================================
187 
188 void
189 GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value) {
190  switch (key) {
191  case SUMO_ATTR_ID:
192  changeAdditionalID(value);
193  break;
194  case SUMO_ATTR_TIME:
195  myTime = parse<double>(value);
196  break;
197  case SUMO_ATTR_SPEED:
198  mySpeed = parse<double>(value);
199  break;
200  case GNE_ATTR_GENERIC:
202  break;
203  default:
204  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
205  }
206 }
207 
208 
209 /****************************************************************************/
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
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
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 moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
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:53
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 Addititional parent
trigger: a step description
SumoXMLTag getTag() const
get XML Tag assigned to this object
virtual Position getPositionInView() const =0
Returns position of additional in view.