Eclipse SUMO - Simulation of Urban MObility
GNEVTypeDistribution.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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#include <netedit/GNENet.h>
21#include <netedit/GNEUndoList.h>
23
25
26
27// ===========================================================================
28// member method definitions
29// ===========================================================================
30
33 GNEPathManager::PathElement::Options::DEMAND_ELEMENT, {}, {}, {}, {}, {}, {}) {
34 // reset default values
35 resetDefaultValues();
36}
37
38
39GNEVTypeDistribution::GNEVTypeDistribution(GNENet* net, const std::string& vTypeID, const int deterministic) :
41 GNEPathManager::PathElement::Options::DEMAND_ELEMENT, {}, {}, {}, {}, {}, {}),
42myDeterministic(deterministic) {
43}
44
45
47
48
51 return nullptr;
52}
53
54
55void
57 device.openTag(getTagProperty().getTag());
58 device.writeAttr(SUMO_ATTR_ID, getID());
59 // write all vTypes
60 for (const auto& vType : getChildDemandElements()) {
61 vType->writeDemandElement(device);
62 }
63 device.closeTag();
64}
65
66
69 // currently vTypeDistributions don't have problems
71}
72
73
74std::string
76 return "";
77}
78
79
80void
82 // nothing to fix
83}
84
85
88 return SVC_IGNORING;
89}
90
91
92const RGBColor&
94 return RGBColor::BLACK;
95}
96
97
98void
100 // nothing to update
101}
102
103
106 return Position();
107}
108
109
110std::string
112 return myNet->getMicrosimID();
113}
114
115
116double
118 return 1;
119}
120
121
124 // VehicleType distribution doesn't have boundaries
125 return Boundary(-0.1, -0.1, 0.1, 0.1);
126}
127
128
129void
130GNEVTypeDistribution::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
131 // geometry of this element cannot be splitted
132}
133
134
135void
137 // Vehicle Types aren't draw
138}
139
140
141void
143 // nothing to compute
144}
145
146
147void
148GNEVTypeDistribution::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*lane*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
149 // vehicleType distributions don't use drawPartialGL
150}
151
152
153void
154GNEVTypeDistribution::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*fromLane*/, const GNELane* /*toLane*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
155 // vehicleType distributions don't use drawPartialGL
156}
157
158
159GNELane*
161 // vehicle types don't use lanes
162 return nullptr;
163}
164
165
166GNELane*
168 // vehicle types don't use lanes
169 return nullptr;
170}
171
172
173std::string
175 switch (key) {
176 case SUMO_ATTR_ID:
177 return getMicrosimID();
179 if (myDeterministic == -1) {
180 return "";
181 } else {
183 }
184 default:
185 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
186 }
187}
188
189
190double
192 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
193}
194
195
198 throw InvalidArgument(getTagStr() + " doesn't have a Position attribute of type '" + toString(key) + "'");
199}
200
201
202void
203GNEVTypeDistribution::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
204 if (value == getAttribute(key)) {
205 return; //avoid needless changes, later logic relies on the fact that attributes have changed
206 }
207 switch (key) {
208 case SUMO_ATTR_ID:
210 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
211 break;
212 default:
213 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
214 }
215}
216
217
218bool
219GNEVTypeDistribution::isValid(SumoXMLAttr key, const std::string& value) {
220 switch (key) {
221 case SUMO_ATTR_ID:
222 // Vtypes and PTypes shares namespace
224 return true;
225 } else {
226 return false;
227 }
229 if (value == "-1" || value.empty()) {
230 return true;
231 } else {
232 return canParse<int>(value) && (parse<int>(value) >= 0);
233 }
234 default:
235 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
236 }
237}
238
239
240std::string
242 return getTagStr();
243}
244
245
246std::string
248 return getTagStr() + ": " + getAttribute(SUMO_ATTR_ID) ;
249}
250
251
254 throw InvalidArgument(getTagStr() + " doesn't have parameters");
255}
256
257// ===========================================================================
258// private
259// ===========================================================================
260
261void
262GNEVTypeDistribution::setAttribute(SumoXMLAttr key, const std::string& value) {
263 switch (key) {
264 case SUMO_ATTR_ID:
265 setMicrosimID(value);
266 break;
268 if (value.empty()) {
269 myDeterministic = -1;
270 } else {
271 myDeterministic = parse<int>(value);
272 }
273 break;
274 default:
275 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
276 }
277}
278
279
280void
282 // vehicleType distributions cannot be moved
283}
284
285
286void
288 // vehicleType distributions cannot be moved
289}
290
291/****************************************************************************/
@ GLO_VTYPE
@bief vTypes
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ VTYPEDISTRIBUTION
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_VTYPE_DISTRIBUTION
distribution of a vehicle type
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ 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
get ID (all Attribute Carriers have one)
friend class GNEChange_Attribute
declare friend class
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
An Element which don't belong to GNENet but has influence in the simulation.
Problem
enum class for demandElement problems
const std::vector< 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
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:132
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
void drawPartialGL(const GUIVisualizationSettings &s, const GNELane *lane, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object.
std::string getParentName() const
Returns the name of the parent object.
void computePathElement()
compute pathElement
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform demand element changes
Problem isDemandElementValid() const
check if current demand element is valid to be writed into XML
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
GNELane * getFirstPathLane() const
get first path lane
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Position getPositionInView() const
Returns position of additional in view.
void updateGeometry()
update pre-computed geometry information
GNEVTypeDistribution(GNENet *net)
default constructor
const RGBColor & getColor() const
get color
double getAttributeDouble(SumoXMLAttr key) const
int myDeterministic
deterministic attribute
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
SUMOVehicleClass getVClass() const
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
const Parameterised::Map & getACParametersMap() const
get parameters map
GNELane * getLastPathLane() const
get last path lane
Position getAttributePosition(SumoXMLAttr key) const
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GNEMoveOperation * getMoveOperation()
get move operation
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void fixDemandElementProblem()
fix demand element problem
std::string getDemandElementProblem() const
return a string with the current demand element problem
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:141
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
Stores the information about how to visualize structures.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
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
Definition: Parameterised.h:45
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
static const RGBColor BLACK
Definition: RGBColor.h:193
static bool isValidVehicleID(const std::string &value)
whether the given string is a valid id for a vehicle or flow