Path: blob/main/src/netedit/elements/additional/GNEDestProbReroute.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 GNEDestProbReroute.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 "GNEDestProbReroute.h"2627// ===========================================================================28// member method definitions29// ===========================================================================3031GNEDestProbReroute::GNEDestProbReroute(GNENet* net):32GNEAdditional("", net, "", SUMO_TAG_DEST_PROB_REROUTE, ""),33myNewEdgeDestination(nullptr),34myProbability(0) {35}363738GNEDestProbReroute::GNEDestProbReroute(GNEAdditional* rerouterIntervalParent, GNEEdge* newEdgeDestination, double probability):39GNEAdditional(rerouterIntervalParent, SUMO_TAG_DEST_PROB_REROUTE, ""),40myNewEdgeDestination(newEdgeDestination),41myProbability(probability) {42// set parents43setParent<GNEAdditional*>(rerouterIntervalParent);44setParent<GNEEdge*>(newEdgeDestination);45// update boundary of rerouter parent46rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);47}484950GNEDestProbReroute::~GNEDestProbReroute() {}515253void54GNEDestProbReroute::writeAdditional(OutputDevice& device) const {55device.openTag(SUMO_TAG_DEST_PROB_REROUTE);56device.writeAttr(SUMO_ATTR_ID, getAttribute(SUMO_ATTR_EDGE));57device.writeAttr(SUMO_ATTR_PROB, myProbability);58device.closeTag();59}606162bool63GNEDestProbReroute::isAdditionalValid() const {64return true;65}666768std::string69GNEDestProbReroute::getAdditionalProblem() const {70return "";71}727374void75GNEDestProbReroute::fixAdditionalProblem() {76// nothing to fix77}787980bool81GNEDestProbReroute::checkDrawMoveContour() const {82return false;83}848586GNEMoveOperation*87GNEDestProbReroute::getMoveOperation() {88// GNEDestProbReroutes cannot be moved89return nullptr;90}919293void94GNEDestProbReroute::updateGeometry() {95// update centering boundary (needed for centering)96updateCenteringBoundary(false);97}9899100Position101GNEDestProbReroute::getPositionInView() const {102// get rerouter parent position103Position signPosition = getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView();104// set position depending of indexes105signPosition.add(4.5 + 6.25, (getDrawPositionIndex() * -1) - getParentAdditionals().front()->getDrawPositionIndex() + 1, 0);106// return signPosition107return signPosition;108}109110111void112GNEDestProbReroute::updateCenteringBoundary(const bool /*updateGrid*/) {113// nothing to update114}115116117void118GNEDestProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {119// geometry of this element cannot be splitted120}121122123std::string124GNEDestProbReroute::getParentName() const {125return getParentAdditionals().at(0)->getID();126}127128129void130GNEDestProbReroute::drawGL(const GUIVisualizationSettings& s) const {131// draw dest prob reroute as listed attribute132drawListedAdditional(s, getParentAdditionals().front()->getParentAdditionals().front()->getPositionInView(),1331, getParentAdditionals().front()->getDrawPositionIndex(),134RGBColor::RED, RGBColor::YELLOW, GUITexture::REROUTER_DESTPROBREROUTE,135getAttribute(SUMO_ATTR_EDGE) + ": " + getAttribute(SUMO_ATTR_PROB));136}137138139std::string140GNEDestProbReroute::getAttribute(SumoXMLAttr key) const {141switch (key) {142case SUMO_ATTR_ID:143return getMicrosimID();144case SUMO_ATTR_EDGE:145return myNewEdgeDestination->getID();146case SUMO_ATTR_PROB:147return toString(myProbability);148case GNE_ATTR_PARENT:149return getParentAdditionals().at(0)->getID();150default:151return getCommonAttribute(this, key);152}153}154155156double157GNEDestProbReroute::getAttributeDouble(SumoXMLAttr key) const {158throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");159}160161162const Parameterised::Map&163GNEDestProbReroute::getACParametersMap() const {164return getParametersMap();165}166167168void169GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {170if (value == getAttribute(key)) {171return; //avoid needless changes, later logic relies on the fact that attributes have changed172}173switch (key) {174case SUMO_ATTR_ID:175case SUMO_ATTR_EDGE:176case SUMO_ATTR_PROB:177GNEChange_Attribute::changeAttribute(this, key, value, undoList);178break;179default:180setCommonAttribute(key, value, undoList);181break;182}183}184185186bool187GNEDestProbReroute::isValid(SumoXMLAttr key, const std::string& value) {188switch (key) {189case SUMO_ATTR_ID:190return isValidAdditionalID(value);191case SUMO_ATTR_EDGE:192return (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr);193case SUMO_ATTR_PROB:194return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;195default:196return isCommonValid(key, value);197}198}199200201std::string202GNEDestProbReroute::getPopUpID() const {203return getTagStr();204}205206207std::string208GNEDestProbReroute::getHierarchyName() const {209return getTagStr() + ": " + myNewEdgeDestination->getID();210}211212// ===========================================================================213// private214// ===========================================================================215216void217GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {218switch (key) {219case SUMO_ATTR_ID:220// update microsimID221setAdditionalID(value);222break;223case SUMO_ATTR_EDGE:224myNewEdgeDestination = myNet->getAttributeCarriers()->retrieveEdge(value);225break;226case SUMO_ATTR_PROB:227myProbability = parse<double>(value);228break;229default:230setCommonAttribute(this, key, value);231break;232}233}234235236void237GNEDestProbReroute::setMoveShape(const GNEMoveResult& /*moveResult*/) {238// nothing to do239}240241242void243GNEDestProbReroute::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {244// nothing to do245}246247248/****************************************************************************/249250251