diff --git a/Modules/IGTUI/Qmitk/QmitkIGTLoggerWidget.cpp b/Modules/IGTUI/Qmitk/QmitkIGTLoggerWidget.cpp index 3151032bfb..ee5cdf310e 100644 --- a/Modules/IGTUI/Qmitk/QmitkIGTLoggerWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkIGTLoggerWidget.cpp @@ -1,295 +1,298 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-12 19:14:45 +0200 (Di, 12 Mai 2009) $ Version: $Revision: 1.12 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkIGTLoggerWidget.h" //mitk headers #include "mitkTrackingTypes.h" #include #include #include #include #include #include #include #include +//itk headers #include //qt headers #include #include #include QmitkIGTLoggerWidget::QmitkIGTLoggerWidget(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f), m_Recorder(NULL), m_RecordingActivated(false) { m_Controls = NULL; CreateQtPartControl(this); CreateConnections(); //set output file this->SetOutputFileName(); //update milliseconds and samples this->SetDefaultRecordingSettings(); } QmitkIGTLoggerWidget::~QmitkIGTLoggerWidget() { m_RecordingTimer->stop(); m_Recorder = NULL; m_RecordingTimer = NULL; } void QmitkIGTLoggerWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkIGTLoggerWidgetControls; m_Controls->setupUi(parent); m_RecordingTimer = new QTimer(this); } } void QmitkIGTLoggerWidget::CreateConnections() { if ( m_Controls ) { connect( (QObject*)(m_Controls->m_pbLoadDir), SIGNAL(clicked()), this, SLOT(OnChangePressed()) ); connect( (QObject*)(m_Controls->m_pbStartRecording), SIGNAL(clicked(bool)), this, SLOT(OnStartRecording(bool)) ); connect( m_RecordingTimer, SIGNAL(timeout()), this, SLOT(OnRecording()) ); connect( (QObject*)(m_Controls->m_leRecordingValue), SIGNAL(editingFinished()), this, SLOT(UpdateRecordingTime()) ); connect( (QObject*)(m_Controls->m_cbRecordingType), SIGNAL(activated(int)), this, SLOT(UpdateRecordingTime()) ); connect( (QObject*)(m_Controls->m_leOutputFile), SIGNAL(editingFinished()), this, SLOT(UpdateOutputFileName()) ); } } void QmitkIGTLoggerWidget::SetDataStorage(mitk::DataStorage* dataStorage) { m_DataStorage = dataStorage; } void QmitkIGTLoggerWidget::OnStartRecording(bool recording) { if (m_Recorder.IsNull()) { QMessageBox::warning(NULL, "Warning", QString("Please start tracking before recording!")); return; } if (m_CmpFilename.isEmpty()) { QMessageBox::warning(NULL, "Warning", QString("Please specify filename!")); return; } if(recording) { - if (!m_RecordingActivated) - { - m_Recorder->SetFileName(m_CmpFilename.toStdString()); - - try - { /*start the recording mechanism */ - m_Recorder->StartRecording(); - m_RecordingTimer->start(50); //now every update of the recorder stores one line into the file for each added NavigationData - mitk::StatusBar::GetInstance()->DisplayText("Recording tracking data now"); // Display recording message for 75ms in status bar + if (!m_RecordingActivated) + { + m_Recorder->SetFileName(m_CmpFilename.toStdString()); + + try + { /*start the recording mechanism */ + m_Recorder->StartRecording(); + m_RecordingTimer->start(50); //now every update of the recorder stores one line into the file for each added NavigationData + mitk::StatusBar::GetInstance()->DisplayText("Recording tracking data now"); // Display recording message for 75ms in status bar + + emit SignalRecordingStarted(); + } + catch (std::exception& e) + { + QMessageBox::warning(NULL, "IGT-Tracking Logger: Error", QString("Error while recording tracking data: %1").arg(e.what())); + mitk::StatusBar::GetInstance()->DisplayText(""); // Display recording message for 75ms in status bar + } + m_Controls->m_pbStartRecording->setText("Stop recording"); + m_Controls->m_leRecordingValue->setEnabled(false); + m_Controls->m_cbRecordingType->setEnabled(false); + + m_RecordingActivated = true; + + if(m_Controls->m_cbRecordingType->currentIndex()==0) + { + bool success = false; + QString str_ms = m_Controls->m_leRecordingValue->text(); + int int_ms = str_ms.toInt(&success); + if (success) + QTimer::singleShot(int_ms, this, SLOT(StopRecording())); + } } - catch (std::exception& e) - { - QMessageBox::warning(NULL, "IGT-Tracking Logger: Error", QString("Error while recording tracking data: %1").arg(e.what())); - mitk::StatusBar::GetInstance()->DisplayText(""); // Display recording message for 75ms in status bar + else + { + this->StopRecording(); } - m_Controls->m_pbStartRecording->setText("Stop recording"); - m_Controls->m_leRecordingValue->setEnabled(false); - m_Controls->m_cbRecordingType->setEnabled(false); - - m_RecordingActivated = true; - - if(m_Controls->m_cbRecordingType->currentIndex()==0) - { - bool success = false; - QString str_ms = m_Controls->m_leRecordingValue->text(); - int int_ms = str_ms.toInt(&success); - if (success) - QTimer::singleShot(int_ms, this, SLOT(StopRecording())); - } - } - else - { - this->StopRecording(); - } } else { this->StopRecording(); m_Controls->m_pbStartRecording->setChecked(false); } } void QmitkIGTLoggerWidget::StopRecording() { m_RecordingTimer->stop(); m_Recorder->StopRecording(); mitk::StatusBar::GetInstance()->DisplayText("Recording STOPPED", 2000); // Display message for 2s in status bar m_Controls->m_pbStartRecording->setText("Start recording"); m_Controls->m_pbStartRecording->setChecked(false); m_Controls->m_leRecordingValue->setEnabled(true); m_Controls->m_cbRecordingType->setEnabled(true); m_RecordingActivated = false; - + emit SignalRecordingStopped(); } void QmitkIGTLoggerWidget::OnRecording() { static unsigned int sampleCounter = 0; unsigned int int_samples = m_Samples.toInt(); if(sampleCounter >= int_samples) { this->StopRecording(); sampleCounter=0; return; } m_Recorder->Update(); if (m_Controls->m_cbRecordingType->currentIndex()==1) sampleCounter++; } void QmitkIGTLoggerWidget::OnChangePressed() { QString oldName = m_CmpFilename; m_CmpFilename.clear(); m_CmpFilename = QFileDialog::getSaveFileName( QApplication::activeWindow() , "Save tracking data", "IGT_Tracking_Data.xml", "XML files (*.xml)" ); if (m_CmpFilename.isEmpty())//if something went wrong or user pressed cancel in the save dialog { m_CmpFilename=oldName; } m_Controls->m_leOutputFile->setText(m_CmpFilename); } void QmitkIGTLoggerWidget::UpdateOutputFileName() { QString oldName = m_CmpFilename; m_CmpFilename.clear(); m_CmpFilename = m_Controls->m_leOutputFile->text(); if (m_CmpFilename.isEmpty()) { QMessageBox::warning(NULL, "Warning", QString("Please enter valid path! Using previous path again.")); m_CmpFilename=oldName; m_Controls->m_leOutputFile->setText(m_CmpFilename); } } void QmitkIGTLoggerWidget::SetRecorder( mitk::NavigationDataRecorder::Pointer recorder ) { m_Recorder = recorder; } void QmitkIGTLoggerWidget::UpdateRecordingTime() { // milliseconds selected in the combobox if (m_Controls->m_cbRecordingType->currentIndex()==0) { m_MilliSeconds = m_Controls->m_leRecordingValue->text(); if(m_MilliSeconds.compare("infinite")==0) { this->SetDefaultRecordingSettings(); } bool success = false; m_MilliSeconds.toInt(&success); if (!success) { QMessageBox::warning(NULL, "Warning", QString("Please enter a number!")); this->SetDefaultRecordingSettings(); return; } } else if(m_Controls->m_cbRecordingType->currentIndex()==1) // #samples selected in the combobox { m_Samples = m_Controls->m_leRecordingValue->text(); if(m_Samples.compare("infinite")==0) { this->SetDefaultRecordingSettings(); } bool success = false; m_Samples.toInt(&success); if (!success) { QMessageBox::warning(NULL, "Warning", QString("Please enter a number!")); this->SetDefaultRecordingSettings(); return; } } else if (m_Controls->m_cbRecordingType->currentIndex()==2)// infinite selected in the combobox { // U+221E unicode symbole for infinite QString infinite("infinite"); m_Controls->m_leRecordingValue->setText(infinite); } // m_Controls->m_leSamples->setText(QString::number(samples)); } void QmitkIGTLoggerWidget::SetDefaultRecordingSettings() { m_Controls->m_leRecordingValue->setText("2000"); m_Controls->m_cbRecordingType->setCurrentIndex(0); m_Samples="100"; m_MilliSeconds="2000"; } void QmitkIGTLoggerWidget::SetOutputFileName() { std::string tmpDir = itksys::SystemTools::GetCurrentWorkingDirectory(); QString dir = QString(tmpDir.c_str()); QString filename = "IGT_Tracking_Data.xml"; m_CmpFilename.append(dir); if(dir.isEmpty()) { QMessageBox::warning(NULL, "Warning", QString("Could not load current working directory")); return; } if(dir.endsWith("/")||dir.endsWith("\\")) { m_CmpFilename.append(filename); } else { m_CmpFilename.append("/"); m_CmpFilename.append(filename); } m_Controls->m_leOutputFile->setText(m_CmpFilename); } diff --git a/Modules/IGTUI/Qmitk/QmitkIGTLoggerWidget.h b/Modules/IGTUI/Qmitk/QmitkIGTLoggerWidget.h index b97853c72d..e2528fe552 100644 --- a/Modules/IGTUI/Qmitk/QmitkIGTLoggerWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkIGTLoggerWidget.h @@ -1,86 +1,91 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-12 19:14:45 +0200 (Di, 12 Mai 2009) $ Version: $Revision: 1.12 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef QmitkIGTLoggerWidget_H #define QmitkIGTLoggerWidget_H //QT headers #include //mitk headers #include "MitkIGTUIExports.h" #include "mitkNavigationTool.h" #include #include "mitkNavigationDataRecorder.h" //ui header #include "ui_QmitkIGTLoggerWidgetControls.h" + /** Documentation: * \brief GUI to access the IGT recorder. * User can specify the file name where the output shall be stored and * how long the recording shall be performed. * * \ingroup IGTUI */ class MitkIGTUI_EXPORT QmitkIGTLoggerWidget : public QWidget { Q_OBJECT public: static const std::string VIEW_ID; QmitkIGTLoggerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkIGTLoggerWidget(); void SetDataStorage(mitk::DataStorage* dataStorage); void SetRecorder(mitk::NavigationDataRecorder::Pointer recorder); + signals: + void SignalRecordingStarted(); + void SignalRecordingStopped(); + protected slots: void OnChangePressed(); void OnStartRecording(bool recording); void OnRecording(); void UpdateRecordingTime(); void StopRecording(); void UpdateOutputFileName(); protected: /// \brief Creation of the connections virtual void CreateConnections(); virtual void CreateQtPartControl(QWidget *parent); void SetDefaultRecordingSettings(); void SetOutputFileName(); Ui::QmitkIGTLoggerWidgetControls* m_Controls; /** @brief holds the DataStorage */ mitk::DataStorage::Pointer m_DataStorage; mitk::NavigationDataRecorder::Pointer m_Recorder; ///< records NDs to a XML file QString m_CmpFilename; QString m_Dir; QTimer* m_RecordingTimer; QString m_MilliSeconds; QString m_Samples; bool m_RecordingActivated; }; #endif \ No newline at end of file