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-2019 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 /****************************************************************************/
14 //
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.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 {}, {}, {}, {variableSpeedSignDialog->getEditedAdditional()}, {}, {}, {}, {}, {}, {}) {
37  // fill VSS Step with default values
38  setDefaultValues();
39  // set time Attribute manually
40  if (getParentAdditionals().at(0)->getChildAdditionals().size() > 0) {
41  myTime = getParentAdditionals().at(0)->getChildAdditionals().back()->getAttributeDouble(SUMO_ATTR_TIME) + 1;
42  } else {
43  myTime = 0;
44  }
45 }
46 
47 
48 GNEVariableSpeedSignStep::GNEVariableSpeedSignStep(GNEAdditional* variableSpeedSignParent, double time, double speed) :
49  GNEAdditional(variableSpeedSignParent, variableSpeedSignParent->getViewNet(), GLO_VSS, SUMO_TAG_STEP, "", false,
50 {}, {}, {}, {variableSpeedSignParent}, {}, {}, {}, {}, {}, {}),
51 myTime(time),
52 mySpeed(speed) {
53 }
54 
55 
57 
58 
59 double
61  return myTime;
62 }
63 
64 
65 void
67  // This additional cannot be moved
68 }
69 
70 
71 void
73  // This additional cannot be moved
74 }
75 
76 
77 void
79  // Currently this additional doesn't own a Geometry
80 }
81 
82 
85  return getParentAdditionals().at(0)->getPositionInView();
86 }
87 
88 
91  return getParentAdditionals().at(0)->getCenteringBoundary();
92 }
93 
94 
95 void
96 GNEVariableSpeedSignStep::splitEdgeGeometry(const double /*splitPosition*/, const GNENetElement* /*originalElement*/, const GNENetElement* /*newElement*/, GNEUndoList* /*undoList*/) {
97  // geometry of this element cannot be splitted
98 }
99 
100 
101 std::string
103  return getParentAdditionals().at(0)->getID();
104 }
105 
106 
107 void
109  // Currently This additional isn't drawn
110 }
111 
112 
113 std::string
115  switch (key) {
116  case SUMO_ATTR_ID:
117  return getAdditionalID();
118  case SUMO_ATTR_TIME:
119  return toString(myTime);
120  case SUMO_ATTR_SPEED:
121  return toString(mySpeed);
122  case GNE_ATTR_PARENT:
123  return getParentAdditionals().at(0)->getID();
124  case GNE_ATTR_PARAMETERS:
125  return getParametersStr();
126  default:
127  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
128  }
129 }
130 
131 
132 double
134  switch (key) {
135  case SUMO_ATTR_TIME:
136  return myTime;
137  default:
138  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
139  }
140 }
141 
142 
143 void
144 GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
145  if (value == getAttribute(key)) {
146  return; //avoid needless changes, later logic relies on the fact that attributes have changed
147  }
148  switch (key) {
149  case SUMO_ATTR_ID:
150  case SUMO_ATTR_TIME:
151  case SUMO_ATTR_SPEED:
152  case GNE_ATTR_PARAMETERS:
153  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
154  break;
155  default:
156  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
157  }
158 }
159 
160 
161 bool
162 GNEVariableSpeedSignStep::isValid(SumoXMLAttr key, const std::string& value) {
163  switch (key) {
164  case SUMO_ATTR_ID:
165  return isValidAdditionalID(value);
166  case SUMO_ATTR_TIME:
167  if (canParse<double>(value)) {
168  // Check that
169  double newTime = parse<double>(value);
170  // Only allowed positiv times
171  if (newTime < 0) {
172  return false;
173  }
174  // check that there isn't duplicate times
175  int counter = 0;
176  for (auto i : getParentAdditionals().at(0)->getChildAdditionals()) {
177  if (i->getAttributeDouble(SUMO_ATTR_TIME) == newTime) {
178  counter++;
179  }
180  }
181  return (counter <= 1);
182  } else {
183  return false;
184  }
185  case SUMO_ATTR_SPEED:
186  return canParse<double>(value);
187  case GNE_ATTR_PARAMETERS:
188  return Parameterised::areParametersValid(value);
189  default:
190  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
191  }
192 }
193 
194 
195 bool
197  return true;
198 }
199 
200 
201 std::string
203  return getTagStr();
204 }
205 
206 
207 std::string
209  return getTagStr() + ": " + getAttribute(SUMO_ATTR_TIME);
210 }
211 
212 // ===========================================================================
213 // private
214 // ===========================================================================
215 
216 void
217 GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value) {
218  switch (key) {
219  case SUMO_ATTR_ID:
220  changeAdditionalID(value);
221  break;
222  case SUMO_ATTR_TIME:
223  myTime = parse<double>(value);
224  break;
225  case SUMO_ATTR_SPEED:
226  mySpeed = parse<double>(value);
227  break;
228  case GNE_ATTR_PARAMETERS:
229  setParametersStr(value);
230  break;
231  default:
232  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
233  }
234 }
235 
236 
237 /****************************************************************************/
GNEVariableSpeedSignStep::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEVariableSpeedSignStep.cpp:202
GNEVariableSpeedSignStep::setAttribute
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
Definition: GNEVariableSpeedSignStep.cpp:144
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
Parameterised::getParametersStr
std::string getParametersStr() const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
Definition: Parameterised.cpp:112
GNEVariableSpeedSignStep::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEVariableSpeedSignStep.cpp:108
GNEAdditional::getAdditionalID
const std::string & getAdditionalID() const
Definition: GNEAdditional.cpp:476
GNEVariableSpeedSignStep::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEVariableSpeedSignStep.cpp:208
GNEVariableSpeedSignStep::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEVariableSpeedSignStep.cpp:90
GNEVariableSpeedSignStep::commitGeometryMoving
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNEVariableSpeedSignStep.cpp:72
SUMO_ATTR_SPEED
Definition: SUMOXMLDefinitions.h:384
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
GNEAdditional::changeAdditionalID
void changeAdditionalID(const std::string &newID)
change ID of additional
Definition: GNEAdditional.cpp:502
GNEAdditional::myViewNet
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
Definition: GNEAdditional.h:335
GNEVariableSpeedSignStep::~GNEVariableSpeedSignStep
~GNEVariableSpeedSignStep()
destructor
Definition: GNEVariableSpeedSignStep.cpp:56
GNEAttributeCarrier::GNEChange_Attribute
friend class GNEChange_Attribute
declare friend class
Definition: GNEAttributeCarrier.h:57
GNEUndoList::p_add
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Definition: GNEUndoList.cpp:131
GNEViewNet::getNet
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:1014
GNEHierarchicalParentElements::getParentAdditionals
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
Definition: GNEHierarchicalParentElements.cpp:85
GNEVariableSpeedSignStep::getParentName
std::string getParentName() const
Returns the name of the parent object.
Definition: GNEVariableSpeedSignStep.cpp:102
GNEVariableSpeedSignStep::GNEVariableSpeedSignStep
GNEVariableSpeedSignStep(GNEVariableSpeedSignDialog *variableSpeedSignDialog)
default constructor
Definition: GNEVariableSpeedSignStep.cpp:34
GNEVariableSpeedSignStep::splitEdgeGeometry
void splitEdgeGeometry(const double splitPosition, const GNENetElement *originalElement, const GNENetElement *newElement, GNEUndoList *undoList)
split geometry
Definition: GNEVariableSpeedSignStep.cpp:96
GNEVariableSpeedSignStep::myTime
double myTime
timeStep
Definition: GNEVariableSpeedSignStep.h:137
GNEViewNet.h
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
GNEVariableSpeedSignDialog.h
GNEVariableSpeedSignStep::isAttributeEnabled
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNEVariableSpeedSignStep.cpp:196
GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
Definition: SUMOXMLDefinitions.h:989
SUMO_TAG_STEP
trigger: a step description
Definition: SUMOXMLDefinitions.h:157
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
GNEVariableSpeedSignStep::moveGeometry
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEVariableSpeedSignStep.cpp:66
GNEVariableSpeedSignStep.h
GNENetElement
Definition: GNENetElement.h:43
SUMO_ATTR_TIME
trigger: the time of the step
Definition: SUMOXMLDefinitions.h:676
GNEVariableSpeedSignStep::getAttribute
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
Definition: GNEVariableSpeedSignStep.cpp:114
GNEVariableSpeedSignDialog
Definition: GNEVariableSpeedSignDialog.h:44
Parameterised::setParametersStr
void setParametersStr(const std::string &paramsString)
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
Definition: Parameterised.cpp:139
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
Parameterised::areParametersValid
static bool areParametersValid(const std::string &value, bool report=false)
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
Definition: Parameterised.cpp:166
InvalidArgument
Definition: UtilExceptions.h:56
GNEVariableSpeedSignStep::getAttributeDouble
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNEVariableSpeedSignStep.cpp:133
GNEVariableSpeedSignStep::mySpeed
double mySpeed
speed in this timeStep
Definition: GNEVariableSpeedSignStep.h:140
config.h
GNEVariableSpeedSignStep::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEVariableSpeedSignStep.cpp:84
GNEVariableSpeedSignStep::updateGeometry
void updateGeometry()
update pre-computed geometry information
Definition: GNEVariableSpeedSignStep.cpp:78
GNEVariableSpeedSignStep::getTime
double getTime() const
get time
Definition: GNEVariableSpeedSignStep.cpp:60
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1267
GNEUndoList
Definition: GNEUndoList.h:48
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:345
GNEAdditional::isValidAdditionalID
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Definition: GNEAdditional.cpp:482
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:372
GNEVariableSpeedSignStep::isValid
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEVariableSpeedSignStep.cpp:162
GNEHierarchicalChildElements::getChildAdditionals
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
Definition: GNEHierarchicalChildElements.cpp:131
GNEChange_Attribute.h
GLO_VSS
a Variable Speed Sign
Definition: GUIGlObjectTypes.h:89
GNEUndoList.h
GNE_ATTR_PARENT
parent of an additional element
Definition: SUMOXMLDefinitions.h:987