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 // distributions cannot be moved
49 return nullptr;
50}
51
52
53void
55 // now write attributes
56 device.openTag(getTagProperty()->getTag());
57 device.writeAttr(SUMO_ATTR_ID, getID());
60 }
61 // check if write vType or refs)
62 for (const auto& refChild : getChildDemandElements()) {
63 if (refChild->getTagProperty()->getTag() == GNE_TAG_VTYPEREF) {
64 int numReferences = 0;
65 for (const auto& vTypeChild : refChild->getParentDemandElements().at(1)->getChildDemandElements()) {
66 if (vTypeChild->getTagProperty()->getTag() == GNE_TAG_VTYPEREF) {
67 numReferences++;
68 }
69 }
70 if (numReferences == 1) {
71 refChild->getParentDemandElements().at(1)->writeDemandElement(device);
72 } else {
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 for (const auto& childDemandElement : getChildDemandElements()) {
103 if (childDemandElement->getTagProperty()->hasAttribute(SUMO_ATTR_REFID)) {
104 return childDemandElement->getVClass();
105 }
106 }
107 return SVC_IGNORING;
108}
109
110
111const RGBColor&
113 for (const auto& childDemandElement : getChildDemandElements()) {
114 if (childDemandElement->getTagProperty()->hasAttribute(SUMO_ATTR_REFID)) {
115 return childDemandElement->getColor();
116 }
117 }
118 return RGBColor::YELLOW;
119}
120
121
122void
124 // nothing to update
125}
126
127
130 if (getChildDemandElements().size() > 0) {
131 return getChildDemandElements().front()->getPositionInView();
132 } else {
133 return Position();
134 }
135}
136
137
138std::string
142
143
146 if (getChildDemandElements().size() > 0) {
147 return getChildDemandElements().front()->getCenteringBoundary();
148 } else {
149 return Boundary(-0.1, -0.1, 0.1, 0.1);
150 }
151}
152
153
154void
155GNEVTypeDistribution::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
156 // geometry of this element cannot be splitted
157}
158
159
160void
162 // Vehicle Types aren't draw
163}
164
165
166void
168 // nothing to compute
169}
170
171
172void
173GNEVTypeDistribution::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
174 // route distributions don't use drawJunctionPartialGL
175}
176
177
178void
179GNEVTypeDistribution::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
180 // route distributions don't use drawJunctionPartialGL
181}
182
183
184GNELane*
186 return nullptr;
187}
188
189
190GNELane*
192 return nullptr;
193}
194
195
196std::string
198 switch (key) {
199 case SUMO_ATTR_ID:
200 return getMicrosimID();
202 if (myDeterministic == -1) {
203 return "";
204 } else {
206 }
207 default:
208 // check if the given attribute is part of
209 for (const auto& childDemandElement : getChildDemandElements()) {
210 if (childDemandElement->getTagProperty()->hasAttribute(SUMO_ATTR_REFID)) {
211 return childDemandElement->getParentDemandElements().at(1)->getAttribute(key);
212 }
213 }
214 return "";
215 }
216}
217
218
219double
221 // first try to get value from type child
222 for (const auto& childDemandElement : getChildDemandElements()) {
223 if (childDemandElement->getTagProperty()->hasAttribute(SUMO_ATTR_REFID)) {
224 return childDemandElement->getParentDemandElements().at(1)->getAttributeDouble(key);
225 }
226 }
227 // special cases for vehicles
228 switch (key) {
229 case SUMO_ATTR_WIDTH:
230 return 1;
231 case SUMO_ATTR_LENGTH:
232 return 3;
233 default:
234 return 0;
235 }
236}
237
238
241 for (const auto& childDemandElement : getChildDemandElements()) {
242 if (childDemandElement->getTagProperty()->hasAttribute(SUMO_ATTR_REFID)) {
243 return childDemandElement->getAttributePosition(key);
244 }
245 }
246 return Position();
247}
248
249
250void
251GNEVTypeDistribution::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
252 if (value == getAttribute(key)) {
253 return; //avoid needless changes, later logic relies on the fact that attributes have changed
254 }
255 switch (key) {
256 case SUMO_ATTR_ID:
258 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
259 break;
260 default:
261 setCommonAttribute(key, value, undoList);
262 break;
263 }
264}
265
266
267bool
268GNEVTypeDistribution::isValid(SumoXMLAttr key, const std::string& value) {
269 switch (key) {
270 case SUMO_ATTR_ID:
273 if ((value == "-1") || value.empty()) {
274 return true;
275 } else {
276 return canParse<int>(value) && (parse<int>(value) >= 0);
277 }
278 default:
279 return isCommonValid(key, value);
280 }
281}
282
283
284std::string
286 return getTagStr();
287}
288
289
290std::string
294
295
298 throw InvalidArgument(getTagStr() + " doesn't have parameters");
299}
300
301// ===========================================================================
302// private
303// ===========================================================================
304
305void
306GNEVTypeDistribution::setAttribute(SumoXMLAttr key, const std::string& value) {
307 switch (key) {
308 case SUMO_ATTR_ID:
309 setDemandElementID(value);
310 break;
312 if (value.empty()) {
313 myDeterministic = -1;
314 } else {
315 myDeterministic = parse<int>(value);
316 }
317 break;
318 default:
319 setCommonAttribute(this, key, value);
320 break;
321 }
322}
323
324
325void
327 // distributions cannot be moved
328}
329
330
331void
333 // distributions cannot be moved
334}
335
336/****************************************************************************/
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
@ GNE_TAG_VTYPEREF
reference to a vType (used in VType distributions)
@ SUMO_TAG_VTYPE_DISTRIBUTION
distribution of a vehicle type
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_REFID
@ SUMO_ATTR_DETERMINISTIC
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_ID
@ SUMO_ATTR_WIDTH
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)
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
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
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
int getDefaultIntValue(SumoXMLAttr attr) const
get default int value
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 written 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
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over junction.
double getAttributeDouble(SumoXMLAttr key) const
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over lane.
int myDeterministic
deterministic distribution
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
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.
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.
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 YELLOW
Definition RGBColor.h:191