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 // write references
69 for (const auto& refChild : getChildDemandElements()) {
70 if (refChild->getTagProperty()->isDistributionReference()) {
71 if (refChild->getTagProperty()->isDistributionReference() &&
72 (refChild->getParentDemandElements().front() == this)) {
73 refChild->writeDemandElement(device);
74 }
75 }
76 }
77 device.closeTag();
78}
79
80
83 // currently distributions don't have problems
85}
86
87
88std::string
92
93
94void
98
99
102 if (getChildDemandElements().size() > 0) {
103 return getChildDemandElements().front()->getVClass();
104 } else {
105 return SVC_IGNORING;
106 }
107}
108
109
110const RGBColor&
112 if (getChildDemandElements().size() > 0) {
113 return getChildDemandElements().front()->getColor();
114 } else {
115 return RGBColor::INVISIBLE;
116 }
117}
118
119
120void
122 // update geometries of all vehicles
123 for (auto vehicle : getChildDemandElements()) {
124 if (vehicle->getTagProperty()->isVehicle()) {
125 vehicle->updateGeometry();
126 }
127 }
128}
129
130
133 if (getChildDemandElements().size() > 0) {
134 return getChildDemandElements().front()->getPositionInView();
135 } else {
136 return Position();
137 }
138}
139
140
141std::string
145
146
149 if (getChildDemandElements().size() > 0) {
150 return getChildDemandElements().front()->getCenteringBoundary();
151 } else {
152 return Boundary(-0.1, -0.1, 0.1, 0.1);
153 }
154}
155
156
157void
158GNERouteDistribution::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
159 // geometry of this element cannot be splitted
160}
161
162
163void
165 // draw all vehicles
166 for (auto vehicle : getChildDemandElements()) {
167 if (vehicle->getTagProperty()->isVehicle()) {
168 vehicle->drawGL(s);
169 }
170 }
171}
172
173
174void
176 // nothing to compute
177}
178
179
180void
181GNERouteDistribution::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
182 // route distributions don't use drawJunctionPartialGL
183}
184
185
186void
187GNERouteDistribution::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
188 // route distributions don't use drawJunctionPartialGL
189}
190
191
192GNELane*
194 if (getChildDemandElements().size() > 0) {
195 return getChildDemandElements().front()->getFirstPathLane();
196 } else {
197 return nullptr;
198 }
199}
200
201
202GNELane*
204 if (getChildDemandElements().size() > 0) {
205 return getChildDemandElements().front()->getLastPathLane();
206 } else {
207 return nullptr;
208 }
209}
210
211
212std::string
214 switch (key) {
215 case SUMO_ATTR_ID:
216 return getMicrosimID();
217 default:
218 return getCommonAttribute(key);
219 }
220}
221
222
223double
227
228
233
234
235void
236GNERouteDistribution::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
237 if (value == getAttribute(key)) {
238 return; //avoid needless changes, later logic relies on the fact that attributes have changed
239 }
240 switch (key) {
241 case SUMO_ATTR_ID:
242 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
243 break;
244 default:
245 setCommonAttribute(key, value, undoList);
246 break;
247 }
248}
249
250
251bool
252GNERouteDistribution::isValid(SumoXMLAttr key, const std::string& value) {
253 switch (key) {
254 case SUMO_ATTR_ID:
256 default:
257 return isCommonAttributeValid(key, value);
258 }
259}
260
261
262std::string
264 return getTagStr();
265}
266
267
268std::string
272
273// ===========================================================================
274// private
275// ===========================================================================
276
277void
278GNERouteDistribution::setAttribute(SumoXMLAttr key, const std::string& value) {
279 switch (key) {
280 case SUMO_ATTR_ID:
281 setDemandElementID(value);
282 break;
283 default:
284 setCommonAttribute(key, value);
285 break;
286 }
287}
288
289/****************************************************************************/
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
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_ID
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
double getCommonAttributeDouble(SumoXMLAttr key) const
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
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
void computePathElement() override
compute pathElement
Problem isDemandElementValid() const override
check if current demand element is valid to be written into XML
SUMOVehicleClass getVClass() const override
obtain VClass related with this demand element
bool isValid(SumoXMLAttr key, const std::string &value) override
Boundary getCenteringBoundary() const override
Returns the boundary to which the view shall be centered in order to show the object.
Parameterised * getParameters() override
get parameters associated with this routeDistribution
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
GNELane * getFirstPathLane() const override
get first path lane
void fixDemandElementProblem() override
fix demand element problem
std::string getAttribute(SumoXMLAttr key) const override
inherited from GNEAttributeCarrier
void writeDemandElement(OutputDevice &device) const override
write demand element element into a xml file
std::string getParentName() const override
Returns the name of the parent object.
double getAttributeDouble(SumoXMLAttr key) const override
Position getAttributePosition(SumoXMLAttr key) const override
const RGBColor & getColor() const override
get color
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const override
Draws partial object over junction.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
Position getPositionInView() const override
Returns position of additional in view.
void updateGeometry() override
update pre-computed geometry information
GNELane * getLastPathLane() const override
get last path lane
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
GNERouteDistribution(GNENet *net)
default constructor
std::string getDemandElementProblem() const override
return a string with the current demand element problem
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const override
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