Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/GNEHierarchicalElement.h
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.h
15
/// @author Pablo Alvarez Lopez
16
/// @date Jul 2020
17
///
18
// A abstract class for representation of hierarchical elements
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include "GNEHierarchicalStructureParents.h"
24
#include "GNEHierarchicalStructureChildren.h"
25
26
// ===========================================================================
27
// class definitions
28
// ===========================================================================
29
30
class GNEHierarchicalElement {
31
32
public:
33
/// @brief declare GNEChange_Children as friend class
34
friend class GNEChange_Children;
35
friend class GNEDemandElement;
36
37
/// @brief default Constructor
38
GNEHierarchicalElement();
39
40
/// @brief Destructor
41
~GNEHierarchicalElement();
42
43
/// @brief clear hierarchical structure parents (used in GNE_Change)
44
void clearParents();
45
46
/// @name get parent functions
47
/// @{
48
49
/// @brief get parents container
50
const GNEHierarchicalStructureParents& getParents() const;
51
52
/// @brief get parent junctions
53
const GNEHierarchicalContainerParents<GNEJunction*>& getParentJunctions() const;
54
55
/// @brief get parent edges
56
const GNEHierarchicalContainerParents<GNEEdge*>& getParentEdges() const;
57
58
/// @brief get parent lanes
59
const GNEHierarchicalContainerParents<GNELane*>& getParentLanes() const;
60
61
/// @brief get parent additionals
62
const GNEHierarchicalContainerParents<GNEAdditional*>& getParentAdditionals() const;
63
64
/// @brief get parent stoppingPlaces (used by plans)
65
const GNEHierarchicalContainerParents<GNEAdditional*> getParentStoppingPlaces() const;
66
67
/// @brief get parent TAZs (used by plans)
68
const GNEHierarchicalContainerParents<GNEAdditional*> getParentTAZs() const;
69
70
/// @brief get parent demand elements
71
const GNEHierarchicalContainerParents<GNEDemandElement*>& getParentDemandElements() const;
72
73
/// @brief get parent demand elements
74
const GNEHierarchicalContainerParents<GNEGenericData*>& getParentGenericDatas() const;
75
76
/// @}
77
78
/// @name get children functions
79
/// @{
80
81
/// @brief get child container
82
const GNEHierarchicalStructureChildren& getChildren() const;
83
84
/// @brief get child junctions
85
const GNEHierarchicalContainerChildren<GNEJunction*>& getChildJunctions() const;
86
87
/// @brief get child edges
88
const GNEHierarchicalContainerChildren<GNEEdge*>& getChildEdges() const;
89
90
/// @brief get child lanes
91
const GNEHierarchicalContainerChildren<GNELane*>& getChildLanes() const;
92
93
/// @brief return child additionals
94
const GNEHierarchicalContainerChildren<GNEAdditional*>& getChildAdditionals() const;
95
96
/// @brief return child demand elements
97
const GNEHierarchicalContainerChildren<GNEDemandElement*>& getChildDemandElements() const;
98
99
/// @brief return child generic data elements
100
const GNEHierarchicalContainerChildren<GNEGenericData*>& getChildGenericDatas() const;
101
102
/// @brief return child TAZSourceSinks (Set)
103
const GNEHierarchicalContainerChildrenSet<GNETAZSourceSink*>& getChildTAZSourceSinks() const;
104
105
/// @}
106
107
/// @brief edit parent and childrens without maintain integrity (use carefully)
108
/// @{
109
110
/// @brief set single parent element (ONLY use in constructors)
111
template<typename ParentType>
112
void setParent(ParentType parent) {
113
GNEHierarchicalContainerParents<ParentType> parents;
114
parents.push_back(parent);
115
myHierarchicalStructureParents.replaceAll(parents);
116
}
117
118
/// @brief set multiple parent element (ONLY use in constructors)
119
template<typename ParentType>
120
void setParents(const GNEHierarchicalContainerParents<ParentType>& parents) {
121
myHierarchicalStructureParents.replaceAll(parents);
122
}
123
124
/// @brief add child without updating parent (ONLY used if we're creating elements without undo-redo)
125
template<typename ChildType>
126
void addChildElement(ChildType* element) {
127
myHierarchicalStructureChildren.add(element);
128
}
129
130
/// @}
131
132
/// @name edit function maintain integrity
133
/// @{
134
135
/// @brief insert parent element
136
template<typename ElementType, typename ParentType>
137
static void insertParent(ElementType* element, ParentType* parent, const int index = -1) {
138
element->myHierarchicalStructureParents.add(parent, index);
139
parent->myHierarchicalStructureChildren.add(element);
140
}
141
142
/// @brief remove parent element
143
template<typename ElementType, typename ParentType>
144
static void removeParent(ElementType* element, ParentType* parent) {
145
element->myHierarchicalStructureParents.remove(parent);
146
parent->myHierarchicalStructureChildren.remove(element);
147
}
148
149
/// @brief update single parent element
150
template<typename ElementType, typename ParentType>
151
static void updateParent(ElementType element, const int index, ParentType newParent) {
152
// remove element from old parent
153
auto oldParent = element->myHierarchicalStructureParents.template at<ParentType>(index);
154
oldParent->myHierarchicalStructureChildren.remove(element);
155
// update parent
156
element->myHierarchicalStructureParents.replaceSingle(index, newParent);
157
// insert child in new parent
158
newParent->myHierarchicalStructureChildren.add(element);
159
}
160
161
/// @brief update all parent elements
162
template<typename ElementType, typename ParentType>
163
static void updateParents(ElementType element, GNEHierarchicalContainerParents<ParentType> newParents) {
164
// remove children
165
for (const auto parent : element->myHierarchicalStructureParents.template get<ParentType>()) {
166
parent->myHierarchicalStructureChildren.remove(element);
167
}
168
// update parents
169
element->myHierarchicalStructureParents.replaceAll(newParents);
170
// restore children
171
for (const auto parent : element->myHierarchicalStructureParents.template get<ParentType>()) {
172
parent->myHierarchicalStructureChildren.add(element);
173
}
174
}
175
176
/// @brief insert child element
177
template<typename ElementType, typename ChildType>
178
static void insertChild(ElementType element, ChildType child) {
179
element->myHierarchicalStructureChildren.add(child);
180
child->myHierarchicalStructureParents.add(element);
181
}
182
183
/// @brief remove child element
184
template<typename ElementType, typename ChildType>
185
static void removeChild(ElementType element, ChildType child) {
186
element->myHierarchicalStructureChildren.remove(child);
187
child->myHierarchicalStructureParents.remove(element);
188
}
189
190
/// @brief update all children elements
191
template<typename ElementType, typename ChildType>
192
static void updateChildren(ElementType element, GNEHierarchicalContainerChildren<ChildType> newChildren) {
193
// remove children
194
for (const auto children : element->myHierarchicalStructureChildren.template get<ChildType>()) {
195
children->myHierarchicalStructureParents.remove(element);
196
}
197
// update children
198
element->myHierarchicalStructureChildren.replaceAll(newChildren);
199
// restore children
200
for (const auto children : element->myHierarchicalStructureChildren.template get<ChildType>()) {
201
children->myHierarchicalStructureParents.add(element);
202
}
203
}
204
205
/// @}
206
207
/// @name specific get functions
208
/// @{
209
210
/// @brief if use edge/parent lanes as a list of consecutive elements, obtain a list of IDs of elements after insert a new element
211
std::string getNewListOfParents(const GNENetworkElement* currentElement, const GNENetworkElement* newNextElement) const;
212
213
/// @}
214
215
private:
216
/// @brief hierarchical structure with parents
217
GNEHierarchicalStructureParents myHierarchicalStructureParents;
218
219
/// @brief hierarchical structure with children
220
GNEHierarchicalStructureChildren myHierarchicalStructureChildren;
221
222
/// @brief Invalidated copy constructor.
223
GNEHierarchicalElement(const GNEHierarchicalElement&) = delete;
224
};
225
226