diff --git a/Plugins/org.mitk.gui.qt.photoacoustics.pausmotioncompensation/src/internal/PAUSMotionCompensation.cpp b/Plugins/org.mitk.gui.qt.photoacoustics.pausmotioncompensation/src/internal/PAUSMotionCompensation.cpp index 932c8800a6..9179a10ae4 100644 --- a/Plugins/org.mitk.gui.qt.photoacoustics.pausmotioncompensation/src/internal/PAUSMotionCompensation.cpp +++ b/Plugins/org.mitk.gui.qt.photoacoustics.pausmotioncompensation/src/internal/PAUSMotionCompensation.cpp @@ -1,102 +1,111 @@ /*=================================================================== 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. ===================================================================*/ - // Blueberry #include #include // Qmitk #include "PAUSMotionCompensation.h" // Qt #include // mitk image #include const std::string PAUSMotionCompensation::VIEW_ID = "org.mitk.views.pausmotioncompensation"; void PAUSMotionCompensation::SetFocus() { m_Controls.buttonPerformImageProcessing->setFocus(); } void PAUSMotionCompensation::CreateQtPartControl(QWidget *parent) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi(parent); - connect(m_Controls.buttonPerformImageProcessing, &QPushButton::clicked, this, &PAUSMotionCompensation::DoImageProcessing); + connect( + m_Controls.buttonPerformImageProcessing, &QPushButton::clicked, this, &PAUSMotionCompensation::DoImageProcessing); } void PAUSMotionCompensation::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*source*/, const QList &nodes) { - // iterate all selected objects, adjust warning visibility - foreach (mitk::DataNode::Pointer node, nodes) + // Make sure that there are exactle 2 nodes selected + if (nodes.size() == 2) { - if (node.IsNotNull() && dynamic_cast(node->GetData())) + // iterate all selected objects, adjust warning visibility + foreach (mitk::DataNode::Pointer node, nodes) { - m_Controls.labelWarning->setVisible(false); - m_Controls.buttonPerformImageProcessing->setEnabled(true); - return; + if (node.IsNotNull() && dynamic_cast(node->GetData())) + { + m_Controls.labelWarning->setVisible(false); + m_Controls.buttonPerformImageProcessing->setEnabled(true); + return; + } } } - m_Controls.labelWarning->setVisible(true); m_Controls.buttonPerformImageProcessing->setEnabled(false); } void PAUSMotionCompensation::DoImageProcessing() { QList nodes = this->GetDataManagerSelection(); - if (nodes.empty()) + + // Make sure that there are two images selected + if (nodes.empty() || nodes.size() != 2) + { + QMessageBox::information(nullptr, "Warning", "Please select two images before starting image processing."); return; + } + //TODO: I need to process two nodes and get the BaseData. mitk::DataNode *node = nodes.front(); if (!node) { // Nothing selected. Inform the user and return QMessageBox::information(nullptr, "Template", "Please load and select an image before starting image processing."); return; } // here we have a valid mitk::DataNode // a node itself is not very useful, we need its data item (the image) mitk::BaseData *data = node->GetData(); if (data) { // test if this data item is an image or not (could also be a surface or something totally different) mitk::Image *image = dynamic_cast(data); if (image) { std::stringstream message; std::string name; message << "Performing image processing for image "; if (node->GetName(name)) { // a property called "name" was found for this DataNode message << "'" << name << "'"; } message << "."; MITK_INFO << message.str(); // actually do something here... } } }