Mantid
Loading...
Searching...
No Matches
FitScriptGeneratorPresenter.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2020 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 +
7#pragma once
8
9#include "DllOption.h"
10#include "MantidAPI/IFunction.h"
15
16#include <string>
17#include <tuple>
18#include <vector>
19
20#include <QStringList>
21
22namespace MantidQt {
23namespace MantidWidgets {
24
25class IFitScriptGeneratorModel;
26class IFitScriptGeneratorView;
27struct GlobalParameter;
28struct GlobalTie;
29
31public:
33 QStringList const &workspaceNames = QStringList(), double startX = 0.0,
34 double endX = 0.0);
36
37 void notifyPresenter(ViewEvent const &event, [[maybe_unused]] std::string const &arg1 = "",
38 [[maybe_unused]] std::string const &arg2 = "") override;
39 void notifyPresenter(ViewEvent const &event, std::vector<std::string> const &vec) override;
40 void notifyPresenter(ViewEvent const &event, FittingMode fittingMode) override;
41
42 void openFitScriptGenerator() override;
43
44 void setGlobalTies(std::vector<GlobalTie> const &globalTies) override;
45 void setGlobalParameters(std::vector<GlobalParameter> const &globalParameters) override;
46
47private:
48 void handleADSDeleteEvent(std::string const &workspaceName);
49 void handleADSClearEvent();
50 void handleADSRenameEvent(std::string const &workspaceName, std::string const &newName);
51 void handleRemoveDomainClicked();
52 void handleAddDomainClicked();
53 void handleAddDomainAccepted();
54 void handleSelectionChanged();
55 void handleStartXChanged();
56 void handleEndXChanged();
57 void handleFunctionRemoved(std::string const &function);
58 void handleFunctionAdded(std::string const &function);
59 void handleFunctionReplaced(std::string const &function);
60 void handleParameterChanged(std::string const &parameter);
61 void handleAttributeChanged(std::string const &attribute);
62 void handleParameterTieChanged(std::string const &parameter, std::string const &tie);
63 void handleParameterConstraintRemoved(std::string const &parameter);
64 void handleParameterConstraintChanged(std::string const &functionIndex, std::string const &constraint);
65 void handleGlobalParametersChanged(std::vector<std::string> const &globalParameters);
66 void handleEditLocalParameterClicked(std::string const &parameter);
67 void handleEditLocalParameterFinished();
68 void handleOutputBaseNameChanged(std::string const &outputBaseName);
69 void handleFittingModeChanged(FittingMode fittingMode);
70 void handleGenerateScriptToFileClicked();
71 void handleGenerateScriptToClipboardClicked();
72
73 void setWorkspaces(QStringList const &workspaceNames, double startX, double endX);
74 void addWorkspaces(std::vector<Mantid::API::MatrixWorkspace_const_sptr> const &workspaces,
75 std::vector<WorkspaceIndex> const &workspaceIndices);
76 void addWorkspace(std::string const &workspaceName, double startX, double endX);
77 void addWorkspace(Mantid::API::MatrixWorkspace_const_sptr const &workspace, double startX, double endX);
79 double startX, double endX);
80 void addWorkspace(std::string const &workspaceName, WorkspaceIndex workspaceIndex, double startX, double endX);
81
82 void removeDomains(std::vector<FitDomainIndex> const &domainIndices);
83
84 void updateStartX(std::string const &workspaceName, WorkspaceIndex workspaceIndex, double startX);
85 void updateEndX(std::string const &workspaceName, WorkspaceIndex workspaceIndex, double endX);
86
87 void updateParameterValue(std::string const &workspaceName, WorkspaceIndex workspaceIndex,
88 std::string const &parameter, double newValue);
89 void updateAttributeValue(std::string const &workspaceName, WorkspaceIndex workspaceIndex,
90 std::string const &fullAttribute, Mantid::API::IFunction::Attribute const &newValue);
91
92 void updateParameterTie(std::string const &workspaceName, WorkspaceIndex workspaceIndex, std::string const &parameter,
93 std::string const &tie);
94
95 void removeParameterConstraint(std::string const &workspaceName, WorkspaceIndex workspaceIndex,
96 std::string const &parameter);
97 void updateParameterConstraint(std::string const &workspaceName, WorkspaceIndex workspaceIndex,
98 std::string const &functionIndex, std::string const &constraint);
99
100 void removeFunction(std::string const &workspaceName, WorkspaceIndex workspaceIndex, std::string const &function);
101 void addFunction(std::string const &workspaceName, WorkspaceIndex workspaceIndex, std::string const &function);
102 void setFunction(std::string const &workspaceName, WorkspaceIndex workspaceIndex, std::string const &function);
103
104 void updateFunctionInViewFromModel(FitDomainIndex domainIndex);
105
106 template <typename GetX, typename UpdateX> void updateXLimitForDomain(GetX &&getX, UpdateX &&updateX);
107
108 template <typename UpdateFunction>
109 void updateFunctionStructure(UpdateFunction &&updateFunction, std::string const &function);
110
111 template <typename UpdateFunction, typename... Args>
112 void updateFunctionsInModel(UpdateFunction &&updateFunction, Args... arguments);
113
114 template <typename Function, typename... Args>
115 void invokeFunctionForDomain(FitDomainIndex domainIndex, Function &&func, Args... arguments);
116
117 [[nodiscard]] std::vector<FitDomainIndex> getRowIndices() const;
118
119 void insertLocalParameterData(std::string const &parameter, std::vector<std::string> &workspaceNames,
120 std::vector<std::string> &domainNames, std::vector<double> &values,
121 std::vector<bool> &fixes, std::vector<std::string> &ties,
122 std::vector<std::string> &constraints) const;
123 void insertLocalParameterDataForDomain(FitDomainIndex domainIndex, std::string const &parameter,
124 std::vector<std::string> &workspaceNames,
125 std::vector<std::string> &domainNames, std::vector<double> &values,
126 std::vector<bool> &fixes, std::vector<std::string> &ties,
127 std::vector<std::string> &constraints) const;
128
129 void setLocalParameterDataForDomain(FitDomainIndex domainIndex, std::string const &parameter, double value, bool fix,
130 std::string const &tie, std::string const &constraint);
131
132 std::vector<FitDomainIndex> getDomainsWithLocalParameter(std::string const &parameter) const;
133
134 std::tuple<std::string, std::string> convertFunctionIndexOfParameterTie(std::string const &workspaceName,
135 WorkspaceIndex workspaceIndex,
136 std::string const &parameter,
137 std::string const &tie) const;
138
139 void checkForWarningMessages();
140
141 template <typename Generator> void generateFitScript(Generator &&func) const;
142 void generateScriptToFile() const;
143 void generateScriptToClipboard() const;
144
145 std::vector<std::string> m_warnings;
146
149};
150
151} // namespace MantidWidgets
152} // namespace MantidQt
#define EXPORT_OPT_MANTIDQT_COMMON
Definition: DllOption.h:15
double value
The value of the point.
Definition: FitMW.cpp:51
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
void addWorkspace(WorkspaceGroup &self, const boost::python::object &pyobj)
Attribute is a non-fitting parameter.
Definition: IFunction.h:282
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)