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 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
25 #include <netedit/GNEUndoList.h>
26 #include <netedit/GNEViewNet.h>
27 
29 
30 
31 // ===========================================================================
32 // member method definitions
33 // ===========================================================================
34 
36  GNEAdditional(variableSpeedSignDialog->getEditedAdditional(), variableSpeedSignDialog->getEditedAdditional()->getViewNet(), GLO_VSS, SUMO_TAG_STEP, "", false,
37 {}, {}, {}, {variableSpeedSignDialog->getEditedAdditional()}, {}, {}, {}, {}, {}, {}) {
38  // fill VSS Step with default values
39  setDefaultValues();
40  // set time Attribute manually
41  if (getAdditionalParents().at(0)->getAdditionalChildren().size() > 0) {
42  myTime = parse<double>(getAdditionalParents().at(0)->getAdditionalChildren().back()->getAttribute(SUMO_ATTR_TIME)) + 1;
43  } else {
44  myTime = 0;
45  }
46 }
47 
48 
49 GNEVariableSpeedSignStep::GNEVariableSpeedSignStep(GNEAdditional* variableSpeedSignParent, double time, double speed) :
50  GNEAdditional(variableSpeedSignParent, variableSpeedSignParent->getViewNet(), GLO_VSS, SUMO_TAG_STEP, "", false,
51 {}, {}, {}, {variableSpeedSignParent}, {}, {}, {}, {}, {}, {}),
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 
86  return getAdditionalParents().at(0)->getPositionInView();
87 }
88 
89 
92  return getAdditionalParents().at(0)->getCenteringBoundary();
93 }
94 
95 
96 std::string
98  return getAdditionalParents().at(0)->getID();
99 }
100 
101 
102 void
104  // Currently This additional isn't drawn
105 }
106 
107 
108 std::string
110  switch (key) {
111  case SUMO_ATTR_ID:
112  return getAdditionalID();
113  case SUMO_ATTR_TIME:
114  return toString(myTime);
115  case SUMO_ATTR_SPEED:
116  return toString(mySpeed);
117  case GNE_ATTR_PARENT:
118  return getAdditionalParents().at(0)->getID();
119  case GNE_ATTR_GENERIC:
120  return getGenericParametersStr();
121  default:
122  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
123  }
124 }
125 
126 
127 void
128 GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
129  if (value == getAttribute(key)) {
130  return; //avoid needless changes, later logic relies on the fact that attributes have changed
131  }
132  switch (key) {
133  case SUMO_ATTR_ID:
134  case SUMO_ATTR_TIME:
135  case SUMO_ATTR_SPEED:
136  case GNE_ATTR_GENERIC:
137  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
138  break;
139  default:
140  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
141  }
142 }
143 
144 
145 bool
146 GNEVariableSpeedSignStep::isValid(SumoXMLAttr key, const std::string& value) {
147  switch (key) {
148  case SUMO_ATTR_ID:
149  return isValidAdditionalID(value);
150  case SUMO_ATTR_TIME:
151  if (canParse<double>(value)) {
152  // Check that
153  double newTime = parse<double>(value);
154  // Only allowed positiv times
155  if (newTime < 0) {
156  return false;
157  }
158  // check that there isn't duplicate times
159  int counter = 0;
160  for (auto i : getAdditionalParents().at(0)->getAdditionalChildren()) {
161  if (parse<double>(i->getAttribute(SUMO_ATTR_TIME)) == newTime) {
162  counter++;
163  }
164  }
165  return (counter <= 1);
166  } else {
167  return false;
168  }
169  case SUMO_ATTR_SPEED:
170  return canParse<double>(value);
171  case GNE_ATTR_GENERIC:
172  return isGenericParametersValid(value);
173  default:
174  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
175  }
176 }
177 
178 
179 std::string
181  return getTagStr();
182 }
183 
184 
185 std::string
187  return getTagStr() + ": " + getAttribute(SUMO_ATTR_TIME);
188 }
189 
190 // ===========================================================================
191 // private
192 // ===========================================================================
193 
194 void
195 GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value) {
196  switch (key) {
197  case SUMO_ATTR_ID:
198  changeAdditionalID(value);
199  break;
200  case SUMO_ATTR_TIME:
201  myTime = parse<double>(value);
202  break;
203  case SUMO_ATTR_SPEED:
204  mySpeed = parse<double>(value);
205  break;
206  case GNE_ATTR_GENERIC:
208  break;
209  default:
210  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
211  }
212 }
213 
214 
215 /****************************************************************************/
GNEVariableSpeedSignStep::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEVariableSpeedSignStep.cpp:180
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:128
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
GNEVariableSpeedSignStep::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEVariableSpeedSignStep.cpp:103
GNEAdditional::setGenericParametersStr
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
Definition: GNEAdditional.cpp:704
GNEAdditional::getAdditionalID
const std::string & getAdditionalID() const
Definition: GNEAdditional.cpp:578
GNEVariableSpeedSignStep::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEVariableSpeedSignStep.cpp:186
GNEAttributeCarrier::isGenericParametersValid
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
Definition: GNEAttributeCarrier.cpp:1354
GNEVariableSpeedSignStep::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEVariableSpeedSignStep.cpp:91
GNEVariableSpeedSignStep::commitGeometryMoving
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNEVariableSpeedSignStep.cpp:73
SUMO_ATTR_SPEED
Definition: SUMOXMLDefinitions.h:385
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
GNEAdditional::changeAdditionalID
void changeAdditionalID(const std::string &newID)
change ID of additional
Definition: GNEAdditional.cpp:604
GNEAdditional::myViewNet
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
Definition: GNEAdditional.h:365
GNEVariableSpeedSignStep::~GNEVariableSpeedSignStep
~GNEVariableSpeedSignStep()
destructor
Definition: GNEVariableSpeedSignStep.cpp:57
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:132
GNEViewNet::getNet
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
GNEVariableSpeedSignStep::getParentName
std::string getParentName() const
Returns the name of the parent object.
Definition: GNEVariableSpeedSignStep.cpp:97
GNEVariableSpeedSignStep::GNEVariableSpeedSignStep
GNEVariableSpeedSignStep(GNEVariableSpeedSignDialog *variableSpeedSignDialog)
default constructor
Definition: GNEVariableSpeedSignStep.cpp:35
GNEVariableSpeedSignStep::myTime
double myTime
timeStep
Definition: GNEVariableSpeedSignStep.h:124
GNEViewNet.h
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
GNEVariableSpeedSignDialog.h
SUMO_TAG_STEP
trigger: a step description
Definition: SUMOXMLDefinitions.h:158
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
GNEVariableSpeedSignStep::moveGeometry
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEVariableSpeedSignStep.cpp:67
GNEVariableSpeedSignStep.h
SUMO_ATTR_TIME
trigger: the time of the step
Definition: SUMOXMLDefinitions.h:673
GNEVariableSpeedSignStep::getAttribute
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
Definition: GNEVariableSpeedSignStep.cpp:109
GNEVariableSpeedSignDialog
Definition: GNEVariableSpeedSignDialog.h:45
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GNE_ATTR_GENERIC
generic attribute
Definition: SUMOXMLDefinitions.h:986
GNEHierarchicalElementParents::getAdditionalParents
const std::vector< GNEAdditional * > & getAdditionalParents() const
return vector of additionals that have as Parent this edge (For example, Calibrators)
Definition: GNEHierarchicalElementParents.cpp:86
InvalidArgument
Definition: UtilExceptions.h:57
GNEAdditional::getGenericParametersStr
std::string getGenericParametersStr() const
return generic parameters in string format
Definition: GNEAdditional.cpp:678
GNEHierarchicalElementChildren::getAdditionalChildren
const std::vector< GNEAdditional * > & getAdditionalChildren() const
return vector of additionals that have as Parent this edge (For example, Calibrators)
Definition: GNEHierarchicalElementChildren.cpp:132
GNEVariableSpeedSignStep::mySpeed
double mySpeed
speed in this timeStep
Definition: GNEVariableSpeedSignStep.h:127
config.h
GNEVariableSpeedSignStep::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEVariableSpeedSignStep.cpp:85
GNEVariableSpeedSignStep::updateGeometry
void updateGeometry()
update pre-computed geometry information
Definition: GNEVariableSpeedSignStep.cpp:79
GNEVariableSpeedSignStep::getTime
double getTime() const
get time
Definition: GNEVariableSpeedSignStep.cpp:61
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1165
GNEUndoList
Definition: GNEUndoList.h:49
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:346
GNEAdditional::isValidAdditionalID
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Definition: GNEAdditional.cpp:584
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:373
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:146
GNEChange_Attribute.h
GLO_VSS
a Variable Speed Sign
Definition: GUIGlObjectTypes.h:90
GNEUndoList.h
GNE_ATTR_PARENT
parent of an additional element
Definition: SUMOXMLDefinitions.h:984