Eclipse 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-2019 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 
25 
26 #include "GNEParkingAreaReroute.h"
27 #include <netedit/GNEUndoList.h>
28 #include <netedit/GNEViewNet.h>
29 #include <netedit/GNENet.h>
30 
31 // ===========================================================================
32 // member method definitions
33 // ===========================================================================
34 
36  GNEAdditional(rerouterIntervalDialog->getEditedAdditional(), rerouterIntervalDialog->getEditedAdditional()->getViewNet(), GLO_REROUTER, SUMO_TAG_PARKING_ZONE_REROUTE, "", false,
37 {}, {}, {}, {rerouterIntervalDialog->getEditedAdditional(), rerouterIntervalDialog->getEditedAdditional()->getViewNet()->getNet()->getAttributeCarriers().additionals.at(SUMO_TAG_PARKING_AREA).begin()->second}, {}, {}, {}, {}, {}, {}) {
38  // fill route type with default values
40 }
41 
42 
43 GNEParkingAreaReroute::GNEParkingAreaReroute(GNEAdditional* rerouterIntervalParent, GNEAdditional* newParkingArea, double probability, bool visible):
44  GNEAdditional(rerouterIntervalParent, rerouterIntervalParent->getViewNet(), GLO_REROUTER, SUMO_TAG_PARKING_ZONE_REROUTE, "", false,
45 {}, {}, {}, {rerouterIntervalParent, newParkingArea}, {}, {}, {}, {}, {}, {}),
46 myProbability(probability),
47 myVisible(visible) {
48 }
49 
50 
52 
53 
54 void
56  // This additional cannot be moved
57 }
58 
59 
60 void
62  // This additional cannot be moved
63 }
64 
65 
66 void
68  // Currently this additional doesn't own a Geometry
69 }
70 
71 
74  return getAdditionalParents().at(0)->getPositionInView();
75 }
76 
77 
80  return getAdditionalParents().at(0)->getCenteringBoundary();
81 }
82 
83 
84 std::string
86  return getAdditionalParents().at(0)->getID();
87 }
88 
89 
90 void
92  // Currently this additional isn't drawn
93 }
94 
95 
96 std::string
98  switch (key) {
99  case SUMO_ATTR_ID:
100  return getAdditionalID();
101  case SUMO_ATTR_PARKING:
102  return getAdditionalParents().at(1)->getID();
103  case SUMO_ATTR_PROB:
104  return toString(myProbability);
105  case SUMO_ATTR_VISIBLE:
106  return toString(myVisible);
107  case GNE_ATTR_PARENT:
108  return toString(getAdditionalParents().at(0)->getID());
109  case GNE_ATTR_GENERIC:
110  return getGenericParametersStr();
111  default:
112  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
113  }
114 }
115 
116 
117 void
118 GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
119  if (value == getAttribute(key)) {
120  return; //avoid needless changes, later logic relies on the fact that attributes have changed
121  }
122  switch (key) {
123  case SUMO_ATTR_ID:
124  case SUMO_ATTR_PARKING:
125  case SUMO_ATTR_PROB:
126  case SUMO_ATTR_VISIBLE:
127  case GNE_ATTR_GENERIC:
128  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
129  break;
130  default:
131  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
132  }
133 }
134 
135 
136 bool
137 GNEParkingAreaReroute::isValid(SumoXMLAttr key, const std::string& value) {
138  switch (key) {
139  case SUMO_ATTR_ID:
140  return isValidAdditionalID(value);
141  case SUMO_ATTR_PARKING:
142  return isValidAdditionalID(value) && (myViewNet->getNet()->retrieveAdditional(SUMO_TAG_PARKING_AREA, value, false) != nullptr);
143  case SUMO_ATTR_PROB:
144  return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
145  case SUMO_ATTR_VISIBLE:
146  return canParse<bool>(value);
147  case GNE_ATTR_GENERIC:
148  return isGenericParametersValid(value);
149  default:
150  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
151  }
152 }
153 
154 
155 std::string
157  return getTagStr();
158 }
159 
160 
161 std::string
163  return getTagStr() + ": " + getAdditionalParents().at(1)->getID();
164 }
165 
166 // ===========================================================================
167 // private
168 // ===========================================================================
169 
170 void
171 GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
172  switch (key) {
173  case SUMO_ATTR_ID:
174  changeAdditionalID(value);
175  break;
176  case SUMO_ATTR_PARKING:
177  changeAdditionalParent(this, value, 1);
178  break;
179  case SUMO_ATTR_PROB:
180  myProbability = parse<double>(value);
181  break;
182  case SUMO_ATTR_VISIBLE:
183  myVisible = parse<bool>(value);
184  break;
185  case GNE_ATTR_GENERIC:
187  break;
188  default:
189  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
190  }
191 }
192 
193 /****************************************************************************/
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
Stores the information about how to visualize structures.
void changeAdditionalParent(GNEShape *shapeTobeChanged, const std::string &newAdditionalParentID, int additionalParentIndex)
change additional parent of a shape
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
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
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
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:2133
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:48
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
const std::vector< GNEAdditional * > & getAdditionalParents() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
a Rerouter
void updateGeometry()
update pre-computed geometry information
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
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const std::string & getTagStr() const
get tag assigned to this object in string format
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
Definition: GNEViewNet.cpp:927
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 ...
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList