SUMO - Simulation of Urban MObility
GNERouteProbReroute.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>
30 
31 #include "GNERouteProbReroute.h"
32 #include "GNEEdge.h"
33 #include "GNEChange_Attribute.h"
34 #include "GNEUndoList.h"
35 #include "GNERerouter.h"
37 #include "GNEViewNet.h"
38 #include "GNENet.h"
39 
40 // ===========================================================================
41 // member method definitions
42 // ===========================================================================
43 
46  myRerouterIntervalParent(rerouterIntervalDialog->getEditedRerouterInterval()),
47  myNewRouteId(rerouterIntervalDialog->getEditedRerouterInterval()->getRerouterParent()->getViewNet()->getNet()->generateCalibratorRouteID()),
48  myProbability(getDefaultValue<double>(SUMO_TAG_ROUTE_PROB_REROUTE, SUMO_ATTR_PROB)) {
49 }
50 
51 
52 GNERouteProbReroute::GNERouteProbReroute(GNERerouterInterval* rerouterIntervalParent, const std::string& newRouteId, double probability) :
54  myRerouterIntervalParent(rerouterIntervalParent),
55  myNewRouteId(newRouteId),
56  myProbability(probability) {
57 }
58 
59 
61 
62 
63 void
65  // open Tag
66  device.openTag(getTag());
67  // write Route ID
69  // write Probability
71  // close tag
72  device.closeTag();
73 }
74 
75 
79 }
80 
81 
82 std::string
84  switch (key) {
85  case SUMO_ATTR_ID:
86  return myNewRouteId;
87  case SUMO_ATTR_PROB:
88  return toString(myProbability);
89  default:
90  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
91  }
92 }
93 
94 
95 void
96 GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
97  if (value == getAttribute(key)) {
98  return; //avoid needless changes, later logic relies on the fact that attributes have changed
99  }
100  switch (key) {
101  case SUMO_ATTR_ID:
102  case SUMO_ATTR_PROB:
103  undoList->p_add(new GNEChange_Attribute(this, key, value));
104  break;
105  default:
106  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
107  }
108 }
109 
110 
111 bool
112 GNERouteProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
113  switch (key) {
114  case SUMO_ATTR_ID:
115  return isValidID(value);
116  case SUMO_ATTR_PROB:
117  return canParse<double>(value);
118  default:
119  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
120  }
121 }
122 
123 // ===========================================================================
124 // private
125 // ===========================================================================
126 
127 void
128 GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
129  switch (key) {
130  case SUMO_ATTR_ID: {
131  myNewRouteId = value;
132  break;
133  }
134  case SUMO_ATTR_PROB: {
135  myProbability = parse<double>(value);
136  break;
137  }
138  default:
139  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
140  }
141 }
142 
143 /****************************************************************************/
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
Dialog for edit rerouter intervals.
std::string myNewRouteId
id of new route
void writeRouteProbReroute(OutputDevice &device) const
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
double myProbability
probability with which a vehicle will use the given edge as destination
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
static bool isValidID(const std::string &value)
true if value is a valid sumo ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
GNERerouterInterval * getRerouterIntervalParent() const
get rerouter interval parent
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in all GNEAttributeCarriers.
~GNERouteProbReroute()
destructor
friend class GNEChange_Attribute
declare friend class
GNERerouterInterval * myRerouterIntervalParent
reference to rerouter interval parent
probability of route of a reroute
GNERouteProbReroute(GNERerouterIntervalDialog *rerouterIntervalDialog)
constructor (Used in GNERerouterIntervalDialog)
bool isValid(SumoXMLAttr key, const std::string &value)
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)
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
SumoXMLTag getTag() const
get XML Tag assigned to this object