Path: blob/main/src/netedit/changes/GNEChange_ToggleAttribute.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_ToggleAttribute.cpp14/// @author Pablo Alvarez Lopez15/// @date Aug 201916///17// A network change in which something is changed (for undo/redo)18/****************************************************************************/1920#include <netedit/GNENet.h>21#include <netedit/GNETagProperties.h>22#include <netedit/GNEViewNet.h>23#include <netedit/GNEViewParent.h>24#include <netedit/GNEApplicationWindow.h>2526#include "GNEChange_ToggleAttribute.h"2728// ===========================================================================29// FOX-declarations30// ===========================================================================3132FXIMPLEMENT_ABSTRACT(GNEChange_ToggleAttribute, GNEChange, nullptr, 0)3334// ===========================================================================35// member method definitions36// ===========================================================================3738GNEChange_ToggleAttribute::GNEChange_ToggleAttribute(GNEAttributeCarrier* ac, const SumoXMLAttr key, const bool value) :39GNEChange(ac->getTagProperty()->getSupermode(), true, false),40myAC(ac),41myKey(key),42myOrigValue(ac->isAttributeEnabled(key)),43myNewValue(value) {44myAC->incRef("GNEChange_ToggleAttribute " + myAC->getTagProperty()->getTagStr());45}464748GNEChange_ToggleAttribute::~GNEChange_ToggleAttribute() {49// only continue we have undo-redo mode enabled50if (myAC->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed()) {51// decrease reference52myAC->decRef("GNEChange_ToggleAttribute " + myAC->getTagProperty()->getTagStr());53// remove if is unreferenced54if (myAC->unreferenced()) {55// delete AC56delete myAC;57}58}59}606162void63GNEChange_ToggleAttribute::undo() {64// set original value65myAC->toggleAttribute(myKey, myOrigValue);66// check if networkElements, additional or shapes has to be saved67if (myAC->getTagProperty()->isNetworkElement()) {68myAC->getNet()->getSavingStatus()->requireSaveNetwork();69} else if (myAC->getTagProperty()->isAdditionalElement()) {70myAC->getNet()->getSavingStatus()->requireSaveAdditionals();71} else if (myAC->getTagProperty()->isDemandElement()) {72myAC->getNet()->getSavingStatus()->requireSaveDemandElements();73} else if (myAC->getTagProperty()->isDataElement()) {74myAC->getNet()->getSavingStatus()->requireSaveDataElements();75} else if (myAC->getTagProperty()->isMeanData()) {76myAC->getNet()->getSavingStatus()->requireSaveMeanDatas();77}78}798081void82GNEChange_ToggleAttribute::redo() {83// set new attributes84myAC->toggleAttribute(myKey, myNewValue);85// check if networkElements, additional or shapes has to be saved86if (myAC->getTagProperty()->isNetworkElement()) {87myAC->getNet()->getSavingStatus()->requireSaveNetwork();88} else if (myAC->getTagProperty()->isAdditionalElement()) {89myAC->getNet()->getSavingStatus()->requireSaveAdditionals();90} else if (myAC->getTagProperty()->isDemandElement()) {91myAC->getNet()->getSavingStatus()->requireSaveDemandElements();92} else if (myAC->getTagProperty()->isDataElement()) {93myAC->getNet()->getSavingStatus()->requireSaveDataElements();94} else if (myAC->getTagProperty()->isMeanData()) {95myAC->getNet()->getSavingStatus()->requireSaveMeanDatas();96}97}9899100std::string101GNEChange_ToggleAttribute::undoName() const {102return (TLF("Undo toggle % attribute in '%'", myAC->getTagStr(), myAC->getID()));103}104105106std::string107GNEChange_ToggleAttribute::redoName() const {108return (TLF("Redo toggle % attribute in '%'", myAC->getTagStr(), myAC->getID()));109}110111/****************************************************************************/112113114