Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/GNEHierarchicalElement.cpp
169678 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 GNEHierarchicalElement.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jul 2020
17
///
18
// A abstract class for representation of hierarchical elements
19
/****************************************************************************/
20
21
#include <netedit/GNENet.h>
22
#include <netedit/GNETagProperties.h>
23
24
#include "GNEHierarchicalElement.h"
25
26
// ===========================================================================
27
// member method definitions
28
// ===========================================================================
29
30
// ---------------------------------------------------------------------------
31
// GNEHierarchicalElement - methods
32
// ---------------------------------------------------------------------------
33
34
GNEHierarchicalElement::GNEHierarchicalElement() {}
35
36
37
GNEHierarchicalElement::~GNEHierarchicalElement() {}
38
39
40
const GNEHierarchicalStructureParents&
41
GNEHierarchicalElement::getParents() const {
42
return myHierarchicalStructureParents;
43
}
44
45
46
void
47
GNEHierarchicalElement::clearParents() {
48
myHierarchicalStructureParents.clear();
49
}
50
51
52
const GNEHierarchicalContainerParents<GNEJunction*>&
53
GNEHierarchicalElement::getParentJunctions() const {
54
return myHierarchicalStructureParents.get<GNEJunction*>();
55
}
56
57
58
const GNEHierarchicalContainerParents<GNEEdge*>&
59
GNEHierarchicalElement::getParentEdges() const {
60
return myHierarchicalStructureParents.get<GNEEdge*>();
61
}
62
63
64
const GNEHierarchicalContainerParents<GNELane*>&
65
GNEHierarchicalElement::getParentLanes() const {
66
return myHierarchicalStructureParents.get<GNELane*>();
67
}
68
69
70
const GNEHierarchicalContainerParents<GNEAdditional*>&
71
GNEHierarchicalElement::getParentAdditionals() const {
72
return myHierarchicalStructureParents.get<GNEAdditional*>();
73
}
74
75
76
const GNEHierarchicalContainerParents<GNEAdditional*>
77
GNEHierarchicalElement::getParentStoppingPlaces() const {
78
GNEHierarchicalContainerParents<GNEAdditional*> stoppingPlaces;
79
for (const auto& additional : getParentAdditionals()) {
80
if (additional->getTagProperty()->isStoppingPlace()) {
81
stoppingPlaces.push_back(additional);
82
}
83
}
84
return stoppingPlaces;
85
}
86
87
88
const GNEHierarchicalContainerParents<GNEAdditional*>
89
GNEHierarchicalElement::getParentTAZs() const {
90
GNEHierarchicalContainerParents<GNEAdditional*> TAZs;
91
for (const auto& additional : getParentAdditionals()) {
92
if (additional->getTagProperty()->isTAZElement()) {
93
TAZs.push_back(additional);
94
}
95
}
96
return TAZs;
97
}
98
99
100
const GNEHierarchicalContainerParents<GNEDemandElement*>&
101
GNEHierarchicalElement::getParentDemandElements() const {
102
return myHierarchicalStructureParents.get<GNEDemandElement*>();
103
}
104
105
106
const GNEHierarchicalContainerParents<GNEGenericData*>&
107
GNEHierarchicalElement::getParentGenericDatas() const {
108
return myHierarchicalStructureParents.get<GNEGenericData*>();
109
}
110
111
112
const GNEHierarchicalStructureChildren&
113
GNEHierarchicalElement::getChildren() const {
114
return myHierarchicalStructureChildren;
115
}
116
117
118
const GNEHierarchicalContainerChildren<GNEJunction*>&
119
GNEHierarchicalElement::getChildJunctions() const {
120
return myHierarchicalStructureChildren.get<GNEJunction*>();
121
}
122
123
124
const GNEHierarchicalContainerChildren<GNEEdge*>&
125
GNEHierarchicalElement::getChildEdges() const {
126
return myHierarchicalStructureChildren.get<GNEEdge*>();
127
}
128
129
130
const GNEHierarchicalContainerChildren<GNELane*>&
131
GNEHierarchicalElement::getChildLanes() const {
132
return myHierarchicalStructureChildren.get<GNELane*>();
133
}
134
135
136
const GNEHierarchicalContainerChildren<GNEAdditional*>&
137
GNEHierarchicalElement::getChildAdditionals() const {
138
return myHierarchicalStructureChildren.get<GNEAdditional*>();
139
}
140
141
142
const GNEHierarchicalContainerChildren<GNEDemandElement*>&
143
GNEHierarchicalElement::getChildDemandElements() const {
144
return myHierarchicalStructureChildren.get<GNEDemandElement*>();
145
}
146
147
148
const GNEHierarchicalContainerChildren<GNEGenericData*>&
149
GNEHierarchicalElement::getChildGenericDatas() const {
150
return myHierarchicalStructureChildren.get<GNEGenericData*>();
151
}
152
153
154
const GNEHierarchicalContainerChildrenSet<GNETAZSourceSink*>&
155
GNEHierarchicalElement::getChildTAZSourceSinks() const {
156
return myHierarchicalStructureChildren.getSet<GNETAZSourceSink*>();
157
}
158
159
160
std::string
161
GNEHierarchicalElement::getNewListOfParents(const GNENetworkElement* currentElement, const GNENetworkElement* newNextElement) const {
162
std::vector<std::string> solution;
163
if ((currentElement->getTagProperty()->getTag() == SUMO_TAG_EDGE) && (newNextElement->getTagProperty()->getTag() == SUMO_TAG_EDGE)) {
164
// reserve solution
165
solution.reserve(getParentEdges().size());
166
// iterate over edges
167
for (const auto& edge : getParentEdges()) {
168
// add edge ID
169
solution.push_back(edge->getID());
170
// if current edge is the current element, then insert newNextElement ID
171
if (edge == currentElement) {
172
solution.push_back(newNextElement->getID());
173
}
174
}
175
} else if ((currentElement->getTagProperty()->getTag() == SUMO_TAG_LANE) && (newNextElement->getTagProperty()->getTag() == SUMO_TAG_LANE)) {
176
// reserve solution
177
solution.reserve(getParentLanes().size());
178
// iterate over lanes
179
for (const auto& lane : getParentLanes()) {
180
// add lane ID
181
solution.push_back(lane->getID());
182
// if current lane is the current element, then insert newNextElement ID
183
if (lane == currentElement) {
184
solution.push_back(newNextElement->getID());
185
}
186
}
187
}
188
// remove consecutive (adjacent) duplicates
189
solution.erase(std::unique(solution.begin(), solution.end()), solution.end());
190
// return solution
191
return toString(solution);
192
}
193
194
/****************************************************************************/
195
196