Skip to content

Commit

Permalink
Refs #5421 Added plotting of energy range and validation for it.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Jackson committed Sep 13, 2013
1 parent 6e76190 commit 2e0eb51
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
#define MANTID_CUSTOMINTERFACES_INDIRECTBAYESTAB_H_

#include "MantidAPI/MatrixWorkspace.h"
#include "MantidQtMantidWidgets/RangeSelector.h"

#include <QMap>
#include <QDoubleValidator>
#include <QtDoublePropertyManager>
#include <QtIntPropertyManager>
#include <QtTreePropertyBrowser>
Expand All @@ -12,6 +14,23 @@
#include <qwt_plot.h>
#include <qwt_plot_curve.h>

// Suppress a warning coming out of code that isn't ours
#if defined(__INTEL_COMPILER)
#pragma warning disable 1125
#elif defined(__GNUC__)
#if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 6 )
#pragma GCC diagnostic push
#endif
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
#endif
#include "DoubleEditorFactory.h"
#if defined(__INTEL_COMPILER)
#pragma warning enable 1125
#elif defined(__GNUC__)
#if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 6 )
#pragma GCC diagnostic pop
#endif
#endif

namespace MantidQt
{
Expand Down Expand Up @@ -47,6 +66,8 @@ namespace MantidQt

/// precision of double properties in bayes tabs
static const unsigned int NUM_DECIMALS = 6;
/// precision for integer properties in bayes tabs
static const unsigned int INT_DECIMALS = 0;

class DLLExport IndirectBayesTab : public QWidget
{
Expand All @@ -70,26 +91,45 @@ namespace MantidQt
/// Send signal to parent window to show a message box to user
void showMessageBox(const QString& message);

protected slots:
/// Slot for when the min range on the range selector changes
virtual void minValueChanged(double min) = 0;
/// Slot for when the min range on the range selector changes
virtual void maxValueChanged(double max) = 0;
/// Slot to handle when a user edits a property
virtual void updateProperties(QtProperty* prop, double val) = 0;
/// Function to set the range selector on the mini plot
void setMiniPlotRange(double min, double max);

protected:
/// Function to plot a workspace to the miniplot using a workspace name
void plotMiniPlot(const QString& workspace, size_t index);
/// Function to plot a workspace to the miniplot using a workspace pointer
void plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex);
/// Function to run a string as python code
void runPythonScript(const QString& pyInput);
/// Function to read an instrument's resolution from the IPF using a string
double getInstrumentResolution(const QString& filename);
/// Function to read an instrument's resolution from the IPF using a workspace pointer
double getInstrumentResolution(Mantid::API::MatrixWorkspace_const_sptr ws);

/// Function to get the range of the curve displayed on the mini plot
std::pair<double,double> getCurveRange();

/// Plot of the input
QwtPlot* m_plot;
/// Curve on the plot
QwtPlotCurve* m_curve;
/// Range selector widget for mini plot
MantidQt::MantidWidgets::RangeSelector* m_rangeSelector;
/// Tree of the properties
QtTreePropertyBrowser* m_propTree;
/// Internal list of the properties
QMap<QString, QtProperty*> m_properties;
/// Double manager to create properties
QtDoublePropertyManager* m_dblManager;
/// Int manager to create properties
QtIntPropertyManager* m_intManager;
/// Double editor facotry for the properties browser
DoubleEditorFactory* m_dblEdFac;

};
} // namespace CustomInterfaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ namespace MantidQt
public:
JumpFit(QWidget * parent = 0);

private slots:
/// Slot for when the min range on the range selector changes
virtual void minValueChanged(double min);
/// Slot for when the min range on the range selector changes
virtual void maxValueChanged(double max);
void updateProperties(QtProperty* prop, double val);

private:
virtual QString help() { return "JumpFit"; };
virtual bool validate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ namespace MantidQt
public:
Quasi(QWidget * parent = 0);

