Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEChange_ToggleAttribute.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// A network change in which something is changed (for undo/redo)
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
23#include <netedit/GNEViewNet.h>
26
28
29// ===========================================================================
30// FOX-declarations
31// ===========================================================================
32
33FXIMPLEMENT_ABSTRACT(GNEChange_ToggleAttribute, GNEChange, nullptr, 0)
34
35// ===========================================================================
36// member method definitions
37// ===========================================================================
38
40 GNEChange(ac->getTagProperty()->getSupermode(), true, false),
41 myAC(ac),
42 myKey(key),
43 myOrigValue(ac->isAttributeEnabled(key)),
45 myAC->incRef("GNEChange_ToggleAttribute " + myAC->getTagProperty()->getTagStr());
46}
47
48
50 // only continue we have undo-redo mode enabled
51 if (myAC->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed()) {
52 // decrease reference
53 myAC->decRef("GNEChange_ToggleAttribute " + myAC->getTagProperty()->getTagStr());
54 // remove if is unreferenced
55 if (myAC->unreferenced()) {
56 // delete AC
57 delete myAC;
58 }
59 }
60}
61
62
63void
65 // set original value
66 myAC->toggleAttribute(myKey, myOrigValue);
67 // check if networkElements, additional or shapes has to be saved
68 if (myAC->getTagProperty()->isNetworkElement()) {
69 myAC->getNet()->getSavingStatus()->requireSaveNetwork();
70 } else if (myAC->getTagProperty()->isAdditionalElement()) {
71 myAC->getNet()->getSavingStatus()->requireSaveAdditionals();
72 } else if (myAC->getTagProperty()->isDemandElement()) {
73 myAC->getNet()->getSavingStatus()->requireSaveDemandElements();
74 } else if (myAC->getTagProperty()->isDataElement()) {
75 myAC->getNet()->getSavingStatus()->requireSaveDataElements();
76 } else if (myAC->getTagProperty()->isMeanData()) {
77 myAC->getNet()->getSavingStatus()->requireSaveMeanDatas();
78 }
79}
80
81
82void
84 // set new attributes
85 myAC->toggleAttribute(myKey, myNewValue);
86 // check if networkElements, additional or shapes has to be saved
87 if (myAC->getTagProperty()->isNetworkElement()) {
88 myAC->getNet()->getSavingStatus()->requireSaveNetwork();
89 } else if (myAC->getTagProperty()->isAdditionalElement()) {
90 myAC->getNet()->getSavingStatus()->requireSaveAdditionals();
91 } else if (myAC->getTagProperty()->isDemandElement()) {
92 myAC->getNet()->getSavingStatus()->requireSaveDemandElements();
93 } else if (myAC->getTagProperty()->isDataElement()) {
94 myAC->getNet()->getSavingStatus()->requireSaveDataElements();
95 } else if (myAC->getTagProperty()->isMeanData()) {
96 myAC->getNet()->getSavingStatus()->requireSaveMeanDatas();
97 }
98}
99
100
101std::string
103 return (TLF("Undo toggle % attribute in '%'", myAC->getTagStr(), myAC->getID()));
104}
105
106
107std::string
109 return (TLF("Redo toggle % attribute in '%'", myAC->getTagStr(), myAC->getID()));
110}
111
112/****************************************************************************/
#define TLF(string,...)
Definition MsgHandler.h:306
const std::string invalid_return< std::string >::value
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
the function-object for an editing operation (abstract base)
const bool myOrigValue
the original value
GNEAttributeCarrier * myAC
the net to which all operations shall be applied
std::string redoName() const
get Redo name
GNEChange_ToggleAttribute(GNEAttributeCarrier *ac, const SumoXMLAttr key, const bool value)
constructor
std::string undoName() const
return undoName
const bool myNewValue
the new value
const SumoXMLAttr myKey
The attribute name.
the function-object for an editing operation (abstract base)
Definition GNEChange.h:56
Supermode getSupermode() const
get supermode
Definition GNEChange.cpp:66
GNEChange(Supermode supermode, bool forward, const bool selectedElement)
Constructor.
Definition GNEChange.cpp:34