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