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.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 #include <netedit/GNENet.h>
24 #include <netedit/GNEUndoList.h>
25 
26 #include "GNEDestProbReroute.h"
27 
28 // ===========================================================================
29 // member method definitions
30 // ===========================================================================
31 
34 {}, {}, {}, {}, {}, {}, {}, {},
35 std::map<std::string, std::string>()),
36  myNewEdgeDestination(nullptr),
37 myProbability(0) {
38  // reset default values
39  resetDefaultValues();
40 }
41 
42 
43 GNEDestProbReroute::GNEDestProbReroute(GNEAdditional* rerouterIntervalParent, GNEEdge* newEdgeDestination, double probability):
44  GNEAdditional(rerouterIntervalParent->getNet(), GLO_REROUTER_DESTPROBREROUTE, SUMO_TAG_DEST_PROB_REROUTE, "",
45 {}, {}, {}, {rerouterIntervalParent}, {}, {}, {}, {},
46 std::map<std::string, std::string>()),
47 myNewEdgeDestination(newEdgeDestination),
48 myProbability(probability) {
49  // update boundary of rerouter parent
50  rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);
51 }
52 
53 
55 
56 
57 void
62  device.closeTag();
63 }
64 
65 
68  // GNEDestProbReroutes cannot be moved
69  return nullptr;
70 }
71 
72 
73 void
75  // update centering boundary (needed for centering)
77 }
78 
79 
82  // get rerouter parent position
83  Position signPosition = getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView();
84  // set position depending of indexes
85  signPosition.add(4.5 + 6.25, (getDrawPositionIndex() * -1) - getParentAdditionals().front()->getDrawPositionIndex() + 1, 0);
86  // return signPosition
87  return signPosition;
88 }
89 
90 
91 void
92 GNEDestProbReroute::updateCenteringBoundary(const bool /*updateGrid*/) {
96 }
97 
98 
99 void
100 GNEDestProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
101  // geometry of this element cannot be splitted
102 }
103 
104 
105 std::string
107  return getParentAdditionals().at(0)->getID();
108 }
109 
110 
111 void
113  // draw dest prob reroute as listed attribute
118 }
119 
120 
121 std::string
123  switch (key) {
124  case SUMO_ATTR_ID:
125  return getID();
126  case SUMO_ATTR_EDGE:
127  return myNewEdgeDestination->getID();
128  case SUMO_ATTR_PROB:
129  return toString(myProbability);
130  case GNE_ATTR_PARENT:
131  return getParentAdditionals().at(0)->getID();
132  case GNE_ATTR_SELECTED:
134  default:
135  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
136  }
137 }
138 
139 
140 double
142  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
143 }
144 
145 
146 void
147 GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
148  if (value == getAttribute(key)) {
149  return; //avoid needless changes, later logic relies on the fact that attributes have changed
150  }
151  switch (key) {
152  case SUMO_ATTR_ID:
153  case SUMO_ATTR_EDGE:
154  case SUMO_ATTR_PROB:
155  case GNE_ATTR_SELECTED:
156  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
157  break;
158  default:
159  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
160  }
161 }
162 
163 
164 bool
165 GNEDestProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
166  switch (key) {
167  case SUMO_ATTR_ID:
168  return isValidAdditionalID(value);
169  case SUMO_ATTR_EDGE:
170  return (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr);
171  case SUMO_ATTR_PROB:
172  return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;
173  case GNE_ATTR_SELECTED:
174  return canParse<bool>(value);
175  default:
176  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
177  }
178 }
179 
180 
181 bool
183  return true;
184 }
185 
186 
187 std::string
189  return getTagStr();
190 }
191 
192 
193 std::string
195  return getTagStr() + ": " + myNewEdgeDestination->getID();
196 }
197 
198 // ===========================================================================
199 // private
200 // ===========================================================================
201 
202 void
203 GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
204  switch (key) {
205  case SUMO_ATTR_ID:
206  // update microsimID
207  setMicrosimID(value);
208  break;
209  case SUMO_ATTR_EDGE:
211  break;
212  case SUMO_ATTR_PROB:
213  myProbability = parse<double>(value);
214  break;
215  case GNE_ATTR_SELECTED:
216  if (parse<bool>(value)) {
218  } else {
220  }
221  break;
222  default:
223  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
224  }
225 }
226 
227 
228 void
230  // nothing to do
231 }
232 
233 
234 void
235 GNEDestProbReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
236  // nothing to do
237 }
238 
239 
240 /****************************************************************************/
@ GLO_REROUTER_DESTPROBREROUTE
a destiny probability reroute
@ REROUTER_DESTPROBREROUTE
@ SUMO_TAG_DEST_PROB_REROUTE
probability of destiny 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
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 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
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
writte 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
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
bool isAttributeEnabled(SumoXMLAttr key) const
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 conrrespond 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
~GNEDestProbReroute()
destructor
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:125
const std::string & getID() const
get ID
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