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 GNEPathElement::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 GNEPathElement::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 GNESegment* /*segment*/, const double /*offsetFront*/) const {
147 // route distributions don't use drawJunctionPartialGL
148}
149
150
151void
152GNEDistribution::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*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 return getCommonAttribute(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 setCommonAttribute(key, value, undoList);
233 break;
234 }
235}
236
237
238bool
239GNEDistribution::isValid(SumoXMLAttr key, const std::string& value) {
240 switch (key) {
241 case SUMO_ATTR_ID:
244 if ((value == "-1") || value.empty()) {
245 return true;
246 } else {
247 return canParse<int>(value) && (parse<int>(value) >= 0);
248 }
249 default:
250 return isCommonValid(key, value);
251 }
252}
253
254
255std::string
257 return getTagStr();
258}
259
260
261std::string
265
266
269 throw InvalidArgument(getTagStr() + " doesn't have parameters");
270}
271
272// ===========================================================================
273// private
274// ===========================================================================
275
276void
277GNEDistribution::setAttribute(SumoXMLAttr key, const std::string& value) {
278 switch (key) {
279 case SUMO_ATTR_ID:
280 setDemandElementID(value);
281 break;
283 if (value.empty()) {
284 myDeterministic = -1;
285 } else {
286 myDeterministic = parse<int>(value);
287 }
288 break;
289 default:
290 setCommonAttribute(key, value);
291 break;
292 }
293}
294
295
296void
298 // distributions cannot be moved
299}
300
301
302void
303GNEDistribution::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
304 // distributions cannot be moved
305}
306
307/****************************************************************************/
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
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
bool isCommonValid(SumoXMLAttr key, const std::string &value)
GNENet * myNet
pointer to net
std::string getCommonAttribute(SumoXMLAttr key) 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
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
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