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