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-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// ===========================================================================
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()->getViewNet()->getViewParent()->getGNEAppWindows()->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
85 if (myAC->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed()) {
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
100 myAC->setAttribute(myKey, myOrigValue);
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()) {
105 myAC->updateGeometry();
106 }
107 // if is a dataelement, update attribute colors
108 if (myAC->getTagProperty()->isGenericData()) {
109 myAC->getNet()->getAttributeCarriers()->retrieveDataSet(myAC->getAttribute(GNE_ATTR_DATASET))->updateAttributeColors();
110 } else if (myAC->getTagProperty()->getTag() == SUMO_TAG_DATASET) {
111 myAC->getNet()->getAttributeCarriers()->retrieveDataSet(myAC->getAttribute(SUMO_ATTR_ID))->updateAttributeColors();
112 }
113 // check if networkElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
114 if (myAC->getTagProperty()->isNetworkElement()) {
115 myAC->getNet()->getSavingStatus()->requireSaveNetwork();
116 } else if (myAC->getTagProperty()->isAdditionalElement()) {
117 myAC->getNet()->getSavingStatus()->requireSaveAdditionals();
118 } else if (myAC->getTagProperty()->isDemandElement()) {
119 myAC->getNet()->getSavingStatus()->requireSaveDemandElements();
120 } else if (myAC->getTagProperty()->isDataElement()) {
121 myAC->getNet()->getSavingStatus()->requireSaveDataElements();
122 } else if (myAC->getTagProperty()->isMeanData()) {
123 myAC->getNet()->getSavingStatus()->requireSaveMeanDatas();
124 }
125 }
126}
127
128
129void
131 // set new value
132 myAC->setAttribute(myKey, myNewValue);
133 // certain attributes needs extra operations
134 if (myKey != GNE_ATTR_SELECTED) {
135 // check if updated attribute requires a update geometry
136 if (myAC->getTagProperty()->hasAttribute(myKey) && myAC->getTagProperty()->getAttributeProperties(myKey)->requireUpdateGeometry()) {
137 myAC->updateGeometry();
138 }
139 // if is a dataelement, update attribute colors
140 if (myAC->getTagProperty()->isGenericData()) {
141 myAC->getNet()->getAttributeCarriers()->retrieveDataSet(myAC->getAttribute(GNE_ATTR_DATASET))->updateAttributeColors();
142 } else if (myAC->getTagProperty()->getTag() == SUMO_TAG_DATASET) {
143 myAC->getNet()->getAttributeCarriers()->retrieveDataSet(myAC->getAttribute(SUMO_ATTR_ID))->updateAttributeColors();
144 }
145 // check if networkElements, additional or shapes has to be saved (only if key isn't GNE_ATTR_SELECTED)
146 if (myAC->getTagProperty()->isNetworkElement()) {
147 myAC->getNet()->getSavingStatus()->requireSaveNetwork();
148 } else if (myAC->getTagProperty()->isAdditionalElement()) {
149 myAC->getNet()->getSavingStatus()->requireSaveAdditionals();
150 } else if (myAC->getTagProperty()->isDemandElement()) {
151 myAC->getNet()->getSavingStatus()->requireSaveDemandElements();
152 } else if (myAC->getTagProperty()->isDataElement()) {
153 myAC->getNet()->getSavingStatus()->requireSaveDataElements();
154 } else if (myAC->getTagProperty()->isMeanData()) {
155 myAC->getNet()->getSavingStatus()->requireSaveMeanDatas();
156 }
157 }
158}
159
160
161std::string
163 return (TL("Undo change ") + myAC->getTagStr() + " attribute");
164}
165
166
167std::string
169 return (TL("Redo change ") + myAC->getTagStr() + " attribute");
170}
171
172
174 GNEChange(ac->getTagProperty()->getSupermode(), true, false),
175 myAC(ac),
176 myKey(key),
177 myForceChange(false),
178 myOrigValue(ac->getAttribute(key)),
180 myAC->incRef("GNEChange_Attribute " + toString(myKey));
181}
182
183
184GNEChange_Attribute::GNEChange_Attribute(GNEAttributeCarrier* ac, SumoXMLAttr key, const std::string& value, const std::string& origValue) :
185 GNEChange(ac->getTagProperty()->getSupermode(), true, false),
186 myAC(ac),
187 myKey(key),
188 myForceChange(false),
189 myOrigValue(origValue),
191 myAC->incRef("GNEChange_Attribute " + toString(myKey));
192}
193
194
195bool
197 // check if we're editing the value of an attribute or changing a disjoint attribute
198 if (myForceChange) {
199 return true;
200 } else {
201 return (myOrigValue != myNewValue);
202 }
203}
204
205/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:304
#define TLF(string,...)
Definition MsgHandler.h:306
const std::string invalid_return< std::string >::value
@ 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 override
get ID (all Attribute Carriers have one)
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * getNet() const
get pointer to net
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=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
Supermode getSupermode() const
get supermode
Definition GNEChange.cpp:66
GNEChange(Supermode supermode, bool forward, const bool selectedElement)
Constructor.
Definition GNEChange.cpp:34
friend class GNEUndoList
Definition GNEChange.h:62
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
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