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-2026 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, FileBucket* fileBucket,
38 const int deterministic) :
40 myDeterministic(deterministic) {
41}
42
43
45
46
49 return nullptr;
50}
51
52
55 return nullptr;
56}
57
58
59const Parameterised*
61 return nullptr;
62}
63
64
65void
67 // now write attributes
68 device.openTag(getTagProperty()->getTag());
69 device.writeAttr(SUMO_ATTR_ID, getID());
70 if (myDeterministic != myTagProperty->getDefaultIntValue(SUMO_ATTR_DETERMINISTIC)) {
72 }
73 // write references
74 for (const auto& refChild : getChildDemandElements()) {
75 if (refChild->getTagProperty()->isDistributionReference() &&
76 (refChild->getParentDemandElements().front() == this)) {
77 refChild->writeDemandElement(device);
78 }
79 }
80 device.closeTag();
81}
82
83
86 // currently distributions don't have problems
88}
89
90
91std::string
95
96
97void
101
102
105 // get value of first referenced vType
106 for (const auto& vTypeRef : getChildDemandElements()) {
107 if (vTypeRef->getTagProperty()->isDistributionReference()) {
108 return vTypeRef->getParentDemandElements().at(1)->getVClass();
109 }
110 }
111 // if this distribution doesn't have vTypes, use default vType
112 return myNet->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_TYPE, DEFAULT_VTYPE_ID)->getVClass();
113}
114
115
116const RGBColor&
118 // get value of first referenced vType
119 for (const auto& vTypeRef : getChildDemandElements()) {
120 if (vTypeRef->getTagProperty()->isDistributionReference()) {
121 return vTypeRef->getParentDemandElements().at(1)->getColor();
122 }
123 }
124 // if this distribution doesn't have vTypes, use default vType
125 return myNet->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_TYPE, DEFAULT_VTYPE_ID)->getColor();
126}
127
128
129void
131 // nothing to update
132}
133
134
137 // get value of first referenced vType
138 for (const auto& vTypeRef : getChildDemandElements()) {
139 if (vTypeRef->getTagProperty()->isDistributionReference()) {
140 return vTypeRef->getParentDemandElements().at(1)->getPositionInView();
141 }
142 }
143 // if this distribution doesn't have vTypes, use default vType
144 return myNet->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_TYPE, DEFAULT_VTYPE_ID)->getPositionInView();
145}
146
147
148std::string
150 return myNet->getMicrosimID();
151}
152
153
156 return Boundary(-0.1, -0.1, 0.1, 0.1);
157}
158
159
160void
161GNEVTypeDistribution::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
162 // geometry of this element cannot be splitted
163}
164
165
166void
168 // Vehicle Types aren't draw
169}
170
171
172void
174 // nothing to compute
175}
176
177
178void
179GNEVTypeDistribution::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
180 // route distributions don't use drawJunctionPartialGL
181}
182
183
184void
185GNEVTypeDistribution::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
186 // route distributions don't use drawJunctionPartialGL
187}
188
189
190GNELane*
192 return nullptr;
193}
194
195
196GNELane*
198 return nullptr;
199}
200
201
202std::string
204 switch (key) {
205 case SUMO_ATTR_ID:
206 return getMicrosimID();
208 if (myDeterministic == -1) {
209 return "";
210 } else {
212 }
214 return getCommonAttribute(key);
215 default:
216 // get value of first referenced vType
217 for (const auto& vTypeRef : getChildDemandElements()) {
218 if (vTypeRef->getTagProperty()->isDistributionReference() &&
219 (vTypeRef->getParentDemandElements().at(1)->getTagProperty()->getTag() == SUMO_TAG_VTYPE)) {
220 return vTypeRef->getParentDemandElements().at(1)->getAttribute(key);
221 }
222 }
223 // if this distribution doesn't have vTypes, use default vType
224 return myNet->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_VTYPE, DEFAULT_VTYPE_ID)->getAttribute(key);
225 }
226}
227
228
229double
231 // get value of first referenced vType
232 for (const auto& vTypeRef : getChildDemandElements()) {
233 if (vTypeRef->getTagProperty()->isDistributionReference() &&
234 (vTypeRef->getParentDemandElements().at(1)->getTagProperty()->getTag() == SUMO_TAG_VTYPE)) {
235 return vTypeRef->getParentDemandElements().at(1)->getAttributeDouble(key);
236 }
237 }
238 // if this distribution doesn't have vTypes, use default vType
239 return myNet->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_VTYPE, DEFAULT_VTYPE_ID)->getAttributeDouble(key);
240}
241
242
245 // get value of first referenced vType
246 for (const auto& vTypeRef : getChildDemandElements()) {
247 if (vTypeRef->getTagProperty()->isDistributionReference() &&
248 (vTypeRef->getParentDemandElements().at(1)->getTagProperty()->getTag() == SUMO_TAG_VTYPE)) {
249 return vTypeRef->getParentDemandElements().at(1)->getAttributePosition(key);
250 }
251 }
252 // if this distribution doesn't have vTypes, use default vType
253 return myNet->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_VTYPE, DEFAULT_VTYPE_ID)->getAttributePosition(key);
254}
255
256
257void
259 if (value == getAttribute(key)) {
260 return; //avoid needless changes, later logic relies on the fact that attributes have changed
261 }
262 switch (key) {
263 case SUMO_ATTR_ID:
265 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
266 break;
267 default:
268 setCommonAttribute(key, value, undoList);
269 break;
270 }
271}
272
273
274bool
276 switch (key) {
277 case SUMO_ATTR_ID:
280 if ((value == "-1") || value.empty()) {
281 return true;
282 } else {
283 return canParse<int>(value) && (parse<int>(value) >= 0);
284 }
285 default:
286 return isCommonAttributeValid(key, value);
287 }
288}
289
290
291std::string
293 return getTagStr();
294}
295
296
297std::string
301
302// ===========================================================================
303// private
304// ===========================================================================
305
306void
308 switch (key) {
309 case SUMO_ATTR_ID:
311 break;
313 if (value.empty()) {
314 myDeterministic = -1;
315 } else {
317 }
318 break;
319 default:
321 break;
322 }
323}
324
325/****************************************************************************/
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_SAVEFILE
save file
@ SUMO_ATTR_DETERMINISTIC
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:49
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
void setDemandElementID(const std::string &newID)
set demand element id
GNEDemandElement(GNENet *net, SumoXMLTag tag)
Constructor for templates.
Problem
enum class for demandElement problems
const GNEHierarchicalContainerChildren< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
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