Eclipse SUMO - Simulation of Urban MObility
GNERouteProbReroute.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/GNEUndoList.h>
24 #include <netedit/GNENet.h>
25 
26 #include "GNERouteProbReroute.h"
27 
28 // ===========================================================================
29 // member method definitions
30 // ===========================================================================
31 
34 {}, {}, {}, {}, {}, {}, {}, {},
35 std::map<std::string, std::string>()),
36 myProbability(0) {
37  // reset default values
39 }
40 
41 
42 GNERouteProbReroute::GNERouteProbReroute(GNEAdditional* rerouterIntervalParent, GNEDemandElement* route, double probability) :
43  GNEAdditional(rerouterIntervalParent->getNet(), GLO_REROUTER_ROUTEPROBREROUTE, SUMO_TAG_ROUTE_PROB_REROUTE, "",
44 {}, {}, {}, {rerouterIntervalParent}, {}, {}, {route}, {},
45 std::map<std::string, std::string>()),
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 
66  // GNERouteProbReroutes cannot be moved
67  return nullptr;
68 }
69 
70 
71 void
73  // update centering boundary (needed for centering)
75 }
76 
77 
78 void
83 }
84 
85 
88  // get rerouter parent position
89  Position signPosition = getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView();
90  // set position depending of indexes
91  signPosition.add(4.5 + 6.25, (getDrawPositionIndex() * -1) - getParentAdditionals().front()->getDrawPositionIndex() + 1, 0);
92  // return signPosition
93  return signPosition;
94 }
95 
96 
97 void
98 GNERouteProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
99  // geometry of this element cannot be splitted
100 }
101 
102 
103 std::string
105  return getParentAdditionals().at(0)->getID();
106 }
107 
108 
109 void
111  // draw route prob reroute as listed attribute
116 }
117 
118 
119 std::string
121  switch (key) {
122  case SUMO_ATTR_ID:
123  return getID();
124  case SUMO_ATTR_ROUTE:
125  return getParentDemandElements().front()->getID();
126  case SUMO_ATTR_PROB:
127  return toString(myProbability);
128  case GNE_ATTR_PARENT:
129  return getParentAdditionals().at(0)->getID();
130  case GNE_ATTR_SELECTED:
132  default:
133  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
134  }
135 }
136 
137 
138 double
140  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
141 }
142 
143 
144 void
145 GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
146  if (value == getAttribute(key)) {
147  return; //avoid needless changes, later logic relies on the fact that attributes have changed
148  }
149  switch (key) {
150  case SUMO_ATTR_ID:
151  case SUMO_ATTR_ROUTE:
152  case SUMO_ATTR_PROB:
153  case GNE_ATTR_SELECTED:
154  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
155  break;
156  default:
157  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
158  }
159 }
160 
161 
162 bool
163 GNERouteProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
164  switch (key) {
165  case SUMO_ATTR_ID:
166  return isValidAdditionalID(value);
167  case SUMO_ATTR_ROUTE:
168  return (myNet->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_ROUTE, value, false) != nullptr);
169  case SUMO_ATTR_PROB:
170  return canParse<double>(value);
171  case GNE_ATTR_SELECTED:
172  return canParse<bool>(value);
173  default:
174  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
175  }
176 }
177 
178 
179 bool
181  return true;
182 }
183 
184 
185 std::string
187  return getTagStr();
188 }
189 
190 
191 std::string
193  return getTagStr() + ": " + getParentDemandElements().front()->getID();
194 }
195 
196 // ===========================================================================
197 // private
198 // ===========================================================================
199 
200 void
201 GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
202  switch (key) {
203  case SUMO_ATTR_ID:
204  // update microsimID
205  setMicrosimID(value);
206  break;
207  case SUMO_ATTR_ROUTE:
209  break;
210  case SUMO_ATTR_PROB:
211  myProbability = parse<double>(value);
212  break;
213  case GNE_ATTR_SELECTED:
214  if (parse<bool>(value)) {
216  } else {
218  }
219  break;
220  default:
221  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
222  }
223 }
224 
225 
226 void
228  // nothing to do
229 }
230 
231 
232 void GNERouteProbReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
233  // nothing to do
234 }
235 
236 
237 /****************************************************************************/
@ GLO_REROUTER_ROUTEPROBREROUTE
a route probability reroute
@ REROUTER_ROUTEPROBREROUTE
@ SUMO_TAG_ROUTE_PROB_REROUTE
probability of route of a reroute
@ SUMO_TAG_ROUTE
begin/end of the description of a route
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_PARENT
parent of an additional element
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ROUTE
@ 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.
void replaceDemandElementParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace demand element parent
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
void resetDefaultValues()
reset attribute carrier to their default values
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
An Element which don't belongs to GNENet but has influency in the simulation.
const std::vector< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
move operation
move result
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
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
double myProbability
probability with which a vehicle will use the given edge as destination
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string getParentName() const
Returns the name of the parent object.
GNERouteProbReroute(GNENet *net)
default constructor
void updateGeometry()
update pre-computed geometry information
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
GNEMoveOperation * getMoveOperation()
get move operation
std::string getAttribute(SumoXMLAttr key) const
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
double getAttributeDouble(SumoXMLAttr key) const
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Position getPositionInView() const
Returns position of additional in view.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
bool isAttributeEnabled(SumoXMLAttr key) const
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
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