Skip to content

Commit

Permalink
Added spectra spinner to res norm
Browse files Browse the repository at this point in the history
Refs #10723
  • Loading branch information
DanNixon committed Jan 13, 2015
1 parent 1808fc7 commit 02d9fed
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
Expand Up @@ -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;

};
Expand Down
Expand Up @@ -100,7 +100,18 @@
<layout class="QVBoxLayout" name="treeSpace"/>
</item>
<item>
<layout class="QVBoxLayout" name="plotSpace"/>
<layout class="QVBoxLayout" name="plotPane">
<item>
<layout class="QVBoxLayout" name="plotSpace"/>
</item>
<item>
<layout class="QHBoxLayout" name="underPlotSpace">
<item>
<widget class="QSpinBox" name="spPreviewSpectrum"/>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
Expand Down
62 changes: 36 additions & 26 deletions 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);

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -77,8 +82,6 @@ namespace MantidQt
*/
void ResNorm::run()
{
using namespace Mantid::API;

QString verbose("False");
QString save("False");

Expand Down Expand Up @@ -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<MatrixWorkspace>(outWsName.toStdString());
TextAxis* axis = dynamic_cast<TextAxis*>(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");
}
Expand All @@ -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<double,double> res;
std::pair<double,double> range = getCurveRange("RawPlotCurve");

MatrixWorkspace_sptr vanWs = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(filename.toStdString());
m_uiForm.spPreviewSpectrum->setMaximum(static_cast<int>(vanWs->getNumberHistograms()) - 1);

//Use the values from the instrument parameter file if we can
if(getInstrumentResolution(filename, res))
{
Expand Down Expand Up @@ -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

0 comments on commit 02d9fed

Please sign in to comment.