SUMO - Simulation of Urban MObility
GNEDestProbReroute.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 "GNEDestProbReroute.h"
32 #include "GNEEdge.h"
33 #include "GNEUndoList.h"
34 #include "GNEChange_Attribute.h"
35 #include "GNERerouter.h"
36 #include "GNEViewNet.h"
37 #include "GNENet.h"
38 #include "GNERerouterInterval.h"
40 
41 // ===========================================================================
42 // member method definitions
43 // ===========================================================================
44 
47  myRerouterIntervalParent(rerouterIntervalDialog->getEditedRerouterInterval()),
48  myNewEdgeDestination(rerouterIntervalDialog->getEditedRerouterInterval()->getRerouterParent()->getEdgeChilds().at(0)),
49  myProbability(getDefaultValue<double>(SUMO_TAG_ROUTE_PROB_REROUTE, SUMO_ATTR_PROB)) {
50 }
51 
52 
53 GNEDestProbReroute::GNEDestProbReroute(GNERerouterInterval* rerouterIntervalParent, GNEEdge* newEdgeDestination, double probability):
55  myRerouterIntervalParent(rerouterIntervalParent),
56  myNewEdgeDestination(newEdgeDestination),
57  myProbability(probability) {
58 }
59 
60 
62 
63 
64 void
66  // open tag
67  device.openTag(getTag());
68  // write edge ID
70  // write probability
72  // close tag
73  device.closeTag();
74 }
75 
76 
80 }
81 
82 
83 std::string
85  switch (key) {
86  case SUMO_ATTR_ID:
87  return myNewEdgeDestination->getID();
88  case SUMO_ATTR_PROB:
89  return toString(myProbability);
90  default:
91  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
92  }
93 }
94 
95 
96 void
97 GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
98  if (value == getAttribute(key)) {
99  return; //avoid needless changes, later logic relies on the fact that attributes have changed
100  }
101  switch (key) {
102  case SUMO_ATTR_ID:
103  case SUMO_ATTR_PROB:
104  undoList->p_add(new GNEChange_Attribute(this, key, value));
105  break;
106  default:
107  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
108  }
109 }
110 
111 
112 bool
113 GNEDestProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
114  switch (key) {
115  case SUMO_ATTR_ID:
116  return (myRerouterIntervalParent->getRerouterParent()->getViewNet()->getNet()->retrieveEdge(value, false) != NULL);
117  case SUMO_ATTR_PROB:
118  return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
119  default:
120  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
121  }
122 }
123 
124 // ===========================================================================
125 // private
126 // ===========================================================================
127 
128 void
129 GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
130  switch (key) {
131  case SUMO_ATTR_ID: {
133  break;
134  }
135  case SUMO_ATTR_PROB: {
136  myProbability = parse<double>(value);
137  break;
138  }
139  default:
140  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
141  }
142 }
143 
144 /****************************************************************************/
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:902
GNERerouterInterval * getRerouterIntervalParent() const
get rerouter interval parent
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in all GNEAttributeCarriers.
Dialog for edit rerouter intervals.
double myProbability
probability with which a vehicle will use the given edge as destination
GNEDestProbReroute(GNERerouterIntervalDialog *rerouterIntervalDialog)
constructor (Used in GNERerouterIntervalDialog)
GNEEdge * myNewEdgeDestination
id of new edge destination
bool isValid(SumoXMLAttr key, const std::string &value)
GNERerouterInterval * myRerouterIntervalParent
reference to rerouter interval parent
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
friend class GNEChange_Attribute
declare friend class
void writeDestProbReroute(OutputDevice &device) const
GNERerouter * getRerouterParent() const
get rerouter parent
probability of route of a reroute
probability of destiny of a reroute
~GNEDestProbReroute()
destructor
const std::string getID() const
function to support debugging
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:56
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
GNENet * getNet() const
get the net object
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
SumoXMLTag getTag() const
get XML Tag assigned to this object