Eclipse SUMO - Simulation of Urban MObility
GNEHierarchicalElement.h
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 #pragma once
21 #include <config.h>
22 
25 
27 
28 
29 // ===========================================================================
30 // class definitions
31 // ===========================================================================
32 
38 
39 public:
41  friend class GNEChange_Children;
42  friend class GNEDemandElement;
43 
55  const std::vector<GNEJunction*>& parentJunctions,
56  const std::vector<GNEEdge*>& parentEdges,
57  const std::vector<GNELane*>& parentLanes,
58  const std::vector<GNEAdditional*>& parentAdditionals,
59  const std::vector<GNEDemandElement*>& parentDemandElements,
60  const std::vector<GNEGenericData*>& parentGenericDatas);
61 
64 
67  return this;
68  }
69 
73  virtual void updateGeometry() = 0;
74 
76  virtual Position getPositionInView() const = 0;
78 
81 
84 
87 
89  std::vector<GNEHierarchicalElement*> getAllHierarchicalElements() const;
90 
92  const std::vector<GNEJunction*>& getParentJunctions() const;
93 
95  const std::vector<GNEEdge*>& getParentEdges() const;
96 
98  const std::vector<GNELane*>& getParentLanes() const;
99 
101  const std::vector<GNEAdditional*>& getParentAdditionals() const;
102 
104  const std::vector<GNEDemandElement*>& getParentDemandElements() const;
105 
107  const std::vector<GNEGenericData*>& getParentGenericDatas() const;
108 
110  const std::vector<GNEJunction*>& getChildJunctions() const;
111 
113  const std::vector<GNEEdge*>& getChildEdges() const;
114 
116  const std::vector<GNELane*>& getChildLanes() const;
117 
119  const std::vector<GNEAdditional*>& getChildAdditionals() const;
120 
122  const std::vector<GNEDemandElement*>& getChildDemandElements() const;
123 
125  const std::vector<GNEGenericData*>& getChildGenericDatas() const;
127 
130 
132  template<typename T>
133  void addParentElement(T* element);
134 
136  template<typename T>
137  void removeParentElement(T* element);
138 
140  template<typename T>
141  void addChildElement(T* element);
142 
144  template<typename T>
145  void removeChildElement(T* element);
147 
150 
152  std::string getNewListOfParents(const GNENetworkElement* currentElement, const GNENetworkElement* newNextElement) const;
153 
155 
158 
161 
162 protected:
164  template<typename T, typename U>
165  void replaceParentElements(T* elementChild, const U& newParents) {
166  // remove elementChild from parents
167  for (const auto& parent : myHierarchicalContainer.getParents<U>()) {
168  parent->removeChildElement(elementChild);
169  }
170  // set new parents junctions
172  // add elementChild into new parents
173  for (const auto& parent : myHierarchicalContainer.getParents<U>()) {
174  parent->addChildElement(elementChild);
175  }
176  }
177 
179  template<typename T, typename U>
180  void replaceChildElements(T* elementChild, const U& newChildren) {
181  // remove elementChild from childs
182  for (const auto& child : myHierarchicalContainer.getChildren<U>()) {
183  child->removeChildElement(elementChild);
184  }
185  // set new childs junctions
187  // add elementChild into new childs
188  for (const auto& child : myHierarchicalContainer.getChildren<U>()) {
189  child->addChildElement(elementChild);
190  }
191  }
192 
193 private:
196 
199 
202 };
SumoXMLTag
Numbers representing SUMO-XML - element names.
Hierarchical container (used for keep myParent and myChildren.
const T & getParents() const
get parents
const T & getChildren() const
get children
void setChildren(const T &newChildren)
set children
void setParents(const T &newParents)
set 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
virtual Position getPositionInView() const =0
Returns position of hierarchical element in view.
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...
virtual void updateGeometry()=0
update pre-computed geometry information
GNEHierarchicalElement(const GNEHierarchicalElement &)=delete
Invalidated copy constructor.
const std::vector< GNEJunction * > & getChildJunctions() const
get child junctions
const std::vector< GNELane * > & getParentLanes() const
get parent lanes
GNEHierarchicalElement * getHierarchicalElement()
get GNEHierarchicalElement associated with this AttributeCarrier
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
void replaceParentElements(T *elementChild, const U &newParents)
replace parent elements
GNEHierarchicalElement & operator=(const GNEHierarchicalElement &)=delete
Invalidated assignment operator.
void replaceChildElements(T *elementChild, const U &newChildren)
replace child elements
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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37