Medical Imaging Interaction Toolkit  2018.4.99-ef453c4b
Medical Imaging Interaction Toolkit
mitkTrackingDeviceWidgetCollection.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 (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 
14 
15 //Microservices
16 #include <usGetModuleContext.h>
17 #include <usModuleContext.h>
18 
20  : m_ServiceRegistration()
21  , m_TrackingDeviceWidgets()
22 {
23 }
24 
26 {
27  for (auto& item : m_TrackingDeviceWidgets)
28  {
29  delete item.second;
30  }
31 }
32 
34 {
35  us::ModuleContext* context = us::GetModuleContext();
36 
37  m_ServiceRegistration = context->RegisterService(this);
38 }
39 
41 {
42  if (m_ServiceRegistration != nullptr) m_ServiceRegistration.Unregister();
43  m_ServiceRegistration = 0;
44 }
45 
47 {
48  if (widget != nullptr)
49  {
50  //Don't add widget, if it is already included
51  for (unsigned int i = 0; i < m_TrackingDeviceWidgets.size(); i++)
52  {
53  if (m_TrackingDeviceWidgets.at(i).first == type)
54  return;
55  }
56  m_TrackingDeviceWidgets.push_back(std::make_pair(type, widget));
57  }
58 }
59 
61 {
62  for (unsigned int i = 0; i < m_TrackingDeviceWidgets.size(); i++)
63  {
64  if (m_TrackingDeviceWidgets.at(i).first == type)
65  {
66  if (!(m_TrackingDeviceWidgets.at(i).second->IsInitialized()))
67  {
68  m_TrackingDeviceWidgets.at(i).second->Initialize();
69  if (!(m_TrackingDeviceWidgets.at(i).second->IsInitialized())) //still not initialized?
70  MITK_ERROR << "Something went wrong with initialization of your tracking device widget!";
71  }
72  return (m_TrackingDeviceWidgets.at(i).second->CloneForQt());
73  }
74  }
75  return nullptr;
76 }
QmitkAbstractTrackingDeviceWidget * GetTrackingDeviceWidgetClone(TrackingDeviceType type)
#define MITK_ERROR
Definition: mitkLogMacros.h:20
virtual void RegisterAsMicroservice()
Registers this object as a Microservice, making it available to every module and/or plugin...
std::string TrackingDeviceType
Abstract class to configure a tracking device. Inherited widgets should be registered in the Microser...
virtual void UnRegisterMicroservice()
Registers this object as a Microservice, making it available to every module and/or plugin...
void RegisterTrackingDeviceWidget(TrackingDeviceType type, QmitkAbstractTrackingDeviceWidget *widget)
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.