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
39  setDefaultValues();
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 /****************************************************************************/
GNENet::retrieveAdditional
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:2133
GNEParkingAreaReroute::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEParkingAreaReroute.cpp:79
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
GNEParkingAreaReroute.h
GNEAdditional::setGenericParametersStr
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
Definition: GNEAdditional.cpp:704
GNEAdditional::getAdditionalID
const std::string & getAdditionalID() const
Definition: GNEAdditional.cpp:578
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1187
GNEParkingAreaReroute::myProbability
double myProbability
probability with which a vehicle will use the given edge as destination
Definition: GNEParkingAreaReroute.h:122
GNEHierarchicalElementParents::changeAdditionalParent
void changeAdditionalParent(GNEShape *shapeTobeChanged, const std::string &newAdditionalParentID, int additionalParentIndex)
change additional parent of a shape
Definition: GNEHierarchicalElementParents.cpp:480
GNEAttributeCarrier::isGenericParametersValid
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
Definition: GNEAttributeCarrier.cpp:1354
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
GNEAdditional::changeAdditionalID
void changeAdditionalID(const std::string &newID)
change ID of additional
Definition: GNEAdditional.cpp:604
GNEParkingAreaReroute::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEParkingAreaReroute.cpp:162
GNEAdditional::myViewNet
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
Definition: GNEAdditional.h:365
GNEAttributeCarrier::GNEChange_Attribute
friend class GNEChange_Attribute
declare friend class
Definition: GNEAttributeCarrier.h:57
GNEUndoList::p_add
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Definition: GNEUndoList.cpp:132
GNEViewNet::getNet
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
SUMO_TAG_PARKING_ZONE_REROUTE
entry for an alternative parking zone
Definition: SUMOXMLDefinitions.h:199
SUMO_ATTR_PROB
Definition: SUMOXMLDefinitions.h:627
GNEParkingAreaReroute::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEParkingAreaReroute.cpp:156
GNEParkingAreaReroute::isValid
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEParkingAreaReroute.cpp:137
GNEViewNet.h
GNERerouterIntervalDialog.h
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
SUMO_TAG_PARKING_AREA
A parking area.
Definition: SUMOXMLDefinitions.h:108
GNEParkingAreaReroute::GNEParkingAreaReroute
GNEParkingAreaReroute(GNERerouterIntervalDialog *rerouterIntervalDialog)
constructor (Used in GNERerouterIntervalDialog)
Definition: GNEParkingAreaReroute.cpp:35
GNEParkingAreaReroute::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEParkingAreaReroute.cpp:91
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
GNEParkingAreaReroute::moveGeometry
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEParkingAreaReroute.cpp:55
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GNE_ATTR_GENERIC
generic attribute
Definition: SUMOXMLDefinitions.h:986
GNEParkingAreaReroute::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEParkingAreaReroute.cpp:73
GNEHierarchicalElementParents::getAdditionalParents
const std::vector< GNEAdditional * > & getAdditionalParents() const
return vector of additionals that have as Parent this edge (For example, Calibrators)
Definition: GNEHierarchicalElementParents.cpp:86
InvalidArgument
Definition: UtilExceptions.h:57
GNEAdditional::getGenericParametersStr
std::string getGenericParametersStr() const
return generic parameters in string format
Definition: GNEAdditional.cpp:678
GLO_REROUTER
a Rerouter
Definition: GUIGlObjectTypes.h:86
SUMO_ATTR_VISIBLE
Definition: SUMOXMLDefinitions.h:893
GNEParkingAreaReroute::setAttribute
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
Definition: GNEParkingAreaReroute.cpp:118
GNEParkingAreaReroute::commitGeometryMoving
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNEParkingAreaReroute.cpp:61
GNEParkingAreaReroute::getAttribute
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEParkingAreaReroute.cpp:97
SUMO_ATTR_PARKING
Definition: SUMOXMLDefinitions.h:798
config.h
GNEParkingAreaReroute::~GNEParkingAreaReroute
~GNEParkingAreaReroute()
destructor
Definition: GNEParkingAreaReroute.cpp:51
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1165
GNEUndoList
Definition: GNEUndoList.h:49
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:346
GNEParkingAreaReroute::updateGeometry
void updateGeometry()
update pre-computed geometry information
Definition: GNEParkingAreaReroute.cpp:67
GNEParkingAreaReroute::myVisible
bool myVisible
enable or disable visibility of Parking Area Reroute
Definition: GNEParkingAreaReroute.h:125
GNEAdditional::isValidAdditionalID
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Definition: GNEAdditional.cpp:584
GNEParkingAreaReroute::getParentName
std::string getParentName() const
Returns the name of the parent object.
Definition: GNEParkingAreaReroute.cpp:85
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:373
GNEChange_Attribute.h
GNENet.h
GNERerouterIntervalDialog
Dialog for edit rerouter intervals.
Definition: GNERerouterIntervalDialog.h:53
GNEUndoList.h
GNE_ATTR_PARENT
parent of an additional element
Definition: SUMOXMLDefinitions.h:984