Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkBindDispatcherInteractor.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 
18 #include "mitkMessage.h"
19 #include <string.h>
20 
21 // us
22 #include "usGetModuleContext.h"
23 #include "usModule.h"
24 #include "usModuleRegistry.h"
25 
27 {
28  us::ModuleContext *context = us::ModuleRegistry::GetModule(1)->GetModuleContext();
29  if (context == NULL)
30  {
31  MITK_ERROR << "BindDispatcherInteractor() - Context could not be obtained.";
32  return;
33  }
34 
35  m_Dispatcher = Dispatcher::New(rendererName);
36 }
37 
39 {
40  // Set/Change Datastorage. This registers BDI to listen for events of DataStorage, to be informed when
41  // a DataNode with a Interactor is added/modified/removed.
42 
43  if (dataStorage != m_DataStorage)
44  {
45  // clean up events from previous datastorage
46  UnRegisterDataStorageEvents();
47  m_DataStorage = dataStorage;
48  RegisterDataStorageEvents();
49  }
50 }
51 
53 {
54  if (m_DataStorage.IsNotNull())
55  {
56  UnRegisterDataStorageEvents();
57  }
58 }
59 
60 void mitk::BindDispatcherInteractor::RegisterInteractor(const mitk::DataNode *dataNode)
61 {
62  if (m_Dispatcher.IsNotNull())
63  {
64  m_Dispatcher->AddDataInteractor(dataNode);
65  }
66 }
67 
68 void mitk::BindDispatcherInteractor::RegisterDataStorageEvents()
69 {
70  if (m_DataStorage.IsNotNull())
71  {
72  m_DataStorage->AddNodeEvent.AddListener(MessageDelegate1<BindDispatcherInteractor, const DataNode *>(
73  this, &BindDispatcherInteractor::RegisterInteractor));
74 
75  m_DataStorage->RemoveNodeEvent.AddListener(MessageDelegate1<BindDispatcherInteractor, const DataNode *>(
76  this, &BindDispatcherInteractor::UnRegisterInteractor));
77 
78  m_DataStorage->InteractorChangedNodeEvent.AddListener(MessageDelegate1<BindDispatcherInteractor, const DataNode *>(
79  this, &BindDispatcherInteractor::RegisterInteractor));
80  }
81 }
82 
83 void mitk::BindDispatcherInteractor::UnRegisterInteractor(const DataNode *dataNode)
84 {
85  if (m_Dispatcher.IsNotNull())
86  {
87  m_Dispatcher->RemoveDataInteractor(dataNode);
88  }
89 }
90 
92 {
93  return m_Dispatcher;
94 }
95 
97 {
98  m_Dispatcher = dispatcher;
99 }
100 
101 void mitk::BindDispatcherInteractor::UnRegisterDataStorageEvents()
102 {
103  if (m_DataStorage.IsNotNull())
104  {
106  this, &BindDispatcherInteractor::RegisterInteractor));
108  this, &BindDispatcherInteractor::UnRegisterInteractor));
109  m_DataStorage->InteractorChangedNodeEvent.RemoveListener(
111  &BindDispatcherInteractor::RegisterInteractor));
112  }
113 }
#define MITK_ERROR
Definition: mitkLogMacros.h:24
static Module * GetModule(long id)
void SetDataStorage(DataStorage::Pointer dataStorage)
mitk::DataStorage::Pointer m_DataStorage
Dispatcher::Pointer GetDispatcher() const
ModuleContext * GetModuleContext() const
Definition: usModule.cpp:206
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
static Pointer New(const std::string &_arg)
void SetDispatcher(Dispatcher::Pointer dispatcher)