Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNERouteDistribution.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// Route distribution used in netedit
19/****************************************************************************/
20
22#include <netedit/GNENet.h>
25
27
28// ===========================================================================
29// member method definitions
30// ===========================================================================
31
35
36
37GNERouteDistribution::GNERouteDistribution(const std::string& ID, GNENet* net, const std::string& filename) :
38 GNEDemandElement(ID, net, filename, SUMO_TAG_ROUTE_DISTRIBUTION, GNEPathElement::Options::DEMAND_ELEMENT) {
39}
40
41
43
44
47 return nullptr;
48}
49
50
53 return nullptr;
54}
55
56
57const Parameterised*
59 return nullptr;
60}
61
62
63void
65 // write attributes
66 device.openTag(getTagProperty()->getTag());
67 device.writeAttr(SUMO_ATTR_ID, getID());
68 // check if write route or refs)
69 for (const auto& refChild : getChildDemandElements()) {
70 if (refChild->getTagProperty()->getTag() == GNE_TAG_ROUTEREF) {
71 int numReferences = 0;
72 for (const auto& routeChild : refChild->getParentDemandElements().at(1)->getChildDemandElements()) {
73 if (routeChild->getTagProperty()->getTag() == GNE_TAG_ROUTEREF) {
74 numReferences++;
75 }
76 }
77 if (numReferences == 1) {
78 refChild->getParentDemandElements().at(1)->writeDemandElement(device);
79 } else {
80 refChild->writeDemandElement(device);
81 }
82 }
83 }
84 device.closeTag();
85}
86
87
90 // currently distributions don't have problems
92}
93
94
95std::string
99
100
101void
105
106
109 if (getChildDemandElements().size() > 0) {
110 return getChildDemandElements().front()->getVClass();
111 } else {
112 return SVC_IGNORING;
113 }
114}
115
116
117const RGBColor&
119 if (getChildDemandElements().size() > 0) {
120 return getChildDemandElements().front()->getColor();
121 } else {
122 return RGBColor::INVISIBLE;
123 }
124}
125
126
127void
129 // nothing to update
130}
131
132
135 if (getChildDemandElements().size() > 0) {
136 return getChildDemandElements().front()->getPositionInView();
137 } else {
138 return Position();
139 }
140}
141
142
143std::string
147
148
151 if (getChildDemandElements().size() > 0) {
152 return getChildDemandElements().front()->getCenteringBoundary();
153 } else {
154 return Boundary(-0.1, -0.1, 0.1, 0.1);
155 }
156}
157
158
159void
160GNERouteDistribution::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
161 // geometry of this element cannot be splitted
162}
163
164
165void
167 // Vehicle Types aren't draw
168}
169
170
171void
173 // nothing to compute
174}
175
176
177void
178GNERouteDistribution::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
179 // route distributions don't use drawJunctionPartialGL
180}
181
182
183void
184GNERouteDistribution::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
185 // route distributions don't use drawJunctionPartialGL
186}
187
188
189GNELane*
191 if (getChildDemandElements().size() > 0) {
192 return getChildDemandElements().front()->getFirstPathLane();
193 } else {
194 return nullptr;
195 }
196}
197
198
199GNELane*
201 if (getChildDemandElements().size() > 0) {
202 return getChildDemandElements().front()->getLastPathLane();
203 } else {
204 return nullptr;
205 }
206}
207
208
209std::string
211 switch (key) {
212 case SUMO_ATTR_ID:
213 return getMicrosimID();
214 default:
215 return getCommonAttribute(key);
216 }
217}
218
219
220double
224
225
230
231
232void
233GNERouteDistribution::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
234 if (value == getAttribute(key)) {
235 return; //avoid needless changes, later logic relies on the fact that attributes have changed
236 }
237 switch (key) {
238 case SUMO_ATTR_ID:
239 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
240 break;
241 default:
242 setCommonAttribute(key, value, undoList);
243 break;
244 }
245}
246
247
248bool
249GNERouteDistribution::isValid(SumoXMLAttr key, const std::string& value) {
250 switch (key) {
251 case SUMO_ATTR_ID:
253 default:
254 return isCommonAttributeValid(key, value);
255 }
256}
257
258
259std::string
261 return getTagStr();
262}
263
264
265std::string
269
270// ===========================================================================
271// private
272// ===========================================================================
273
274void
275GNERouteDistribution::setAttribute(SumoXMLAttr key, const std::string& value) {
276 switch (key) {
277 case SUMO_ATTR_ID:
278 setDemandElementID(value);
279 break;
280 default:
281 setCommonAttribute(key, value);
282 break;
283 }
284}
285
286/****************************************************************************/
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
@ SUMO_TAG_ROUTE_DISTRIBUTION
distribution of a route
@ GNE_TAG_ROUTEREF
virtual element used to reference routes with distributions
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_ID
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
const std::string getID() const
get ID (all Attribute Carriers have one)
double getCommonAttributeDouble(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
Position getCommonAttributePosition(SumoXMLAttr key) const
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * myNet
pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
std::string getCommonAttribute(SumoXMLAttr key) const
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
bool isValidDemandElementID(const std::string &value) const
check if a new demand element ID is valid
void setDemandElementID(const std::string &newID)
set demand element id
Problem
enum class for demandElement problems
const GNEHierarchicalContainerChildren< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this routeDistribution
GNELane * getFirstPathLane() const
get first path lane
bool isValid(SumoXMLAttr key, const std::string &value) override
Parameterised * getParameters() override
get parameters associated with this routeDistribution
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string getDemandElementProblem() const
return a string with the current demand element problem
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
std::string getParentName() const
Returns the name of the parent object.
Problem isDemandElementValid() const
check if current demand element is valid to be written into XML
const RGBColor & getColor() const
get color
std::string getAttribute(SumoXMLAttr key) const override
inherited from GNEAttributeCarrier
double getAttributeDouble(SumoXMLAttr key) const override
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
Position getAttributePosition(SumoXMLAttr key) const override
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
void updateGeometry() override
update pre-computed geometry information
void computePathElement()
compute pathElement
void fixDemandElementProblem()
fix demand element problem
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over junction.
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
Position getPositionInView() const
Returns position of additional in view.
GNERouteDistribution(GNENet *net)
default constructor
GNELane * getLastPathLane() const
get last path lane
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over lane.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Stores the information about how to visualize structures.
static const std::vector< SumoXMLTag > routes
route namespace
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