Path: blob/main/src/netedit/elements/additional/GNEClosingLaneReroute.cpp
169684 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 GNEClosingLaneReroute.cpp14/// @author Pablo Alvarez Lopez15/// @date Jan 201716///17//18/****************************************************************************/19#include <config.h>2021#include <netedit/changes/GNEChange_Attribute.h>22#include <netedit/GNENet.h>23#include <netedit/GNEUndoList.h>2425#include "GNEClosingLaneReroute.h"2627// ===========================================================================28// member method definitions29// ===========================================================================3031GNEClosingLaneReroute::GNEClosingLaneReroute(GNENet* net) :32GNEAdditional("", net, "", SUMO_TAG_CLOSING_LANE_REROUTE, ""),33myClosedLane(nullptr),34myPermissions(0) {35}363738GNEClosingLaneReroute::GNEClosingLaneReroute(GNEAdditional* rerouterIntervalParent, GNELane* closedLane, SVCPermissions permissions) :39GNEAdditional(rerouterIntervalParent, SUMO_TAG_CLOSING_LANE_REROUTE, ""),40myClosedLane(closedLane),41myPermissions(permissions) {42// set parents43setParent<GNEAdditional*>(rerouterIntervalParent);44setParent<GNELane*>(closedLane);45// update boundary of rerouter parent46rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);47}484950GNEClosingLaneReroute::~GNEClosingLaneReroute() {}515253void54GNEClosingLaneReroute::writeAdditional(OutputDevice& device) const {55device.openTag(SUMO_TAG_CLOSING_LANE_REROUTE);56device.writeAttr(SUMO_ATTR_ID, getAttribute(SUMO_ATTR_LANE));57if (getAttribute(SUMO_ATTR_ALLOW) != getVehicleClassNames(SVCAll)) {58if (!getAttribute(SUMO_ATTR_ALLOW).empty()) {59device.writeAttr(SUMO_ATTR_ALLOW, getAttribute(SUMO_ATTR_ALLOW));60} else {61device.writeAttr(SUMO_ATTR_DISALLOW, getAttribute(SUMO_ATTR_DISALLOW));62}63}64device.closeTag();65}666768bool69GNEClosingLaneReroute::isAdditionalValid() const {70return true;71}727374std::string75GNEClosingLaneReroute::getAdditionalProblem() const {76return "";77}787980void81GNEClosingLaneReroute::fixAdditionalProblem() {82// nothing to fix83}848586bool87GNEClosingLaneReroute::checkDrawMoveContour() const {88return false;89}909192GNEMoveOperation*93GNEClosingLaneReroute::getMoveOperation() {94// GNEClosingLaneReroute cannot be moved95return nullptr;96}979899void100GNEClosingLaneReroute::updateGeometry() {101// update centering boundary (needed for centering)102updateCenteringBoundary(false);103}104105106Position107GNEClosingLaneReroute::getPositionInView() const {108// get rerouter parent position109Position signPosition = getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView();110// set position depending of indexes111signPosition.add(4.5 + 6.25, (getDrawPositionIndex() * -1) - getParentAdditionals().front()->getDrawPositionIndex() + 1, 0);112// return signPosition113return signPosition;114}115116117void118GNEClosingLaneReroute::updateCenteringBoundary(const bool /*updateGrid*/) {119// nothing to update120}121122123void124GNEClosingLaneReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {125// geometry of this element cannot be splitted126}127128129std::string130GNEClosingLaneReroute::getParentName() const {131return getParentAdditionals().at(0)->getID();132}133134135void136GNEClosingLaneReroute::drawGL(const GUIVisualizationSettings& s) const {137// draw closing lane reroute as listed attribute138drawListedAdditional(s, getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView(),1391, getParentAdditionals().front()->getDrawPositionIndex(),140RGBColor::RED, RGBColor::YELLOW, GUITexture::REROUTER_CLOSINGLANEREROUTE,141getAttribute(SUMO_ATTR_LANE));142}143144145std::string146GNEClosingLaneReroute::getAttribute(SumoXMLAttr key) const {147switch (key) {148case SUMO_ATTR_ID:149return getMicrosimID();150case SUMO_ATTR_LANE:151return myClosedLane->getID();152case SUMO_ATTR_ALLOW:153return getVehicleClassNames(myPermissions);154case SUMO_ATTR_DISALLOW:155return getVehicleClassNames(invertPermissions(myPermissions));156case GNE_ATTR_PARENT:157return getParentAdditionals().at(0)->getID();158case GNE_ATTR_SHIFTLANEINDEX:159return "";160default:161return getCommonAttribute(this, key);162}163}164165166double167GNEClosingLaneReroute::getAttributeDouble(SumoXMLAttr key) const {168throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");169}170171172const Parameterised::Map&173GNEClosingLaneReroute::getACParametersMap() const {174return getParametersMap();175}176177178void179GNEClosingLaneReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {180switch (key) {181case SUMO_ATTR_ID:182case SUMO_ATTR_LANE:183case SUMO_ATTR_ALLOW:184case SUMO_ATTR_DISALLOW:185case GNE_ATTR_SHIFTLANEINDEX:186GNEChange_Attribute::changeAttribute(this, key, value, undoList);187break;188default:189setCommonAttribute(key, value, undoList);190break;191}192}193194195bool196GNEClosingLaneReroute::isValid(SumoXMLAttr key, const std::string& value) {197switch (key) {198case SUMO_ATTR_ID:199return isValidAdditionalID(value);200case SUMO_ATTR_LANE:201return (myNet->getAttributeCarriers()->retrieveLane(value, false) != nullptr);202case SUMO_ATTR_ALLOW:203case SUMO_ATTR_DISALLOW:204return canParseVehicleClasses(value);205default:206return isCommonValid(key, value);207}208}209210211std::string212GNEClosingLaneReroute::getPopUpID() const {213return getTagStr();214}215216217std::string218GNEClosingLaneReroute::getHierarchyName() const {219return getTagStr() + ": " + myClosedLane->getID();220}221222// ===========================================================================223// private224// ===========================================================================225226void227GNEClosingLaneReroute::setAttribute(SumoXMLAttr key, const std::string& value) {228switch (key) {229case SUMO_ATTR_ID:230// update microsimID231setAdditionalID(value);232break;233case SUMO_ATTR_LANE:234myClosedLane = myNet->getAttributeCarriers()->retrieveLane(value);235break;236case SUMO_ATTR_ALLOW:237myPermissions = parseVehicleClasses(value);238break;239case SUMO_ATTR_DISALLOW:240myPermissions = invertPermissions(parseVehicleClasses(value));241break;242case GNE_ATTR_SHIFTLANEINDEX:243shiftLaneIndex();244break;245default:246setCommonAttribute(this, key, value);247break;248}249}250251252void253GNEClosingLaneReroute::setMoveShape(const GNEMoveResult& /*moveResult*/) {254// nothing to do255}256257258void259GNEClosingLaneReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {260// nothing to do261}262263/****************************************************************************/264265266