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
38 GNEDemandElement(distributionParent, GNE_TAG_ROUTEREF) {
39 // set parents
40 setParents<GNEDemandElement*>({distributionParent, routeParent});
41}
42
43
45 const double probability) :
46 GNEDemandElement(distributionParent, GNE_TAG_ROUTEREF),
47 myProbability(probability) {
48 // set parents
49 setParents<GNEDemandElement*>({distributionParent, routeParent});
50}
51
52
54
55
58 return nullptr;
59}
60
61
64 return nullptr;
65}
66
67
68const Parameterised*
70 return nullptr;
71}
72
73
76 // create popup
77 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
78 // build common options
80 return ret;
81}
82
83
84void
94
95
100
101
102std::string
104 return "";
105}
106
107
108void
110 // currently the only solution is removing Route
111}
112
113
116 return getParentDemandElements().back()->getVClass();
117}
118
119
120const RGBColor&
124
125
126void
128 // nothing to update
129}
130
131
134 return getParentDemandElements().front()->getPositionInView();
135}
136
137
138std::string
140 return getParentDemandElements().front()->getID();
141}
142
143
144double
146 return 1;
147}
148
149
152 if (getParentDemandElements().size() > 1) {
153 return getParentDemandElements().at(1)->getCenteringBoundary();
154 } else {
155 return Boundary(-0.1, -0.1, 0.1, 0.1);
156 }
157}
158
159
160void
161GNERouteRef::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/,
162 const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
163 // nothing to do
164}
165
166
167void
169 // nothing to draw
170}
171
172
173void
175 // nothing to do
176}
177
178
179void
180GNERouteRef::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
181 // nothing to draw
182}
183
184
185void
186GNERouteRef::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
187 // nothing to draw
188}
189
190
191GNELane*
193 return getParentDemandElements().back()->getFirstPathLane();
194}
195
196
197GNELane*
199 return getParentDemandElements().back()->getLastPathLane();
200}
201
202
203std::string
205 switch (key) {
206 case SUMO_ATTR_ID:
207 return getMicrosimID();
208 case SUMO_ATTR_REFID:
209 return getParentDemandElements().back()->getID();
210 case SUMO_ATTR_PROB:
212 return getParentDemandElements().at(1)->getAttribute(key);
213 } else {
214 return toString(myProbability);
215 }
218 default:
219 return getCommonAttribute(key);
220 }
221}
222
223
224double
226 switch (key) {
227 case SUMO_ATTR_PROB:
229 return getParentDemandElements().at(1)->getAttributeDouble(key);
230 } else {
231 return myProbability;
232 }
233 default:
234 return getCommonAttributeDouble(key);
235 }
236}
237
238
243
244
245bool
247 switch (key) {
248 case SUMO_ATTR_REFID:
249 return false;
250 default:
251 return true;
252 }
253}
254
255
256void
257GNERouteRef::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
258 if (value == getAttribute(key)) {
259 return; //avoid needless changes, later logic relies on the fact that attributes have changed
260 }
261 switch (key) {
262 case SUMO_ATTR_PROB:
263 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
264 break;
265 default:
266 setCommonAttribute(key, value, undoList);
267 break;
268 }
269}
270
271
272bool
273GNERouteRef::isValid(SumoXMLAttr key, const std::string& value) {
274 switch (key) {
275 case SUMO_ATTR_PROB:
276 if (value.empty()) {
277 return true;
278 } else {
279 return canParse<double>(value) && (parse<double>(value) >= 0);
280 }
281 default:
282 return isCommonAttributeValid(key, value);
283 }
284}
285
286bool
288 switch (key) {
289 case SUMO_ATTR_PROB:
291 default:
292 return false;
293 }
294}
295
296std::string
298 return getTagStr();
299}
300
301
302std::string
306
307// ===========================================================================
308// private
309// ===========================================================================
310
311void
312GNERouteRef::setAttribute(SumoXMLAttr key, const std::string& value) {
313 switch (key) {
314 case SUMO_ATTR_PROB:
315 if (value.empty()) {
317 } else {
318 myProbability = parse<double>(value);
319 }
320 break;
321 default:
322 setCommonAttribute(key, value);
323 break;
324 }
325}
326
327/****************************************************************************/
#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
@ GNE_ATTR_DEFAULT_PROBABILITY
Flag to check if we're using a default probability.
@ SUMO_ATTR_ID
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:68
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)
static const std::string FALSE_STR
true value in string format(used for comparing boolean values in getAttribute(...))
static const std::string TRUE_STR
true value in string format (used for comparing boolean values in getAttribute(......
const std::string getID() const override
get ID (all Attribute Carriers have one)
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
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
bool isValid(SumoXMLAttr key, const std::string &value) override
SUMOVehicleClass getVClass() const override
obtain VClass related with this demand element
std::string getParentName() const override
Returns the name of the parent object.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
Position getPositionInView() const override
Returns position of additional in view.
void computePathElement() override
compute pathElement
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const override
Draws partial object over lane.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own popup-menu.
~GNERouteRef()
destructor
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this routeRef
double getAttributeDouble(SumoXMLAttr key) const override
double getExaggeration(const GUIVisualizationSettings &s) const override
return exaggeration associated with this GLObject
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
void updateGeometry() override
update pre-computed geometry information
Problem isDemandElementValid() const override
check if current demand element is valid to be written into XML (by default true, can be reimplemente...
Boundary getCenteringBoundary() const override
Returns the boundary to which the view shall be centered in order to show the object.
bool isAttributeEnabled(SumoXMLAttr key) const override
double myProbability
probability
std::string getDemandElementProblem() const override
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
bool isAttributeComputed(SumoXMLAttr key) const override
Parameterised * getParameters() override
get parameters associated with this routeRef
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
std::string getAttribute(SumoXMLAttr key) const override
inherited from GNEAttributeCarrier
Position getAttributePosition(SumoXMLAttr key) const override
GNELane * getLastPathLane() const override
get last path lane
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const override
Draws partial object over junction.
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
void writeDemandElement(OutputDevice &device) const override
write demand element element into a xml file
const RGBColor & getColor() const override
get color
void fixDemandElementProblem() override
fix demand element problem (by default throw an exception, has to be reimplemented in children)
GNELane * getFirstPathLane() const override
get first path lane
GNERouteRef(GNENet *net)
default constructor
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
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
static const RGBColor INVISIBLE
Definition RGBColor.h:198