MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
QmitkNavigationDataSourceSelectionWidget.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found 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;
28
29}
30
31
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
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 }
Ui::QmitkNavigationDataSourceSelectionWidgetControls * m_Controls
void NavigationDataSourceSelected(mitk::NavigationDataSource::Pointer n)
This signal is emitted when a new navigation data source is selected.
void NavigationToolSelected(mitk::NavigationTool::Pointer n)
This signal is emitted when a new navigation data tool is selected.
virtual void CreateConnections()
Creation of the connections.
QmitkNavigationDataSourceSelectionWidget(QWidget *parent=nullptr, Qt::WindowFlags f={})
mitk::NavigationToolStorage::Pointer GetNavigationToolStorageOfSource()
static const std::string US_PROPKEY_DEVICENAME