Path: blob/main/src/netedit/elements/GNEHierarchicalElement.cpp
169678 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GNEHierarchicalElement.cpp14/// @author Pablo Alvarez Lopez15/// @date Jul 202016///17// A abstract class for representation of hierarchical elements18/****************************************************************************/1920#include <netedit/GNENet.h>21#include <netedit/GNETagProperties.h>2223#include "GNEHierarchicalElement.h"2425// ===========================================================================26// member method definitions27// ===========================================================================2829// ---------------------------------------------------------------------------30// GNEHierarchicalElement - methods31// ---------------------------------------------------------------------------3233GNEHierarchicalElement::GNEHierarchicalElement() {}343536GNEHierarchicalElement::~GNEHierarchicalElement() {}373839const GNEHierarchicalStructureParents&40GNEHierarchicalElement::getParents() const {41return myHierarchicalStructureParents;42}434445void46GNEHierarchicalElement::clearParents() {47myHierarchicalStructureParents.clear();48}495051const GNEHierarchicalContainerParents<GNEJunction*>&52GNEHierarchicalElement::getParentJunctions() const {53return myHierarchicalStructureParents.get<GNEJunction*>();54}555657const GNEHierarchicalContainerParents<GNEEdge*>&58GNEHierarchicalElement::getParentEdges() const {59return myHierarchicalStructureParents.get<GNEEdge*>();60}616263const GNEHierarchicalContainerParents<GNELane*>&64GNEHierarchicalElement::getParentLanes() const {65return myHierarchicalStructureParents.get<GNELane*>();66}676869const GNEHierarchicalContainerParents<GNEAdditional*>&70GNEHierarchicalElement::getParentAdditionals() const {71return myHierarchicalStructureParents.get<GNEAdditional*>();72}737475const GNEHierarchicalContainerParents<GNEAdditional*>76GNEHierarchicalElement::getParentStoppingPlaces() const {77GNEHierarchicalContainerParents<GNEAdditional*> stoppingPlaces;78for (const auto& additional : getParentAdditionals()) {79if (additional->getTagProperty()->isStoppingPlace()) {80stoppingPlaces.push_back(additional);81}82}83return stoppingPlaces;84}858687const GNEHierarchicalContainerParents<GNEAdditional*>88GNEHierarchicalElement::getParentTAZs() const {89GNEHierarchicalContainerParents<GNEAdditional*> TAZs;90for (const auto& additional : getParentAdditionals()) {91if (additional->getTagProperty()->isTAZElement()) {92TAZs.push_back(additional);93}94}95return TAZs;96}979899const GNEHierarchicalContainerParents<GNEDemandElement*>&100GNEHierarchicalElement::getParentDemandElements() const {101return myHierarchicalStructureParents.get<GNEDemandElement*>();102}103104105const GNEHierarchicalContainerParents<GNEGenericData*>&106GNEHierarchicalElement::getParentGenericDatas() const {107return myHierarchicalStructureParents.get<GNEGenericData*>();108}109110111const GNEHierarchicalStructureChildren&112GNEHierarchicalElement::getChildren() const {113return myHierarchicalStructureChildren;114}115116117const GNEHierarchicalContainerChildren<GNEJunction*>&118GNEHierarchicalElement::getChildJunctions() const {119return myHierarchicalStructureChildren.get<GNEJunction*>();120}121122123const GNEHierarchicalContainerChildren<GNEEdge*>&124GNEHierarchicalElement::getChildEdges() const {125return myHierarchicalStructureChildren.get<GNEEdge*>();126}127128129const GNEHierarchicalContainerChildren<GNELane*>&130GNEHierarchicalElement::getChildLanes() const {131return myHierarchicalStructureChildren.get<GNELane*>();132}133134135const GNEHierarchicalContainerChildren<GNEAdditional*>&136GNEHierarchicalElement::getChildAdditionals() const {137return myHierarchicalStructureChildren.get<GNEAdditional*>();138}139140141const GNEHierarchicalContainerChildren<GNEDemandElement*>&142GNEHierarchicalElement::getChildDemandElements() const {143return myHierarchicalStructureChildren.get<GNEDemandElement*>();144}145146147const GNEHierarchicalContainerChildren<GNEGenericData*>&148GNEHierarchicalElement::getChildGenericDatas() const {149return myHierarchicalStructureChildren.get<GNEGenericData*>();150}151152153const GNEHierarchicalContainerChildrenSet<GNETAZSourceSink*>&154GNEHierarchicalElement::getChildTAZSourceSinks() const {155return myHierarchicalStructureChildren.getSet<GNETAZSourceSink*>();156}157158159std::string160GNEHierarchicalElement::getNewListOfParents(const GNENetworkElement* currentElement, const GNENetworkElement* newNextElement) const {161std::vector<std::string> solution;162if ((currentElement->getTagProperty()->getTag() == SUMO_TAG_EDGE) && (newNextElement->getTagProperty()->getTag() == SUMO_TAG_EDGE)) {163// reserve solution164solution.reserve(getParentEdges().size());165// iterate over edges166for (const auto& edge : getParentEdges()) {167// add edge ID168solution.push_back(edge->getID());169// if current edge is the current element, then insert newNextElement ID170if (edge == currentElement) {171solution.push_back(newNextElement->getID());172}173}174} else if ((currentElement->getTagProperty()->getTag() == SUMO_TAG_LANE) && (newNextElement->getTagProperty()->getTag() == SUMO_TAG_LANE)) {175// reserve solution176solution.reserve(getParentLanes().size());177// iterate over lanes178for (const auto& lane : getParentLanes()) {179// add lane ID180solution.push_back(lane->getID());181// if current lane is the current element, then insert newNextElement ID182if (lane == currentElement) {183solution.push_back(newNextElement->getID());184}185}186}187// remove consecutive (adjacent) duplicates188solution.erase(std::unique(solution.begin(), solution.end()), solution.end());189// return solution190return toString(solution);191}192193/****************************************************************************/194195196