Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkMicronTrackerWidget.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 #include <QFileDialog>
16 #include <QScrollBar>
17 
19 
20 #include <itksys/SystemTools.hxx>
21 #include <Poco/Path.h>
22 #include <QSettings>
23 
24 #include <QmitkIGTCommonHelper.h>
25 
26 const std::string QmitkMicronTrackerWidget::VIEW_ID = "org.mitk.views.NDIMicronTrackerWidget";
27 
28 QmitkMicronTrackerWidget::QmitkMicronTrackerWidget(QWidget* parent, Qt::WindowFlags f)
30  , m_Controls(nullptr)
31 {
32 }
33 
35 {
37  CreateQtPartControl(this);
38  CreateConnections();
40 }
41 
43 {
44  delete m_Controls;
45 }
46 
47 void QmitkMicronTrackerWidget::CreateQtPartControl(QWidget *parent)
48 {
49  if (!m_Controls)
50  {
51  // create GUI widgets
52  m_Controls = new Ui::QmitkMicronTrackerWidget;
53  m_Controls->setupUi(parent);
54  }
55 }
56 
57 void QmitkMicronTrackerWidget::CreateConnections()
58 {
59  if (m_Controls)
60  {
61  connect((QObject*)(m_Controls->m_testConnectionMicronTracker), SIGNAL(clicked()), this, SLOT(TestConnection()));
62  connect((QObject*)(m_Controls->m_SetMTCalibrationFile), SIGNAL(clicked()), this, SLOT(SetMTCalibrationFileClicked()));
63  }
64 }
65 
67 {
68  m_Controls->m_outputTextMicronTracker->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>");
69 }
70 
72 {
73  m_Controls->m_outputTextMicronTracker->setHtml(QString(s.c_str()));
74  m_Controls->m_outputTextMicronTracker->verticalScrollBar()->setValue(m_Controls->m_outputTextMicronTracker->verticalScrollBar()->maximum());
75 }
76 
77 mitk::TrackingDevice::Pointer QmitkMicronTrackerWidget::GetTrackingDevice()
78 {
79  mitk::ClaronTrackingDevice::Pointer newDevice = mitk::ClaronTrackingDevice::New();
80  if (this->m_MTCalibrationFile.empty()) //if configuration file for MicronTracker is empty: load default
81  {
82  mitk::ClaronTrackingDevice::Pointer tempDevice = mitk::ClaronTrackingDevice::New();
83  m_MTCalibrationFile = tempDevice->GetCalibrationDir();
84  Poco::Path myPath = Poco::Path(m_MTCalibrationFile.c_str());
85  m_Controls->m_MTCalibrationFile->setText("Calibration File: " + QString(myPath.getFileName().c_str()));
86  }
87  if (!this->m_MTCalibrationFile.empty())
88  {
89  //extract path from calibration file and set the calibration dir of the device
90  std::string path = itksys::SystemTools::GetFilenamePath(m_MTCalibrationFile);
91  newDevice->SetCalibrationDir(path);
92  }
93  else
94  AddOutput("<br>Warning: Calibration file is not set!");
95  return static_cast<mitk::TrackingDevice::Pointer>(newDevice);
96 }
97 
99 {
100  std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget";
101  if (this->GetPersistenceService()) // now save the settings using the persistence service
102  {
103  mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList(id);
104  propList->Set("MTCalibrationFile", m_MTCalibrationFile);
105  }
106  else // QSettings as a fallback if the persistence service is not available
107  {
108  QSettings settings;
109  settings.beginGroup(QString::fromStdString(id));
110  settings.setValue("mTCalibrationFile", QVariant(QString::fromStdString(m_MTCalibrationFile)));
111  settings.endGroup();
112  }
113 }
114 
116 {
117  std::string id = "org.mitk.modules.igt.ui.trackingdeviceconfigurationwidget";
118 
119  if (this->GetPersistenceService())
120  {
121  mitk::PropertyList::Pointer propList = this->GetPersistenceService()->GetPropertyList(id);
122  if (propList.IsNull())
123  {
124  MITK_ERROR << "Property list for this UI (" << id << ") is not available, could not load UI settings!"; return;
125  }
126 
127  propList->Get("MTCalibrationFile", m_MTCalibrationFile);
128  }
129  else
130  {
131  // QSettings as a fallback if the persistence service is not available
132  QSettings settings;
133  settings.beginGroup(QString::fromStdString(id));
134  m_MTCalibrationFile = settings.value("mTCalibrationFile", "").toString().toStdString();
135 
136  settings.endGroup();
137  }
138  m_Controls->m_MTCalibrationFile->setText("Calibration File: " + QString::fromStdString(m_MTCalibrationFile));
139 }
140 
142 {
143  return mitk::ClaronTrackingDevice::New()->IsDeviceInstalled();
144 }
145 
147 {
148  std::string filename = QFileDialog::getOpenFileName(nullptr, tr("Open Calibration File"), QmitkIGTCommonHelper::GetLastFileLoadPath(), "*.*").toLatin1().data();
149  if (filename == "") { return; }
150  else
151  {
152  QmitkIGTCommonHelper::SetLastFileLoadPathByFileName(QString::fromStdString(filename));
153  m_MTCalibrationFile = filename;
154  Poco::Path myPath = Poco::Path(m_MTCalibrationFile.c_str());
155  m_Controls->m_MTCalibrationFile->setText("Calibration File: " + QString(myPath.getFileName().c_str()));
156  }
157 }
158 
160 {
161  QmitkMicronTrackerWidget* clonedWidget = new QmitkMicronTrackerWidget(parent);
162  clonedWidget->Initialize();
164  m_Controls->m_MTCalibrationFile->setText("Calibration File: " + QString::fromStdString(m_MTCalibrationFile));
165 
166  return clonedWidget;
167 }
static const QString GetLastFileLoadPath()
static const std::string VIEW_ID
#define MITK_ERROR
Definition: mitkLogMacros.h:20
static void SetLastFileLoadPathByFileName(const QString &str)
void Initialize() override
Subclass must implement this method to return a pointer to a copy of the object. Please don&#39;t forget ...
void AddOutput(std::string s) override
Optional method to add output to a small screen in the trackingToolbox (see QmitkNDIPolarisWidget) ...
QmitkMicronTrackerWidget * 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 LoadUISettings() override
Optional method to store and load settings of your widget (see QmitkNDIPolarisWidget) ...
Ui::QmitkMicronTrackerWidget * m_Controls
void StoreUISettings() override
Optional method to store and load settings of your widget (see QmitkNDIPolarisWidget) ...
Implementation of a configuration widget for Micron Tracking Devices.
mitk::TrackingDevice::Pointer GetTrackingDevice() override
void ResetOutput() override
Optional method to add output to a small screen in the trackingToolbox (see QmitkNDIPolarisWidget) ...
PERSISTENCE_GET_SERVICE_METHOD_MACRO void InitializeSuperclassWidget()
QmitkMicronTrackerWidget(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
Abstract class to configure a tracking device. Inherited widgets should be registered in the Microser...
mitk::IPropertyPersistence * GetPersistenceService()
bool IsDeviceInstalled() override
Optional method to investigate if drivers etc for your device are installed. The default value is "tr...