Medical Imaging Interaction Toolkit  2018.4.99-c7ee88da
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 (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 //mitk headers
17 #include <usGetModuleContext.h>
18 #include <usServiceReference.h>
19 
20 
21 
23 : QWidget(parent, f)
24 {
25  m_Controls = nullptr;
26  CreateQtPartControl(this);
28 
29 }
30 
31 
33 {
34 
35 }
36 
38 {
39  if (!m_Controls)
40  {
41  // create GUI widgets
42  m_Controls = new Ui::QmitkNavigationDataSourceSelectionWidgetControls;
43  m_Controls->setupUi(parent);
44 
45  std::string empty = "";
46  m_Controls->m_NavigationDataSourceWidget->Initialize<mitk::NavigationDataSource>(mitk::NavigationDataSource::US_PROPKEY_DEVICENAME,empty);
47 
48  }
49 }
50 
52 {
53  if ( m_Controls )
54  {
55  connect( (QObject*)(m_Controls->m_NavigationDataSourceWidget), SIGNAL(ServiceSelectionChanged(us::ServiceReferenceU)), this, SLOT(NavigationDataSourceSelected(us::ServiceReferenceU)) );
56  connect((QObject*)(m_Controls->m_ToolView), SIGNAL(currentRowChanged(int)), this, SLOT(NavigationToolSelected(int)));
57 
58  }
59 }
60 
62 {
63  emit NavigationToolSelected(this->m_CurrentStorage->GetTool(selection));
64 }
65 
67  {
68  if (!s) //no device selected
69  {
70  //reset everything
71  m_CurrentSource = nullptr;
72  m_CurrentStorage = nullptr;
74  return;
75  }
76 
77  // Get Source
78  us::ModuleContext* context = us::GetModuleContext();
79  m_CurrentSource = context->GetService<mitk::NavigationDataSource>(s);
80 
81  // clear tool list before filling it
82  m_Controls->m_ToolView->clear();
83  //Fill tool list
84  MITK_INFO<<"no outputs: "<<m_CurrentSource->GetNumberOfOutputs();
85  for(std::size_t i = 0; i < m_CurrentSource->GetNumberOfOutputs(); i++)
86  {
87  new QListWidgetItem(tr(m_CurrentSource->GetOutput(i)->GetName()), m_Controls->m_ToolView);
88  }
89 
90  // Get corresponding tool storage
91  m_CurrentStorage = m_CurrentSource->GetToolMetaDataCollection();
92 
93  if (m_CurrentStorage.IsNull())
94  {
95  MITK_WARN << "Found an invalid storage object!";
96  return;
97  }
98  if (m_CurrentStorage->GetToolCount() != m_CurrentSource->GetNumberOfOutputs()) //there is something wrong with the storage
99  {
100  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.";
101  m_CurrentStorage = nullptr;
102  }
103 
105  }
106 
108  {
109  return this->m_CurrentSource;
110  }
111 
112 
114  {
115  return this->m_Controls->m_ToolView->currentIndex().row();
116  }
117 
118 
120  {
121  if (this->m_CurrentStorage.IsNull()) return nullptr;
122  if ((m_Controls->m_ToolView->currentIndex().row() < 0) || (static_cast<unsigned int>(m_Controls->m_ToolView->currentIndex().row()) >= m_CurrentStorage->GetToolCount())) return nullptr;
123  return this->m_CurrentStorage->GetTool(m_Controls->m_ToolView->currentIndex().row());
124  }
125 
126 
128  {
129  return this->m_CurrentStorage;
130  }
#define MITK_INFO
Definition: mitkLogMacros.h:18
#define MITK_WARN
Definition: mitkLogMacros.h:19
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
QmitkNavigationDataSourceSelectionWidget(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
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.