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-2024 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#include <netedit/GNEViewNet.h>
26#include <netedit/GNEUndoList.h>
28
29#include "GNEChange_Attribute.h"
30
31// ===========================================================================
32// FOX-declarations
33// ===========================================================================
34FXIMPLEMENT_ABSTRACT(GNEChange_Attribute, GNEChange, nullptr, 0)
35
36// ===========================================================================
37// member method definitions
38// ===========================================================================
39
40void
41GNEChange_Attribute::changeAttribute(GNEAttributeCarrier* AC, SumoXMLAttr key, const std::string& value, GNEUndoList* undoList, const bool force) {
42 if (AC->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed()) {
43 // create change
44 auto change = new GNEChange_Attribute(AC, key, value);
45 // set force
46 change->myForceChange = force;
47 // check if process change
48 if (change->trueChange()) {
49 undoList->begin(AC, TLF("change '%' attribute in % '%' to '%'", toString(key), AC->getTagStr(), AC->getID(), value));
50 undoList->add(change, true);
51 undoList->end();
52 } else {
53 delete change;
54 }
55 } else {
56 AC->setAttribute(key, value);
57 }
58}
59
60
61void
62GNEChange_Attribute::changeAttribute(GNEAttributeCarrier* AC, SumoXMLAttr key, const std::string& value, const std::string& originalValue, GNEUndoList* undoList, const bool force) {
64 // create change
65 auto change = new GNEChange_Attribute(AC, key, value, originalValue);
66 // set force
67 change->myForceChange = force;
68 // check if process change
69 if (change->trueChange()) {
70 undoList->begin(AC, TLF("change '%' attribute in % '%' to '%'", toString(key), AC->getTagStr(), AC->getID(), value));
71 undoList->add(change, true);
72 undoList->end();
73 } else {
74 delete change;
75 }
76 } else {
77 AC->setAttribute(key, value);
78 }
79}
80
81
83 // only continue we have undo-redo mode enabled
85 // decrease reference
86 myAC->decRef("GNEChange_Attribute " + toString(myKey));
87 // remove if is unreferenced
88 if (myAC->unreferenced()) {
89 // show extra information for tests
90 WRITE_DEBUG("Deleting unreferenced " + myAC->getTagStr() + " in GNEChange_Attribute");
91 // delete AC
92 delete myAC;
93 }
94 }
95}
96
97
98void
100 // show extra information for tests
101 WRITE_DEBUG("Restoring previous attribute"/* + toString(myKey)*/);
102 // set original value
104 // certain attributes needs extra operations
105 if (myKey != GNE_ATTR_SELECTED) {
106 // check if updated attribute requires a update geometry
109 }
110 // if is a dataelement, update attribute colors
113 } else if (myAC->getTagProperty().getTag() == SUMO_TAG_DATASET) {
115 }
116 // check if networkElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
119 } else if (myAC->getTagProperty().isAdditionalElement()) {
121 } else if (myAC->getTagProperty().isDemandElement()) {
123 } else if (myAC->getTagProperty().isDataElement()) {
125 } else if (myAC->getTagProperty().isMeanData()) {
127 }
128 }
129}
130
131
132void
134 // show extra information for tests
135 WRITE_DEBUG("Setting new attribute"/* + toString(myKey)*/);
136 // set new value
138 // certain attributes needs extra operations
139 if (myKey != GNE_ATTR_SELECTED) {
140 // check if updated attribute requires a update geometry
143 }
144 // if is a dataelement, update attribute colors
147 } else if (myAC->getTagProperty().getTag() == SUMO_TAG_DATASET) {
149 }
150 // check if networkElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
153 } else if (myAC->getTagProperty().isAdditionalElement()) {
155 } else if (myAC->getTagProperty().isDemandElement()) {
157 } else if (myAC->getTagProperty().isDataElement()) {
159 } else if (myAC->getTagProperty().isMeanData()) {
161 }
162 }
163}
164
165
166std::string
168 return (TL("Undo change ") + myAC->getTagStr() + " attribute");
169}
170
171
172std::string
174 return (TL("Redo change ") + myAC->getTagStr() + " attribute");
175}
176
177
179 GNEChange(ac->getTagProperty().getSupermode(), true, false),
180 myAC(ac),
181 myKey(key),
182 myForceChange(false),
183 myOrigValue(ac->getAttribute(key)),
184 myNewValue(value) {
185 myAC->incRef("GNEChange_Attribute " + toString(myKey));
186}
187
188
189GNEChange_Attribute::GNEChange_Attribute(GNEAttributeCarrier* ac, SumoXMLAttr key, const std::string& value, const std::string& origValue) :
190 GNEChange(ac->getTagProperty().getSupermode(), true, false),
191 myAC(ac),
192 myKey(key),
193 myForceChange(false),
194 myOrigValue(origValue),
195 myNewValue(value) {
196 myAC->incRef("GNEChange_Attribute " + toString(myKey));
197}
198
199
200bool
202 // check if we're editing the value of an attribute or changing a disjoint attribute
203 if (myForceChange) {
204 return true;
205 } else {
206 return (myOrigValue != myNewValue);
207 }
208}
209
210/****************************************************************************/
#define WRITE_DEBUG(msg)
Definition MsgHandler.h:306
#define TL(string)
Definition MsgHandler.h:315
#define TLF(string,...)
Definition MsgHandler.h:317
@ 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 getID() const
get ID (all Attribute Carriers have one)
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)
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
get undo Name
const std::string myNewValue
the new value
GNEChange_Attribute(GNEAttributeCarrier *ac, const SumoXMLAttr key, const std::string &value)
constructor
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
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:133
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:127
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2163
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
data elements
const GNEAttributeProperties & getAttributeProperties(SumoXMLAttr attr) const
get attribute propety associated with the given Sumo XML Attribute (throw error if doesn't exist)
bool isNetworkElement() const
element sets
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"
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
void add(GNEChange *command, bool doit=false, bool merge=true)
Add new command, executing it if desired. The new command will be merged with the previous command if...
GNEViewParent * getViewParent() const
get the net object
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows
Definition json.hpp:4471