Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GNERouteRef.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-2025 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// A class for route references
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
26
27#include "GNERouteRef.h"
28#include "GNEVehicle.h"
29
30// ===========================================================================
31// GNERouteRef - methods
32// ===========================================================================
33
37
38
39GNERouteRef::GNERouteRef(GNEDemandElement* distributionParent, GNEDemandElement* routeParent, const double probability) :
40 GNEDemandElement(distributionParent, GNE_TAG_ROUTEREF, GNEPathElement::Options::DEMAND_ELEMENT),
41 myProbability(probability) {
42 // set parents
43 setParents<GNEDemandElement*>({distributionParent, routeParent});
44}
45
46
48
49
52 return nullptr;
53}
54
55
58 // create popup
59 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
60 // build common options
62 return ret;
63}
64
65
66void
68 device.openTag(SUMO_TAG_ROUTE);
71 // write parameters
72 writeParams(device);
73 // close tag
74 device.closeTag();
75}
76
77
82
83
84std::string
86 return "";
87}
88
89
90void
92 // currently the only solution is removing Route
93}
94
95
98 return getParentDemandElements().back()->getVClass();
99}
100
101
102const RGBColor&
104 return getParentDemandElements().back()->getColor();
105}
106
107
108void
110 // nothing to update
111}
112
113
116 return getParentDemandElements().front()->getPositionInView();
117}
118
119
120std::string
122 return getParentDemandElements().front()->getID();
123}
124
125
126double
128 return 1;
129}
130
131
134 return getParentDemandElements().front()->getCenteringBoundary();
135}
136
137
138void
139GNERouteRef::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/,
140 const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
141 // nothing to do
142}
143
144
145void
147 // nothing to draw
148}
149
150
151void
153 // nothing to do
154}
155
156
157void
158GNERouteRef::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
159 // nothing to draw
160}
161
162
163void
164GNERouteRef::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
165 // nothing to draw
166}
167
168
169GNELane*
171 return getParentDemandElements().back()->getFirstPathLane();
172}
173
174
175GNELane*
177 return getParentDemandElements().back()->getLastPathLane();
178}
179
180
181std::string
183 switch (key) {
184 case SUMO_ATTR_ID:
185 return getMicrosimID();
187 return getParentDemandElements().front()->getID();
188 case SUMO_ATTR_REFID:
189 return getParentDemandElements().back()->getID();
190 case SUMO_ATTR_PROB:
191 return toString(myProbability);
192 default:
193 return getCommonAttribute(this, key);
194 }
195}
196
197
198double
200 switch (key) {
201 case SUMO_ATTR_PROB:
202 return myProbability;
203 default:
204 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
205 }
206}
207
208
211 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
212}
213
214
215bool
217 switch (key) {
219 case SUMO_ATTR_REFID:
220 return false;
221 default:
222 return true;
223 }
224}
225
226
227void
228GNERouteRef::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
229 if (value == getAttribute(key)) {
230 return; //avoid needless changes, later logic relies on the fact that attributes have changed
231 }
232 switch (key) {
233 case SUMO_ATTR_PROB:
234 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
235 break;
236 default:
237 setCommonAttribute(key, value, undoList);
238 break;
239 }
240}
241
242
243bool
244GNERouteRef::isValid(SumoXMLAttr key, const std::string& value) {
245 switch (key) {
246 case SUMO_ATTR_PROB:
247 if (value.empty()) {
248 return true;
249 } else {
250 return canParse<double>(value) && (parse<double>(value) >= 0);
251 }
252 default:
253 return isCommonValid(key, value);
254 }
255}
256
257
258std::string
260 return getTagStr();
261}
262
263
264std::string
268
269
274
275// ===========================================================================
276// private
277// ===========================================================================
278
279void
280GNERouteRef::setAttribute(SumoXMLAttr key, const std::string& value) {
281 switch (key) {
282 case SUMO_ATTR_PROB:
283 if (value.empty()) {
285 } else {
286 myProbability = parse<double>(value);
287 }
288 break;
289 default:
290 setCommonAttribute(this, key, value);
291 break;
292 }
293}
294
295
296void
298 // routesRefs cannot be moved
299}
300
301
302void
303GNERouteRef::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
304 // routesRefs cannot be moved
305}
306
307/****************************************************************************/
#define TLF(string,...)
Definition MsgHandler.h:303
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SUMO_TAG_ROUTE
description of a route
@ GNE_TAG_ROUTEREF
virtual element used to reference routes with distributions
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_REFID
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ID
@ GNE_ATTR_ROUTE_DISTRIBUTION
route distribution
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
std::string getCommonAttribute(const Parameterised *parameterised, SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
bool isCommonValid(SumoXMLAttr key, const std::string &value) const
const GNETagProperties * myTagProperty
reference to tagProperty associated with this attribute carrier
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
Problem
enum class for demandElement problems
const GNEHierarchicalContainerParents< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
move operation
move result
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2194
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over junction.
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Position getPositionInView() const
Returns position of additional in view.
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
~GNERouteRef()
destructor
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform demand element changes
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
double myProbability
probability
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over lane.
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
Position getAttributePosition(SumoXMLAttr key) const
const Parameterised::Map & getACParametersMap() const
get parameters map
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
std::string getParentName() const
Returns the name of the parent object.
std::string getDemandElementProblem() const
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
GNELane * getLastPathLane() const
get last path lane
const RGBColor & getColor() const
get color
void updateGeometry()
update pre-computed geometry information
bool isAttributeEnabled(SumoXMLAttr key) const
Problem isDemandElementValid() const
check if current demand element is valid to be written into XML (by default true, can be reimplemente...
GNEMoveOperation * getMoveOperation()
get move operation
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void computePathElement()
compute pathElement
GNELane * getFirstPathLane() const
get first path lane
double getAttributeDouble(SumoXMLAttr key) const
GNERouteRef(GNENet *net)
default constructor
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
double getDefaultDoubleValue(SumoXMLAttr attr) const
get default double value
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
The popup menu of a globject.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
void buildPopUpMenuCommonOptions(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, GUISUMOAbstractView *parent, const SumoXMLTag tag, const bool selected, bool addSeparator=true)
Stores the information about how to visualize structures.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
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
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37