SUMO - Simulation of Urban MObility
GNERerouterInterval.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 "GNERerouterInterval.h"
26 #include <netedit/GNEUndoList.h>
27 
28 
29 // ===========================================================================
30 // member method definitions
31 // ===========================================================================
32 
34  GNEAdditional(rerouterDialog->getEditedAdditional(), rerouterDialog->getEditedAdditional()->getViewNet(), GLO_REROUTER, SUMO_TAG_INTERVAL, "", false) {
35  // fill reroute interval with default values
37 }
38 
39 
40 GNERerouterInterval::GNERerouterInterval(GNEAdditional* rerouterParent, double begin, double end) :
41  GNEAdditional(rerouterParent, rerouterParent->getViewNet(), GLO_REROUTER, SUMO_TAG_INTERVAL, "", false),
42  myBegin(begin),
43  myEnd(end) {
44 }
45 
46 
48 
49 void
51  // This additional cannot be moved
52 }
53 
54 
55 void
57  // This additional cannot be moved
58 }
59 
60 
61 void
63  // Currently this additional doesn't own a Geometry
64 }
65 
66 
70 }
71 
72 
73 std::string
76 }
77 
78 
79 void
81  // Currently This additional isn't drawn
82 }
83 
84 
85 std::string
87  switch (key) {
88  case SUMO_ATTR_ID:
89  return getAdditionalID();
90  case SUMO_ATTR_BEGIN:
91  return toString(myBegin);
92  case SUMO_ATTR_END:
93  return toString(myEnd);
94  case GNE_ATTR_PARENT:
96  case GNE_ATTR_GENERIC:
97  return getGenericParametersStr();
98  default:
99  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
100  }
101 }
102 
103 
104 void
105 GNERerouterInterval::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_ID: {
111  // change ID of Rerouter Interval
112  undoList->p_add(new GNEChange_Attribute(this, key, value));
113  // Change Ids of all Rerouter childs
114  for (auto i : myAdditionalChilds) {
115  i->setAttribute(SUMO_ATTR_ID, generateAdditionalChildID(i->getTagProperty().getTag()), undoList);
116  }
117  break;
118  }
119  case SUMO_ATTR_BEGIN:
120  case SUMO_ATTR_END:
121  case GNE_ATTR_GENERIC:
122  undoList->p_add(new GNEChange_Attribute(this, key, value));
123  break;
124  default:
125  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
126  }
127 }
128 
129 
130 bool
131 GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {
132  switch (key) {
133  case SUMO_ATTR_ID:
134  return isValidAdditionalID(value);
135  case SUMO_ATTR_BEGIN:
136  return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) < myEnd);
137  case SUMO_ATTR_END:
138  return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) > myBegin);
139  case GNE_ATTR_GENERIC:
140  return isGenericParametersValid(value);
141  default:
142  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
143  }
144 }
145 
146 
147 std::string
149  return getTagStr();
150 }
151 
152 
153 std::string
155  return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
156 }
157 
158 // ===========================================================================
159 // private
160 // ===========================================================================
161 
162 void
163 GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
164  switch (key) {
165  case SUMO_ATTR_ID:
166  changeAdditionalID(value);
167  break;
168  case SUMO_ATTR_BEGIN:
169  myBegin = parse<double>(value);
170  break;
171  case SUMO_ATTR_END:
172  myEnd = parse<double>(value);
173  break;
174  case GNE_ATTR_GENERIC:
176  break;
177  default:
178  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
179  }
180 }
181 
182 /****************************************************************************/
std::string getParentName() const
Returns the name of the parent object.
void updateGeometry(bool updateGrid)
update pre-computed geometry information
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
GNERerouterInterval(GNERerouterDialog *rerouterDialog)
constructor (Used in GNERerouterDialog)
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Stores the information about how to visualize structures.
weights: time range begin
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void setDefaultValues()
change all attributes of additional with their default values (note: this cannot be undo) ...
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
Dialog for edit rerouters.
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
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
friend class GNEChange_Attribute
declare friend class
double myBegin
begin timeStep
a Rerouter
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
const std::string getID() const
function to support debugging
double myEnd
end timeStep
std::string getAttribute(SumoXMLAttr key) const
std::vector< GNEAdditional * > myAdditionalChilds
vector with the Additional childs
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
weights: time range end
std::string getGenericParametersStr() const
return generic parameters in string format
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
std::string generateAdditionalChildID(SumoXMLTag childTag)
gererate a new ID for an additional child
an aggreagated-output interval
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
parent of an additional element
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
~GNERerouterInterval()
destructor
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
GNEAdditional * myFirstAdditionalParent
pointer to first Additional parent
virtual Position getPositionInView() const =0
Returns position of additional in view.