Path: blob/main/src/netedit/elements/additional/GNEDestProbReroute.cpp
193885 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 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>2324#include "GNEDestProbReroute.h"2526// ===========================================================================27// member method definitions28// ===========================================================================2930GNEDestProbReroute::GNEDestProbReroute(GNENet* net):31GNEAdditional(net, SUMO_TAG_DEST_PROB_REROUTE),32GNEAdditionalListed(this),33myNewEdgeDestination(nullptr),34myProbability(0) {35}363738GNEDestProbReroute::GNEDestProbReroute(GNEAdditional* rerouterIntervalParent, GNEEdge* newEdgeDestination, double probability):39GNEAdditional(rerouterIntervalParent, SUMO_TAG_DEST_PROB_REROUTE, ""),40GNEAdditionalListed(this),41myNewEdgeDestination(newEdgeDestination),42myProbability(probability) {43// set parents44setParent<GNEAdditional*>(rerouterIntervalParent);45setParent<GNEEdge*>(newEdgeDestination);46// update boundary of rerouter parent47rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);48}495051GNEDestProbReroute::~GNEDestProbReroute() {}525354GNEMoveElement*55GNEDestProbReroute::getMoveElement() const {56return nullptr;57}585960Parameterised*61GNEDestProbReroute::getParameters() {62return nullptr;63}646566const Parameterised*67GNEDestProbReroute::getParameters() const {68return nullptr;69}707172void73GNEDestProbReroute::writeAdditional(OutputDevice& device) const {74device.openTag(SUMO_TAG_DEST_PROB_REROUTE);75// write common additional attributes76writeAdditionalAttributes(device);77// write specific attributes78device.writeAttr(SUMO_ATTR_ID, getAttribute(SUMO_ATTR_EDGE));79device.writeAttr(SUMO_ATTR_PROB, myProbability);80device.closeTag();81}828384bool85GNEDestProbReroute::isAdditionalValid() const {86return true;87}888990std::string91GNEDestProbReroute::getAdditionalProblem() const {92return "";93}949596void97GNEDestProbReroute::fixAdditionalProblem() {98// nothing to fix99}100101102bool103GNEDestProbReroute::checkDrawMoveContour() const {104return false;105}106107108void109GNEDestProbReroute::updateGeometry() {110updateGeometryListedAdditional();111}112113114Position115GNEDestProbReroute::getPositionInView() const {116return getListedPositionInView();117}118119120void121GNEDestProbReroute::updateCenteringBoundary(const bool /*updateGrid*/) {122// nothing to update123}124125126void127GNEDestProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {128// geometry of this element cannot be splitted129}130131132std::string133GNEDestProbReroute::getParentName() const {134return getParentAdditionals().at(0)->getID();135}136137138void139GNEDestProbReroute::drawGL(const GUIVisualizationSettings& s) const {140// draw dest prob reroute as listed attribute141drawListedAdditional(s, RGBColor::RED, RGBColor::YELLOW, GUITexture::REROUTER_DESTPROBREROUTE,142getAttribute(SUMO_ATTR_EDGE) + ": " + getAttribute(SUMO_ATTR_PROB));143}144145146std::string147GNEDestProbReroute::getAttribute(SumoXMLAttr key) const {148switch (key) {149case SUMO_ATTR_ID:150return getMicrosimID();151case SUMO_ATTR_EDGE:152return myNewEdgeDestination->getID();153case SUMO_ATTR_PROB:154return toString(myProbability);155case GNE_ATTR_PARENT:156return getParentAdditionals().at(0)->getID();157default:158return getCommonAttribute(key);159}160}161162163double164GNEDestProbReroute::getAttributeDouble(SumoXMLAttr key) const {165return getCommonAttributeDouble(key);166}167168169Position170GNEDestProbReroute::getAttributePosition(SumoXMLAttr key) const {171return getCommonAttributePosition(key);172}173174175PositionVector176GNEDestProbReroute::getAttributePositionVector(SumoXMLAttr key) const {177return getCommonAttributePositionVector(key);178}179180181void182GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {183if (value == getAttribute(key)) {184return; //avoid needless changes, later logic relies on the fact that attributes have changed185}186switch (key) {187case SUMO_ATTR_ID:188case SUMO_ATTR_EDGE:189case SUMO_ATTR_PROB:190GNEChange_Attribute::changeAttribute(this, key, value, undoList);191break;192default:193setCommonAttribute(key, value, undoList);194break;195}196}197198199bool200GNEDestProbReroute::isValid(SumoXMLAttr key, const std::string& value) {201switch (key) {202case SUMO_ATTR_ID:203return isValidAdditionalID(value);204case SUMO_ATTR_EDGE:205return (myNet->getAttributeCarriers()->retrieveEdge(value, false) != nullptr);206case SUMO_ATTR_PROB:207return canParse<double>(value) && parse<double>(value) >= 0 && parse<double>(value) <= 1;208default:209return isCommonAttributeValid(key, value);210}211}212213214std::string215GNEDestProbReroute::getPopUpID() const {216return getTagStr();217}218219220std::string221GNEDestProbReroute::getHierarchyName() const {222return getTagStr() + ": " + myNewEdgeDestination->getID();223}224225// ===========================================================================226// private227// ===========================================================================228229void230GNEDestProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {231switch (key) {232case SUMO_ATTR_ID:233// update microsimID234setAdditionalID(value);235break;236case SUMO_ATTR_EDGE:237myNewEdgeDestination = myNet->getAttributeCarriers()->retrieveEdge(value);238break;239case SUMO_ATTR_PROB:240myProbability = parse<double>(value);241break;242default:243setCommonAttribute(key, value);244break;245}246}247248/****************************************************************************/249250251