Path: blob/main/src/netedit/changes/GNEChange_Attribute.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_Attribute.cpp14/// @author Jakob Erdmann15/// @date Mar 201116///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>25#include <netedit/GNEUndoList.h>26#include <netedit/elements/data/GNEDataSet.h>2728#include "GNEChange_Attribute.h"2930// ===========================================================================31// FOX-declarations32// ===========================================================================3334FXIMPLEMENT_ABSTRACT(GNEChange_Attribute, GNEChange, nullptr, 0)3536// ===========================================================================37// member method definitions38// ===========================================================================3940void41GNEChange_Attribute::changeAttribute(GNEAttributeCarrier* AC, SumoXMLAttr key, const std::string& value, GNEUndoList* undoList, const bool force) {42if (AC->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed()) {43// create change44auto change = new GNEChange_Attribute(AC, key, value);45// set force46change->myForceChange = force;47// check if process change48if (change->trueChange()) {49undoList->begin(AC, TLF("change '%' attribute in % '%' to '%'", toString(key), AC->getTagStr(), AC->getID(), value));50undoList->add(change, true);51undoList->end();52} else {53delete change;54}55} else {56AC->setAttribute(key, value);57}58}596061void62GNEChange_Attribute::changeAttribute(GNEAttributeCarrier* AC, SumoXMLAttr key, const std::string& value, const std::string& originalValue, GNEUndoList* undoList, const bool force) {63if (AC->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed()) {64// create change65auto change = new GNEChange_Attribute(AC, key, value, originalValue);66// set force67change->myForceChange = force;68// check if process change69if (change->trueChange()) {70undoList->begin(AC, TLF("change '%' attribute in % '%' to '%'", toString(key), AC->getTagStr(), AC->getID(), value));71undoList->add(change, true);72undoList->end();73} else {74delete change;75}76} else {77AC->setAttribute(key, value);78}79}808182GNEChange_Attribute::~GNEChange_Attribute() {83// only continue we have undo-redo mode enabled84if (myAC->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed()) {85// decrease reference86myAC->decRef("GNEChange_Attribute " + toString(myKey));87// remove if is unreferenced88if (myAC->unreferenced()) {89// delete AC90delete myAC;91}92}93}949596void97GNEChange_Attribute::undo() {98// set original value99myAC->setAttribute(myKey, myOrigValue);100// certain attributes needs extra operations101if (myKey != GNE_ATTR_SELECTED) {102// check if updated attribute requires a update geometry103if (myAC->getTagProperty()->hasAttribute(myKey) && myAC->getTagProperty()->getAttributeProperties(myKey)->requireUpdateGeometry()) {104myAC->updateGeometry();105}106// if is a dataelement, update attribute colors107if (myAC->getTagProperty()->isGenericData()) {108myAC->getNet()->getAttributeCarriers()->retrieveDataSet(myAC->getAttribute(GNE_ATTR_DATASET))->updateAttributeColors();109} else if (myAC->getTagProperty()->getTag() == SUMO_TAG_DATASET) {110myAC->getNet()->getAttributeCarriers()->retrieveDataSet(myAC->getAttribute(SUMO_ATTR_ID))->updateAttributeColors();111}112// check if networkElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)113if (myAC->getTagProperty()->isNetworkElement()) {114myAC->getNet()->getSavingStatus()->requireSaveNetwork();115} else if (myAC->getTagProperty()->isAdditionalElement()) {116myAC->getNet()->getSavingStatus()->requireSaveAdditionals();117} else if (myAC->getTagProperty()->isDemandElement()) {118myAC->getNet()->getSavingStatus()->requireSaveDemandElements();119} else if (myAC->getTagProperty()->isDataElement()) {120myAC->getNet()->getSavingStatus()->requireSaveDataElements();121} else if (myAC->getTagProperty()->isMeanData()) {122myAC->getNet()->getSavingStatus()->requireSaveMeanDatas();123}124}125}126127128void129GNEChange_Attribute::redo() {130// set new value131myAC->setAttribute(myKey, myNewValue);132// certain attributes needs extra operations133if (myKey != GNE_ATTR_SELECTED) {134// check if updated attribute requires a update geometry135if (myAC->getTagProperty()->hasAttribute(myKey) && myAC->getTagProperty()->getAttributeProperties(myKey)->requireUpdateGeometry()) {136myAC->updateGeometry();137}138// if is a dataelement, update attribute colors139if (myAC->getTagProperty()->isGenericData()) {140myAC->getNet()->getAttributeCarriers()->retrieveDataSet(myAC->getAttribute(GNE_ATTR_DATASET))->updateAttributeColors();141} else if (myAC->getTagProperty()->getTag() == SUMO_TAG_DATASET) {142myAC->getNet()->getAttributeCarriers()->retrieveDataSet(myAC->getAttribute(SUMO_ATTR_ID))->updateAttributeColors();143}144// check if networkElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)145if (myAC->getTagProperty()->isNetworkElement()) {146myAC->getNet()->getSavingStatus()->requireSaveNetwork();147} else if (myAC->getTagProperty()->isAdditionalElement()) {148myAC->getNet()->getSavingStatus()->requireSaveAdditionals();149} else if (myAC->getTagProperty()->isDemandElement()) {150myAC->getNet()->getSavingStatus()->requireSaveDemandElements();151} else if (myAC->getTagProperty()->isDataElement()) {152myAC->getNet()->getSavingStatus()->requireSaveDataElements();153} else if (myAC->getTagProperty()->isMeanData()) {154myAC->getNet()->getSavingStatus()->requireSaveMeanDatas();155}156}157}158159160std::string161GNEChange_Attribute::undoName() const {162return (TL("Undo change ") + myAC->getTagStr() + " attribute");163}164165166std::string167GNEChange_Attribute::redoName() const {168return (TL("Redo change ") + myAC->getTagStr() + " attribute");169}170171172GNEChange_Attribute::GNEChange_Attribute(GNEAttributeCarrier* ac, SumoXMLAttr key, const std::string& value) :173GNEChange(ac->getTagProperty()->getSupermode(), true, false),174myAC(ac),175myKey(key),176myForceChange(false),177myOrigValue(ac->getAttribute(key)),178myNewValue(value) {179myAC->incRef("GNEChange_Attribute " + toString(myKey));180}181182183GNEChange_Attribute::GNEChange_Attribute(GNEAttributeCarrier* ac, SumoXMLAttr key, const std::string& value, const std::string& origValue) :184GNEChange(ac->getTagProperty()->getSupermode(), true, false),185myAC(ac),186myKey(key),187myForceChange(false),188myOrigValue(origValue),189myNewValue(value) {190myAC->incRef("GNEChange_Attribute " + toString(myKey));191}192193194bool195GNEChange_Attribute::trueChange() {196// check if we're editing the value of an attribute or changing a disjoint attribute197if (myForceChange) {198return true;199} else {200return (myOrigValue != myNewValue);201}202}203204/****************************************************************************/205206207