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 // distributions cannot be moved
48 return nullptr;
49}
50
51
52void
54 // write attributes
55 device.openTag(getTagProperty()->getTag());
56 device.writeAttr(SUMO_ATTR_ID, getID());
57 // check if write route or refs)
58 for (const auto& refChild : getChildDemandElements()) {
59 if (refChild->getTagProperty()->getTag() == GNE_TAG_ROUTEREF) {
60 int numReferences = 0;
61 for (const auto& routeChild : refChild->getParentDemandElements().at(1)->getChildDemandElements()) {
62 if (routeChild->getTagProperty()->getTag() == GNE_TAG_ROUTEREF) {
63 numReferences++;
64 }
65 }
66 if (numReferences == 1) {
67 refChild->getParentDemandElements().at(1)->writeDemandElement(device);
68 } else {
69 refChild->writeDemandElement(device);
70 }
71 }
72 }
73 device.closeTag();
74}
75
76
79 // currently distributions don't have problems
81}
82
83
84std::string
88
89
90void
94
95
98 if (getChildDemandElements().size() > 0) {
99 return getChildDemandElements().front()->getVClass();
100 } else {
101 return SVC_IGNORING;
102 }
103}
104
105
106const RGBColor&
108 if (getChildDemandElements().size() > 0) {
109 return getChildDemandElements().front()->getColor();
110 } else {
111 return RGBColor::INVISIBLE;
112 }
113}
114
115
116void
118 // nothing to update
119}
120
121
124 if (getChildDemandElements().size() > 0) {
125 return getChildDemandElements().front()->getPositionInView();
126 } else {
127 return Position();
128 }
129}
130
131
132std::string
136
137
140 if (getChildDemandElements().size() > 0) {
141 return getChildDemandElements().front()->getCenteringBoundary();
142 } else {
143 return Boundary(-0.1, -0.1, 0.1, 0.1);
144 }
145}
146
147
148void
149GNERouteDistribution::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
150 // geometry of this element cannot be splitted
151}
152
153
154void
156 // Vehicle Types aren't draw
157}
158
159
160void
162 // nothing to compute
163}
164
165
166void
167GNERouteDistribution::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
168 // route distributions don't use drawJunctionPartialGL
169}
170
171
172void
173GNERouteDistribution::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
174 // route distributions don't use drawJunctionPartialGL
175}
176
177
178GNELane*
180 if (getChildDemandElements().size() > 0) {
181 return getChildDemandElements().front()->getFirstPathLane();
182 } else {
183 return nullptr;
184 }
185}
186
187
188GNELane*
190 if (getChildDemandElements().size() > 0) {
191 return getChildDemandElements().front()->getLastPathLane();
192 } else {
193 return nullptr;
194 }
195}
196
197
198std::string
200 switch (key) {
201 case SUMO_ATTR_ID:
202 return getMicrosimID();
203 default:
204 return getCommonAttribute(this, key);
205 }
206}
207
208
209double
211 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
212}
213
214
217 throw InvalidArgument(getTagStr() + " doesn't have a Position attribute of type '" + toString(key) + "'");
218}
219
220
221void
222GNERouteDistribution::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
223 if (value == getAttribute(key)) {
224 return; //avoid needless changes, later logic relies on the fact that attributes have changed
225 }
226 switch (key) {
227 case SUMO_ATTR_ID:
228 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
229 break;
230 default:
231 setCommonAttribute(key, value, undoList);
232 break;
233 }
234}
235
236
237bool
238GNERouteDistribution::isValid(SumoXMLAttr key, const std::string& value) {
239 switch (key) {
240 case SUMO_ATTR_ID:
242 default:
243 return isCommonValid(key, value);
244 }
245}
246
247
248std::string
250 return getTagStr();
251}
252
253
254std::string
258
259
262 throw InvalidArgument(getTagStr() + " doesn't have parameters");
263}
264
265// ===========================================================================
266// private
267// ===========================================================================
268
269void
270GNERouteDistribution::setAttribute(SumoXMLAttr key, const std::string& value) {
271 switch (key) {
272 case SUMO_ATTR_ID:
273 setDemandElementID(value);
274 break;
275 default:
276 setCommonAttribute(this, key, value);
277 break;
278 }
279}
280
281
282void
284 // distributions cannot be moved
285}
286
287
288void
290 // distributions cannot be moved
291}
292
293/****************************************************************************/
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
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
const std::string getID() const
get ID (all Attribute Carriers have one)
std::string getCommonAttribute(const Parameterised *parameterised, 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
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * myNet
pointer to net
bool isCommonValid(SumoXMLAttr key, const std::string &value) 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
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
move operation
move result
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEMoveOperation * getMoveOperation()
get move operation
void updateGeometry()
update pre-computed geometry information
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
GNELane * getFirstPathLane() const
get first path lane
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform demand element changes
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
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
double getAttributeDouble(SumoXMLAttr key) const
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
Position getAttributePosition(SumoXMLAttr key) const
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
void computePathElement()
compute pathElement
void fixDemandElementProblem()
fix demand element problem
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
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.
const Parameterised::Map & getACParametersMap() const
get parameters map
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.
std::map< std::string, std::string > Map
parameters map
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
static const RGBColor INVISIBLE
Definition RGBColor.h:198