SUMO - Simulation of Urban MObility
GNEParkingAreaReroute.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-2018 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 
23 #include <utils/common/ToString.h>
26 
27 #include "GNEParkingArea.h"
28 #include "GNEParkingAreaReroute.h"
29 #include <netedit/GNEUndoList.h>
30 #include "GNERerouter.h"
31 #include <netedit/GNEViewNet.h>
32 #include <netedit/GNENet.h>
33 #include "GNERerouterInterval.h"
34 
35 // ===========================================================================
36 // member method definitions
37 // ===========================================================================
38 
40  GNEAdditional(rerouterIntervalDialog->getEditedAdditional(),
41  rerouterIntervalDialog->getEditedAdditional()->getViewNet()->getNet()->getAdditionalByType(SUMO_TAG_PARKING_AREA).begin()->second,
42  rerouterIntervalDialog->getEditedAdditional()->getViewNet(), GLO_REROUTER, SUMO_TAG_PARKING_ZONE_REROUTE, "", false) {
43  // fill route type with default values
45 }
46 
47 
48 GNEParkingAreaReroute::GNEParkingAreaReroute(GNEAdditional* rerouterIntervalParent, GNEAdditional* newParkingArea, double probability, bool visible):
49  GNEAdditional(rerouterIntervalParent, newParkingArea, rerouterIntervalParent->getViewNet(), GLO_REROUTER, SUMO_TAG_PARKING_ZONE_REROUTE, "", false),
50  myProbability(probability),
51  myVisible(visible) {
52 }
53 
54 
56 
57 
58 void
60  // This additional cannot be moved
61 }
62 
63 
64 void
66  // This additional cannot be moved
67 }
68 
69 
70 void
72  // Currently this additional doesn't own a Geometry
73 }
74 
75 
79 }
80 
81 
82 std::string
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_PARKING:
101  case SUMO_ATTR_PROB:
102  return toString(myProbability);
103  case SUMO_ATTR_VISIBLE:
104  return toString(myVisible);
105  case GNE_ATTR_PARENT:
107  case GNE_ATTR_GENERIC:
108  return getGenericParametersStr();
109  default:
110  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
111  }
112 }
113 
114 
115 void
116 GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
117  if (value == getAttribute(key)) {
118  return; //avoid needless changes, later logic relies on the fact that attributes have changed
119  }
120  switch (key) {
121  case SUMO_ATTR_ID:
122  case SUMO_ATTR_PARKING:
123  case SUMO_ATTR_PROB:
124  case SUMO_ATTR_VISIBLE:
125  case GNE_ATTR_GENERIC:
126  undoList->p_add(new GNEChange_Attribute(this, key, value));
127  break;
128  default:
129  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
130  }
131 }
132 
133 
134 bool
135 GNEParkingAreaReroute::isValid(SumoXMLAttr key, const std::string& value) {
136  switch (key) {
137  case SUMO_ATTR_ID:
138  return isValidAdditionalID(value);
139  case SUMO_ATTR_PARKING:
140  return isValidAdditionalID(value) && (myViewNet->getNet()->retrieveAdditional(SUMO_TAG_PARKING_AREA, value, false) != nullptr);
141  case SUMO_ATTR_PROB:
142  return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
143  case SUMO_ATTR_VISIBLE:
144  return canParse<bool>(value);
145  case GNE_ATTR_GENERIC:
146  return isGenericParametersValid(value);
147  default:
148  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
149  }
150 }
151 
152 
153 std::string
155  return toString(getTag());
156 }
157 
158 
159 std::string
161  return toString(getTag()) + ": " + getSecondAdditionalParent()->getID();
162 }
163 
164 // ===========================================================================
165 // private
166 // ===========================================================================
167 
168 void
169 GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
170  switch (key) {
171  case SUMO_ATTR_ID:
172  changeAdditionalID(value);
173  break;
174  case SUMO_ATTR_PARKING:
176  break;
177  case SUMO_ATTR_PROB:
178  myProbability = parse<double>(value);
179  break;
180  case SUMO_ATTR_VISIBLE:
181  myVisible = parse<bool>(value);
182  break;
183  case GNE_ATTR_GENERIC:
185  break;
186  default:
187  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
188  }
189 }
190 
191 /****************************************************************************/
std::string getAttribute(SumoXMLAttr key) const
Dialog for edit rerouter intervals.
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
Stores the information about how to visualize structures.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
void setDefaultValues()
change all attributes of additional with their default values (note: this cannot be undo) ...
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:1787
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Position getPositionInView() const
Returns position of additional in view.
double myProbability
probability with which a vehicle will use the given edge as destination
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
GNEAdditional * getSecondAdditionalParent() const
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
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
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
a Rerouter
bool myVisible
enable or disable visibility of Parking Area Reroute
const std::string getID() const
function to support debugging
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
GNEParkingAreaReroute(GNERerouterIntervalDialog *rerouterIntervalDialog)
constructor (Used in GNERerouterIntervalDialog)
entry for an alternative parking zone
void changeSecondAdditionalParent(const std::string &newAdditionalParentID)
change second additional parent of additional
void updateGeometry(bool updateGrid)
update pre-computed geometry information
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:53
std::string getGenericParametersStr() const
return generic parameters in string format
std::string getParentName() const
Returns the name of the parent object.
GNENet * getNet() const
get the net object
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
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 ...
GNEAdditional * myFirstAdditionalParent
pointer to first Addititional parent
GNEAdditional * mySecondAdditionalParent
pointer to second Addititional parent
SumoXMLTag getTag() const
get XML Tag assigned to this object
virtual Position getPositionInView() const =0
Returns position of additional in view.