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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 //
19 /****************************************************************************/
20 #include <config.h>
21 
23 
24 #include "GNEParkingAreaReroute.h"
25 #include <netedit/GNEUndoList.h>
26 #include <netedit/GNENet.h>
27 
28 // ===========================================================================
29 // member method definitions
30 // ===========================================================================
31 
34 {}, {}, {}, {}, {}, {}, {}, {},
35 std::map<std::string, std::string>()),
36  myProbability(0),
37 myVisible(0) {
38  // reset default values
39  resetDefaultValues();
40 }
41 
42 
43 GNEParkingAreaReroute::GNEParkingAreaReroute(GNEAdditional* rerouterIntervalParent, GNEAdditional* newParkingArea, double probability, bool visible):
44  GNEAdditional(rerouterIntervalParent->getNet(), GLO_REROUTER, SUMO_TAG_PARKING_AREA_REROUTE, "",
45 {}, {}, {}, {rerouterIntervalParent, newParkingArea}, {}, {}, {}, {},
46 std::map<std::string, std::string>()),
47 myProbability(probability),
48 myVisible(visible) {
49  // update boundary of rerouter parent
50  rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);
51 }
52 
53 
55 
56 
57 void
61  if (myProbability != 1.0) {
63  }
64  if (myVisible) {
65  device.writeAttr(SUMO_ATTR_VISIBLE, true);
66  }
67  device.closeTag();
68 }
69 
70 
73  // GNEParkingAreaReroutes cannot be moved
74  return nullptr;
75 }
76 
77 
78 void
80  // update centering boundary (needed for centering)
82 }
83 
84 
87  // get rerouter parent position
88  Position signPosition = getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView();
89  // set position depending of indexes
90  signPosition.add(4.5 + 6.25, (getDrawPositionIndex() * -1) - getParentAdditionals().front()->getDrawPositionIndex() + 1, 0);
91  // return signPosition
92  return signPosition;
93 }
94 
95 
96 void
101 }
102 
103 
104 void
105 GNEParkingAreaReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
106  // geometry of this element cannot be splitted
107 }
108 
109 
110 std::string
112  return getParentAdditionals().at(0)->getID();
113 }
114 
115 
116 void
118  // draw route prob reroute as listed attribute
123 }
124 
125 
126 std::string
128  switch (key) {
129  case SUMO_ATTR_ID:
130  return getID();
131  case SUMO_ATTR_PARKING:
132  return getParentAdditionals().at(1)->getID();
133  case SUMO_ATTR_PROB:
134  return toString(myProbability);
135  case SUMO_ATTR_VISIBLE:
136  return toString(myVisible);
137  case GNE_ATTR_PARENT:
138  return toString(getParentAdditionals().at(0)->getID());
139  case GNE_ATTR_SELECTED:
141  default:
142  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
143  }
144 }
145 
146 
147 double
149  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
150 }
151 
152 
153 void
154 GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
155  if (value == getAttribute(key)) {
156  return; //avoid needless changes, later logic relies on the fact that attributes have changed
157  }
158  switch (key) {
159  case SUMO_ATTR_ID:
160  case SUMO_ATTR_PARKING:
161  case SUMO_ATTR_PROB:
162  case SUMO_ATTR_VISIBLE:
163  case GNE_ATTR_SELECTED:
164  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
165  break;
166  default:
167  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
168  }
169 }
170 
171 
172 bool
173 GNEParkingAreaReroute::isValid(SumoXMLAttr key, const std::string& value) {
174  switch (key) {
175  case SUMO_ATTR_ID:
176  return isValidAdditionalID(value);
177  case SUMO_ATTR_PARKING:
178  return isValidAdditionalID(value) && (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_PARKING_AREA, value, false) != nullptr);
179  case SUMO_ATTR_PROB:
180  return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
181  case SUMO_ATTR_VISIBLE:
182  return canParse<bool>(value);
183  case GNE_ATTR_SELECTED:
184  return canParse<bool>(value);
185  default:
186  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
187  }
188 }
189 
190 
191 bool
193  return true;
194 }
195 
196 
197 std::string
199  return getTagStr();
200 }
201 
202 
203 std::string
205  return getTagStr() + ": " + getParentAdditionals().at(1)->getID();
206 }
207 
208 // ===========================================================================
209 // private
210 // ===========================================================================
211 
212 void
213 GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
214  switch (key) {
215  case SUMO_ATTR_ID:
216  // update microsimID
217  setMicrosimID(value);
218  break;
219  case SUMO_ATTR_PARKING:
221  break;
222  case SUMO_ATTR_PROB:
223  myProbability = parse<double>(value);
224  break;
225  case SUMO_ATTR_VISIBLE:
226  myVisible = parse<bool>(value);
227  break;
228  case GNE_ATTR_SELECTED:
229  if (parse<bool>(value)) {
231  } else {
233  }
234  break;
235  default:
236  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
237  }
238 }
239 
240 
241 void
243  // nothing to do
244 }
245 
246 
247 void
248 GNEParkingAreaReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
249  // nothing to do
250 }
251 
252 
253 /****************************************************************************/
@ GLO_REROUTER
a Rerouter
@ REROUTER_PARKINGAREAREROUTE
@ SUMO_TAG_PARKING_AREA_REROUTE
entry for an alternative parking zone
@ SUMO_TAG_PARKING_AREA
A parking area.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_PARKING
@ GNE_ATTR_PARENT
parent of an additional element
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ID
@ SUMO_ATTR_VISIBLE
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:77
void reset()
Resets the boundary.
Definition: Boundary.cpp:65
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
const std::string & getID() const
get ID
void replaceAdditionalParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace additional parent
void drawListedAddtional(const GUIVisualizationSettings &s, const Position &parentPosition, const int offsetX, const int extraOffsetY, const RGBColor baseCol, const RGBColor textCol, GUITexture texture, const std::string text) const
draw listed additional
int getDrawPositionIndex() const
get draw position index (used in rerouters and VSS)
Boundary myAdditionalBoundary
Additional Boundary.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
move operation
move result
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:125
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
double myProbability
probability with which a vehicle will use the given edge as destination
GNEParkingAreaReroute(GNENet *net)
constructor
bool myVisible
enable or disable visibility of Parking Area Reroute
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Position getPositionInView() const
Returns position of additional in view.
double getAttributeDouble(SumoXMLAttr key) const
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void updateGeometry()
update pre-computed geometry information
std::string getParentName() const
Returns the name of the parent object.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string getAttribute(SumoXMLAttr key) const
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
GNEMoveOperation * getMoveOperation()
get move operation
bool isAttributeEnabled(SumoXMLAttr key) const
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
Stores the information about how to visualize structures.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:125
static const RGBColor YELLOW
Definition: RGBColor.h:188
static const RGBColor RED
named colors
Definition: RGBColor.h:185