Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEHierarchicalElement.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// A abstract class for representation of hierarchical elements
19/****************************************************************************/
20#include <config.h>
21
22#include <netedit/GNENet.h>
23
24
26
27// ===========================================================================
28// member method definitions
29// ===========================================================================
30
31// ---------------------------------------------------------------------------
32// GNEHierarchicalElement - methods
33// ---------------------------------------------------------------------------
34
36 const std::vector<GNEJunction*>& parentJunctions,
37 const std::vector<GNEEdge*>& parentEdges,
38 const std::vector<GNELane*>& parentLanes,
39 const std::vector<GNEAdditional*>& parentAdditionals,
40 const std::vector<GNEDemandElement*>& ParentDemandElements,
41 const std::vector<GNEGenericData*>& parentGenericDatas) :
42 GNEAttributeCarrier(tag, net),
43 myHierarchicalContainer(parentJunctions, parentEdges, parentLanes, parentAdditionals, ParentDemandElements, parentGenericDatas) {
44}
45
46
48
49
54
55
56void
60
61
62std::vector<GNEHierarchicalElement*>
64 // declare result
65 std::vector<GNEHierarchicalElement*> result;
66 // reserve
68 // add parent elements
69 for (const auto& element : getParentJunctions()) {
70 result.push_back(element);
71 }
72 for (const auto& element : getParentEdges()) {
73 result.push_back(element);
74 }
75 for (const auto& element : getParentLanes()) {
76 result.push_back(element);
77 }
78 for (const auto& element : getParentAdditionals()) {
79 result.push_back(element);
80 }
81 for (const auto& element : getParentDemandElements()) {
82 result.push_back(element);
83 }
84 for (const auto& element : getParentGenericDatas()) {
85 result.push_back(element);
86 }
87 // add child elements
88 for (const auto& element : getChildJunctions()) {
89 result.push_back(element);
90 }
91 for (const auto& element : getChildEdges()) {
92 result.push_back(element);
93 }
94 for (const auto& element : getChildLanes()) {
95 result.push_back(element);
96 }
97 for (const auto& element : getChildAdditionals()) {
98 result.push_back(element);
99 }
100 for (const auto& element : getChildDemandElements()) {
101 result.push_back(element);
102 }
103 for (const auto& element : getChildGenericDatas()) {
104 result.push_back(element);
105 }
106 return result;
107}
108
109
110const std::vector<GNEJunction*>&
112 return myHierarchicalContainer.getParents<std::vector<GNEJunction*> >();
113}
114
115
116const std::vector<GNEEdge*>&
118 return myHierarchicalContainer.getParents<std::vector<GNEEdge*> >();
119}
120
121
122const std::vector<GNELane*>&
124 return myHierarchicalContainer.getParents<std::vector<GNELane*> >();
125}
126
127
128const std::vector<GNEAdditional*>&
130 return myHierarchicalContainer.getParents<std::vector<GNEAdditional*> >();
131}
132
133
134const std::vector<GNEAdditional*>
136 std::vector<GNEAdditional*> stoppingPlaces;
137 for (const auto& additional : getParentAdditionals()) {
138 if (additional->getTagProperty().isStoppingPlace()) {
139 stoppingPlaces.push_back(additional);
140 }
141 }
142 return stoppingPlaces;
143}
144
145
146const std::vector<GNEAdditional*>
148 std::vector<GNEAdditional*> TAZs;
149 for (const auto& additional : getParentAdditionals()) {
150 if (additional->getTagProperty().isTAZElement()) {
151 TAZs.push_back(additional);
152 }
153 }
154 return TAZs;
155}
156
157
158const std::vector<GNEDemandElement*>&
160 return myHierarchicalContainer.getParents<std::vector<GNEDemandElement*> >();
161}
162
163
164const std::vector<GNEGenericData*>&
166 return myHierarchicalContainer.getParents<std::vector<GNEGenericData*> >();
167}
168
169
170const std::vector<GNEJunction*>&
172 return myHierarchicalContainer.getChildren<std::vector<GNEJunction*> >();
173}
174
175
176const std::vector<GNEEdge*>&
178 return myHierarchicalContainer.getChildren<std::vector<GNEEdge*> >();
179}
180
181
182const std::vector<GNELane*>&
184 return myHierarchicalContainer.getChildren<std::vector<GNELane*> >();
185}
186
187
188const std::vector<GNEAdditional*>&
190 return myHierarchicalContainer.getChildren<std::vector<GNEAdditional*> >();
191}
192
193
194const std::vector<GNEDemandElement*>&
196 return myHierarchicalContainer.getChildren<std::vector<GNEDemandElement*> >();
197}
198
199
200const std::vector<GNEGenericData*>&
202 return myHierarchicalContainer.getChildren<std::vector<GNEGenericData*> >();
203}
204
205
206template<> void
208 // add parent element into container
210}
211
212
213template<> void
215 // add parent element into container
217}
218
219
220template<> void
222 // add parent element into container
224}
225
226
227template<> void
229 // add parent element into container
231}
232
233
234template<> void
236 // add parent element into container
238}
239
240
241template<> void
243 // add parent element into container
245}
246
247
248template<> void
250 // remove parent element from container
252}
253
254
255template<> void
257 // remove parent element from container
259}
260
261
262template<> void
264 // remove parent element from container
266}
267
268
269template<> void
271 // remove parent element from container
273}
274
275
276template<> void
278 // remove parent element from container
280}
281
282
283template<> void
285 // remove parent element from container
287}
288
289
290template<> void
292 // add child element into container
294}
295
296
297template<> void
299 // add child element into container
301}
302
303
304template<> void
306 // add child element into container
308}
309
310
311template<> void
313 // add child element into container
315}
316
317
318template<> void
320 // add child element into container
322}
323
324
325template<> void
327 // add child element into container
329}
330
331
332template<> void
334 // remove child element from container
336}
337
338
339template<> void
341 // remove child element from container
343}
344
345
346template<> void
348 // remove child element from container
350}
351
352
353template<> void
355 // remove child element from container
357}
358
359
360template<> void
362 // remove child element from container
364}
365
366
367template<> void
369 // remove child element from container
371}
372
373
374std::string
375GNEHierarchicalElement::getNewListOfParents(const GNENetworkElement* currentElement, const GNENetworkElement* newNextElement) const {
376 std::vector<std::string> solution;
377 if ((currentElement->getTagProperty().getTag() == SUMO_TAG_EDGE) && (newNextElement->getTagProperty().getTag() == SUMO_TAG_EDGE)) {
378 // reserve solution
379 solution.reserve(getParentEdges().size());
380 // iterate over edges
381 for (const auto& edge : getParentEdges()) {
382 // add edge ID
383 solution.push_back(edge->getID());
384 // if current edge is the current element, then insert newNextElement ID
385 if (edge == currentElement) {
386 solution.push_back(newNextElement->getID());
387 }
388 }
389 } else if ((currentElement->getTagProperty().getTag() == SUMO_TAG_LANE) && (newNextElement->getTagProperty().getTag() == SUMO_TAG_LANE)) {
390 // reserve solution
391 solution.reserve(getParentLanes().size());
392 // iterate over lanes
393 for (const auto& lane : getParentLanes()) {
394 // add lane ID
395 solution.push_back(lane->getID());
396 // if current lane is the current element, then insert newNextElement ID
397 if (lane == currentElement) {
398 solution.push_back(newNextElement->getID());
399 }
400 }
401 }
402 // remove consecutive (adjacent) duplicates
403 solution.erase(std::unique(solution.begin(), solution.end()), solution.end());
404 // return solution
405 return toString(solution);
406}
407
408
409bool
411 // declare a vector to keep sorted children
412 std::vector<std::pair<std::pair<double, double>, GNEAdditional*> > sortedChildren;
413 // iterate over child meanData
414 for (const auto& meanData : getChildAdditionals()) {
415 sortedChildren.push_back(std::make_pair(std::make_pair(0., 0.), meanData));
416 // set begin/start attribute
417 if (meanData->getTagProperty().hasAttribute(SUMO_ATTR_TIME) && GNEAttributeCarrier::canParse<double>(meanData->getAttribute(SUMO_ATTR_TIME))) {
418 sortedChildren.back().first.first = meanData->getAttributeDouble(SUMO_ATTR_TIME);
419 } else if (meanData->getTagProperty().hasAttribute(SUMO_ATTR_BEGIN) && GNEAttributeCarrier::canParse<double>(meanData->getAttribute(SUMO_ATTR_BEGIN))) {
420 sortedChildren.back().first.first = meanData->getAttributeDouble(SUMO_ATTR_BEGIN);
421 }
422 // set end attribute
423 if (meanData->getTagProperty().hasAttribute(SUMO_ATTR_END) && GNEAttributeCarrier::canParse<double>(meanData->getAttribute(SUMO_ATTR_END))) {
424 sortedChildren.back().first.second = meanData->getAttributeDouble(SUMO_ATTR_END);
425 } else {
426 sortedChildren.back().first.second = sortedChildren.back().first.first;
427 }
428 }
429 // sort children
430 std::sort(sortedChildren.begin(), sortedChildren.end());
431 // make sure that number of sorted children is the same as the child meanData
432 if (sortedChildren.size() == getChildAdditionals().size()) {
433 if (sortedChildren.size() <= 1) {
434 return true;
435 } else {
436 // check overlapping
437 for (int i = 0; i < (int)sortedChildren.size() - 1; i++) {
438 if (sortedChildren.at(i).first.second > sortedChildren.at(i + 1).first.first) {
439 return false;
440 }
441 }
442 }
443 return true;
444 } else {
445 throw ProcessError(TL("Some child meanData were lost during sorting"));
446 }
447}
448
449
450bool
454
455/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:315
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_LANE
begin/end of the description of a single lane
@ SUMO_TAG_EDGE
begin/end of the description of an edge
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_TIME
trigger: the time of the step
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
An Element which don't belong to GNENet but has influence in the simulation.
virtual double getAttributeDouble(SumoXMLAttr key) const =0
const std::string getID() const
get ID (all Attribute Carriers have one)
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
An Element which don't belong to GNENet but has influence in the simulation.
Hierarchical container (used for keep myParent and myChildren.
void addParentElement(const GNEHierarchicalElement *hierarchicalElement, T *element)
add parent element
size_t getContainerSize() const
get container size
const T & getChildren() const
get children
void addChildElement(const GNEHierarchicalElement *hierarchicalElement, T *element)
add child element
void removeParentElement(const GNEHierarchicalElement *hierarchicalElement, T *element)
remove parent element
void removeChildElement(const GNEHierarchicalElement *hierarchicalElement, T *element)
remove child element
const T & getParents() const
get parents
const std::vector< GNEJunction * > & getParentJunctions() const
get parent junctions
void addChildElement(T *element)
add child element
const std::vector< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
GNEHierarchicalElement(GNENet *net, SumoXMLTag tag, const std::vector< GNEJunction * > &parentJunctions, const std::vector< GNEEdge * > &parentEdges, const std::vector< GNELane * > &parentLanes, const std::vector< GNEAdditional * > &parentAdditionals, const std::vector< GNEDemandElement * > &parentDemandElements, const std::vector< GNEGenericData * > &parentGenericDatas)
Constructor.
const std::vector< GNEGenericData * > & getParentGenericDatas() const
get parent demand elements
bool checkChildAdditionalsOverlapping() const
check if children are overlapped (Used by Rerouters)
const std::vector< GNELane * > & getChildLanes() const
get child lanes
const GNEHierarchicalContainer & getHierarchicalContainer() const
get hierarchicalcontainer with parents and children
const std::vector< GNEAdditional * > getParentStoppingPlaces() const
get parent stoppingPlaces (used by plans)
const std::vector< GNEAdditional * > getParentTAZs() const
get parent TAZs (used by plans)
const std::vector< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
GNEHierarchicalContainer myHierarchicalContainer
hierarchical container with parents and children
bool checkChildDemandElementsOverlapping() const
check if childs demand elements are overlapped
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
void addParentElement(T *element)
add parent element
const std::vector< GNEEdge * > & getChildEdges() const
get child edges
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
std::vector< GNEHierarchicalElement * > getAllHierarchicalElements() const
get all parents and children
void removeChildElement(T *element)
remove child element
std::string getNewListOfParents(const GNENetworkElement *currentElement, const GNENetworkElement *newNextElement) const
if use edge/parent lanes as a list of consecutive elements, obtain a list of IDs of elements after in...
const std::vector< GNEJunction * > & getChildJunctions() const
get child junctions
const std::vector< GNELane * > & getParentLanes() const
get parent lanes
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
const std::vector< GNEGenericData * > & getChildGenericDatas() const
return child generic data elements
void removeParentElement(T *element)
remove parent element
void restoreHierarchicalContainer(const GNEHierarchicalContainer &container)
restore hierarchical container
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property