Eclipse SUMO - Simulation of Urban MObility
GNEDestProbReroute.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 #include <netedit/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 
26 #include "GNEDestProbReroute.h"
27 
28 // ===========================================================================
29 // member method definitions
30 // ===========================================================================
31 
34  GUIIconSubSys::getIcon(GUIIcon::DESTPROBREROUTE), "", {}, {}, {}, {}, {}, {}),
35  myNewEdgeDestination(nullptr),
36 myProbability(0) {
37  // reset default values
38  resetDefaultValues();
39 }
40 
41 
42 GNEDestProbReroute::GNEDestProbReroute(GNEAdditional* rerouterIntervalParent, GNEEdge* newEdgeDestination, double probability):
44  GUIIconSubSys::getIcon(GUIIcon::DESTPROBREROUTE), "", {}, {}, {}, {rerouterIntervalParent}, {}, {}),
45 myNewEdgeDestination(newEdgeDestination),
46 myProbability(probability) {
47  // update boundary of rerouter parent
48  rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);
49 }
50 
51 
53 
54 
55 void
60  device.closeTag();
61 }
62 
63 
64 bool
66  return true;
67 }
68 
69 
70 std::string
72  return "";
73 }
74 
75 
76 void
78  // nothing to fix
79 }
80 
81 
82 bool
84  return false;
85 }
86 
87 
90  // GNEDestProbReroutes cannot be moved
91  return nullptr;
92 }
93 
94 
95 void
97  // update centering boundary (needed for centering)
99 }
100 
101 
102 Position
104  // get rerouter parent position
105  Position signPosition = getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView();
106  // set position depending of indexes
107  signPosition.add(4.5 + 6.25, (getDrawPositionIndex() * -1) - getParentAdditionals().front()->getDrawPositionIndex() + 1, 0);
108  // return signPosition
109  return signPosition;
110 }
111 
112 
113 void
115  // nothing to update
116 }
117 
118 
119 void
120 GNEDestProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
121  // geometry of this element cannot be splitted
122 }
123 
124 
125 std::string
127  return getParentAdditionals().at(0)->getID();
128 }
129 
130 
131 void
133  // draw dest prob reroute as listed attribute
138 }
139 
140 
141 std::string
143  switch (key) {
144  case SUMO_ATTR_ID:
145  return getMicrosimID();
146  case SUMO_ATTR_EDGE:
147  return myNewEdgeDestination->getID();
148  case SUMO_ATTR_PROB:
149  return toString(myProbability);
150  case GNE_ATTR_PARENT:
151  return getParentAdditionals().at(0)->getID();
152  case GNE_ATTR_SELECTED:
154  default:
155  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
156  }
157 }
158 
159 
160 double
162  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
163 }
164 
165 
166 const Parameterised::Map&
168  return PARAMETERS_EMPTY;
169 }
170 
171 
172 void
173 GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
174  if (value == getAttribute(key)) {
175  return; //avoid needless changes, later logic relies on the fact that attributes have changed
176  }
177  switch (key) {
178  case SUMO_ATTR_ID:
179  case SUMO_ATTR_EDGE:
180  case SUMO_ATTR_PROB:
181  case GNE_ATTR_SELECTED:
182  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
183  break;
184  default:
185  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
186  }
187 }
188 
189 
190 bool
191 GNEDestProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
192  switch (key) {
193  case SUMO_ATTR_ID:
194  return isValidAdditionalID(value);
195  case SUMO_ATTR_EDGE:
196  return (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr);
197  case SUMO_ATTR_PROB:
198  return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
199  case GNE_ATTR_SELECTED:
200  return canParse<bool>(value);
201  default:
202  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
203  }
204 }
205 
206 
207 std::string
209  return getTagStr();
210 }
211 
212 
213 std::string
215  return getTagStr() + ": " + myNewEdgeDestination->getID();
216 }
217 
218 // ===========================================================================
219 // private
220 // ===========================================================================
221 
222 void
223 GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
224  switch (key) {
225  case SUMO_ATTR_ID:
226  // update microsimID
227  setAdditionalID(value);
228  break;
229  case SUMO_ATTR_EDGE:
231  break;
232  case SUMO_ATTR_PROB:
233  myProbability = parse<double>(value);
234  break;
235  case GNE_ATTR_SELECTED:
236  if (parse<bool>(value)) {
238  } else {
240  }
241  break;
242  default:
243  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
244  }
245 }
246 
247 
248 void
250  // nothing to do
251 }
252 
253 
254 void
255 GNEDestProbReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
256  // nothing to do
257 }
258 
259 
260 /****************************************************************************/
@ GLO_REROUTER_DESTPROBREROUTE
a destination probability reroute
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ DESTPROBREROUTE
@ REROUTER_DESTPROBREROUTE
@ SUMO_TAG_DEST_PROB_REROUTE
probability of destination of a reroute
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_EDGE
@ GNE_ATTR_PARENT
parent of an additional element
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ID
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 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
std::string getAttribute(SumoXMLAttr key) const
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
double getAttributeDouble(SumoXMLAttr key) const
GNEMoveOperation * getMoveOperation()
get move operation
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
std::string getAdditionalProblem() const
return a string with the current additional problem (must be reimplemented in all detector children)
void fixAdditionalProblem()
fix additional problem (must be reimplemented in all detector children)
const Parameterised::Map & getACParametersMap() const
get parameters map
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
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Position getPositionInView() const
Returns position of additional in view.
GNEDestProbReroute(GNENet *net)
constructor
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their correspondent attribute are valids
std::string getParentName() const
Returns the name of the parent object.
GNEEdge * myNewEdgeDestination
id of new edge destination
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
bool checkDrawMoveContour() const
check if draw move contour (red)
~GNEDestProbReroute()
destructor
bool isAdditionalValid() const
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
void updateGeometry()
update pre-computed geometry information
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
move operation
move result
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
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
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