Mantid
Loading...
Searching...
No Matches
IFunctionModel.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10
12
13using namespace Mantid::API;
14
15void IFunctionModel::setFunctionString(const QString &funStr) {
16 if (funStr.isEmpty()) {
17 clear();
18 return;
19 }
20 setFunction(FunctionFactory::Instance().createInitialized(funStr.toStdString()));
21}
22
24 auto fun = getCurrentFunction();
25 if (!fun)
26 return "";
27 return QString::fromStdString(fun->asString());
28}
29
31 auto fun = getFitFunction();
32 if (!fun)
33 return "";
34 return QString::fromStdString(fun->asString());
35}
36
38
40 auto const n = getNumberDomains();
41 return n > 0 ? n : 1;
42}
43
45 if (funTo.nParams() != funFrom.nParams())
46 return;
47 for (size_t i = 0; i < funFrom.nParams(); ++i) {
48 funTo.setParameter(i, funFrom.getParameter(i));
49 funTo.setError(i, funFrom.getError(i));
50 }
51}
52
54 for (auto i = 0; i < getNumberLocalFunctions(); ++i) {
55 auto localFun = getSingleFunction(i);
56 copyParametersAndErrors(fun, *localFun);
57 }
58}
59
60} // namespace MantidQt::MantidWidgets
virtual int getNumberDomains() const =0
static void copyParametersAndErrors(const IFunction &funFrom, IFunction &funTo)
virtual IFunction_sptr getCurrentFunction() const =0
void copyParametersAndErrorsToAllLocalFunctions(const IFunction &fun)
virtual void setFunction(IFunction_sptr fun)=0
virtual IFunction_sptr getSingleFunction(int index) const =0
void setFunctionString(const QString &funStr)
virtual IFunction_sptr getFitFunction() const =0
This is an interface to a fitting function - a semi-abstarct class.
Definition: IFunction.h:163
virtual size_t nParams() const =0
Total number of parameters.
virtual double getParameter(size_t i) const =0
Get i-th parameter.
virtual void setParameter(size_t, const double &value, bool explicitlySet=true)=0
Set i-th parameter.
virtual void setError(size_t i, double err)=0
Set the fitting error for a parameter.
virtual double getError(size_t i) const =0
Get the fitting error for a parameter.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition: IFunction.h:732