Medical Imaging Interaction Toolkit  2018.4.99-87d68d9f
Medical Imaging Interaction Toolkit
QmitkNDIAuroraWidget.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 
13 #include "QmitkNDIAuroraWidget.h"
14 
15 #include "mitkNDITrackingDevice.h"
17 
18 #include <QScrollBar>
19 #include <QSettings>
20 
21 const std::string QmitkNDIAuroraWidget::VIEW_ID = "org.mitk.views.NDIAuroraWidget";
22 
23 QmitkNDIAuroraWidget::QmitkNDIAuroraWidget(QWidget* parent, Qt::WindowFlags f)
24  : QmitkNDIAbstractDeviceWidget(parent, f)
25  , m_Controls(nullptr)
26 {
27 }
28 
30 {
32  CreateQtPartControl(this);
33  CreateConnections();
34 }
35 
37 {
38  delete m_Controls;
39 }
40 
41 void QmitkNDIAuroraWidget::CreateQtPartControl(QWidget *parent)
42 {
43  if (!m_Controls)
44  {
45  // create GUI widgets
46  m_Controls = new Ui::QmitkNDIAuroraWidget;
47  m_Controls->setupUi(parent);
48  }
49 }
50 
51 void QmitkNDIAuroraWidget::CreateConnections()
52 {
53  if (m_Controls)
54  {
55  connect((QObject*)(m_Controls->m_testConnectionAurora), SIGNAL(clicked()), this, SLOT(TestConnection()));
56  connect((QObject*)(m_Controls->m_AutoScanAurora), SIGNAL(clicked()), this, SLOT(AutoScanPorts()));
57  //set a few UI components depending on Windows / Linux
58 #ifdef WIN32
59  m_Controls->portTypeLabelAurora->setVisible(false);
60  m_Controls->portTypeAurora->setVisible(false);
61 #else
62  m_Controls->comPortLabelAurora->setText("Port Nr:");
63  m_Controls->m_portSpinBoxAurora->setPrefix("");
64 #endif
65  }
66 }
67 
69 {
70  m_Controls->m_outputTextAurora->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>");
71 }
72 
74 {
75  m_Controls->m_outputTextAurora->setHtml(QString(s.c_str()));
76  m_Controls->m_outputTextAurora->verticalScrollBar()->setValue(m_Controls->m_outputTextAurora->verticalScrollBar()->maximum());
77 }
78 
79 mitk::TrackingDevice::Pointer QmitkNDIAuroraWidget::GetTrackingDevice()
80 {
81  mitk::NDITrackingDevice::Pointer tempTrackingDevice = mitk::NDITrackingDevice::New();
82 
83  //get port
84  int port = 0;
85  port = m_Controls->m_portSpinBoxAurora->value();
86 
87  //build prefix (depends on linux/win)
88  QString prefix = "";
89 #ifdef WIN32
90  prefix = "COM";
91  tempTrackingDevice->SetPortNumber(static_cast<mitk::SerialCommunication::PortNumber>(port)); //also set the com port for compatibility
92 #else
93  prefix = m_Controls->portTypeAurora->currentText();
94 #endif
95 
96  //build port name string
97  QString portName = prefix + QString::number(port);
98 
99  tempTrackingDevice->SetDeviceName(portName.toStdString()); //set the port name
100  tempTrackingDevice->SetBaudRate(mitk::SerialCommunication::BaudRate115200);//set baud rate
101  tempTrackingDevice->SetType(mitk::NDIAuroraTypeInformation::GetTrackingDeviceName());
102  return static_cast<mitk::TrackingDevice::Pointer>(tempTrackingDevice);
103 }
104 
106 {
107  std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget";
108  if (this->GetPersistenceService()) // now save the settings using the persistence service
109  {
110  mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList(id);
111  propList->Set("AuroraPortWin", m_Controls->m_portSpinBoxAurora->value());
112  propList->Set("PortTypeAurora", m_Controls->portTypeAurora->currentIndex());
113  }
114  else // QSettings as a fallback if the persistence service is not available
115  {
116  QSettings settings;
117  settings.beginGroup(QString::fromStdString(id));
118  settings.setValue("portSpinBoxAurora", QVariant(m_Controls->m_portSpinBoxAurora->value()));
119  settings.setValue("portTypeAurora", QVariant(m_Controls->portTypeAurora->currentIndex()));
120  settings.endGroup();
121  }
122 }
123 
125 {
126  std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget";
127  if (this->GetPersistenceService())
128  {
129  int port = 0;
130  int portType = 0;
131  mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList(id);
132  if (propList.IsNull())
133  {
134  MITK_ERROR << "Property list for this UI (" << id << ") is not available, could not load UI settings!"; return;
135  }
136 
137  propList->Get("AuroraPortWin", port);
138  propList->Get("PortTypeAurora", portType);
139  this->SetPortTypeToGUI(portType);
140  this->SetPortValueToGUI(port);
141  }
142  else
143  {
144  // QSettings as a fallback if the persistence service is not available
145  QSettings settings;
146  settings.beginGroup(QString::fromStdString(id));
147 
148  m_Controls->m_portSpinBoxAurora->setValue(settings.value("portSpinBoxAurora", 0).toInt());
149  m_Controls->portTypeAurora->setCurrentIndex(settings.value("portTypeAurora", 0).toInt());
150 
151  settings.endGroup();
152  }
153 }
154 
156  m_Controls->m_portSpinBoxAurora->setValue(portValue);
157 }
159  m_Controls->portTypeAurora->setCurrentIndex(portType);
160 }
161 
163 {
164  QmitkNDIAuroraWidget* clonedWidget = new QmitkNDIAuroraWidget(parent);
165  clonedWidget->Initialize();
166 
167  clonedWidget->SetPortTypeToGUI(m_Controls->portTypeAurora->currentIndex());
168  clonedWidget->SetPortValueToGUI(m_Controls->m_portSpinBoxAurora->value());
169  return clonedWidget;
170 }
static Pointer New()
#define MITK_ERROR
Definition: mitkLogMacros.h:20
Ui::QmitkNDIAuroraWidget * m_Controls
void StoreUISettings() override
Optional method to store and load settings of your widget (see QmitkNDIPolarisWidget) ...
static const std::string VIEW_ID
QmitkNDIAuroraWidget(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
void AddOutput(std::string s) override
Optional method to add output to a small screen in the trackingToolbox (see QmitkNDIPolarisWidget) ...
void LoadUISettings() override
Optional method to store and load settings of your widget (see QmitkNDIPolarisWidget) ...
void Initialize() override
Subclass must implement this method to return a pointer to a copy of the object. Please don&#39;t forget ...
Abstract class of a configuration widget for NDI Devices. For implementations see NDIAuroraWidget or ...
void SetPortValueToGUI(int portValue) override
void SetPortTypeToGUI(int portType) override
mitk::IPropertyPersistence * GetPersistenceService()
mitk::TrackingDevice::Pointer GetTrackingDevice() override
QmitkNDIAuroraWidget * Clone(QWidget *parent) const override
Subclass must implement this method to return a pointer to a copy of the object. Please don&#39;t forget ...
void ResetOutput() override
Optional method to add output to a small screen in the trackingToolbox (see QmitkNDIPolarisWidget) ...
Implementation of a configuration widget for NDI Aurora Devices.