diff --git a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/DicomEventHandler.cpp b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/DicomEventHandler.cpp index 0edd173a96..b6d722be6d 100644 --- a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/DicomEventHandler.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/DicomEventHandler.cpp @@ -1,50 +1,76 @@ /*========================================================================= 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. =========================================================================*/ +#include "mitkPluginActivator.h" #include "DicomEventHandler.h" #include #include #include +#include +#include +#include +#include +#include +#include +#include + DicomEventHandler::DicomEventHandler() { } DicomEventHandler::~DicomEventHandler() { } -void DicomEventHandler::handleEvent(const ctkEvent& ctkEvent) +void DicomEventHandler::OnSignalAddSeriesToDataManager(const ctkEvent& ctkEvent) { - MITK_INFO << "I'll handle your event:" << ctkEvent.getProperty("title").toString().toStdString(); + mitk::DicomSeriesReader::UidFileNamesMap dicomSeriesMap = mitk::DicomSeriesReader::GetSeries(ctkEvent.getProperty("Path").toString().toStdString()); + mitk::DataNode::Pointer node = mitk::DicomSeriesReader::LoadDicomSeries(dicomSeriesMap[ctkEvent.getProperty("SeriesUID").toString().toStdString()]); + if (node.IsNull()) + { + MITK_ERROR << "Could not load series: " << ctkEvent.getProperty("SeriesUID").toString().toStdString(); + } + else + { + node->SetName(ctkEvent.getProperty("SeriesUID").toString().toStdString()); + ctkServiceReference serviceReference =mitk::PluginActivator::getContext()->getServiceReference(); + mitk::IDataStorageService* storageService = mitk::PluginActivator::getContext()->getService(serviceReference); + storageService->GetActiveDataStorage().GetPointer()->GetDataStorage()->Add(node); + mitk::RenderingManager::GetInstance()->SetDataStorage(storageService->GetActiveDataStorage().GetPointer()->GetDataStorage()); + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + + } } -void DicomEventHandler::Register(QString eventTopic, QString filter) +void DicomEventHandler::OnSignalRemoveSeriesFromStorage(const ctkEvent& ctkEvent) { - ctkDictionary properties; - properties[ctkEventConstants::EVENT_TOPIC] = eventTopic; - if(!filter.isEmpty()) - { - properties[ctkEventConstants::EVENT_FILTER] = filter; - } - m_PluginContext->registerService(this, properties); } -void DicomEventHandler::SetPluginContext(ctkPluginContext* context) +void DicomEventHandler::SubscribeSlots() { - m_PluginContext = context; + ctkServiceReference ref = mitk::PluginActivator::getContext()->getServiceReference(); + if (ref) + { + ctkEventAdmin* eventAdmin = mitk::PluginActivator::getContext()->getService(ref); + ctkDictionary properties; + properties[ctkEventConstants::EVENT_TOPIC] = "org/mitk/gui/qt/dicom/ADD"; + eventAdmin->subscribeSlot(this, SLOT(OnSignalAddSeriesToDataManager(ctkEvent)), properties); + properties[ctkEventConstants::EVENT_TOPIC] = "org/mitk/gui/qt/dicom/DELETED"; + eventAdmin->subscribeSlot(this, SLOT(OnSignalRemoveSeriesFromStorage(ctkEvent)), properties); + } } \ No newline at end of file diff --git a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/DicomEventHandler.h b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/DicomEventHandler.h index 27b1db0d76..17127d18cd 100644 --- a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/DicomEventHandler.h +++ b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/DicomEventHandler.h @@ -1,53 +1,42 @@ /*========================================================================= 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 DicomEventHandler_h #define DicomEventHandler_h #include -#include -#include #include -#include -class DicomEventHandler : public QObject, public ctkEventHandler +class DicomEventHandler : public QObject { Q_OBJECT - Q_INTERFACES(ctkEventHandler) public: DicomEventHandler(); virtual ~DicomEventHandler(); - void handleEvent(const ctkEvent& ctkEvent); + void SubscribeSlots(); - /*! - \brief Registers the dicom event handler with its topic as a service - \param eventTopic the specific topic which will be handeled - \param filter you can filter events e.g. if you pass "(title=samplereport)" only events with a title samplereport will be processed. - */ - void Register(QString eventTopic, QString filter = QString()); + public slots: - void SetPluginContext(ctkPluginContext* context); + void OnSignalAddSeriesToDataManager(const ctkEvent& ctkEvent); - private: - - ctkPluginContext* m_PluginContext; + void OnSignalRemoveSeriesFromStorage(const ctkEvent& ctkEvent); }; #endif // QmitkDicomEventHandlerBuilder_h \ No newline at end of file diff --git a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomDataEventPublisher.cpp b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomDataEventPublisher.cpp index 1961612b1a..434d32dfe8 100644 --- a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomDataEventPublisher.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomDataEventPublisher.cpp @@ -1,51 +1,55 @@ /*========================================================================= 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. =========================================================================*/ #include "QmitkDicomDataEventPublisher.h" +#include +#include +#include + QmitkDicomDataEventPublisher::QmitkDicomDataEventPublisher() { } QmitkDicomDataEventPublisher::~QmitkDicomDataEventPublisher() { - delete m_EventAdmin; } -void QmitkDicomDataEventPublisher::SendEvent(const ctkEvent& ctkEvent,bool synchronously) +void QmitkDicomDataEventPublisher::AddSeriesToDataManagerEvent(const ctkDictionary& properties) { - if(synchronously) - { - m_EventAdmin->sendEvent(ctkEvent); - }else{ - m_EventAdmin->postEvent(ctkEvent); - } + emit SignalAddSeriesToDataManager(properties); } -void QmitkDicomDataEventPublisher::SetEventAdmin(ctkPluginContext* context) +void QmitkDicomDataEventPublisher::RemoveSeriesFromStorageEvent(const ctkDictionary& properties) { - SetServiceReference(context); - if(m_ServiceReference) - { - m_EventAdmin = context->getService(m_ServiceReference); - } + emit SignalRemoveSeriesFromStorage(properties); } -void QmitkDicomDataEventPublisher::SetServiceReference(ctkPluginContext* context) +void QmitkDicomDataEventPublisher::PublishSignals(ctkPluginContext* context) { - m_ServiceReference = context->getServiceReference(); + ctkServiceReference ref = context->getServiceReference(); + if (ref) + { + ctkEventAdmin* eventAdmin = context->getService(ref); + // Using Qt::DirectConnection is equivalent to ctkEventAdmin::sendEvent() + eventAdmin->publishSignal(this, SIGNAL(SignalAddSeriesToDataManager(ctkDictionary)), + "org/mitk/gui/qt/dicom/ADD"); + + eventAdmin->publishSignal(this, SIGNAL(SignalAddSeriesToDataManager(ctkDictionary)), + "org/mitk/gui/qt/dicom/DELETED"); + } } \ No newline at end of file diff --git a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomDataEventPublisher.h b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomDataEventPublisher.h index b9a867d37b..6ec7d2be10 100644 --- a/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomDataEventPublisher.h +++ b/Modules/Bundles/org.mitk.gui.qt.dicom/src/internal/QmitkDicomDataEventPublisher.h @@ -1,50 +1,46 @@ /*========================================================================= 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 QmitkDicomDataEventPublisher_H #define QmitkDicomDataEventPublisher_H -#include #include -#include -#include +#include -class QmitkDicomDataEventPublisher +class QmitkDicomDataEventPublisher : public QObject { + Q_OBJECT public: QmitkDicomDataEventPublisher(); virtual ~QmitkDicomDataEventPublisher(); - /// @brief sends an ctkEvent default asynchronously - void SendEvent(const ctkEvent& ctkEvent, bool synchronously = false ); - /// @brief sets the event admin from given plugin context - void SetEventAdmin(ctkPluginContext* context); - - private: + void PublishSignals(ctkPluginContext* context); + + void AddSeriesToDataManagerEvent(const ctkDictionary& properties); - /// @brief sets the service reference from given plugin context - void SetServiceReference(ctkPluginContext* context); + void RemoveSeriesFromStorageEvent(const ctkDictionary& properties); - ctkServiceReference m_ServiceReference; - ctkEventAdmin* m_EventAdmin; + signals: + void SignalAddSeriesToDataManager(const ctkDictionary&); + void SignalRemoveSeriesFromStorage(const ctkDictionary&); }; #endif // QmitkDicomDataEventPublisher_H \ No newline at end of file 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 ace6b8c23d..a53953b522 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,235 +1,191 @@ /*========================================================================= 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()) { } QmitkDicomEditor::~QmitkDicomEditor() { m_Thread->terminate(); delete m_Handler; delete m_Publisher; delete m_StoreSCPLauncher; delete m_Thread; delete m_DicomDirectoryListener; } void QmitkDicomEditor::CreateQtPartControl(QWidget *parent ) { m_Controls.setupUi( parent ); TestHandler(); SetupDefaults(); + 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(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())); - connect(m_Controls.externalDataWidget,SIGNAL(SignalChangePage(int)), this, SLOT(OnChangePage(int))); -} - -void QmitkDicomEditor::OnSeriesModelDoubleClicked(QModelIndex index){ - QModelIndex studyIndex = index.parent(); - QModelIndex seriesIndex = index; - - //ctkDICOMModel* model = const_cast(qobject_cast(index.model())); - - //if(model) - //{ - // model->fetchMore(seriesIndex); - - // int imageCount = model->rowCount(seriesIndex); - - // MITK_INFO<< "Series Index:"<< imageCount << "\n"; - - // QString filePath = m_Controls.m_ctkDICOMAppWidget->databaseDirectory() + - // "/dicom/" + model->data(studyIndex ,ctkDICOMModel::UIDRole).toString() + "/"; - - // MITK_INFO << "filepath: "<< filePath.toStdString() << "\n"; - - // QString series_uid = model->data(seriesIndex ,ctkDICOMModel::UIDRole).toString(); - - // MITK_INFO << "series_uid: " << series_uid.toStdString() << "\n"; - - // if(QFile(filePath).exists()) - // { - // filePath.replace(0,1,""); - // QString absolutFilePath("C:/home/bauerm/bin/MITK/MITK-build/Applications/ExtApp/ctkDICOM-Database/dicom/"); - // absolutFilePath.append(model->data(studyIndex ,ctkDICOMModel::UIDRole).toString()); - // absolutFilePath.append("/"); - // //add all fienames from series to strin container - // mitk::DicomSeriesReader::StringContainer names = mitk::DicomSeriesReader::GetSeries(absolutFilePath.toStdString(),series_uid.toStdString()); - // mitk::DataNode::Pointer node = mitk::DicomSeriesReader::LoadDicomSeries(names, true, true); - - // if (node.IsNull()) - // { - // MITK_ERROR << "Could not load series: " << series_uid.toStdString(); - // } - // else - // { - // node->SetName(series_uid.toStdString()); - // this->GetDefaultDataStorage()->Add(node); - - // this->GetActiveStdMultiWidget(); - - // mitk::RenderingManager::GetInstance()->InitializeViews(node->GetData()->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true); - // mitk::RenderingManager::GetInstance()->RequestUpdateAll(); - // } - - // } - //} + 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) { m_DicomDirectoryListener->SetDicomListenerDirectory(directory); 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("C:/DicomDatabase")); QDir tmp(databaseDirectory); tmp.mkpath(databaseDirectory); m_Controls.internalDataWidget->SetDatabaseDirectory(databaseDirectory); QString listenerDirectory("C:/DICOMListenerDirectory"); StartDicomDirectoryListener(listenerDirectory); QmitkStoreSCPLauncherBuilder builder; builder.AddPort()->AddTransferSyntax()->AddOtherNetworkOptions()->AddMode()->AddOutputDirectory(listenerDirectory); m_StoreSCPLauncher = new QmitkStoreSCPLauncher(&builder); m_StoreSCPLauncher->StartStoreSCP(); } //TODO Remove void QmitkDicomEditor::TestHandler() { - ctkDictionary properties; - properties["title"] = "bla"; - m_Handler = new DicomEventHandler(); - m_Handler->SetPluginContext(mitk::PluginActivator::getContext()); - m_Handler->Register(QString("com/acme/reportgenerator/GENERATED")); + m_Handler->SubscribeSlots(); +} + +void QmitkDicomEditor::OnViewButtonAddToDataManager(const QStringList& eventProperties) +{ + ctkDictionary properties; + properties["Action"] = "ADD"; + properties["SeriesUID"] = eventProperties.at(0); + properties["Path"] = eventProperties.at(1); - ctkEvent reportGeneratedEvent("com/acme/reportgenerator/GENERATED", properties); + m_Publisher = new QmitkDicomDataEventPublisher(); + m_Publisher->PublishSignals(mitk::PluginActivator::getContext()); - m_Publisher = new QmitkDicomDataEventPublisher(); - m_Publisher->SetEventAdmin(mitk::PluginActivator::getContext()); - m_Publisher->SendEvent(reportGeneratedEvent); + m_Publisher->AddSeriesToDataManagerEvent(properties); } \ 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 bc241ae380..a3afc90b90 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,129 +1,130 @@ /*========================================================================= 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 #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 /*! \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 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 import is finished void OnDicomImportFinished(const QString& path); /// \brief Called when import is finished void OnDicomImportFinished(const QStringList& path); - /// \brief Called when series in TreeView is double clicked. - void OnSeriesModelDoubleClicked(QModelIndex index); - /// \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 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(); protected: void CreateQtPartControl(QWidget *parent); void SetupDefaults(); Events::Types GetPartEventTypes() const; Ui::QmitkDicomEditorControls m_Controls; QThread* m_Thread; QmitkDicomDirectoryListener* m_DicomDirectoryListener; QmitkStoreSCPLauncher* m_StoreSCPLauncher; DicomEventHandler* m_Handler; QmitkDicomDataEventPublisher* m_Publisher; }; #endif // QmitkDicomEditor_h diff --git a/Modules/DicomUI/Qmitk/QmitkDicomExternalDataWidget.cpp b/Modules/DicomUI/Qmitk/QmitkDicomExternalDataWidget.cpp index 0d8c0e7c09..238f96b617 100644 --- a/Modules/DicomUI/Qmitk/QmitkDicomExternalDataWidget.cpp +++ b/Modules/DicomUI/Qmitk/QmitkDicomExternalDataWidget.cpp @@ -1,210 +1,212 @@ /*========================================================================= 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. =========================================================================*/ #include // Qmitk #include "QmitkDicomExternalDataWidget.h" #include // Qt #include #include // CTK #include const std::string QmitkDicomExternalDataWidget::Widget_ID = "org.mitk.Widgets.QmitkDicomExternalDataWidget"; QmitkDicomExternalDataWidget::QmitkDicomExternalDataWidget(QWidget *parent) : m_Controls( 0 ) +, m_DirectoryName(new QString()) { Initialize(); CreateQtPartControl(this); } QmitkDicomExternalDataWidget::~QmitkDicomExternalDataWidget() { delete m_ImportDialog; delete m_ExternalDatabase; delete m_ExternalModel; delete m_ExternalIndexer; delete m_Controls; - //delete m_Timer; + delete m_DirectoryName; } void QmitkDicomExternalDataWidget::CreateQtPartControl( QWidget *parent ) { // build up qt Widget, unless already done if ( !m_Controls ) { // create GUI widgets from the Qt Designer's .ui file m_Controls = new Ui::QmitkDicomExternalDataWidgetControls; m_Controls->setupUi( parent ); // m_Controls->ExternalDataTreeView->setSortingEnabled(true); m_Controls->ExternalDataTreeView->setSelectionBehavior(QAbstractItemView::SelectRows); m_Controls->ExternalDataTreeView->setModel(m_ExternalModel); //Initialize import widget m_ImportDialog = new ctkFileDialog(); QCheckBox* importCheckbox = new QCheckBox("Copy on import", m_ImportDialog); m_ImportDialog->setBottomWidget(importCheckbox); m_ImportDialog->setFileMode(QFileDialog::Directory); m_ImportDialog->setLabelText(QFileDialog::Accept,"Import"); m_ImportDialog->setWindowTitle("Import DICOM files from directory ..."); m_ImportDialog->setWindowModality(Qt::ApplicationModal); connect(m_ImportDialog, SIGNAL(fileSelected(QString)),this,SLOT(OnFileSelectedAddExternalData(QString))); //connect Buttons connect(m_Controls->downloadButton, SIGNAL(clicked()),this,SLOT(OnDownloadButtonClicked())); - connect(m_Controls->viewExternalDataButton, SIGNAL(clicked()),this,SLOT(OnDownloadButtonClicked())); + connect(m_Controls->viewExternalDataButton, SIGNAL(clicked()),this,SLOT(OnViewButtonClicked())); connect(m_Controls->cancelButton, SIGNAL(clicked()),this,SLOT(OnDownloadButtonClicked())); connect(m_Controls->SearchOption_2, SIGNAL(parameterChanged()), this, SLOT(OnSearchParameterChanged())); } } void QmitkDicomExternalDataWidget::Initialize() { m_ExternalDatabase = new ctkDICOMDatabase(); //m_ExternalDatabase->initializeDatabase(); try{ m_ExternalDatabase->openDatabase(QString(":memory:"),QString( "EXTERNAL-DB")); }catch(std::exception e){ MITK_ERROR <<"Database error: "<< m_ExternalDatabase->lastError().toStdString(); m_ExternalDatabase->closeDatabase(); return; } m_ExternalModel = new ctkDICOMModel(); m_ExternalModel->setDatabase(m_ExternalDatabase->database()); m_ExternalModel->setEndLevel(ctkDICOMModel::SeriesType); m_ExternalIndexer = new ctkDICOMIndexer(); } void QmitkDicomExternalDataWidget::OnFolderCDImport() { m_ImportDialog->show(); m_ImportDialog->raise(); - } void QmitkDicomExternalDataWidget::OnFileSelectedAddExternalData(QString directory) { - if (QDir(directory).exists()) { + m_DirectoryName = new QString(directory); QCheckBox* copyOnImport = qobject_cast(m_ImportDialog->bottomWidget()); - if (copyOnImport->isChecked()) { //targetDirectory = d->DICOMDatabase->databaseDirectory(); MBI_DEBUG<ExternalDataTreeView->currentIndex(); + if(m_ExternalModel->data(currentIndex,ctkDICOMModel::TypeRole)==static_cast(ctkDICOMModel::SeriesType)) + { + QString seriesUID = m_ExternalModel->data(currentIndex,ctkDICOMModel::UIDRole).toString(); + QStringList eventProperties; + eventProperties << seriesUID << *m_DirectoryName; + MITK_INFO << m_DirectoryName->toStdString(); + + emit SignalDicomToDataManager(eventProperties); + } } void QmitkDicomExternalDataWidget::OnCancelButtonClicked() { m_Watcher.cancel(); m_Watcher.waitForFinished(); } void QmitkDicomExternalDataWidget::GetFileNamesFromIndex(QStringList& filePaths) { QModelIndex currentIndex = m_Controls->ExternalDataTreeView->currentIndex(); - QString currentUID = m_ExternalModel->data(currentIndex,ctkDICOMModel::UIDRole).toString(); - - if(m_ExternalModel->data(currentIndex,ctkDICOMModel::TypeRole)==static_cast(ctkDICOMModel::SeriesType)) { filePaths.append(m_ExternalDatabase->filesForSeries(currentUID)); } else if(m_ExternalModel->data(currentIndex,ctkDICOMModel::TypeRole)==static_cast(ctkDICOMModel::StudyType)) { QStringList seriesList; seriesList.append( m_ExternalDatabase->seriesForStudy(currentUID) ); QStringList::Iterator serieIt; for(serieIt=seriesList.begin();serieIt!=seriesList.end();++serieIt) { filePaths.append(m_ExternalDatabase->filesForSeries(*serieIt)); } } else if(m_ExternalModel->data(currentIndex,ctkDICOMModel::TypeRole)==static_cast(ctkDICOMModel::PatientType)) { QStringList studiesList,seriesList; studiesList.append( m_ExternalDatabase->studiesForPatient(currentUID) ); QStringList::Iterator studyIt,serieIt; for(studyIt=studiesList.begin();studyIt!=studiesList.end();++studyIt) { seriesList.append( m_ExternalDatabase->seriesForStudy(*studyIt) ); for(serieIt=seriesList.begin();serieIt!=seriesList.end();++serieIt) { filePaths.append(m_ExternalDatabase->filesForSeries(*serieIt)); } } } - } void QmitkDicomExternalDataWidget::AddDicomTemporary(QString directory) { m_ExternalIndexer->addDirectory(*m_ExternalDatabase,directory); m_ExternalModel->reset(); } -void QmitkDicomExternalDataWidget::OnSearchParameterChanged(){ - +void QmitkDicomExternalDataWidget::OnSearchParameterChanged() +{ m_ExternalModel->setDatabase(m_ExternalDatabase->database(),m_Controls->SearchOption_2->parameters()); } \ No newline at end of file diff --git a/Modules/DicomUI/Qmitk/QmitkDicomExternalDataWidget.h b/Modules/DicomUI/Qmitk/QmitkDicomExternalDataWidget.h index 3290d00c4c..cb71e277a4 100644 --- a/Modules/DicomUI/Qmitk/QmitkDicomExternalDataWidget.h +++ b/Modules/DicomUI/Qmitk/QmitkDicomExternalDataWidget.h @@ -1,121 +1,123 @@ /*========================================================================= 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 QmitkDicomExternalDataWidget_h #define QmitkDicomExternalDataWidget_h // #include #include "ui_QmitkDicomExternalDataWidgetControls.h" #include "mitkDicomUIExports.h" // include ctk #include #include #include #include //include QT #include #include #include #include //For running dicom import in background #include #include #include #include /*! \brief QmitkDicomExternalDataWidget \warning This application module is not yet documented. Use "svn blame/praise/annotate" and ask the author to provide basic documentation. \sa QmitkFunctionality \ingroup Functionalities */ class MITK_DICOMUI_EXPORT QmitkDicomExternalDataWidget : public QWidget { // 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: static const std::string Widget_ID; QmitkDicomExternalDataWidget(QWidget *parent); virtual ~QmitkDicomExternalDataWidget(); virtual void CreateQtPartControl(QWidget *parent); /* @brief Initializes the widget. This method has to be called before widget can start. * @param dataStorage The data storage the widget should work with. * @param multiWidget The corresponding multiwidget were the ct Image is displayed and the user should define his path. * @param imageNode The image node which will be the base of mitral processing */ void Initialize(); signals: void SignalChangePage(int); void SignalAddDicomData(const QString&); void SignalAddDicomData(const QStringList&); + void SignalDicomToDataManager(const QStringList&); public slots: /// @brief Called when import CD or import Folder was clicked. void OnFolderCDImport(); /// @brief Called when import directory was selected. void OnFileSelectedAddExternalData(QString); /// @brief Called when download button was clicked. void OnDownloadButtonClicked(); /// @brief Called when view button was clicked. void OnViewButtonClicked(); /// @brief Called when cancel button was clicked. void OnCancelButtonClicked(); /// @brief Called when search parameters change. void OnSearchParameterChanged(); protected: /// \brief Get the list of filepath from current selected index in TreeView. All file paths referring to the index will be returned. void GetFileNamesFromIndex(QStringList& filePaths); void AddDicomTemporary(QString directory); ctkDICOMDatabase* m_ExternalDatabase; ctkDICOMModel* m_ExternalModel; ctkDICOMIndexer* m_ExternalIndexer; ctkFileDialog* m_ImportDialog; Ui::QmitkDicomExternalDataWidgetControls* m_Controls; QFuture m_Future; QFutureWatcher m_Watcher; QTimer* m_Timer; + QString* m_DirectoryName; }; #endif // _QmitkDicomExternalDataWidget_H_INCLUDED diff --git a/Modules/DicomUI/Qmitk/QmitkDicomLocalStorageWidget.cpp b/Modules/DicomUI/Qmitk/QmitkDicomLocalStorageWidget.cpp index eede2d496b..525599c04d 100644 --- a/Modules/DicomUI/Qmitk/QmitkDicomLocalStorageWidget.cpp +++ b/Modules/DicomUI/Qmitk/QmitkDicomLocalStorageWidget.cpp @@ -1,160 +1,180 @@ /*========================================================================= 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. =========================================================================*/ // Qmitk #include "QmitkDicomLocalStorageWidget.h" #include //#include // Qt #include #include //#include "QmitkDicomDataEventPublisher.h" const std::string QmitkDicomLocalStorageWidget::Widget_ID = "org.mitk.Widgets.QmitkDicomLocalStorageWidget"; QmitkDicomLocalStorageWidget::QmitkDicomLocalStorageWidget(QWidget *parent) : m_Controls( 0 ) ,m_LocalIndexer(new ctkDICOMIndexer()) ,m_LocalModel(new ctkDICOMModel()) { CreateQtPartControl(this); } QmitkDicomLocalStorageWidget::~QmitkDicomLocalStorageWidget() { m_LocalDatabase->closeDatabase(); delete m_LocalDatabase; delete m_LocalIndexer; delete m_LocalModel; delete m_Controls; } void QmitkDicomLocalStorageWidget::CreateQtPartControl( QWidget *parent ) { if ( !m_Controls ) { m_Controls = new Ui::QmitkDicomLocalStorageWidgetControls; m_Controls->setupUi( parent ); m_Controls->groupBox->setVisible(false); m_Controls->InternalDataTreeView->setSortingEnabled(true); m_Controls->InternalDataTreeView->setSelectionBehavior(QAbstractItemView::SelectRows); m_Controls->InternalDataTreeView->setModel(m_LocalModel); connect(m_Controls->deleteButton,SIGNAL(clicked()),this,SLOT(OnDeleteButtonClicked())); connect(m_Controls->CancelButton, SIGNAL(clicked()), this , SLOT(OnCancelButtonClicked())); connect(m_Controls->viewInternalDataButton, SIGNAL(clicked()), this , SLOT(OnViewButtonClicked())); connect(m_Controls->SearchOption, SIGNAL(parameterChanged()), this, SLOT(OnSearchParameterChanged())); } } void QmitkDicomLocalStorageWidget::StartDicomImport(const QString& dicomData) { if (m_Watcher.isRunning()){ m_Watcher.waitForFinished(); } m_Future = QtConcurrent::run(this,(void (QmitkDicomLocalStorageWidget::*)(const QString&)) &QmitkDicomLocalStorageWidget::AddDICOMData,dicomData); m_Watcher.setFuture(m_Future); } void QmitkDicomLocalStorageWidget::StartDicomImport(const QStringList& dicomData) { if (m_Watcher.isRunning()) { m_Watcher.waitForFinished(); } m_Future = QtConcurrent::run(this,(void (QmitkDicomLocalStorageWidget::*)(const QStringList&)) &QmitkDicomLocalStorageWidget::AddDICOMData,dicomData); m_Watcher.setFuture(m_Future); } void QmitkDicomLocalStorageWidget::AddDICOMData(const QString& directory) { if(m_LocalDatabase->isOpen()) { m_LocalIndexer->addDirectory(*m_LocalDatabase,directory,m_LocalDatabase->databaseDirectory()); } m_LocalModel->setDatabase(m_LocalDatabase->database()); emit FinishedImport(directory); } void QmitkDicomLocalStorageWidget::AddDICOMData(const QStringList& patientFiles) { if(m_LocalDatabase->isOpen()) { QStringListIterator fileIterator(patientFiles); while(fileIterator.hasNext()) { m_LocalIndexer->addFile(*m_LocalDatabase,fileIterator.next(),m_LocalDatabase->databaseDirectory()); } } m_LocalModel->setDatabase(m_LocalDatabase->database()); emit FinishedImport(patientFiles); } void QmitkDicomLocalStorageWidget::OnDeleteButtonClicked() { QModelIndex currentIndex = m_Controls->InternalDataTreeView->currentIndex(); QString currentUID = m_LocalModel->data(currentIndex,ctkDICOMModel::UIDRole).toString(); if(m_LocalModel->data(currentIndex,ctkDICOMModel::TypeRole)==static_cast(ctkDICOMModel::SeriesType)) { m_LocalDatabase->removeSeries(currentUID); } else if(m_LocalModel->data(currentIndex,ctkDICOMModel::TypeRole)==static_cast(ctkDICOMModel::StudyType)) { m_LocalDatabase->removeStudy(currentUID); } else if(m_LocalModel->data(currentIndex,ctkDICOMModel::TypeRole)==static_cast(ctkDICOMModel::PatientType)) { m_LocalDatabase->removePatient(currentUID); } m_LocalModel->reset(); } void QmitkDicomLocalStorageWidget::OnCancelButtonClicked() { m_Watcher.cancel(); m_Watcher.waitForFinished(); m_LocalDatabase->closeDatabase(); } //TODO void QmitkDicomLocalStorageWidget::OnViewButtonClicked() { - //QModelIndex index = m_Controls->InternalDataTreeView->currentIndex(); + QModelIndex currentIndex = m_Controls->InternalDataTreeView->currentIndex(); + if(m_LocalModel->data(currentIndex,ctkDICOMModel::TypeRole)==static_cast(ctkDICOMModel::SeriesType)) + { + QString seriesUID = m_LocalModel->data(currentIndex,ctkDICOMModel::UIDRole).toString(); + + QModelIndex studyIndex = m_LocalModel->parent(currentIndex); + QString studyUID = m_LocalModel->data(studyIndex,ctkDICOMModel::UIDRole).toString(); + + QString filePath; + filePath.append(m_LocalDatabase->databaseDirectory()); + filePath.append("/dicom/"); + filePath.append(studyUID); + filePath.append("/"); + filePath.append(seriesUID); + filePath.append("/"); + + QStringList eventProperties; + eventProperties << seriesUID << filePath; + MITK_INFO << filePath.toStdString(); + emit SignalDicomToDataManager(eventProperties); + } } void QmitkDicomLocalStorageWidget::OnSearchParameterChanged() { m_LocalModel->setDatabase(m_LocalDatabase->database(),m_Controls->SearchOption->parameters()); } void QmitkDicomLocalStorageWidget::SetDatabaseDirectory(QString newDatatbaseDirectory) { QDir databaseDirecory = QDir(newDatatbaseDirectory); if(!databaseDirecory.exists()) { databaseDirecory.mkpath(databaseDirecory.absolutePath()); } QString newDatatbaseFile = databaseDirecory.absolutePath() + QString("/ctkDICOM.sql"); this->SetDatabase(newDatatbaseFile); } void QmitkDicomLocalStorageWidget::SetDatabase(QString databaseFile) { m_LocalDatabase = new ctkDICOMDatabase(databaseFile); m_LocalModel->setEndLevel(ctkDICOMModel::SeriesType); m_LocalModel->setDatabase(m_LocalDatabase->database()); } \ No newline at end of file diff --git a/Modules/DicomUI/Qmitk/QmitkDicomLocalStorageWidget.h b/Modules/DicomUI/Qmitk/QmitkDicomLocalStorageWidget.h index bec9f06ec3..8ed484769c 100644 --- a/Modules/DicomUI/Qmitk/QmitkDicomLocalStorageWidget.h +++ b/Modules/DicomUI/Qmitk/QmitkDicomLocalStorageWidget.h @@ -1,113 +1,114 @@ /*========================================================================= 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 QmitkDicomLocalStorageWidget_h #define QmitkDicomLocalStorageWidget_h // #include #include "ui_QmitkDicomLocalStorageWidgetControls.h" #include "mitkDicomUIExports.h" // include ctk #include #include #include #include //include QT #include #include #include //For running dicom import in background #include #include #include #include /*! \brief QmitkDicomLocalStorageWidget \warning This application module is not yet documented. Use "svn blame/praise/annotate" and ask the author to provide basic documentation. \sa QmitkFunctionality \ingroup Functionalities */ class MITK_DICOMUI_EXPORT QmitkDicomLocalStorageWidget : public QWidget { // 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: static const std::string Widget_ID; QmitkDicomLocalStorageWidget(QWidget *parent); virtual ~QmitkDicomLocalStorageWidget(); virtual void CreateQtPartControl(QWidget *parent); void SetDatabaseDirectory(QString newDatabaseDirectory); signals: void FinishedImport(const QString&); void FinishedImport(const QStringList&); + void SignalDicomToDataManager(const QStringList&); public slots: /// @brief Called when cancel button was clicked. void OnViewButtonClicked(); /// @brief Called when cancel button was clicked. void OnCancelButtonClicked(); /// @brief Called delete button was clicked. void OnDeleteButtonClicked(); /// @brief Called when adding a dicom directory. Starts a thread adding the directory. void StartDicomImport(const QString& dicomData); /// @brief Called when adding a list of dicom files. Starts a thread adding the dicom files. void StartDicomImport(const QStringList& dicomData); /// @brief Called when search parameters change. void OnSearchParameterChanged(); protected: // adds dicom files from a directory containing dicom files to the local storage. void AddDICOMData(const QString& dicomDirectory); // adds dicom files from a string list containing the filepath to the local storage. void AddDICOMData(const QStringList& dicomFiles); void SetDatabase(QString databaseFile); ctkDICOMDatabase* m_LocalDatabase; ctkDICOMModel* m_LocalModel; ctkDICOMIndexer* m_LocalIndexer; Ui::QmitkDicomLocalStorageWidgetControls* m_Controls; QFuture m_Future; QFutureWatcher m_Watcher; }; #endif // _QmitkDicomLocalStorageWidget_H_INCLUDED