Medical Imaging Interaction Toolkit  2025.08.99-f7084adb
Medical Imaging Interaction Toolkit
mitkLimitedLinearUndo.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkLimitedLinearUndo_h
14 #define mitkLimitedLinearUndo_h
15 
16 // MITK header
17 #include "mitkOperationEvent.h"
18 #include "mitkUndoModel.h"
19 #include <MitkCoreExports.h>
20 // STL header
21 #include <vector>
22 // ITK header
23 #pragma GCC visibility push(default)
24 #include <itkEventObject.h>
25 #pragma GCC visibility pop
26 
27 #include <deque>
28 
29 namespace mitk
30 {
31  //##Documentation
32  //## @brief A linear undo model with one undo and one redo stack.
33  //##
34  //## Derived from UndoModel AND itk::Object. Invokes ITK-events to signal listening
35  //## GUI elements, whether each of the stacks is empty or not (to enable/disable button, ...)
37  {
38  public:
39  typedef std::deque<UndoStackItem *> UndoContainer;
40  typedef std::deque<UndoStackItem *>::reverse_iterator UndoContainerRevIter;
41 
43  itkFactorylessNewMacro(Self);
44  itkCloneMacro(Self);
45 
46  bool SetOperationEvent(UndoStackItem *stackItem) override;
47 
48  //##Documentation
49  //## @brief Undoes the last changes
50  //##
51  //## Reads the top element of the Undo-Stack,
52  //## executes the operation,
53  //## swaps the OperationEvent-Undo with the Operation
54  //## and sets it to Redo-Stack
55  bool Undo() override;
56  bool Undo(bool) override;
57 
58  //##Documentation
59  //## @brief Undoes all changes until ObjectEventID oeid
60  virtual bool Undo(int oeid);
61 
62  //##Documentation
63  //## @brief Undoes the last changes
64  //##
65  //## Reads the top element of the Redo-Stack,
66  //## executes the operation,
67  //## swaps the OperationEvent-Operation with the Undo-Operation
68  //## and sets it to Undo-Stack
69  bool Redo() override;
70  bool Redo(bool) override;
71 
72  //##Documentation
73  //## @brief Redoes all changes until ObjectEventID oeid
74  virtual bool Redo(int oeid);
75 
76  //##Documentation
77  //## @brief Clears UndoList and RedoList
78  void Clear() override;
79 
80  //##Documentation
81  //## @brief Clears the RedoList
82  void ClearRedoList() override;
83 
84  //##Documentation
85  //## @brief True, if RedoList is empty
86  bool RedoListEmpty() override;
87 
88  //##Documentation
89  //## @brief True, if UndoList is empty
90  bool UndoListEmpty() override;
91 
92  //##Documentation
93  //## @brief Gets the limit on the size of the undo history.
94  //## The undo limit determines how many items can be stored
95  //## in the undo stack. If the value is 0 that means that
96  //## there is no limit.
97  std::size_t GetUndoLimit() const override;
98 
99  //##Documentation
100  //## @brief Sets a limit on the size of the undo history.
101  //## If the limit is reached, the oldest undo items will
102  //## be dropped from the bottom of the undo stack.
103  //## The 0 value means that there is no limit.
104  //## @param limit the maximum number of items on the stack
105  void SetUndoLimit(std::size_t limit) override;
106 
107  //##Documentation
108  //## @brief Returns the ObjectEventId of the
109  //## top element in the OperationHistory
110  int GetLastObjectEventIdInList() override;
111 
112  //##Documentation
113  //## @brief Returns the GroupEventId of the
114  //## top element in the OperationHistory
115  int GetLastGroupEventIdInList() override;
116 
117  //##Documentation
118  //## @brief Returns the last specified OperationEvent in Undo-list
119  //## corresponding to the given values; if nothing found, then returns nullptr
120  OperationEvent *GetLastOfType(OperationActor *destination, OperationType opType) override;
121 
127  unsigned int RemoveInvalidOperations() override;
128 
129  protected:
130  //##Documentation
131  //## Constructor
133 
134  //##Documentation
135  //## Destructor
136  ~LimitedLinearUndo() override;
137 
138  //## @brief Convenience method to free the memory of
139  //## elements in the list and to clear the list
140  void ClearList(UndoContainer *list);
141 
143 
145 
146  private:
147  int FirstObjectEventIdOfCurrentGroup(UndoContainer &stack);
148 
149  std::size_t m_UndoLimit;
150 
151  };
152 
153 #pragma GCC visibility push(default)
154 
157  itkEventMacroDeclaration(UndoStackEvent, itk::ModifiedEvent);
158  itkEventMacroDeclaration(UndoEmptyEvent, UndoStackEvent);
159  itkEventMacroDeclaration(RedoEmptyEvent, UndoStackEvent);
160  itkEventMacroDeclaration(UndoNotEmptyEvent, UndoStackEvent);
161  itkEventMacroDeclaration(RedoNotEmptyEvent, UndoStackEvent);
163  itkEventMacroDeclaration(UndoFullEvent, UndoStackEvent);
164  itkEventMacroDeclaration(RedoFullEvent, UndoStackEvent);
165 
166 #pragma GCC visibility pop
167 
168 } // namespace mitk
169 
170 #endif
mitk::OperationActor
abstract class, that can be used by Undo to undo an operation.
Definition: mitkOperationActor.h:41
mitk::LimitedLinearUndo::m_RedoList
UndoContainer m_RedoList
Definition: mitkLimitedLinearUndo.h:144
mitk::LimitedLinearUndo::m_UndoList
UndoContainer m_UndoList
Definition: mitkLimitedLinearUndo.h:142
mitk::UndoStackItem
Represents an entry of the undo or redo stack.
Definition: mitkOperationEvent.h:40
mitk::LimitedLinearUndo::UndoContainer
std::deque< UndoStackItem * > UndoContainer
Definition: mitkLimitedLinearUndo.h:39
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitkUndoModel.h
mitkOperationEvent.h
MitkCoreExports.h
mitk::LimitedLinearUndo::UndoContainerRevIter
std::deque< UndoStackItem * >::reverse_iterator UndoContainerRevIter
Definition: mitkLimitedLinearUndo.h:40
mitk::OperationType
int OperationType
Definition: mitkOperation.h:23
mitk::OperationEvent
Represents a pair of operations: undo and the according redo.
Definition: mitkOperationEvent.h:148
mitk::UndoModel
superclass for all UndoModels
Definition: mitkUndoModel.h:32
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
mitk::LimitedLinearUndo
A linear undo model with one undo and one redo stack.
Definition: mitkLimitedLinearUndo.h:36
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition: MitkCoreExports.h:15
mitk::itkEventMacroDeclaration
itkEventMacroDeclaration(BoundingShapeInteractionEvent, itk::AnyEvent)