Skip to content

Commit

Permalink
Refs #9213. Massive re-factoring of the Baseline Modelling step
Browse files Browse the repository at this point in the history
It now follows MVC patter much stricter - we have a model which handles
the data, a very thin view which displays stuff, and presenter which
glues those two together. Both model and view have intermediate
interfaces which allow to test presenter throughlty. Model is tested
independently as well.
  • Loading branch information
arturbekasov committed Apr 10, 2014
1 parent ce9afc4 commit 6d7b24c
Show file tree
Hide file tree
Showing 13 changed files with 687 additions and 417 deletions.
8 changes: 6 additions & 2 deletions Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt
Expand Up @@ -28,8 +28,9 @@ set ( SRC_FILES
src/MSDFit.cpp
src/MantidEV.cpp
src/MantidEVWorker.cpp
src/Muon/ALCBaselineModellingModel.cpp
src/Muon/ALCBaselineModellingPresenter.cpp
src/Muon/ALCBaselineModellingView.cpp
src/Muon/ALCBaselineModellingView.cpp
src/Muon/ALCDataLoadingPresenter.cpp
src/Muon/ALCDataLoadingView.cpp
src/Muon/ALCInterface.cpp
Expand Down Expand Up @@ -93,13 +94,15 @@ set ( INC_FILES
inc/MantidQtCustomInterfaces/MSDFit.h
inc/MantidQtCustomInterfaces/MantidEV.h
inc/MantidQtCustomInterfaces/MantidEVWorker.h
inc/MantidQtCustomInterfaces/Muon/ALCBaselineModellingModel.h
inc/MantidQtCustomInterfaces/Muon/ALCBaselineModellingPresenter.h
inc/MantidQtCustomInterfaces/Muon/ALCBaselineModellingView.h
inc/MantidQtCustomInterfaces/Muon/ALCDataLoadingPresenter.h
inc/MantidQtCustomInterfaces/Muon/ALCDataLoadingView.h
inc/MantidQtCustomInterfaces/Muon/ALCInterface.h
inc/MantidQtCustomInterfaces/Muon/ALCPeakFittingPresenter.h
inc/MantidQtCustomInterfaces/Muon/ALCPeakFittingView.h
inc/MantidQtCustomInterfaces/Muon/IALCBaselineModellingModel.h
inc/MantidQtCustomInterfaces/Muon/IALCBaselineModellingView.h
inc/MantidQtCustomInterfaces/Muon/IALCDataLoadingView.h
inc/MantidQtCustomInterfaces/Muon/IALCPeakFittingView.h
Expand Down Expand Up @@ -210,7 +213,8 @@ set ( UI_FILES inc/MantidQtCustomInterfaces/ConvertToEnergy.ui
)

set ( TEST_FILES
ALCBaselineModellingTest.h
ALCBaselineModellingModelTest.h
ALCBaselineModellingPresenterTest.h
ALCDataLoadingTest.h
ALCPeakFittingTest.h
CreateMDWorkspaceAlgDialogTest.h
Expand Down
@@ -0,0 +1,71 @@
#ifndef MANTID_CUSTOMINTERFACES_ALCBASELINEMODELLINGMODEL_H_
#define MANTID_CUSTOMINTERFACES_ALCBASELINEMODELLINGMODEL_H_

#include "MantidKernel/System.h"
#include "MantidQtCustomInterfaces/DllConfig.h"

#include "MantidQtCustomInterfaces/Muon/IALCBaselineModellingModel.h"

using namespace Mantid::API;

namespace MantidQt
{
namespace CustomInterfaces
{
/** ALCBaselineModellingModel : Concrete ALC Baseline Modelling step model implementation.
Copyright © 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport ALCBaselineModellingModel : public IALCBaselineModellingModel
{
public:
/// @see IALCBaselineModellingModel::setData
void setData(MatrixWorkspace_const_sptr data) { m_data = data; }
/// @see IALCBaselineModellingModel::data
MatrixWorkspace_const_sptr data() const { return m_data; }

/// @see IALCBaselineModellingModel::fit
void fit(IFunction_const_sptr function, const std::vector<Section> &sections);

/// @see IALCBaselineModellingModel::fittedFunction
IFunction_const_sptr fittedFunction() const { return m_fittedFunction; }

/// @see IALCBaselineModellingModel::correctedData
MatrixWorkspace_const_sptr correctedData() const { return m_correctedData; }

private:
/// Data to use for fitting
MatrixWorkspace_const_sptr m_data;

/// Corrected data of the last fit
MatrixWorkspace_const_sptr m_correctedData;

/// Result function of the last fit
IFunction_const_sptr m_fittedFunction;

/// Disables points which shouldn't be used for fitting
static void disableUnwantedPoints(MatrixWorkspace_sptr ws, const std::vector<Section>& sections);
};

} // namespace CustomInterfaces
} // namespace MantidQt

#endif /* MANTID_CUSTOMINTERFACES_ALCBASELINEMODELLINGMODEL_H_ */
Expand Up @@ -5,6 +5,7 @@

#include "MantidQtCustomInterfaces/DllConfig.h"
#include "MantidQtCustomInterfaces/Muon/IALCBaselineModellingView.h"
#include "MantidQtCustomInterfaces/Muon/IALCBaselineModellingModel.h"

#include <QObject>

Expand All @@ -13,13 +14,6 @@ namespace MantidQt
namespace CustomInterfaces
{

namespace
{
// Shortcuts
typedef IALCBaselineModellingView::Section Section;
typedef IALCBaselineModellingView::SectionIndex SectionIndex;
}

/** ALCBaselineModellingPresenter : Presenter for ALC Baseline Modelling step
Copyright &copy; 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
Expand Down Expand Up @@ -47,45 +41,35 @@ namespace
Q_OBJECT

public:
ALCBaselineModellingPresenter(IALCBaselineModellingView* view);
ALCBaselineModellingPresenter(IALCBaselineModellingView* view, IALCBaselineModellingModel* model);

void initialize();

/// @param data :: Data to fit peaks in
void setData(MatrixWorkspace_const_sptr data);

/// @return Corrected data calculated after the last fit
MatrixWorkspace_const_sptr correctedData() const { return m_correctedData; }
/// Set the data we should fit baseline for
void setData(MatrixWorkspace_const_sptr data);

private slots:
/// Perform fit
/// Perform a fit
void fit();

/// @param newSection :: Section to add
void addSection(Section newSection);

/// @param index :: Index of the section to modify
/// @param modified :: Modified section values
void modifySection(SectionIndex index, Section modified);
/// Add a new section
void addSection();

private:
/// Returns a filtered copy of m_data, where all uninteresting points where disabled.
/// Unintersing points are ones which are not included in any of the sections specified in the
/// view. Disabled here means "won't be used when fitting".
/// @return A copy of m_data which we can pass to Fit algorithm
MatrixWorkspace_sptr filteredData() const;

/// Associated view
IALCBaselineModellingView* const m_view;

/// Data we are fitting the baseline to
MatrixWorkspace_const_sptr m_data;
/// Associated model
IALCBaselineModellingModel* const m_model;

/// Baseline sections we are using
std::vector<Section> m_sections;
/// Create Qwt curve data from a workspace
static boost::shared_ptr<QwtData> curveDataFromWs(MatrixWorkspace_const_sptr ws,
size_t wsIndex);

/// Corrected data of the last fit
MatrixWorkspace_const_sptr m_correctedData;
/// Create Qwt curve data from a function
static boost::shared_ptr<QwtData> curveDataFromFunction(IFunction_const_sptr func,
const std::vector<double>& xValues);
};

} // namespace CustomInterfaces
Expand Down
Expand Up @@ -5,7 +5,6 @@

#include "MantidQtCustomInterfaces/DllConfig.h"
#include "MantidQtCustomInterfaces/Muon/IALCBaselineModellingView.h"
#include "MantidQtCustomInterfaces/Muon/ALCBaselineModellingPresenter.h"
#include "MantidQtMantidWidgets/RangeSelector.h"

#include "ui_ALCBaselineModellingView.h"
Expand Down Expand Up @@ -54,38 +53,32 @@ namespace CustomInterfaces
/// @see IALCBaselineModellingView::function
IFunction_const_sptr function() const;

/// @see IALCBaselineModellingView::sectionCount
int sectionCount() const;

/// @see IALCBaselineModellingView::section
IALCBaselineModellingModel::Section section(int index) const;

public slots:
/// @see IALCBaselineModellingView::displayData
void setData(MatrixWorkspace_const_sptr data);
/// @see IALCBaselineModellingView::setDataCurve
void setDataCurve(const QwtData &data);

/// @see IALCBaselineModellingView::displayCorrected
void setCorrectedData(MatrixWorkspace_const_sptr data);
/// @see IALCBaselineModellingView::setCorrectedCurve
void setCorrectedCurve(const QwtData &data);

/// @see IALCBaselineModellingView::setBaselineCurve
void setBaselineCurve(const QwtData &data);

/// @see IALCBaselineModellingView::updateFunction
void setFunction(IFunction_const_sptr func);

/// @see IALCBaselineModellingView::setSections
void setSectionsTable(const std::vector<Section> &sections);
/// @see IALCBaselineModellingView::addSection
void addSection(IALCBaselineModellingModel::Section newSection);

private slots:
/// Show context menu for sections table
void sectionsContextMenu(const QPoint& widgetPoint);

/// Called when section adding is requested
void onAddSectionRequested();

/// Called whenever section in sections table is changed
/// @param row :: Changed section row
/// @param col :: Changed section column
void onSectionChanged(int row, int col);

/// Called whenever section in sections table is selected by user
/// @param newRow :: Selected section row
/// @param newCol :: Selected section column
/// @param prevRow :: Previously selected section row
/// @param prevCol :: Previously selected section column
void onSectionSelected(int newRow, int newCol, int prevRow, int prevCol);

private:
/// Index of section start column in sections table
static const int SECTION_START_COL = 0;
Expand All @@ -100,9 +93,6 @@ namespace CustomInterfaces

/// Plot curves
QwtPlotCurve *m_dataCurve, *m_fitCurve, *m_correctedCurve;

/// Range selectors for all the sections
std::vector<RangeSelector*> m_sectionSelectors;
};


Expand Down
@@ -0,0 +1,76 @@
#ifndef MANTID_CUSTOMINTERFACES_IALCBASELINEMODELLINGMODEL_H_
#define MANTID_CUSTOMINTERFACES_IALCBASELINEMODELLINGMODEL_H_

#include "MantidKernel/System.h"

#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/IFunction.h"

using namespace Mantid::API;

namespace MantidQt
{
namespace CustomInterfaces
{

/** IALCBaselineModellingModel : Model interface for ALC BaselineModelling step
Copyright &copy; 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport IALCBaselineModellingModel
{
public:
typedef std::pair<double, double> Section;

/**
* @return Function produced by the last fit
*/
virtual IFunction_const_sptr fittedFunction() const = 0;

/**
* @return Corrected data produced by the last fit
*/
virtual MatrixWorkspace_const_sptr correctedData() const = 0;

/**
* @return Current data used for fitting
*/
virtual MatrixWorkspace_const_sptr data() const = 0;

/**
* @param data :: New data which will be used for fit
*/
virtual void setData(MatrixWorkspace_const_sptr data) = 0;

/**
* Perform a fit using current data and specified function and sections. Modified values returned
* by fittedFunction and correctedData.
* @param function :: Function to fit
* @param sections :: Data sections to include in the fit
*/
virtual void fit(IFunction_const_sptr function, const std::vector<Section>& sections) = 0;

};

} // namespace CustomInterfaces
} // namespace MantidQt

#endif /* MANTID_CUSTOMINTERFACES_IALCBASELINEMODELLINGMODEL_H_ */

0 comments on commit 6d7b24c

Please sign in to comment.