diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/files.cmake b/Plugins/org.mitk.gui.qt.semanticrelations/files.cmake index 1250ec9d47..09421a5b1d 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/files.cmake +++ b/Plugins/org.mitk.gui.qt.semanticrelations/files.cmake @@ -1,53 +1,52 @@ set(INTERNAL_CPP_FILES mitkPluginActivator.cpp - QmitkAbstractSemanticRelationsAction.cpp QmitkDataNodeAddToSemanticRelationsAction.cpp QmitkDataNodeRemoveFromSemanticRelationsAction.cpp QmitkDataNodeUnlinkFromLesionAction.cpp QmitkDataNodeSetControlPointAction.cpp QmitkDataNodeSetInformationTypeAction.cpp QmitkDataSetOpenInAction.cpp QmitkFocusOnLesionAction.cpp QmitkLabelSetJumpToAction.cpp QmitkLesionInfoWidget.cpp QmitkSemanticRelationsContextMenu.cpp QmitkSemanticRelationsNodeSelectionDialog.cpp QmitkSemanticRelationsStatisticsView.cpp QmitkSemanticRelationsView.cpp ) set(UI_FILES src/internal/QmitkLesionInfoWidgetControls.ui src/internal/QmitkSemanticRelationsControls.ui src/internal/QmitkSemanticRelationsStatisticsControls.ui ) set(MOC_H_FILES src/internal/mitkPluginActivator.h src/internal/QmitkDataNodeAddToSemanticRelationsAction.h src/internal/QmitkDataNodeRemoveFromSemanticRelationsAction.h src/internal/QmitkDataNodeUnlinkFromLesionAction.h src/internal/QmitkDataNodeSetControlPointAction.h src/internal/QmitkDataNodeSetInformationTypeAction.h src/internal/QmitkDataSetOpenInAction.h src/internal/QmitkFocusOnLesionAction.h src/internal/QmitkLabelSetJumpToAction.h src/internal/QmitkLesionInfoWidget.h src/internal/QmitkSemanticRelationsContextMenu.h src/internal/QmitkSemanticRelationsNodeSelectionDialog.h src/internal/QmitkSemanticRelationsStatisticsView.h src/internal/QmitkSemanticRelationsView.h ) set(CACHED_RESOURCE_FILES resources/SemanticRelations_48.png resources/SemanticRelationsStatistics_48.png plugin.xml ) set(QRC_FILES ) foreach(file ${INTERNAL_CPP_FILES}) set(CPP_FILES ${CPP_FILES} src/internal/${file}) endforeach(file ${INTERNAL_CPP_FILES}) diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkAbstractSemanticRelationsAction.cpp b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkAbstractSemanticRelationsAction.cpp deleted file mode 100644 index 43699e88fd..0000000000 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkAbstractSemanticRelationsAction.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -// semantic relations plugin -#include "QmitkAbstractSemanticRelationsAction.h" - -QmitkAbstractSemanticRelationsAction::QmitkAbstractSemanticRelationsAction(berry::IWorkbenchPartSite::Pointer workbenchPartSite) - : QmitkAbstractDataNodeAction(workbenchPartSite) -{ - m_SemanticRelationsIntegration = std::make_unique(); -} - -QmitkAbstractSemanticRelationsAction::QmitkAbstractSemanticRelationsAction(berry::IWorkbenchPartSite* workbenchPartSite) - : QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) -{ - // nothing here -} diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkAbstractSemanticRelationsAction.h b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkAbstractSemanticRelationsAction.h deleted file mode 100644 index 0cef975cb7..0000000000 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkAbstractSemanticRelationsAction.h +++ /dev/null @@ -1,39 +0,0 @@ -/*=================================================================== - -The Medical Imaging Interaction Toolkit (MITK) - -Copyright (c) German Cancer Research Center, -Division of Medical and Biological Informatics. -All rights reserved. - -This software is distributed WITHOUT ANY WARRANTY; without -even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. - -See LICENSE.txt or http://www.mitk.org for details. - -===================================================================*/ - -#ifndef QMITKABSTRACTSEMANTICRELATIONSACTION_H -#define QMITKABSTRACTSEMANTICRELATIONSACTION_H - -// mitk gui qt application plugin -#include - -// semantic relations module -#include - -class QmitkAbstractSemanticRelationsAction : public QmitkAbstractDataNodeAction -{ - -public: - - QmitkAbstractSemanticRelationsAction(berry::IWorkbenchPartSite::Pointer workbenchPartSite); - QmitkAbstractSemanticRelationsAction(berry::IWorkbenchPartSite* workbenchPartSite); - -protected: - - std::unique_ptr m_SemanticRelationsIntegration; -}; - -#endif // QMITKABSTRACTSEMANTICRELATIONSACTION_H diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeAddToSemanticRelationsAction.cpp b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeAddToSemanticRelationsAction.cpp index 33f17f8408..02821e6490 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeAddToSemanticRelationsAction.cpp +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeAddToSemanticRelationsAction.cpp @@ -1,259 +1,251 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // semantic relations plugin #include "QmitkDataNodeAddToSemanticRelationsAction.h" #include "QmitkDataNodeRemoveFromSemanticRelationsAction.h" // semantic relations module #include #include #include #include -#include #include +#include +#include #include #include // mitk gui common plugin #include // mitk core #include // qt #include // namespace that contains the concrete action namespace AddToSemanticRelationsAction { - void Run(mitk::SemanticRelationsIntegration* semanticRelationsIntegration, mitk::DataStorage* dataStorage, const mitk::DataNode* dataNode) + void Run(mitk::DataStorage* dataStorage, const mitk::DataNode* dataNode) { - if (nullptr == semanticRelationsIntegration - || nullptr == dataStorage + if (nullptr == dataStorage || nullptr == dataNode) { return; } if (mitk::NodePredicates::GetImagePredicate()->CheckNode(dataNode)) { try { - AddImage(semanticRelationsIntegration, dataStorage, dataNode); + AddImage(dataStorage, dataNode); } catch (mitk::SemanticRelationException& e) { mitkReThrow(e); } } else if (mitk::NodePredicates::GetSegmentationPredicate()->CheckNode(dataNode)) { try { - AddSegmentation(semanticRelationsIntegration, dataStorage, dataNode); + AddSegmentation(dataStorage, dataNode); } catch (mitk::SemanticRelationException& e) { mitkReThrow(e); } } } - void AddImage(mitk::SemanticRelationsIntegration* semanticRelationsIntegration, mitk::DataStorage* dataStorage, const mitk::DataNode* image) + void AddImage(mitk::DataStorage* dataStorage, const mitk::DataNode* image) { mitk::SemanticTypes::InformationType informationType; mitk::SemanticTypes::ExaminationPeriod examinationPeriod; mitk::SemanticRelationsDataStorageAccess::DataNodeVector allSpecificImages; try { mitk::SemanticTypes::CaseID caseID = GetCaseIDFromDataNode(image); informationType = GetDICOMModalityFromDataNode(image); // see if the examination period - information type cell is already taken examinationPeriod = FindFittingExaminationPeriod(image); auto semanticRelationsDataStorageAccess = mitk::SemanticRelationsDataStorageAccess(dataStorage); try { allSpecificImages = semanticRelationsDataStorageAccess.GetAllSpecificImages(caseID, informationType, examinationPeriod); } catch (const mitk::SemanticRelationException&) { // just continue since an exception means that there is no specific image } } catch (mitk::SemanticRelationException& e) { mitkReThrow(e); } if (!allSpecificImages.empty()) { // examination period - information type cell is already taken // ask if cell should be overwritten QMessageBox::StandardButton answerButton = QMessageBox::question(nullptr, "Specific image already exists.", QString::fromStdString("Force overwriting existing image " + informationType + " at " + examinationPeriod.name + "?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if (answerButton == QMessageBox::Yes) { try { // remove already existent images at specific cell for (const auto& specificImage : allSpecificImages) { - RemoveFromSemanticRelationsAction::Run(semanticRelationsIntegration, dataStorage, specificImage); + RemoveFromSemanticRelationsAction::Run(dataStorage, specificImage); } } catch (mitk::SemanticRelationException& e) { mitkReThrow(e); return; } } else { // else case is: no overwriting return; } } // specific image does not exist or has been removed; adding the image should work + mitk::SemanticRelationsIntegration semanticRelationsIntegration; try { - semanticRelationsIntegration->AddImage(image); + semanticRelationsIntegration.AddImage(image); } catch (mitk::SemanticRelationException& e) { mitkReThrow(e); } } - void AddSegmentation(mitk::SemanticRelationsIntegration* semanticRelationsIntegration, mitk::DataStorage* dataStorage, const mitk::DataNode* segmentation) + void AddSegmentation(mitk::DataStorage* dataStorage, const mitk::DataNode* segmentation) { if (nullptr == segmentation) { return; } mitk::BaseData* baseData = segmentation->GetData(); if (nullptr == baseData) { return; } // continue with valid segmentation data // get parent node of the current segmentation node with the node predicate mitk::DataStorage::SetOfObjects::ConstPointer parentNodes = dataStorage->GetSources(segmentation, mitk::NodePredicates::GetImagePredicate(), false); if (parentNodes->empty()) { // segmentation without corresponding image will not be added QMessageBox msgBox(QMessageBox::Warning, "Could not add the selected segmentation.", "The program wasn't able to correctly add the selected segmentation.\n" "Reason: No parent image found"); msgBox.exec(); return; } // check for already existing, identifying base properties auto caseIDPropertyName = mitk::GetCaseIDDICOMProperty(); auto nodeIDPropertyName = mitk::GetNodeIDDICOMProperty(); mitk::BaseProperty* caseIDProperty = baseData->GetProperty(caseIDPropertyName.c_str()); mitk::BaseProperty* nodeIDProperty = baseData->GetProperty(nodeIDPropertyName.c_str()); if (nullptr == caseIDProperty || nullptr == nodeIDProperty) { MITK_INFO << "No DICOM tags for case and node identification found. Transferring DICOM tags from the parent node to the selected segmentation node."; mitk::SemanticTypes::CaseID caseID; mitk::SemanticTypes::ID nodeID; try { caseID = mitk::GetCaseIDFromDataNode(parentNodes->front()); nodeID = mitk::GetIDFromDataNode(parentNodes->front()); } catch (mitk::SemanticRelationException& e) { mitkReThrow(e); return; } // transfer DICOM tags to the segmentation node baseData->SetProperty(caseIDPropertyName, mitk::TemporoSpatialStringProperty::New(caseID)); // add UID to distinguish between different segmentations of the same parent node baseData->SetProperty(nodeIDPropertyName, mitk::TemporoSpatialStringProperty::New(nodeID + mitk::UIDGeneratorBoost::GenerateUID())); } // add the parent node if not already existent if (!mitk::SemanticRelationsInference::InstanceExists(parentNodes->front())) { - AddImage(semanticRelationsIntegration, dataStorage, parentNodes->front()); + AddImage(dataStorage, parentNodes->front()); } + mitk::SemanticRelationsIntegration semanticRelationsIntegration; try { // add the segmentation with its parent image to the semantic relations storage - semanticRelationsIntegration->AddSegmentation(segmentation, parentNodes->front()); + semanticRelationsIntegration.AddSegmentation(segmentation, parentNodes->front()); } catch (mitk::SemanticRelationException& e) { mitkReThrow(e); } } } QmitkDataNodeAddToSemanticRelationsAction::QmitkDataNodeAddToSemanticRelationsAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite) : QAction(parent) - , QmitkAbstractSemanticRelationsAction(workbenchPartSite) + , QmitkAbstractDataNodeAction(workbenchPartSite) { setText(tr("Add to semantic relations")); InitializeAction(); } QmitkDataNodeAddToSemanticRelationsAction::QmitkDataNodeAddToSemanticRelationsAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite) : QAction(parent) - , QmitkAbstractSemanticRelationsAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) { setText(tr("Add to semantic relations")); InitializeAction(); } -QmitkDataNodeAddToSemanticRelationsAction::~QmitkDataNodeAddToSemanticRelationsAction() -{ - // nothing here -} - void QmitkDataNodeAddToSemanticRelationsAction::InitializeAction() { connect(this, &QAction::triggered, this, &QmitkDataNodeAddToSemanticRelationsAction::OnActionTriggered); } void QmitkDataNodeAddToSemanticRelationsAction::OnActionTriggered(bool /*checked*/) { - if (nullptr == m_SemanticRelationsIntegration) - { - return; - } - if (m_DataStorage.IsExpired()) { return; } auto dataNode = GetSelectedNode(); - AddToSemanticRelationsAction::Run(m_SemanticRelationsIntegration.get(), m_DataStorage.Lock(), dataNode); + AddToSemanticRelationsAction::Run(m_DataStorage.Lock(), dataNode); } diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeAddToSemanticRelationsAction.h b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeAddToSemanticRelationsAction.h index 8cc04aec19..cdb4f94585 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeAddToSemanticRelationsAction.h +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeAddToSemanticRelationsAction.h @@ -1,77 +1,73 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKDATANODEADDTOSEMANTICRELATIONSACTION_H #define QMITKDATANODEADDTOSEMANTICRELATIONSACTION_H #include // mitk gui qt application plugin -#include "QmitkAbstractSemanticRelationsAction.h" +#include // qt #include namespace AddToSemanticRelationsAction { /** * @brief The function checks whether the given node is an image or a segmentation and calls the corresponding add function. * The corresponding add functions will add the data node to the semantic relations storage. * If an image is added, the 'AddImage' function will check if another image at the fitting control-point - information type cell * already exists. If so, the user is prompted to overwrite the existing image or abort the process. * If the user wants to overwrite the existing image, the image and it's corresponding segmentation nodes will be removed from the semantic relations storage. * If a segmentation is added, the parent image node will also be to the semantic relations storage. If the segmentation does not contain the required DICOM information, * the DICOM information of the parent data will be transfered to the segmentation data. * - * @pre The given semantic relations integration has to be valid (!nullptr). * @pre The given dataStorage has to be valid (!nullptr). * @pre The given dataNode has to be valid (!nullptr). * The function simply returns if the preconditions are not met. * * @throw SemanticRelationException re-thrown. * - * @param semanticRelationsIntegration An instance of the semantic relations integration that should be used to perform the node adding. * @param dataStorage The data storage to use for to remove the existing image and to check for the parent image node of a segmentation. * @param dataNode The data node to add. */ - MITK_GUI_SEMANTICRELATIONS_EXPORT void Run(mitk::SemanticRelationsIntegration* semanticRelationsIntegration, mitk::DataStorage* dataStorage, const mitk::DataNode* image); + MITK_GUI_SEMANTICRELATIONS_EXPORT void Run(mitk::DataStorage* dataStorage, const mitk::DataNode* image); - void AddImage(mitk::SemanticRelationsIntegration* semanticRelationsIntegration, mitk::DataStorage* dataStorage, const mitk::DataNode* image); - void AddSegmentation(mitk::SemanticRelationsIntegration* semanticRelationsIntegration, mitk::DataStorage* dataStorage, const mitk::DataNode* segmentation); + void AddImage(mitk::DataStorage* dataStorage, const mitk::DataNode* image); + void AddSegmentation(mitk::DataStorage* dataStorage, const mitk::DataNode* segmentation); } -class MITK_GUI_SEMANTICRELATIONS_EXPORT QmitkDataNodeAddToSemanticRelationsAction : public QAction, public QmitkAbstractSemanticRelationsAction +class MITK_GUI_SEMANTICRELATIONS_EXPORT QmitkDataNodeAddToSemanticRelationsAction : public QAction, public QmitkAbstractDataNodeAction { Q_OBJECT public: QmitkDataNodeAddToSemanticRelationsAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); QmitkDataNodeAddToSemanticRelationsAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite); - virtual ~QmitkDataNodeAddToSemanticRelationsAction() override; - private Q_SLOTS: void OnActionTriggered(bool); protected: virtual void InitializeAction() override; }; #endif // QMITKDATANODEADDTOSEMANTICRELATIONSACTION_H diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeRemoveFromSemanticRelationsAction.cpp b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeRemoveFromSemanticRelationsAction.cpp index 503e0dca1c..30ac801473 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeRemoveFromSemanticRelationsAction.cpp +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeRemoveFromSemanticRelationsAction.cpp @@ -1,139 +1,131 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // semantic relations plugin #include "QmitkDataNodeRemoveFromSemanticRelationsAction.h" // semantic relations module #include #include +#include // mitk gui common plugin #include // qt #include // namespace that contains the concrete action namespace RemoveFromSemanticRelationsAction { - void Run(mitk::SemanticRelationsIntegration* semanticRelationsIntegration, mitk::DataStorage* dataStorage, const mitk::DataNode* dataNode) + void Run(mitk::DataStorage* dataStorage, const mitk::DataNode* dataNode) { - if (nullptr == semanticRelationsIntegration - || nullptr == dataStorage + if (nullptr == dataStorage || nullptr == dataNode) { return; } if (mitk::NodePredicates::GetImagePredicate()->CheckNode(dataNode)) { try { - RemoveImage(semanticRelationsIntegration, dataStorage, dataNode); + RemoveImage(dataStorage, dataNode); } catch (mitk::SemanticRelationException& e) { mitkReThrow(e); } } else if (mitk::NodePredicates::GetSegmentationPredicate()->CheckNode(dataNode)) { try { - RemoveSegmentation(semanticRelationsIntegration, dataNode); + RemoveSegmentation(dataNode); } catch (mitk::SemanticRelationException& e) { mitkReThrow(e); } } } - void RemoveImage(mitk::SemanticRelationsIntegration* semanticRelationsIntegration, mitk::DataStorage* dataStorage, const mitk::DataNode* image) + void RemoveImage(mitk::DataStorage* dataStorage, const mitk::DataNode* image) { + mitk::SemanticRelationsIntegration semanticRelationsIntegration; try { // remove each corresponding segmentation from the semantic relations storage mitk::DataStorage::SetOfObjects::ConstPointer childNodes = dataStorage->GetDerivations(image, mitk::NodePredicates::GetSegmentationPredicate(), false); for (auto it = childNodes->Begin(); it != childNodes->End(); ++it) { - RemoveSegmentation(semanticRelationsIntegration, it->Value()); + RemoveSegmentation(it->Value()); } // remove the image from the semantic relations storage - semanticRelationsIntegration->RemoveImage(image); + semanticRelationsIntegration.RemoveImage(image); } catch (mitk::SemanticRelationException& e) { mitkReThrow(e); } } - void RemoveSegmentation(mitk::SemanticRelationsIntegration* semanticRelationsIntegration, const mitk::DataNode* segmentation) + void RemoveSegmentation(const mitk::DataNode* segmentation) { + mitk::SemanticRelationsIntegration semanticRelationsIntegration; try { // remove the segmentation from the semantic relations storage - semanticRelationsIntegration->RemoveSegmentation(segmentation); + semanticRelationsIntegration.RemoveSegmentation(segmentation); } catch (mitk::SemanticRelationException& e) { mitkReThrow(e); } } } QmitkDataNodeRemoveFromSemanticRelationsAction::QmitkDataNodeRemoveFromSemanticRelationsAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite) : QAction(parent) - , QmitkAbstractSemanticRelationsAction(workbenchPartSite) + , QmitkAbstractDataNodeAction(workbenchPartSite) { setText(tr("Remove from semantic relations")); InitializeAction(); } QmitkDataNodeRemoveFromSemanticRelationsAction::QmitkDataNodeRemoveFromSemanticRelationsAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite) : QAction(parent) - , QmitkAbstractSemanticRelationsAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) { setText(tr("Remove from semantic relations")); InitializeAction(); } -QmitkDataNodeRemoveFromSemanticRelationsAction::~QmitkDataNodeRemoveFromSemanticRelationsAction() -{ - // nothing here -} - void QmitkDataNodeRemoveFromSemanticRelationsAction::InitializeAction() { connect(this, &QAction::triggered, this, &QmitkDataNodeRemoveFromSemanticRelationsAction::OnActionTriggered); } void QmitkDataNodeRemoveFromSemanticRelationsAction::OnActionTriggered(bool /*checked*/) { - if (nullptr == m_SemanticRelationsIntegration) - { - return; - } - if (m_DataStorage.IsExpired()) { return; } auto dataNode = GetSelectedNode(); - RemoveFromSemanticRelationsAction::Run(m_SemanticRelationsIntegration.get(), m_DataStorage.Lock(),dataNode); + RemoveFromSemanticRelationsAction::Run(m_DataStorage.Lock(),dataNode); } diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeRemoveFromSemanticRelationsAction.h b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeRemoveFromSemanticRelationsAction.h index b5b73ee73d..2ac42add53 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeRemoveFromSemanticRelationsAction.h +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeRemoveFromSemanticRelationsAction.h @@ -1,73 +1,69 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKDATANODEREMOVEFROMSEMANTICRELATIONSACTION_H #define QMITKDATANODEREMOVEFROMSEMANTICRELATIONSACTION_H #include // mitk gui qt application plugin -#include "QmitkAbstractSemanticRelationsAction.h" +#include // qt #include namespace RemoveFromSemanticRelationsAction { /** * @brief The function checks whether the given node is an image or a segmentation and calls the corresponding remove function. * The corresponding remove functions will remove the data node from the semantic relations storage. * If an image is removed, the child segmentation nodes will also be removed from the semantic relations storage. * - * @pre The given semantic relations integration has to be valid (!nullptr). * @pre The given dataStorage has to be valid (!nullptr). * @pre The given dataNode has to be valid (!nullptr). * The function simply returns if the preconditions are not met. * * @throw SemanticRelationException re-thrown. * - * @param semanticRelationsIntegration An instance of the semantic relations integration that should be used to perform the node removal. * @param dataStorage The data storage to use to check for the child segmentation nodes of an image. * @param dataNode The data node to remove. */ - MITK_GUI_SEMANTICRELATIONS_EXPORT void Run(mitk::SemanticRelationsIntegration* semanticRelationsIntegration, mitk::DataStorage* dataStorage, const mitk::DataNode* dataNode); + MITK_GUI_SEMANTICRELATIONS_EXPORT void Run(mitk::DataStorage* dataStorage, const mitk::DataNode* dataNode); - void RemoveImage(mitk::SemanticRelationsIntegration* semanticRelationsIntegration, mitk::DataStorage* dataStorage, const mitk::DataNode* image); - void RemoveSegmentation(mitk::SemanticRelationsIntegration* semanticRelationsIntegration, const mitk::DataNode* segmentation); + void RemoveImage(mitk::DataStorage* dataStorage, const mitk::DataNode* image); + void RemoveSegmentation(const mitk::DataNode* segmentation); } -class MITK_GUI_SEMANTICRELATIONS_EXPORT QmitkDataNodeRemoveFromSemanticRelationsAction : public QAction, public QmitkAbstractSemanticRelationsAction +class MITK_GUI_SEMANTICRELATIONS_EXPORT QmitkDataNodeRemoveFromSemanticRelationsAction : public QAction, public QmitkAbstractDataNodeAction { Q_OBJECT public: QmitkDataNodeRemoveFromSemanticRelationsAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); QmitkDataNodeRemoveFromSemanticRelationsAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite); - virtual ~QmitkDataNodeRemoveFromSemanticRelationsAction() override; - private Q_SLOTS: void OnActionTriggered(bool); protected: virtual void InitializeAction() override; }; #endif // QMITKDATANODEREMOVEFROMSEMANTICRELATIONSACTION_H diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetControlPointAction.cpp b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetControlPointAction.cpp index 37c192b029..070da81ebb 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetControlPointAction.cpp +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetControlPointAction.cpp @@ -1,180 +1,174 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // semantic relations plugin #include "QmitkDataNodeSetControlPointAction.h" #include "QmitkDataNodeRemoveFromSemanticRelationsAction.h" // semantic relations module #include #include -#include #include +#include #include +#include #include // semantic relations UI module #include "QmitkControlPointDialog.h" // qt #include #include QmitkDataNodeSetControlPointAction::QmitkDataNodeSetControlPointAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite) : QAction(parent) - , QmitkAbstractSemanticRelationsAction(workbenchPartSite) + , QmitkAbstractDataNodeAction(workbenchPartSite) { setText(tr("Set control point")); m_Parent = parent; InitializeAction(); } QmitkDataNodeSetControlPointAction::QmitkDataNodeSetControlPointAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite) : QAction(parent) - , QmitkAbstractSemanticRelationsAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) { setText(tr("Set control point")); m_Parent = parent; InitializeAction(); } -QmitkDataNodeSetControlPointAction::~QmitkDataNodeSetControlPointAction() -{ - // nothing here -} - void QmitkDataNodeSetControlPointAction::InitializeAction() { connect(this, &QAction::triggered, this, &QmitkDataNodeSetControlPointAction::OnActionTriggered); } void QmitkDataNodeSetControlPointAction::OnActionTriggered(bool /*checked*/) { - if (nullptr == m_SemanticRelationsIntegration) - { - return; - } - if (m_DataStorage.IsExpired()) { return; } + auto dataStorage = m_DataStorage.Lock(); + auto dataNode = GetSelectedNode(); if (dataNode.IsNull()) { return; } QmitkControlPointDialog* inputDialog = new QmitkControlPointDialog(m_Parent); inputDialog->setWindowTitle("Set control point"); inputDialog->SetCurrentDate(mitk::SemanticRelationsInference::GetControlPointOfImage(dataNode)); int dialogReturnValue = inputDialog->exec(); if (QDialog::Rejected == dialogReturnValue) { return; } const QDate& userSelectedDate = inputDialog->GetCurrentDate(); mitk::SemanticTypes::ControlPoint controlPoint; controlPoint.UID = mitk::UIDGeneratorBoost::GenerateUID(); controlPoint.date = boost::gregorian::date(userSelectedDate.year(), userSelectedDate.month(), userSelectedDate.day()); mitk::SemanticTypes::InformationType informationType; mitk::SemanticTypes::ExaminationPeriod examinationPeriod; mitk::SemanticRelationsDataStorageAccess::DataNodeVector allSpecificImages; try { mitk::SemanticTypes::CaseID caseID = mitk::GetCaseIDFromDataNode(dataNode); informationType = mitk::SemanticRelationsInference::GetInformationTypeOfImage(dataNode); // see if the examination period - information type cell is already taken examinationPeriod = mitk::FindFittingExaminationPeriod(caseID, controlPoint); - auto semanticRelationsDataStorageAccess = mitk::SemanticRelationsDataStorageAccess(m_DataStorage.Lock()); + auto semanticRelationsDataStorageAccess = mitk::SemanticRelationsDataStorageAccess(dataStorage); try { allSpecificImages = semanticRelationsDataStorageAccess.GetAllSpecificImages(caseID, informationType, examinationPeriod); } catch (const mitk::SemanticRelationException&) { // just continue since an exception means that there is no specific image } } catch (const mitk::SemanticRelationException& e) { std::stringstream exceptionMessage; exceptionMessage << e; QMessageBox msgBox(QMessageBox::Warning, "Could not set the control point.", "The program wasn't able to correctly set the control point.\n" "Reason:\n" + QString::fromStdString(exceptionMessage.str() + "\n")); msgBox.exec(); } if (!allSpecificImages.empty()) { // examination period - information type cell is already taken // ask if cell should be overwritten QMessageBox::StandardButton answerButton = QMessageBox::question(nullptr, "Specific image already exists.", QString::fromStdString("Force overwriting existing image " + informationType + " at " + examinationPeriod.name + "?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if (answerButton == QMessageBox::Yes) { try { // remove already existent images at specific cell for (const auto& specificImage : allSpecificImages) { - RemoveFromSemanticRelationsAction::Run(m_SemanticRelationsIntegration.get(), m_DataStorage.Lock(), specificImage); + RemoveFromSemanticRelationsAction::Run(dataStorage, specificImage); } } catch (const mitk::SemanticRelationException& e) { std::stringstream exceptionMessage; exceptionMessage << e; QMessageBox msgBox(QMessageBox::Warning, "Could not set the control point.", "The program wasn't able to correctly set the control point.\n" "Reason:\n" + QString::fromStdString(exceptionMessage.str() + "\n")); msgBox.exec(); } } else { // else case is: no overwriting return; } } // specific image does not exist or has been removed; setting the control point should work + mitk::SemanticRelationsIntegration semanticRelationsIntegration; try { - m_SemanticRelationsIntegration->UnlinkImageFromControlPoint(dataNode); - m_SemanticRelationsIntegration->SetControlPointOfImage(dataNode, controlPoint); + semanticRelationsIntegration.UnlinkImageFromControlPoint(dataNode); + semanticRelationsIntegration.SetControlPointOfImage(dataNode, controlPoint); } catch (const mitk::SemanticRelationException& e) { std::stringstream exceptionMessage; exceptionMessage << e; QMessageBox msgBox(QMessageBox::Warning, "Could not set the control point.", "The program wasn't able to correctly set the control point.\n" "Reason:\n" + QString::fromStdString(exceptionMessage.str() + "\n")); msgBox.exec(); } } diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetControlPointAction.h b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetControlPointAction.h index 625e707e92..b11eddbb9b 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetControlPointAction.h +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetControlPointAction.h @@ -1,49 +1,47 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKDATANODESETCONTROLPOINTACTION_H #define QMITKDATANODESETCONTROLPOINTACTION_H -// mitk gui qt semanticrelations plugin -#include "QmitkAbstractSemanticRelationsAction.h" +// mitk gui qt application plugin +#include // qt #include -class QmitkDataNodeSetControlPointAction : public QAction, public QmitkAbstractSemanticRelationsAction +class QmitkDataNodeSetControlPointAction : public QAction, public QmitkAbstractDataNodeAction { Q_OBJECT public: QmitkDataNodeSetControlPointAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); QmitkDataNodeSetControlPointAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite); - virtual ~QmitkDataNodeSetControlPointAction() override; - private Q_SLOTS: void OnActionTriggered(bool); protected: virtual void InitializeAction() override; QWidget* m_Parent; }; #endif // QMITKDATANODESETCONTROLPOINTACTION_H diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetInformationTypeAction.cpp b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetInformationTypeAction.cpp index 4075650f6f..f5fc1816fe 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetInformationTypeAction.cpp +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetInformationTypeAction.cpp @@ -1,171 +1,165 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // semantic relations plugin #include "QmitkDataNodeSetInformationTypeAction.h" #include "QmitkDataNodeRemoveFromSemanticRelationsAction.h" // semantic relations module #include #include -#include #include +#include #include +#include // qt #include #include QmitkDataNodeSetInformationTypeAction::QmitkDataNodeSetInformationTypeAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite) : QAction(parent) - , QmitkAbstractSemanticRelationsAction(workbenchPartSite) + , QmitkAbstractDataNodeAction(workbenchPartSite) { setText(tr("Set information type")); m_Parent = parent; InitializeAction(); } QmitkDataNodeSetInformationTypeAction::QmitkDataNodeSetInformationTypeAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite) : QAction(parent) - , QmitkAbstractSemanticRelationsAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) { setText(tr("Set information type")); m_Parent = parent; InitializeAction(); } -QmitkDataNodeSetInformationTypeAction::~QmitkDataNodeSetInformationTypeAction() -{ - // nothing here -} - void QmitkDataNodeSetInformationTypeAction::InitializeAction() { connect(this, &QAction::triggered, this, &QmitkDataNodeSetInformationTypeAction::OnActionTriggered); } void QmitkDataNodeSetInformationTypeAction::OnActionTriggered(bool /*checked*/) { - if (nullptr == m_SemanticRelationsIntegration) - { - return; - } - if (m_DataStorage.IsExpired()) { return; } + auto dataStorage = m_DataStorage.Lock(); + auto dataNode = GetSelectedNode(); if (dataNode.IsNull()) { return; } QInputDialog* inputDialog = new QInputDialog(m_Parent); inputDialog->setWindowTitle(tr("Set information type of selected node")); inputDialog->setLabelText(tr("Information type:")); inputDialog->setTextValue(QString::fromStdString(mitk::SemanticRelationsInference::GetInformationTypeOfImage(dataNode))); inputDialog->setMinimumSize(250, 100); int dialogReturnValue = inputDialog->exec(); if (QDialog::Rejected == dialogReturnValue) { return; } mitk::SemanticTypes::InformationType informationType = inputDialog->textValue().toStdString(); mitk::SemanticTypes::ExaminationPeriod examinationPeriod; mitk::SemanticTypes::ControlPoint controlPoint; mitk::SemanticRelationsDataStorageAccess::DataNodeVector allSpecificImages; try { mitk::SemanticTypes::CaseID caseID = mitk::GetCaseIDFromDataNode(dataNode); controlPoint = mitk::SemanticRelationsInference::GetControlPointOfImage(dataNode); // see if the examination period - information type cell is already taken examinationPeriod = mitk::FindFittingExaminationPeriod(caseID, controlPoint); - auto semanticRelationsDataStorageAccess = mitk::SemanticRelationsDataStorageAccess(m_DataStorage.Lock()); + auto semanticRelationsDataStorageAccess = mitk::SemanticRelationsDataStorageAccess(dataStorage); try { allSpecificImages = semanticRelationsDataStorageAccess.GetAllSpecificImages(caseID, informationType, examinationPeriod); } catch (const mitk::SemanticRelationException&) { // just continue since an exception means that there is no specific image } } catch (const mitk::SemanticRelationException& e) { std::stringstream exceptionMessage; exceptionMessage << e; QMessageBox msgBox(QMessageBox::Warning, "Could not set the information type.", "The program wasn't able to correctly set the information type.\n" "Reason:\n" + QString::fromStdString(exceptionMessage.str() + "\n")); msgBox.exec(); } if (!allSpecificImages.empty()) { // examination period - information type cell is already taken // ask if cell should be overwritten QMessageBox::StandardButton answerButton = QMessageBox::question(nullptr, "Specific image already exists.", QString::fromStdString("Force overwriting existing image " + informationType + " at " + examinationPeriod.name + "?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if (answerButton == QMessageBox::Yes) { try { // remove already existent images at specific cell for (const auto& specificImage : allSpecificImages) { - RemoveFromSemanticRelationsAction::Run(m_SemanticRelationsIntegration.get(), m_DataStorage.Lock(), specificImage); + RemoveFromSemanticRelationsAction::Run(dataStorage, specificImage); } } catch (const mitk::SemanticRelationException& e) { std::stringstream exceptionMessage; exceptionMessage << e; QMessageBox msgBox(QMessageBox::Warning, "Could not set the information type.", "The program wasn't able to correctly set the information type.\n" "Reason:\n" + QString::fromStdString(exceptionMessage.str() + "\n")); msgBox.exec(); } } else { // else case is: no overwriting return; } } + mitk::SemanticRelationsIntegration semanticRelationsIntegration; try { - m_SemanticRelationsIntegration->SetInformationType(dataNode, informationType); + semanticRelationsIntegration.SetInformationType(dataNode, informationType); } catch (const mitk::SemanticRelationException& e) { std::stringstream exceptionMessage; exceptionMessage << e; QMessageBox msgBox(QMessageBox::Warning, "Could not set the information type.", "The program wasn't able to correctly set the information type.\n" "Reason:\n" + QString::fromStdString(exceptionMessage.str() + "\n")); msgBox.exec(); } } diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetInformationTypeAction.h b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetInformationTypeAction.h index 618b5d7f55..472def3765 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetInformationTypeAction.h +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeSetInformationTypeAction.h @@ -1,49 +1,47 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKDATANODESETINFORMATIONTYPEACTION_H #define QMITKDATANODESETINFORMATIONTYPEACTION_H // mitk gui qt application plugin -#include "QmitkAbstractSemanticRelationsAction.h" +#include // qt #include -class QmitkDataNodeSetInformationTypeAction : public QAction, public QmitkAbstractSemanticRelationsAction +class QmitkDataNodeSetInformationTypeAction : public QAction, public QmitkAbstractDataNodeAction { Q_OBJECT public: QmitkDataNodeSetInformationTypeAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); QmitkDataNodeSetInformationTypeAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite); - virtual ~QmitkDataNodeSetInformationTypeAction() override; - private Q_SLOTS: void OnActionTriggered(bool); protected: virtual void InitializeAction() override; QWidget* m_Parent; }; #endif // QMITKDATANODESETINFORMATIONTYPEACTION_H diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeUnlinkFromLesionAction.cpp b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeUnlinkFromLesionAction.cpp index c01e1301b0..3c1619e8f3 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeUnlinkFromLesionAction.cpp +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeUnlinkFromLesionAction.cpp @@ -1,102 +1,94 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // semantic relations plugin #include "QmitkDataNodeUnlinkFromLesionAction.h" // semantic relations module #include #include +#include #include // mitk gui common plugin #include // qt #include // namespace that contains the concrete action namespace UnlinkFromLesionAction { - void Run(mitk::SemanticRelationsIntegration* semanticRelationsIntegration, const mitk::DataNode* dataNode) + void Run(const mitk::DataNode* dataNode) { if (nullptr == dataNode) { return; } if (mitk::NodePredicates::GetSegmentationPredicate()->CheckNode(dataNode)) { + mitk::SemanticRelationsIntegration semanticRelationsIntegration; try { - semanticRelationsIntegration->UnlinkSegmentationFromLesion(dataNode); + semanticRelationsIntegration.UnlinkSegmentationFromLesion(dataNode); } catch (const mitk::SemanticRelationException& e) { std::stringstream exceptionMessage; exceptionMessage << e; QMessageBox msgBox(QMessageBox::Warning, "Could not unlink the selected segmentation.", "The program wasn't able to correctly unlink the selected segmentation.\n" "Reason:\n" + QString::fromStdString(exceptionMessage.str())); msgBox.exec(); } } else { QMessageBox msgBox(QMessageBox::Warning, "Could not unlink the selected data node.", "Please chose a valid segmentation to unlink from its represented lesion!"); msgBox.exec(); } } } QmitkDataNodeUnlinkFromLesionAction::QmitkDataNodeUnlinkFromLesionAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite) : QAction(parent) - , QmitkAbstractSemanticRelationsAction(workbenchPartSite) + , QmitkAbstractDataNodeAction(workbenchPartSite) { setText(tr("Unlink from lesion")); InitializeAction(); } QmitkDataNodeUnlinkFromLesionAction::QmitkDataNodeUnlinkFromLesionAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite) : QAction(parent) - , QmitkAbstractSemanticRelationsAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) + , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) { setText(tr("Unlink from lesion")); InitializeAction(); } -QmitkDataNodeUnlinkFromLesionAction::~QmitkDataNodeUnlinkFromLesionAction() -{ - // nothing here -} - void QmitkDataNodeUnlinkFromLesionAction::InitializeAction() { connect(this, &QAction::triggered, this, &QmitkDataNodeUnlinkFromLesionAction::OnActionTriggered); } void QmitkDataNodeUnlinkFromLesionAction::OnActionTriggered(bool /*checked*/) { - if (nullptr == m_SemanticRelationsIntegration) - { - return; - } - auto dataNode = GetSelectedNode(); - UnlinkFromLesionAction::Run(m_SemanticRelationsIntegration.get(), dataNode); + UnlinkFromLesionAction::Run(dataNode); } diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeUnlinkFromLesionAction.h b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeUnlinkFromLesionAction.h index 452d8b39fa..b9e0bf9d18 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeUnlinkFromLesionAction.h +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkDataNodeUnlinkFromLesionAction.h @@ -1,54 +1,52 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKDATANODEUNLINKFROMLESIONACTION_H #define QMITKDATANODEUNLINKFROMLESIONACTION_H #include -// mitk gui qt semanticrelations plugin -#include "QmitkAbstractSemanticRelationsAction.h" +// mitk gui qt application plugin +#include // qt #include namespace UnlinkFromLesionAction { - MITK_GUI_SEMANTICRELATIONS_EXPORT void Run(const mitk::DataNode* dataNode, mitk::SemanticRelationsIntegration* semanticRelationsIntegration); + MITK_GUI_SEMANTICRELATIONS_EXPORT void Run(const mitk::DataNode* dataNode); } -class MITK_GUI_SEMANTICRELATIONS_EXPORT QmitkDataNodeUnlinkFromLesionAction : public QAction, public QmitkAbstractSemanticRelationsAction +class MITK_GUI_SEMANTICRELATIONS_EXPORT QmitkDataNodeUnlinkFromLesionAction : public QAction, public QmitkAbstractDataNodeAction { Q_OBJECT public: QmitkDataNodeUnlinkFromLesionAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); QmitkDataNodeUnlinkFromLesionAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite); - virtual ~QmitkDataNodeUnlinkFromLesionAction() override; - private Q_SLOTS: void OnActionTriggered(bool); protected: virtual void InitializeAction() override; }; #endif // QMITKDATANODEUNLINKFROMLESIONACTION_H diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkFocusOnLesionAction.cpp b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkFocusOnLesionAction.cpp index 33d0a622ce..bd507fdd94 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkFocusOnLesionAction.cpp +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkFocusOnLesionAction.cpp @@ -1,127 +1,126 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // semantic relations plugin #include "QmitkFocusOnLesionAction.h" #include "QmitkLabelSetJumpToAction.h" // mitk core #include #include // render window manager module #include #include // semantic relations module #include -#include #include // qt #include #include QmitkFocusOnLesionAction::QmitkFocusOnLesionAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite) : QAction(parent) , QmitkAbstractDataNodeAction(workbenchPartSite) { setText(tr("Focus on lesion")); InitializeAction(); } QmitkFocusOnLesionAction::QmitkFocusOnLesionAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite) : QAction(parent) , QmitkAbstractDataNodeAction(berry::IWorkbenchPartSite::Pointer(workbenchPartSite)) { setText(tr("Focus on lesion")); InitializeAction(); } void QmitkFocusOnLesionAction::SetSelectedLesion(mitk::SemanticTypes::Lesion selectedLesion) { m_Lesion = selectedLesion; } void QmitkFocusOnLesionAction::InitializeAction() { setCheckable(true); connect(this, &QAction::triggered, this, &QmitkFocusOnLesionAction::OnActionTriggered); SetControlledRenderer(); } void QmitkFocusOnLesionAction::OnActionTriggered(bool /*checked*/) { if (m_WorkbenchPartSite.Expired()) { return; } if (m_DataStorage.IsExpired()) { return; } auto dataStorage = m_DataStorage.Lock(); auto renderWindowLayerController = std::make_unique(); renderWindowLayerController->SetDataStorage(dataStorage); // check each renderer to see if it contains a segmentation represented by the currently selected lesion for (const auto& renderer : m_ControlledRenderer) { // get currently fixed layer nodes of the specified renderer auto layerStack = mitk::RenderWindowLayerUtilities::GetLayerStack(dataStorage, renderer, true); // check each node to see if it is a segmentation represented by the currently selected lesion for (const auto& layer : layerStack) { auto dataNode = layer.second; bool isVisible = false; if (dataNode.IsNotNull()) { dataNode->GetBoolProperty("visible", isVisible, renderer); } // only focus in renderer where the segmentation is visible if (!isVisible) { continue; } auto currentLesion = mitk::SemanticRelationsInference::GetLesionOfSegmentation(dataNode); if (currentLesion.UID == m_Lesion.UID) { // jump to this lesion in the specified renderer LabelSetJumpToAction::Run(m_WorkbenchPartSite.Lock(), dataNode, renderer); } } } } void QmitkFocusOnLesionAction::SetControlledRenderer() { const mitk::RenderingManager::RenderWindowVector allRegisteredRenderWindows = mitk::RenderingManager::GetInstance()->GetAllRegisteredRenderWindows(); mitk::BaseRenderer *baseRenderer = nullptr; m_ControlledRenderer.clear(); for (const auto& renderWindow : allRegisteredRenderWindows) { baseRenderer = mitk::BaseRenderer::GetInstance(renderWindow); if (nullptr != baseRenderer) { m_ControlledRenderer.push_back(baseRenderer); } } } diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkFocusOnLesionAction.h b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkFocusOnLesionAction.h index d7e7b13efc..7f01b292fb 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkFocusOnLesionAction.h +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkFocusOnLesionAction.h @@ -1,55 +1,56 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef QMITKLESIONSHOWINACTION_H #define QMITKLESIONSHOWINACTION_H -#include "QmitkAbstractDataNodeAction.h" +// mitk gui qt application plugin +#include // semantic relations module #include // qt #include class QmitkFocusOnLesionAction : public QAction, public QmitkAbstractDataNodeAction { Q_OBJECT public: typedef std::vector RendererVector; QmitkFocusOnLesionAction(QWidget* parent, berry::IWorkbenchPartSite::Pointer workbenchPartSite); QmitkFocusOnLesionAction(QWidget* parent, berry::IWorkbenchPartSite* workbenchPartSite); void SetSelectedLesion(mitk::SemanticTypes::Lesion selectedLesion); private Q_SLOTS: void OnActionTriggered(bool); protected: virtual void InitializeAction() override; void SetControlledRenderer(); RendererVector m_ControlledRenderer; mitk::SemanticTypes::Lesion m_Lesion; }; #endif // QMITKLESIONSHOWINACTION_H diff --git a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkSemanticRelationsView.cpp b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkSemanticRelationsView.cpp index 23ecd6ce1b..19c4b7c8ba 100644 --- a/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkSemanticRelationsView.cpp +++ b/Plugins/org.mitk.gui.qt.semanticrelations/src/internal/QmitkSemanticRelationsView.cpp @@ -1,295 +1,285 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // semantic relations plugin #include "QmitkSemanticRelationsView.h" #include "QmitkDataNodeAddToSemanticRelationsAction.h" #include "QmitkDataNodeRemoveFromSemanticRelationsAction.h" #include "QmitkLabelSetJumpToAction.h" // semantic relations module #include #include #include #include #include // mitk core #include // mitk qt widgets module #include #include // berry #include #include // qt #include #include #include const std::string QmitkSemanticRelationsView::VIEW_ID = "org.mitk.views.semanticrelations"; void QmitkSemanticRelationsView::SetFocus() { // nothing here } void QmitkSemanticRelationsView::RenderWindowPartActivated(mitk::IRenderWindowPart* renderWindowPart) { if (m_RenderWindowPart != renderWindowPart) { m_RenderWindowPart = renderWindowPart; SetControlledRenderer(); } } void QmitkSemanticRelationsView::RenderWindowPartDeactivated(mitk::IRenderWindowPart* renderWindowPart) { if (m_RenderWindowPart == renderWindowPart) { m_RenderWindowPart = nullptr; SetControlledRenderer(); } } void QmitkSemanticRelationsView::RenderWindowPartInputChanged(mitk::IRenderWindowPart* renderWindowPart) { if (m_RenderWindowPart == renderWindowPart) { SetControlledRenderer(); } } void QmitkSemanticRelationsView::CreateQtPartControl(QWidget* parent) { // create GUI widgets m_Controls.setupUi(parent); m_LesionInfoWidget = new QmitkLesionInfoWidget(GetDataStorage(), GetSite(), parent); m_Controls.gridLayout->addWidget(m_LesionInfoWidget); m_PatientTableInspector = new QmitkPatientTableInspector(parent); m_PatientTableInspector->SetDataStorage(GetDataStorage()); m_Controls.gridLayout->addWidget(m_PatientTableInspector); QGridLayout* dndDataNodeWidgetLayout = new QGridLayout; dndDataNodeWidgetLayout->addWidget(m_PatientTableInspector, 0, 0); dndDataNodeWidgetLayout->setContentsMargins(0, 0, 0, 0); m_DnDDataNodeWidget = new QmitkDnDDataNodeWidget(parent); m_DnDDataNodeWidget->setLayout(dndDataNodeWidgetLayout); m_Controls.gridLayout->addWidget(m_DnDDataNodeWidget); m_ContextMenu = new QmitkSemanticRelationsContextMenu(GetSite(), m_PatientTableInspector); m_ContextMenu->SetDataStorage(GetDataStorage()); mitk::IRenderWindowPart* renderWindowPart = GetRenderWindowPart(); if (nullptr != renderWindowPart) { RenderWindowPartActivated(renderWindowPart); } SetUpConnections(); const auto& allCaseIDs = mitk::RelationStorage::GetAllCaseIDs(); for (const auto& caseID : allCaseIDs) { AddToComboBox(caseID); } } void QmitkSemanticRelationsView::SetUpConnections() { connect(m_Controls.caseIDComboBox, static_cast(&QComboBox::currentIndexChanged), this, &QmitkSemanticRelationsView::OnCaseIDSelectionChanged); connect(m_LesionInfoWidget, &QmitkLesionInfoWidget::LesionSelectionChanged, this, &QmitkSemanticRelationsView::OnLesionSelectionChanged); connect(m_PatientTableInspector, &QmitkPatientTableInspector::CurrentSelectionChanged, this, &QmitkSemanticRelationsView::OnDataNodeSelectionChanged); connect(m_PatientTableInspector, &QmitkPatientTableInspector::DataNodeDoubleClicked, this, &QmitkSemanticRelationsView::OnDataNodeDoubleClicked); connect(m_DnDDataNodeWidget, &QmitkDnDDataNodeWidget::NodesDropped, this, &QmitkSemanticRelationsView::OnNodesAdded); connect(m_PatientTableInspector, &QmitkPatientTableInspector::OnContextMenuRequested, m_ContextMenu, &QmitkSemanticRelationsContextMenu::OnContextMenuRequested); connect(m_PatientTableInspector, &QmitkPatientTableInspector::OnNodeRemoved, this, &QmitkSemanticRelationsView::NodeRemoved); } QItemSelectionModel* QmitkSemanticRelationsView::GetDataNodeSelectionModel() const { return m_PatientTableInspector->GetSelectionModel(); } void QmitkSemanticRelationsView::NodeRemoved(const mitk::DataNode* dataNode) { if (nullptr == dataNode) { return; } if (mitk::SemanticRelationsInference::InstanceExists(dataNode)) { try { RemoveFromSemanticRelationsAction::Run(GetDataStorage(), dataNode); mitk::SemanticTypes::CaseID caseID = mitk::GetCaseIDFromDataNode(dataNode); RemoveFromComboBox(caseID); } catch (const mitk::SemanticRelationException& e) { std::stringstream exceptionMessage; exceptionMessage << e; QMessageBox msgBox(QMessageBox::Warning, "Could not remove the data node(s).", "The program wasn't able to correctly remove the selected data node(s).\n" "Reason:\n" + QString::fromStdString(exceptionMessage.str() + "\n")); msgBox.exec(); } - // no observer needed for the integration; simply use a temporary instance for removing - mitk::SemanticRelationsIntegration semanticRelationsIntegration; - RemoveFromSemanticRelationsAction::Run(&semanticRelationsIntegration, GetDataStorage(), dataNode); - mitk::SemanticTypes::CaseID caseID = mitk::GetCaseIDFromDataNode(dataNode); - RemoveFromComboBox(caseID); } } void QmitkSemanticRelationsView::OnLesionSelectionChanged(const mitk::SemanticTypes::Lesion& lesion) { m_PatientTableInspector->SetLesion(lesion); } void QmitkSemanticRelationsView::OnDataNodeSelectionChanged(const QList& dataNodeSelection) { m_LesionInfoWidget->SetDataNodeSelection(dataNodeSelection); } void QmitkSemanticRelationsView::OnDataNodeDoubleClicked(const mitk::DataNode* dataNode) { if (nullptr == dataNode) { return; } if (mitk::NodePredicates::GetImagePredicate()->CheckNode(dataNode)) { OpenInEditor(dataNode); } else if (mitk::NodePredicates::GetSegmentationPredicate()->CheckNode(dataNode)) { LabelSetJumpToAction::Run(GetSite(), dataNode); } } void QmitkSemanticRelationsView::OnCaseIDSelectionChanged(const QString& caseID) { m_LesionInfoWidget->SetCaseID(caseID.toStdString()); m_PatientTableInspector->SetCaseID(caseID.toStdString()); } void QmitkSemanticRelationsView::OnNodesAdded(std::vector nodes) { mitk::SemanticTypes::CaseID caseID = ""; for (mitk::DataNode* dataNode : nodes) { try { AddToSemanticRelationsAction::Run(GetDataStorage(), dataNode); caseID = mitk::GetCaseIDFromDataNode(dataNode); AddToComboBox(caseID); } catch (const mitk::SemanticRelationException& e) { std::stringstream exceptionMessage; exceptionMessage << e; QMessageBox msgBox(QMessageBox::Warning, "Could not add the data node(s).", "The program wasn't able to correctly add the selected data node(s).\n" "Reason:\n" + QString::fromStdString(exceptionMessage.str() + "\n")); msgBox.exec(); } - // no observer needed for the integration; simply use a temporary instance for adding - mitk::SemanticRelationsIntegration semanticRelationsIntegration; - AddToSemanticRelationsAction::Run(&semanticRelationsIntegration, GetDataStorage(), dataNode); - caseID = mitk::GetCaseIDFromDataNode(dataNode); - AddToComboBox(caseID); } } void QmitkSemanticRelationsView::OnNodeRemoved(const mitk::DataNode* dataNode) { NodeRemoved(dataNode); } void QmitkSemanticRelationsView::AddToComboBox(const mitk::SemanticTypes::CaseID& caseID) { int foundIndex = m_Controls.caseIDComboBox->findText(QString::fromStdString(caseID)); if (-1 == foundIndex) { // add the caseID to the combo box, as it is not already contained m_Controls.caseIDComboBox->addItem(QString::fromStdString(caseID)); } } void QmitkSemanticRelationsView::RemoveFromComboBox(const mitk::SemanticTypes::CaseID& caseID) { std::vector allControlPoints = mitk::RelationStorage::GetAllControlPointsOfCase(caseID); int foundIndex = m_Controls.caseIDComboBox->findText(QString::fromStdString(caseID)); if (allControlPoints.empty() && -1 != foundIndex) { // caseID does not contain any control points and therefore no data // remove the caseID, if it is still contained m_Controls.caseIDComboBox->removeItem(foundIndex); } } void QmitkSemanticRelationsView::OpenInEditor(const mitk::DataNode* dataNode) { auto renderWindowPart = GetRenderWindowPart(); if (nullptr == renderWindowPart) { renderWindowPart = GetRenderWindowPart(mitk::WorkbenchUtil::IRenderWindowPartStrategy::BRING_TO_FRONT | mitk::WorkbenchUtil::IRenderWindowPartStrategy::OPEN); if (nullptr == renderWindowPart) { // no render window available return; } } auto image = dynamic_cast(dataNode->GetData()); if (nullptr != image) { mitk::RenderingManager::GetInstance()->InitializeViews(image->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true); } } void QmitkSemanticRelationsView::SetControlledRenderer() { QHash renderWindows; if (m_RenderWindowPart != nullptr) { renderWindows = m_RenderWindowPart->GetQmitkRenderWindows(); } mitk::RenderWindowLayerUtilities::RendererVector controlledRenderer; mitk::BaseRenderer* baseRenderer = nullptr; for (const auto& renderWindow : renderWindows.values()) { baseRenderer = mitk::BaseRenderer::GetInstance(renderWindow->GetVtkRenderWindow()); if (nullptr != baseRenderer) { controlledRenderer.push_back(baseRenderer); } } m_ContextMenu->SetControlledRenderer(controlledRenderer); }