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 441ed7d2f4..0edd173a96 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,49 +1,50 @@ /*========================================================================= 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 "DicomEventHandler.h" #include #include +#include DicomEventHandler::DicomEventHandler() { } DicomEventHandler::~DicomEventHandler() { } void DicomEventHandler::handleEvent(const ctkEvent& ctkEvent) { - std::cout << "I'll handle your event:" ctkEvent.getProperty("SeriesName").toString(); + MITK_INFO << "I'll handle your event:" << ctkEvent.getProperty("title").toString().toStdString(); } void DicomEventHandler::Register(QString eventTopic, QString filter) { 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) { m_PluginContext = context; } \ 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 b6fbd152fe..27b1db0d76 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,55 +1,53 @@ /*========================================================================= 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 { Q_OBJECT Q_INTERFACES(ctkEventHandler) public: DicomEventHandler(); virtual ~DicomEventHandler(); void handleEvent(const ctkEvent& ctkEvent); - /*! \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()); + void Register(QString eventTopic, QString filter = QString()); void SetPluginContext(ctkPluginContext* context); private: ctkPluginContext* m_PluginContext; - }; #endif // QmitkDicomEventHandlerBuilder_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 274a2fb25b..ace6b8c23d 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,214 +1,235 @@ /*========================================================================= 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.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.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(); // } // } //} } 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")); + + ctkEvent reportGeneratedEvent("com/acme/reportgenerator/GENERATED", properties); + + m_Publisher = new QmitkDicomDataEventPublisher(); + m_Publisher->SetEventAdmin(mitk::PluginActivator::getContext()); + m_Publisher->SendEvent(reportGeneratedEvent); } \ 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 544b0414cb..bc241ae380 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,123 +1,129 @@ /*========================================================================= 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 /*! \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(); 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/QmitkDicomLocalStorageWidget.cpp b/Modules/DicomUI/Qmitk/QmitkDicomLocalStorageWidget.cpp index 03d0f21d57..eede2d496b 100644 --- a/Modules/DicomUI/Qmitk/QmitkDicomLocalStorageWidget.cpp +++ b/Modules/DicomUI/Qmitk/QmitkDicomLocalStorageWidget.cpp @@ -1,157 +1,160 @@ /*========================================================================= 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(); } 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