Medical Imaging Interaction Toolkit  2016.11.0
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,
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 
19 //Microservices
20 #include <usGetModuleContext.h>
21 #include <usModuleContext.h>
22 
24  : m_ServiceRegistration()
25  , m_TrackingDeviceWidgets()
26 {
27 }
28 
30 {
31  for (auto& item : m_TrackingDeviceWidgets)
32  {
33  delete item.second;
34  }
35 }
36 
38 {
39  us::ModuleContext* context = us::GetModuleContext();
40 
41  m_ServiceRegistration = context->RegisterService(this);
42 }
43 
45 {
46  if (m_ServiceRegistration != nullptr) m_ServiceRegistration.Unregister();
47  m_ServiceRegistration = 0;
48 }
49 
51 {
52  if (widget != nullptr)
53  {
54  //Don't add widget, if it is already included
55  for (unsigned int i = 0; i < m_TrackingDeviceWidgets.size(); i++)
56  {
57  if (m_TrackingDeviceWidgets.at(i).first == type)
58  return;
59  }
60  m_TrackingDeviceWidgets.push_back(std::make_pair(type, widget));
61  }
62 }
63 
65 {
66  for (unsigned int i = 0; i < m_TrackingDeviceWidgets.size(); i++)
67  {
68  if (m_TrackingDeviceWidgets.at(i).first == type)
69  {
70  if (!(m_TrackingDeviceWidgets.at(i).second->IsInitialized()))
71  {
72  m_TrackingDeviceWidgets.at(i).second->Initialize();
73  if (!(m_TrackingDeviceWidgets.at(i).second->IsInitialized())) //still not initialized?
74  MITK_ERROR << "Something went wrong with initialization of your tracking device widget!";
75  }
76  return (m_TrackingDeviceWidgets.at(i).second->CloneForQt());
77  }
78  }
79  return nullptr;
80 }
QmitkAbstractTrackingDeviceWidget * GetTrackingDeviceWidgetClone(TrackingDeviceType type)
#define MITK_ERROR
Definition: mitkLogMacros.h:24
virtual void Initialize()=0
Subclass must implement this method to return a pointer to a copy of the object. Please don't forget ...
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.