1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    GNEHierarchicalElementChilds.h
11 /// @author  Pablo Alvarez Lopez
12 /// @date    March 2019
13 /// @version $Id$
14 ///
15 // A abstract class for representation of Hierarchical Elements
16 /****************************************************************************/
17 #ifndef GNEHierarchicalElementChilds_h
18 #define GNEHierarchicalElementChilds_h
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 
24 #include <config.h>
25 
26 #include <utils/gui/globjects/GUIGlObjectTypes.h>
27 
28 #include "GNEAttributeCarrier.h"
29 
30 // ===========================================================================
31 // class declarations
32 // ===========================================================================
33 
34 class GNEAdditional;
35 class GNEDemandElement;
36 class GNEShape;
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
41 
42 /**
43  * @class GNEHierarchicalElementChilds
44  * @brief An special type of Attribute carrier that owns hierarchical elements
45  */
46 class GNEHierarchicalElementChilds {
47 
48 public:
49     /**@brief Parameter Constructor
50      * @param[in] edgeChilds vector of edge childs
51      * @param[in] laneChilds vector of lane childs
52      * @param[in] shapeChilds vector of shape childs
53      * @param[in] additionalChilds vector of additional childs
54      * @param[in] demandElementChilds vector of demand element childs
55      */
56     GNEHierarchicalElementChilds(GNEAttributeCarrier* AC,
57                                  const std::vector<GNEEdge*>& edgeChilds,
58                                  const std::vector<GNELane*>& laneChilds,
59                                  const std::vector<GNEShape*>& shapeChilds,
60                                  const std::vector<GNEAdditional*>& additionalChilds,
61                                  const std::vector<GNEDemandElement*>& demandElementChilds);
62 
63     /// @brief Destructor
64     ~GNEHierarchicalElementChilds();
65 
66     /// @brief gererate a new ID for an element child
67     virtual std::string generateChildID(SumoXMLTag childTag) = 0;
68 
69     /// @name Functions related with geometry of element
70     /// @{
71     /// @brief update pre-computed geometry information
72     virtual void updateGeometry(bool updateGrid) = 0;
73 
74     /// @brief Returns position of hierarchical element in view
75     virtual Position getPositionInView() const = 0;
76     /// @}
77 
78     /// @name members and functions related to edge childs
79     /// @{
80     /// @brief add edge child
81     void addEdgeChild(GNEEdge* edge);
82 
83     /// @brief remove edge child
84     void removeEdgeChild(GNEEdge* edge);
85 
86     /// @brief get edge chidls
87     const std::vector<GNEEdge*>& getEdgeChilds() const;
88 
89     /// @}
90 
91     /// @name members and functions related to lane childs
92     /// @{
93     /// @brief add lane child
94     void addLaneChild(GNELane* lane);
95 
96     /// @brief remove lane child
97     void removeLaneChild(GNELane* lane);
98 
99     /// @brief get lanes of VSS
100     const std::vector<GNELane*>& getLaneChilds() const;
101 
102     /// @}
103 
104     /// @name members and functions related to shape childs
105     /// @{
106     /// @brief add shape child
107     void addShapeChild(GNEShape* shape);
108 
109     /// @brief remove shape child
110     void removeShapeChild(GNEShape* shape);
111 
112     /// @brief get shapes of VSS
113     const std::vector<GNEShape*>& getShapeChilds() const;
114 
115     /// @}
116 
117     /// @name members and functions related to additional childs
118     /// @{
119     /// @brief add additional child to this additional
120     void addAdditionalChild(GNEAdditional* additional);
121 
122     /// @brief remove additional child from this additional
123     void removeAdditionalChild(GNEAdditional* additional);
124 
125     /// @brief return vector of additionals that have as Parent this edge (For example, Calibrators)
126     const std::vector<GNEAdditional*>& getAdditionalChilds() const;
127 
128     /// @brief sort childs (used by Rerouters, VSS, TAZs...)
129     void sortAdditionalChilds();
130 
131     /// @brief check if childs are overlapped (Used by Rerouters)
132     bool checkAdditionalChildsOverlapping() const;
133 
134     /// @}
135 
136     /// @name members and functions related to demand element childs
137     /// @{
138     /// @brief add demand element child to this demand element
139     void addDemandElementChild(GNEDemandElement* demandElement);
140 
141     /// @brief remove demand element child from this demand element
142     void removeDemandElementChild(GNEDemandElement* demandElement);
143 
144     /// @brief return vector of demand elements that have as Parent this edge (For example, Calibrators)
145     const std::vector<GNEDemandElement*>& getDemandElementChilds() const;
146 
147     /// @brief sort childs (used by Rerouters, VSS, TAZs...)
148     void sortDemandElementChilds();
149 
150     /// @brief check if childs are overlapped (Used by Rerouters)
151     bool checkDemandElementChildsOverlapping() const;
152 
153     /// @}
154 
155     /// @brief update parent after add or remove a child (can be reimplemented, for example used for statistics)
156     virtual void updateAdditionalParent();
157 
158     /// @brief update parent after add or remove a child (can be reimplemented, for example used for statistics)
159     virtual void updateDemandElementParent();
160 
161 protected:
162 
163     /// @brief struct for pack all variables and functions relative to connections between hierarchical element and their childs
164     struct ChildConnections {
165         /// @brief constructor
166         ChildConnections(GNEHierarchicalElementChilds* hierarchicalElement);
167 
168         /// @brief update Connection's geometry
169         void update();
170 
171         /// @brief draw connections between Parent and childrens
172         void draw(GUIGlObjectType parentType) const;
173 
174         /// @brief position and rotation of every symbol over lane
175         std::vector<std::pair<Position, double> > symbolsPositionAndRotation;
176 
177         /// @brief Matrix with the Vertex's positions of connections between parents an their childs
178         std::vector<PositionVector> connectionPositions;
179 
180     private:
181         /// @brief pointer to hierarchical element parent
182         GNEHierarchicalElementChilds* myHierarchicalElement;
183     };
184 
185     /// @brief change edge childs of an additional
186     void changeEdgeChilds(GNEAdditional* elementChild, const std::string& newEdgeIDs);
187 
188     /// @brief change edge childs of an additional
189     void changeLaneChilds(GNEAdditional* elementChild, const std::string& newEdgeIDs);
190 
191     /// @brief variable ChildConnections
192     ChildConnections myChildConnections;
193 
194 private:
195     /// @brief vector with the edge childs of this element
196     std::vector<GNEEdge*> myEdgeChilds;
197 
198     /// @brief vector with the lane childs of this element
199     std::vector<GNELane*> myLaneChilds;
200 
201     /// @brief vector with the lane childs of this element
202     std::vector<GNEShape*> myShapeChilds;
203 
204     /// @brief vector with the additional childs
205     std::vector<GNEAdditional*> myAdditionalChilds;
206 
207     /// @brief vector with the demand elements childs
208     std::vector<GNEDemandElement*> myDemandElementChilds;
209 
210     /// @brief pointer to AC (needed to avoid diamond problem)
211     GNEAttributeCarrier* myAC;
212 
213     /// @brief Invalidated copy constructor.
214     GNEHierarchicalElementChilds(const GNEHierarchicalElementChilds&) = delete;
215 
216     /// @brief Invalidated assignment operator.
217     GNEHierarchicalElementChilds& operator=(const GNEHierarchicalElementChilds&) = delete;
218 };
219 
220 #endif
221