diff --git a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomEditor.cpp b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomEditor.cpp index b35f20d986..b1f90ae5da 100644 --- a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomEditor.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomEditor.cpp @@ -1,200 +1,238 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ 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. =========================================================================*/ // Blueberry #include #include #include #include #include #include #include #include #include "berryFileEditorInput.h" // Qmitk #include "QmitkDicomEditor.h" #include "mitkPluginActivator.h" #include //#include "mitkProgressBar.h" // Qt #include #include #include #include #include #include #include #include #include #include #include #include #include #include //CTK #include #include #include #include #include const std::string QmitkDicomEditor::EDITOR_ID = "org.mitk.editors.dicomeditor"; QmitkDicomEditor::QmitkDicomEditor() : m_Thread(new QThread()) , m_DicomDirectoryListener(new QmitkDicomDirectoryListener()) +, m_ListenerDirectory(new QString()) +, m_DatabaseDirectory(new QString()) +, m_PluginDirectory(new QString()) { } QmitkDicomEditor::~QmitkDicomEditor() { m_Thread->terminate(); delete m_Handler; delete m_Publisher; delete m_StoreSCPLauncher; delete m_Thread; delete m_DicomDirectoryListener; + delete m_ListenerDirectory; + delete m_DatabaseDirectory; + delete m_PluginDirectory; } void QmitkDicomEditor::CreateQtPartControl(QWidget *parent ) { m_Controls.setupUi( parent ); TestHandler(); - SetupDefaults(); + + SetPluginDirectory(); + SetDatabaseDirectory("DatabaseDirectory"); + SetListenerDirectory("ListenerDirectory"); + StartDicomDirectoryListener(); + StartStoreSCP(); connect(m_Controls.externalDataWidget,SIGNAL(SignalAddDicomData(const QString&)),m_Controls.internalDataWidget,SLOT(StartDicomImport(const QString&))); connect(m_Controls.externalDataWidget,SIGNAL(SignalAddDicomData(const QStringList&)),m_Controls.internalDataWidget,SLOT(StartDicomImport(const QStringList&))); connect(m_Controls.externalDataWidget,SIGNAL(SignalDicomToDataManager(const QStringList&)),this,SLOT(OnViewButtonAddToDataManager(const QStringList&))); connect(m_Controls.externalDataWidget,SIGNAL(SignalChangePage(int)), this, SLOT(OnChangePage(int))); connect(m_Controls.internalDataWidget,SIGNAL(FinishedImport(const QString&)),this,SLOT(OnDicomImportFinished(const QString&))); connect(m_Controls.internalDataWidget,SIGNAL(FinishedImport(const QStringList&)),this,SLOT(OnDicomImportFinished(const QStringList&))); connect(m_Controls.internalDataWidget,SIGNAL(SignalDicomToDataManager(const QStringList&)),this,SLOT(OnViewButtonAddToDataManager(const QStringList&))); connect(m_Controls.CDButton, SIGNAL(clicked()), m_Controls.externalDataWidget, SLOT(OnFolderCDImport())); connect(m_Controls.FolderButton, SIGNAL(clicked()), m_Controls.externalDataWidget, SLOT(OnFolderCDImport())); connect(m_Controls.QueryRetrieveButton, SIGNAL(clicked()), this, SLOT(OnQueryRetrieve())); connect(m_Controls.LocalStorageButton, SIGNAL(clicked()), this, SLOT(OnLocalStorage())); } void QmitkDicomEditor::Init(berry::IEditorSite::Pointer site, berry::IEditorInput::Pointer input) { this->SetSite(site); this->SetInput(input); } void QmitkDicomEditor::SetFocus() { } berry::IPartListener::Events::Types QmitkDicomEditor::GetPartEventTypes() const { return Events::CLOSED | Events::HIDDEN | Events::VISIBLE; } void QmitkDicomEditor::OnQueryRetrieve() { OnChangePage(2); } void QmitkDicomEditor::OnLocalStorage() { OnChangePage(0); } void QmitkDicomEditor::OnChangePage(int page) { try{ m_Controls.stackedWidget->setCurrentIndex(page); }catch(std::exception e){ MITK_ERROR <<"error: "<< e.what(); return; } } void QmitkDicomEditor::OnDicomImportFinished(const QString& path) { } void QmitkDicomEditor::OnDicomImportFinished(const QStringList& path) { } -void QmitkDicomEditor::StartDicomDirectoryListener(QString& directory) +void QmitkDicomEditor::StartDicomDirectoryListener() { - m_DicomDirectoryListener->SetDicomListenerDirectory(directory); + if(!m_Thread->isRunning()) + { + m_DicomDirectoryListener->SetDicomListenerDirectory(*m_ListenerDirectory); connect(m_DicomDirectoryListener,SIGNAL(SignalAddDicomData(const QStringList&)),m_Controls.internalDataWidget,SLOT(StartDicomImport(const QStringList&)),Qt::DirectConnection); connect(m_Controls.internalDataWidget,SIGNAL(FinishedImport(const QStringList&)),m_DicomDirectoryListener,SLOT(OnDicomImportFinished(const QStringList&)),Qt::DirectConnection); m_DicomDirectoryListener->moveToThread(m_Thread); - m_Thread->start(); -} - -void QmitkDicomEditor::SetupDefaults() -{ - QString pluginDirectory; - mitk::PluginActivator::getContext()->getDataFile(pluginDirectory); - pluginDirectory.append("/"); - QString databaseDirectory; - databaseDirectory.append(pluginDirectory); - databaseDirectory.append(QString("DICOMDatabaseDirectory")); - QDir tmp(databaseDirectory); - tmp.mkpath(databaseDirectory); - m_Controls.internalDataWidget->SetDatabaseDirectory(databaseDirectory); - QString listenerDirectory; - listenerDirectory.append(pluginDirectory); - listenerDirectory.append("DICOMListenerDirectory"); - StartDicomDirectoryListener(listenerDirectory); - QmitkStoreSCPLauncherBuilder builder; - std::string storagePort = m_Controls.m_ctkDICOMQueryRetrieveWidget->getServerParameters()["StoragePort"].toString().toStdString(); - std::string storageAET = m_Controls.m_ctkDICOMQueryRetrieveWidget->getServerParameters()["StorageAETitle"].toString().toStdString(); - MITK_INFO << storagePort; - MITK_INFO << storageAET; - builder.AddPort()->AddTransferSyntax()->AddOtherNetworkOptions()->AddMode()->AddOutputDirectory(listenerDirectory); - m_StoreSCPLauncher = new QmitkStoreSCPLauncher(&builder); - m_StoreSCPLauncher->StartStoreSCP(); + m_Thread->start(); + } } //TODO Remove void QmitkDicomEditor::TestHandler() { - m_Handler = new DicomEventHandler(); - m_Handler->SubscribeSlots(); + m_Handler = new DicomEventHandler(); + m_Handler->SubscribeSlots(); } void QmitkDicomEditor::OnViewButtonAddToDataManager(const QStringList& eventProperties) { ctkDictionary properties; properties["PatientName"] = eventProperties.at(0); properties["StudyUID"] = eventProperties.at(1); properties["StudyName"] = eventProperties.at(2); properties["SeriesUID"] = eventProperties.at(3); properties["SeriesName"] = eventProperties.at(4); properties["Path"] = eventProperties.at(5); m_Publisher = new QmitkDicomDataEventPublisher(); m_Publisher->PublishSignals(mitk::PluginActivator::getContext()); m_Publisher->AddSeriesToDataManagerEvent(properties); +} + + +void QmitkDicomEditor::StartStoreSCP() +{ + QmitkStoreSCPLauncherBuilder builder; + QString storagePort = m_Controls.m_ctkDICOMQueryRetrieveWidget->getServerParameters()["StoragePort"].toString(); + QString storageAET = m_Controls.m_ctkDICOMQueryRetrieveWidget->getServerParameters()["StorageAETitle"].toString(); + MITK_INFO << storagePort.toStdString(); + MITK_INFO << storageAET.toStdString(); + builder.AddPort(storagePort)->AddAETitle(storageAET)->AddTransferSyntax()->AddOtherNetworkOptions()->AddMode()->AddOutputDirectory(*m_ListenerDirectory); + m_StoreSCPLauncher = new QmitkStoreSCPLauncher(&builder); + m_StoreSCPLauncher->StartStoreSCP(); +} + + +void QmitkDicomEditor::StopStoreSCP() +{ + if(m_StoreSCPLauncher) + { + delete m_StoreSCPLauncher; + } +} + +void QmitkDicomEditor::UpdateStartStoreSCP() +{ + StopStoreSCP(); + StartStoreSCP(); +} + +void QmitkDicomEditor::SetPluginDirectory() +{ + mitk::PluginActivator::getContext()->getDataFile(*m_PluginDirectory); + m_PluginDirectory->append("/"); +} + +void QmitkDicomEditor::SetDatabaseDirectory(const QString& databaseDirectory) +{ + m_DatabaseDirectory->clear(); + m_DatabaseDirectory->append(m_PluginDirectory); + m_DatabaseDirectory->append(databaseDirectory); + m_Controls.internalDataWidget->SetDatabaseDirectory(*m_DatabaseDirectory); +} + +void QmitkDicomEditor::SetListenerDirectory(const QString& listenerDirectory) +{ + m_ListenerDirectory->clear(); + m_ListenerDirectory->append(m_PluginDirectory); + m_ListenerDirectory->append(listenerDirectory); } \ No newline at end of file diff --git a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomEditor.h b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomEditor.h index af8bc2d284..5e1b720471 100644 --- a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomEditor.h +++ b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomEditor.h @@ -1,128 +1,139 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ 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 QmitkDicomEditor_h #define QmitkDicomEditor_h #include #include #include #include "ui_QmitkDicomEditorControls.h" #include "QmitkDicomDirectoryListener.h" #include "QmitkStoreSCPLauncher.h" #include "QmitkStoreSCPLauncherBuilder.h" #include "DicomEventHandler.h" #include "QmitkDicomDataEventPublisher.h" #include #include #include #include #include #include #include #include #include #include /*! \brief QmitkDicomEditor \warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation. \sa QmitkFunctionality \ingroup ${plugin_target}_internal */ class DICOM_EXPORT QmitkDicomEditor : public berry::QtEditorPart, virtual public berry::IPartListener { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: berryObjectMacro(QmitkDicomEditor); static const std::string EDITOR_ID; QmitkDicomEditor(); QmitkDicomEditor(const QmitkDicomEditor& other) { Q_UNUSED(other) throw std::runtime_error("Copy constructor not implemented"); } virtual ~QmitkDicomEditor(); void Init(berry::IEditorSite::Pointer site, berry::IEditorInput::Pointer input); void SetFocus(); void DoSave() {} void DoSaveAs() {} bool IsDirty() const { return false; } bool IsSaveAsAllowed() const { return false; } - + signals: protected slots: + /// \brief Called when StoreSCP shold be started or updated + void UpdateStartStoreSCP(); + /// \brief Called when import is finished void OnDicomImportFinished(const QString& path); /// \brief Called when import is finished void OnDicomImportFinished(const QStringList& path); /// \brief Called when Query Retrieve or Import Folder was clicked. void OnQueryRetrieve(); /// \brief Called when LocalStorageButton was clicked. void OnLocalStorage(); /// \brief Called when view button is clicked. Sends out an event for adding the current selected file to the mitkDataStorage. void OnViewButtonAddToDataManager(const QStringList& eventProperties); - void StartDicomDirectoryListener(QString& directory); + void StartDicomDirectoryListener(); void OnChangePage(int); - /// To be called when an entry of the tree list is collapsed - //void OnTreeCollapsed(const QModelIndex& index); - - /// To be called when an entry of the tree list is expanded - //void OnTreeExpanded(const QModelIndex& index); void TestHandler(); + void SetDatabaseDirectory(const QString& databaseDirectory); + + void SetListenerDirectory(const QString& listenerDirectory); + protected: + /// \brief Called when StoreSCP shold start + void StartStoreSCP(); + + /// \brief Called when StoreSCP should stop + void StopStoreSCP(); + void CreateQtPartControl(QWidget *parent); - void SetupDefaults(); + void QmitkDicomEditor::SetPluginDirectory(); Events::Types GetPartEventTypes() const; Ui::QmitkDicomEditorControls m_Controls; QThread* m_Thread; QmitkDicomDirectoryListener* m_DicomDirectoryListener; QmitkStoreSCPLauncher* m_StoreSCPLauncher; DicomEventHandler* m_Handler; QmitkDicomDataEventPublisher* m_Publisher; - + QString* m_PluginDirectory; + QString* m_ListenerDirectory; + QString* m_DatabaseDirectory; + }; #endif // QmitkDicomEditor_h