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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 //
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
29 #include <utils/common/ToString.h>
31 
33 #include "GNEVariableSpeedSign.h"
35 #include "GNEChange_Attribute.h"
36 #include "GNEUndoList.h"
37 
38 
39 // ===========================================================================
40 // member method definitions
41 // ===========================================================================
42 
45  myVariableSpeedSignParent(variableSpeedSignDialog->getEditedVariableSpeedSign()),
46  myTime(0),
47  mySpeed(getDefaultValue<double>(SUMO_TAG_STEP, SUMO_ATTR_SPEED)) {
48  // set Time
49  if (variableSpeedSignDialog->getEditedVariableSpeedSign()->getVariableSpeedSignSteps().size() > 0) {
50  myTime = variableSpeedSignDialog->getEditedVariableSpeedSign()->getVariableSpeedSignSteps().back()->getTime() + 1;
51  }
52 }
53 
54 
55 GNEVariableSpeedSignStep::GNEVariableSpeedSignStep(GNEVariableSpeedSign* variableSpeedSignParent, double time, double speed) :
57  myVariableSpeedSignParent(variableSpeedSignParent),
58  myTime(time),
59  mySpeed(speed) {
60 }
61 
62 
64 
65 
69 }
70 
71 
72 void
74  // Open VSS tag
75  device.openTag(SUMO_TAG_STEP);
76  // Write TimeSTep
78  // Write speed
80  // Close VSS tag
81  device.closeTag();
82 }
83 
84 
85 double
87  return myTime;
88 }
89 
90 
91 std::string
93  switch (key) {
94  case SUMO_ATTR_TIME:
95  return toString(myTime);
96  case SUMO_ATTR_SPEED:
97  return toString(mySpeed);
98  default:
99  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
100  }
101 }
102 
103 
104 void
105 GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
106  if (value == getAttribute(key)) {
107  return; //avoid needless changes, later logic relies on the fact that attributes have changed
108  }
109  switch (key) {
110  case SUMO_ATTR_TIME:
111  case SUMO_ATTR_SPEED:
112  undoList->p_add(new GNEChange_Attribute(this, key, value));
113  break;
114  default:
115  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
116  }
117 }
118 
119 
120 bool
121 GNEVariableSpeedSignStep::isValid(SumoXMLAttr key, const std::string& value) {
122  switch (key) {
123  case SUMO_ATTR_TIME:
124  return canParse<double>(value) && (parse<double>(value) >= 0);
125  case SUMO_ATTR_SPEED:
126  return canParse<double>(value) && (parse<double>(value) >= 0);
127  default:
128  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
129  }
130 }
131 
132 // ===========================================================================
133 // private
134 // ===========================================================================
135 
136 void
137 GNEVariableSpeedSignStep::setAttribute(SumoXMLAttr key, const std::string& value) {
138  switch (key) {
139  case SUMO_ATTR_TIME: {
140  myTime = parse<double>(value);
141  break;
142  }
143  case SUMO_ATTR_SPEED: {
144  mySpeed = parse<double>(value);
145  break;
146  }
147  default:
148  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
149  }
150 }
151 
152 
153 /****************************************************************************/
GNEVariableSpeedSign * myVariableSpeedSignParent
pointer to variable speed sign parent
void writeStep(OutputDevice &device)
write step into XML
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
const std::vector< GNEVariableSpeedSignStep * > & getVariableSpeedSignSteps() const
get values of variable speed signal
GNEVariableSpeedSignStep(GNEVariableSpeedSignDialog *variableSpeedSignDialog)
default constructor
double getTime() const
get time
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
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:55
double mySpeed
speed in this timeStep
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
friend class GNEChange_Attribute
declare friend class
GNEVariableSpeedSign * getEditedVariableSpeedSign() const
get edited Variable Speed Sign
bool isValid(SumoXMLAttr key, const std::string &value)
trigger: the time of the step
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
GNEVariableSpeedSign * getVariableSpeedSignParent() const
get variable speed sign parent
trigger: a step description
SumoXMLTag getTag() const
get XML Tag assigned to this object