Path: blob/main/src/netedit/elements/additional/GNERerouterInterval.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 GNERerouterInterval.cpp14/// @author Pablo Alvarez Lopez15/// @date Jan 201716///17//18/****************************************************************************/19#include <config.h>2021#include <netedit/GNENet.h>22#include <netedit/GNEUndoList.h>23#include <netedit/GNEViewNet.h>24#include <netedit/changes/GNEChange_Attribute.h>2526#include "GNERerouterInterval.h"2728// ===========================================================================29// member method definitions30// ===========================================================================3132GNERerouterInterval::GNERerouterInterval(GNENet* net) :33GNEAdditional("", net, "", SUMO_TAG_INTERVAL, "") {34}353637GNERerouterInterval::GNERerouterInterval(GNEAdditional* rerouterParent, SUMOTime begin, SUMOTime end) :38GNEAdditional(rerouterParent, SUMO_TAG_INTERVAL, ""),39myBegin(begin),40myEnd(end) {41// set parents42setParent<GNEAdditional*>(rerouterParent);43// update boundary of rerouter parent44rerouterParent->updateCenteringBoundary(true);45}464748GNERerouterInterval::~GNERerouterInterval() {}495051void52GNERerouterInterval::writeAdditional(OutputDevice& device) const {53// avoid write empty intervals54if (getChildAdditionals().size() > 0) {55device.openTag(SUMO_TAG_INTERVAL);56device.writeAttr(SUMO_ATTR_BEGIN, getAttribute(SUMO_ATTR_BEGIN));57device.writeAttr(SUMO_ATTR_END, getAttribute(SUMO_ATTR_END));58// write all rerouter interval59for (const auto& rerouterElement : getChildAdditionals()) {60rerouterElement->writeAdditional(device);61}62device.closeTag();63}64}656667bool68GNERerouterInterval::isAdditionalValid() const {69return true;70}717273std::string74GNERerouterInterval::getAdditionalProblem() const {75return "";76}777879void80GNERerouterInterval::fixAdditionalProblem() {81// nothing to fix82}838485bool86GNERerouterInterval::checkDrawMoveContour() const {87return false;88}899091GNEMoveOperation*92GNERerouterInterval::getMoveOperation() {93// rerouter intervals cannot be moved94return nullptr;95}969798void99GNERerouterInterval::updateGeometry() {100// update centering boundary (needed for centering)101updateCenteringBoundary(false);102// update geometries (boundaries of all children)103for (const auto& rerouterElement : getChildAdditionals()) {104rerouterElement->updateGeometry();105}106}107108109Position110GNERerouterInterval::getPositionInView() const {111// get rerouter parent position112Position signPosition = getParentAdditionals().front()->getPositionInView();113// set position depending of indexes114signPosition.add(4.5, (getDrawPositionIndex() * -1) + 1, 0);115// return signPosition116return signPosition;117}118119120void121GNERerouterInterval::updateCenteringBoundary(const bool /*updateGrid*/) {122// nothing to do123}124125126void127GNERerouterInterval::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {128// geometry of this element cannot be splitted129}130131132std::string133GNERerouterInterval::getParentName() const {134return getParentAdditionals().at(0)->getID();135}136137138void139GNERerouterInterval::drawGL(const GUIVisualizationSettings& s) const {140const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();141// draw rerouter interval as listed attribute142drawListedAdditional(s, getParentAdditionals().front()->getPositionInView(),1430, 0, RGBColor::RED, RGBColor::YELLOW, GUITexture::REROUTER_INTERVAL,144getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END));145// iterate over additionals and check if drawn146for (const auto& rerouterElement : getChildAdditionals()) {147// if rerouter or their child is selected, then draw148if (isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||149rerouterElement->isAttributeCarrierSelected() || inspectedElements.isACInspected(rerouterElement) ||150rerouterElement->isMarkedForDrawingFront()) {151rerouterElement->drawGL(s);152}153}154}155156157std::string158GNERerouterInterval::getAttribute(SumoXMLAttr key) const {159switch (key) {160case SUMO_ATTR_ID:161return getParentAdditionals().front()->getID();162case SUMO_ATTR_BEGIN:163return time2string(myBegin);164case SUMO_ATTR_END:165return time2string(myEnd);166case GNE_ATTR_PARENT:167return getParentAdditionals().at(0)->getID();168default:169return getCommonAttribute(this, key);170}171}172173174double175GNERerouterInterval::getAttributeDouble(SumoXMLAttr key) const {176switch (key) {177case SUMO_ATTR_BEGIN:178return STEPS2TIME(myBegin);179case SUMO_ATTR_END:180return STEPS2TIME(myEnd);181default:182throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");183}184}185186187const Parameterised::Map&188GNERerouterInterval::getACParametersMap() const {189return getParametersMap();190}191192193void194GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {195if (value == getAttribute(key)) {196return; //avoid needless changes, later logic relies on the fact that attributes have changed197}198switch (key) {199case SUMO_ATTR_BEGIN:200case SUMO_ATTR_END:201GNEChange_Attribute::changeAttribute(this, key, value, undoList);202break;203default:204setCommonAttribute(key, value, undoList);205break;206}207}208209210bool211GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {212switch (key) {213case SUMO_ATTR_BEGIN:214if (canParse<SUMOTime>(value)) {215const auto begin = parse<SUMOTime>(value);216if (begin < 0) {217return false;218} else {219return (begin <= myEnd);220}221} else {222return false;223}224case SUMO_ATTR_END:225if (canParse<SUMOTime>(value)) {226const auto end = parse<SUMOTime>(value);227if (end < 0) {228return false;229} else {230return (myBegin <= end);231}232} else {233return false;234}235default:236return isCommonValid(key, value);237}238}239240241std::string242GNERerouterInterval::getPopUpID() const {243return getTagStr();244}245246247std::string248GNERerouterInterval::getHierarchyName() const {249return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);250}251252// ===========================================================================253// private254// ===========================================================================255256void257GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {258switch (key) {259case SUMO_ATTR_BEGIN:260myBegin = parse<SUMOTime>(value);261break;262case SUMO_ATTR_END:263myEnd = parse<SUMOTime>(value);264break;265default:266setCommonAttribute(this, key, value);267break;268}269}270271272void273GNERerouterInterval::setMoveShape(const GNEMoveResult& /*moveResult*/) {274// nothing to do275}276277278void279GNERerouterInterval::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {280// nothing to do281}282283/****************************************************************************/284285286