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, GNEPathElement::Options::DEMAND_ELEMENT) {
39 // set parents
40 setParents<GNEDemandElement*>({distributionParent, routeParent});
41}
42
43
44GNERouteRef::GNERouteRef(GNEDemandElement* distributionParent, GNEDemandElement* routeParent, const double probability) :
45 GNEDemandElement(distributionParent, GNE_TAG_ROUTEREF, GNEPathElement::Options::DEMAND_ELEMENT),
46 myProbability(probability) {
47 // set parents
48 setParents<GNEDemandElement*>({distributionParent, routeParent});
49}
50
51
53
54
57 return nullptr;
58}
59
60
63 return nullptr;
64}
65
66
67const Parameterised*
69 return nullptr;
70}
71
72
75 // create popup
76 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
77 // build common options
79 return ret;
80}
81
82
83void
93
94
99
100
101std::string
103 return "";
104}
105
106
107void
109 // currently the only solution is removing Route
110}
111
112
115 return getParentDemandElements().back()->getVClass();
116}
117
118
119const RGBColor&
123
124
125void
127 // nothing to update
128}
129
130
133 return getParentDemandElements().front()->getPositionInView();
134}
135
136
137std::string
139 return getParentDemandElements().front()->getID();
140}
141
142
143double
145 return 1;
146}
147
148
151 if (getParentDemandElements().size() > 1) {
152 return getParentDemandElements().at(1)->getCenteringBoundary();
153 } else {
154 return Boundary(-0.1, -0.1, 0.1, 0.1);
155 }
156}
157
158
159void
160GNERouteRef::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/,
161 const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
162 // nothing to do
163}
164
165
166void
168 // nothing to draw
169}
170
171
172void
174 // nothing to do
175}
176
177
178void
179GNERouteRef::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
180 // nothing to draw
181}
182
183
184void
185GNERouteRef::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
186 // nothing to draw
187}
188
189
190GNELane*
192 return getParentDemandElements().back()->getFirstPathLane();
193}
194
195
196GNELane*
198 return getParentDemandElements().back()->getLastPathLane();
199}
200
201
202std::string
204 switch (key) {
205 case SUMO_ATTR_ID:
206 return getMicrosimID();
207 case SUMO_ATTR_REFID:
208 return getParentDemandElements().back()->getID();
209 case SUMO_ATTR_PROB:
211 return getParentDemandElements().at(1)->getAttribute(key);
212 } else {
213 return toString(myProbability);
214 }
217 default:
218 return getCommonAttribute(key);
219 }
220}
221
222
223double
225 switch (key) {
226 case SUMO_ATTR_PROB:
228 return getParentDemandElements().at(1)->getAttributeDouble(key);
229 } else {
230 return myProbability;
231 }
232 default:
233 return getCommonAttributeDouble(key);
234 }
235}
236
237
242
243
244bool
246 switch (key) {
247 case SUMO_ATTR_REFID:
248 return false;
249 default:
250 return true;
251 }
252}
253
254
255void
256GNERouteRef::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
257 if (value == getAttribute(key)) {
258 return; //avoid needless changes, later logic relies on the fact that attributes have changed
259 }
260 switch (key) {
261 case SUMO_ATTR_PROB:
262 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
263 break;
264 default:
265 setCommonAttribute(key, value, undoList);
266 break;
267 }
268}
269
270
271bool
272GNERouteRef::isValid(SumoXMLAttr key, const std::string& value) {
273 switch (key) {
274 case SUMO_ATTR_PROB:
275 if (value.empty()) {
276 return true;
277 } else {
278 return canParse<double>(value) && (parse<double>(value) >= 0);
279 }
280 default:
281 return isCommonAttributeValid(key, value);
282 }
283}
284
285bool
287 switch (key) {
288 case SUMO_ATTR_PROB:
290 default:
291 return false;
292 }
293}
294
295std::string
297 return getTagStr();
298}
299
300
301std::string
305
306// ===========================================================================
307// private
308// ===========================================================================
309
310void
311GNERouteRef::setAttribute(SumoXMLAttr key, const std::string& value) {
312 switch (key) {
313 case SUMO_ATTR_PROB:
314 if (value.empty()) {
316 } else {
317 myProbability = parse<double>(value);
318 }
319 break;
320 default:
321 setCommonAttribute(key, value);
322 break;
323 }
324}
325
326/****************************************************************************/
#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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
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