Eclipse SUMO - Simulation of Urban MObility
GNEChange_Attribute.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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 // ===========================================================================
30 FXIMPLEMENT_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 
47 GNEChange_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() + " '" + myAC->getID() + "' in GNEChange_Attribute");
65  // delete AC
66  delete myAC;
67  }
68 }
69 
70 
71 void
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
87  } else {
89  }
90  }
91  // check if networkElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
93  myAC->getNet()->requireSaveNet(true);
96  } else if (myAC->getTagProperty().isDemandElement()) {
98  } else if (myAC->getTagProperty().isDemandElement()) {
100  }
101  }
102 }
103 
104 
105 void
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
115  myAC->updateGeometry();
116  }
117  // if is a dataelement, update attribute colors
118  if (myAC->getTagProperty().isDataElement()) {
119  if (myAC->getTagProperty().isGenericData()) {
121  } else {
123  }
124  }
125  // check if networkElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
127  myAC->getNet()->requireSaveNet(true);
130  } else if (myAC->getTagProperty().isDemandElement()) {
132  } else if (myAC->getTagProperty().isDemandElement()) {
134  }
135  }
136 }
137 
138 
139 void
141  myForceChange = true;
142 }
143 
144 
145 bool
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 
156 std::string
158  return ("Undo change " + myAC->getTagStr() + " attribute");
159 }
160 
161 
162 std::string
164  return ("Redo change " + myAC->getTagStr() + " attribute");
165 }
166 
167 /****************************************************************************/
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:290
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
virtual const std::string & getID() const =0
return ID of object
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 atribute 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
void undo()
undo action
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
~GNEChange_Attribute()
Destructor.
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:64
void updateAttributeColors()
update attribute colors deprecated
Definition: GNEDataSet.cpp:143
GNEDataSet * retrieveDataSet(const std::string &id, bool hardFail=true) const
Returns the named data set.
void requireSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:1144
void requireSaveAdditionals(bool value)
inform that additionals has to be saved
Definition: GNENet.cpp:1994
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:125
void requireSaveDemandElements(bool value)
inform that demand elements has to be saved
Definition: GNENet.cpp:2058
void requireSaveDataElements(bool value)
inform that data sets has to be saved
Definition: GNENet.cpp:2123
void decRef(const std::string &debugMsg="")
Decrease reference.
void incRef(const std::string &debugMsg="")
Increarse reference.
bool unreferenced()
check if object ins't referenced
bool isShape() const
return true if tag correspond to a shape
bool isTAZElement() const
return true if tag correspond to a TAZ 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
bool isDemandElement() const
return true if tag correspond to a demand element
bool isAdditionalElement() const
return true if tag correspond to an additional element
bool hasAttribute(SumoXMLAttr attr) const
check if current TagProperties owns the attribute "attr"