Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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>
24
25#include "GNERouteRef.h"
26#include "GNEVehicle.h"
27
28// ===========================================================================
29// GNERouteRef - methods
30// ===========================================================================
31
35
36
37GNERouteRef::GNERouteRef(GNEDemandElement* distributionParent, GNEDemandElement* routeParent, const double probability) :
38 GNEDemandElement(distributionParent, GNE_TAG_ROUTEREF, GNEPathElement::Options::DEMAND_ELEMENT),
39 myProbability(probability) {
40 // set parents
41 setParents<GNEDemandElement*>({distributionParent, routeParent});
42}
43
44
46
47
50 return nullptr;
51}
52
53
56 return nullptr;
57}
58
59
60const Parameterised*
62 return nullptr;
63}
64
65
68 // create popup
69 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
70 // build common options
72 return ret;
73}
74
75
76void
84
85
90
91
92std::string
94 return "";
95}
96
97
98void
100 // currently the only solution is removing Route
101}
102
103
106 return getParentDemandElements().back()->getVClass();
107}
108
109
110const RGBColor&
112 return getParentDemandElements().back()->getColor();
113}
114
115
116void
118 // nothing to update
119}
120
121
124 return getParentDemandElements().front()->getPositionInView();
125}
126
127
128std::string
130 return getParentDemandElements().front()->getID();
131}
132
133
134double
136 return 1;
137}
138
139
142 if (getParentDemandElements().size() > 1) {
143 return getParentDemandElements().at(1)->getCenteringBoundary();
144 } else {
145 return Boundary(-0.1, -0.1, 0.1, 0.1);
146 }
147}
148
149
150void
151GNERouteRef::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/,
152 const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
153 // nothing to do
154}
155
156
157void
159 // nothing to draw
160}
161
162
163void
165 // nothing to do
166}
167
168
169void
170GNERouteRef::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
171 // nothing to draw
172}
173
174
175void
176GNERouteRef::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
177 // nothing to draw
178}
179
180
181GNELane*
183 return getParentDemandElements().back()->getFirstPathLane();
184}
185
186
187GNELane*
189 return getParentDemandElements().back()->getLastPathLane();
190}
191
192
193std::string
195 switch (key) {
196 case SUMO_ATTR_ID:
197 return getMicrosimID();
199 return getParentDemandElements().front()->getID();
200 case SUMO_ATTR_REFID:
201 return getParentDemandElements().back()->getID();
202 case SUMO_ATTR_PROB:
203 return toString(myProbability);
204 default:
205 return getCommonAttribute(key);
206 }
207}
208
209
210double
212 switch (key) {
213 case SUMO_ATTR_PROB:
214 return myProbability;
215 default:
216 return getCommonAttributeDouble(key);
217 }
218}
219
220
225
226
227bool
229 switch (key) {
231 case SUMO_ATTR_REFID:
232 return false;
233 default:
234 return true;
235 }
236}
237
238
239void
240GNERouteRef::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
241 if (value == getAttribute(key)) {
242 return; //avoid needless changes, later logic relies on the fact that attributes have changed
243 }
244 switch (key) {
245 case SUMO_ATTR_PROB:
246 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
247 break;
248 default:
249 setCommonAttribute(key, value, undoList);
250 break;
251 }
252}
253
254
255bool
256GNERouteRef::isValid(SumoXMLAttr key, const std::string& value) {
257 switch (key) {
258 case SUMO_ATTR_PROB:
259 if (value.empty()) {
260 return true;
261 } else {
262 return canParse<double>(value) && (parse<double>(value) >= 0);
263 }
264 default:
265 return isCommonAttributeValid(key, value);
266 }
267}
268
269
270std::string
272 return getTagStr();
273}
274
275
276std::string
280
281// ===========================================================================
282// private
283// ===========================================================================
284
285void
286GNERouteRef::setAttribute(SumoXMLAttr key, const std::string& value) {
287 switch (key) {
288 case SUMO_ATTR_PROB:
289 if (value.empty()) {
291 } else {
292 myProbability = parse<double>(value);
293 }
294 break;
295 default:
296 setCommonAttribute(key, value);
297 break;
298 }
299}
300
301/****************************************************************************/
#define TLF(string,...)
Definition MsgHandler.h:306
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
double getCommonAttributeDouble(SumoXMLAttr key) const
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
Position getCommonAttributePosition(SumoXMLAttr key) const
GNENet * myNet
pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
std::string getCommonAttribute(SumoXMLAttr key) 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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over junction.
bool isValid(SumoXMLAttr key, const std::string &value) override
Position getPositionInView() const
Returns position of additional in view.
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
~GNERouteRef()
destructor
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this routeRef
double getAttributeDouble(SumoXMLAttr key) const override
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
void updateGeometry() override
update pre-computed geometry information
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.
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)
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...
Parameterised * getParameters() override
get parameters associated with this routeRef
GNELane * getLastPathLane() const
get last path lane
const RGBColor & getColor() const
get color
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
std::string getAttribute(SumoXMLAttr key) const override
inherited from GNEAttributeCarrier
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...
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Position getAttributePosition(SumoXMLAttr key) const override
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
void computePathElement()
compute pathElement
GNELane * getFirstPathLane() const
get first path lane
GNERouteRef(GNENet *net)
default constructor
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
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.
An upper class for objects with additional parameters.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37