Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/changes/GNEChange_Attribute.cpp
169678 views
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
/****************************************************************************/
14
/// @file GNEChange_Attribute.cpp
15
/// @author Jakob Erdmann
16
/// @date Mar 2011
17
///
18
// A network change in which something is changed (for undo/redo)
19
/****************************************************************************/
20
21
#include <netedit/GNENet.h>
22
#include <netedit/GNETagProperties.h>
23
#include <netedit/GNEViewNet.h>
24
#include <netedit/GNEViewParent.h>
25
#include <netedit/GNEApplicationWindow.h>
26
#include <netedit/GNEUndoList.h>
27
#include <netedit/elements/data/GNEDataSet.h>
28
29
#include "GNEChange_Attribute.h"
30
31
// ===========================================================================
32
// FOX-declarations
33
// ===========================================================================
34
35
FXIMPLEMENT_ABSTRACT(GNEChange_Attribute, GNEChange, nullptr, 0)
36
37
// ===========================================================================
38
// member method definitions
39
// ===========================================================================
40
41
void
42
GNEChange_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
62
void
63
GNEChange_Attribute::changeAttribute(GNEAttributeCarrier* AC, SumoXMLAttr key, const std::string& value, const std::string& originalValue, GNEUndoList* undoList, const bool force) {
64
if (AC->getNet()->getViewNet()->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed()) {
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
83
GNEChange_Attribute::~GNEChange_Attribute() {
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
97
void
98
GNEChange_Attribute::undo() {
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
129
void
130
GNEChange_Attribute::redo() {
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
161
std::string
162
GNEChange_Attribute::undoName() const {
163
return (TL("Undo change ") + myAC->getTagStr() + " attribute");
164
}
165
166
167
std::string
168
GNEChange_Attribute::redoName() const {
169
return (TL("Redo change ") + myAC->getTagStr() + " attribute");
170
}
171
172
173
GNEChange_Attribute::GNEChange_Attribute(GNEAttributeCarrier* ac, SumoXMLAttr key, const std::string& value) :
174
GNEChange(ac->getTagProperty()->getSupermode(), true, false),
175
myAC(ac),
176
myKey(key),
177
myForceChange(false),
178
myOrigValue(ac->getAttribute(key)),
179
myNewValue(value) {
180
myAC->incRef("GNEChange_Attribute " + toString(myKey));
181
}
182
183
184
GNEChange_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),
190
myNewValue(value) {
191
myAC->incRef("GNEChange_Attribute " + toString(myKey));
192
}
193
194
195
bool
196
GNEChange_Attribute::trueChange() {
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
/****************************************************************************/
206
207