Path: blob/main/src/netedit/elements/additional/GNEClosingReroute.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 GNEClosingReroute.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 "GNEClosingReroute.h"2627// ===========================================================================28// member method definitions29// ===========================================================================3031GNEClosingReroute::GNEClosingReroute(GNENet* net) :32GNEAdditional("", net, "", SUMO_TAG_CLOSING_REROUTE, "") {33}343536GNEClosingReroute::GNEClosingReroute(GNEAdditional* rerouterIntervalParent, GNEEdge* closedEdge, SVCPermissions permissions) :37GNEAdditional(rerouterIntervalParent, SUMO_TAG_CLOSING_REROUTE, ""),38myClosedEdge(closedEdge),39myPermissions(permissions) {40// set parents41setParent<GNEAdditional*>(rerouterIntervalParent);42setParent<GNEEdge*>(closedEdge);43// update boundary of rerouter parent44rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);45}464748GNEClosingReroute::~GNEClosingReroute() {}495051void52GNEClosingReroute::writeAdditional(OutputDevice& device) const {53device.openTag(SUMO_TAG_CLOSING_REROUTE);54device.writeAttr(SUMO_ATTR_ID, getAttribute(SUMO_ATTR_EDGE));55if (getAttribute(SUMO_ATTR_ALLOW) != "authority") {56if (!getAttribute(SUMO_ATTR_ALLOW).empty()) {57device.writeAttr(SUMO_ATTR_ALLOW, getAttribute(SUMO_ATTR_ALLOW));58} else {59device.writeAttr(SUMO_ATTR_DISALLOW, getAttribute(SUMO_ATTR_DISALLOW));60}61}62device.closeTag();63}646566bool67GNEClosingReroute::isAdditionalValid() const {68return true;69}707172std::string73GNEClosingReroute::getAdditionalProblem() const {74return "";75}767778void79GNEClosingReroute::fixAdditionalProblem() {80// nothing to fix81}828384bool85GNEClosingReroute::checkDrawMoveContour() const {86return false;87}888990GNEMoveOperation*91GNEClosingReroute::getMoveOperation() {92// GNEClosingReroutes cannot be moved93return nullptr;94}959697void98GNEClosingReroute::updateGeometry() {99// update centering boundary (needed for centering)100updateCenteringBoundary(false);101}102103104Position105GNEClosingReroute::getPositionInView() const {106// get rerouter parent position107Position signPosition = getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView();108// set position depending of indexes109signPosition.add(4.5 + 6.25, (getDrawPositionIndex() * -1) - getParentAdditionals().front()->getDrawPositionIndex() + 1, 0);110// return signPosition111return signPosition;112}113114115void116GNEClosingReroute::updateCenteringBoundary(const bool /*updateGrid*/) {117// nothing to update118}119120121void122GNEClosingReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {123// geometry of this element cannot be splitted124}125126127std::string128GNEClosingReroute::getParentName() const {129return getParentAdditionals().at(0)->getID();130}131132133void134GNEClosingReroute::drawGL(const GUIVisualizationSettings& s) const {135// draw closing reroute as listed attribute136drawListedAdditional(s, getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView(),1371, getParentAdditionals().front()->getDrawPositionIndex(),138RGBColor::RED, RGBColor::YELLOW, GUITexture::REROUTER_CLOSINGREROUTE,139getAttribute(SUMO_ATTR_EDGE));140}141142143std::string144GNEClosingReroute::getAttribute(SumoXMLAttr key) const {145switch (key) {146case SUMO_ATTR_ID:147return getMicrosimID();148case SUMO_ATTR_EDGE:149return myClosedEdge->getID();150case SUMO_ATTR_ALLOW:151return getVehicleClassNames(myPermissions);152case SUMO_ATTR_DISALLOW:153return getVehicleClassNames(invertPermissions(myPermissions));154case GNE_ATTR_PARENT:155return getParentAdditionals().at(0)->getID();156default:157return getCommonAttribute(this, key);158}159}160161162double163GNEClosingReroute::getAttributeDouble(SumoXMLAttr key) const {164throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");165}166167168const Parameterised::Map&169GNEClosingReroute::getACParametersMap() const {170return getParametersMap();171}172173174void175GNEClosingReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {176if (value == getAttribute(key)) {177return; //avoid needless changes, later logic relies on the fact that attributes have changed178}179switch (key) {180case SUMO_ATTR_ID:181case SUMO_ATTR_EDGE:182case SUMO_ATTR_ALLOW:183case SUMO_ATTR_DISALLOW:184GNEChange_Attribute::changeAttribute(this, key, value, undoList);185break;186default:187setCommonAttribute(key, value, undoList);188break;189}190}191192193bool194GNEClosingReroute::isValid(SumoXMLAttr key, const std::string& value) {195switch (key) {196case SUMO_ATTR_ID:197return isValidAdditionalID(value);198case SUMO_ATTR_EDGE:199return (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr);200case SUMO_ATTR_ALLOW:201return canParseVehicleClasses(value);202case SUMO_ATTR_DISALLOW:203return canParseVehicleClasses(value);204default:205return isCommonValid(key, value);206}207}208209210std::string211GNEClosingReroute::getPopUpID() const {212return getTagStr();213}214215216std::string217GNEClosingReroute::getHierarchyName() const {218return getTagStr() + ": " + myClosedEdge->getID();219}220221// ===========================================================================222// private223// ===========================================================================224225void226GNEClosingReroute::setAttribute(SumoXMLAttr key, const std::string& value) {227switch (key) {228case SUMO_ATTR_ID:229// update microsimID230setAdditionalID(value);231break;232case SUMO_ATTR_EDGE:233myClosedEdge = myNet->getAttributeCarriers()->retrieveEdge(value);234break;235case SUMO_ATTR_ALLOW:236myPermissions = parseVehicleClasses(value);237break;238case SUMO_ATTR_DISALLOW:239myPermissions = invertPermissions(parseVehicleClasses(value));240break;241default:242setCommonAttribute(this, key, value);243break;244}245}246247248void249GNEClosingReroute::setMoveShape(const GNEMoveResult& /*moveResult*/) {250// nothing to do251}252253254void255GNEClosingReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {256// nothing to do257}258259260/****************************************************************************/261262263