Skip to content

Commit

Permalink
Refs #5421 More documentation and refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Jackson committed Sep 17, 2013
1 parent 2e0eb51 commit 6354253
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace MantidQt
/// 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);
void setMiniPlotGuides(QtProperty* lower, QtProperty* upper, const std::pair<double, double>& bounds);

protected:
/// Function to plot a workspace to the miniplot using a workspace name
Expand All @@ -109,10 +109,15 @@ namespace MantidQt
/// 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);
bool getInstrumentResolution(const QString& filename, std::pair<double,double>& res);
/// Function to read an instrument's resolution from the IPF using a workspace pointer
double getInstrumentResolution(Mantid::API::MatrixWorkspace_const_sptr ws);

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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace MantidQt
virtual void minValueChanged(double min);
/// Slot for when the min range on the range selector changes
virtual void maxValueChanged(double max);
/// Slot to update the guides when the range properties change
void updateProperties(QtProperty* prop, double val);

private:
Expand Down
107 changes: 96 additions & 11 deletions Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayesTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,27 @@ namespace MantidQt
}
}

double IndirectBayesTab::getInstrumentResolution(const QString& workspace)
/**
* Checks the workspace's intrument for a resolution parameter to use as
* a default for the energy range on the mini plot
*
* @param workspace :: Name of the workspace to use
* @param res :: The retrieved values for the resolution parameter (if one was found)
*/
bool IndirectBayesTab::getInstrumentResolution(const QString& workspace, std::pair<double,double>& res)
{
auto ws = Mantid::API::AnalysisDataService::Instance().retrieveWS<const Mantid::API::MatrixWorkspace>(workspace.toStdString());
return getInstrumentResolution(ws);
return getInstrumentResolution(ws, res);
}

double IndirectBayesTab::getInstrumentResolution(Mantid::API::MatrixWorkspace_const_sptr ws)
/**
* Checks the workspace's intrument for a resolution parameter to use as
* a default for the energy range on the mini plot
*
* @param workspace :: Pointer to the workspace to use
* @param res :: The retrieved values for the resolution parameter (if one was found)
*/
bool IndirectBayesTab::getInstrumentResolution(Mantid::API::MatrixWorkspace_const_sptr ws, std::pair<double,double>& res)
{
auto inst = ws->getInstrument();
auto analyser = inst->getStringParameter("analyser");
Expand All @@ -120,19 +134,19 @@ namespace MantidQt
//set the default instrument resolution
if(params.size() > 0)
{
return params[0];
res = std::make_pair(-params[0], params[0]);
return true;
}
}

return 0;
}

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

