Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkOperationEvent.cpp
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 #include "mitkOperationEvent.h"
18 #include <itkCommand.h>
19 
20 int mitk::UndoStackItem::m_CurrObjectEventId = 0;
21 int mitk::UndoStackItem::m_CurrGroupEventId = 0;
22 
23 mitk::UndoStackItem::UndoStackItem(std::string description) : m_Reversed(false), m_Description(description)
24 {
25  m_ObjectEventId = GetCurrObjectEventId();
26  m_GroupEventId = GetCurrGroupEventId();
27 }
28 
30 {
31  // nothing to do
32 }
33 
35 {
36  return m_CurrObjectEventId;
37 }
38 
40 {
41  return m_CurrGroupEventId;
42 }
43 
45 {
46  ++m_CurrObjectEventId;
47 }
48 
50 {
51  ++m_CurrGroupEventId;
52 }
53 
55 {
56  return m_ObjectEventId;
57 }
58 
60 {
61  return m_GroupEventId;
62 }
63 
65 {
66  return m_Description;
67 }
68 
70 {
71  m_Reversed = !m_Reversed;
72 }
73 
75 {
76  ReverseOperations();
77 }
78 
79 // ******************** mitk::OperationEvent ********************
80 
82 {
83  return m_Operation;
84 }
85 
87  Operation *operation,
88  Operation *undoOperation,
89  std::string description)
90  : UndoStackItem(description),
91  m_Destination(destination),
92  m_Operation(operation),
93  m_UndoOperation(undoOperation),
94  m_Invalid(false)
95 {
96  // connect to delete event
97  if (itk::Object *object = dynamic_cast<itk::Object *>(m_Destination))
98  {
100  command->SetCallbackFunction(this, &OperationEvent::OnObjectDeleted);
101  m_DeleteTag = object->AddObserver(itk::DeleteEvent(), command);
102  }
103 }
104 
106 {
107  // remove the observer if the data m_Destination still is present
108  if (!m_Invalid)
109  {
110  if (itk::Object *object = dynamic_cast<itk::Object *>(m_Destination))
111  {
112  object->RemoveObserver(m_DeleteTag);
113  }
114  }
115 
116  delete m_Operation;
117  delete m_UndoOperation;
118 }
119 
120 //##Documentation
121 //## swaps the Undo and Redo- operation and changes m_Reversed
123 {
124  if (m_Operation == nullptr)
125  return;
126 
127  Operation *tempOperation = m_Operation;
128  m_Operation = m_UndoOperation;
129  m_UndoOperation = tempOperation;
130 
132 }
133 
135 {
136  ReverseOperations();
137  if (m_Destination && m_Operation && !m_Invalid)
138  m_Destination->ExecuteOperation(m_Operation);
139 }
140 
142 {
143  return m_Destination;
144 }
145 
147 {
148  m_Invalid = true;
149 }
150 
152 {
153  return !m_Invalid;
154 }
int GetObjectEventId()
Returns the ObjectEventId for this object.
itk::SmartPointer< Self > Pointer
Base class of all Operation-classes.
Definition: mitkOperation.h:33
std::string GetDescription()
Returns the textual description of this object.
static int GetCurrGroupEventId()
For combining operations in groups.
OperationActor * GetDestination()
abstract class, that can be used by Undo to undo an operation.
virtual void ReverseAndExecute()
virtual void ReverseOperations()
virtual void ReverseAndExecute() override
int GetGroupEventId()
Returns the GroupEventId for this object.
Represents an entry of the undo or redo stack.
UndoStackItem(std::string description="")
OperationEvent(OperationActor *destination, Operation *operation, Operation *undoOperation, std::string description="")
virtual void ReverseOperations() override
static void IncCurrObjectEventId()
Increases the current ObjectEventId For example if a button click generates operations the ObjectEven...
static int GetCurrObjectEventId()
For combining operations in Objects.
static void IncCurrGroupEventId()
Increases the current GroupEventId For example if a button click generates operations the GroupEventI...
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.