private slots:
/// Slot for when the min range on the range selector changes
virtual void minValueChanged(double min);
/// Slot for when the min range on the range selector changes
virtual void maxValueChanged(double max);
void updateProperties(QtProperty* prop, double val);

private:
virtual QString help() { return "Quasi"; };
virtual bool validate();
virtual void run();

//The ui form
Ui::Quasi m_uiForm;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ namespace MantidQt
private slots:
/// Handle when the vanadium input is ready
void handleVanadiumInputReady(const QString& filename);
/// Slot for when the min range on the range selector changes
virtual void minValueChanged(double min);
/// Slot for when the min range on the range selector changes
virtual void maxValueChanged(double max);
void updateProperties(QtProperty* prop, double val);

private:
/// Inherited methods from IndirectBayesTab
virtual QString help() { return "ResNorm"; };
virtual bool validate();
virtual void run();

//The ui form
Ui::ResNorm m_uiForm;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</property>
<property name="workspaceSuffixes" stdset="0">
<stringlist>
<string>*_red</string>
<string>_red</string>
</stringlist>
</property>
<property name="fileBrowserSuffixes" stdset="0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ namespace MantidQt
public:
Stretch(QWidget * parent = 0);

private slots:
/// Slot for when the min range on the range selector changes
virtual void minValueChanged(double min);
/// Slot for when the min range on the range selector changes
virtual void maxValueChanged(double max);
void updateProperties(QtProperty* prop, double val);

private:
virtual QString help() { return "Stretch"; };
virtual bool validate();
virtual void run();

//The ui form
Ui::Stretch m_uiForm;

Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ IndirectBayes::IndirectBayes(QWidget *parent) : UserSubWindow(parent)
for (iter = m_bayesTabs.begin(); iter != m_bayesTabs.end(); ++iter)
{
connect(iter->second, SIGNAL(executePythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
connect(iter->second, SIGNAL(showMessageBox(const QString&)), this, SIGNAL(showMessageBox(const QString&)));
connect(iter->second, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&)));
}

//Connect statements for the buttons shared between all tabs on the Indirect Bayes interface
Expand Down Expand Up @@ -89,9 +89,9 @@ void IndirectBayes::manageUserDirectories()
*
* @param message :: The message to display in the message box
*/
void showMessageBox(const QString& message)
void IndirectBayes::showMessageBox(const QString& message)
{
showInformationBox(const QString & message);
showInformationBox(message);
}

IndirectBayes::~IndirectBayes()
Expand Down
53 changes: 51 additions & 2 deletions Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayesTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ namespace MantidQt
/** Constructor
*/
IndirectBayesTab::IndirectBayesTab(QWidget * parent) : QWidget(parent),
m_plot(new QwtPlot(parent)), m_curve(new QwtPlotCurve()), m_propTree(new QtTreePropertyBrowser()),
m_properties(), m_dblManager(new QtDoublePropertyManager()), m_intManager(new QtIntPropertyManager())
m_plot(new QwtPlot(parent)), m_curve(new QwtPlotCurve()), m_rangeSelector(new MantidWidgets::RangeSelector(m_plot)),
m_propTree(new QtTreePropertyBrowser()), m_properties(), m_dblManager(new QtDoublePropertyManager()),
m_dblEdFac(new DoubleEditorFactory())
{
m_propTree->setFactoryForManager(m_dblManager, m_dblEdFac);
m_rangeSelector->setInfoOnly(false);

connect(m_rangeSelector, SIGNAL(minValueChanged(double)), this, SLOT(minValueChanged(double)));
connect(m_rangeSelector, SIGNAL(maxValueChanged(double)), this, SLOT(maxValueChanged(double)));
connect(m_dblManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(updateProperties(QtProperty*, double)));
}

//----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -93,5 +100,47 @@ namespace MantidQt
m_plot->replot();
}
}

double IndirectBayesTab::getInstrumentResolution(const QString& workspace)
{
auto ws = Mantid::API::AnalysisDataService::Instance().retrieveWS<const Mantid::API::MatrixWorkspace>(workspace.toStdString());
return getInstrumentResolution(ws);
}

