Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEChange_Attribute.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>
24
25#include "GNEChange_Attribute.h"
26
27// ===========================================================================
28// FOX-declarations
29// ===========================================================================
30FXIMPLEMENT_ABSTRACT(GNEChange_Attribute, GNEChange, nullptr, 0)
31
32// ===========================================================================
33// member method definitions
34// ===========================================================================
35
37 GNEChange(ac->getTagProperty().getSupermode(), true, false),
38 myAC(ac),
39 myKey(key),
40 myForceChange(false),
41 myOrigValue(ac->getAttribute(key)),
42 myNewValue(value) {
43 myAC->incRef("GNEChange_Attribute " + toString(myKey));
44}
45
46
47GNEChange_Attribute::GNEChange_Attribute(GNEAttributeCarrier* ac, SumoXMLAttr key, const std::string& value, const std::string& origValue) :
48 GNEChange(ac->getTagProperty().getSupermode(), true, false),
49 myAC(ac),
50 myKey(key),
51 myForceChange(false),
52 myOrigValue(origValue),
53 myNewValue(value) {
54 myAC->incRef("GNEChange_Attribute " + toString(myKey));
55}
56
57
59 // decrease reference
60 myAC->decRef("GNEChange_Attribute " + toString(myKey));
61 // remove if is unreferenced
62 if (myAC->unreferenced()) {
63 // show extra information for tests
64 WRITE_DEBUG("Deleting unreferenced " + myAC->getTagStr() + " in GNEChange_Attribute");
65 // delete AC
66 delete myAC;
67 }
68}
69
70
71void
73 // show extra information for tests
74 WRITE_DEBUG("Restoring previous attribute"/* + toString(myKey)*/);
75 // set original value
77 // certain attributes needs extra operations
78 if (myKey != GNE_ATTR_SELECTED) {
79 // check if updated attribute requires a update geometry
82 }
83 // if is a dataelement, update attribute colors
86 } else if (myAC->getTagProperty().getTag() == SUMO_TAG_DATASET) {
88 }
89 // check if networkElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
92 } else if (myAC->getTagProperty().isAdditionalElement()) {
94 } else if (myAC->getTagProperty().isDemandElement()) {
96 } else if (myAC->getTagProperty().isDataElement()) {
98 } else if (myAC->getTagProperty().isMeanData()) {
100 }
101 }
102}
103
104
105void
107 // show extra information for tests
108 WRITE_DEBUG("Setting new attribute"/* + toString(myKey)*/);
109 // set new value
111 // certain attributes needs extra operations
112 if (myKey != GNE_ATTR_SELECTED) {
113 // check if updated attribute requires a update geometry
116 }
117 // if is a dataelement, update attribute colors
120 } else if (myAC->getTagProperty().getTag() == SUMO_TAG_DATASET) {
122 }
123 // check if networkElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
126 } else if (myAC->getTagProperty().isAdditionalElement()) {
128 } else if (myAC->getTagProperty().isDemandElement()) {
130 } else if (myAC->getTagProperty().isDataElement()) {
132 } else if (myAC->getTagProperty().isMeanData()) {
134 }
135 }
136}
137
138
139void
143
144
145bool
147 // check if we're editing the value of an attribute or changing a disjoint attribute
148 if (myForceChange) {
149 return true;
150 } else {
151 return (myOrigValue != myNewValue);
152 }
153}
154
155
156std::string
158 return (TL("Undo change ") + myAC->getTagStr() + " attribute");
159}
160
161
162std::string
164 return (TL("Redo change ") + myAC->getTagStr() + " attribute");
165}
166
167/****************************************************************************/
#define WRITE_DEBUG(msg)
Definition MsgHandler.h:281
#define TL(string)
Definition MsgHandler.h:287
@ SUMO_TAG_DATASET
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_DATASET
data set of a generic data
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
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
virtual void updateGeometry()=0
update pre-computed geometry information
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
virtual std::string getAttribute(SumoXMLAttr key) const =0
bool requireUpdateGeometry() const
return true if attribute requires a update geometry in setAttribute(...)
the function-object for an editing operation (abstract base)
void forceChange()
force change
const SumoXMLAttr myKey
The attribute name (or the original attribute if we're editing a disjoint attribute)
bool myForceChange
flag used to force set attributes
bool trueChange()
wether original and new value differ
std::string undoName() const
return undoName
const std::string myNewValue
the new value
GNEChange_Attribute(GNEAttributeCarrier *ac, const SumoXMLAttr key, const std::string &value)
constructor
GNEAttributeCarrier * myAC
the net to which all operations shall be applied
const std::string myOrigValue
the original value
std::string redoName() const
get Redo name
the function-object for an editing operation (abstract base)
Definition GNEChange.h:56
void updateAttributeColors()
update attribute colors deprecated
GNEDataSet * retrieveDataSet(const std::string &id, bool hardFail=true) const
Returns the named data set.
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
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:120
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
bool isGenericData() const
return true if tag correspond to a generic data element
const GNEAttributeProperties & getAttributeProperties(SumoXMLAttr attr) const
get attribute (throw error if doesn't exist)
bool isNetworkElement() const
return true if tag correspond to a network element
bool isDataElement() const
return true if tag correspond to a data element
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
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)
bool hasAttribute(SumoXMLAttr attr) const
check if current TagProperties owns the attribute "attr"
Definition json.hpp:4471