Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/demand/GNEPlanParents.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 GNEPlanParents.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Aug 2024
17
///
18
// Builds demand objects for netedit
19
/****************************************************************************/
20
21
#include <netedit/GNENet.h>
22
23
#include "GNEPlanParents.h"
24
25
// ===========================================================================
26
// member method definitions
27
// ===========================================================================
28
29
GNEPlanParents::GNEPlanParents() {}
30
31
32
GNEPlanParents::GNEPlanParents(const CommonXMLStructure::PlanParameters& planParameters,
33
const GNENetHelper::AttributeCarriers* ACs) {
34
// edges
35
fromEdge = ACs->retrieveEdge(planParameters.fromEdge, false);
36
toEdge = ACs->retrieveEdge(planParameters.toEdge, false);
37
for (const auto& edgeID : planParameters.consecutiveEdges) {
38
auto parsedEdge = ACs->retrieveEdge(edgeID, false);
39
// avoid null and consecutive dulicated edges
40
if (parsedEdge && (consecutiveEdges.empty() || (consecutiveEdges.back() != parsedEdge))) {
41
consecutiveEdges.push_back(parsedEdge);
42
}
43
}
44
// junctions
45
fromJunction = ACs->retrieveJunction(planParameters.fromJunction, false);
46
toJunction = ACs->retrieveJunction(planParameters.toJunction, false);
47
// TAZs
48
fromTAZ = ACs->retrieveAdditional(SUMO_TAG_TAZ, planParameters.fromTAZ, false);
49
toTAZ = ACs->retrieveAdditional(SUMO_TAG_TAZ, planParameters.toTAZ, false);
50
// bus stops
51
if (fromStoppingPlace == nullptr) {
52
fromStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_BUS_STOP, planParameters.fromBusStop, false);
53
}
54
if (toStoppingPlace == nullptr) {
55
toStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_BUS_STOP, planParameters.toBusStop, false);
56
}
57
// train stops
58
if (fromStoppingPlace == nullptr) {
59
fromStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_TRAIN_STOP, planParameters.fromTrainStop, false);
60
}
61
if (toStoppingPlace == nullptr) {
62
toStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_TRAIN_STOP, planParameters.toTrainStop, false);
63
}
64
// container stops
65
if (fromStoppingPlace == nullptr) {
66
fromStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_CONTAINER_STOP, planParameters.fromContainerStop, false);
67
}
68
if (toStoppingPlace == nullptr) {
69
toStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_CONTAINER_STOP, planParameters.toContainerStop, false);
70
}
71
// charging station
72
if (fromStoppingPlace == nullptr) {
73
fromStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_CHARGING_STATION, planParameters.fromChargingStation, false);
74
}
75
if (toStoppingPlace == nullptr) {
76
toStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_CHARGING_STATION, planParameters.toChargingStation, false);
77
}
78
// parking area
79
if (fromStoppingPlace == nullptr) {
80
fromStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_PARKING_AREA, planParameters.fromParkingArea, false);
81
}
82
if (toStoppingPlace == nullptr) {
83
toStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_PARKING_AREA, planParameters.toParkingArea, false);
84
}
85
// routes
86
fromRoute = ACs->retrieveDemandElement(SUMO_TAG_ROUTE, planParameters.fromRoute, false);
87
toRoute = ACs->retrieveDemandElement(SUMO_TAG_ROUTE, planParameters.toRoute, false);
88
}
89
90
91
bool
92
GNEPlanParents::checkIntegrity(SumoXMLTag planTag, const GNEDemandElement* parent, const CommonXMLStructure::PlanParameters& planParameters) const {
93
if (!planParameters.fromEdge.empty() && !fromEdge) {
94
WRITE_WARNING(TLF("Invalid from edge '%' used in % of % '%'", planParameters.fromEdge, toString(planTag), parent->getTagStr(), parent->getID()));
95
return false;
96
} else if (!planParameters.toEdge.empty() && !toEdge) {
97
WRITE_WARNING(TLF("Invalid to edge '%' used in % of % '%'", planParameters.toEdge, toString(planTag), parent->getTagStr(), parent->getID()));
98
return false;
99
} else if (!planParameters.fromJunction.empty() && !fromJunction) {
100
WRITE_WARNING(TLF("Invalid from junction '%' used in % of % '%'", planParameters.fromJunction, toString(planTag), parent->getTagStr(), parent->getID()));
101
return false;
102
} else if (!planParameters.toJunction.empty() && !toJunction) {
103
WRITE_WARNING(TLF("Invalid to junction '%' used in % of % '%'", planParameters.toJunction, toString(planTag), parent->getTagStr(), parent->getID()));
104
return false;
105
} else if (!planParameters.fromTAZ.empty() && !fromTAZ) {
106
WRITE_WARNING(TLF("Invalid from TAZ '%' used in % of % '%'", planParameters.fromTAZ, toString(planTag), parent->getTagStr(), parent->getID()));
107
return false;
108
} else if (!planParameters.toTAZ.empty() && !toTAZ) {
109
WRITE_WARNING(TLF("Invalid to TAZ '%' used in % of % '%'", planParameters.toTAZ, toString(planTag), parent->getTagStr(), parent->getID()));
110
return false;
111
} else if (!planParameters.fromBusStop.empty() && !fromStoppingPlace) {
112
WRITE_WARNING(TLF("Invalid from bus stop '%' used in % of % '%'", planParameters.fromBusStop, toString(planTag), parent->getTagStr(), parent->getID()));
113
return false;
114
} else if (!planParameters.fromTrainStop.empty() && !fromStoppingPlace) {
115
WRITE_WARNING(TLF("Invalid from train stop '%' used in % of % '%'", planParameters.fromTrainStop, toString(planTag), parent->getTagStr(), parent->getID()));
116
return false;
117
} else if (!planParameters.fromContainerStop.empty() && !fromStoppingPlace) {
118
WRITE_WARNING(TLF("Invalid from container stop '%' used in % of % '%'", planParameters.fromContainerStop, toString(planTag), parent->getTagStr(), parent->getID()));
119
return false;
120
} else if (!planParameters.fromChargingStation.empty() && !fromStoppingPlace) {
121
WRITE_WARNING(TLF("Invalid from charging station '%' used in % of % '%'", planParameters.fromChargingStation, toString(planTag), parent->getTagStr(), parent->getID()));
122
return false;
123
} else if (!planParameters.fromParkingArea.empty() && !fromStoppingPlace) {
124
WRITE_WARNING(TLF("Invalid from parking area '%' used in % of % '%'", planParameters.fromParkingArea, toString(planTag), parent->getTagStr(), parent->getID()));
125
return false;
126
} else if (!planParameters.toBusStop.empty() && !toStoppingPlace) {
127
WRITE_WARNING(TLF("Invalid to bus stop '%' used in % of % '%'", planParameters.toBusStop, toString(planTag), parent->getTagStr(), parent->getID()));
128
return false;
129
} else if (!planParameters.toTrainStop.empty() && !toStoppingPlace) {
130
WRITE_WARNING(TLF("Invalid to train stop '%' used in % of % '%'", planParameters.toTrainStop, toString(planTag), parent->getTagStr(), parent->getID()));
131
return false;
132
} else if (!planParameters.toContainerStop.empty() && !toStoppingPlace) {
133
WRITE_WARNING(TLF("Invalid to container stop '%' used in % of % '%'", planParameters.toContainerStop, toString(planTag), parent->getTagStr(), parent->getID()));
134
return false;
135
} else if (!planParameters.toChargingStation.empty() && !toStoppingPlace) {
136
WRITE_WARNING(TLF("Invalid to charging station '%' used in % of % '%'", planParameters.toChargingStation, toString(planTag), parent->getTagStr(), parent->getID()));
137
return false;
138
} else if (!planParameters.toParkingArea.empty() && !toStoppingPlace) {
139
WRITE_WARNING(TLF("Invalid to parking area '%' used in % of % '%'", planParameters.toParkingArea, toString(planTag), parent->getTagStr(), parent->getID()));
140
return false;
141
} else if (!planParameters.fromRoute.empty() && !fromRoute) {
142
WRITE_WARNING(TLF("Invalid from route '%' used in % of % '%'", planParameters.fromRoute, toString(planTag), parent->getTagStr(), parent->getID()));
143
return false;
144
} else if (!planParameters.toRoute.empty() && !toRoute) {
145
WRITE_WARNING(TLF("Invalid to route '%' used in % of % '%'", planParameters.toRoute, toString(planTag), parent->getTagStr(), parent->getID()));
146
return false;
147
} else {
148
return true;
149
}
150
}
151
152
void
153
GNEPlanParents::addDemandElementChild(GNEDemandElement* element) {
154
if (fromEdge) {
155
fromEdge->addChildElement(element);
156
}
157
if (toEdge) {
158
toEdge->addChildElement(element);
159
}
160
for (const auto& consecutiveEdge : consecutiveEdges) {
161
consecutiveEdge->addChildElement(element);
162
}
163
if (fromJunction) {
164
fromJunction->addChildElement(element);
165
}
166
if (toJunction) {
167
toJunction->addChildElement(element);
168
}
169
if (fromTAZ) {
170
fromTAZ->addChildElement(element);
171
}
172
if (toTAZ) {
173
toTAZ->addChildElement(element);
174
}
175
if (fromStoppingPlace) {
176
fromStoppingPlace->addChildElement(element);
177
}
178
if (toStoppingPlace) {
179
toStoppingPlace->addChildElement(element);
180
}
181
if (fromRoute) {
182
fromRoute->addChildElement(element);
183
}
184
if (toRoute) {
185
toRoute->addChildElement(element);
186
}
187
}
188
189
190
void
191
GNEPlanParents::clear() {
192
fromEdge = nullptr;
193
toEdge = nullptr;
194
consecutiveEdges.clear();
195
fromJunction = nullptr;
196
toJunction = nullptr;
197
fromTAZ = nullptr;
198
toTAZ = nullptr;
199
fromStoppingPlace = nullptr;
200
toStoppingPlace = nullptr;
201
fromRoute = nullptr;
202
toRoute = nullptr;
203
}
204
205
206
bool
207
GNEPlanParents::getFromBusStop() const {
208
if (fromStoppingPlace) {
209
return (fromStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_BUS_STOP);
210
} else {
211
return false;
212
}
213
}
214
215
216
bool
217
GNEPlanParents::getToBusStop() const {
218
if (toStoppingPlace) {
219
return (toStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_BUS_STOP);
220
} else {
221
return false;
222
}
223
}
224
225
226
bool
227
GNEPlanParents::getFromTrainStop() const {
228
if (fromStoppingPlace) {
229
return (fromStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_TRAIN_STOP);
230
} else {
231
return false;
232
}
233
}
234
235
236
bool
237
GNEPlanParents::getToTrainStop() const {
238
if (toStoppingPlace) {
239
return (toStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_TRAIN_STOP);
240
} else {
241
return false;
242
}
243
}
244
245
246
bool
247
GNEPlanParents::getFromContainerStop() const {
248
if (fromStoppingPlace) {
249
return (fromStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_CONTAINER_STOP);
250
} else {
251
return false;
252
}
253
}
254
255
256
bool
257
GNEPlanParents::getToContainerStop() const {
258
if (toStoppingPlace) {
259
return (toStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_CONTAINER_STOP);
260
} else {
261
return false;
262
}
263
}
264
265
266
bool
267
GNEPlanParents::getFromChargingStation() const {
268
if (fromStoppingPlace) {
269
return (fromStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_CHARGING_STATION);
270
} else {
271
return false;
272
}
273
}
274
275
276
bool
277
GNEPlanParents::getToChargingStation() const {
278
if (toStoppingPlace) {
279
return (toStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_CHARGING_STATION);
280
} else {
281
return false;
282
}
283
}
284
285
286
bool
287
GNEPlanParents::getFromParkingArea() const {
288
if (fromStoppingPlace) {
289
return (fromStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_PARKING_AREA);
290
} else {
291
return false;
292
}
293
}
294
295
296
bool
297
GNEPlanParents::getToParkingArea() const {
298
if (toStoppingPlace) {
299
return (toStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_PARKING_AREA);
300
} else {
301
return false;
302
}
303
}
304
305
306
std::vector<GNEJunction*>
307
GNEPlanParents::getJunctions() const {
308
std::vector<GNEJunction*> junctions;
309
if (fromJunction) {
310
junctions.push_back(fromJunction);
311
}
312
if (toJunction) {
313
junctions.push_back(toJunction);
314
}
315
return junctions;
316
}
317
318
319
std::vector<GNEEdge*>
320
GNEPlanParents::getEdges() const {
321
if (consecutiveEdges.size() > 0) {
322
return consecutiveEdges;
323
} else {
324
std::vector<GNEEdge*> edges;
325
if (fromEdge) {
326
edges.push_back(fromEdge);
327
}
328
if (toEdge) {
329
edges.push_back(toEdge);
330
}
331
return edges;
332
}
333
}
334
335
336
std::vector<GNEAdditional*>
337
GNEPlanParents::getAdditionalElements() const {
338
std::vector<GNEAdditional*> additionals;
339
if (fromStoppingPlace) {
340
additionals.push_back(fromStoppingPlace);
341
}
342
if (toStoppingPlace) {
343
additionals.push_back(toStoppingPlace);
344
}
345
if (fromTAZ) {
346
additionals.push_back(fromTAZ);
347
}
348
if (toTAZ) {
349
additionals.push_back(toTAZ);
350
}
351
return additionals;
352
}
353
354
355
std::vector<GNEDemandElement*>
356
GNEPlanParents::getDemandElements(GNEDemandElement* parent) const {
357
std::vector<GNEDemandElement*> demandElements;
358
// always add parent first
359
demandElements.push_back(parent);
360
if (fromRoute) {
361
demandElements.push_back(fromRoute);
362
}
363
if (toRoute) {
364
demandElements.push_back(toRoute);
365
}
366
return demandElements;
367
}
368
369
/****************************************************************************/
370
371