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 // create change
43 auto change = new GNEChange_Attribute(AC, key, value);
44 // set force
45 change->myForceChange = force;
46 // check if process change
47 if (change->trueChange()) {
48 undoList->begin(AC, TLF("change '%' attribute in % '%' to '%'", toString(key), AC->getTagStr(), AC->getID(), value));
49 undoList->add(change, true);
50 undoList->end();
51 } else {
52 delete change;
53 }
54}
55
56
57void
58GNEChange_Attribute::changeAttribute(GNEAttributeCarrier* AC, SumoXMLAttr key, const std::string& value, const std::string& originalValue, GNEUndoList* undoList, const bool force) {
59 // create change
60 auto change = new GNEChange_Attribute(AC, key, value, originalValue);
61 // set force
62 change->myForceChange = force;
63 // check if process change
64 if (change->trueChange()) {
65 undoList->begin(AC, TLF("change '%' attribute in % '%' to '%'", toString(key), AC->getTagStr(), AC->getID(), value));
66 undoList->add(change, true);
67 undoList->end();
68 } else {
69 delete change;
70 }
71}
72
73
75 // only continue we have undo-redo mode enabled
77 // decrease reference
78 myAC->decRef("GNEChange_Attribute " + toString(myKey));
79 // remove if is unreferenced
80 if (myAC->unreferenced()) {
81 // show extra information for tests
82 WRITE_DEBUG("Deleting unreferenced " + myAC->getTagStr() + " in GNEChange_Attribute");
83 // delete AC
84 delete myAC;
85 }
86 }
87}
88
89
90void
92 // show extra information for tests
93 WRITE_DEBUG("Restoring previous attribute"/* + toString(myKey)*/);
94 // set original value
96 // certain attributes needs extra operations
97 if (myKey != GNE_ATTR_SELECTED) {
98 // check if updated attribute requires a update geometry
101 }
102 // if is a dataelement, update attribute colors
105 } else if (myAC->getTagProperty().getTag() == SUMO_TAG_DATASET) {
107 }
108 // check if networkElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
111 } else if (myAC->getTagProperty().isAdditionalElement()) {
113 } else if (myAC->getTagProperty().isDemandElement()) {
115 } else if (myAC->getTagProperty().isDataElement()) {
117 } else if (myAC->getTagProperty().isMeanData()) {
119 }
120 }
121}
122
123
124void
126 // show extra information for tests
127 WRITE_DEBUG("Setting new attribute"/* + toString(myKey)*/);
128 // set new value
130 // certain attributes needs extra operations
131 if (myKey != GNE_ATTR_SELECTED) {
132 // check if updated attribute requires a update geometry
135 }
136 // if is a dataelement, update attribute colors
139 } else if (myAC->getTagProperty().getTag() == SUMO_TAG_DATASET) {
141 }
142 // check if networkElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
145 } else if (myAC->getTagProperty().isAdditionalElement()) {
147 } else if (myAC->getTagProperty().isDemandElement()) {
149 } else if (myAC->getTagProperty().isDataElement()) {
151 } else if (myAC->getTagProperty().isMeanData()) {
153 }
154 }
155}
156
157
158std::string
160 return (TL("Undo change ") + myAC->getTagStr() + " attribute");
161}
162
163
164std::string
166 return (TL("Redo change ") + myAC->getTagStr() + " attribute");
167}
168
169
171 GNEChange(ac->getTagProperty().getSupermode(), true, false),
172 myAC(ac),
173 myKey(key),
174 myForceChange(false),
175 myOrigValue(ac->getAttribute(key)),
176 myNewValue(value) {
177 myAC->incRef("GNEChange_Attribute " + toString(myKey));
178}
179
180
181GNEChange_Attribute::GNEChange_Attribute(GNEAttributeCarrier* ac, SumoXMLAttr key, const std::string& value, const std::string& origValue) :
182 GNEChange(ac->getTagProperty().getSupermode(), true, false),
183 myAC(ac),
184 myKey(key),
185 myForceChange(false),
186 myOrigValue(origValue),
187 myNewValue(value) {
188 myAC->incRef("GNEChange_Attribute " + toString(myKey));
189}
190
191
192bool
194 // check if we're editing the value of an attribute or changing a disjoint attribute
195 if (myForceChange) {
196 return true;
197 } else {
198 return (myOrigValue != myNewValue);
199 }
200}
201
202/****************************************************************************/
#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:131
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:125
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2147
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 (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