Path: blob/main/src/netedit/elements/demand/GNEPlanParents.cpp
185790 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 GNEPlanParents.cpp14/// @author Pablo Alvarez Lopez15/// @date Aug 202416///17// Builds demand objects for netedit18/****************************************************************************/1920#include <netedit/GNENet.h>2122#include "GNEPlanParents.h"2324// ===========================================================================25// member method definitions26// ===========================================================================2728GNEPlanParents::GNEPlanParents() {}293031GNEPlanParents::GNEPlanParents(const CommonXMLStructure::PlanParameters& planParameters,32const GNENetHelper::AttributeCarriers* ACs) {33// edges34fromEdge = ACs->retrieveEdge(planParameters.fromEdge, false);35toEdge = ACs->retrieveEdge(planParameters.toEdge, false);36for (const auto& edgeID : planParameters.consecutiveEdges) {37auto parsedEdge = ACs->retrieveEdge(edgeID, false);38// avoid null and consecutive dulicated edges39if (parsedEdge && (consecutiveEdges.empty() || (consecutiveEdges.back() != parsedEdge))) {40consecutiveEdges.push_back(parsedEdge);41}42}43// junctions44fromJunction = ACs->retrieveJunction(planParameters.fromJunction, false);45toJunction = ACs->retrieveJunction(planParameters.toJunction, false);46// TAZs47fromTAZ = ACs->retrieveAdditional(SUMO_TAG_TAZ, planParameters.fromTAZ, false);48toTAZ = ACs->retrieveAdditional(SUMO_TAG_TAZ, planParameters.toTAZ, false);49// bus stops50if (fromStoppingPlace == nullptr) {51fromStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_BUS_STOP, planParameters.fromBusStop, false);52}53if (toStoppingPlace == nullptr) {54toStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_BUS_STOP, planParameters.toBusStop, false);55}56// train stops57if (fromStoppingPlace == nullptr) {58fromStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_TRAIN_STOP, planParameters.fromTrainStop, false);59}60if (toStoppingPlace == nullptr) {61toStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_TRAIN_STOP, planParameters.toTrainStop, false);62}63// container stops64if (fromStoppingPlace == nullptr) {65fromStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_CONTAINER_STOP, planParameters.fromContainerStop, false);66}67if (toStoppingPlace == nullptr) {68toStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_CONTAINER_STOP, planParameters.toContainerStop, false);69}70// charging station71if (fromStoppingPlace == nullptr) {72fromStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_CHARGING_STATION, planParameters.fromChargingStation, false);73}74if (toStoppingPlace == nullptr) {75toStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_CHARGING_STATION, planParameters.toChargingStation, false);76}77// parking area78if (fromStoppingPlace == nullptr) {79fromStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_PARKING_AREA, planParameters.fromParkingArea, false);80}81if (toStoppingPlace == nullptr) {82toStoppingPlace = ACs->retrieveAdditional(SUMO_TAG_PARKING_AREA, planParameters.toParkingArea, false);83}84// routes85fromRoute = ACs->retrieveDemandElement(SUMO_TAG_ROUTE, planParameters.fromRoute, false);86toRoute = ACs->retrieveDemandElement(SUMO_TAG_ROUTE, planParameters.toRoute, false);87}888990bool91GNEPlanParents::checkIntegrity(SumoXMLTag planTag, const GNEDemandElement* parent, const CommonXMLStructure::PlanParameters& planParameters) const {92if (!planParameters.fromEdge.empty() && !fromEdge) {93WRITE_WARNING(TLF("Invalid from edge '%' used in % of % '%'", planParameters.fromEdge, toString(planTag), parent->getTagStr(), parent->getID()));94return false;95} else if (!planParameters.toEdge.empty() && !toEdge) {96WRITE_WARNING(TLF("Invalid to edge '%' used in % of % '%'", planParameters.toEdge, toString(planTag), parent->getTagStr(), parent->getID()));97return false;98} else if (!planParameters.fromJunction.empty() && !fromJunction) {99WRITE_WARNING(TLF("Invalid from junction '%' used in % of % '%'", planParameters.fromJunction, toString(planTag), parent->getTagStr(), parent->getID()));100return false;101} else if (!planParameters.toJunction.empty() && !toJunction) {102WRITE_WARNING(TLF("Invalid to junction '%' used in % of % '%'", planParameters.toJunction, toString(planTag), parent->getTagStr(), parent->getID()));103return false;104} else if (!planParameters.fromTAZ.empty() && !fromTAZ) {105WRITE_WARNING(TLF("Invalid from TAZ '%' used in % of % '%'", planParameters.fromTAZ, toString(planTag), parent->getTagStr(), parent->getID()));106return false;107} else if (!planParameters.toTAZ.empty() && !toTAZ) {108WRITE_WARNING(TLF("Invalid to TAZ '%' used in % of % '%'", planParameters.toTAZ, toString(planTag), parent->getTagStr(), parent->getID()));109return false;110} else if (!planParameters.fromBusStop.empty() && !fromStoppingPlace) {111WRITE_WARNING(TLF("Invalid from bus stop '%' used in % of % '%'", planParameters.fromBusStop, toString(planTag), parent->getTagStr(), parent->getID()));112return false;113} else if (!planParameters.fromTrainStop.empty() && !fromStoppingPlace) {114WRITE_WARNING(TLF("Invalid from train stop '%' used in % of % '%'", planParameters.fromTrainStop, toString(planTag), parent->getTagStr(), parent->getID()));115return false;116} else if (!planParameters.fromContainerStop.empty() && !fromStoppingPlace) {117WRITE_WARNING(TLF("Invalid from container stop '%' used in % of % '%'", planParameters.fromContainerStop, toString(planTag), parent->getTagStr(), parent->getID()));118return false;119} else if (!planParameters.fromChargingStation.empty() && !fromStoppingPlace) {120WRITE_WARNING(TLF("Invalid from charging station '%' used in % of % '%'", planParameters.fromChargingStation, toString(planTag), parent->getTagStr(), parent->getID()));121return false;122} else if (!planParameters.fromParkingArea.empty() && !fromStoppingPlace) {123WRITE_WARNING(TLF("Invalid from parking area '%' used in % of % '%'", planParameters.fromParkingArea, toString(planTag), parent->getTagStr(), parent->getID()));124return false;125} else if (!planParameters.toBusStop.empty() && !toStoppingPlace) {126WRITE_WARNING(TLF("Invalid to bus stop '%' used in % of % '%'", planParameters.toBusStop, toString(planTag), parent->getTagStr(), parent->getID()));127return false;128} else if (!planParameters.toTrainStop.empty() && !toStoppingPlace) {129WRITE_WARNING(TLF("Invalid to train stop '%' used in % of % '%'", planParameters.toTrainStop, toString(planTag), parent->getTagStr(), parent->getID()));130return false;131} else if (!planParameters.toContainerStop.empty() && !toStoppingPlace) {132WRITE_WARNING(TLF("Invalid to container stop '%' used in % of % '%'", planParameters.toContainerStop, toString(planTag), parent->getTagStr(), parent->getID()));133return false;134} else if (!planParameters.toChargingStation.empty() && !toStoppingPlace) {135WRITE_WARNING(TLF("Invalid to charging station '%' used in % of % '%'", planParameters.toChargingStation, toString(planTag), parent->getTagStr(), parent->getID()));136return false;137} else if (!planParameters.toParkingArea.empty() && !toStoppingPlace) {138WRITE_WARNING(TLF("Invalid to parking area '%' used in % of % '%'", planParameters.toParkingArea, toString(planTag), parent->getTagStr(), parent->getID()));139return false;140} else if (!planParameters.fromRoute.empty() && !fromRoute) {141WRITE_WARNING(TLF("Invalid from route '%' used in % of % '%'", planParameters.fromRoute, toString(planTag), parent->getTagStr(), parent->getID()));142return false;143} else if (!planParameters.toRoute.empty() && !toRoute) {144WRITE_WARNING(TLF("Invalid to route '%' used in % of % '%'", planParameters.toRoute, toString(planTag), parent->getTagStr(), parent->getID()));145return false;146} else {147return true;148}149}150151void152GNEPlanParents::addDemandElementChild(GNEDemandElement* element) {153if (fromEdge) {154fromEdge->addChildElement(element);155}156if (toEdge) {157toEdge->addChildElement(element);158}159for (const auto& consecutiveEdge : consecutiveEdges) {160consecutiveEdge->addChildElement(element);161}162if (fromJunction) {163fromJunction->addChildElement(element);164}165if (toJunction) {166toJunction->addChildElement(element);167}168if (fromTAZ) {169fromTAZ->addChildElement(element);170}171if (toTAZ) {172toTAZ->addChildElement(element);173}174if (fromStoppingPlace) {175fromStoppingPlace->addChildElement(element);176}177if (toStoppingPlace) {178toStoppingPlace->addChildElement(element);179}180if (fromRoute) {181fromRoute->addChildElement(element);182}183if (toRoute) {184toRoute->addChildElement(element);185}186}187188189void190GNEPlanParents::clear() {191fromEdge = nullptr;192toEdge = nullptr;193consecutiveEdges.clear();194fromJunction = nullptr;195toJunction = nullptr;196fromTAZ = nullptr;197toTAZ = nullptr;198fromStoppingPlace = nullptr;199toStoppingPlace = nullptr;200fromRoute = nullptr;201toRoute = nullptr;202}203204205bool206GNEPlanParents::getFromBusStop() const {207if (fromStoppingPlace) {208return (fromStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_BUS_STOP);209} else {210return false;211}212}213214215bool216GNEPlanParents::getToBusStop() const {217if (toStoppingPlace) {218return (toStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_BUS_STOP);219} else {220return false;221}222}223224225bool226GNEPlanParents::getFromTrainStop() const {227if (fromStoppingPlace) {228return (fromStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_TRAIN_STOP);229} else {230return false;231}232}233234235bool236GNEPlanParents::getToTrainStop() const {237if (toStoppingPlace) {238return (toStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_TRAIN_STOP);239} else {240return false;241}242}243244245bool246GNEPlanParents::getFromContainerStop() const {247if (fromStoppingPlace) {248return (fromStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_CONTAINER_STOP);249} else {250return false;251}252}253254255bool256GNEPlanParents::getToContainerStop() const {257if (toStoppingPlace) {258return (toStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_CONTAINER_STOP);259} else {260return false;261}262}263264265bool266GNEPlanParents::getFromChargingStation() const {267if (fromStoppingPlace) {268return (fromStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_CHARGING_STATION);269} else {270return false;271}272}273274275bool276GNEPlanParents::getToChargingStation() const {277if (toStoppingPlace) {278return (toStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_CHARGING_STATION);279} else {280return false;281}282}283284285bool286GNEPlanParents::getFromParkingArea() const {287if (fromStoppingPlace) {288return (fromStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_PARKING_AREA);289} else {290return false;291}292}293294295bool296GNEPlanParents::getToParkingArea() const {297if (toStoppingPlace) {298return (toStoppingPlace->getTagProperty()->getTag() == SUMO_TAG_PARKING_AREA);299} else {300return false;301}302}303304305std::vector<GNEJunction*>306GNEPlanParents::getJunctions() const {307std::vector<GNEJunction*> junctions;308if (fromJunction) {309junctions.push_back(fromJunction);310}311if (toJunction) {312junctions.push_back(toJunction);313}314return junctions;315}316317318std::vector<GNEEdge*>319GNEPlanParents::getEdges() const {320if (consecutiveEdges.size() > 0) {321return consecutiveEdges;322} else {323std::vector<GNEEdge*> edges;324if (fromEdge) {325edges.push_back(fromEdge);326}327if (toEdge) {328edges.push_back(toEdge);329}330return edges;331}332}333334335std::vector<GNEAdditional*>336GNEPlanParents::getAdditionalElements() const {337std::vector<GNEAdditional*> additionals;338if (fromStoppingPlace) {339additionals.push_back(fromStoppingPlace);340}341if (toStoppingPlace) {342additionals.push_back(toStoppingPlace);343}344if (fromTAZ) {345additionals.push_back(fromTAZ);346}347if (toTAZ) {348additionals.push_back(toTAZ);349}350return additionals;351}352353354std::vector<GNEDemandElement*>355GNEPlanParents::getDemandElements(GNEDemandElement* parent) const {356std::vector<GNEDemandElement*> demandElements;357// always add parent first358demandElements.push_back(parent);359if (fromRoute) {360demandElements.push_back(fromRoute);361}362if (toRoute) {363demandElements.push_back(toRoute);364}365return demandElements;366}367368/****************************************************************************/369370371