Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkNavigationDataSourceSelectionWidget.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 //mitk headers
21 #include <usGetModuleContext.h>
22 #include <usServiceReference.h>
23 
24 
25 
27 : QWidget(parent, f)
28 {
29  m_Controls = NULL;
30  CreateQtPartControl(this);
32 
33 }
34 
35 
37 {
38 
39 }
40 
42 {
43  if (!m_Controls)
44  {
45  // create GUI widgets
46  m_Controls = new Ui::QmitkNavigationDataSourceSelectionWidgetControls;
47  m_Controls->setupUi(parent);
48 
49  std::string empty = "";
50  m_Controls->m_NavigationDataSourceWidget->Initialize<mitk::NavigationDataSource>(mitk::NavigationDataSource::US_PROPKEY_DEVICENAME,empty);
51 
52  }
53 }
54 
56 {
57  if ( m_Controls )
58  {
59  connect( (QObject*)(m_Controls->m_NavigationDataSourceWidget), SIGNAL(ServiceSelectionChanged(us::ServiceReferenceU)), this, SLOT(NavigationDataSourceSelected(us::ServiceReferenceU)) );
60  connect((QObject*)(m_Controls->m_ToolView), SIGNAL(currentRowChanged(int)), this, SLOT(NavigationToolSelected(int)));
61 
62  }
63 }
64 
66 {
67  emit NavigationToolSelected(this->m_CurrentStorage->GetTool(selection));
68 }
69 
71  {
72  if (!s) //no device selected
73  {
74  //reset everything
75  m_CurrentSource = NULL;
76  m_CurrentStorage = NULL;
78  return;
79  }
80 
81  // Get Source
82  us::ModuleContext* context = us::GetModuleContext();
83  m_CurrentSource = context->GetService<mitk::NavigationDataSource>(s);
84  std::string id = s.GetProperty(mitk::NavigationDataSource::US_PROPKEY_ID).ToString();
85 
86  // clear tool list before filling it
87  m_Controls->m_ToolView->clear();
88  //Fill tool list
89  MITK_INFO<<"no outputs: "<<m_CurrentSource->GetNumberOfOutputs();
90  for(std::size_t i = 0; i < m_CurrentSource->GetNumberOfOutputs(); i++)
91  {
92  new QListWidgetItem(tr(m_CurrentSource->GetOutput(i)->GetName()), m_Controls->m_ToolView);
93  }
94 
95 
96  // Create Filter for ToolStorage
97  std::string filter = "("+ mitk::NavigationToolStorage::US_PROPKEY_SOURCE_ID + "=" + id + ")";
98 
99  // Get Storage
100  std::vector<us::ServiceReference<mitk::NavigationToolStorage> > refs = context->GetServiceReferences<mitk::NavigationToolStorage>(filter);
101  if (refs.empty()) return; //no storage was found
102  m_CurrentStorage = context->GetService(refs.front());
103  if (m_CurrentStorage.IsNull())
104  {
105  MITK_WARN << "Found an invalid storage object!";
106  return;
107  }
108  if (m_CurrentStorage->GetToolCount() != m_CurrentSource->GetNumberOfOutputs()) //there is something wrong with the storage
109  {
110  MITK_WARN << "Found a tool storage, but it has not the same number of tools like the NavigationDataSource. This storage won't be used because it isn't the right one.";
111  m_CurrentStorage = NULL;
112  }
113 
115  }
116 
118  {
119  return this->m_CurrentSource;
120  }
121 
122 
124  {
125  return this->m_Controls->m_ToolView->currentIndex().row();
126  }
127 
128 
130  {
131  if (this->m_CurrentStorage.IsNull()) return NULL;
132  if (m_Controls->m_ToolView->currentIndex().row() >= m_CurrentStorage->GetToolCount()) return NULL;
133  return this->m_CurrentStorage->GetTool(m_Controls->m_ToolView->currentIndex().row());
134  }
135 
136 
138  {
139  return this->m_CurrentStorage;
140  }
itk::SmartPointer< Self > Pointer
#define MITK_INFO
Definition: mitkLogMacros.h:22
static const std::string US_PROPKEY_SOURCE_ID
static const std::string US_PROPKEY_ID
An object of this class represents a collection of navigation tools. You may add/delete navigation to...
#define MITK_WARN
Definition: mitkLogMacros.h:23
QmitkNavigationDataSourceSelectionWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Ui::QmitkNavigationDataSourceSelectionWidgetControls * m_Controls
void NavigationToolSelected(mitk::NavigationTool::Pointer n)
This signal is emitted when a new navigation data tool is selected.
mitk::NavigationDataSource::Pointer GetSelectedNavigationDataSource()
virtual void CreateConnections()
Creation of the connections.
static const std::string US_PROPKEY_DEVICENAME
void NavigationDataSourceSelected(mitk::NavigationDataSource::Pointer n)
This signal is emitted when a new navigation data source is selected.
mitk::NavigationToolStorage::Pointer GetNavigationToolStorageOfSource()
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.