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.dev/sumo
3 // Copyright (C) 2001-2024 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  GUIIconSubSys::getIcon(GUIIcon::PARKINGZONEREROUTE), "", {}, {}, {}, {}, {}, {}),
35  myProbability(0),
36 myVisible(0) {
37  // reset default values
38  resetDefaultValues();
39 }
40 
41 
42 GNEParkingAreaReroute::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}, {}, {}),
45 myProbability(probability),
46 myVisible(visible) {
47  // update boundary of rerouter parent
48  rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);
49 }
50 
51 
53 
54 
55 void
59  if (myProbability != 1.0) {
61  }
62  if (myVisible) {
63  device.writeAttr(SUMO_ATTR_VISIBLE, true);
64  }
65  device.closeTag();
66 }
67 
68 
69 bool
71  return true;
72 }
73 
74 
75 std::string
77  return "";
78 }
79 
80 
81 void
83  // nothing to fix
84 }
85 
86 
87 bool
89  return false;
90 }
91 
92 
95  // GNEParkingAreaReroutes cannot be moved
96  return nullptr;
97 }
98 
99 
100 void
102  // update centering boundary (needed for centering)
104 }
105 
106 
107 Position
109  // get rerouter parent position
110  Position signPosition = getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView();
111  // set position depending of indexes
112  signPosition.add(4.5 + 6.25, (getDrawPositionIndex() * -1) - getParentAdditionals().front()->getDrawPositionIndex() + 1, 0);
113  // return signPosition
114  return signPosition;
115 }
116 
117 
118 void
120  // nothing to update
121 }
122 
123 
124 void
125 GNEParkingAreaReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
126  // geometry of this element cannot be splitted
127 }
128 
129 
130 std::string
132  return getParentAdditionals().at(0)->getID();
133 }
134 
135 
136 void
138  // draw route prob reroute as listed attribute
143 }
144 
145 
146 std::string
148  switch (key) {
149  case SUMO_ATTR_ID:
150  return getMicrosimID();
151  case SUMO_ATTR_PARKING:
152  return getParentAdditionals().at(1)->getID();
153  case SUMO_ATTR_PROB:
154  return toString(myProbability);
155  case SUMO_ATTR_VISIBLE:
156  return toString(myVisible);
157  case GNE_ATTR_PARENT:
158  return toString(getParentAdditionals().at(0)->getID());
159  case GNE_ATTR_SELECTED:
161  default:
162  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
163  }
164 }
165 
166 
167 double
169  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
170 }
171 
172 
173 const Parameterised::Map&
175  return PARAMETERS_EMPTY;
176 }
177 
178 
179 void
180 GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
181  if (value == getAttribute(key)) {
182  return; //avoid needless changes, later logic relies on the fact that attributes have changed
183  }
184  switch (key) {
185  case SUMO_ATTR_ID:
186  case SUMO_ATTR_PARKING:
187  case SUMO_ATTR_PROB:
188  case SUMO_ATTR_VISIBLE:
189  case GNE_ATTR_SELECTED:
190  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
191  break;
192  default:
193  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
194  }
195 }
196 
197 
198 bool
199 GNEParkingAreaReroute::isValid(SumoXMLAttr key, const std::string& value) {
200  switch (key) {
201  case SUMO_ATTR_ID:
202  return isValidAdditionalID(value);
203  case SUMO_ATTR_PARKING:
204  return (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_PARKING_AREA, value, false) != nullptr);
205  case SUMO_ATTR_PROB:
206  return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
207  case SUMO_ATTR_VISIBLE:
208  return canParse<bool>(value);
209  case GNE_ATTR_SELECTED:
210  return canParse<bool>(value);
211  default:
212  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
213  }
214 }
215 
216 
217 std::string
219  return getTagStr();
220 }
221 
222 
223 std::string
225  return getTagStr() + ": " + getParentAdditionals().at(1)->getID();
226 }
227 
228 // ===========================================================================
229 // private
230 // ===========================================================================
231 
232 void
233 GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
234  switch (key) {
235  case SUMO_ATTR_ID:
236  // update microsimID
237  setAdditionalID(value);
238  break;
239  case SUMO_ATTR_PARKING:
241  break;
242  case SUMO_ATTR_PROB:
243  myProbability = parse<double>(value);
244  break;
245  case SUMO_ATTR_VISIBLE:
246  myVisible = parse<bool>(value);
247  break;
248  case GNE_ATTR_SELECTED:
249  if (parse<bool>(value)) {
251  } else {
253  }
254  break;
255  default:
256  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
257  }
258 }
259 
260 
261 void
263  // nothing to do
264 }
265 
266 
267 void
268 GNEParkingAreaReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
269  // nothing to do
270 }
271 
272 
273 /****************************************************************************/
@ 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
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:49
bool isValidAdditionalID(const std::string &value) const
check if a new additional ID is valid
void replaceAdditionalParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace additional parent
void drawListedAdditional(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
void setAdditionalID(const std::string &newID)
set additional ID
int getDrawPositionIndex() const
get draw position index (used in rerouters and VSS)
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
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
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
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:121
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
bool isAdditionalValid() const
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
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
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
bool checkDrawMoveContour() const
check if draw move contour (red)
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void updateGeometry()
update pre-computed geometry information
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
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
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:143
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:254
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:132
static const RGBColor YELLOW
Definition: RGBColor.h:188
static const RGBColor RED
named colors
Definition: RGBColor.h:185