Eclipse 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-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 
28 #include "GNERerouterInterval.h"
29 
30 // ===========================================================================
31 // member method definitions
32 // ===========================================================================
33 
35  GNEAdditional(rerouterDialog->getEditedAdditional(), rerouterDialog->getEditedAdditional()->getViewNet(), GLO_REROUTER, SUMO_TAG_INTERVAL, "", false,
36 {}, {}, {}, {rerouterDialog->getEditedAdditional()}, {}, {}, {}, {}, {}, {}) {
37  // fill reroute interval with default values
39 }
40 
41 
43  GNEAdditional(rerouterParent, rerouterParent->getViewNet(), GLO_REROUTER, SUMO_TAG_INTERVAL, "", false,
44 {}, {}, {}, {rerouterParent}, {}, {}, {}, {}, {}, {}),
45 myBegin(begin),
46 myEnd(end) {
47 }
48 
49 
51 
52 void
54  // This additional cannot be moved
55 }
56 
57 
58 void
60  // This additional cannot be moved
61 }
62 
63 
64 void
66  // Currently this additional doesn't own a Geometry
67 }
68 
69 
72  return getAdditionalParents().at(0)->getPositionInView();
73 }
74 
75 
78  return getAdditionalParents().at(0)->getCenteringBoundary();
79 }
80 
81 
82 std::string
84  return getAdditionalParents().at(0)->getID();
85 }
86 
87 
88 void
90  // Currently This additional isn't drawn
91 }
92 
93 
94 std::string
96  switch (key) {
97  case SUMO_ATTR_ID:
98  return getAdditionalID();
99  case SUMO_ATTR_BEGIN:
100  return time2string(myBegin);
101  case SUMO_ATTR_END:
102  return time2string(myEnd);
103  case GNE_ATTR_PARENT:
104  return getAdditionalParents().at(0)->getID();
105  case GNE_ATTR_GENERIC:
106  return getGenericParametersStr();
107  default:
108  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
109  }
110 }
111 
112 
113 void
114 GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
115  if (value == getAttribute(key)) {
116  return; //avoid needless changes, later logic relies on the fact that attributes have changed
117  }
118  switch (key) {
119  case SUMO_ATTR_ID: {
120  // change ID of Rerouter Interval
121  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
122  // Change Ids of all Rerouter children
123  for (auto i : getAdditionalChildren()) {
124  i->setAttribute(SUMO_ATTR_ID, generateChildID(i->getTagProperty().getTag()), undoList);
125  }
126  break;
127  }
128  case SUMO_ATTR_BEGIN:
129  case SUMO_ATTR_END:
130  case GNE_ATTR_GENERIC:
131  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
132  break;
133  default:
134  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
135  }
136 }
137 
138 
139 bool
140 GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {
141  switch (key) {
142  case SUMO_ATTR_ID:
143  return isValidAdditionalID(value);
144  case SUMO_ATTR_BEGIN:
145  return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) < myEnd);
146  case SUMO_ATTR_END:
147  return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) > myBegin);
148  case GNE_ATTR_GENERIC:
149  return isGenericParametersValid(value);
150  default:
151  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
152  }
153 }
154 
155 
156 std::string
158  return getTagStr();
159 }
160 
161 
162 std::string
164  return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
165 }
166 
167 // ===========================================================================
168 // private
169 // ===========================================================================
170 
171 void
172 GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
173  switch (key) {
174  case SUMO_ATTR_ID:
175  changeAdditionalID(value);
176  break;
177  case SUMO_ATTR_BEGIN:
178  myBegin = parse<SUMOTime>(value);
179  break;
180  case SUMO_ATTR_END:
181  myEnd = parse<SUMOTime>(value);
182  break;
183  case GNE_ATTR_GENERIC:
185  break;
186  default:
187  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
188  }
189 }
190 
191 /****************************************************************************/
long long int SUMOTime
Definition: SUMOTime.h:35
std::string getParentName() const
Returns the name of the parent object.
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
SUMOTime myEnd
end timeStep
std::string generateChildID(SumoXMLTag childTag)
gererate a new ID for an element child
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
GNERerouterInterval(GNERerouterDialog *rerouterDialog)
constructor (Used in GNERerouterDialog)
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Stores the information about how to visualize structures.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
weights: time range begin
SUMOTime myBegin
begin timeStep
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void setDefaultValues()
change all attributes of additional with their default values (note: this cannot be undo) ...
const std::vector< GNEAdditional * > & getAdditionalChildren() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
Position getPositionInView() const
Returns position of additional in view.
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
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:48
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
void updateGeometry()
update pre-computed geometry information
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
const std::vector< GNEAdditional * > & getAdditionalParents() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
a Rerouter
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string getAttribute(SumoXMLAttr key) const
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:47
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
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
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(...)