Eclipse SUMO - Simulation of Urban MObility
GNEUndoList.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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 /****************************************************************************/
19 /****************************************************************************/
20 #pragma once
21 #include <config.h>
22 
23 #include <stack>
24 #include <string>
25 
27 
28 
29 // ===========================================================================
30 // class declarations
31 // ===========================================================================
32 class GNEChange;
35 
36 // ===========================================================================
37 // class definitions
38 // ===========================================================================
42 class GNEUndoList : public GNEChangeGroup {
44  FXDECLARE_ABSTRACT(GNEUndoList)
45 
46 public:
48  class Iterator {
49 
50  public:
53 
55  ~Iterator();
56 
58  bool end() const;
59 
61  int getIndex() const;
62 
64  const std::string getDescription() const;
65 
67  FXIcon* getIcon() const;
68 
70  Iterator& operator++(int);
71 
72  private:
75 
77  int myIndex;
78  };
79 
80 
83 
85  ~GNEUndoList();
86 
88  void undo();
89 
91  void redo();
92 
96  std::string undoName() const;
97 
101  std::string redoName() const;
102 
109  void begin(GUIIcon icon, const std::string& description);
110 
117  void begin(Supermode supermode, GUIIcon icon, const std::string& description);
118 
124  void end();
125 
134  void add(GNEChange* command, bool doit = false, bool merge = true);
135 
137  void changeAttribute(GNEChange_Attribute* change);
138 
139  /* @brief clears the undo list (implies abort)
140  * All undo and redo information will be destroyed.
141  */
142  void clear();
143 
145  void abortAllChangeGroups();
146 
148  void abortLastChangeGroup();
149 
151  int currentCommandGroupSize() const;
152 
154  Supermode getUndoSupermode() const;
155 
157  Supermode getRedoSupermode() const;
158 
160  bool hasCommandGroup() const;
161 
166  bool busy() const;
167 
171  long onCmdUndo(FXObject*, FXSelector, void*);
172 
174  long onUpdUndo(FXObject*, FXSelector, void*);
175 
177  long onCmdRedo(FXObject*, FXSelector, void*);
178 
180  long onUpdRedo(FXObject*, FXSelector, void*);
182 
183 protected:
187  void cut();
188 
193  void abortCurrentSubGroup();
194 
196  bool canUndo() const;
197 
199  bool canRedo() const;
200 
201 private:
203  bool myWorking;
204 
205  // @brief the stack of currently active change groups
206  std::stack<GNEChangeGroup*> myChangeGroups;
207 
208  // @brief the parent GNEApplicationWindow for this undolist
210 };
Supermode
@brie enum for supermodes
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
The main window of the Netedit.
the function-object for an editing operation (abstract base)
GNEChange * undoList
undo list command (can be access by GNEUndoList)
friend class GNEUndoList
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:64
FOX declaration.
Definition: GNEUndoList.h:48
const std::string getDescription() const
get description
Definition: GNEUndoList.cpp:79
bool end() const
check if iterator is at the end
Definition: GNEUndoList.cpp:67
FXIcon * getIcon() const
get icon
Definition: GNEUndoList.cpp:90
Iterator(const GNEUndoList *undoList)
constructor for GNEUndoList
Definition: GNEUndoList.cpp:57
Iterator & operator++(int)
increment operator
GNEChange * myCurrentChange
current change
Definition: GNEUndoList.h:74
int getIndex() const
get index
Definition: GNEUndoList.cpp:73
void abortCurrentSubGroup()
Abort the current command sub-group being compiled. All commands already added to the sub-groups undo...
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
bool hasCommandGroup() const
Check if undoList has command group.
void undo()
undo the last command group
long onUpdUndo(FXObject *, FXSelector, void *)
event after Undo
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...
std::string undoName() const
Return name of the first undo command available; if no undo command available this will return the em...
~GNEUndoList()
destructor
GNEApplicationWindow *const myGNEApplicationWindowParent
Definition: GNEUndoList.h:209
void abortAllChangeGroups()
reverts and discards ALL active chained change groups
Supermode getRedoSupermode() const
get redo supermode
long onUpdRedo(FXObject *, FXSelector, void *)
event after Redo
bool myWorking
Currently busy with undo or redo.
Definition: GNEUndoList.h:203
void cut()
Cut the redo list. This is automatically invoked when a new undo command is added.
bool canRedo() const
Can we redo more commands.
Supermode getUndoSupermode() const
get undo supermode
bool canUndo() const
Can we undo more commands.
std::stack< GNEChangeGroup * > myChangeGroups
Definition: GNEUndoList.h:206
void redo()
redo the last command group
long onCmdUndo(FXObject *, FXSelector, void *)
int currentCommandGroupSize() const
get size of current CommandGroup
void abortLastChangeGroup()
reverts last active chained change group
long onCmdRedo(FXObject *, FXSelector, void *)
redo change
bool busy() const
Return TRUE if currently inside undo or redo operation; this is useful to avoid generating another un...
std::string redoName() const
Return name of the first redo command available; if no Redo command available this will return the em...
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...
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute