Eclipse SUMO - Simulation of Urban MObility
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-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 // Builds demand objects for netedit
19 /****************************************************************************/
20 #include <netedit/GNENet.h>
21 #include <netedit/GNEUndoList.h>
22 #include <netedit/GNEViewNet.h>
23 #include <netedit/GNEViewParent.h>
29 
30 #include "GNEContainer.h"
31 #include "GNEPerson.h"
32 #include "GNEPersonTrip.h"
33 #include "GNERide.h"
34 #include "GNERoute.h"
35 #include "GNERouteDistribution.h"
36 #include "GNEPlanParents.h"
37 #include "GNEStop.h"
38 #include "GNETranship.h"
39 #include "GNETransport.h"
40 #include "GNEVehicle.h"
41 #include "GNEVType.h"
42 #include "GNEVTypeDistribution.h"
43 #include "GNEWalk.h"
44 #include "GNEStopPlan.h"
45 
46 // ===========================================================================
47 // member method definitions
48 // ===========================================================================
49 
51 
52 
55  // edges
56  fromEdge = ACs->retrieveEdge(planParameters.fromEdge, false);
57  toEdge = ACs->retrieveEdge(planParameters.toEdge, false);
58  for (const auto& edgeID : planParameters.consecutiveEdges) {
59  auto parsedEdge = ACs->retrieveEdge(edgeID, false);
60  // avoid null and consecutive dulicated edges
61  if (parsedEdge && (consecutiveEdges.empty() || (consecutiveEdges.back() != parsedEdge))) {
62  consecutiveEdges.push_back(parsedEdge);
63  }
64  }
65  // junctions
66  fromJunction = ACs->retrieveJunction(planParameters.fromJunction, false);
67  toJunction = ACs->retrieveJunction(planParameters.toJunction, false);
68  // TAZs
69  fromTAZ = ACs->retrieveAdditional(SUMO_TAG_TAZ, planParameters.fromTAZ, false);
70  toTAZ = ACs->retrieveAdditional(SUMO_TAG_TAZ, planParameters.toTAZ, false);
71  // bus stops
72  if (fromStoppingPlace == nullptr) {
74  }
75  if (toStoppingPlace == nullptr) {
76  toStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_BUS_STOP, planParameters.toBusStop, false);
77  }
78  // train stops
79  if (fromStoppingPlace == nullptr) {
81  }
82  if (toStoppingPlace == nullptr) {
84  }
85  // container stops
86  if (fromStoppingPlace == nullptr) {
88  }
89  if (toStoppingPlace == nullptr) {
91  }
92  // charging station
93  if (fromStoppingPlace == nullptr) {
95  }
96  if (toStoppingPlace == nullptr) {
98  }
99  // parking area
100  if (fromStoppingPlace == nullptr) {
102  }
103  if (toStoppingPlace == nullptr) {
105  }
106  // routes
107  fromRoute = ACs->retrieveDemandElement(SUMO_TAG_ROUTE, planParameters.fromRoute, false);
108  toRoute = ACs->retrieveDemandElement(SUMO_TAG_ROUTE, planParameters.toRoute, false);
109 }
110 
111 
112 bool
114  if (!planParameters.fromEdge.empty() && !fromEdge) {
115  WRITE_WARNING(TLF("Invalid from edge '%' used in % of % '%'", planParameters.fromEdge, toString(planTag), parent->getTagStr(), parent->getID()));
116  return false;
117  } else if (!planParameters.toEdge.empty() && !toEdge) {
118  WRITE_WARNING(TLF("Invalid to edge '%' used in % of % '%'", planParameters.toEdge, toString(planTag), parent->getTagStr(), parent->getID()));
119  return false;
120  } else if (!planParameters.fromJunction.empty() && !fromJunction) {
121  WRITE_WARNING(TLF("Invalid from junction '%' used in % of % '%'", planParameters.fromJunction, toString(planTag), parent->getTagStr(), parent->getID()));
122  return false;
123  } else if (!planParameters.toJunction.empty() && !toJunction) {
124  WRITE_WARNING(TLF("Invalid to junction '%' used in % of % '%'", planParameters.toJunction, toString(planTag), parent->getTagStr(), parent->getID()));
125  return false;
126  } else if (!planParameters.fromTAZ.empty() && !fromTAZ) {
127  WRITE_WARNING(TLF("Invalid from TAZ '%' used in % of % '%'", planParameters.fromTAZ, toString(planTag), parent->getTagStr(), parent->getID()));
128  return false;
129  } else if (!planParameters.toTAZ.empty() && !toTAZ) {
130  WRITE_WARNING(TLF("Invalid to TAZ '%' used in % of % '%'", planParameters.toTAZ, toString(planTag), parent->getTagStr(), parent->getID()));
131  return false;
132  } else if (!planParameters.fromBusStop.empty() && !fromStoppingPlace) {
133  WRITE_WARNING(TLF("Invalid from bus stop '%' used in % of % '%'", planParameters.fromBusStop, toString(planTag), parent->getTagStr(), parent->getID()));
134  return false;
135  } else if (!planParameters.fromTrainStop.empty() && !fromStoppingPlace) {
136  WRITE_WARNING(TLF("Invalid from train stop '%' used in % of % '%'", planParameters.fromTrainStop, toString(planTag), parent->getTagStr(), parent->getID()));
137  return false;
138  } else if (!planParameters.fromContainerStop.empty() && !fromStoppingPlace) {
139  WRITE_WARNING(TLF("Invalid from container stop '%' used in % of % '%'", planParameters.fromContainerStop, toString(planTag), parent->getTagStr(), parent->getID()));
140  return false;
141  } else if (!planParameters.fromChargingStation.empty() && !fromStoppingPlace) {
142  WRITE_WARNING(TLF("Invalid from charging station '%' used in % of % '%'", planParameters.fromChargingStation, toString(planTag), parent->getTagStr(), parent->getID()));
143  return false;
144  } else if (!planParameters.fromParkingArea.empty() && !fromStoppingPlace) {
145  WRITE_WARNING(TLF("Invalid from parking area '%' used in % of % '%'", planParameters.fromParkingArea, toString(planTag), parent->getTagStr(), parent->getID()));
146  return false;
147  } else if (!planParameters.toBusStop.empty() && !toStoppingPlace) {
148  WRITE_WARNING(TLF("Invalid to bus stop '%' used in % of % '%'", planParameters.toBusStop, toString(planTag), parent->getTagStr(), parent->getID()));
149  return false;
150  } else if (!planParameters.toTrainStop.empty() && !toStoppingPlace) {
151  WRITE_WARNING(TLF("Invalid to train stop '%' used in % of % '%'", planParameters.toTrainStop, toString(planTag), parent->getTagStr(), parent->getID()));
152  return false;
153  } else if (!planParameters.toContainerStop.empty() && !toStoppingPlace) {
154  WRITE_WARNING(TLF("Invalid to container stop '%' used in % of % '%'", planParameters.toContainerStop, toString(planTag), parent->getTagStr(), parent->getID()));
155  return false;
156  } else if (!planParameters.toChargingStation.empty() && !toStoppingPlace) {
157  WRITE_WARNING(TLF("Invalid to charging station '%' used in % of % '%'", planParameters.toChargingStation, toString(planTag), parent->getTagStr(), parent->getID()));
158  return false;
159  } else if (!planParameters.toParkingArea.empty() && !toStoppingPlace) {
160  WRITE_WARNING(TLF("Invalid to parking area '%' used in % of % '%'", planParameters.toParkingArea, toString(planTag), parent->getTagStr(), parent->getID()));
161  return false;
162  } else if (!planParameters.fromRoute.empty() && !fromRoute) {
163  WRITE_WARNING(TLF("Invalid from route '%' used in % of % '%'", planParameters.fromRoute, toString(planTag), parent->getTagStr(), parent->getID()));
164  return false;
165  } else if (!planParameters.toRoute.empty() && !toRoute) {
166  WRITE_WARNING(TLF("Invalid to route '%' used in % of % '%'", planParameters.toRoute, toString(planTag), parent->getTagStr(), parent->getID()));
167  return false;
168  } else {
169  return true;
170  }
171 }
172 
173 void
175  if (fromEdge) {
176  fromEdge->addChildElement(element);
177  }
178  if (toEdge) {
179  toEdge->addChildElement(element);
180  }
181  for (const auto& consecutiveEdge : consecutiveEdges) {
182  consecutiveEdge->addChildElement(element);
183  }
184  if (fromJunction) {
185  fromJunction->addChildElement(element);
186  }
187  if (toJunction) {
188  toJunction->addChildElement(element);
189  }
190  if (fromTAZ) {
191  fromTAZ->addChildElement(element);
192  }
193  if (toTAZ) {
194  toTAZ->addChildElement(element);
195  }
196  if (fromStoppingPlace) {
198  }
199  if (toStoppingPlace) {
201  }
202  if (fromRoute) {
203  fromRoute->addChildElement(element);
204  }
205  if (toRoute) {
206  toRoute->addChildElement(element);
207  }
208 }
209 
210 
211 void
213  fromEdge = nullptr;
214  toEdge = nullptr;
215  consecutiveEdges.clear();
216  fromJunction = nullptr;
217  toJunction = nullptr;
218  fromTAZ = nullptr;
219  toTAZ = nullptr;
220  fromStoppingPlace = nullptr;
221  toStoppingPlace = nullptr;
222  fromRoute = nullptr;
223  toRoute = nullptr;
224 }
225 
226 
227 bool
229  if (fromStoppingPlace) {
231  } else {
232  return false;
233  }
234 }
235 
236 
237 bool
239  if (toStoppingPlace) {
241  } else {
242  return false;
243  }
244 }
245 
246 
247 bool
249  if (fromStoppingPlace) {
251  } else {
252  return false;
253  }
254 }
255 
256 
257 bool
259  if (toStoppingPlace) {
261  } else {
262  return false;
263  }
264 }
265 
266 
267 bool
269  if (fromStoppingPlace) {
271  } else {
272  return false;
273  }
274 }
275 
276 
277 bool
279  if (toStoppingPlace) {
281  } else {
282  return false;
283  }
284 }
285 
286 
287 bool
289  if (fromStoppingPlace) {
291  } else {
292  return false;
293  }
294 }
295 
296 
297 bool
299  if (toStoppingPlace) {
301  } else {
302  return false;
303  }
304 }
305 
306 
307 bool
309  if (fromStoppingPlace) {
311  } else {
312  return false;
313  }
314 }
315 
316 
317 bool
319  if (toStoppingPlace) {
321  } else {
322  return false;
323  }
324 }
325 
326 
327 std::vector<GNEJunction*>
329  std::vector<GNEJunction*> junctions;
330  if (fromJunction) {
331  junctions.push_back(fromJunction);
332  }
333  if (toJunction) {
334  junctions.push_back(toJunction);
335  }
336  return junctions;
337 }
338 
339 
340 std::vector<GNEEdge*>
342  if (consecutiveEdges.size() > 0) {
343  return consecutiveEdges;
344  } else {
345  std::vector<GNEEdge*> edges;
346  if (fromEdge) {
347  edges.push_back(fromEdge);
348  }
349  if (toEdge) {
350  edges.push_back(toEdge);
351  }
352  return edges;
353  }
354 }
355 
356 
357 std::vector<GNEAdditional*>
359  std::vector<GNEAdditional*> additionals;
360  if (fromStoppingPlace) {
361  additionals.push_back(fromStoppingPlace);
362  }
363  if (toStoppingPlace) {
364  additionals.push_back(toStoppingPlace);
365  }
366  if (fromTAZ) {
367  additionals.push_back(fromTAZ);
368  }
369  if (toTAZ) {
370  additionals.push_back(toTAZ);
371  }
372  return additionals;
373 }
374 
375 
376 std::vector<GNEDemandElement*>
378  std::vector<GNEDemandElement*> demandElements;
379  // always add parent first
380  demandElements.push_back(parent);
381  if (fromRoute) {
382  demandElements.push_back(fromRoute);
383  }
384  if (toRoute) {
385  demandElements.push_back(toRoute);
386  }
387  return demandElements;
388 }
389 
390 /****************************************************************************/
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:295
#define TLF(string,...)
Definition: MsgHandler.h:317
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
begin/end of the 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 toTrainStop
to trainStop
std::string fromTrainStop
from trainStop
std::string toParkingArea
to parkingArea
std::string fromBusStop
from busStop
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(T *element)
add child element
struct used for saving all attribute carriers of net, in different formats
Definition: GNENetHelper.h:75
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)
void addChildElements(GNEDemandElement *element)
add the given element in the element as child
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
GNEDemandElement * toRoute
to route (currently only used by walks)
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property