Path: blob/main/src/netedit/elements/additional/GNERerouterInterval.cpp
193716 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 GNERerouterInterval.cpp14/// @author Pablo Alvarez Lopez15/// @date Jan 201716///17//18/****************************************************************************/1920#include <netedit/GNENet.h>21#include <netedit/changes/GNEChange_Attribute.h>2223#include "GNERerouterInterval.h"2425// ===========================================================================26// member method definitions27// ===========================================================================2829GNERerouterInterval::GNERerouterInterval(GNENet* net) :30GNEAdditional(net, SUMO_TAG_INTERVAL),31GNEAdditionalListed(this) {32}333435GNERerouterInterval::GNERerouterInterval(GNEAdditional* rerouterParent, const SUMOTime begin, const SUMOTime end) :36GNEAdditional(rerouterParent, SUMO_TAG_INTERVAL, ""),37GNEAdditionalListed(this),38myBegin(begin),39myEnd(end) {40// set parents41setParent<GNEAdditional*>(rerouterParent);42// update boundary of rerouter parent43rerouterParent->updateCenteringBoundary(true);44}454647GNERerouterInterval::~GNERerouterInterval() {}484950GNEMoveElement*51GNERerouterInterval::getMoveElement() const {52return nullptr;53}545556Parameterised*57GNERerouterInterval::getParameters() {58return nullptr;59}606162const Parameterised*63GNERerouterInterval::getParameters() const {64return nullptr;65}666768void69GNERerouterInterval::writeAdditional(OutputDevice& device) const {70// avoid write empty intervals71if (getChildAdditionals().size() > 0) {72device.openTag(SUMO_TAG_INTERVAL);73// write common additional attributes74writeAdditionalAttributes(device);75// write specific attributes76device.writeAttr(SUMO_ATTR_BEGIN, getAttribute(SUMO_ATTR_BEGIN));77device.writeAttr(SUMO_ATTR_END, getAttribute(SUMO_ATTR_END));78// write all rerouter interval79for (const auto& rerouterElement : getChildAdditionals()) {80rerouterElement->writeAdditional(device);81}82device.closeTag();83}84}858687bool88GNERerouterInterval::isAdditionalValid() const {89return true;90}919293std::string94GNERerouterInterval::getAdditionalProblem() const {95return "";96}979899void100GNERerouterInterval::fixAdditionalProblem() {101// nothing to fix102}103104105bool106GNERerouterInterval::checkDrawMoveContour() const {107return false;108}109110111void112GNERerouterInterval::updateGeometry() {113updateGeometryListedAdditional();114}115116117Position118GNERerouterInterval::getPositionInView() const {119return getListedPositionInView();120}121122123void124GNERerouterInterval::updateCenteringBoundary(const bool /*updateGrid*/) {125// nothing to do126}127128129void130GNERerouterInterval::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {131// geometry of this element cannot be splitted132}133134135std::string136GNERerouterInterval::getParentName() const {137return getParentAdditionals().at(0)->getID();138}139140141void142GNERerouterInterval::drawGL(const GUIVisualizationSettings& s) const {143// draw rerouter interval as listed attribute144drawListedAdditional(s, RGBColor::RED, RGBColor::YELLOW, GUITexture::REROUTER_INTERVAL,145getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END));146const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();147// iterate over additionals and check if drawn148for (const auto& rerouterElement : getChildAdditionals()) {149// if rerouter or their child is selected, then draw150if (isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||151rerouterElement->isAttributeCarrierSelected() || inspectedElements.isACInspected(rerouterElement) ||152rerouterElement->isMarkedForDrawingFront()) {153rerouterElement->drawGL(s);154}155}156}157158159std::string160GNERerouterInterval::getAttribute(SumoXMLAttr key) const {161switch (key) {162case SUMO_ATTR_ID:163return getParentAdditionals().front()->getID();164case SUMO_ATTR_BEGIN:165return time2string(myBegin);166case SUMO_ATTR_END:167return time2string(myEnd);168case GNE_ATTR_PARENT:169return getParentAdditionals().at(0)->getID();170default:171return getCommonAttribute(key);172}173}174175176double177GNERerouterInterval::getAttributeDouble(SumoXMLAttr key) const {178switch (key) {179case SUMO_ATTR_BEGIN:180return STEPS2TIME(myBegin);181case SUMO_ATTR_END:182return STEPS2TIME(myEnd);183default:184return getCommonAttributeDouble(key);185}186}187188189Position190GNERerouterInterval::getAttributePosition(SumoXMLAttr key) const {191return getCommonAttributePosition(key);192}193194195PositionVector196GNERerouterInterval::getAttributePositionVector(SumoXMLAttr key) const {197return getCommonAttributePositionVector(key);198}199200201void202GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {203if (value == getAttribute(key)) {204return; //avoid needless changes, later logic relies on the fact that attributes have changed205}206switch (key) {207case SUMO_ATTR_BEGIN:208case SUMO_ATTR_END:209GNEChange_Attribute::changeAttribute(this, key, value, undoList);210break;211default:212setCommonAttribute(key, value, undoList);213break;214}215}216217218bool219GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {220switch (key) {221case SUMO_ATTR_BEGIN:222if (canParse<SUMOTime>(value)) {223const auto begin = parse<SUMOTime>(value);224if (begin < 0) {225return false;226} else {227return (begin <= myEnd);228}229} else {230return false;231}232case SUMO_ATTR_END:233if (canParse<SUMOTime>(value)) {234const auto end = parse<SUMOTime>(value);235if (end < 0) {236return false;237} else {238return (myBegin <= end);239}240} else {241return false;242}243default:244return isCommonAttributeValid(key, value);245}246}247248249std::string250GNERerouterInterval::getPopUpID() const {251return getTagStr();252}253254255std::string256GNERerouterInterval::getHierarchyName() const {257return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);258}259260// ===========================================================================261// private262// ===========================================================================263264void265GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {266switch (key) {267case SUMO_ATTR_BEGIN:268myBegin = parse<SUMOTime>(value);269break;270case SUMO_ATTR_END:271myEnd = parse<SUMOTime>(value);272break;273default:274setCommonAttribute(key, value);275break;276}277}278279/****************************************************************************/280281282