Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkNDIPolarisWidget.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 
17 #include "QmitkNDIPolarisWidget.h"
18 
19 #include "mitkNDITrackingDevice.h"
21 
22 #include <QScrollBar>
23 #include <QSettings>
24 
25 const std::string QmitkNDIPolarisWidget::VIEW_ID = "org.mitk.views.NDIPolarisWidget";
26 
27 QmitkNDIPolarisWidget::QmitkNDIPolarisWidget(QWidget* parent, Qt::WindowFlags f)
28  : QmitkNDIAbstractDeviceWidget(parent, f)
29  , m_Controls(nullptr)
30 {
31 }
32 
34 {
36  CreateQtPartControl(this);
37  CreateConnections();
38 }
39 
41 {
42  delete m_Controls;
43 }
44 
45 void QmitkNDIPolarisWidget::CreateQtPartControl(QWidget *parent)
46 {
47  if (!m_Controls)
48  {
49  // create GUI widgets
50  m_Controls = new Ui::QmitkNDIPolarisWidget;
51  m_Controls->setupUi(parent);
52  }
53 }
54 
55 void QmitkNDIPolarisWidget::CreateConnections()
56 {
57  if (m_Controls)
58  {
59  connect((QObject*)(m_Controls->m_testConnectionPolaris), SIGNAL(clicked()), this, SLOT(TestConnection()));
60  connect((QObject*)(m_Controls->m_AutoScanPolaris), SIGNAL(clicked()), this, SLOT(AutoScanPorts()));
61 
62  //set a few UI components depending on Windows / Linux
63 #ifdef WIN32
64  m_Controls->portTypeLabelPolaris->setVisible(false);
65  m_Controls->portTypePolaris->setVisible(false);
66 
67 #else
68  m_Controls->m_comPortLabelPolaris->setText("Port Nr:");
69  m_Controls->m_portSpinBoxPolaris->setPrefix("");
70 #endif
71  }
72  }
73 
75 {
76  m_Controls->m_outputTextPolaris->setHtml("<body style=\" font-family:\'MS Shell Dlg 2\'; font-size:7pt; font-weight:400; font-style:normal;\" bgcolor=black><span style=\"color:#ffffff;\"><u>output:</u>");
77 }
78 
80 {
81  m_Controls->m_outputTextPolaris->setHtml(QString(s.c_str()));
82  m_Controls->m_outputTextPolaris->verticalScrollBar()->setValue(m_Controls->m_outputTextPolaris->verticalScrollBar()->maximum());
83 }
84 
86 {
88 
89  //get port
90  int port = 0;
91  port = m_Controls->m_portSpinBoxPolaris->value();
92 
93  //build prefix (depends on linux/win)
94  QString prefix = "";
95 #ifdef WIN32
96  prefix = "COM";
97  tempTrackingDevice->SetPortNumber(static_cast<mitk::SerialCommunication::PortNumber>(port)); //also set the com port for compatibility
98  tempTrackingDevice->SetIlluminationActivationRate(GetPolarisFrameRate());
99 #else
100  prefix = m_Controls->portTypePolaris->currentText();
101  tempTrackingDevice->SetIlluminationActivationRate(GetPolarisFrameRate());
102 #endif
103 
104  //build port name string
105  QString portName = prefix + QString::number(port);
106 
107  tempTrackingDevice->SetDeviceName(portName.toStdString()); //set the port name
108  tempTrackingDevice->SetBaudRate(mitk::SerialCommunication::BaudRate115200);//set baud rate
109  tempTrackingDevice->SetType(mitk::NDIPolarisTypeInformation::GetTrackingDeviceName());
110  return static_cast<mitk::TrackingDevice::Pointer>(tempTrackingDevice);
111 }
112 
114 {
115  std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget";
116  if (this->GetPersistenceService()) // now save the settings using the persistence service
117  {
118  mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList(id);
119  propList->Set("PolarisPortWin", m_Controls->m_portSpinBoxPolaris->value());
120  propList->Set("PortTypePolaris", m_Controls->portTypePolaris->currentIndex());
121  propList->Set("PolarisFrameRate", GetPolarisFrameRate());
122  }
123  else // QSettings as a fallback if the persistence service is not available
124  {
125  QSettings settings;
126  settings.beginGroup(QString::fromStdString(id));
127  settings.setValue("portSpinBoxPolaris", QVariant(m_Controls->m_portSpinBoxPolaris->value()));
128  settings.setValue("portTypePolaris", QVariant(m_Controls->portTypePolaris->currentIndex()));
129  settings.setValue("PolarisFrameRate", QVariant(GetPolarisFrameRate()));
130  settings.endGroup();
131  }
132 }
133 
135 {
136  std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget";
137  if (this->GetPersistenceService())
138  {
139  int port = 0;
140  int portType = 0;
141  int polarisFrameRate = 0;
142 
143  mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList(id);
144  if (propList.IsNull())
145  {
146  MITK_ERROR << "Property list for this UI (" << id << ") is not available, could not load UI settings!"; return;
147  }
148 
149  propList->Get("PolarisPortWin", port);
150  propList->Get("PortTypePolaris", portType);
151  propList->Get("PolarisFrameRate", polarisFrameRate);
152  this->SetPortTypeToGUI(portType);
153  this->SetPortValueToGUI(port);
154  m_Controls->m_frameRateComboBoxPolaris->setCurrentIndex((int)(polarisFrameRate / 30));
155  }
156  else
157  {
158  // QSettings as a fallback if the persistence service is not available
159  QSettings settings;
160  settings.beginGroup(QString::fromStdString(id));
161 
162  m_Controls->m_portSpinBoxPolaris->setValue(settings.value("portSpinBoxPolaris", 0).toInt());
163  m_Controls->portTypePolaris->setCurrentIndex(settings.value("portTypePolaris", 0).toInt());
164  //framerates 20,30,60 --> divided by 30 = 0,1,2 --> index of combobox
165  m_Controls->m_frameRateComboBoxPolaris->setCurrentIndex((int)(settings.value("PolarisFrameRate", 0).toInt() / 30));
166 
167  settings.endGroup();
168  }
169 }
170 
172 {
174  QString comboBox = m_Controls->m_frameRateComboBoxPolaris->currentText();
175  if (comboBox == "20 Hz") frameRate = mitk::Hz20;
176  else if (comboBox == "30 Hz") frameRate = mitk::Hz30;
177  else if (comboBox == "60 Hz") frameRate = mitk::Hz60;
178  return frameRate;
179 }
180 
182  m_Controls->m_portSpinBoxPolaris->setValue(portValue);
183 }
185  m_Controls->portTypePolaris->setCurrentIndex(portType);
186 }
187 
189 {
190  QmitkNDIPolarisWidget* clonedWidget = new QmitkNDIPolarisWidget(parent);
191  clonedWidget->Initialize();
192 
193  clonedWidget->SetPortTypeToGUI(m_Controls->portTypePolaris->currentIndex());
194  clonedWidget->SetPortValueToGUI(m_Controls->m_portSpinBoxPolaris->value());
195  clonedWidget->m_Controls->m_frameRateComboBoxPolaris->setCurrentIndex(m_Controls->m_frameRateComboBoxPolaris->currentIndex());
196  return clonedWidget;
197 }
static Pointer New()
Implementation of a configuration widget for NDI Polaris Devices.
virtual void AddOutput(std::string s)
Optional method to add output to a small screen in the trackingToolbox (see QmitkNDIPolarisWidget) ...
virtual void SetPortTypeToGUI(int portType)
itk::SmartPointer< Self > Pointer
QmitkNDIPolarisWidget(QWidget *parent=0, Qt::WindowFlags f=0)
static const std::string VIEW_ID
#define MITK_ERROR
Definition: mitkLogMacros.h:24
virtual void LoadUISettings()
Optional method to store and load settings of your widget (see QmitkNDIPolarisWidget) ...
IlluminationActivationRate
activation rate of IR illuminator for NDI Polaris tracking device
Ui::QmitkNDIPolarisWidget * m_Controls
virtual mitk::TrackingDevice::Pointer ConstructTrackingDevice()
virtual void ResetOutput()
Optional method to add output to a small screen in the trackingToolbox (see QmitkNDIPolarisWidget) ...
virtual void SetPortValueToGUI(int portValue)
virtual void StoreUISettings()
Optional method to store and load settings of your widget (see QmitkNDIPolarisWidget) ...
Abstract class of a configuration widget for NDI Devices. For implementations see NDIAuroraWidget or ...
mitk::IlluminationActivationRate GetPolarisFrameRate()
virtual void Initialize()
Subclass must implement this method to return a pointer to a copy of the object. Please don't forget ...
mitk::IPropertyPersistence * GetPersistenceService()
virtual QmitkNDIPolarisWidget * Clone(QWidget *parent) const
Subclass must implement this method to return a pointer to a copy of the object. Please don't forget ...