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-2026 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// ===========================================================================
34
35FXIMPLEMENT_ABSTRACT(GNEChange_Attribute, GNEChange, nullptr, 0)
36
37// ===========================================================================
38// member method definitions
39// ===========================================================================
40
41void
42GNEChange_Attribute::changeAttribute(GNEAttributeCarrier* AC, SumoXMLAttr key, const std::string& value, GNEUndoList* undoList, const bool force) {
43 if (AC->getNet()->getGNEApplicationWindow()->isUndoRedoAllowed()) {
44 // create change
45 auto change = new GNEChange_Attribute(AC, key, value);
46 // set force
47 change->myForceChange = force;
48 // check if process change
49 if (change->trueChange()) {
50 undoList->begin(AC, TLF("change '%' attribute in % '%' to '%'", toString(key), AC->getTagStr(), AC->getID(), value));
51 undoList->add(change, true);
52 undoList->end();
53 } else {
54 delete change;
55 }
56 } else {
57 AC->setAttribute(key, value);
58 }
59}
60
61
62void
63GNEChange_Attribute::changeAttribute(GNEAttributeCarrier* AC, SumoXMLAttr key, const std::string& value, const std::string& originalValue, GNEUndoList* undoList, const bool force) {
65 // create change
66 auto change = new GNEChange_Attribute(AC, key, value, originalValue);
67 // set force
68 change->myForceChange = force;
69 // check if process change
70 if (change->trueChange()) {
71 undoList->begin(AC, TLF("change '%' attribute in % '%' to '%'", toString(key), AC->getTagStr(), AC->getID(), value));
72 undoList->add(change, true);
73 undoList->end();
74 } else {
75 delete change;
76 }
77 } else {
78 AC->setAttribute(key, value);
79 }
80}
81
82
84 // only continue we have undo-redo mode enabled
86 // decrease reference
87 myAC->decRef("GNEChange_Attribute " + toString(myKey));
88 // remove if is unreferenced
89 if (myAC->unreferenced()) {
90 // delete AC
91 delete myAC;
92 }
93 }
94}
95
96
97void
99 // set original value
101 // certain attributes needs extra operations
102 if (myKey != GNE_ATTR_SELECTED) {
103 // check if updated attribute requires a update geometry
104 if (myAC->getTagProperty()->hasAttribute(myKey) && myAC->getTagProperty()->getAttributeProperties(myKey)->requireUpdateGeometry()) {
106 }
107 // if is a dataelement, update attribute colors
110 } else if (myAC->getTagProperty()->getTag() == SUMO_TAG_DATASET) {
112 }
113 // check if networkElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
116 // any attribute change could impact junction logic and thus requires recompute
118 } else if (myAC->getTagProperty()->isAdditionalElement()) {
120 } else if (myAC->getTagProperty()->isDemandElement()) {
122 } else if (myAC->getTagProperty()->isDataElement()) {
124 } else if (myAC->getTagProperty()->isMeanData()) {
126 }
127 }
128}
129
130
131void
133 // set new value
135 // certain attributes needs extra operations
136 if (myKey != GNE_ATTR_SELECTED) {
137 // check if updated attribute requires a update geometry
138 if (myAC->getTagProperty()->hasAttribute(myKey) && myAC->getTagProperty()->getAttributeProperties(myKey)->requireUpdateGeometry()) {
140 }
141 // if is a dataelement, update attribute colors
144 } else if (myAC->getTagProperty()->getTag() == SUMO_TAG_DATASET) {
146 }
147 // check if networkElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
150 // any attribute change could impact junction logic and thus requires recompute
152 } else if (myAC->getTagProperty()->isAdditionalElement()) {
154 } else if (myAC->getTagProperty()->isDemandElement()) {
156 } else if (myAC->getTagProperty()->isDataElement()) {
158 } else if (myAC->getTagProperty()->isMeanData()) {
160 }
161 }
162}
163
164
165std::string
167 return (TL("Undo change ") + myAC->getTagStr() + " attribute");
168}
169
170
171std::string
173 return (TL("Redo change ") + myAC->getTagStr() + " attribute");
174}
175
176
178 GNEChange(ac->getTagProperty()->getSupermode(), true, false),
179 myAC(ac),
180 myKey(key),
181 myForceChange(false),
182 myOrigValue(ac->getAttribute(key)),
183 myNewValue(value) {
184 myAC->incRef("GNEChange_Attribute " + toString(myKey));
185}
186
187
188GNEChange_Attribute::GNEChange_Attribute(GNEAttributeCarrier* ac, SumoXMLAttr key, const std::string& value, const std::string& origValue) :
189 GNEChange(ac->getTagProperty()->getSupermode(), true, false),
190 myAC(ac),
191 myKey(key),
192 myForceChange(false),
193 myOrigValue(origValue),
194 myNewValue(value) {
195 myAC->incRef("GNEChange_Attribute " + toString(myKey));
196}
197
198
199bool
201 // check if we're editing the value of an attribute or changing a disjoint attribute
202 if (myForceChange) {
203 return true;
204 } else {
205 return (myOrigValue != myNewValue);
206 }
207}
208
209/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:304
#define TLF(string,...)
Definition MsgHandler.h:306
@ 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:49
const std::string getID() const override
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:186
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:174
GNEApplicationWindow * getGNEApplicationWindow() const
get tag properties database
Definition GNENet.cpp:138
void requireRecompute()
inform the net about the need for recomputation
Definition GNENet.cpp:1619
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...
Definition json.hpp:4471