Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkOperationEvent.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 mitkOperationEvent_h
14 #define mitkOperationEvent_h
15 
16 #include <mitkOperation.h>
17 #include <mitkOperationActor.h>
18 #include <mitkUndoModel.h>
19 
21 
22 #include <list>
23 #include <string>
24 
25 
26 #include <MitkCoreExports.h>
27 
28 namespace mitk
29 {
44  {
45  public:
50  UndoStackItem(std::string description = "");
51 
53  virtual ~UndoStackItem();
54 
63  static int GetCurrGroupEventId();
64 
74  static int GetCurrObjectEventId();
75 
81 
87 
92  std::string GetDescription();
93 
95  virtual void ReverseOperations();
96 
98  virtual void ReverseAndExecute();
99 
108  virtual bool IsValid() const = 0;
109 
118  static void IncCurrObjectEventId();
119 
127  static void IncCurrGroupEventId();
128 
129  protected:
130  //##Documentation
131  //## @brief true, if operation and undooperation have been swapped/changed
133 
134  private:
135  static int m_CurrObjectEventId;
136 
137  static int m_CurrGroupEventId;
138 
139  int m_ObjectEventId;
140 
141  int m_GroupEventId;
142 
143  std::string m_Description;
144 
145  UndoStackItem(UndoStackItem &); // hide copy constructor
146  void operator=(const UndoStackItem &); // hide operator=
147  };
148 
166  {
167  public:
180  Operation *operation,
181  Operation *undoOperation,
182  std::string description = "");
183 
190  ~OperationEvent() override;
191 
197 
203 
204  friend class UndoModel;
205 
212  void ReverseOperations() override;
213 
219  void ReverseAndExecute() override;
220 
229  bool IsValid() const override;
230 
231  protected:
233 
234  private:
235  // Has to be observed for itk::DeleteEvents.
236  // When destination is deleted, this stack item is invalid!
237  OperationActor* m_Destination;
238 
239  //## reference to the operation
240  Operation *m_Operation;
241 
242  //## reference to the undo operation
243  Operation *m_UndoOperation;
244 
245  //## hide copy constructor
247  //## hide operator=
248  void operator=(const OperationEvent &);
249 
250  ITKEventObserverGuard m_DelObserver;
251 
252  //## stores if destination is valid or already has been freed
253  bool m_Invalid;
254  };
255 
256 } // namespace mitk
257 
258 #endif
#define MITKCORE_EXPORT
Convenience class that helps to manage the lifetime of itk event observers.
abstract class, that can be used by Undo to undo an operation.
Pairs a do-operation with its inverse undo-operation.
void ReverseAndExecute() override
Reverse the operations and execute the (now current) do-operation.
OperationActor * GetDestination()
Get the destination actor for the operations.
~OperationEvent() override
Destructor.
Operation * GetOperation()
Get the current do-operation.
bool IsValid() const override
Check whether this event is still valid.
void ReverseOperations() override
Swap the do-operation and undo-operation.
OperationEvent(OperationActor *destination, Operation *operation, Operation *undoOperation, std::string description="")
Construct an OperationEvent.
Base class for all operations in the undo/redo framework.
Definition: mitkOperation.h:38
Abstract superclass for all undo models.
Definition: mitkUndoModel.h:36
Represents an entry on the undo or redo stack.
virtual void ReverseOperations()
Swap the do/undo operations (toggle reversed state).
static void IncCurrObjectEventId()
Increment the global ObjectEventId counter.
std::string GetDescription()
Get the textual description of this undo entry.
virtual bool IsValid() const =0
Check whether this entry is still valid.
UndoStackItem(std::string description="")
Construct an UndoStackItem with an optional description.
static int GetCurrObjectEventId()
Get the current global ObjectEventId.
static int GetCurrGroupEventId()
Get the current global GroupEventId.
int GetGroupEventId()
Get this item's GroupEventId.
bool m_Reversed
true, if operation and undooperation have been swapped/changed
virtual ~UndoStackItem()
Virtual destructor.
int GetObjectEventId()
Get this item's ObjectEventId.
static void IncCurrGroupEventId()
Increment the global GroupEventId counter.
virtual void ReverseAndExecute()
Reverse the operations and execute them.
Find image slices visible on a given plane.