Skip to content

Commit

Permalink
Work in progress, IndirectBayesTab inherit from IndirectTab
Browse files Browse the repository at this point in the history
Refs #10277
  • Loading branch information
DanNixon committed Oct 8, 2014
1 parent d1a232a commit 6b594b2
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 197 deletions.
Expand Up @@ -2,6 +2,7 @@
#define MANTID_CUSTOMINTERFACES_INDIRECTBAYESTAB_H_

#include "MantidAPI/MatrixWorkspace.h"
#include "MantidQtCustomInterfaces/IndirectTab.h"
#include "MantidQtMantidWidgets/RangeSelector.h"
#include "MantidQtAPI/QwtWorkspaceSpectrumData.h"

Expand Down Expand Up @@ -71,7 +72,7 @@ namespace MantidQt
/// precision for integer properties in bayes tabs
static const unsigned int INT_DECIMALS = 0;

class DLLExport IndirectBayesTab : public QWidget
class DLLExport IndirectBayesTab : public IndirectTab
{
Q_OBJECT

Expand All @@ -84,8 +85,6 @@ namespace MantidQt

/// Base methods implemented in derived classes
virtual QString help() = 0;
virtual bool validate() = 0;
virtual void run() = 0;
virtual void loadSettings(const QSettings& settings) = 0;

signals:
Expand All @@ -94,53 +93,27 @@ 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;
protected slots:
/// Slot to update the guides when the range properties change
void updateProperties(QtProperty* prop, double val);

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 set the range selector on the mini plot
void setMiniPlotGuides(QtProperty* lower, QtProperty* upper, const std::pair<double, double>& bounds);
/// 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
bool getInstrumentResolution(const QString& filename, std::pair<double,double>& res);
/// Function to read an instrument's resolution from the IPF using a workspace pointer
bool getInstrumentResolution(Mantid::API::MatrixWorkspace_const_sptr ws, std::pair<double,double>& res);
/// Function to set the range limits of the plot
void setPlotRange(QtProperty* min, QtProperty* max, const std::pair<double, double>& bounds);
/// Function to set the position of the lower guide on the plot
void updateLowerGuide(QtProperty* lower, QtProperty* upper, double value);
/// Function to set the position of the upper guide on the plot
void updateUpperGuide(QtProperty* lower, QtProperty* upper, double value);
/// 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;
/// Double editor facotry for the properties browser
DoubleEditorFactory* m_dblEdFac;

};
} // namespace CustomInterfaces
} // namespace Mantid

#endif
#endif
Expand Up @@ -43,7 +43,7 @@ namespace CustomInterfaces
/** IndirectTab : TODO: DESCRIPTION
@author Dan Nixon
@date 13/08/2013
@date 08/10/2014
Copyright &copy; 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
Expand Down Expand Up @@ -76,7 +76,7 @@ namespace CustomInterfaces
public slots:
void runTab();
void setupTab();
void validateTab();
bool validateTab();

protected slots:
/// Slot to handle when an algorithm finishes running
Expand Down
Expand Up @@ -17,6 +17,7 @@ namespace MantidQt

// Inherited methods from IndirectBayesTab
QString help() { return "JumpFit"; };
void setup();
bool validate();
void run();
/// Load default settings into the interface
Expand All @@ -28,19 +29,19 @@ namespace MantidQt
/// Slot to handle plotting a different spectrum of the workspace
void handleWidthChange(const QString& text);
/// Slot for when the min range on the range selector changes
virtual void minValueChanged(double min);
void minValueChanged(double min);
/// Slot for when the min range on the range selector changes
virtual void maxValueChanged(double max);
void maxValueChanged(double max);
/// Slot to update the guides when the range properties change
void updateProperties(QtProperty* prop, double val);
/// Find all spectra with width data in the workspace
void findAllWidths(Mantid::API::MatrixWorkspace_const_sptr ws);

private:
//The ui form
// The UI form
Ui::JumpFit m_uiForm;
// map of axis labels to spectrum number
std::map<std::string,int> spectraList;
std::map<std::string, int> spectraList;

};
} // namespace CustomInterfaces
Expand Down
Expand Up @@ -17,16 +17,17 @@ namespace MantidQt

// Inherited methods from IndirectBayesTab
QString help() { return "Quasi"; };
void setup();
bool validate();
void run();
/// Load default settings into the interface
void loadSettings(const QSettings& settings);

private slots:
/// Slot for when the min range on the range selector changes
virtual void minValueChanged(double min);
void minValueChanged(double min);
/// Slot for when the min range on the range selector changes
virtual void maxValueChanged(double max);
void maxValueChanged(double max);
/// Slot to update the guides when the range properties change
void updateProperties(QtProperty* prop, double val);
/// Slot to handle when a new sample file is available
Expand Down
Expand Up @@ -17,6 +17,7 @@ namespace MantidQt

// Inherited methods from IndirectBayesTab
QString help() { return "ResNorm"; };
void setup();
bool validate();
void run();
/// Load default settings into the interface
Expand All @@ -26,9 +27,9 @@ namespace MantidQt
/// 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);
void minValueChanged(double min);
/// Slot for when the min range on the range selector changes
virtual void maxValueChanged(double max);
void maxValueChanged(double max);
/// Slot to update the guides when the range properties change
void updateProperties(QtProperty* prop, double val);

Expand Down
Expand Up @@ -17,16 +17,17 @@ namespace MantidQt

// Inherited methods from IndirectBayesTab
QString help() { return "Stretch"; };
void setup();
bool validate();
void run();
/// Load default settings into the interface
void loadSettings(const QSettings& settings);

private slots:
/// Slot for when the min range on the range selector changes
virtual void minValueChanged(double min);
void minValueChanged(double min);
/// Slot for when the min range on the range selector changes
virtual void maxValueChanged(double max);
void maxValueChanged(double max);
/// Slot to update the guides when the range properties change
void updateProperties(QtProperty* prop, double val);
/// Slot to handle when a new sample file is available
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayes.cpp
Expand Up @@ -110,9 +110,9 @@ void IndirectBayes::runClicked()
{
int tabIndex = m_uiForm.indirectBayesTabs->currentIndex();

if(m_bayesTabs[tabIndex]->validate())
if(m_bayesTabs[tabIndex]->validateTab())
{
m_bayesTabs[tabIndex]->run();
m_bayesTabs[tabIndex]->runTab();
}
}

Expand Down
121 changes: 5 additions & 116 deletions Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayesTab.cpp
Expand Up @@ -12,22 +12,13 @@ namespace MantidQt
//----------------------------------------------------------------------------------------------
/** Constructor
*/
IndirectBayesTab::IndirectBayesTab(QWidget * parent) : QWidget(parent),
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())
IndirectBayesTab::IndirectBayesTab(QWidget * parent) : IndirectTab(parent),
m_propTree(new QtTreePropertyBrowser())
{
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 double maneger signals
connect(m_dblManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(updateProperties(QtProperty*, double)));

// initilise plot
m_plot->setCanvasBackground(Qt::white);
m_plot->setAxisFont(QwtPlot::xBottom, parent->font());
m_plot->setAxisFont(QwtPlot::yLeft, parent->font());
}

