Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/GNEUndoList.h
169667 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 GNEUndoList.h
15
/// @author Jakob Erdmann
16
/// @author Pablo Alvarez Lopez
17
/// @date Mar 2011
18
///
19
/****************************************************************************/
20
#pragma once
21
#include <config.h>
22
23
#include <stack>
24
#include <string>
25
26
#include <netedit/changes/GNEChangeGroup.h>
27
28
29
// ===========================================================================
30
// class declarations
31
// ===========================================================================
32
class GNEChange;
33
class GNEChange_Attribute;
34
class GNEApplicationWindow;
35
36
// ===========================================================================
37
// class definitions
38
// ===========================================================================
39
/**
40
* @class GNEUndoList
41
*/
42
class GNEUndoList : public GNEChangeGroup {
43
/// @brief FOX declaration
44
FXDECLARE_ABSTRACT(GNEUndoList)
45
46
public:
47
/// @brief iterator
48
class Iterator {
49
50
public:
51
/// @brief destructor
52
~Iterator();
53
54
/// @brief check if iterator is at the end
55
bool end() const;
56
57
/// @brief get index
58
int getIndex() const;
59
60
/// @brief get description
61
const std::string getDescription() const;
62
63
/// @brief get timeStamp
64
const std::string getTimeStamp() const;
65
66
/// @brief get icon
67
FXIcon* getIcon() const;
68
69
/// @brief increment operator
70
Iterator& operator++(int);
71
72
protected:
73
/// @brief constructor for GNEUndoList
74
Iterator(GNEChange* change);
75
76
private:
77
/// @brief default constructor
78
Iterator();
79
80
/// @brief current change
81
GNEChange* myCurrentChange;
82
83
/// @brief counter
84
int myIndex;
85
};
86
87
/// @brief undo iterator
88
class UndoIterator : public Iterator {
89
90
public:
91
/// @brief constructor for GNEUndoList
92
UndoIterator(const GNEUndoList* undoList);
93
};
94
95
/// @brief redo iterator
96
class RedoIterator : public Iterator {
97
98
public:
99
/// @brief constructor for GNEUndoList
100
RedoIterator(const GNEUndoList* undoList);
101
};
102
103
/// @brief constructor
104
GNEUndoList(GNEApplicationWindow* parent);
105
106
/// @brief destructor
107
~GNEUndoList();
108
109
/// @brief undo the last command group
110
void undo();
111
112
/// @brief redo the last command group
113
void redo();
114
115
/**@brief Return name of the first undo command available; if no
116
* undo command available this will return the empty string.
117
*/
118
std::string undoName() const;
119
120
/**@brief Return name of the first redo command available; if no
121
* Redo command available this will return the empty string.
122
*/
123
std::string redoName() const;
124
125
/**@brief Begin undo command sub-group with current supermode.
126
* This begins a new group of commands that
127
* are treated as a single command. Must eventually be followed by a
128
* matching end() after recording the sub-commands. The new sub-group
129
* will be appended to its parent group's undo list when end() is called.
130
*/
131
void begin(GUIIcon icon, const std::string& description);
132
133
/**@brief Begin undo command sub-group with current supermode. (used for ACs
134
* This begins a new group of commands that
135
* are treated as a single command. Must eventually be followed by a
136
* matching end() after recording the sub-commands. The new sub-group
137
* will be appended to its parent group's undo list when end() is called.
138
*/
139
void begin(const GNEAttributeCarrier* AC, const std::string& description);
140
141
/**@brief Begin undo command sub-group specifying supermode.
142
* This begins a new group of commands that
143
* are treated as a single command. Must eventually be followed by a
144
* matching end() after recording the sub-commands. The new sub-group
145
* will be appended to its parent group's undo list when end() is called.
146
*/
147
void begin(Supermode supermode, GUIIcon icon, const std::string& description);
148
149
/**@brief End undo command sub-group. If the sub-group is still empty, it will
150
* be deleted; otherwise, the sub-group will be added as a new command
151
* into parent group.
152
* @note A matching begin() must have been called previously.
153
*/
154
void end();
155
156
/**@brief Add new command, executing it if desired. The new command will be merged
157
* with the previous command if merge is TRUE and we're not at a marked position
158
* and the commands are mergeable. Otherwise the new command will be appended
159
* after the last undo command in the currently active undo group.
160
* If the new command is successfully merged, it will be deleted. Furthermore,
161
* all redo commands will be deleted since it is no longer possible to redo
162
* from this point.
163
*/
164
void add(GNEChange* command, bool doit = false, bool merge = true);
165
166
/* @brief clears the undo list (implies abort)
167
* All undo and redo information will be destroyed.
168
*/
169
void clear();
170
171
/// @brief reverts and discards ALL active chained change groups
172
void abortAllChangeGroups();
173
174
/// @brief reverts last active chained change group
175
void abortLastChangeGroup();
176
177
/// @brief get size of current CommandGroup
178
int currentCommandGroupSize() const;
179
180
/// @brief get undo supermode
181
Supermode getUndoSupermode() const;
182
183
/// @brief get redo supermode
184
Supermode getRedoSupermode() const;
185
186
/// @brief Check if undoList has command group
187
bool hasCommandGroup() const;
188
189
/**@brief Return TRUE if currently inside undo or redo operation; this
190
* is useful to avoid generating another undo command while inside
191
* an undo operation.
192
*/
193
bool busy() const;
194
195
/// @name FOX-callbacks
196
/// @{
197
/// @brief undo change
198
long onCmdUndo(FXObject*, FXSelector, void*);
199
200
/// @brief event after Undo
201
long onUpdUndo(FXObject*, FXSelector, void*);
202
203
/// @brief redo change
204
long onCmdRedo(FXObject*, FXSelector, void*);
205
206
/// @brief event after Redo
207
long onUpdRedo(FXObject*, FXSelector, void*);
208
/// @}
209
210
protected:
211
/**@brief Cut the redo list.
212
* This is automatically invoked when a new undo command is added.
213
*/
214
void cut();
215
216
/** @brief Abort the current command sub-group being compiled. All commands
217
* already added to the sub-groups undo list will be discarded.
218
* Intermediate command groups will be left intact.
219
*/
220
void abortCurrentSubGroup();
221
222
///@brief Can we undo more commands
223
bool canUndo() const;
224
225
///@brief Can we redo more commands
226
bool canRedo() const;
227
228
private:
229
/// @brief Currently busy with undo or redo
230
bool myWorking;
231
232
// @brief the stack of currently active change groups
233
std::stack<GNEChangeGroup*> myChangeGroups;
234
235
// @brief the parent GNEApplicationWindow for this undolist
236
GNEApplicationWindow* const myGNEApplicationWindowParent;
237
};
238
239