Skip to content

Commit

Permalink
refs #11630. Insert CutMD.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Apr 24, 2015
1 parent b09daf7 commit f4efc41
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 112 deletions.
Expand Up @@ -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();
Expand Down
Expand Up @@ -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<QString, QString>& 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<Mantid::API::IMDEventWorkspace> m_adsWorkspaceProvider;

QString m_lblInputWorkspace;
QString m_lblOutputWorkspace;
size_t m_binCutOffValue;
const QString m_lblInputWorkspace;
const QString m_lblOutputWorkspace;
QWidget* m_parent;
};

Expand Down
Expand Up @@ -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)
Expand All @@ -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;
};

Expand Down
Expand Up @@ -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);
Expand Down
Expand Up @@ -25,6 +25,8 @@
#include <QHash>
#include "boost/shared_ptr.hpp"

using namespace MantidQt::MantidWidgets;

namespace Mantid
{
namespace Vates
Expand All @@ -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)
{
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<QString, QString> presets;
//Check if a workspace is selected in the dock and set this as a preference for the input workspace
Expand All @@ -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);
Expand All @@ -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<MantidQt::MantidWidgets::BinMDDialog *>(dialog);
MantidQt::MantidWidgets::SliceMDDialog * sliceDialog = dynamic_cast<MantidQt::MantidWidgets::SliceMDDialog *>(dialog);


if (binDialog)
if (SlicingAlgorithmDialog * slicingDialog = dynamic_cast<SlicingAlgorithmDialog *>(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<QString, QString>& 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.
Expand All @@ -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<MantidQt::MantidWidgets::BinMDDialog *>(dialog))
{
newNumberOfBins = QString::number(static_cast<unsigned long long>(m_binCutOffValue));
newNumberOfBins = QString::number(static_cast<unsigned long long>(BinCutOffValue));
}
else
{
Expand Down
80 changes: 39 additions & 41 deletions Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/StandardView.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -77,6 +78,7 @@ StandardView::~StandardView()

void StandardView::setupViewButtons()
{

// Populate the rebin button
QMenu* rebinMenu = new QMenu(this->ui.rebinToolButton);

Expand All @@ -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()),
Expand Down Expand Up @@ -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<QAction*>(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);
}


Expand All @@ -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;
}
Expand All @@ -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);
}
}

Expand Down

0 comments on commit f4efc41

Please sign in to comment.