Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPropertyObserver.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 <itkCommand.h>
18 #include <mitkBaseProperty.h>
19 #include <mitkPropertyObserver.h>
20 #include <stdexcept>
21 
22 namespace mitk
23 {
24  //---- PropertyObserver -----------------------------------------------------------
25  PropertyObserver::PropertyObserver() : m_SelfCall(false) {}
29  //---- PropertyView ---------------------------------------------------------------
30 
31  PropertyView::PropertyView(const mitk::BaseProperty *property) : m_Property(property)
32  {
33  if (!property)
34  throw std::invalid_argument("NULL pointer makes no sense in PropertyView()"); // no NULL property allowed
35 
36  {
38  command->SetCallbackFunction(this, &PropertyView::OnModified);
39  m_ModifiedTag = property->AddObserver(itk::ModifiedEvent(), command);
40  }
41  {
43  command->SetCallbackFunction(this, &PropertyView::OnDelete);
44  m_DeleteTag = property->AddObserver(itk::DeleteEvent(), command);
45  }
46  }
47 
49  {
50  if (m_Property)
51  {
52  mitk::BaseProperty *prop = const_cast<mitk::BaseProperty *>(m_Property);
53  prop->RemoveObserver(m_ModifiedTag);
54  prop->RemoveObserver(m_DeleteTag);
55  m_Property = nullptr;
56  }
57  }
58 
59  void PropertyView::OnModified(const itk::EventObject & /*e*/)
60  {
61  if (m_SelfCall)
62  return;
63 
65  }
66 
67  void PropertyView::OnDelete(const itk::EventObject & /*e*/)
68  {
69  if (m_SelfCall)
70  return;
71 
73  if (m_Property)
74  {
75  mitk::BaseProperty *prop = const_cast<mitk::BaseProperty *>(m_Property);
76  prop->RemoveObserver(m_ModifiedTag);
77  prop->RemoveObserver(m_DeleteTag);
78  m_Property = nullptr;
79  }
80  }
81 
82  //---- PropertyEditor -------------------------------------------------------------
83 
84  PropertyEditor::PropertyEditor(mitk::BaseProperty *property) : m_Property(property)
85  {
86  if (!property)
87  throw std::invalid_argument("NULL pointer makes no sense in PropertyEditor()"); // no NULL property allowed
88 
89  {
91  command->SetCallbackFunction(this, &PropertyEditor::OnModified);
92  m_ModifiedTag = property->AddObserver(itk::ModifiedEvent(), command);
93  }
94  {
96  command->SetCallbackFunction(this, &PropertyEditor::OnDelete);
97  m_DeleteTag = property->AddObserver(itk::DeleteEvent(), command);
98  }
99  }
100 
102  {
103  if (m_Property)
104  {
105  m_Property->RemoveObserver(m_ModifiedTag);
106  m_Property->RemoveObserver(m_DeleteTag);
107  m_Property = nullptr;
108  }
109  }
110 
111  void PropertyEditor::OnModified(const itk::EventObject & /*e*/)
112  {
113  if (m_SelfCall)
114  return;
115 
116  PropertyChanged();
117  }
118 
119  void PropertyEditor::OnDelete(const itk::EventObject & /*e*/)
120  {
121  if (m_SelfCall)
122  return; // does this make any sense?
123 
124  PropertyRemoved();
125  if (m_Property)
126  {
127  m_Property->RemoveObserver(m_ModifiedTag);
128  m_Property->RemoveObserver(m_DeleteTag);
129  m_Property = nullptr;
130  }
131  }
132 
133 } // namespace
PropertyView(const mitk::BaseProperty *)
itk::SmartPointer< Self > Pointer
virtual void PropertyRemoved()=0
DataCollection - Class to facilitate loading/accessing structured data.
mitk::BaseProperty * m_Property
Abstract base class for properties.
void OnDelete(const itk::EventObject &e)
const mitk::BaseProperty * m_Property
PropertyEditor(mitk::BaseProperty *)
virtual void PropertyChanged()=0
void OnModified(const itk::EventObject &e)
void OnDelete(const itk::EventObject &e)
void OnModified(const itk::EventObject &e)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.