From 02d9fed938e32f35724833050a889fa82bfc4a3f Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Tue, 13 Jan 2015 15:44:22 +0000 Subject: [PATCH] Added spectra spinner to res norm Refs #10723 --- .../inc/MantidQtCustomInterfaces/ResNorm.h | 7 ++- .../inc/MantidQtCustomInterfaces/ResNorm.ui | 13 +++- .../MantidQt/CustomInterfaces/src/ResNorm.cpp | 62 +++++++++++-------- 3 files changed, 53 insertions(+), 29 deletions(-) diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ResNorm.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ResNorm.h index 1ed67276dacf..66c0f03b7a16 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ResNorm.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ResNorm.h @@ -32,10 +32,13 @@ namespace MantidQt void maxValueChanged(double max); /// Slot to update the guides when the range properties change void updateProperties(QtProperty* prop, double val); + /// Slot to handle the preview spectrum being changed + void previewSpecChanged(int value); private: - - //The ui form + /// Current preview spectrum + int m_previewSpec; + /// The ui form Ui::ResNorm m_uiForm; }; diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ResNorm.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ResNorm.ui index aa63b5445f16..32184b68ce2f 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ResNorm.ui +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ResNorm.ui @@ -100,7 +100,18 @@ - + + + + + + + + + + + + diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/ResNorm.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/ResNorm.cpp index 54a64894de43..20d7de80cb3c 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/ResNorm.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/ResNorm.cpp @@ -1,13 +1,15 @@ -#include "MantidAPI/TextAxis.h" #include "MantidQtCustomInterfaces/ResNorm.h" #include "MantidQtCustomInterfaces/UserInputValidator.h" +using namespace Mantid::API; + namespace MantidQt { namespace CustomInterfaces { ResNorm::ResNorm(QWidget * parent) : - IndirectBayesTab(parent) + IndirectBayesTab(parent), + m_previewSpec(0) { m_uiForm.setupUi(parent); @@ -44,6 +46,9 @@ namespace MantidQt // Connect data selector to handler method connect(m_uiForm.dsVanadium, SIGNAL(dataReady(const QString&)), this, SLOT(handleVanadiumInputReady(const QString&))); + + // Connect the preview spectrum selector + connect(m_uiForm.spPreviewSpectrum, SIGNAL(valueChanged(int)), this, SLOT(previewSpecChanged(int))); } void ResNorm::setup() @@ -77,8 +82,6 @@ namespace MantidQt */ void ResNorm::run() { - using namespace Mantid::API; - QString verbose("False"); QString save("False"); @@ -107,27 +110,9 @@ namespace MantidQt runPythonScript(pyInput); - // Update mini plot - QString outWsName = VanName.left(VanName.size() - 1) + "_ResNorm_Fit"; - MatrixWorkspace_sptr outputWorkspace = AnalysisDataService::Instance().retrieveWS(outWsName.toStdString()); - TextAxis* axis = dynamic_cast(outputWorkspace->getAxis(1)); - - for(size_t histIndex = 0; histIndex < outputWorkspace->getNumberHistograms(); histIndex++) - { - QString specName = QString::fromStdString(axis->label(histIndex)); - - if(specName.contains("fit")) - { - plotMiniPlot(outputWorkspace, histIndex, "ResNormPlot", specName); - m_curves[specName]->setPen(QColor(Qt::red)); - } - - if(specName.contains("diff")) - { - plotMiniPlot(outputWorkspace, histIndex, "ResNormPlot", specName); - m_curves[specName]->setPen(QColor(Qt::green)); - } - } + // Plot the fit curve + plotMiniPlot("Fit", m_previewSpec, "ResNormPlot", "ResNormFitCurve"); + m_curves["ResNormFitCurve"]->setPen(QColor(Qt::red)); replot("ResNormPlot"); } @@ -152,10 +137,13 @@ namespace MantidQt */ void ResNorm::handleVanadiumInputReady(const QString& filename) { - plotMiniPlot(filename, 0, "ResNormPlot", "RawPlotCurve"); + plotMiniPlot(filename, m_previewSpec, "ResNormPlot", "RawPlotCurve"); std::pair res; std::pair range = getCurveRange("RawPlotCurve"); + MatrixWorkspace_sptr vanWs = AnalysisDataService::Instance().retrieveWS(filename.toStdString()); + m_uiForm.spPreviewSpectrum->setMaximum(static_cast(vanWs->getNumberHistograms()) - 1); + //Use the values from the instrument parameter file if we can if(getInstrumentResolution(filename, res)) { @@ -210,5 +198,27 @@ namespace MantidQt updateUpperGuide(m_rangeSelectors["ResNormERange"], m_properties["EMin"], m_properties["EMax"], val); } } + + /** + * Sets a new preview spectrum for the mini plot. + * + * @parm value Spectrum index + */ + void ResNorm::previewSpecChanged(int value) + { + m_previewSpec = value; + + if(m_uiForm.dsVanadium->isValid()) + plotMiniPlot(m_uiForm.dsVanadium->getCurrentDataName(), m_previewSpec, "ResNormPlot", "RawPlotCurve"); + + if(AnalysisDataService::Instance().doesExist("Fit")) + { + plotMiniPlot("Fit", m_previewSpec, "ResNormPlot", "ResNormFitCurve"); + m_curves["ResNormFitCurve"]->setPen(QColor(Qt::red)); + } + + replot("ResNormPlot"); + } + } // namespace CustomInterfaces } // namespace MantidQt