Eclipse SUMO - Simulation of Urban MObility
GNEHierarchicalElement.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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
53}
54
55
56void
58 myHierarchicalContainer = container;
59}
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<GNEDemandElement*>&
136 return myHierarchicalContainer.getParents<std::vector<GNEDemandElement*> >();
137}
138
139
140const std::vector<GNEGenericData*>&
142 return myHierarchicalContainer.getParents<std::vector<GNEGenericData*> >();
143}
144
145
146const std::vector<GNEJunction*>&
148 return myHierarchicalContainer.getChildren<std::vector<GNEJunction*> >();
149}
150
151
152const std::vector<GNEEdge*>&
154 return myHierarchicalContainer.getChildren<std::vector<GNEEdge*> >();
155}
156
157
158const std::vector<GNELane*>&
160 return myHierarchicalContainer.getChildren<std::vector<GNELane*> >();
161}
162
163
164const std::vector<GNEAdditional*>&
166 return myHierarchicalContainer.getChildren<std::vector<GNEAdditional*> >();
167}
168
169
170const std::vector<GNEDemandElement*>&
172 return myHierarchicalContainer.getChildren<std::vector<GNEDemandElement*> >();
173}
174
175
176const std::vector<GNEGenericData*>&
178 return myHierarchicalContainer.getChildren<std::vector<GNEGenericData*> >();
179}
180
181
182template<> void
184 // add parent element into container
186}
187
188
189template<> void
191 // add parent element into container
193}
194
195
196template<> void
198 // add parent element into container
200}
201
202
203template<> void
205 // add parent element into container
207}
208
209
210template<> void
212 // add parent element into container
214}
215
216
217template<> void
219 // add parent element into container
221}
222
223
224template<> void
226 // remove parent element from container
228}
229
230
231template<> void
233 // remove parent element from container
235}
236
237
238template<> void
240 // remove parent element from container
242}
243
244
245template<> void
247 // remove parent element from container
249}
250
251
252template<> void
254 // remove parent element from container
256}
257
258
259template<> void
261 // remove parent element from container
263}
264
265
266template<> void
268 // add child element into container
270}
271
272
273template<> void
275 // add child element into container
277}
278
279
280template<> void
282 // add child element into container
284}
285
286
287template<> void
289 // add child element into container
291}
292
293
294template<> void
296 // add child element into container
298}
299
300
301template<> void
303 // add child element into container
305}
306
307
308template<> void
310 // remove child element from container
312}
313
314
315template<> void
317 // remove child element from container
319}
320
321
322template<> void
324 // remove child element from container
326}
327
328
329template<> void
331 // remove child element from container
333}
334
335
336template<> void
338 // remove child element from container
340}
341
342
343template<> void
345 // remove child element from container
347}
348
349
350std::string
351GNEHierarchicalElement::getNewListOfParents(const GNENetworkElement* currentElement, const GNENetworkElement* newNextElement) const {
352 std::vector<std::string> solution;
353 if ((currentElement->getTagProperty().getTag() == SUMO_TAG_EDGE) && (newNextElement->getTagProperty().getTag() == SUMO_TAG_EDGE)) {
354 // reserve solution
355 solution.reserve(getParentEdges().size());
356 // iterate over edges
357 for (const auto& edge : getParentEdges()) {
358 // add edge ID
359 solution.push_back(edge->getID());
360 // if current edge is the current element, then insert newNextElement ID
361 if (edge == currentElement) {
362 solution.push_back(newNextElement->getID());
363 }
364 }
365 } else if ((currentElement->getTagProperty().getTag() == SUMO_TAG_LANE) && (newNextElement->getTagProperty().getTag() == SUMO_TAG_LANE)) {
366 // reserve solution
367 solution.reserve(getParentLanes().size());
368 // iterate over lanes
369 for (const auto& lane : getParentLanes()) {
370 // add lane ID
371 solution.push_back(lane->getID());
372 // if current lane is the current element, then insert newNextElement ID
373 if (lane == currentElement) {
374 solution.push_back(newNextElement->getID());
375 }
376 }
377 }
378 // remove consecutive (adjacent) duplicates
379 solution.erase(std::unique(solution.begin(), solution.end()), solution.end());
380 // return solution
381 return toString(solution);
382}
383
384
385bool
387 // declare a vector to keep sorted children
388 std::vector<std::pair<std::pair<double, double>, GNEAdditional*> > sortedChildren;
389 // iterate over child additional
390 for (const auto& additional : getChildAdditionals()) {
391 sortedChildren.push_back(std::make_pair(std::make_pair(0., 0.), additional));
392 // set begin/start attribute
393 if (additional->getTagProperty().hasAttribute(SUMO_ATTR_TIME) && GNEAttributeCarrier::canParse<double>(additional->getAttribute(SUMO_ATTR_TIME))) {
394 sortedChildren.back().first.first = additional->getAttributeDouble(SUMO_ATTR_TIME);
395 } else if (additional->getTagProperty().hasAttribute(SUMO_ATTR_BEGIN) && GNEAttributeCarrier::canParse<double>(additional->getAttribute(SUMO_ATTR_BEGIN))) {
396 sortedChildren.back().first.first = additional->getAttributeDouble(SUMO_ATTR_BEGIN);
397 }
398 // set end attribute
399 if (additional->getTagProperty().hasAttribute(SUMO_ATTR_END) && GNEAttributeCarrier::canParse<double>(additional->getAttribute(SUMO_ATTR_END))) {
400 sortedChildren.back().first.second = additional->getAttributeDouble(SUMO_ATTR_END);
401 } else {
402 sortedChildren.back().first.second = sortedChildren.back().first.first;
403 }
404 }
405 // sort children
406 std::sort(sortedChildren.begin(), sortedChildren.end());
407 // make sure that number of sorted children is the same as the child additional
408 if (sortedChildren.size() == getChildAdditionals().size()) {
409 if (sortedChildren.size() <= 1) {
410 return true;
411 } else {
412 // check overlapping
413 for (int i = 0; i < (int)sortedChildren.size() - 1; i++) {
414 if (sortedChildren.at(i).first.second > sortedChildren.at(i + 1).first.first) {
415 return false;
416 }
417 }
418 }
419 return true;
420 } else {
421 throw ProcessError("Some child additional were lost during sorting");
422 }
423}
424
425
426bool
428 return true;
429}
430
431/****************************************************************************/
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.
Definition: GNEAdditional.h:48
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
An Element which don't belong to GNENet but has influence in the simulation.
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< 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