Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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-2025 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
21#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 // delete AC
90 delete myAC;
91 }
92 }
93}
94
95
96void
98 // set original value
100 // certain attributes needs extra operations
101 if (myKey != GNE_ATTR_SELECTED) {
102 // check if updated attribute requires a update geometry
103 if (myAC->getTagProperty()->hasAttribute(myKey) && myAC->getTagProperty()->getAttributeProperties(myKey)->requireUpdateGeometry()) {
105 }
106 // if is a dataelement, update attribute colors
109 } else if (myAC->getTagProperty()->getTag() == SUMO_TAG_DATASET) {
111 }
112 // check if networkElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
115 } else if (myAC->getTagProperty()->isAdditionalElement()) {
117 } else if (myAC->getTagProperty()->isDemandElement()) {
119 } else if (myAC->getTagProperty()->isDataElement()) {
121 } else if (myAC->getTagProperty()->isMeanData()) {
123 }
124 }
125}
126
127
128void
130 // set new value
132 // certain attributes needs extra operations
133 if (myKey != GNE_ATTR_SELECTED) {
134 // check if updated attribute requires a update geometry
135 if (myAC->getTagProperty()->hasAttribute(myKey) && myAC->getTagProperty()->getAttributeProperties(myKey)->requireUpdateGeometry()) {
137 }
138 // if is a dataelement, update attribute colors
141 } else if (myAC->getTagProperty()->getTag() == SUMO_TAG_DATASET) {
143 }
144 // check if networkElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
147 } else if (myAC->getTagProperty()->isAdditionalElement()) {
149 } else if (myAC->getTagProperty()->isDemandElement()) {
151 } else if (myAC->getTagProperty()->isDataElement()) {
153 } else if (myAC->getTagProperty()->isMeanData()) {
155 }
156 }
157}
158
159
160std::string
162 return (TL("Undo change ") + myAC->getTagStr() + " attribute");
163}
164
165
166std::string
168 return (TL("Redo change ") + myAC->getTagStr() + " attribute");
169}
170
171
173 GNEChange(ac->getTagProperty()->getSupermode(), true, false),
174 myAC(ac),
175 myKey(key),
176 myForceChange(false),
177 myOrigValue(ac->getAttribute(key)),
178 myNewValue(value) {
179 myAC->incRef("GNEChange_Attribute " + toString(myKey));
180}
181
182
183GNEChange_Attribute::GNEChange_Attribute(GNEAttributeCarrier* ac, SumoXMLAttr key, const std::string& value, const std::string& origValue) :
184 GNEChange(ac->getTagProperty()->getSupermode(), true, false),
185 myAC(ac),
186 myKey(key),
187 myForceChange(false),
188 myOrigValue(origValue),
189 myNewValue(value) {
190 myAC->incRef("GNEChange_Attribute " + toString(myKey));
191}
192
193
194bool
196 // check if we're editing the value of an attribute or changing a disjoint attribute
197 if (myForceChange) {
198 return true;
199 } else {
200 return (myOrigValue != myNewValue);
201 }
202}
203
204/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:301
#define TLF(string,...)
Definition MsgHandler.h:303
@ 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
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:164
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:146
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2194
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
bool isNetworkElement() const
network elements
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
const std::vector< const GNEAttributeProperties * > & getAttributeProperties() const
get all attribute properties
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