Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEVTypeDistribution.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// VehicleType distribution used in netedit
19/****************************************************************************/
20
22#include <netedit/GNENet.h>
25
27
28// ===========================================================================
29// member method definitions
30// ===========================================================================
31
35
36
37GNEVTypeDistribution::GNEVTypeDistribution(const std::string& ID, GNENet* net, const std::string& filename, const int deterministic) :
38 GNEDemandElement(ID, net, filename, SUMO_TAG_VTYPE_DISTRIBUTION, GNEPathElement::Options::DEMAND_ELEMENT),
39 myDeterministic(deterministic) {
40}
41
42
44
45
48 return nullptr;
49}
50
51
54 return nullptr;
55}
56
57
58const Parameterised*
60 return nullptr;
61}
62
63
64void
66 // now write attributes
67 device.openTag(getTagProperty()->getTag());
68 device.writeAttr(SUMO_ATTR_ID, getID());
69 if (myDeterministic != myTagProperty->getDefaultIntValue(SUMO_ATTR_DETERMINISTIC)) {
71 }
72 // write references
73 for (const auto& refChild : getChildDemandElements()) {
74 if (refChild->getTagProperty()->isDistributionReference() &&
75 (refChild->getParentDemandElements().front() == this)) {
76 refChild->writeDemandElement(device);
77 }
78 }
79 device.closeTag();
80}
81
82
85 // currently distributions don't have problems
87}
88
89
90std::string
94
95
96void
100
101
104 // get value of first referenced vType
105 for (const auto& vTypeRef : getChildDemandElements()) {
106 if (vTypeRef->getTagProperty()->isDistributionReference()) {
107 return vTypeRef->getParentDemandElements().at(1)->getVClass();
108 }
109 }
110 // if this distribution doesn't have vTypes, use default vType
111 return myNet->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_TYPE, DEFAULT_VTYPE_ID)->getVClass();
112}
113
114
115const RGBColor&
117 // get value of first referenced vType
118 for (const auto& vTypeRef : getChildDemandElements()) {
119 if (vTypeRef->getTagProperty()->isDistributionReference()) {
120 return vTypeRef->getParentDemandElements().at(1)->getColor();
121 }
122 }
123 // if this distribution doesn't have vTypes, use default vType
124 return myNet->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_TYPE, DEFAULT_VTYPE_ID)->getColor();
125}
126
127
128void
130 // nothing to update
131}
132
133
136 // get value of first referenced vType
137 for (const auto& vTypeRef : getChildDemandElements()) {
138 if (vTypeRef->getTagProperty()->isDistributionReference()) {
139 return vTypeRef->getParentDemandElements().at(1)->getPositionInView();
140 }
141 }
142 // if this distribution doesn't have vTypes, use default vType
143 return myNet->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_TYPE, DEFAULT_VTYPE_ID)->getPositionInView();
144}
145
146
147std::string
149 return myNet->getMicrosimID();
150}
151
152
155 return Boundary(-0.1, -0.1, 0.1, 0.1);
156}
157
158
159void
160GNEVTypeDistribution::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
178GNEVTypeDistribution::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
179 // route distributions don't use drawJunctionPartialGL
180}
181
182
183void
184GNEVTypeDistribution::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
185 // route distributions don't use drawJunctionPartialGL
186}
187
188
189GNELane*
191 return nullptr;
192}
193
194
195GNELane*
197 return nullptr;
198}
199
200
201std::string
203 switch (key) {
204 case SUMO_ATTR_ID:
205 return getMicrosimID();
207 if (myDeterministic == -1) {
208 return "";
209 } else {
211 }
213 return getCommonAttribute(key);
214 default:
215 // get value of first referenced vType
216 for (const auto& vTypeRef : getChildDemandElements()) {
217 if (vTypeRef->getTagProperty()->isDistributionReference() &&
218 (vTypeRef->getParentDemandElements().at(1)->getTagProperty()->getTag() == SUMO_TAG_VTYPE)) {
219 return vTypeRef->getParentDemandElements().at(1)->getAttribute(key);
220 }
221 }
222 // if this distribution doesn't have vTypes, use default vType
223 return myNet->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_VTYPE, DEFAULT_VTYPE_ID)->getAttribute(key);
224 }
225}
226
227
228double
230 // get value of first referenced vType
231 for (const auto& vTypeRef : getChildDemandElements()) {
232 if (vTypeRef->getTagProperty()->isDistributionReference() &&
233 (vTypeRef->getParentDemandElements().at(1)->getTagProperty()->getTag() == SUMO_TAG_VTYPE)) {
234 return vTypeRef->getParentDemandElements().at(1)->getAttributeDouble(key);
235 }
236 }
237 // if this distribution doesn't have vTypes, use default vType
238 return myNet->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_VTYPE, DEFAULT_VTYPE_ID)->getAttributeDouble(key);
239}
240
241
244 // get value of first referenced vType
245 for (const auto& vTypeRef : getChildDemandElements()) {
246 if (vTypeRef->getTagProperty()->isDistributionReference() &&
247 (vTypeRef->getParentDemandElements().at(1)->getTagProperty()->getTag() == SUMO_TAG_VTYPE)) {
248 return vTypeRef->getParentDemandElements().at(1)->getAttributePosition(key);
249 }
250 }
251 // if this distribution doesn't have vTypes, use default vType
252 return myNet->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_VTYPE, DEFAULT_VTYPE_ID)->getAttributePosition(key);
253}
254
255
256void
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_ID:
264 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
265 break;
266 default:
267 setCommonAttribute(key, value, undoList);
268 break;
269 }
270}
271
272
273bool
275 switch (key) {
276 case SUMO_ATTR_ID:
279 if ((value == "-1") || value.empty()) {
280 return true;
281 } else {
282 return canParse<int>(value) && (parse<int>(value) >= 0);
283 }
284 default:
285 return isCommonAttributeValid(key, value);
286 }
287}
288
289
290std::string
292 return getTagStr();
293}
294
295
296std::string
300
301// ===========================================================================
302// private
303// ===========================================================================
304
305void
307 switch (key) {
308 case SUMO_ATTR_ID:
310 break;
312 if (value.empty()) {
313 myDeterministic = -1;
314 } else {
316 }
317 break;
318 default:
320 break;
321 }
322}
323
324/****************************************************************************/
const std::string invalid_return< std::string >::value
const std::string DEFAULT_VTYPE_ID
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_VTYPE_DISTRIBUTION
distribution of a vehicle type
@ SUMO_TAG_TYPE
type (edge)
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_DEMAND_FILE
demand demand file
@ SUMO_ATTR_DETERMINISTIC
@ 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 override
get ID (all Attribute Carriers have one)
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc....
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
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
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
bool isValidDemandElementID(const std::string &value) const
check if a new demand element ID is valid
GNEDemandElement(const std::string &id, GNENet *net, const std::string &filename, SumoXMLTag tag, const GNEPathElement::Options pathOptions)
Constructor.
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
GNEPathElement(const GNEPathElement::Options options)
constructor
std::string getDemandElementProblem() const override
return a string with the current demand element problem
Parameterised * getParameters() override
get parameters associated with this vTypeDistribution
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
void computePathElement() override
compute pathElement
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
Boundary getCenteringBoundary() const override
Returns the boundary to which the view shall be centered in order to show the object.
double getAttributeDouble(SumoXMLAttr key) const override
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const override
Draws partial object over junction.
bool isValid(SumoXMLAttr key, const std::string &value) override
GNEVTypeDistribution(GNENet *net)
default constructor
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
void updateGeometry() override
update pre-computed geometry information
void writeDemandElement(OutputDevice &device) const override
write demand element element into a xml file
SUMOVehicleClass getVClass() const override
obtain VClass related with this demand element
void fixDemandElementProblem() override
fix demand element problem
std::string getParentName() const override
Returns the name of the parent object.
int myDeterministic
deterministic distribution
Position getPositionInView() const override
Returns position of additional in view.
GNELane * getLastPathLane() const override
get last path lane
Position getAttributePosition(SumoXMLAttr key) const override
Problem isDemandElementValid() const override
check if current demand element is valid to be written into XML
std::string getAttribute(SumoXMLAttr key) const override
inherited from GNEAttributeCarrier
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const override
Draws partial object over lane.
const RGBColor & getColor() const override
get color
GNELane * getFirstPathLane() const override
get first path lane
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this vTypeDistribution
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
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