MeVisLab Toolbox Reference
CSOUndoRedoManager.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 
15 
16 #pragma once
17 
18 #include "CSOUndoRedoCommands.h"
19 
20 #include <mlUndoContext.h>
21 
22 ML_START_NAMESPACE
23 
24 
26 
30 {
31 
32 public:
33 
35  enum UNDO_MODE
36  {
37  MODE_UNDOING = 0,
38  MODE_REDOING = 1,
39  MODE_NORMAL = 2
40  };
41 
42 
45 
48 
52  void addCommand(CSOCommand* command);
56 
58  void undo();
60  void redo();
61 
63  void openGroup(const std::string& description = "Contour Operation");
65  void closeGroup();
68 
70  void clearUndo();
72  void clearRedo();
74  void clearAll();
75 
81  int getCurrentUndoGroupDepth() { return _currentGroupDepth; }
82 
84  bool canUndo() const;
86  bool canRedo() const;
87 
89  int maxNumUndos() const;
91  void setMaxNumUndos(int newMaxNumUndos);
92  void setMaxNumUndos(MLint newMaxNumUndos) { setMaxNumUndos(static_cast<int>(newMaxNumUndos)); }
93 
95  int numUndos() const;
97  int numRedos() const;
98 
100  bool isInUndoMode() const;
102  bool isInRedoMode() const;
103 
109 
111  inline bool isEnabled() { return _isEnabled; }
112 
114  void setUndoContext(ml::UndoContextPtr undoContext);
115 
116 private:
117  static void _undoContextCB(void* userData, BaseEvent* event);
118 
120  int _currentGroupDepth;
121 
123  bool _isEnabled;
124 
126  ml::UndoContextPtr _undoContext;
127 
129  ml::UndoContextPtr _defaultUndoContext;
130 
132  CSOList* _csoList;
133 };
134 
136 
137 ML_END_NAMESPACE
#define MLCSO_EXPORT
Defines export symbols for classes, so they can be used in other DLLs.
Definition: MLCSOSystem.h:23
BaseEvent is the base class for all events emitted from EventSourceBase.
Definition: mlEventSource.h:86
Base class for a CSOCommand for the undo/redo mechanism.
A CSOList comprises a number of CSOs and CSOGroups and is the central object for contour segmentation...
Definition: CSOList.h:61
Manager class for maintaining the undo and the redo stacks.
bool isInRedoMode() const
Returns whether the manager is in redo-mode.
void disableUndoRedo()
Disables this undo/redo manager; if it is disabled, the incoming commands are deleted and not added.
bool canRedo() const
Returns whether there are possible redoes.
void openGroup(const std::string &description="Contour Operation")
Opens a group of commands that are undone/redone as one.
UNDO_MODE
The undo (and redo) modes.
int numUndos() const
Returns the number of stored undo steps.
CSOUndoRedoManager(CSOList *csoList)
Constructor.
void popUndoCommand()
Removes the last added undo command without executing it.
void clearAll()
Clears the undo and redo stack.
void enableUndoRedo()
Enables this undo/redo manager.
void closeGroup()
Closes a group of commands that are undone/redone as one.
bool isEnabled()
Returns whether this undo/redo manager is currently enabled.
void closeAllGroups()
Closes all undo/redo groups.
void undo()
Performs an undo of the last modification (if undo stack is not empty).
int maxNumUndos() const
Returns the maximum number of possible undos. If a -1 is returned, the undo stack has no limitation.
void redo()
Performs a redo (if the undo stack is not empty).
int getCurrentUndoGroupDepth()
Returns the current undo group depth.
bool isInUndoMode() const
Returns whether the manager is in undo-mode.
void setUndoContext(ml::UndoContextPtr undoContext)
Set a new undo context.
void setMaxNumUndos(MLint newMaxNumUndos)
void setMaxNumUndos(int newMaxNumUndos)
Sets the maximum number of possible undos. If a -1 is passed, the undo stack has no limitation.
~CSOUndoRedoManager()
Destructor.
int numRedos() const
Returns the number of stored redo steps.
bool canUndo() const
Returns whether there are possible undoes.
void addCommand(CSOCommand *command)
Adds a command (modification).
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition: mlTypeDefs.h:578