Path: blob/main/src/netedit/elements/additional/GNEParkingAreaReroute.cpp
193767 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 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 GNEParkingAreaReroute.cpp14/// @author Jakob Erdmann15/// @date May 201816///17//18/****************************************************************************/1920#include <netedit/GNENet.h>21#include <netedit/changes/GNEChange_Attribute.h>2223#include "GNEParkingAreaReroute.h"2425// ===========================================================================26// member method definitions27// ===========================================================================2829GNEParkingAreaReroute::GNEParkingAreaReroute(GNENet* net):30GNEAdditional(net, SUMO_TAG_PARKING_AREA_REROUTE),31GNEAdditionalListed(this) {32}333435GNEParkingAreaReroute::GNEParkingAreaReroute(GNEAdditional* rerouterIntervalParent, GNEAdditional* newParkingArea,36const double probability, const bool visible):37GNEAdditional(rerouterIntervalParent, SUMO_TAG_PARKING_AREA_REROUTE, ""),38GNEAdditionalListed(this),39myProbability(probability),40myVisible(visible) {41// set parents42setParents<GNEAdditional*>({rerouterIntervalParent, newParkingArea});43// update boundary of rerouter parent44rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);45}464748GNEParkingAreaReroute::~GNEParkingAreaReroute() {}495051GNEMoveElement*52GNEParkingAreaReroute::getMoveElement() const {53return nullptr;54}555657Parameterised*58GNEParkingAreaReroute::getParameters() {59return nullptr;60}616263const Parameterised*64GNEParkingAreaReroute::getParameters() const {65return nullptr;66}676869void70GNEParkingAreaReroute::writeAdditional(OutputDevice& device) const {71device.openTag(SUMO_TAG_PARKING_AREA_REROUTE);72// write common additional attributes73writeAdditionalAttributes(device);74// write specific attributes75device.writeAttr(SUMO_ATTR_ID, getAttribute(SUMO_ATTR_PARKING));76if (myProbability != 1.0) {77device.writeAttr(SUMO_ATTR_PROB, myProbability);78}79if (myVisible) {80device.writeAttr(SUMO_ATTR_VISIBLE, true);81}82device.closeTag();83}848586bool87GNEParkingAreaReroute::isAdditionalValid() const {88return true;89}909192std::string93GNEParkingAreaReroute::getAdditionalProblem() const {94return "";95}969798void99GNEParkingAreaReroute::fixAdditionalProblem() {100// nothing to fix101}102103104bool105GNEParkingAreaReroute::checkDrawMoveContour() const {106return false;107}108109110void111GNEParkingAreaReroute::updateGeometry() {112updateGeometryListedAdditional();113}114115116Position117GNEParkingAreaReroute::getPositionInView() const {118return getListedPositionInView();119}120121122void123GNEParkingAreaReroute::updateCenteringBoundary(const bool /*updateGrid*/) {124// nothing to update125}126127128void129GNEParkingAreaReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {130// geometry of this element cannot be splitted131}132133134std::string135GNEParkingAreaReroute::getParentName() const {136return getParentAdditionals().at(0)->getID();137}138139140void141GNEParkingAreaReroute::drawGL(const GUIVisualizationSettings& s) const {142// draw dest prob reroute as listed attribute143drawListedAdditional(s, RGBColor::RED, RGBColor::YELLOW, GUITexture::REROUTER_PARKINGAREAREROUTE,144getAttribute(SUMO_ATTR_PARKING) + ": " + getAttribute(SUMO_ATTR_PROB));145}146147148std::string149GNEParkingAreaReroute::getAttribute(SumoXMLAttr key) const {150switch (key) {151case SUMO_ATTR_ID:152return getMicrosimID();153case SUMO_ATTR_PARKING:154return getParentAdditionals().at(1)->getID();155case SUMO_ATTR_PROB:156return toString(myProbability);157case SUMO_ATTR_VISIBLE:158return toString(myVisible);159case GNE_ATTR_PARENT:160return toString(getParentAdditionals().at(0)->getID());161default:162return getCommonAttribute(key);163}164}165166167double168GNEParkingAreaReroute::getAttributeDouble(SumoXMLAttr key) const {169return getCommonAttributeDouble(key);170}171172173Position174GNEParkingAreaReroute::getAttributePosition(SumoXMLAttr key) const {175return getCommonAttributePosition(key);176}177178179PositionVector180GNEParkingAreaReroute::getAttributePositionVector(SumoXMLAttr key) const {181return getCommonAttributePositionVector(key);182}183184185void186GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {187if (value == getAttribute(key)) {188return; //avoid needless changes, later logic relies on the fact that attributes have changed189}190switch (key) {191case SUMO_ATTR_ID:192case SUMO_ATTR_PARKING:193case SUMO_ATTR_PROB:194case SUMO_ATTR_VISIBLE:195GNEChange_Attribute::changeAttribute(this, key, value, undoList);196break;197default:198setCommonAttribute(key, value, undoList);199break;200}201}202203204bool205GNEParkingAreaReroute::isValid(SumoXMLAttr key, const std::string& value) {206switch (key) {207case SUMO_ATTR_ID:208return isValidAdditionalID(value);209case SUMO_ATTR_PARKING:210return (myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_PARKING_AREA, value, false) != nullptr);211case SUMO_ATTR_PROB:212return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;213case SUMO_ATTR_VISIBLE:214return canParse<bool>(value);215default:216return isCommonAttributeValid(key, value);217}218}219220221std::string222GNEParkingAreaReroute::getPopUpID() const {223return getTagStr();224}225226227std::string228GNEParkingAreaReroute::getHierarchyName() const {229return getTagStr() + ": " + getParentAdditionals().at(1)->getID();230}231232// ===========================================================================233// private234// ===========================================================================235236void237GNEParkingAreaReroute::setAttribute(SumoXMLAttr key, const std::string& value) {238switch (key) {239case SUMO_ATTR_ID:240// update microsimID241setAdditionalID(value);242break;243case SUMO_ATTR_PARKING:244replaceAdditionalParent(SUMO_TAG_PARKING_AREA, value, 1);245break;246case SUMO_ATTR_PROB:247myProbability = parse<double>(value);248break;249case SUMO_ATTR_VISIBLE:250myVisible = parse<bool>(value);251break;252default:253setCommonAttribute(key, value);254break;255}256}257258/****************************************************************************/259260261