Path: blob/main/src/netedit/elements/additional/GNEClosingReroute.cpp
193697 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 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>2324#include "GNEClosingReroute.h"2526// ===========================================================================27// member method definitions28// ===========================================================================2930GNEClosingReroute::GNEClosingReroute(GNENet* net) :31GNEAdditional(net, SUMO_TAG_CLOSING_REROUTE),32GNEAdditionalListed(this) {33}343536GNEClosingReroute::GNEClosingReroute(GNEAdditional* rerouterIntervalParent, GNEEdge* closedEdge, SVCPermissions permissions) :37GNEAdditional(rerouterIntervalParent, SUMO_TAG_CLOSING_REROUTE, ""),38GNEAdditionalListed(this),39myClosedEdge(closedEdge),40myPermissions(permissions) {41// set parents42setParent<GNEAdditional*>(rerouterIntervalParent);43setParent<GNEEdge*>(closedEdge);44// update boundary of rerouter parent45rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);46}474849GNEClosingReroute::~GNEClosingReroute() {}505152GNEMoveElement*53GNEClosingReroute::getMoveElement() const {54return nullptr;55}565758Parameterised*59GNEClosingReroute::getParameters() {60return nullptr;61}626364const Parameterised*65GNEClosingReroute::getParameters() const {66return nullptr;67}686970void71GNEClosingReroute::writeAdditional(OutputDevice& device) const {72device.openTag(SUMO_TAG_CLOSING_REROUTE);73// write common additional attributes74writeAdditionalAttributes(device);75// write specific attributes76device.writeAttr(SUMO_ATTR_ID, getAttribute(SUMO_ATTR_EDGE));77if (getAttribute(SUMO_ATTR_ALLOW) != getVehicleClassNames(SVCAll)) {78if (!getAttribute(SUMO_ATTR_ALLOW).empty()) {79device.writeAttr(SUMO_ATTR_ALLOW, getAttribute(SUMO_ATTR_ALLOW));80} else {81device.writeAttr(SUMO_ATTR_DISALLOW, getAttribute(SUMO_ATTR_DISALLOW));82}83}84device.closeTag();85}868788bool89GNEClosingReroute::isAdditionalValid() const {90return true;91}929394std::string95GNEClosingReroute::getAdditionalProblem() const {96return "";97}9899100void101GNEClosingReroute::fixAdditionalProblem() {102// nothing to fix103}104105106bool107GNEClosingReroute::checkDrawMoveContour() const {108return false;109}110111112void113GNEClosingReroute::updateGeometry() {114updateGeometryListedAdditional();115}116117118Position119GNEClosingReroute::getPositionInView() const {120return getListedPositionInView();121}122123124void125GNEClosingReroute::updateCenteringBoundary(const bool /*updateGrid*/) {126// nothing to update127}128129130void131GNEClosingReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {132// geometry of this element cannot be splitted133}134135136std::string137GNEClosingReroute::getParentName() const {138return getParentAdditionals().at(0)->getID();139}140141142void143GNEClosingReroute::drawGL(const GUIVisualizationSettings& s) const {144// draw closing reroute as listed attribute145drawListedAdditional(s, RGBColor::RED, RGBColor::YELLOW, GUITexture::REROUTER_CLOSINGREROUTE,146getAttribute(SUMO_ATTR_EDGE));147}148149150std::string151GNEClosingReroute::getAttribute(SumoXMLAttr key) const {152switch (key) {153case SUMO_ATTR_ID:154return getMicrosimID();155case SUMO_ATTR_EDGE:156return myClosedEdge->getID();157case SUMO_ATTR_ALLOW:158return getVehicleClassNames(myPermissions);159case SUMO_ATTR_DISALLOW:160return getVehicleClassNames(invertPermissions(myPermissions));161case GNE_ATTR_PARENT:162return getParentAdditionals().at(0)->getID();163default:164return getCommonAttribute(key);165}166}167168169double170GNEClosingReroute::getAttributeDouble(SumoXMLAttr key) const {171return getCommonAttributeDouble(key);172}173174175Position176GNEClosingReroute::getAttributePosition(SumoXMLAttr key) const {177return getCommonAttributePosition(key);178}179180181PositionVector182GNEClosingReroute::getAttributePositionVector(SumoXMLAttr key) const {183return getCommonAttributePositionVector(key);184}185186187void188GNEClosingReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {189if (value == getAttribute(key)) {190return; //avoid needless changes, later logic relies on the fact that attributes have changed191}192switch (key) {193case SUMO_ATTR_ID:194case SUMO_ATTR_EDGE:195case SUMO_ATTR_ALLOW:196case SUMO_ATTR_DISALLOW:197GNEChange_Attribute::changeAttribute(this, key, value, undoList);198break;199default:200setCommonAttribute(key, value, undoList);201break;202}203}204205206bool207GNEClosingReroute::isValid(SumoXMLAttr key, const std::string& value) {208switch (key) {209case SUMO_ATTR_ID:210return isValidAdditionalID(value);211case SUMO_ATTR_EDGE:212return (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr);213case SUMO_ATTR_ALLOW:214return canParseVehicleClasses(value);215case SUMO_ATTR_DISALLOW:216return canParseVehicleClasses(value);217default:218return isCommonAttributeValid(key, value);219}220}221222223std::string224GNEClosingReroute::getPopUpID() const {225return getTagStr();226}227228229std::string230GNEClosingReroute::getHierarchyName() const {231return getTagStr() + ": " + myClosedEdge->getID();232}233234// ===========================================================================235// private236// ===========================================================================237238void239GNEClosingReroute::setAttribute(SumoXMLAttr key, const std::string& value) {240switch (key) {241case SUMO_ATTR_ID:242// update microsimID243setAdditionalID(value);244break;245case SUMO_ATTR_EDGE:246myClosedEdge = myNet->getAttributeCarriers()->retrieveEdge(value);247break;248case SUMO_ATTR_ALLOW:249myPermissions = parseVehicleClasses(value);250break;251case SUMO_ATTR_DISALLOW:252myPermissions = invertPermissions(parseVehicleClasses(value));253break;254default:255setCommonAttribute(key, value);256break;257}258}259260/****************************************************************************/261262263