double IndirectBayesTab::getInstrumentResolution(Mantid::API::MatrixWorkspace_const_sptr ws)
{
auto inst = ws->getInstrument();
auto analyser = inst->getStringParameter("analyser");

if(analyser.size() > 0)
{
auto comp = inst->getComponentByName(analyser[0]);
auto params = comp->getNumberParameter("resolution", true);

//set the default instrument resolution
if(params.size() > 0)
{
return params[0];
}
}

return 0;
}

void IndirectBayesTab::setMiniPlotRange(double min, double max)
{
m_rangeSelector->setMinimum(min);
m_rangeSelector->setMaximum(max);
}

std::pair<double,double> IndirectBayesTab::getCurveRange()
{
size_t npts = m_curve->data().size();

if( npts < 2 )
throw std::invalid_argument("Too few points on data curve to determine range.");

return std::make_pair(m_curve->data().x(0), m_curve->data().x(npts-1));
}
}
} // namespace MantidQt
22 changes: 22 additions & 0 deletions Code/Mantid/MantidQt/CustomInterfaces/src/JumpFit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,27 @@ namespace MantidQt
{

}

void JumpFit::minValueChanged(double min)
{
m_dblManager->setValue(m_properties["QMin"], min);
}

void JumpFit::maxValueChanged(double max)
{
m_dblManager->setValue(m_properties["QMax"], max);
}

void JumpFit::updateProperties(QtProperty* prop, double val)
{
if(prop == m_properties["QMin"])
{
m_rangeSelector->setMinimum(val);
}
else if (prop == m_properties["QMax"])
{
m_rangeSelector->setMaximum(val);
}
}
} // namespace CustomInterfaces
} // namespace MantidQt
32 changes: 28 additions & 4 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Quasi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ namespace MantidQt

m_properties["EMin"] = m_dblManager->addProperty("EMin");
m_properties["EMax"] = m_dblManager->addProperty("EMax");
m_properties["SampleBinning"] = m_intManager->addProperty("Sample Binning");
m_properties["ResBinning"] = m_intManager->addProperty("Resolution Binning");
m_properties["SampleBinning"] = m_dblManager->addProperty("Sample Binning");
m_properties["ResBinning"] = m_dblManager->addProperty("Resolution Binning");

m_dblManager->setDecimals(m_properties["EMin"], NUM_DECIMALS);
m_dblManager->setDecimals(m_properties["EMax"], NUM_DECIMALS);
m_dblManager->setDecimals(m_properties["SampleBinning"], INT_DECIMALS);
m_dblManager->setDecimals(m_properties["ResBinning"], INT_DECIMALS);

m_propTree->addProperty(m_properties["EMin"]);
m_propTree->addProperty(m_properties["EMax"]);
m_propTree->addProperty(m_properties["SampleBinning"]);
m_propTree->addProperty(m_properties["ResBinning"]);

//Set default values
m_intManager->setValue(m_properties["SampleBinning"], 1);
m_intManager->setValue(m_properties["ResBinning"], 1);
m_dblManager->setValue(m_properties["SampleBinning"], 1);
m_dblManager->setValue(m_properties["ResBinning"], 1);

//add the plot to the ui form
m_uiForm.plotSpace->addWidget(m_plot);
Expand All @@ -45,5 +47,27 @@ namespace MantidQt
{

}

void Quasi::minValueChanged(double min)
{
m_dblManager->setValue(m_properties["EMin"], min);
}

void Quasi::maxValueChanged(double max)
{
m_dblManager->setValue(m_properties["EMax"], max);
}

void Quasi::updateProperties(QtProperty* prop, double val)
{
if(prop == m_properties["EMin"])
{
m_rangeSelector->setMinimum(val);
}
else if (prop == m_properties["EMax"])
{
m_rangeSelector->setMaximum(val);
}
}
} // namespace CustomInterfaces
} // namespace MantidQt

0 comments on commit 2e0eb51

Please sign in to comment.