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.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 #include <config.h>
21 
22 #include <netedit/GNENet.h>
23 
24 
25 #include "GNEHierarchicalElement.h"
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 
56 void
58  myHierarchicalContainer = container;
59 }
60 
61 
62 std::vector<GNEHierarchicalElement*>
64  // declare result
65  std::vector<GNEHierarchicalElement*> result;
66  // reserve
67  result.reserve(myHierarchicalContainer.getContainerSize());
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 
110 const std::vector<GNEJunction*>&
112  return myHierarchicalContainer.getParents<std::vector<GNEJunction*> >();
113 }
114 
115 
116 const std::vector<GNEEdge*>&
118  return myHierarchicalContainer.getParents<std::vector<GNEEdge*> >();
119 }
120 
121 
122 const std::vector<GNELane*>&
124  return myHierarchicalContainer.getParents<std::vector<GNELane*> >();
125 }
126 
127 
128 const std::vector<GNEAdditional*>&
130  return myHierarchicalContainer.getParents<std::vector<GNEAdditional*> >();
131 }
132 
133 
134 const std::vector<GNEAdditional*>
136  std::vector<GNEAdditional*> stoppingPlaces;
137  for (const auto& additional : getParentAdditionals()) {
138  if (additional->getTagProperty().isStoppingPlace()) {
139  stoppingPlaces.push_back(additional);
140  }
141  }
142  return stoppingPlaces;
143 }
144 
145 
146 const std::vector<GNEAdditional*>
148  std::vector<GNEAdditional*> TAZs;
149  for (const auto& additional : getParentAdditionals()) {
150  if (additional->getTagProperty().isTAZElement()) {
151  TAZs.push_back(additional);
152  }
153  }
154  return TAZs;
155 }
156 
157 
158 const std::vector<GNEDemandElement*>&
160  return myHierarchicalContainer.getParents<std::vector<GNEDemandElement*> >();
161 }
162 
163 
164 const std::vector<GNEGenericData*>&
166  return myHierarchicalContainer.getParents<std::vector<GNEGenericData*> >();
167 }
168 
169 
170 const std::vector<GNEJunction*>&
172  return myHierarchicalContainer.getChildren<std::vector<GNEJunction*> >();
173 }
174 
175 
176 const std::vector<GNEEdge*>&
178  return myHierarchicalContainer.getChildren<std::vector<GNEEdge*> >();
179 }
180 
181 
182 const std::vector<GNELane*>&
184  return myHierarchicalContainer.getChildren<std::vector<GNELane*> >();
185 }
186 
187 
188 const std::vector<GNEAdditional*>&
190  return myHierarchicalContainer.getChildren<std::vector<GNEAdditional*> >();
191 }
192 
193 
194 const std::vector<GNEDemandElement*>&
196  return myHierarchicalContainer.getChildren<std::vector<GNEDemandElement*> >();
197 }
198 
199 
200 const std::vector<GNEGenericData*>&
202  return myHierarchicalContainer.getChildren<std::vector<GNEGenericData*> >();
203 }
204 
205 
206 template<> void
208  // add parent element into container
210 }
211 
212 
213 template<> void
215  // add parent element into container
217 }
218 
219 
220 template<> void
222  // add parent element into container
224 }
225 
226 
227 template<> void
229  // add parent element into container
231 }
232 
233 
234 template<> void
236  // add parent element into container
238 }
239 
240 
241 template<> void
243  // add parent element into container
245 }
246 
247 
248 template<> void
250  // remove parent element from container
252 }
253 
254 
255 template<> void
257  // remove parent element from container
259 }
260 
261 
262 template<> void
264  // remove parent element from container
266 }
267 
268 
269 template<> void
271  // remove parent element from container
273 }
274 
275 
276 template<> void
278  // remove parent element from container
280 }
281 
282 
283 template<> void
285  // remove parent element from container
287 }
288 
289 
290 template<> void
292  // add child element into container
294 }
295 
296 
297 template<> void
299  // add child element into container
301 }
302 
303 
304 template<> void
306  // add child element into container
308 }
309 
310 
311 template<> void
313  // add child element into container
315 }
316 
317 
318 template<> void
320  // add child element into container
322 }
323 
324 
325 template<> void
327  // add child element into container
329 }
330 
331 
332 template<> void
334  // remove child element from container
336 }
337 
338 
339 template<> void
341  // remove child element from container
343 }
344 
345 
346 template<> void
348  // remove child element from container
350 }
351 
352 
353 template<> void
355  // remove child element from container
357 }
358 
359 
360 template<> void
362  // remove child element from container
364 }
365 
366 
367 template<> void
369  // remove child element from container
371 }
372 
373 
374 std::string
375 GNEHierarchicalElement::getNewListOfParents(const GNENetworkElement* currentElement, const GNENetworkElement* newNextElement) const {
376  std::vector<std::string> solution;
377  if ((currentElement->getTagProperty().getTag() == SUMO_TAG_EDGE) && (newNextElement->getTagProperty().getTag() == SUMO_TAG_EDGE)) {
378  // reserve solution
379  solution.reserve(getParentEdges().size());
380  // iterate over edges
381  for (const auto& edge : getParentEdges()) {
382  // add edge ID
383  solution.push_back(edge->getID());
384  // if current edge is the current element, then insert newNextElement ID
385  if (edge == currentElement) {
386  solution.push_back(newNextElement->getID());
387  }
388  }
389  } else if ((currentElement->getTagProperty().getTag() == SUMO_TAG_LANE) && (newNextElement->getTagProperty().getTag() == SUMO_TAG_LANE)) {
390  // reserve solution
391  solution.reserve(getParentLanes().size());
392  // iterate over lanes
393  for (const auto& lane : getParentLanes()) {
394  // add lane ID
395  solution.push_back(lane->getID());
396  // if current lane is the current element, then insert newNextElement ID
397  if (lane == currentElement) {
398  solution.push_back(newNextElement->getID());
399  }
400  }
401  }
402  // remove consecutive (adjacent) duplicates
403  solution.erase(std::unique(solution.begin(), solution.end()), solution.end());
404  // return solution
405  return toString(solution);
406 }
407 
408 
409 bool
411  // declare a vector to keep sorted children
412  std::vector<std::pair<std::pair<double, double>, GNEAdditional*> > sortedChildren;
413  // iterate over child meanData
414  for (const auto& meanData : getChildAdditionals()) {
415  sortedChildren.push_back(std::make_pair(std::make_pair(0., 0.), meanData));
416  // set begin/start attribute
417  if (meanData->getTagProperty().hasAttribute(SUMO_ATTR_TIME) && GNEAttributeCarrier::canParse<double>(meanData->getAttribute(SUMO_ATTR_TIME))) {
418  sortedChildren.back().first.first = meanData->getAttributeDouble(SUMO_ATTR_TIME);
419  } else if (meanData->getTagProperty().hasAttribute(SUMO_ATTR_BEGIN) && GNEAttributeCarrier::canParse<double>(meanData->getAttribute(SUMO_ATTR_BEGIN))) {
420  sortedChildren.back().first.first = meanData->getAttributeDouble(SUMO_ATTR_BEGIN);
421  }
422  // set end attribute
423  if (meanData->getTagProperty().hasAttribute(SUMO_ATTR_END) && GNEAttributeCarrier::canParse<double>(meanData->getAttribute(SUMO_ATTR_END))) {
424  sortedChildren.back().first.second = meanData->getAttributeDouble(SUMO_ATTR_END);
425  } else {
426  sortedChildren.back().first.second = sortedChildren.back().first.first;
427  }
428  }
429  // sort children
430  std::sort(sortedChildren.begin(), sortedChildren.end());
431  // make sure that number of sorted children is the same as the child meanData
432  if (sortedChildren.size() == getChildAdditionals().size()) {
433  if (sortedChildren.size() <= 1) {
434  return true;
435  } else {
436  // check overlapping
437  for (int i = 0; i < (int)sortedChildren.size() - 1; i++) {
438  if (sortedChildren.at(i).first.second > sortedChildren.at(i + 1).first.first) {
439  return false;
440  }
441  }
442  }
443  return true;
444  } else {
445  throw ProcessError(TL("Some child meanData were lost during sorting"));
446  }
447 }
448 
449 
450 bool
452  return true;
453 }
454 
455 /****************************************************************************/
#define TL(string)
Definition: MsgHandler.h:315
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:49
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
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 & getParents() const
get parents
void addChildElement(const GNEHierarchicalElement *hierarchicalElement, T *element)
add child element
const T & getChildren() const
get children
void removeParentElement(const GNEHierarchicalElement *hierarchicalElement, T *element)
remove parent element
void removeChildElement(const GNEHierarchicalElement *hierarchicalElement, T *element)
remove child element
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< GNEAdditional * > getParentStoppingPlaces() const
get parent stoppingPlaces (used by plans)
const std::vector< GNEAdditional * > getParentTAZs() const
get parent TAZs (used by plans)
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