/****************************************************************************/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 GNEChange_Lane.cpp14/// @author Jakob Erdmann15/// @date April 201116///17// A network change in which a single lane is created or deleted18/****************************************************************************/1920#include <netedit/GNENet.h>21#include <netedit/GNEViewNet.h>22#include <netedit/GNEViewParent.h>23#include <netedit/GNEApplicationWindow.h>2425#include "GNEChange_Lane.h"2627// ===========================================================================28// FOX-declarations29// ===========================================================================3031FXIMPLEMENT_ABSTRACT(GNEChange_Lane, GNEChange, nullptr, 0)3233// ===========================================================================34// member method definitions35// ===========================================================================3637GNEChange_Lane::GNEChange_Lane(GNEEdge* edge, const NBEdge::Lane& laneAttrs):38GNEChange(Supermode::NETWORK, true, false),39myEdge(edge),40myLane(nullptr),41myLaneAttrs(laneAttrs),42myRecomputeConnections(true) {43myEdge->incRef("GNEChange_Lane");44}454647GNEChange_Lane::GNEChange_Lane(GNEEdge* edge, GNELane* lane, const NBEdge::Lane& laneAttrs, bool forward, bool recomputeConnections):48GNEChange(Supermode::NETWORK, lane, forward, lane->isAttributeCarrierSelected()),49myEdge(edge),50myLane(lane),51myLaneAttrs(laneAttrs),52myRecomputeConnections(recomputeConnections) {53// include both references (To edge and lane)54myEdge->incRef("GNEChange_Lane");55myLane->incRef("GNEChange_Lane");56}575859GNEChange_Lane::~GNEChange_Lane() {60// only continue we have undo-redo mode enabled61if (myEdge->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed()) {62myEdge->decRef("GNEChange_Lane");63if (myEdge->unreferenced()) {64delete myEdge;65}66if (myLane) {67myLane->decRef("GNEChange_Lane");68if (myLane->unreferenced()) {69// delete lane70delete myLane;71}72}73}74}757677void78GNEChange_Lane::undo() {79if (myForward) {80// remove lane from edge (note: myLane can be nullptr)81myEdge->removeLane(myLane, false);82// special case if lane exist83if (myLane && mySelectedElement) {84myLane->unselectAttributeCarrier();85}86} else {87// show extra information for tests88if (myLane && mySelectedElement) {89myLane->selectAttributeCarrier();90}91// add lane and their attributes to edge (lane removal is reverted, no need to recompute connections)92myEdge->addLane(myLane, myLaneAttrs, false);93}94// enable save networkElements95myEdge->getNet()->getSavingStatus()->requireSaveNetwork();96}979899void100GNEChange_Lane::redo() {101if (myForward) {102// show extra information for tests103if (myLane && mySelectedElement) {104myLane->selectAttributeCarrier();105}106// add lane and their attributes to edge107myEdge->addLane(myLane, myLaneAttrs, myRecomputeConnections);108} else {109// special case if lane exist110if (myLane && mySelectedElement) {111myLane->unselectAttributeCarrier();112}113// remove lane from edge114myEdge->removeLane(myLane, myRecomputeConnections);115}116// enable save networkElements117myEdge->getNet()->getSavingStatus()->requireSaveNetwork();118}119120121std::string122GNEChange_Lane::undoName() const {123if (myForward) {124return (TL("Undo create lane '") + myLane->getID() + "'");125} else {126return (TL("Undo delete lane '") + myLane->getID() + "'");127}128}129130131std::string132GNEChange_Lane::redoName() const {133if (myForward) {134return (TL("Redo create lane '") + myLane->getID() + "'");135} else {136return (TL("Redo delete lane '") + myLane->getID() + "'");137}138}139140141