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-2024 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#include <netedit/GNENet.h>
23
24#include "GNEDistribution.h"
25
26// ===========================================================================
27// member method definitions
28// ===========================================================================
29
31 GNEDemandElement("", net, type, elementTag, GUIIconSubSys::getIcon(icon),
32 GNEPathManager::PathElement::Options::DEMAND_ELEMENT, {}, {}, {}, {}, {}, {}) {
33 // reset default values
34 resetDefaultValues();
35}
36
37
39 const std::string& ID, const int deterministic) :
40 GNEDemandElement(ID, net, type, elementTag, GUIIconSubSys::getIcon(icon),
41 GNEPathManager::PathElement::Options::DEMAND_ELEMENT, {}, {}, {}, {}, {}, {}),
42myDeterministic(deterministic) {
43}
44
45
47
48
51 // distributions cannot be moved
52 return nullptr;
53}
54
55
58 // currently distributions don't have problems
60}
61
62
63std::string
65 return "";
66}
67
68
69void
71 // nothing to fix
72}
73
74
77 if (getDistributionKeyValues().size() > 0) {
78 return getDistributionKeyValues().begin()->first->getVClass();
79 } else {
80 return SVC_IGNORING;
81 }
82}
83
84
85const RGBColor&
87 if (getDistributionKeyValues().size() > 0) {
88 return getDistributionKeyValues().begin()->first->getColor();
89 } else {
90 return RGBColor::BLACK;
91 }
92}
93
94
95void
97 // nothing to update
98}
99
100
103 if (getDistributionKeyValues().size() > 0) {
104 return getDistributionKeyValues().begin()->first->getPositionInView();
105 } else {
106 return Position();
107 }
108}
109
110
111std::string
115
116
119 if (getDistributionKeyValues().size() > 0) {
120 return getDistributionKeyValues().begin()->first->getCenteringBoundary();
121 } else {
122 return Boundary(-0.1, -0.1, 0.1, 0.1);
123 }
124}
125
126
127void
128GNEDistribution::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
129 // geometry of this element cannot be splitted
130}
131
132
133void
135 // Vehicle Types aren't draw
136}
137
138
139void
141 // nothing to compute
142}
143
144
145void
146GNEDistribution::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
147 // route distributions don't use drawJunctionPartialGL
148}
149
150
151void
152GNEDistribution::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
153 // route distributions don't use drawJunctionPartialGL
154}
155
156
157GNELane*
159 if (getDistributionKeyValues().size() > 0) {
160 return getDistributionKeyValues().begin()->first->getFirstPathLane();
161 } else {
162 return nullptr;
163 }
164}
165
166
167GNELane*
169 if (getDistributionKeyValues().size() > 0) {
170 return getDistributionKeyValues().begin()->first->getLastPathLane();
171 } else {
172 return nullptr;
173 }
174}
175
176
177std::string
179 switch (key) {
180 case SUMO_ATTR_ID:
181 return getMicrosimID();
183 if (myDeterministic == -1) {
184 return "";
185 } else {
187 }
188 default:
189 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
190 }
191}
192
193
194double
196 switch (key) {
198 // count number of additional placed in distribution keys (needed for save distribution either in route or in additional file)
199 double counter = 0;
200 for (const auto& distributionKey : getDistributionKeyValues()) {
201 counter += (double)distributionKey.first->getChildAdditionals().size();
202 }
203 return counter;
204 }
205 default:
206 if (getDistributionKeyValues().size() > 0) {
207 return getDistributionKeyValues().begin()->first->getAttributeDouble(key);
208 } else {
209 return 0;
210 }
211 }
212}
213
214
217 throw InvalidArgument(getTagStr() + " doesn't have a Position attribute of type '" + toString(key) + "'");
218}
219
220
221void
222GNEDistribution::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
223 if (value == getAttribute(key)) {
224 return; //avoid needless changes, later logic relies on the fact that attributes have changed
225 }
226 switch (key) {
227 case SUMO_ATTR_ID:
229 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
230 break;
231 default:
232 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
233 }
234}
235
236
237bool
238GNEDistribution::isValid(SumoXMLAttr key, const std::string& value) {
239 switch (key) {
240 case SUMO_ATTR_ID:
243 if ((value == "-1") || value.empty()) {
244 return true;
245 } else {
246 return canParse<int>(value) && (parse<int>(value) >= 0);
247 }
248 default:
249 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
250 }
251}
252
253
254std::string
256 return getTagStr();
257}
258
259
260std::string
264
265
268 throw InvalidArgument(getTagStr() + " doesn't have parameters");
269}
270
271// ===========================================================================
272// private
273// ===========================================================================
274
275void
276GNEDistribution::setAttribute(SumoXMLAttr key, const std::string& value) {
277 switch (key) {
278 case SUMO_ATTR_ID:
279 setDemandElementID(value);
280 break;
282 if (value.empty()) {
283 myDeterministic = -1;
284 } else {
285 myDeterministic = parse<int>(value);
286 }
287 break;
288 default:
289 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
290 }
291}
292
293
294void
296 // distributions cannot be moved
297}
298
299
300void
301GNEDistribution::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
302 // distributions cannot be moved
303}
304
305/****************************************************************************/
GUIGlObjectType
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
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
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
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
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.
void drawLanePartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over lane.
~GNEDistribution()
destructor
const RGBColor & getColor() const
get color
SUMOVehicleClass getVClass() const
obtain VClass related with this demand element
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
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.
void drawJunctionPartialGL(const GUIVisualizationSettings &s, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object over junction.
const Parameterised::Map & getACParametersMap() const
get parameters map
std::string getDemandElementProblem() const
return a string with the current demand element problem
GNEDistribution(GNENet *net, GUIGlObjectType type, SumoXMLTag elementTag, GUIIcon icon)
default constructor
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:193