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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 //
19 /****************************************************************************/
20 #include <config.h>
21 
24 #include <netedit/GNEUndoList.h>
25 
26 #include "GNERerouterInterval.h"
27 
28 // ===========================================================================
29 // member method definitions
30 // ===========================================================================
31 
33  GNEAdditional(rerouterDialog->getEditedAdditional()->getNet(), GLO_REROUTER, SUMO_TAG_INTERVAL, "", false,
34 {}, {}, {}, {rerouterDialog->getEditedAdditional()}, {}, {}, {}, {}),
35 myBegin(0),
36 myEnd(0) {
37  // update centering boundary without updating grid
38  updateCenteringBoundary(false);
39  // fill reroute interval with default values
40  setDefaultValues();
41 }
42 
43 
45  GNEAdditional(rerouterParent->getNet(), GLO_REROUTER, SUMO_TAG_INTERVAL, "", false,
46 {}, {}, {}, {rerouterParent}, {}, {}, {}, {}),
47 myBegin(begin),
48 myEnd(end) {
49  // update centering boundary without updating grid
50  updateCenteringBoundary(false);
51 }
52 
53 
55 
56 
58 GNERerouterInterval::getMoveOperation(const double /*shapeOffset*/) {
59  // rerouter intervals cannot be moved
60  return nullptr;
61 }
62 
63 
64 void
66  // This additional doesn't own a geometry
67 }
68 
69 
70 void
72  // use boundary of parent element
73  myBoundary = getParentAdditionals().front()->getCenteringBoundary();
74 }
75 
76 
77 void
78 GNERerouterInterval::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
79  // geometry of this element cannot be splitted
80 }
81 
82 
83 std::string
85  return getParentAdditionals().at(0)->getID();
86 }
87 
88 
89 void
91  // Currently This additional isn't drawn
92 }
93 
94 
95 std::string
97  switch (key) {
98  case SUMO_ATTR_ID:
99  return getParentAdditionals().front()->getID();
100  case SUMO_ATTR_BEGIN:
101  return time2string(myBegin);
102  case SUMO_ATTR_END:
103  return time2string(myEnd);
104  case GNE_ATTR_PARENT:
105  return getParentAdditionals().at(0)->getID();
106  case GNE_ATTR_PARAMETERS:
107  return getParametersStr();
108  default:
109  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
110  }
111 }
112 
113 
114 double
116  switch (key) {
117  case SUMO_ATTR_BEGIN:
118  return STEPS2TIME(myBegin);
119  case SUMO_ATTR_END:
120  return STEPS2TIME(myEnd);
121  default:
122  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
123  }
124 }
125 
126 
127 void
128 GNERerouterInterval::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_BEGIN:
134  case SUMO_ATTR_END:
135  case GNE_ATTR_PARAMETERS:
136  undoList->p_add(new GNEChange_Attribute(this, key, value));
137  break;
138  default:
139  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
140  }
141 }
142 
143 
144 bool
145 GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {
146  switch (key) {
147  case SUMO_ATTR_BEGIN:
148  return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) < myEnd);
149  case SUMO_ATTR_END:
150  return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) > myBegin);
151  case GNE_ATTR_PARAMETERS:
152  return Parameterised::areParametersValid(value);
153  default:
154  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
155  }
156 }
157 
158 
159 bool
161  return true;
162 }
163 
164 
165 std::string
167  return getTagStr();
168 }
169 
170 
171 std::string
173  return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
174 }
175 
176 // ===========================================================================
177 // private
178 // ===========================================================================
179 
180 void
181 GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
182  switch (key) {
183  case SUMO_ATTR_BEGIN:
184  myBegin = parse<SUMOTime>(value);
185  break;
186  case SUMO_ATTR_END:
187  myEnd = parse<SUMOTime>(value);
188  break;
189  case GNE_ATTR_PARAMETERS:
190  setParametersStr(value);
191  break;
192  default:
193  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
194  }
195 }
196 
197 
199  // nothing to do
200 }
201 
202 
203 void GNERerouterInterval::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
204  // nothing to do
205 }
206 
207 
208 /****************************************************************************/
@ GLO_REROUTER
a Rerouter
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
long long int SUMOTime
Definition: SUMOTime.h:31
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_PARENT
parent of an additional element
@ SUMO_ATTR_BEGIN
weights: time range begin
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
Boundary myBoundary
Additional Boundary.
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
move operation
move result
Dialog for edit rerouters.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string getParentName() const
Returns the name of the parent object.
std::string getAttribute(SumoXMLAttr key) const
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
double getAttributeDouble(SumoXMLAttr key) const
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
SUMOTime myEnd
end timeStep
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
SUMOTime myBegin
begin timeStep
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void updateGeometry()
update pre-computed geometry information
bool isAttributeEnabled(SumoXMLAttr key) const
GNERerouterInterval(GNERerouterDialog *rerouterDialog)
constructor (Used in GNERerouterDialog)
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Stores the information about how to visualize structures.
static bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".