Commit 34dfb93e authored by Robert Applin's avatar Robert Applin
Browse files

Refs #28842. Update estimate when adding tube for the first time.

parent d2821fdf
......@@ -100,6 +100,7 @@ void ALFCustomInstrumentPresenter::extractSingleTube() {
m_model->extractSingleTube();
const std::string WSName = m_model->WSName();
m_analysisPane->addSpectrum(WSName);
m_analysisPane->updateEstimateAfterExtraction();
}
void ALFCustomInstrumentPresenter::averageTube() {
......
......@@ -18,7 +18,7 @@ namespace MantidWidgets {
class EXPORT_OPT_MANTIDQT_INSTRUMENTVIEW PlotFitAnalysisPaneModel {
public:
PlotFitAnalysisPaneModel(){};
PlotFitAnalysisPaneModel();
virtual ~PlotFitAnalysisPaneModel(){};
virtual IFunction_sptr doFit(const std::string &wsName,
const std::pair<double, double> &range,
......@@ -26,6 +26,11 @@ public:
virtual IFunction_sptr
calculateEstimate(const std::string &workspaceName,
const std::pair<double, double> &range);
virtual bool hasEstimate() const;
private:
IFunction_sptr m_estimateFunction;
};
} // namespace MantidWidgets
......
......@@ -25,6 +25,7 @@ public:
virtual std::string getCurrentWS() = 0;
virtual void clearCurrentWS() = 0;
virtual void doFit() = 0;
virtual void updateEstimateAfterExtraction() = 0;
virtual void updateEstimate() = 0;
virtual void addSpectrum(const std::string &wsName) = 0;
virtual void addFunction(Mantid::API::IFunction_sptr func) = 0;
......@@ -47,6 +48,7 @@ public:
std::string getCurrentWS() override { return m_currentName; };
void clearCurrentWS() override { m_currentName = ""; };
void doFit() override;
void updateEstimateAfterExtraction() override;
void updateEstimate() override;
void addSpectrum(const std::string &wsName) override;
void addFunction(Mantid::API::IFunction_sptr func) override;
......
......@@ -92,6 +92,9 @@ using namespace Mantid::API;
namespace MantidQt {
namespace MantidWidgets {
PlotFitAnalysisPaneModel::PlotFitAnalysisPaneModel()
: m_estimateFunction(nullptr) {}
IFunction_sptr
PlotFitAnalysisPaneModel::doFit(const std::string &wsName,
const std::pair<double, double> &range,
......@@ -123,10 +126,18 @@ IFunction_sptr PlotFitAnalysisPaneModel::calculateEstimate(
const auto background = std::accumulate(yData.begin(), yData.end(), 0.0) /
static_cast<double>(yData.size());
return createCompositeFunction(createFlatBackground(background),
createGaussian(xData, yData, background));
m_estimateFunction =
createCompositeFunction(createFlatBackground(background),
createGaussian(xData, yData, background));
return m_estimateFunction;
} else {
m_estimateFunction = nullptr;
return createCompositeFunction(createFlatBackground(), createGaussian());
}
return createCompositeFunction(createFlatBackground(), createGaussian());
}
bool PlotFitAnalysisPaneModel::hasEstimate() const {
return m_estimateFunction != nullptr;
}
} // namespace MantidWidgets
......
......@@ -50,13 +50,19 @@ void PlotFitAnalysisPanePresenter::doFit() {
}
}
void PlotFitAnalysisPanePresenter::updateEstimateAfterExtraction() {
if (!m_model->hasEstimate())
updateEstimate();
}
void PlotFitAnalysisPanePresenter::updateEstimate() {
if (!m_currentName.empty())
if (!m_currentName.empty()) {
m_view->updateFunction(
m_model->calculateEstimate(m_currentName, m_view->getRange()));
else
} else {
m_view->displayWarning(
"Could not update estimate: data has not been extracted.");
}
}
void PlotFitAnalysisPanePresenter::addFunction(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment