Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/demand/GNERouteDistribution.cpp
185790 views
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
/****************************************************************************/
14
/// @file GNERouteDistribution.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jan 2022
17
///
18
// Route distribution used in netedit
19
/****************************************************************************/
20
21
#include <netedit/GNETagProperties.h>
22
#include <netedit/GNENet.h>
23
#include <netedit/changes/GNEChange_Attribute.h>
24
#include <utils/xml/NamespaceIDs.h>
25
26
#include "GNERouteDistribution.h"
27
28
// ===========================================================================
29
// member method definitions
30
// ===========================================================================
31
32
GNERouteDistribution::GNERouteDistribution(GNENet* net) :
33
GNEDemandElement(net, SUMO_TAG_ROUTE_DISTRIBUTION) {
34
}
35
36
37
GNERouteDistribution::GNERouteDistribution(const std::string& ID, GNENet* net, FileBucket* fileBucket) :
38
GNEDemandElement(ID, net, SUMO_TAG_ROUTE_DISTRIBUTION, fileBucket) {
39
}
40
41
42
GNERouteDistribution::~GNERouteDistribution() {}
43
44
45
GNEMoveElement*
46
GNERouteDistribution::getMoveElement() const {
47
return nullptr;
48
}
49
50
51
Parameterised*
52
GNERouteDistribution::getParameters() {
53
return nullptr;
54
}
55
56
57
const Parameterised*
58
GNERouteDistribution::getParameters() const {
59
return nullptr;
60
}
61
62
63
void
64
GNERouteDistribution::writeDemandElement(OutputDevice& device) const {
65
// write attributes
66
device.openTag(getTagProperty()->getTag());
67
device.writeAttr(SUMO_ATTR_ID, getID());
68
// write references
69
for (const auto& refChild : getChildDemandElements()) {
70
if (refChild->getTagProperty()->isDistributionReference()) {
71
if (refChild->getTagProperty()->isDistributionReference() &&
72
(refChild->getParentDemandElements().front() == this)) {
73
refChild->writeDemandElement(device);
74
}
75
}
76
}
77
device.closeTag();
78
}
79
80
81
GNEDemandElement::Problem
82
GNERouteDistribution::isDemandElementValid() const {
83
// currently distributions don't have problems
84
return GNEDemandElement::Problem::OK;
85
}
86
87
88
std::string
89
GNERouteDistribution::getDemandElementProblem() const {
90
return "";
91
}
92
93
94
void
95
GNERouteDistribution::fixDemandElementProblem() {
96
// nothing to fix
97
}
98
99
100
SUMOVehicleClass
101
GNERouteDistribution::getVClass() const {
102
if (getChildDemandElements().size() > 0) {
103
return getChildDemandElements().front()->getVClass();
104
} else {
105
return SVC_IGNORING;
106
}
107
}
108
109
110
const RGBColor&
111
GNERouteDistribution::getColor() const {
112
if (getChildDemandElements().size() > 0) {
113
return getChildDemandElements().front()->getColor();
114
} else {
115
return RGBColor::INVISIBLE;
116
}
117
}
118
119
120
void
121
GNERouteDistribution::updateGeometry() {
122
// update geometries of all vehicles
123
for (auto vehicle : getChildDemandElements()) {
124
if (vehicle->getTagProperty()->isVehicle()) {
125
vehicle->updateGeometry();
126
}
127
}
128
}
129
130
131
Position
132
GNERouteDistribution::getPositionInView() const {
133
if (getChildDemandElements().size() > 0) {
134
return getChildDemandElements().front()->getPositionInView();
135
} else {
136
return Position();
137
}
138
}
139
140
141
std::string
142
GNERouteDistribution::getParentName() const {
143
return myNet->getMicrosimID();
144
}
145
146
147
Boundary
148
GNERouteDistribution::getCenteringBoundary() const {
149
if (getChildDemandElements().size() > 0) {
150
return getChildDemandElements().front()->getCenteringBoundary();
151
} else {
152
return Boundary(-0.1, -0.1, 0.1, 0.1);
153
}
154
}
155
156
157
void
158
GNERouteDistribution::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
159
// geometry of this element cannot be splitted
160
}
161
162
163
void
164
GNERouteDistribution::drawGL(const GUIVisualizationSettings& s) const {
165
// draw all vehicles
166
for (auto vehicle : getChildDemandElements()) {
167
if (vehicle->getTagProperty()->isVehicle()) {
168
vehicle->drawGL(s);
169
}
170
}
171
}
172
173
174
void
175
GNERouteDistribution::computePathElement() {
176
// nothing to compute
177
}
178
179
180
void
181
GNERouteDistribution::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
182
// route distributions don't use drawJunctionPartialGL
183
}
184
185
186
void
187
GNERouteDistribution::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {
188
// route distributions don't use drawJunctionPartialGL
189
}
190
191
192
GNELane*
193
GNERouteDistribution::getFirstPathLane() const {
194
if (getChildDemandElements().size() > 0) {
195
return getChildDemandElements().front()->getFirstPathLane();
196
} else {
197
return nullptr;
198
}
199
}
200
201
202
GNELane*
203
GNERouteDistribution::getLastPathLane() const {
204
if (getChildDemandElements().size() > 0) {
205
return getChildDemandElements().front()->getLastPathLane();
206
} else {
207
return nullptr;
208
}
209
}
210
211
212
std::string
213
GNERouteDistribution::getAttribute(SumoXMLAttr key) const {
214
switch (key) {
215
case SUMO_ATTR_ID:
216
return getMicrosimID();
217
default:
218
return getCommonAttribute(key);
219
}
220
}
221
222
223
double
224
GNERouteDistribution::getAttributeDouble(SumoXMLAttr key) const {
225
return getCommonAttributeDouble(key);
226
}
227
228
229
Position
230
GNERouteDistribution::getAttributePosition(SumoXMLAttr key) const {
231
return getCommonAttributePosition(key);
232
}
233
234
235
void
236
GNERouteDistribution::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
237
if (value == getAttribute(key)) {
238
return; //avoid needless changes, later logic relies on the fact that attributes have changed
239
}
240
switch (key) {
241
case SUMO_ATTR_ID:
242
GNEChange_Attribute::changeAttribute(this, key, value, undoList);
243
break;
244
default:
245
setCommonAttribute(key, value, undoList);
246
break;
247
}
248
}
249
250
251
bool
252
GNERouteDistribution::isValid(SumoXMLAttr key, const std::string& value) {
253
switch (key) {
254
case SUMO_ATTR_ID:
255
return isValidDemandElementID(NamespaceIDs::routes, value);
256
default:
257
return isCommonAttributeValid(key, value);
258
}
259
}
260
261
262
std::string
263
GNERouteDistribution::getPopUpID() const {
264
return getTagStr();
265
}
266
267
268
std::string
269
GNERouteDistribution::getHierarchyName() const {
270
return getTagStr() + ": " + getAttribute(SUMO_ATTR_ID) ;
271
}
272
273
// ===========================================================================
274
// private
275
// ===========================================================================
276
277
void
278
GNERouteDistribution::setAttribute(SumoXMLAttr key, const std::string& value) {
279
switch (key) {
280
case SUMO_ATTR_ID:
281
setDemandElementID(value);
282
break;
283
default:
284
setCommonAttribute(key, value);
285
break;
286
}
287
}
288
289
/****************************************************************************/
290
291