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-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 
32 #include "GNERerouterInterval.h"
33 #include "GNEEdge.h"
34 #include "GNELane.h"
35 #include "GNEClosingLaneReroute.h"
36 #include "GNEClosingReroute.h"
37 #include "GNEDestProbReroute.h"
38 #include "GNERouteProbReroute.h"
39 #include "GNERerouter.h"
40 #include "GNEUndoList.h"
41 #include "GNEChange_Attribute.h"
42 #include "GNEViewNet.h"
43 #include "GNENet.h"
44 #include "GNERerouterDialog.h"
45 
46 // ===========================================================================
47 // member method definitions
48 // ===========================================================================
49 
52  myRerouterParent(rerouterDialog->getEditedRerouter()),
53  myBegin(getDefaultValue<double>(SUMO_TAG_INTERVAL, SUMO_ATTR_BEGIN)),
54  myEnd(getDefaultValue<double>(SUMO_TAG_INTERVAL, SUMO_ATTR_END)) {
55 }
56 
57 
58 GNERerouterInterval::GNERerouterInterval(GNERerouter* rerouterParent, double begin, double end) :
60  myRerouterParent(rerouterParent),
61  myBegin(begin),
62  myEnd(end) {
63 }
64 
65 
67 
68 
69 void
71  // openTag
72  device.openTag(getTag());
73  // write begin
75  //write end
76  device.writeAttr(SUMO_ATTR_END, myEnd);
77  // write closing reroutes
78  for (auto i : myClosingReroutes) {
79  i->writeClosingReroute(device);
80  }
81  // write closing lane reroutes
82  for (auto i : myClosingLaneReroutes) {
83  i->writeClosingLaneReroute(device);
84  }
85  // write dest prob reroutes
86  for (auto i : myDestProbReroutes) {
87  i->writeDestProbReroute(device);
88  }
89  // write route prob reroutes
90  for (auto i : myRouteProbReroutes) {
91  i->writeRouteProbReroute(device);
92  }
93  // Close tag
94  device.closeTag();
95 }
96 
97 
100  return myRerouterParent;
101 }
102 
103 
104 double
106  return myBegin;
107 }
108 
109 
110 double
112  return myEnd;
113 }
114 
115 
116 std::string
118  switch (key) {
119  case SUMO_ATTR_ID:
120  return myRerouterParent->getID() + "_" + toString(myBegin) + "_" + toString(myEnd);
121  case SUMO_ATTR_BEGIN:
122  return toString(myBegin);
123  case SUMO_ATTR_END:
124  return toString(myEnd);
125  default:
126  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
127  }
128 }
129 
130 
131 void
132 GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
133  if (value == getAttribute(key)) {
134  return; //avoid needless changes, later logic relies on the fact that attributes have changed
135  }
136  switch (key) {
137  case SUMO_ATTR_BEGIN:
138  case SUMO_ATTR_END:
139  undoList->p_add(new GNEChange_Attribute(this, key, value));
140  break;
141  default:
142  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
143  }
144 }
145 
146 
147 bool
148 GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {
149  switch (key) {
150  case SUMO_ATTR_BEGIN:
151  return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) < myEnd);
152  case SUMO_ATTR_END:
153  return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) > myBegin);
154  default:
155  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
156  }
157 }
158 
159 
160 const std::vector<GNEClosingLaneReroute*>&
162  return myClosingLaneReroutes;
163 }
164 
165 
166 const std::vector<GNEClosingReroute*>&
168  return myClosingReroutes;
169 }
170 
171 
172 const std::vector<GNEDestProbReroute*>&
174  return myDestProbReroutes;
175 }
176 
177 
178 const std::vector<GNERouteProbReroute*>&
180  return myRouteProbReroutes;
181 }
182 
183 
184 void
186  auto it = std::find(myClosingLaneReroutes.begin(), myClosingLaneReroutes.end(), closingLaneReroute);
187  if (it == myClosingLaneReroutes.end()) {
188  myClosingLaneReroutes.push_back(closingLaneReroute);
189  } else {
190  throw ProcessError("Closing lane Reroute already exist");
191  }
192 }
193 
194 
195 void
197  auto it = std::find(myClosingLaneReroutes.begin(), myClosingLaneReroutes.end(), closingLaneReroute);
198  if (it != myClosingLaneReroutes.end()) {
199  myClosingLaneReroutes.erase(it);
200  } else {
201  throw ProcessError("Closing lane Reroute doesn't exist");
202  }
203 }
204 
205 
206 void
208  auto it = std::find(myClosingReroutes.begin(), myClosingReroutes.end(), closingReroute);
209  if (it == myClosingReroutes.end()) {
210  myClosingReroutes.push_back(closingReroute);
211  } else {
212  throw ProcessError("Closing Reroute already exist");
213  }
214 }
215 
216 
217 void
219  auto it = std::find(myClosingReroutes.begin(), myClosingReroutes.end(), closingReroute);
220  if (it != myClosingReroutes.end()) {
221  myClosingReroutes.erase(it);
222  } else {
223  throw ProcessError("Closing Reroute doesn't exist");
224  }
225 }
226 
227 
228 void
230  auto it = std::find(myDestProbReroutes.begin(), myDestProbReroutes.end(), destProbReroute);
231  if (it == myDestProbReroutes.end()) {
232  myDestProbReroutes.push_back(destProbReroute);
233  } else {
234  throw ProcessError("Destiny Probability Reroute already exist");
235  }
236 }
237 
238 
239 void
241  auto it = std::find(myDestProbReroutes.begin(), myDestProbReroutes.end(), destProbReroute);
242  if (it != myDestProbReroutes.end()) {
243  myDestProbReroutes.erase(it);
244  } else {
245  throw ProcessError("Destiny Probability Reroute doesn't exist");
246  }
247 }
248 
249 
250 void
252  auto it = std::find(myRouteProbReroutes.begin(), myRouteProbReroutes.end(), routeProbabilityReroute);
253  if (it == myRouteProbReroutes.end()) {
254  myRouteProbReroutes.push_back(routeProbabilityReroute);
255  } else {
256  throw ProcessError("Route Probability Reroute already exist");
257  }
258 }
259 
260 
261 void
263  auto it = std::find(myRouteProbReroutes.begin(), myRouteProbReroutes.end(), routeProbabilityReroute);
264  if (it != myRouteProbReroutes.end()) {
265  myRouteProbReroutes.erase(it);
266  } else {
267  throw ProcessError("Route Probability Reroute doesn't exist");
268  }
269 }
270 
271 // ===========================================================================
272 // private
273 // ===========================================================================
274 
275 void
276 GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
277  switch (key) {
278  case SUMO_ATTR_BEGIN: {
279  myBegin = parse<double>(value);
280  break;
281  }
282  case SUMO_ATTR_END: {
283  myEnd = parse<double>(value);
284  break;
285  }
286  default:
287  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
288  }
289 }
290 
291 /****************************************************************************/
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
const std::vector< GNEDestProbReroute * > & getDestProbReroutes() const
get destiny probability reroutes
const std::vector< GNEClosingLaneReroute * > & getClosingLaneReroutes() const
get closing reroutes
std::vector< GNEClosingReroute * > myClosingReroutes
vector with the closingReroutes
GNERerouterInterval(GNERerouterDialog *rerouterDialog)
constructor (Used in GNERerouterDialog)
void addDestProbReroute(GNEDestProbReroute *destProbReroute)
add destiny probability reroute
double getBegin() const
get begin
std::vector< GNEDestProbReroute * > myDestProbReroutes
vector with the destProbReroutes
weights: time range begin
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
const std::vector< GNERouteProbReroute * > & getRouteProbReroutes() const
get reoute probability reroutes
void removeDestProbReroute(GNEDestProbReroute *destProbReroute)
add destiny probability reroute
void addClosingReroute(GNEClosingReroute *closingReroute)
add closing reroute
void writeRerouterInterval(OutputDevice &device) const
write Interval and all of their values
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Dialog for edit rerouters.
void removeClosingReroute(GNEClosingReroute *closingReroute)
add closing reroute
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
friend class GNEChange_Attribute
declare friend class
double myBegin
begin timeStep
GNERerouter * getRerouterParent() const
get rerouter parent
void removeClosingLaneReroute(GNEClosingLaneReroute *closingLaneReroute)
add closing reroute
const std::string getID() const
function to support debugging
double myEnd
end timeStep
void addRouteProbReroute(GNERouteProbReroute *routeProbabilityReroute)
add reoute probability reroute
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in all GNEAttributeCarriers.
GNERerouter * myRerouterParent
pointer to rerouter parent
const std::vector< GNEClosingReroute * > & getClosingReroutes() const
get closing reroutes
weights: time range end
bool isValid(SumoXMLAttr key, const std::string &value)
an aggreagated-output interval
std::vector< GNEClosingLaneReroute * > myClosingLaneReroutes
vector with the closingLaneReroutes
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
double getEnd() const
get end
void addClosingLaneReroute(GNEClosingLaneReroute *closingLaneReroute)
add closing reroute
std::vector< GNERouteProbReroute * > myRouteProbReroutes
vector with the routeProbReroutes
~GNERerouterInterval()
destructor
void removeRouteProbReroute(GNERouteProbReroute *routeProbabilityReroute)
add reoute probability reroute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
SumoXMLTag getTag() const
get XML Tag assigned to this object