Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEChange_EnableAttribute.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-2023 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#include <config.h>
21
22#include <netedit/GNENet.h>
23
25
26// ===========================================================================
27// FOX-declarations
28// ===========================================================================
29FXIMPLEMENT_ABSTRACT(GNEChange_EnableAttribute, GNEChange, nullptr, 0)
30
31// ===========================================================================
32// member method definitions
33// ===========================================================================
34
36 GNEChange(ac->getTagProperty().getSupermode(), true, false),
37 myAC(ac),
38 myKey(key),
39 myOrigValue(ac->isAttributeEnabled(key)),
40 myNewValue(value) {
41 myAC->incRef("GNEChange_EnableAttribute " + myAC->getTagProperty().getTagStr());
42}
43
44
45GNEChange_EnableAttribute::GNEChange_EnableAttribute(GNEAttributeCarrier* ac, const SumoXMLAttr key, const bool value, const int /* previousParameters */) :
46 GNEChange(ac->getTagProperty().getSupermode(), true, false),
47 myAC(ac),
48 myKey(key),
49 myOrigValue(ac->isAttributeEnabled(key)),
50 myNewValue(value) {
51 myAC->incRef("GNEChange_EnableAttribute " + myAC->getTagProperty().getTagStr());
52}
53
54
56 // decrease reference
57 myAC->decRef("GNEChange_EnableAttribute " + myAC->getTagProperty().getTagStr());
58 // remove if is unreferenced
59 if (myAC->unreferenced()) {
60 // show extra information for tests
61 WRITE_DEBUG("Deleting unreferenced " + myAC->getTagStr() + " '" + myAC->getID() + "' in GNEChange_EnableAttribute");
62 // delete AC
63 delete myAC;
64 }
65}
66
67
68void
70 // show extra information for tests
71 WRITE_DEBUG("Setting previous attribute into " + myAC->getTagStr() + " '" + myAC->getID() + "'");
72 // set original value
74 // check if networkElements, additional or shapes has to be saved
77 } else if (myAC->getTagProperty().isAdditionalElement()) {
79 } else if (myAC->getTagProperty().isDemandElement()) {
81 } else if (myAC->getTagProperty().isDataElement()) {
83 } else if (myAC->getTagProperty().isMeanData()) {
85 }
86}
87
88
89void
91 // show extra information for tests
92 WRITE_DEBUG("Setting new attribute into " + myAC->getTagStr() + " '" + myAC->getID() + "'");
93 // set new attributes
95 // check if networkElements, additional or shapes has to be saved
98 } else if (myAC->getTagProperty().isAdditionalElement()) {
100 } else if (myAC->getTagProperty().isDemandElement()) {
102 } else if (myAC->getTagProperty().isDataElement()) {
104 } else if (myAC->getTagProperty().isMeanData()) {
106 }
107}
108
109
110std::string
112 if (myNewValue) {
113 return (TLF("Undo enable % attribute in '%'", myAC->getTagStr(), myAC->getID()));
114 } else {
115 return (TLF("Undo enable % attribute in '%'", myAC->getTagStr(), myAC->getID()));
116 }
117}
118
119
120std::string
122 if (myNewValue) {
123 return (TLF("Redo enable % attribute in '%'", myAC->getTagStr(), myAC->getID()));
124 } else {
125 return (TLF("Redo enable % attribute in '%'", myAC->getTagStr(), myAC->getID()));
126 }
127}
128
129/****************************************************************************/
#define WRITE_DEBUG(msg)
Definition MsgHandler.h:281
#define TLF(string,...)
Definition MsgHandler.h:288
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
const std::string getID() const
get ID (all Attribute Carriers have one)
virtual void toggleAttribute(SumoXMLAttr key, const bool value)
method for enable or disable the attribute and nothing else (used in GNEChange_EnableAttribute)
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * getNet() const
get pointer to net
the function-object for an editing operation (abstract base)
GNEAttributeCarrier * myAC
the net to which all operations shall be applied
std::string redoName() const
get Redo name
const bool myNewValue
the new value
const SumoXMLAttr myKey
The attribute name.
GNEChange_EnableAttribute(GNEAttributeCarrier *ac, const SumoXMLAttr key, const bool value)
constructor
const bool myOrigValue
the original value
std::string undoName() const
return undoName
the function-object for an editing operation (abstract base)
Definition GNEChange.h:56
void requireSaveNetwork()
inform that network has to be saved
void requireSaveMeanDatas()
inform that mean data elements has to be saved
void requireSaveAdditionals()
inform that additionals has to be saved
void requireSaveDataElements()
inform that data elements has to be saved
void requireSaveDemandElements()
inform that demand elements has to be saved
GNENetHelper::SavingStatus * getSavingStatus() const
get saving status
Definition GNENet.cpp:126
void decRef(const std::string &debugMsg="")
Decrease reference.
void incRef(const std::string &debugMsg="")
Increase reference.
bool unreferenced()
check if object ins't referenced
bool isMeanData() const
return true if tag correspond to a mean data element
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
bool isNetworkElement() const
return true if tag correspond to a network element
bool isDataElement() const
return true if tag correspond to a data element
bool isDemandElement() const
return true if tag correspond to a demand element
bool isAdditionalElement() const
return true if tag correspond to an additional element (note: this include TAZ, shapes and wires)