Medical Imaging Interaction Toolkit  2024.06.00
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 Gets the limit on the size of the undo history.
90  //## The undo limit determines how many items can be stored
91  //## in the undo stack. If the value is 0 that means that
92  //## there is no limit.
93  std::size_t GetUndoLimit() const override;
94 
95  //##Documentation
96  //## @brief Sets a limit on the size of the undo history.
97  //## If the limit is reached, the oldest undo items will
98  //## be dropped from the bottom of the undo stack.
99  //## The 0 value means that there is no limit.
100  //## @param limit the maximum number of items on the stack
101  void SetUndoLimit(std::size_t limit) override;
102 
103  //##Documentation
104  //## @brief Returns the ObjectEventId of the
105  //## top element in the OperationHistory
106  int GetLastObjectEventIdInList() override;
107 
108  //##Documentation
109  //## @brief Returns the GroupEventId of the
110  //## top element in the OperationHistory
111  int GetLastGroupEventIdInList() override;
112 
113  //##Documentation
114  //## @brief Returns the last specified OperationEvent in Undo-list
115  //## corresponding to the given values; if nothing found, then returns nullptr
116  OperationEvent *GetLastOfType(OperationActor *destination, OperationType opType) override;
117 
118  protected:
119  //##Documentation
120  //## Constructor
122 
123  //##Documentation
124  //## Destructor
125  ~LimitedLinearUndo() override;
126 
127  //## @brief Convenience method to free the memory of
128  //## elements in the list and to clear the list
129  void ClearList(UndoContainer *list);
130 
132 
134 
135  private:
136  int FirstObjectEventIdOfCurrentGroup(UndoContainer &stack);
137 
138  std::size_t m_UndoLimit;
139 
140  };
141 
142 #pragma GCC visibility push(default)
143 
146  itkEventMacroDeclaration(UndoStackEvent, itk::ModifiedEvent);
147  itkEventMacroDeclaration(UndoEmptyEvent, UndoStackEvent);
148  itkEventMacroDeclaration(RedoEmptyEvent, UndoStackEvent);
149  itkEventMacroDeclaration(UndoNotEmptyEvent, UndoStackEvent);
150  itkEventMacroDeclaration(RedoNotEmptyEvent, UndoStackEvent);
152  itkEventMacroDeclaration(UndoFullEvent, UndoStackEvent);
153  itkEventMacroDeclaration(RedoFullEvent, UndoStackEvent);
154 
155 #pragma GCC visibility pop
156 
157 } // namespace mitk
158 
159 #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:133
mitk::LimitedLinearUndo::m_UndoList
UndoContainer m_UndoList
Definition: mitkLimitedLinearUndo.h:131
mitk::UndoStackItem
Represents an entry of the undo or redo stack.
Definition: mitkOperationEvent.h:35
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:139
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)