Medical Imaging Interaction Toolkit
2024.12.99-0da743f6
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
#include <
MitkCoreExports.h
>
20
#include <list>
21
#include <string>
22
23
namespace
mitk
24
{
25
//##Documentation
26
//## @brief Represents an entry of the undo or redo stack.
27
//##
28
//## This basic entry includes a textual description of the item and a pair of IDs. Static
29
//## member functions handle creation and incrementing of these IDs.
30
//##
31
//## The GroupEventID is intended for logical grouping of several related Operations.
32
//## Currently this is used only by PointSetDataInteractor. How this is done and when to use
33
//## GroupEventIDs is still undocumented.
34
//## @ingroup Undo
35
class
MITKCORE_EXPORT
UndoStackItem
36
{
37
public
:
38
UndoStackItem
(std::string description =
""
);
39
40
virtual
~
UndoStackItem
();
41
42
//##Documentation
43
//## @brief For combining operations in groups
44
//##
45
//## This ID is used in the undo mechanism.
46
//## For separation of the separate operations
47
//## If the GroupEventId of two OperationEvents is equal,
48
//## then they share one group and will be undone in case of Undo(fine==false)
49
static
int
GetCurrGroupEventId();
50
51
//##Documentation
52
//## @brief For combining operations in Objects
53
//##
54
//## This ID is used in the Undo-Mechanism.
55
//## For separation of the separate operations
56
//## If the ObjectEventId of two OperationEvents is equal,
57
//## then they share one Object and will be undone in all cases of Undo(true and false).
58
//## they shall not be separated, because they were produced to realize one object-change.
59
//## for example: OE_statechange and OE_addlastpoint
60
static
int
GetCurrObjectEventId();
61
62
//##Documentation
63
//## @brief Returns the GroupEventId for this object
64
int
GetGroupEventId();
65
66
//##Documentation
67
//## @brief Returns the ObjectEventId for this object
68
int
GetObjectEventId();
69
70
//##Documentation
71
//## @brief Returns the textual description of this object
72
std::string GetDescription();
73
74
virtual
void
ReverseOperations();
75
virtual
void
ReverseAndExecute();
76
77
//##Documentation
78
//## @brief Increases the current ObjectEventId
79
//## For example if a button click generates operations the ObjectEventId has to be incremented to be able to undo
80
//the
81
// operations.
82
//## Difference between ObjectEventId and GroupEventId: The ObjectEventId capsulates all operations caused by one
83
// event.
84
//## A GroupEventId capsulates several ObjectEventIds so that several operations caused by several events can be
85
// undone with one Undo call.
86
static
void
IncCurrObjectEventId();
87
88
//##Documentation
89
//## @brief Increases the current GroupEventId
90
//## For example if a button click generates operations the GroupEventId has to be incremented to be able to undo
91
//the
92
// operations.
93
//## Difference between ObjectEventId and GroupEventId: The ObjectEventId capsulates all operations caused by one
94
// event.
95
//## A GroupEventId capsulates several ObjectEventIds so that several operations caused by several events can be
96
// undone with one Undo call.
97
static
void
IncCurrGroupEventId();
98
99
protected
:
100
//##Documentation
101
//## @brief true, if operation and undooperation have been swapped/changed
102
bool
m_Reversed
;
103
104
private
:
105
static
int
m_CurrObjectEventId;
106
107
static
int
m_CurrGroupEventId;
108
109
int
m_ObjectEventId;
110
111
int
m_GroupEventId;
112
113
std::string m_Description;
114
115
UndoStackItem
(
UndoStackItem
&);
// hide copy constructor
116
void
operator=(
const
UndoStackItem
&);
// hide operator=
117
};
118
119
//##Documentation
120
//## @brief Represents a pair of operations: undo and the according redo.
121
//##
122
//## Additionally to the base class UndoStackItem, which only provides a description of an
123
//## item, OperationEvent does the actual accounting of the undo/redo stack. This class
124
//## holds two Operation objects (operation and its inverse operation) and the corresponding
125
//## OperationActor. The operations may be swapped by the
126
//## undo models, when an OperationEvent is moved from their undo to their redo
127
//## stack or vice versa.
128
//##
129
//## Note, that memory management of operation and undooperation is done by this class.
130
//## Memory of both objects is freed in the destructor. For this, the method IsValid() is needed which holds
131
//## information of the state of m_Destination. In case the object referenced by m_Destination is already deleted,
132
//## isValid() returns false.
133
//## In more detail if the destination happens to be an itk::Object (often the case), OperationEvent is informed as
134
//soon
135
//## as the object is deleted - from this moment on the OperationEvent gets invalid. You should
136
//## check this flag before you call anything on destination
137
//##
138
//## @ingroup Undo
139
class
MITKCORE_EXPORT
OperationEvent
:
public
UndoStackItem
140
{
141
public
:
142
//## @brief default constructor
143
OperationEvent
(
OperationActor
*destination,
144
Operation
*operation,
145
Operation
*undoOperation,
146
std::string description =
""
);
147
148
//## @brief default destructor
149
//##
150
//## removes observers if destination is valid
151
//## and frees memory referenced by m_Operation and m_UndoOperation
152
~
OperationEvent
()
override
;
153
154
//## @brief Returns the operation
155
Operation
*GetOperation();
156
157
//## @brief Returns the destination of the operations
158
OperationActor
*GetDestination();
159
160
friend
class
UndoModel
;
161
162
//## @brief Swaps the two operations and sets a flag,
163
//## that it has been swapped and doOp is undoOp and undoOp is doOp
164
void
ReverseOperations()
override
;
165
166
//##reverses and executes both operations (used, when moved from undo to redo stack)
167
void
ReverseAndExecute()
override
;
168
169
//## @brief returns true if the destination still is present
170
//## and false if it already has been deleted
171
virtual
bool
IsValid();
172
173
protected
:
174
void
OnObjectDeleted();
175
176
private
:
177
// Has to be observed for itk::DeleteEvents.
178
// When destination is deleted, this stack item is invalid!
179
OperationActor
*m_Destination;
180
181
//## reference to the operation
182
Operation
*m_Operation;
183
184
//## reference to the undo operation
185
Operation
*m_UndoOperation;
186
187
//## hide copy constructor
188
OperationEvent
(
OperationEvent
&);
189
//## hide operator=
190
void
operator=(
const
OperationEvent
&);
191
192
// observertag used to listen to m_Destination
193
unsigned
long
m_DeleteTag;
194
195
//## stores if destination is valid or already has been freed
196
bool
m_Invalid;
197
};
198
199
}
// namespace mitk
200
201
#endif
mitk::OperationActor
abstract class, that can be used by Undo to undo an operation.
Definition:
mitkOperationActor.h:41
mitk::Operation
Base class of all Operation-classes.
Definition:
mitkOperation.h:29
mitkOperationActor.h
mitk::UndoStackItem
Represents an entry of the undo or redo stack.
Definition:
mitkOperationEvent.h:35
mitk
Find image slices visible on a given plane.
Definition:
RenderingTests.dox:1
mitkUndoModel.h
MitkCoreExports.h
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
mitkOperation.h
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition:
MitkCoreExports.h:15
mitk::UndoStackItem::m_Reversed
bool m_Reversed
true, if operation and undooperation have been swapped/changed
Definition:
mitkOperationEvent.h:102
src
MITK
Modules
Core
include
mitkOperationEvent.h
Generated on Mon Dec 23 2024 02:13:20 for Medical Imaging Interaction Toolkit by
1.8.17