Path: blob/main/src/netedit/elements/demand/GNERouteRef.cpp
185790 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 GNERouteRef.cpp14/// @author Pablo Alvarez Lopez15/// @date April 202516///17// A class for route references18/****************************************************************************/1920#include <netedit/GNENet.h>21#include <netedit/GNETagProperties.h>22#include <netedit/changes/GNEChange_Attribute.h>2324#include "GNERouteRef.h"25#include "GNEVehicle.h"2627// ===========================================================================28// GNERouteRef - methods29// ===========================================================================3031GNERouteRef::GNERouteRef(GNENet* net) :32GNEDemandElement(net, GNE_TAG_ROUTEREF) {33}343536GNERouteRef::GNERouteRef(GNEDemandElement* distributionParent, GNEDemandElement* routeParent) :37GNEDemandElement(distributionParent, GNE_TAG_ROUTEREF) {38// set parents39setParents<GNEDemandElement*>({distributionParent, routeParent});40}414243GNERouteRef::GNERouteRef(GNEDemandElement* distributionParent, GNEDemandElement* routeParent,44const double probability) :45GNEDemandElement(distributionParent, GNE_TAG_ROUTEREF),46myProbability(probability) {47// set parents48setParents<GNEDemandElement*>({distributionParent, routeParent});49}505152GNERouteRef::~GNERouteRef() {}535455GNEMoveElement*56GNERouteRef::getMoveElement() const {57return nullptr;58}596061Parameterised*62GNERouteRef::getParameters() {63return nullptr;64}656667const Parameterised*68GNERouteRef::getParameters() const {69return nullptr;70}717273GUIGLObjectPopupMenu*74GNERouteRef::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {75// create popup76GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);77// build common options78buildPopUpMenuCommonOptions(ret, app, myNet->getViewNet(), myTagProperty->getTag(), mySelected);79return ret;80}818283void84GNERouteRef::writeDemandElement(OutputDevice& device) const {85device.openTag(SUMO_TAG_ROUTE);86device.writeAttr(SUMO_ATTR_REFID, getAttribute(SUMO_ATTR_REFID));87if (myProbability != INVALID_DOUBLE) {88device.writeAttr(SUMO_ATTR_PROB, myProbability);89}90// close tag91device.closeTag();92}939495GNEDemandElement::Problem96GNERouteRef::isDemandElementValid() const {97return Problem::OK;98}99100101std::string102GNERouteRef::getDemandElementProblem() const {103return "";104}105106107void108GNERouteRef::fixDemandElementProblem() {109// currently the only solution is removing Route110}111112113SUMOVehicleClass114GNERouteRef::getVClass() const {115return getParentDemandElements().back()->getVClass();116}117118119const RGBColor&120GNERouteRef::getColor() const {121return RGBColor::INVISIBLE;122}123124125void126GNERouteRef::updateGeometry() {127// nothing to update128}129130131Position132GNERouteRef::getPositionInView() const {133return getParentDemandElements().front()->getPositionInView();134}135136137std::string138GNERouteRef::getParentName() const {139return getParentDemandElements().front()->getID();140}141142143double144GNERouteRef::getExaggeration(const GUIVisualizationSettings& /*s*/) const {145return 1;146}147148149Boundary150GNERouteRef::getCenteringBoundary() const {151if (getParentDemandElements().size() > 1) {152return getParentDemandElements().at(1)->getCenteringBoundary();153} else {154return Boundary(-0.1, -0.1, 0.1, 0.1);155}156}157158159void160GNERouteRef::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/,161const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {162// nothing to do163}164165166void167GNERouteRef::drawGL(const GUIVisualizationSettings& /*s*/) const {168// nothing to draw169}170171172void173GNERouteRef::computePathElement() {174// nothing to do175}176177178void179GNERouteRef::drawLanePartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {180// nothing to draw181}182183184void185GNERouteRef::drawJunctionPartialGL(const GUIVisualizationSettings& /*s*/, const GNESegment* /*segment*/, const double /*offsetFront*/) const {186// nothing to draw187}188189190GNELane*191GNERouteRef::getFirstPathLane() const {192return getParentDemandElements().back()->getFirstPathLane();193}194195196GNELane*197GNERouteRef::getLastPathLane() const {198return getParentDemandElements().back()->getLastPathLane();199}200201202std::string203GNERouteRef::getAttribute(SumoXMLAttr key) const {204switch (key) {205case SUMO_ATTR_ID:206return getMicrosimID();207case SUMO_ATTR_REFID:208return getParentDemandElements().back()->getID();209case SUMO_ATTR_PROB:210if (myProbability == INVALID_DOUBLE) {211return getParentDemandElements().at(1)->getAttribute(key);212} else {213return toString(myProbability);214}215case GNE_ATTR_DEFAULT_PROBABILITY:216return (myProbability == INVALID_DOUBLE) ? TRUE_STR : FALSE_STR;217default:218return getCommonAttribute(key);219}220}221222223double224GNERouteRef::getAttributeDouble(SumoXMLAttr key) const {225switch (key) {226case SUMO_ATTR_PROB:227if (myProbability == INVALID_DOUBLE) {228return getParentDemandElements().at(1)->getAttributeDouble(key);229} else {230return myProbability;231}232default:233return getCommonAttributeDouble(key);234}235}236237238Position239GNERouteRef::getAttributePosition(SumoXMLAttr key) const {240return getCommonAttributePosition(key);241}242243244bool245GNERouteRef::isAttributeEnabled(SumoXMLAttr key) const {246switch (key) {247case SUMO_ATTR_REFID:248return false;249default:250return true;251}252}253254255void256GNERouteRef::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {257if (value == getAttribute(key)) {258return; //avoid needless changes, later logic relies on the fact that attributes have changed259}260switch (key) {261case SUMO_ATTR_PROB:262GNEChange_Attribute::changeAttribute(this, key, value, undoList);263break;264default:265setCommonAttribute(key, value, undoList);266break;267}268}269270271bool272GNERouteRef::isValid(SumoXMLAttr key, const std::string& value) {273switch (key) {274case SUMO_ATTR_PROB:275if (value.empty()) {276return true;277} else {278return canParse<double>(value) && (parse<double>(value) >= 0);279}280default:281return isCommonAttributeValid(key, value);282}283}284285bool286GNERouteRef::isAttributeComputed(SumoXMLAttr key) const {287switch (key) {288case SUMO_ATTR_PROB:289return myProbability == INVALID_DOUBLE;290default:291return false;292}293}294295std::string296GNERouteRef::getPopUpID() const {297return getTagStr();298}299300301std::string302GNERouteRef::getHierarchyName() const {303return TLF("%: %, %", myTagProperty->getTagStr(), getParentDemandElements().back()->getID(), getAttribute(SUMO_ATTR_PROB));304}305306// ===========================================================================307// private308// ===========================================================================309310void311GNERouteRef::setAttribute(SumoXMLAttr key, const std::string& value) {312switch (key) {313case SUMO_ATTR_PROB:314if (value.empty()) {315myProbability = INVALID_DOUBLE;316} else {317myProbability = parse<double>(value);318}319break;320default:321setCommonAttribute(key, value);322break;323}324}325326/****************************************************************************/327328329