/**
* Gets the range of the curve plotted in the mini plot
*
* @param A pair containing the maximum and minimum points of the curve
*/
std::pair<double,double> IndirectBayesTab::getCurveRange()
{
size_t npts = m_curve->data().size();
Expand All @@ -142,5 +156,76 @@ namespace MantidQt

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
*
* @param lower :: The lower guide property in the property browser
* @param upper :: The upper guide property in the property browser
* @param value :: The value of the lower guide
*/
void IndirectBayesTab::updateLowerGuide(QtProperty* lower, QtProperty* upper, double value)
{
// Check if the user is setting the max less than the min
if(value > m_dblManager->value(upper))
{
m_dblManager->setValue(lower, m_dblManager->value(upper));
}
else
{
m_rangeSelector->setMinimum(value);
}
}

/**
* Set the position of the upper guide on the mini plot
*
* @param lower :: The lower guide property in the property browser
* @param upper :: The upper guide property in the property browser
* @param value :: The value of the upper guide
*/
void IndirectBayesTab::updateUpperGuide(QtProperty* lower, QtProperty* upper, double value)
{
// Check if the user is setting the min greater than the max
if(value < m_dblManager->value(lower))
{
m_dblManager->setValue(upper, m_dblManager->value(lower));
}
else
{
m_rangeSelector->setMaximum(value);
}
}
}
} // namespace MantidQt
70 changes: 34 additions & 36 deletions Code/Mantid/MantidQt/CustomInterfaces/src/ResNorm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ namespace MantidQt
bool ResNorm::validate()
{
//check we have files/workspaces available to run with
if(m_uiForm.dsResolution->getCurrentDataName().isEmpty() ||
m_uiForm.dsVanadium->getCurrentDataName().isEmpty())
if(m_uiForm.dsVanadium->getCurrentDataName().isEmpty())
{
emit showMessageBox("Please correct the following:\n Could not find the specified reduction file");
return false;
}
if(m_uiForm.dsResolution->getCurrentDataName().isEmpty())
{
emit showMessageBox("Please correct the following:\n Could not find the specified resolution file");
return false;
}

Expand All @@ -68,15 +73,15 @@ namespace MantidQt
QString VanName = m_uiForm.dsVanadium->getCurrentDataName();
QString ResName = m_uiForm.dsResolution->getCurrentDataName();

//get the parameters for ResNomr
// get the parameters for ResNorm
QString EMin = m_properties["EMin"]->valueText();
QString EMax = m_properties["EMax"]->valueText();

QString ERange = "[" + EMin + "," + EMax + "]";

QString nBin = m_properties["VanBinning"]->valueText();

//get output options
// get output options
if(m_uiForm.ckVerbose->isChecked()){ verbose = "True"; }
if(m_uiForm.ckPlot->isChecked()){ plot = "True"; }
if(m_uiForm.ckSave->isChecked()){ save ="True"; }
Expand All @@ -94,65 +99,58 @@ namespace MantidQt
*/
void ResNorm::handleVanadiumInputReady(const QString& filename)
{
double res = getInstrumentResolution(filename);
plotMiniPlot(filename, 0);
std::pair<double, double> range = getCurveRange();
std::pair<double,double> res;
std::pair<double,double> range = getCurveRange();

if(res != 0)
//Use the values from the instrument parameter file if we can
if(getInstrumentResolution(filename, res))
{
m_dblManager->setValue(m_properties["EMin"], -res);
m_dblManager->setValue(m_properties["EMax"], res);
setMiniPlotRange(-res, res);
setMiniPlotGuides(m_properties["EMin"], m_properties["EMax"], res);
}
else
{
m_dblManager->setValue(m_properties["EMin"], range.first);
m_dblManager->setValue(m_properties["EMax"], range.second);
setMiniPlotRange(range.first, range.second);
setMiniPlotGuides(m_properties["EMin"], m_properties["EMax"], range);
}

m_dblManager->setMinimum(m_properties["EMin"], range.first);
m_dblManager->setMaximum(m_properties["EMin"], range.second);
m_dblManager->setMinimum(m_properties["EMax"], range.first);
m_dblManager->setMaximum(m_properties["EMax"], range.second);
m_rangeSelector->setRange(range.first, range.second);
setPlotRange(m_properties["EMin"], m_properties["EMax"], range);
}

/**
* Updates the property manager when the lower guide is moved on the mini plot
*
* @param min :: The new value of the lower guide
*/
void ResNorm::minValueChanged(double min)
{
m_dblManager->setValue(m_properties["EMin"], min);
}

/**
* Updates the property manager when the upper guide is moved on the mini plot
*
* @param max :: The new value of the upper guide
*/
void ResNorm::maxValueChanged(double max)
{
m_dblManager->setValue(m_properties["EMax"], max);
}

/**
* Handles when properties in the property manager are updated.
*
* @param prop :: The property being updated
* @param val :: The new value for the property
*/
void ResNorm::updateProperties(QtProperty* prop, double val)
{
if(prop == m_properties["EMin"])
{
// Check if the user is setting the max less than the min
if(val > m_dblManager->value(m_properties["EMax"]))
{
m_dblManager->setValue(m_properties["EMin"], m_dblManager->value(m_properties["EMax"]));
}
else
{
m_rangeSelector->setMinimum(val);
}
updateLowerGuide(m_properties["EMin"], m_properties["EMax"], val);
}
else if (prop == m_properties["EMax"])
{
// Check if the user is setting the min greater than the max
if(val < m_dblManager->value(m_properties["EMin"]))
{
m_dblManager->setValue(m_properties["EMax"], m_dblManager->value(m_properties["EMin"]));
}
else
{
m_rangeSelector->setMaximum(val);
}
updateUpperGuide(m_properties["EMin"], m_properties["EMax"], val);
}
}
} // namespace CustomInterfaces
Expand Down

0 comments on commit 6354253

Please sign in to comment.