//----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -58,62 +49,6 @@ namespace MantidQt
emit executePythonScript(pyInput, true);
}

/**
* Plot a workspace to the miniplot given a workspace name and
* a specturm index.
*
* This method uses the analysis data service to retrieve the workspace.
*
* @param workspace :: The name of the workspace
* @param index :: The spectrum index of the workspace
*/
void IndirectBayesTab::plotMiniPlot(const QString& workspace, size_t index)
{
auto ws = Mantid::API::AnalysisDataService::Instance().retrieveWS<const Mantid::API::MatrixWorkspace>(workspace.toStdString());
plotMiniPlot(ws, index);
}

/**
* Plot a workspace to the miniplot given a workspace pointer and
* a specturm index.
*
* @param workspace :: Pointer to the workspace
* @param wsIndex :: The spectrum index of the workspace
*/
void IndirectBayesTab::plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex)
{
using Mantid::MantidVec;

//check if we can plot
if( wsIndex >= workspace->getNumberHistograms() || workspace->readX(0).size() < 2 )
{
return;
}

QwtWorkspaceSpectrumData wsData(*workspace, static_cast<int>(wsIndex), false);

if ( m_curve != NULL )
{
m_curve->attach(0);
delete m_curve;
m_curve = NULL;
}

size_t nhist = workspace->getNumberHistograms();
if ( wsIndex >= nhist )
{
emit showMessageBox("Error: Workspace index out of range.");
}
else
{
m_curve = new QwtPlotCurve();
m_curve->setData(wsData);
m_curve->attach(m_plot);

m_plot->replot();
}
}

/**
* Checks the workspace's intrument for a resolution parameter to use as
* a default for the energy range on the mini plot
Expand Down Expand Up @@ -155,52 +90,6 @@ namespace MantidQt
return false;
}

/**
* Gets the range of the curve plotted in the mini plot
*
* @return A pair containing the maximum and minimum points of the curve
*/
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));
}

/**
* Sets the edge bounds of plot to prevent the user inputting invalid values
*
* @param min :: The lower bound property in the property browser
* @param max :: The upper bound property in the property browser
* @param bounds :: The upper and lower bounds to be set
*/
void IndirectBayesTab::setPlotRange(QtProperty* min, QtProperty* max, const std::pair<double, double>& bounds)
{
m_dblManager->setMinimum(min, bounds.first);
m_dblManager->setMaximum(min, bounds.second);
m_dblManager->setMinimum(max, bounds.first);
m_dblManager->setMaximum(max, bounds.second);
m_rangeSelector->setRange(bounds.first, bounds.second);
}

/**
* Set the position of the guides on the mini plot
*
* @param lower :: The lower bound property in the property browser
* @param upper :: The upper bound property in the property browser
* @param bounds :: The upper and lower bounds to be set
*/
void IndirectBayesTab::setMiniPlotGuides(QtProperty* lower, QtProperty* upper, const std::pair<double, double>& bounds)
{
m_dblManager->setValue(lower, bounds.first);
m_dblManager->setValue(upper, bounds.second);
m_rangeSelector->setMinimum(bounds.first);
m_rangeSelector->setMaximum(bounds.second);
}

/**
* Set the position of the lower guide on the mini plot
*
Expand All @@ -217,7 +106,7 @@ namespace MantidQt
}
else
{
m_rangeSelector->setMinimum(value);
m_rangeSelectors["BayesRS"]->setMinimum(value);
}
}

Expand All @@ -237,7 +126,7 @@ namespace MantidQt
}
else
{
m_rangeSelector->setMaximum(value);
m_rangeSelectors["BayesRS"]->setMaximum(value);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/CustomInterfaces/src/IndirectTab.cpp
Expand Up @@ -58,7 +58,7 @@ namespace CustomInterfaces
setup();
}

void IndirectTab::validateTab()
bool IndirectTab::validateTab()
{
validate();
}
Expand Down

0 comments on commit 6b594b2

Please sign in to comment.