Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEDistribution.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// abstract distribution used in netedit
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
24
25#include "GNEDistribution.h"
26
27// ===========================================================================
28// member method definitions
29// ===========================================================================
30
32 GNEDemandElement("", net, "", type, elementTag, GNEPathElement::Options::DEMAND_ELEMENT) {
33}
34
35
36GNEDistribution::GNEDistribution(const std::string& ID, GNENet* net, const std::string& filename, GUIGlObjectType type, SumoXMLTag elementTag,
37 const int deterministic) :
38 GNEDemandElement(ID, net, filename, type, elementTag, GNEPathElement::Options::DEMAND_ELEMENT),
39 myDeterministic(deterministic) {
40}
41
42
44
45
48 // distributions cannot be moved
49 return nullptr;
50}
51
52
55 // currently distributions don't have problems
57}
58
59
60std::string
62 return "";
63}
64
65
66void
68 // nothing to fix
69}
70
71
74 if (getDistributionKeyValues().size() > 0) {
75 return getDistributionKeyValues().begin()->first->getVClass();
76 } else {
77 return SVC_IGNORING;
78 }
79}
80
81
82const RGBColor&
84 if (getDistributionKeyValues().size() > 0) {
85 return getDistributionKeyValues().begin()->first->getColor();
86 } else {
87 return RGBColor::BLACK;
88 }
89}
90
91
92void
94 // nothing to update
95}
96
97
100 if (getDistributionKeyValues().size() > 0) {
101 return getDistributionKeyValues().begin()->first->getPositionInView();
102 } else {
103 return Position();
104 }
105}
106
107
108std::string
112
113
116 if (getDistributionKeyValues().size() > 0) {
117 return getDistributionKeyValues().begin()->first->getCenteringBoundary();
118 } else {
119 return Boundary(-0.1, -0.1, 0.1, 0.1);
120 }
121}
122
123
124void
125GNEDistribution::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
126 // geometry of this element cannot be splitted
127}
128
129
130void
132 // Vehicle Types aren't draw
133}
134
135
136void
138 // nothing to compute
139}
140
141
142void
143GNEDistribution::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
144 // route distributions don't use drawJunctionPartialGL
145}
146
147
148void
149GNEDistribution::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
150 // route distributions don't use drawJunctionPartialGL
151}
152
153
154GNELane*
156 if (getDistributionKeyValues().size() > 0) {
157 return getDistributionKeyValues().begin()->first->getFirstPathLane();
158 } else {
159 return nullptr;
160 }
161}
162
163
164GNELane*
166 if (getDistributionKeyValues().size() > 0) {
167 return getDistributionKeyValues().begin()->first->getLastPathLane();
168 } else {
169 return nullptr;
170 }
171}
172
173
174std::string
176 switch (key) {
177 case SUMO_ATTR_ID:
178 return getMicrosimID();
180 if (myDeterministic == -1) {
181 return "";
182 } else {
184 }
185 default:
186 return getCommonAttribute(this, key);
187 }
188}
189
190
191double
193 switch (key) {
195 // count number of additional placed in distribution keys (needed for save distribution either in route or in additional file)
196 double counter = 0;
197 for (const auto& distributionKey : getDistributionKeyValues()) {
198 counter += (double)distributionKey.first->getChildAdditionals().size();
199 }
200 return counter;
201 }
202 default:
203 if (getDistributionKeyValues().size() > 0) {
204 return getDistributionKeyValues().begin()->first->getAttributeDouble(key);
205 } else {
206 return 0;
207 }
208 }
209}
210
211
214 throw InvalidArgument(getTagStr() + " doesn't have a Position attribute of type '" + toString(key) + "'");
215}
216
217
218void
219GNEDistribution::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
220 if (value == getAttribute(key)) {
221 return; //avoid needless changes, later logic relies on the fact that attributes have changed
222 }
223 switch (key) {
224 case SUMO_ATTR_ID:
226 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
227 break;
228 default:
229 setCommonAttribute(key, value, undoList);
230 break;
231 }
232}
233
234
235bool
236GNEDistribution::isValid(SumoXMLAttr key, const std::string& value) {
237 switch (key) {
238 case SUMO_ATTR_ID:
241 if ((value == "-1") || value.empty()) {
242 return true;
243 } else {
244 return canParse<int>(value) && (parse<int>(value) >= 0);
245 }
246 default:
247 return isCommonValid(key, value);
248 }
249}
250
251
252std::string
254 return getTagStr();
255}
256
257
258std::string
262
263
266 throw InvalidArgument(getTagStr() + " doesn't have parameters");
267}
268
269// ===========================================================================
270// private
271// ===========================================================================
272
273void
274GNEDistribution::setAttribute(SumoXMLAttr key, const std::string& value) {
275 switch (key) {
276 case SUMO_ATTR_ID:
277 setDemandElementID(value);
278 break;
280 if (value.empty()) {
281 myDeterministic = -1;
282 } else {
283 myDeterministic = parse<int>(value);
284 }
285 break;
286 default:
287 setCommonAttribute(this, key, value);
288 break;
289 }
290}
291
292
293void
295 // distributions cannot be moved
296}
297
298
299void
300GNEDistribution::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
301 // distributions cannot be moved
302}
303
304/****************************************************************************/
GUIGlObjectType
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
SumoXMLTag
Numbers representing SUMO-XML - element names.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_ADDITIONALCHILDREN
check number of additional children (used in vTypeDistribution)
@ 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
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
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
const std::map< const GNEDemandElement *, double > & getDistributionKeyValues() const
get map with distribution keys and values
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
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
GNEMoveOperation * getMoveOperation()
get move operation
void computePathElement()
compute pathElement
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
Position getPositionInView() const
Returns position of additional in view.
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void fixDemandElementProblem()
fix demand element problem
double getAttributeDouble(SumoXMLAttr key) const
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over junction.
GNELane * getFirstPathLane() const
get first path lane
Position getAttributePosition(SumoXMLAttr key) const
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform demand element changes
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
~GNEDistribution()
destructor
const RGBColor & getColor() const
get color
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
GNEDistribution(GNENet *net, GUIGlObjectType type, SumoXMLTag elementTag)
default constructor
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNESegment *segment, const double offsetFront) const
Draws partial object over lane.
int myDeterministic
deterministic attribute
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
GNELane * getLastPathLane() const
get last path lane
std::string getParentName() const
Returns the name of the parent object.
void updateGeometry()
update pre-computed geometry information
Problem isDemandElementValid() const
check if current demand element is valid to be written into XML
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
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
std::string getDemandElementProblem() const
return a string with the current demand element problem
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
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
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 BLACK
Definition RGBColor.h:196