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-2020 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  myHierarchicalConnections(this),
47  myHierarchicalContainer(parentJunctions, parentEdges, parentLanes, parentAdditionals, parentShapes, parentTAZElements, ParentDemandElements, parentGenericDatas) {
48 }
49 
50 
52 
53 
57 }
58 
59 
60 void
62  myHierarchicalContainer = container;
63 }
64 
65 
66 std::vector<GNEHierarchicalElement*>
68  // declare result
69  std::vector<GNEHierarchicalElement*> result;
70  // reserve
71  result.reserve(myHierarchicalContainer.getContainerSize());
72  // add parent elements
73  for (const auto& element : getParentJunctions()) {
74  result.push_back(element);
75  }
76  for (const auto& element : getParentEdges()) {
77  result.push_back(element);
78  }
79  for (const auto& element : getParentLanes()) {
80  result.push_back(element);
81  }
82  for (const auto& element : getParentAdditionals()) {
83  result.push_back(element);
84  }
85  for (const auto& element : getParentShapes()) {
86  result.push_back(element);
87  }
88  for (const auto& element : getParentTAZElements()) {
89  result.push_back(element);
90  }
91  for (const auto& element : getParentDemandElements()) {
92  result.push_back(element);
93  }
94  for (const auto& element : getParentGenericDatas()) {
95  result.push_back(element);
96  }
97  // add child elements
98  for (const auto& element : getChildJunctions()) {
99  result.push_back(element);
100  }
101  for (const auto& element : getChildEdges()) {
102  result.push_back(element);
103  }
104  for (const auto& element : getChildLanes()) {
105  result.push_back(element);
106  }
107  for (const auto& element : getChildAdditionals()) {
108  result.push_back(element);
109  }
110  for (const auto& element : getChildShapes()) {
111  result.push_back(element);
112  }
113  for (const auto& element : getChildTAZElements()) {
114  result.push_back(element);
115  }
116  for (const auto& element : getChildDemandElements()) {
117  result.push_back(element);
118  }
119  for (const auto& element : getChildGenericDatas()) {
120  result.push_back(element);
121  }
122  return result;
123 }
124 
125 
126 const std::vector<GNEJunction*>&
128  return myHierarchicalContainer.getParents<std::vector<GNEJunction*> >();
129 }
130 
131 
132 const std::vector<GNEEdge*>&
134  return myHierarchicalContainer.getParents<std::vector<GNEEdge*> >();
135 }
136 
137 
138 const std::vector<GNELane*>&
140  return myHierarchicalContainer.getParents<std::vector<GNELane*> >();
141 }
142 
143 
144 const std::vector<GNEAdditional*>&
146  return myHierarchicalContainer.getParents<std::vector<GNEAdditional*> >();
147 }
148 
149 
150 const std::vector<GNEShape*>&
152  return myHierarchicalContainer.getParents<std::vector<GNEShape*> >();
153 }
154 
155 
156 const std::vector<GNETAZElement*>&
158  return myHierarchicalContainer.getParents<std::vector<GNETAZElement*> >();
159 }
160 
161 
162 const std::vector<GNEDemandElement*>&
164  return myHierarchicalContainer.getParents<std::vector<GNEDemandElement*> >();
165 }
166 
167 
168 const std::vector<GNEGenericData*>&
170  return myHierarchicalContainer.getParents<std::vector<GNEGenericData*> >();
171 }
172 
173 
174 const std::vector<GNEJunction*>&
176  return myHierarchicalContainer.getChildren<std::vector<GNEJunction*> >();
177 }
178 
179 
180 const std::vector<GNEEdge*>&
182  return myHierarchicalContainer.getChildren<std::vector<GNEEdge*> >();
183 }
184 
185 
186 const std::vector<GNELane*>&
188  return myHierarchicalContainer.getChildren<std::vector<GNELane*> >();
189 }
190 
191 
192 const std::vector<GNEAdditional*>&
194  return myHierarchicalContainer.getChildren<std::vector<GNEAdditional*> >();
195 }
196 
197 
198 const std::vector<GNEShape*>&
200  return myHierarchicalContainer.getChildren<std::vector<GNEShape*> >();
201 }
202 
203 
204 const std::vector<GNETAZElement*>&
206  return myHierarchicalContainer.getChildren<std::vector<GNETAZElement*> >();
207 }
208 
209 
210 const std::vector<GNEDemandElement*>&
212  return myHierarchicalContainer.getChildren<std::vector<GNEDemandElement*> >();
213 }
214 
215 
216 const std::vector<GNEGenericData*>&
218  return myHierarchicalContainer.getChildren<std::vector<GNEGenericData*> >();
219 }
220 
221 
222 template<> void
224  // add parent element into container
226 }
227 
228 
229 template<> void
231  // add parent element into container
233 }
234 
235 
236 template<> void
238  // add parent element into container
240 }
241 
242 
243 template<> void
245  // add parent element into container
247  // update connections geometry
249 }
250 
251 
252 template<> void
254  // add parent element into container
256 }
257 
258 
259 template<> void
261  // add parent element into container
263 }
264 
265 
266 template<> void
268  // add parent element into container
270 }
271 
272 
273 template<> void
275  // add parent element into container
277 }
278 
279 
280 template<> void
282  // remove parent element from container
284 }
285 
286 
287 template<> void
289  // remove parent element from container
291 }
292 
293 
294 template<> void
296  // remove parent element from container
298 }
299 
300 
301 template<> void
303  // remove parent element from container
305  // update connections geometry
307 }
308 
309 
310 template<> void
312  // remove parent element from container
314 }
315 
316 
317 template<> void
319  // remove parent element from container
321 }
322 
323 
324 template<> void
326  // remove parent element from container
328 }
329 
330 
331 template<> void
333  // remove parent element from container
335 }
336 
337 
338 template<> void
340  // add child element into container
342 }
343 
344 
345 template<> void
347  // add child element into container
349 }
350 
351 
352 template<> void
354  // add child element into container
356 }
357 
358 
359 template<> void
361  // add child element into container
363  // update connections geometry
364  if (element->getTagProperty().isSlave()) {
366  }
367 }
368 
369 
370 template<> void
372  // add child element into container
374 }
375 
376 
377 template<> void
379  // add child element into container
381 }
382 
383 
384 template<> void
386  // add child element into container
388 }
389 
390 
391 template<> void
393  // add child element into container
395 }
396 
397 
398 template<> void
400  // remove child element from container
402 }
403 
404 
405 template<> void
407  // remove child element from container
409 }
410 
411 
412 template<> void
414  // remove child element from container
416 }
417 
418 
419 template<> void
421  // remove child element from container
423  // update connections geometry
424  if (element->getTagProperty().isSlave()) {
426  }
427 }
428 
429 
430 template<> void
432  // remove child element from container
434 }
435 
436 
437 template<> void
439  // remove child element from container
441 }
442 
443 
444 template<> void
446  // remove child element from container
448 }
449 
450 
451 template<> void
453  // remove child element from container
455 }
456 
457 
458 std::string
459 GNEHierarchicalElement::getNewListOfParents(const GNENetworkElement* currentElement, const GNENetworkElement* newNextElement) const {
460  std::vector<std::string> solution;
461  if ((currentElement->getTagProperty().getTag() == SUMO_TAG_EDGE) && (newNextElement->getTagProperty().getTag() == SUMO_TAG_EDGE)) {
462  // reserve solution
463  solution.reserve(getParentEdges().size());
464  // iterate over edges
465  for (const auto& edge : getParentEdges()) {
466  // add edge ID
467  solution.push_back(edge->getID());
468  // if current edge is the current element, then insert newNextElement ID
469  if (edge == currentElement) {
470  solution.push_back(newNextElement->getID());
471  }
472  }
473  } else if ((currentElement->getTagProperty().getTag() == SUMO_TAG_LANE) && (newNextElement->getTagProperty().getTag() == SUMO_TAG_LANE)) {
474  // reserve solution
475  solution.reserve(getParentLanes().size());
476  // iterate over lanes
477  for (const auto& lane : getParentLanes()) {
478  // add lane ID
479  solution.push_back(lane->getID());
480  // if current lane is the current element, then insert newNextElement ID
481  if (lane == currentElement) {
482  solution.push_back(newNextElement->getID());
483  }
484  }
485  }
486  // remove consecutive (adjacent) duplicates
487  solution.erase(std::unique(solution.begin(), solution.end()), solution.end());
488  // return solution
489  return toString(solution);
490 }
491 
492 
493 void
496 }
497 
498 
499 void
501  // first check if connections can be drawn
502  if (!s.drawForPositionSelection && !s.drawForRectangleSelection && (exaggeration > 0)) {
503  myHierarchicalConnections.drawConnection(s, AC, exaggeration);
504  // check if we have to draw dotted inspect contour
507  }
508  // check if we have to draw dotted fronto contour
509  if (s.drawDottedContour() || (AC->getNet()->getViewNet()->getFrontAttributeCarrier() == AC)) {
511  }
512  }
513 }
514 
515 
516 bool
518  // declare a vector to keep sorted children
519  std::vector<std::pair<std::pair<double, double>, GNEAdditional*> > sortedChildren;
520  // iterate over child additional
521  for (const auto& additional : getChildAdditionals()) {
522  sortedChildren.push_back(std::make_pair(std::make_pair(0., 0.), additional));
523  // set begin/start attribute
524  if (additional->getTagProperty().hasAttribute(SUMO_ATTR_TIME) && GNEAttributeCarrier::canParse<double>(additional->getAttribute(SUMO_ATTR_TIME))) {
525  sortedChildren.back().first.first = additional->getAttributeDouble(SUMO_ATTR_TIME);
526  } else if (additional->getTagProperty().hasAttribute(SUMO_ATTR_BEGIN) && GNEAttributeCarrier::canParse<double>(additional->getAttribute(SUMO_ATTR_BEGIN))) {
527  sortedChildren.back().first.first = additional->getAttributeDouble(SUMO_ATTR_BEGIN);
528  }
529  // set end attribute
530  if (additional->getTagProperty().hasAttribute(SUMO_ATTR_END) && GNEAttributeCarrier::canParse<double>(additional->getAttribute(SUMO_ATTR_END))) {
531  sortedChildren.back().first.second = additional->getAttributeDouble(SUMO_ATTR_END);
532  } else {
533  sortedChildren.back().first.second = sortedChildren.back().first.first;
534  }
535  }
536  // sort children
537  std::sort(sortedChildren.begin(), sortedChildren.end());
538  // make sure that number of sorted children is the same as the child additional
539  if (sortedChildren.size() == getChildAdditionals().size()) {
540  if (sortedChildren.size() <= 1) {
541  return true;
542  } else {
543  // check overlapping
544  for (int i = 0; i < (int)sortedChildren.size() - 1; i++) {
545  if (sortedChildren.at(i).first.second > sortedChildren.at(i + 1).first.first) {
546  return false;
547  }
548  }
549  }
550  return true;
551  } else {
552  throw ProcessError("Some child additional were lost during sorting");
553  }
554 }
555 
556 
557 bool
559  return true;
560 }
561 
562 
563 void
565  // by default nothing to do
566 }
567 
568 /****************************************************************************/
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:44
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
virtual double getAttributeDouble(SumoXMLAttr key) const =0
const GNETagProperties & getTagProperty() const
get Tag Property assigned to this object
GNENet * getNet() const
get pointer to net
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:49
An Element which don't belongs to GNENet but has influency in the simulation.
void drawConnection(const GUIVisualizationSettings &s, const GNEAttributeCarrier *AC, const double exaggeration) const
draw connections between Parent and childrens
void update()
update Connection's geometry
void drawDottedConnection(const DottedContourType type, const GUIVisualizationSettings &s, const double exaggeration) const
draw dotted connections between Parent and childrens
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
void drawHierarchicalConnections(const GUIVisualizationSettings &s, const GNEAttributeCarrier *AC, const double exaggeration) const
Draw hierarchical connections between parent and children.
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
void updateHierarchicalConnections()
update child connections
virtual void updateParentAdditional()
update parent after add or remove a child (can be reimplemented, for example used for statistics)
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
GNEGeometry::HierarchicalConnections myHierarchicalConnections
hierarchical connections
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:45
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:40
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
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
bool isSlave() const
return true if tag correspond to an element slave of another element (I.e. doesn't have their own ID)
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
Stores the information about how to visualize structures.
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
bool drawDottedContour() const
check if dotted contour can be drawn