From f4efc415b644f63d3a7d487e80da4be7f5393321 Mon Sep 17 00:00:00 2001 From: Owen Arnold Date: Fri, 24 Apr 2015 14:07:47 +0100 Subject: [PATCH] refs #11630. Insert CutMD. --- .../src/SlicingAlgorithmDialog.cpp | 8 +- .../RebinAlgorithmDialogProvider.h | 13 ++- .../StandardView.h | 9 ++- .../ViewBase.h | 2 +- .../src/RebinAlgorithmDialogProvider.cpp | 76 +++++------------- .../ViewWidgets/src/StandardView.cpp | 80 +++++++++---------- 6 files changed, 76 insertions(+), 112 deletions(-) diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/SlicingAlgorithmDialog.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/SlicingAlgorithmDialog.cpp index 61a4e257246b..7a157fe63bee 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/src/SlicingAlgorithmDialog.cpp +++ b/Code/Mantid/MantidQt/MantidWidgets/src/SlicingAlgorithmDialog.cpp @@ -442,12 +442,12 @@ namespace MantidQt ui.file_backend_layout->setVisible(false); // Output workspace - ui.lbl_workspace_output->setVisible(false); - ui.txt_output->setVisible(false); + ui.lbl_workspace_output->setDisabled(true); + ui.txt_output->setDisabled(true); // Input workspace - ui.workspace_selector->setVisible(false); - ui.lbl_workspace_input->setVisible(false); + ui.workspace_selector->setDisabled(true); + ui.lbl_workspace_input->setDisabled(true); // Reset the input workspace ui.workspace_selector->clear(); diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/RebinAlgorithmDialogProvider.h b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/RebinAlgorithmDialogProvider.h index 5d9768accfc6..7a98cdc0b49a 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/RebinAlgorithmDialogProvider.h +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/RebinAlgorithmDialogProvider.h @@ -51,22 +51,21 @@ namespace Mantid void showDialog(std::string inputWorkspace, std::string outputWorkspace, std::string algorithmType); - private: - MantidQt::API::AlgorithmDialog* createDialog(Mantid::API::IAlgorithm_sptr algorithm, std::string inputWorkspace, std::string outputWorkspace, std::string algorithmType); + static const size_t BinCutOffValue; - void getPresetsForSliceMDAlgorithmDialog( std::string inputWorkspace, std::string outputWorkspace, QHash& presets); + private: + MantidQt::API::AlgorithmDialog* createDialog(Mantid::API::IAlgorithm_sptr algorithm, const std::string& inputWorkspace, const std::string& outputWorkspace, const std::string& algorithmType); void setAxisDimensions(MantidQt::MantidWidgets::SlicingAlgorithmDialog* dialog, std::string inputWorkspace); - Mantid::API::IMDEventWorkspace_sptr getWorkspace(std::string workspaceName); + Mantid::API::IMDEventWorkspace_sptr getWorkspace(const std::string& workspaceName); Mantid::API::IAlgorithm_sptr createAlgorithm(const std::string& algName, int version); Mantid::VATES::ADSWorkspaceProvider m_adsWorkspaceProvider; - QString m_lblInputWorkspace; - QString m_lblOutputWorkspace; - size_t m_binCutOffValue; + const QString m_lblInputWorkspace; + const QString m_lblOutputWorkspace; QWidget* m_parent; }; diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/StandardView.h b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/StandardView.h index 4dee0413a3c6..90f50b68b418 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/StandardView.h +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/StandardView.h @@ -88,9 +88,7 @@ protected slots: /// Invoke the ScaleWorkspace on the current dataset. void onScaleButtonClicked(); /// On BinMD button clicked - void onBinMD(); - /// On SliceMD button clicked - void onSliceMD(); + void onRebin(); private: Q_DISABLE_COPY(StandardView) @@ -104,9 +102,14 @@ protected slots: void setRebinAndUnbinButtons(); /// Set up the buttons void setupViewButtons(); + /// Give the user the ability to rebin + void allowRebinningOptions(bool allow); + /// Allow the user the ability to unbin + void allowUnbinOption(bool allow); QAction* m_binMDAction; QAction* m_sliceMDAction; + QAction* m_cutMDAction; QAction* m_unbinAction; }; diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h index 93ce9a1c73b2..dde71f375027 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h @@ -219,7 +219,7 @@ public slots: */ void unbin(); /** - * Singal to tell other elements that the log scale was altered programatically + * Signal to tell other elements that the log scale was altered programatically * @param state flag wheter or not to enable the */ void setLogScale(bool state); diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/RebinAlgorithmDialogProvider.cpp b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/RebinAlgorithmDialogProvider.cpp index 494f211d0224..611150b1d375 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/RebinAlgorithmDialogProvider.cpp +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/RebinAlgorithmDialogProvider.cpp @@ -25,6 +25,8 @@ #include #include "boost/shared_ptr.hpp" +using namespace MantidQt::MantidWidgets; + namespace Mantid { namespace Vates @@ -37,10 +39,11 @@ namespace Mantid Mantid::Kernel::Logger g_log("RebinAlgorithmDialogProvider"); } + const size_t RebinAlgorithmDialogProvider::BinCutOffValue = 50; + RebinAlgorithmDialogProvider::RebinAlgorithmDialogProvider(QWidget* parent) : m_lblInputWorkspace("InputWorkspace"), m_lblOutputWorkspace("OutputWorkspace"), - m_binCutOffValue(50), m_parent(parent) { } @@ -82,7 +85,7 @@ namespace Mantid * @param workspaceName The name of the input workspace. * @returns A pointer to the current event workspace */ - Mantid::API::IMDEventWorkspace_sptr RebinAlgorithmDialogProvider::getWorkspace(std::string workspaceName) + Mantid::API::IMDEventWorkspace_sptr RebinAlgorithmDialogProvider::getWorkspace(const std::string& workspaceName) { Mantid::API::IMDEventWorkspace_sptr eventWorkspace; @@ -129,9 +132,9 @@ namespace Mantid * @returns The algorithm dialog */ MantidQt::API::AlgorithmDialog* RebinAlgorithmDialogProvider::createDialog(Mantid::API::IAlgorithm_sptr algorithm, - std::string inputWorkspace, - std::string outputWorkspace, - std::string algorithmType) + const std::string& inputWorkspace, + const std::string& outputWorkspace, + const std::string& algorithmType) { QHash presets; //Check if a workspace is selected in the dock and set this as a preference for the input workspace @@ -140,21 +143,12 @@ namespace Mantid MantidQt::API::AlgorithmDialog* dialog = NULL; - // Set the correct algorithm dialog, Add CutMD here once it is ready. - if (algorithmType == "BinMD") - { - dialog = new MantidQt::MantidWidgets::BinMDDialog(m_parent); - getPresetsForSliceMDAlgorithmDialog(inputWorkspace, outputWorkspace, presets); - } - else if (algorithmType == "SliceMD") - { - dialog = new MantidQt::MantidWidgets::SliceMDDialog(m_parent); - getPresetsForSliceMDAlgorithmDialog(inputWorkspace, outputWorkspace, presets); - } - else - { - return dialog; - } + + MantidQt::API::InterfaceManager interfaceManager; + presets.insert(m_lblInputWorkspace, QString::fromStdString(inputWorkspace)); + presets.insert(m_lblOutputWorkspace, QString::fromStdString(outputWorkspace)); + + dialog = interfaceManager.createDialogFromName(QString::fromStdString(algorithmType), -1, m_parent, false, presets); // The parent so that the dialog appears on top of it dialog->setParent(m_parent); @@ -166,48 +160,18 @@ namespace Mantid flags |= Qt::WindowContextHelpButtonHint; dialog->setWindowFlags(flags); - dialog->setAlgorithm(algorithm); - dialog->setPresetValues(presets); - dialog->setOptionalMessage(QString(algorithm->summary().c_str())); - - MantidQt::MantidWidgets::BinMDDialog * binDialog = dynamic_cast(dialog); - MantidQt::MantidWidgets::SliceMDDialog * sliceDialog = dynamic_cast(dialog); - - - if (binDialog) + if (SlicingAlgorithmDialog * slicingDialog = dynamic_cast(dialog)) { - binDialog->initializeLayout(); - binDialog->customiseLayoutForVsi(inputWorkspace); + + slicingDialog->customiseLayoutForVsi(inputWorkspace); // Setup the values of the axis dimensions - setAxisDimensions(binDialog, inputWorkspace); - } - else if (sliceDialog) - { - sliceDialog->initializeLayout(); - sliceDialog->customiseLayoutForVsi(inputWorkspace); - - // Setup the values of the axis dimensions - setAxisDimensions(sliceDialog, inputWorkspace); + setAxisDimensions(slicingDialog, inputWorkspace); } return dialog; } - /** - * Determine the preset values - * @param inputWorkspace The name of the input workspace. - * @param outputWorkspace The name of the output workspace. - * @param presets A container for the preset values. - */ - void RebinAlgorithmDialogProvider::getPresetsForSliceMDAlgorithmDialog(std::string inputWorkspace, std::string outputWorkspace, QHash& presets) - { - // Set the input workspace - presets.insert(QString(m_lblInputWorkspace),QString::fromStdString(inputWorkspace)); - - // Set the output workspace - presets.insert(QString(m_lblOutputWorkspace),QString::fromStdString(outputWorkspace)); - } /** * Resets the aligned dimensions properties in a SlicingAlgorithmDialog. @@ -232,12 +196,12 @@ namespace Mantid // Check the bins size QString newNumberOfBins; - if (numberOfBins < m_binCutOffValue && index < 3) + if (numberOfBins < BinCutOffValue && index < 3) { // Only do this for BinMD, it is too costly for SliceMD to have very large cuts if (dynamic_cast(dialog)) { - newNumberOfBins = QString::number(static_cast(m_binCutOffValue)); + newNumberOfBins = QString::number(static_cast(BinCutOffValue)); } else { diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/StandardView.cpp b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/StandardView.cpp index b273cd4d0522..3ca5befff89d 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/StandardView.cpp +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/StandardView.cpp @@ -43,6 +43,7 @@ namespace SimpleGui */ StandardView::StandardView(QWidget *parent) : ViewBase(parent),m_binMDAction(NULL), m_sliceMDAction(NULL), + m_cutMDAction(NULL), m_unbinAction(NULL) { this->ui.setupUi(this); @@ -77,6 +78,7 @@ StandardView::~StandardView() void StandardView::setupViewButtons() { + // Populate the rebin button QMenu* rebinMenu = new QMenu(this->ui.rebinToolButton); @@ -86,21 +88,26 @@ void StandardView::setupViewButtons() m_sliceMDAction = new QAction("SliceMD", rebinMenu); m_sliceMDAction->setIconVisibleInMenu(false); + m_cutMDAction = new QAction("CutMD", rebinMenu); + m_cutMDAction->setIconVisibleInMenu(false); m_unbinAction = new QAction("Remove Rebinning", rebinMenu); m_unbinAction->setIconVisibleInMenu(false); rebinMenu->addAction(m_binMDAction); rebinMenu->addAction(m_sliceMDAction); + rebinMenu->addAction(m_cutMDAction); rebinMenu->addAction(m_unbinAction); this->ui.rebinToolButton->setPopupMode(QToolButton::InstantPopup); this->ui.rebinToolButton->setMenu(rebinMenu); QObject::connect(m_binMDAction, SIGNAL(triggered()), - this, SLOT(onBinMD()), Qt::QueuedConnection); + this, SLOT(onRebin()), Qt::QueuedConnection); QObject::connect(m_sliceMDAction, SIGNAL(triggered()), - this, SLOT(onSliceMD()), Qt::QueuedConnection); + this, SLOT(onRebin()), Qt::QueuedConnection); + QObject::connect(m_cutMDAction, SIGNAL(triggered()), + this, SLOT(onRebin()), Qt::QueuedConnection); // Set the unbinbutton to remove the rebinning on a workspace // which was binned in the VSI QObject::connect(m_unbinAction, SIGNAL(triggered()), @@ -252,55 +259,50 @@ void StandardView::setRebinAndUnbinButtons() { if (isTemporaryWorkspace(*source)) { - numberOfTemporaryWorkspaces++; + ++numberOfTemporaryWorkspaces; } else if (isMDHistoWorkspace(*source)) { - numberOfTrueMDHistoWorkspaces++; + ++numberOfTrueMDHistoWorkspaces; } else if (isPeaksWorkspace(*source)) { - numberOfPeakWorkspaces++; + ++numberOfPeakWorkspaces; } } // If there are any true MDHisto workspaces then the rebin button should be disabled - if (numberOfTrueMDHistoWorkspaces > 0 || numberOfPeakWorkspaces > 0) - { - this->m_binMDAction->setEnabled(false); - this->m_sliceMDAction->setEnabled(false); - } - else - { - this->m_binMDAction->setEnabled(true); - this->m_sliceMDAction->setEnabled(true); - } + bool allowRebinning = numberOfTrueMDHistoWorkspaces > 0 || numberOfPeakWorkspaces > 0; + this->allowRebinningOptions(allowRebinning); // If there are no temporary workspaces the button should be disabled. - if (numberOfTemporaryWorkspaces == 0) - { - this->m_unbinAction->setEnabled(false); - } - else - { - this->m_unbinAction->setEnabled(true); - } + const bool allowUnbin = !( numberOfTemporaryWorkspaces == 0 ); + allowUnbinOption(allowUnbin); } /** * Reacts to the user selecting the BinMD algorithm */ -void StandardView::onBinMD() +void StandardView::onRebin() { - emit rebin("BinMD"); + if(QAction* action = dynamic_cast(sender())) { + emit rebin(action->text().toStdString()); } } /** - * Reacts to the user selecting the SliceMD algorithm - */ -void StandardView::onSliceMD() -{ - emit rebin("SliceMD"); +Disable rebinning options +*/ +void StandardView::allowRebinningOptions(bool allow) { + this->m_binMDAction->setEnabled(allow); + this->m_sliceMDAction->setEnabled(allow); + this->m_cutMDAction->setEnabled(allow); +} + +/** +Enable unbin option +*/ +void StandardView::allowUnbinOption(bool allow) { + this->m_unbinAction->setEnabled(allow); } @@ -313,8 +315,7 @@ void StandardView::activeSourceChangeListener(pqPipelineSource* source) // If there is no active source, then we do not allow rebinning if (!source) { - this->m_binMDAction->setEnabled(false); - this->m_sliceMDAction->setEnabled(false); + this->allowRebinningOptions(false); this->m_unbinAction->setEnabled(false); return; } @@ -334,21 +335,18 @@ void StandardView::activeSourceChangeListener(pqPipelineSource* source) std::string workspaceType(localSource->getProxy()->GetXMLName()); if (isTemporaryWorkspace(localSource)) { - this->m_binMDAction->setEnabled(true); - this->m_sliceMDAction->setEnabled(true); - this->m_unbinAction->setEnabled(true); + this->allowRebinningOptions(true); + this->allowUnbinOption(true); } else if (workspaceType.find("MDEW Source") != std::string::npos) { - this->m_binMDAction->setEnabled(true); - this->m_sliceMDAction->setEnabled(true); - this->m_unbinAction->setEnabled(false); + this->allowRebinningOptions(true); + this->allowUnbinOption(true); } else { - this->m_binMDAction->setEnabled(false); - this->m_sliceMDAction->setEnabled(false); - this->m_unbinAction->setEnabled(false); + this->allowRebinningOptions(false); + this->allowUnbinOption(false); } }