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.org/sumo
3 // Copyright (C) 2001-2022 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 #include <netedit/GNEViewNet.h>
24 
25 
26 #include "GNEHierarchicalElement.h"
27 
28 // ===========================================================================
29 // member method definitions
30 // ===========================================================================
31 
32 // ---------------------------------------------------------------------------
33 // GNEHierarchicalElement - methods
34 // ---------------------------------------------------------------------------
35 
37  const std::vector<GNEJunction*>& parentJunctions,
38  const std::vector<GNEEdge*>& parentEdges,
39  const std::vector<GNELane*>& parentLanes,
40  const std::vector<GNEAdditional*>& parentAdditionals,
41  const std::vector<GNEShape*>& parentShapes,
42  const std::vector<GNETAZElement*>& parentTAZElements,
43  const std::vector<GNEDemandElement*>& ParentDemandElements,
44  const std::vector<GNEGenericData*>& parentGenericDatas) :
45  GNEAttributeCarrier(tag, net),
46  myHierarchicalContainer(parentJunctions, parentEdges, parentLanes, parentAdditionals, parentShapes, parentTAZElements, ParentDemandElements, parentGenericDatas) {
47 }
48 
49 
51 
52 
56 }
57 
58 
59 void
61  myHierarchicalContainer = container;
62 }
63 
64 
65 std::vector<GNEHierarchicalElement*>
67  // declare result
68  std::vector<GNEHierarchicalElement*> result;
69  // reserve
70  result.reserve(myHierarchicalContainer.getContainerSize());
71  // add parent elements
72  for (const auto& element : getParentJunctions()) {
73  result.push_back(element);
74  }
75  for (const auto& element : getParentEdges()) {
76  result.push_back(element);
77  }
78  for (const auto& element : getParentLanes()) {
79  result.push_back(element);
80  }
81  for (const auto& element : getParentAdditionals()) {
82  result.push_back(element);
83  }
84  for (const auto& element : getParentShapes()) {
85  result.push_back(element);
86  }
87  for (const auto& element : getParentTAZElements()) {
88  result.push_back(element);
89  }
90  for (const auto& element : getParentDemandElements()) {
91  result.push_back(element);
92  }
93  for (const auto& element : getParentGenericDatas()) {
94  result.push_back(element);
95  }
96  // add child elements
97  for (const auto& element : getChildJunctions()) {
98  result.push_back(element);
99  }
100  for (const auto& element : getChildEdges()) {
101  result.push_back(element);
102  }
103  for (const auto& element : getChildLanes()) {
104  result.push_back(element);
105  }
106  for (const auto& element : getChildAdditionals()) {
107  result.push_back(element);
108  }
109  for (const auto& element : getChildShapes()) {
110  result.push_back(element);
111  }
112  for (const auto& element : getChildTAZElements()) {
113  result.push_back(element);
114  }
115  for (const auto& element : getChildDemandElements()) {
116  result.push_back(element);
117  }
118  for (const auto& element : getChildGenericDatas()) {
119  result.push_back(element);
120  }
121  return result;
122 }
123 
124 
125 const std::vector<GNEJunction*>&
127  return myHierarchicalContainer.getParents<std::vector<GNEJunction*> >();
128 }
129 
130 
131 const std::vector<GNEEdge*>&
133  return myHierarchicalContainer.getParents<std::vector<GNEEdge*> >();
134 }
135 
136 
137 const std::vector<GNELane*>&
139  return myHierarchicalContainer.getParents<std::vector<GNELane*> >();
140 }
141 
142 
143 const std::vector<GNEAdditional*>&
145  return myHierarchicalContainer.getParents<std::vector<GNEAdditional*> >();
146 }
147 
148 
149 const std::vector<GNEShape*>&
151  return myHierarchicalContainer.getParents<std::vector<GNEShape*> >();
152 }
153 
154 
155 const std::vector<GNETAZElement*>&
157  return myHierarchicalContainer.getParents<std::vector<GNETAZElement*> >();
158 }
159 
160 
161 const std::vector<GNEDemandElement*>&
163  return myHierarchicalContainer.getParents<std::vector<GNEDemandElement*> >();
164 }
165 
166 
167 const std::vector<GNEGenericData*>&
169  return myHierarchicalContainer.getParents<std::vector<GNEGenericData*> >();
170 }
171 
172 
173 const std::vector<GNEJunction*>&
175  return myHierarchicalContainer.getChildren<std::vector<GNEJunction*> >();
176 }
177 
178 
179 const std::vector<GNEEdge*>&
181  return myHierarchicalContainer.getChildren<std::vector<GNEEdge*> >();
182 }
183 
184 
185 const std::vector<GNELane*>&
187  return myHierarchicalContainer.getChildren<std::vector<GNELane*> >();
188 }
189 
190 
191 const std::vector<GNEAdditional*>&
193  return myHierarchicalContainer.getChildren<std::vector<GNEAdditional*> >();
194 }
195 
196 
197 const std::vector<GNEShape*>&
199  return myHierarchicalContainer.getChildren<std::vector<GNEShape*> >();
200 }
201 
202 
203 const std::vector<GNETAZElement*>&
205  return myHierarchicalContainer.getChildren<std::vector<GNETAZElement*> >();
206 }
207 
208 
209 const std::vector<GNEDemandElement*>&
211  return myHierarchicalContainer.getChildren<std::vector<GNEDemandElement*> >();
212 }
213 
214 
215 const std::vector<GNEGenericData*>&
217  return myHierarchicalContainer.getChildren<std::vector<GNEGenericData*> >();
218 }
219 
220 
221 template<> void
223  // add parent element into container
225 }
226 
227 
228 template<> void
230  // add parent element into container
232 }
233 
234 
235 template<> void
237  // add parent element into container
239 }
240 
241 
242 template<> void
244  // add parent element into container
246 }
247 
248 
249 template<> void
251  // add parent element into container
253 }
254 
255 
256 template<> void
258  // add parent element into container
260 }
261 
262 
263 template<> void
265  // add parent element into container
267 }
268 
269 
270 template<> void
272  // add parent element into container
274 }
275 
276 
277 template<> void
279  // remove parent element from container
281 }
282 
283 
284 template<> void
286  // remove parent element from container
288 }
289 
290 
291 template<> void
293  // remove parent element from container
295 }
296 
297 
298 template<> void
300  // remove parent element from container
302 }
303 
304 
305 template<> void
307  // remove parent element from container
309 }
310 
311 
312 template<> void
314  // remove parent element from container
316 }
317 
318 
319 template<> void
321  // remove parent element from container
323 }
324 
325 
326 template<> void
328  // remove parent element from container
330 }
331 
332 
333 template<> void
335  // add child element into container
337 }
338 
339 
340 template<> void
342  // add child element into container
344 }
345 
346 
347 template<> void
349  // add child element into container
351 }
352 
353 
354 template<> void
356  // add child element into container
358 }
359 
360 
361 template<> void
363  // add child element into container
365 }
366 
367 
368 template<> void
370  // add child element into container
372 }
373 
374 
375 template<> void
377  // add child element into container
379 }
380 
381 
382 template<> void
384  // add child element into container
386 }
387 
388 
389 template<> void
391  // remove child element from container
393 }
394 
395 
396 template<> void
398  // remove child element from container
400 }
401 
402 
403 template<> void
405  // remove child element from container
407 }
408 
409 
410 template<> void
412  // remove child element from container
414 }
415 
416 
417 template<> void
419  // remove child element from container
421 }
422 
423 
424 template<> void
426  // remove child element from container
428 }
429 
430 
431 template<> void
433  // remove child element from container
435 }
436 
437 
438 template<> void
440  // remove child element from container
442 }
443 
444 
445 std::string
446 GNEHierarchicalElement::getNewListOfParents(const GNENetworkElement* currentElement, const GNENetworkElement* newNextElement) const {
447  std::vector<std::string> solution;
448  if ((currentElement->getTagProperty().getTag() == SUMO_TAG_EDGE) && (newNextElement->getTagProperty().getTag() == SUMO_TAG_EDGE)) {
449  // reserve solution
450  solution.reserve(getParentEdges().size());
451  // iterate over edges
452  for (const auto& edge : getParentEdges()) {
453  // add edge ID
454  solution.push_back(edge->getID());
455  // if current edge is the current element, then insert newNextElement ID
456  if (edge == currentElement) {
457  solution.push_back(newNextElement->getID());
458  }
459  }
460  } else if ((currentElement->getTagProperty().getTag() == SUMO_TAG_LANE) && (newNextElement->getTagProperty().getTag() == SUMO_TAG_LANE)) {
461  // reserve solution
462  solution.reserve(getParentLanes().size());
463  // iterate over lanes
464  for (const auto& lane : getParentLanes()) {
465  // add lane ID
466  solution.push_back(lane->getID());
467  // if current lane is the current element, then insert newNextElement ID
468  if (lane == currentElement) {
469  solution.push_back(newNextElement->getID());
470  }
471  }
472  }
473  // remove consecutive (adjacent) duplicates
474  solution.erase(std::unique(solution.begin(), solution.end()), solution.end());
475  // return solution
476  return toString(solution);
477 }
478 
479 
480 bool
482  // declare a vector to keep sorted children
483  std::vector<std::pair<std::pair<double, double>, GNEAdditional*> > sortedChildren;
484  // iterate over child additional
485  for (const auto& additional : getChildAdditionals()) {
486  sortedChildren.push_back(std::make_pair(std::make_pair(0., 0.), additional));
487  // set begin/start attribute
488  if (additional->getTagProperty().hasAttribute(SUMO_ATTR_TIME) && GNEAttributeCarrier::canParse<double>(additional->getAttribute(SUMO_ATTR_TIME))) {
489  sortedChildren.back().first.first = additional->getAttributeDouble(SUMO_ATTR_TIME);
490  } else if (additional->getTagProperty().hasAttribute(SUMO_ATTR_BEGIN) && GNEAttributeCarrier::canParse<double>(additional->getAttribute(SUMO_ATTR_BEGIN))) {
491  sortedChildren.back().first.first = additional->getAttributeDouble(SUMO_ATTR_BEGIN);
492  }
493  // set end attribute
494  if (additional->getTagProperty().hasAttribute(SUMO_ATTR_END) && GNEAttributeCarrier::canParse<double>(additional->getAttribute(SUMO_ATTR_END))) {
495  sortedChildren.back().first.second = additional->getAttributeDouble(SUMO_ATTR_END);
496  } else {
497  sortedChildren.back().first.second = sortedChildren.back().first.first;
498  }
499  }
500  // sort children
501  std::sort(sortedChildren.begin(), sortedChildren.end());
502  // make sure that number of sorted children is the same as the child additional
503  if (sortedChildren.size() == getChildAdditionals().size()) {
504  if (sortedChildren.size() <= 1) {
505  return true;
506  } else {
507  // check overlapping
508  for (int i = 0; i < (int)sortedChildren.size() - 1; i++) {
509  if (sortedChildren.at(i).first.second > sortedChildren.at(i + 1).first.first) {
510  return false;
511  }
512  }
513  }
514  return true;
515  } else {
516  throw ProcessError("Some child additional were lost during sorting");
517  }
518 }
519 
520 
521 bool
523  return true;
524 }
525 
526 /****************************************************************************/
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 belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
virtual double getAttributeDouble(SumoXMLAttr key) const =0
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
An Element which don't belongs to GNENet but has influency in the simulation.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:53
An Element which don't belongs to GNENet but has influency 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< GNETAZElement * > & getChildTAZElements() const
get child TAZElements
const std::vector< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
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
const std::vector< GNEShape * > & getParentShapes() const
get parent shapes
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
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< GNEShape * > &parentShapes, const std::vector< GNETAZElement * > &parentTAZElements, const std::vector< GNEDemandElement * > &parentDemandElements, const std::vector< GNEGenericData * > &parentGenericDatas)
Constructor.
const std::vector< GNELane * > & getParentLanes() const
get parent lanes
const std::vector< GNEShape * > & getChildShapes() const
get child shapes
const std::vector< GNETAZElement * > & getParentTAZElements() const
get parent TAZElements
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
const std::string & getID() const
get ID
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNETAZElement.h:45
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property