Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEPlanParents.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// 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
30
31
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) {
53 }
54 if (toStoppingPlace == nullptr) {
56 }
57 // train stops
58 if (fromStoppingPlace == nullptr) {
60 }
61 if (toStoppingPlace == nullptr) {
63 }
64 // container stops
65 if (fromStoppingPlace == nullptr) {
67 }
68 if (toStoppingPlace == nullptr) {
70 }
71 // charging station
72 if (fromStoppingPlace == nullptr) {
74 }
75 if (toStoppingPlace == nullptr) {
77 }
78 // parking area
79 if (fromStoppingPlace == nullptr) {
81 }
82 if (toStoppingPlace == nullptr) {
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
91bool
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
152void
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) {
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) {
177 }
178 if (toStoppingPlace) {
180 }
181 if (fromRoute) {
182 fromRoute->addChildElement(element);
183 }
184 if (toRoute) {
185 toRoute->addChildElement(element);
186 }
187}
188
189
190void
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
206bool
208 if (fromStoppingPlace) {
210 } else {
211 return false;
212 }
213}
214
215
216bool
218 if (toStoppingPlace) {
220 } else {
221 return false;
222 }
223}
224
225
226bool
228 if (fromStoppingPlace) {
230 } else {
231 return false;
232 }
233}
234
235
236bool
238 if (toStoppingPlace) {
240 } else {
241 return false;
242 }
243}
244
245
246bool
248 if (fromStoppingPlace) {
250 } else {
251 return false;
252 }
253}
254
255
256bool
258 if (toStoppingPlace) {
260 } else {
261 return false;
262 }
263}
264
265
266bool
268 if (fromStoppingPlace) {
270 } else {
271 return false;
272 }
273}
274
275
276bool
278 if (toStoppingPlace) {
280 } else {
281 return false;
282 }
283}
284
285
286bool
288 if (fromStoppingPlace) {
290 } else {
291 return false;
292 }
293}
294
295
296bool
298 if (toStoppingPlace) {
300 } else {
301 return false;
302 }
303}
304
305
306std::vector<GNEJunction*>
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
319std::vector<GNEEdge*>
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
336std::vector<GNEAdditional*>
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
355std::vector<GNEDemandElement*>
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/****************************************************************************/
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
#define TLF(string,...)
Definition MsgHandler.h:306
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_TAZ
a traffic assignment zone
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_ROUTE
description of a route
@ SUMO_TAG_TRAIN_STOP
A train stop (alias for bus stop)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
plan parameters (used for group all from-to parameters related with plans)
std::string fromJunction
from junction
std::string fromContainerStop
from containerStop
std::string fromTrainStop
from trainStop
std::string toParkingArea
to parkingArea
std::vector< std::string > consecutiveEdges
consecutive edges
std::string fromChargingStation
from chargingStation
std::string toChargingStation
to chargingStation
std::string fromParkingArea
from parkingArea
std::string toContainerStop
to containerStop
const std::string getID() const
get ID (all Attribute Carriers have one)
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
void addChildElement(ChildType *element)
add child without updating parent (ONLY used if we're creating elements without undo-redo)
struct used for saving all attribute carriers of net, in different formats
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
GNEJunction * retrieveJunction(const std::string &id, bool hardFail=true) const
get junction by id
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
std::vector< GNEDemandElement * > getDemandElements(GNEDemandElement *parent) const
get demand elements (used in plan constructors)
bool checkIntegrity(SumoXMLTag planTag, const GNEDemandElement *parent, const CommonXMLStructure::PlanParameters &planParameters) const
check integrity between planParameters and GNE elements
bool getFromContainerStop() const
get from containerStop
std::vector< GNEEdge * > consecutiveEdges
edges
bool getFromParkingArea() const
get from parkingArea
GNEAdditional * fromTAZ
from TAZ
void clear()
clear elements
GNEJunction * toJunction
to junction
std::vector< GNEAdditional * > getAdditionalElements() const
get additionalElements (used in plan constructors)
GNEEdge * toEdge
to edge
GNEDemandElement * fromRoute
from route (currently only used by walks)
GNEAdditional * toStoppingPlace
to stoppingPlace
GNEEdge * fromEdge
from edge
bool getToParkingArea() const
get to parkingArea
std::vector< GNEEdge * > getEdges() const
get edges (used in plan constructors)
bool getFromTrainStop() const
get from trainStop
bool getFromChargingStation() const
get from chargingStation
bool getToChargingStation() const
get to chargingStation
GNEJunction * fromJunction
from junction
bool getFromBusStop() const
bool getToContainerStop() const
get to containerStop
std::vector< GNEJunction * > getJunctions() const
get junctions (used in plan constructors)
bool getToTrainStop() const
get to trainStop
GNEAdditional * fromStoppingPlace
from stoppingPlace
GNEPlanParents()
default constructor
GNEAdditional * toTAZ
to TAZ
bool getToBusStop() const
get to busStop
void addDemandElementChild(GNEDemandElement *element)
add the given demand element in the element as child
GNEDemandElement * toRoute
to route (currently only used by walks)
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property