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
25#include <netedit/GNEUndoList.h>
26#include <netedit/GNENet.h>
27
28// ===========================================================================
29// member method definitions
30// ===========================================================================
31
34 GUIIconSubSys::getIcon(GUIIcon::PARKINGZONEREROUTE), "", {}, {}, {}, {}, {}, {}),
35 myProbability(0),
36myVisible(0) {
37 // reset default values
38 resetDefaultValues();
39}
40
41
42GNEParkingAreaReroute::GNEParkingAreaReroute(GNEAdditional* rerouterIntervalParent, GNEAdditional* newParkingArea, double probability, bool visible):
43 GNEAdditional(rerouterIntervalParent->getNet(), GLO_REROUTER, SUMO_TAG_PARKING_AREA_REROUTE,
44 GUIIconSubSys::getIcon(GUIIcon::PARKINGZONEREROUTE), "", {}, {}, {}, {rerouterIntervalParent, newParkingArea}, {}, {}),
45myProbability(probability),
46myVisible(visible) {
47 // update boundary of rerouter parent
48 rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);
49}
50
51
53
54
55void
59 if (myProbability != 1.0) {
61 }
62 if (myVisible) {
63 device.writeAttr(SUMO_ATTR_VISIBLE, true);
64 }
65 device.closeTag();
66}
67
68
71 // GNEParkingAreaReroutes cannot be moved
72 return nullptr;
73}
74
75
76void
78 // update centering boundary (needed for centering)
80}
81
82
85 // get rerouter parent position
86 Position signPosition = getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView();
87 // set position depending of indexes
88 signPosition.add(4.5 + 6.25, (getDrawPositionIndex() * -1) - getParentAdditionals().front()->getDrawPositionIndex() + 1, 0);
89 // return signPosition
90 return signPosition;
91}
92
93
94void
99}
100
101
102void
103GNEParkingAreaReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
104 // geometry of this element cannot be splitted
105}
106
107
108std::string
110 return getParentAdditionals().at(0)->getID();
111}
112
113
114void
116 // draw route prob reroute as listed attribute
121}
122
123
124std::string
126 switch (key) {
127 case SUMO_ATTR_ID:
128 return getMicrosimID();
130 return getParentAdditionals().at(1)->getID();
131 case SUMO_ATTR_PROB:
132 return toString(myProbability);
134 return toString(myVisible);
135 case GNE_ATTR_PARENT:
136 return toString(getParentAdditionals().at(0)->getID());
139 default:
140 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
141 }
142}
143
144
145double
147 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
148}
149
150
153 return PARAMETERS_EMPTY;
154}
155
156
157void
158GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
159 if (value == getAttribute(key)) {
160 return; //avoid needless changes, later logic relies on the fact that attributes have changed
161 }
162 switch (key) {
163 case SUMO_ATTR_ID:
165 case SUMO_ATTR_PROB:
168 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
169 break;
170 default:
171 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
172 }
173}
174
175
176bool
177GNEParkingAreaReroute::isValid(SumoXMLAttr key, const std::string& value) {
178 switch (key) {
179 case SUMO_ATTR_ID:
180 return isValidAdditionalID(value);
182 return isValidAdditionalID(value) && (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_PARKING_AREA, value, false) != nullptr);
183 case SUMO_ATTR_PROB:
184 return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
186 return canParse<bool>(value);
188 return canParse<bool>(value);
189 default:
190 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
191 }
192}
193
194
195std::string
197 return getTagStr();
198}
199
200
201std::string
203 return getTagStr() + ": " + getParentAdditionals().at(1)->getID();
204}
205
206// ===========================================================================
207// private
208// ===========================================================================
209
210void
211GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
212 switch (key) {
213 case SUMO_ATTR_ID:
214 // update microsimID
215 setMicrosimID(value);
216 break;
219 break;
220 case SUMO_ATTR_PROB:
221 myProbability = parse<double>(value);
222 break;
224 myVisible = parse<bool>(value);
225 break;
227 if (parse<bool>(value)) {
229 } else {
231 }
232 break;
233 default:
234 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
235 }
236}
237
238
239void
241 // nothing to do
242}
243
244
245void
247 // nothing to do
248}
249
250
251/****************************************************************************/
@ GLO_REROUTER
a Rerouter
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ PARKINGZONEREROUTE
@ 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:78
void reset()
Resets the boundary.
Definition: Boundary.cpp:66
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:48
void replaceAdditionalParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace additional parent
void drawListedAddtional(const GUIVisualizationSettings &s, const Position &parentPosition, const double offsetX, const double 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
const std::string getID() const
get ID (all Attribute Carriers have one)
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
static const Parameterised::Map PARAMETERS_EMPTY
empty parameter maps (used by ACs without parameters)
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:132
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 correspondent attribute are valids
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void updateGeometry()
update pre-computed geometry information
const Parameterised::Map & getACParametersMap() const
get parameters map
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
write 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
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:141
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 & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
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