Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef LIMITEDLINEARUNDO_H_HEADER_INCLUDED_C16E9C96
18 #define LIMITEDLINEARUNDO_H_HEADER_INCLUDED_C16E9C96
19 
20 // MITK header
21 #include "mitkOperationEvent.h"
22 #include "mitkUndoModel.h"
23 #include <MitkCoreExports.h>
24 // STL header
25 #include <vector>
26 // ITK header
27 #pragma GCC visibility push(default)
28 #include <itkEventObject.h>
29 #pragma GCC visibility pop
30 
31 namespace mitk
32 {
33  //##Documentation
34  //## @brief A linear undo model with one undo and one redo stack.
35  //##
36  //## Derived from UndoModel AND itk::Object. Invokes ITK-events to signal listening
37  //## GUI elements, whether each of the stacks is empty or not (to enable/disable button, ...)
39  {
40  public:
41  typedef std::vector<UndoStackItem *> UndoContainer;
42  typedef std::vector<UndoStackItem *>::reverse_iterator UndoContainerRevIter;
43 
45  itkFactorylessNewMacro(Self) itkCloneMacro(Self)
46 
47  virtual bool SetOperationEvent(UndoStackItem *stackItem) override;
48 
49  //##Documentation
50  //## @brief Undoes the last changes
51  //##
52  //## Reads the top element of the Undo-Stack,
53  //## executes the operation,
54  //## swaps the OperationEvent-Undo with the Operation
55  //## and sets it to Redo-Stack
56  virtual bool Undo() override;
57  virtual bool Undo(bool) override;
58 
59  //##Documentation
60  //## @brief Undoes all changes until ObjectEventID oeid
61  virtual bool Undo(int oeid);
62 
63  //##Documentation
64  //## @brief Undoes the last changes
65  //##
66  //## Reads the top element of the Redo-Stack,
67  //## executes the operation,
68  //## swaps the OperationEvent-Operation with the Undo-Operation
69  //## and sets it to Undo-Stack
70  virtual bool Redo() override;
71  virtual bool Redo(bool) override;
72 
73  //##Documentation
74  //## @brief Redoes all changes until ObjectEventID oeid
75  virtual bool Redo(int oeid);
76 
77  //##Documentation
78  //## @brief Clears UndoList and RedoList
79  virtual void Clear() override;
80 
81  //##Documentation
82  //## @brief Clears the RedoList
83  virtual void ClearRedoList() override;
84 
85  //##Documentation
86  //## @brief True, if RedoList is empty
87  virtual bool RedoListEmpty() override;
88 
89  //##Documentation
90  //## @brief Returns the ObjectEventId of the
91  //## top element in the OperationHistory
92  virtual int GetLastObjectEventIdInList() override;
93 
94  //##Documentation
95  //## @brief Returns the GroupEventId of the
96  //## top element in the OperationHistory
97  virtual int GetLastGroupEventIdInList() override;
98 
99  //##Documentation
100  //## @brief Returns the last specified OperationEvent in Undo-list
101  //## corresponding to the given values; if nothing found, then returns NULL
102  virtual OperationEvent *GetLastOfType(OperationActor *destination, OperationType opType) override;
103 
104  protected:
105  //##Documentation
106  //## Constructor
108 
109  //##Documentation
110  //## Destructor
111  virtual ~LimitedLinearUndo();
112 
113  //## @brief Convenience method to free the memory of
114  //## elements in the list and to clear the list
115  void ClearList(UndoContainer *list);
116 
117  UndoContainer m_UndoList;
118 
119  UndoContainer m_RedoList;
120 
121  private:
122  int FirstObjectEventIdOfCurrentGroup(UndoContainer &stack);
123  };
124 
125 #pragma GCC visibility push(default)
126 
129  itkEventMacro(UndoStackEvent, itk::ModifiedEvent);
130  itkEventMacro(UndoEmptyEvent, UndoStackEvent);
131  itkEventMacro(RedoEmptyEvent, UndoStackEvent);
132  itkEventMacro(UndoNotEmptyEvent, UndoStackEvent);
133  itkEventMacro(RedoNotEmptyEvent, UndoStackEvent);
135  itkEventMacro(UndoFullEvent, UndoStackEvent);
136  itkEventMacro(RedoFullEvent, UndoStackEvent);
137 
138 #pragma GCC visibility pop
139 
140 } // namespace mitk
141 
142 #endif /* LIMITEDLINEARUNDO_H_HEADER_INCLUDED_C16E9C96 */
std::vector< UndoStackItem * >::reverse_iterator UndoContainerRevIter
#define MITKCORE_EXPORT
DataCollection - Class to facilitate loading/accessing structured data.
A linear undo model with one undo and one redo stack.
abstract class, that can be used by Undo to undo an operation.
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
Represents an entry of the undo or redo stack.
superclass for all UndoModels
Definition: mitkUndoModel.h:36
itkEventMacro(ContourModelEvent, itk::AnyEvent)
int OperationType
Definition: mitkOperation.h:27
std::vector< UndoStackItem * > UndoContainer
Represents a pair of operations: undo and the according redo.