Path: blob/main/src/netedit/changes/GNEChange_Junction.cpp
169678 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 GNEChange_Junction.cpp14/// @author Jakob Erdmann15/// @date Mar 201116///17// A network change in which a single junction 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_Junction.h"2627// ===========================================================================28// FOX-declarations29// ===========================================================================3031FXIMPLEMENT_ABSTRACT(GNEChange_Junction, GNEChange, nullptr, 0)3233// ===========================================================================34// member method definitions35// ===========================================================================363738/// @brief constructor for creating a junction39GNEChange_Junction::GNEChange_Junction(GNEJunction* junction, bool forward):40GNEChange(Supermode::NETWORK, junction, forward, junction->isAttributeCarrierSelected()),41myJunction(junction) {42junction->incRef("GNEChange_Junction");43}444546GNEChange_Junction::~GNEChange_Junction() {47// only continue we have undo-redo mode enabled48if (myJunction->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed()) {49myJunction->decRef("GNEChange_Junction");50if (myJunction->unreferenced()) {51delete myJunction;52}53}54}555657void58GNEChange_Junction::undo() {59if (myForward) {60// unselect if mySelectedElement is enabled61if (mySelectedElement) {62myJunction->unselectAttributeCarrier();63}64// delete junction from net65myJunction->getNet()->getAttributeCarriers()->deleteSingleJunction(myJunction);66// remove element from parent and children67removeElementFromParentsAndChildren(myJunction);68} else {69// select if mySelectedElement is enabled70if (mySelectedElement) {71myJunction->selectAttributeCarrier();72}73// add element in parent and children74addElementInParentsAndChildren(myJunction);75// insert junction in net76myJunction->getNet()->getAttributeCarriers()->insertJunction(myJunction);77}78// enable save networkElements79myJunction->getNet()->getSavingStatus()->requireSaveNetwork();80}818283void84GNEChange_Junction::redo() {85if (myForward) {86// select if mySelectedElement is enabled87if (mySelectedElement) {88myJunction->selectAttributeCarrier();89}90// add element in parent and children91addElementInParentsAndChildren(myJunction);92// add junction into net93myJunction->getNet()->getAttributeCarriers()->insertJunction(myJunction);94} else {95// unselect if mySelectedElement is enabled96if (mySelectedElement) {97myJunction->unselectAttributeCarrier();98}99// add element in parent and children100addElementInParentsAndChildren(myJunction);101// delete junction from net102myJunction->getNet()->getAttributeCarriers()->deleteSingleJunction(myJunction);103// remove element from parent and children104removeElementFromParentsAndChildren(myJunction);105}106// enable save networkElements107myJunction->getNet()->getSavingStatus()->requireSaveNetwork();108}109110111std::string112GNEChange_Junction::undoName() const {113if (myForward) {114return (TL("Undo create junction '") + myJunction->getID() + "'");115} else {116return (TL("Undo delete junction '") + myJunction->getID() + "'");117}118}119120121std::string122GNEChange_Junction::redoName() const {123if (myForward) {124return (TL("Redo create junction '") + myJunction->getID() + "'");125} else {126return (TL("Redo delete junction '") + myJunction->getID() + "'");127}128}129130131