From a57b4af37e04737970883a09dded411f0250337a Mon Sep 17 00:00:00 2001 From: Jonathan Haigh Date: Fri, 10 May 2024 13:59:14 +0100 Subject: [PATCH 01/58] 6.11 release notes skeleton --- docs/source/release/index.rst | 1 + .../Diffraction/Engineering/Bugfixes/.gitkeep | 0 .../Engineering/New_features/.gitkeep | 0 .../Diffraction/Powder/Bugfixes/.gitkeep | 0 .../Diffraction/Powder/New_features/.gitkeep | 0 .../Single_Crystal/Bugfixes/.gitkeep | 0 .../Single_Crystal/New_features/.gitkeep | 0 .../CrystalField/Bugfixes/.gitkeep | 0 .../CrystalField/New_features/.gitkeep | 0 .../Direct_Geometry/General/Bugfixes/.gitkeep | 0 .../General/New_features/.gitkeep | 0 .../Direct_Geometry/MSlice/Bugfixes/.gitkeep | 0 .../MSlice/New_features/.gitkeep | 0 .../Framework/Algorithms/Bugfixes/.gitkeep | 0 .../Algorithms/New_features/.gitkeep | 0 .../Framework/Data_Objects/Bugfixes/.gitkeep | 0 .../Data_Objects/New_features/.gitkeep | 0 .../Framework/Dependencies/Bugfixes/.gitkeep | 0 .../Dependencies/New_features/.gitkeep | 0 .../Framework/Fit_Functions/Bugfixes/.gitkeep | 0 .../Fit_Functions/New_features/.gitkeep | 0 .../Framework/Python/Bugfixes/.gitkeep | 0 .../Framework/Python/New_features/.gitkeep | 0 .../Indirect/Algorithms/Bugfixes/.gitkeep | 0 .../Indirect/Algorithms/New_features/.gitkeep | 0 .../v6.11.0/Indirect/Bugfixes/.gitkeep | 0 .../v6.11.0/Indirect/New_features/.gitkeep | 0 .../Inelastic/Algorithms/Bugfixes/.gitkeep | 0 .../Algorithms/New_features/.gitkeep | 0 .../v6.11.0/Inelastic/Bugfixes/.gitkeep | 0 .../v6.11.0/Inelastic/New_features/.gitkeep | 0 .../v6.11.0/Muon/ALC/Bugfixes/.gitkeep | 0 .../v6.11.0/Muon/Algorithms/Bugfixes/.gitkeep | 0 .../Muon/Elemental_Analysis/Bugfixes/.gitkeep | 0 .../v6.11.0/Muon/FDA/Bugfixes/.gitkeep | 0 .../v6.11.0/Muon/MA_FDA/Bugfixes/.gitkeep | 0 .../Muon/Muon_Analysis/Bugfixes/.gitkeep | 0 .../v6.11.0/Reflectometry/Bugfixes/.gitkeep | 0 .../Reflectometry/New_features/.gitkeep | 0 .../release/v6.11.0/SANS/Bugfixes/.gitkeep | 0 .../v6.11.0/SANS/New_features/.gitkeep | 0 .../v6.11.0/Workbench/Bugfixes/.gitkeep | 0 .../InstrumentViewer/Bugfixes/.gitkeep | 0 .../InstrumentViewer/New_features/.gitkeep | 0 .../v6.11.0/Workbench/New_features/.gitkeep | 0 .../Workbench/SliceViewer/Bugfixes/.gitkeep | 0 .../SliceViewer/New_features/.gitkeep | 0 docs/source/release/v6.11.0/diffraction.rst | 43 +++++++++ .../release/v6.11.0/direct_geometry.rst | 44 ++++++++++ docs/source/release/v6.11.0/framework.rst | 71 +++++++++++++++ docs/source/release/v6.11.0/index.rst | 87 +++++++++++++++++++ .../release/v6.11.0/indirect_geometry.rst | 29 +++++++ docs/source/release/v6.11.0/inelastic.rst | 29 +++++++ .../release/v6.11.0/mantidworkbench.rst | 42 +++++++++ docs/source/release/v6.11.0/muon.rst | 56 ++++++++++++ docs/source/release/v6.11.0/reflectometry.rst | 16 ++++ docs/source/release/v6.11.0/sans.rst | 16 ++++ 57 files changed, 434 insertions(+) create mode 100644 docs/source/release/v6.11.0/Diffraction/Engineering/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Diffraction/Engineering/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Diffraction/Powder/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Diffraction/Powder/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Diffraction/Single_Crystal/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Diffraction/Single_Crystal/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Direct_Geometry/CrystalField/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Direct_Geometry/CrystalField/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Direct_Geometry/General/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Direct_Geometry/General/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Direct_Geometry/MSlice/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Direct_Geometry/MSlice/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Framework/Algorithms/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Framework/Algorithms/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Framework/Data_Objects/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Framework/Data_Objects/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Framework/Dependencies/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Framework/Dependencies/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Framework/Fit_Functions/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Framework/Fit_Functions/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Framework/Python/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Framework/Python/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Indirect/Algorithms/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Indirect/Algorithms/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Indirect/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Indirect/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Inelastic/Algorithms/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Inelastic/Algorithms/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Inelastic/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Inelastic/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Muon/ALC/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Muon/Algorithms/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Muon/Elemental_Analysis/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Muon/FDA/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Muon/MA_FDA/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Muon/Muon_Analysis/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Reflectometry/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Reflectometry/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/SANS/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/SANS/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Workbench/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Workbench/InstrumentViewer/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Workbench/InstrumentViewer/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Workbench/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/Workbench/SliceViewer/Bugfixes/.gitkeep create mode 100644 docs/source/release/v6.11.0/Workbench/SliceViewer/New_features/.gitkeep create mode 100644 docs/source/release/v6.11.0/diffraction.rst create mode 100644 docs/source/release/v6.11.0/direct_geometry.rst create mode 100644 docs/source/release/v6.11.0/framework.rst create mode 100644 docs/source/release/v6.11.0/index.rst create mode 100644 docs/source/release/v6.11.0/indirect_geometry.rst create mode 100644 docs/source/release/v6.11.0/inelastic.rst create mode 100644 docs/source/release/v6.11.0/mantidworkbench.rst create mode 100644 docs/source/release/v6.11.0/muon.rst create mode 100644 docs/source/release/v6.11.0/reflectometry.rst create mode 100644 docs/source/release/v6.11.0/sans.rst diff --git a/docs/source/release/index.rst b/docs/source/release/index.rst index 1f4593127a4c..66569cbe2a4c 100644 --- a/docs/source/release/index.rst +++ b/docs/source/release/index.rst @@ -11,6 +11,7 @@ Release Notes */index +* :doc:`v6.11.0 ` * :doc:`v6.10.0 ` * :doc:`v6.9.1 ` * :doc:`v6.9.0 ` diff --git a/docs/source/release/v6.11.0/Diffraction/Engineering/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Diffraction/Engineering/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Diffraction/Engineering/New_features/.gitkeep b/docs/source/release/v6.11.0/Diffraction/Engineering/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Diffraction/Powder/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Diffraction/Powder/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Diffraction/Powder/New_features/.gitkeep b/docs/source/release/v6.11.0/Diffraction/Powder/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Diffraction/Single_Crystal/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Diffraction/Single_Crystal/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Diffraction/Single_Crystal/New_features/.gitkeep b/docs/source/release/v6.11.0/Diffraction/Single_Crystal/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Direct_Geometry/CrystalField/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Direct_Geometry/CrystalField/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Direct_Geometry/CrystalField/New_features/.gitkeep b/docs/source/release/v6.11.0/Direct_Geometry/CrystalField/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Direct_Geometry/General/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Direct_Geometry/General/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Direct_Geometry/General/New_features/.gitkeep b/docs/source/release/v6.11.0/Direct_Geometry/General/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Direct_Geometry/MSlice/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Direct_Geometry/MSlice/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Direct_Geometry/MSlice/New_features/.gitkeep b/docs/source/release/v6.11.0/Direct_Geometry/MSlice/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Framework/Algorithms/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Framework/Algorithms/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Framework/Algorithms/New_features/.gitkeep b/docs/source/release/v6.11.0/Framework/Algorithms/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Framework/Data_Objects/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Framework/Data_Objects/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Framework/Data_Objects/New_features/.gitkeep b/docs/source/release/v6.11.0/Framework/Data_Objects/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Framework/Dependencies/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Framework/Dependencies/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Framework/Dependencies/New_features/.gitkeep b/docs/source/release/v6.11.0/Framework/Dependencies/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Framework/Fit_Functions/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Framework/Fit_Functions/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Framework/Fit_Functions/New_features/.gitkeep b/docs/source/release/v6.11.0/Framework/Fit_Functions/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Framework/Python/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Framework/Python/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Framework/Python/New_features/.gitkeep b/docs/source/release/v6.11.0/Framework/Python/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Indirect/Algorithms/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Indirect/Algorithms/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Indirect/Algorithms/New_features/.gitkeep b/docs/source/release/v6.11.0/Indirect/Algorithms/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Indirect/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Indirect/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Indirect/New_features/.gitkeep b/docs/source/release/v6.11.0/Indirect/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Inelastic/Algorithms/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Inelastic/Algorithms/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Inelastic/Algorithms/New_features/.gitkeep b/docs/source/release/v6.11.0/Inelastic/Algorithms/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Inelastic/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Inelastic/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Inelastic/New_features/.gitkeep b/docs/source/release/v6.11.0/Inelastic/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Muon/ALC/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Muon/ALC/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Muon/Algorithms/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Muon/Algorithms/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Muon/Elemental_Analysis/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Muon/Elemental_Analysis/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Muon/FDA/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Muon/FDA/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Muon/MA_FDA/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Muon/MA_FDA/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Muon/Muon_Analysis/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Muon/Muon_Analysis/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Reflectometry/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Reflectometry/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Reflectometry/New_features/.gitkeep b/docs/source/release/v6.11.0/Reflectometry/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/SANS/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/SANS/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/SANS/New_features/.gitkeep b/docs/source/release/v6.11.0/SANS/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Workbench/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Workbench/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Workbench/InstrumentViewer/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Workbench/InstrumentViewer/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Workbench/InstrumentViewer/New_features/.gitkeep b/docs/source/release/v6.11.0/Workbench/InstrumentViewer/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Workbench/New_features/.gitkeep b/docs/source/release/v6.11.0/Workbench/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Workbench/SliceViewer/Bugfixes/.gitkeep b/docs/source/release/v6.11.0/Workbench/SliceViewer/Bugfixes/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/Workbench/SliceViewer/New_features/.gitkeep b/docs/source/release/v6.11.0/Workbench/SliceViewer/New_features/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/source/release/v6.11.0/diffraction.rst b/docs/source/release/v6.11.0/diffraction.rst new file mode 100644 index 000000000000..2683c1164682 --- /dev/null +++ b/docs/source/release/v6.11.0/diffraction.rst @@ -0,0 +1,43 @@ +=================== +Diffraction Changes +=================== + +.. contents:: Table of Contents + :local: + +Powder Diffraction +------------------ + +New features +############ +.. amalgamate:: Diffraction/Powder/New_features + +Bugfixes +############ +.. amalgamate:: Diffraction/Powder/Bugfixes + + +Engineering Diffraction +----------------------- + +New features +############ +.. amalgamate:: Diffraction/Engineering/New_features + +Bugfixes +############ +.. amalgamate:: Diffraction/Engineering/Bugfixes + + +Single Crystal Diffraction +-------------------------- + +New features +############ +.. amalgamate:: Diffraction/Single_Crystal/New_features + +Bugfixes +############ +.. amalgamate:: Diffraction/Single_Crystal/Bugfixes + +:ref:`Release 6.11.0 ` \ No newline at end of file diff --git a/docs/source/release/v6.11.0/direct_geometry.rst b/docs/source/release/v6.11.0/direct_geometry.rst new file mode 100644 index 000000000000..faa3cc7f985a --- /dev/null +++ b/docs/source/release/v6.11.0/direct_geometry.rst @@ -0,0 +1,44 @@ +======================= +Direct Geometry Changes +======================= + +.. contents:: Table of Contents + :local: + +General +------- + +New features +############ +.. amalgamate:: Direct_Geometry/General/New_features + +Bugfixes +############ +.. amalgamate:: Direct_Geometry/General/Bugfixes + + +CrystalField +------------- + +New features +############ +.. amalgamate:: Direct_Geometry/CrystalField/New_features + +Bugfixes +############ +.. amalgamate:: Direct_Geometry/CrystalField/Bugfixes + + +MSlice +------ + +New features +############ +.. amalgamate:: Direct_Geometry/MSlice/New_features + +Bugfixes +############ +.. amalgamate:: Direct_Geometry/MSlice/Bugfixes + + +:ref:`Release 6.11.0 ` \ No newline at end of file diff --git a/docs/source/release/v6.11.0/framework.rst b/docs/source/release/v6.11.0/framework.rst new file mode 100644 index 000000000000..8c657b311ab2 --- /dev/null +++ b/docs/source/release/v6.11.0/framework.rst @@ -0,0 +1,71 @@ +================= +Framework Changes +================= + +.. contents:: Table of Contents + :local: + +Algorithms +---------- + +New features +############ +.. amalgamate:: Framework/Algorithms/New_features + +Bugfixes +############ +.. amalgamate:: Framework/Algorithms/Bugfixes + +Fit Functions +------------- + +New features +############ +.. amalgamate:: Framework/Fit_Functions/New_features + +Bugfixes +############ +.. amalgamate:: Framework/Fit_Functions/Bugfixes + + +Data Objects +------------ + +New features +############ +.. amalgamate:: Framework/Data_Objects/New_features + +Bugfixes +############ +.. amalgamate:: Framework/Data_Objects/Bugfixes + + +Python +------ + +New features +############ +.. amalgamate:: Framework/Python/New_features + +Bugfixes +############ +.. amalgamate:: Framework/Python/Bugfixes + + +Dependencies +------------------ + +New features +############ +.. amalgamate:: Framework/Dependencies/New_features + +Bugfixes +############ +.. amalgamate:: Framework/Dependencies/Bugfixes + + +MantidWorkbench +--------------- + +See :doc:`mantidworkbench`. +:ref:`Release 6.11.0 ` \ No newline at end of file diff --git a/docs/source/release/v6.11.0/index.rst b/docs/source/release/v6.11.0/index.rst new file mode 100644 index 000000000000..35e5c5b0f279 --- /dev/null +++ b/docs/source/release/v6.11.0/index.rst @@ -0,0 +1,87 @@ +.. _v6.11.0: + +=========================== +Mantid 6.11.0 Release Notes +=========================== + +.. figure:: ../../images/ImageNotFound.png + :class: screenshot + :width: 385px + :align: right + +.. contents:: Table of Contents + :local: + +.. warning:: This release is still under construction. The changes can be found in the nightly builds on the `download page`_. + +We are proud to announce version 6.11.0 of Mantid. + +**TODO: Add paragraph summarizing big changes** + +These are just some of the many improvements in this release, so please take a +look at the release notes, which are filled with details of the +important changes and improvements in many areas. The development team +has put a great effort into making all of these improvements within +Mantid, and we would like to thank all of our beta testers for their +time and effort helping us to make this another reliable version of Mantid. + +Throughout the Mantid project we put a lot of effort into ensuring +Mantid is a robust and reliable product. Thank you to everyone that has +reported any issues to us. Please keep on reporting any problems you +have, or crashes that occur on our `forum`_. + +Installation packages can be found on our `download page`_ +which now links to the assets on our `GitHub release page`_, where you can also +access the source code for the release. + +Citation +-------- + +Please cite any usage of Mantid as follows: + +- *Mantid 6.11.0: Manipulation and Analysis Toolkit for Instrument Data.; Mantid Project*. `doi: 10.5286/SOFTWARE/MANTID6.11 `_ + +- Arnold, O. et al. *Mantid-Data Analysis and Visualization Package for Neutron Scattering and mu-SR Experiments.* Nuclear Instruments + and Methods in Physics Research Section A: Accelerators, Spectrometers, Detectors and Associated Equipment 764 (2014): 156-166 + `doi: 10.1016/j.nima.2014.07.029 `_ + (`download bibtex `_) + + +Changes +------- + +.. toctree:: + :hidden: + :glob: + + * + +- :doc:`Framework ` +- :doc:`Mantid Workbench ` +- :doc:`Diffraction ` +- :doc:`Muon Analysis ` +- Low Q + + - :doc:`Reflectometry ` + + - :doc:`SANS ` +- Spectroscopy + + - :doc:`Direct Geometry ` + + - :doc:`Indirect Geometry ` + + - :doc:`Inelastic ` + +Full Change Listings +-------------------- + +For a full list of all issues addressed during this release please see the `GitHub milestone`_. + +.. _download page: https://download.mantidproject.org + +.. _forum: https://forum.mantidproject.org + +.. _GitHub milestone: https://github.com/mantidproject/mantid/pulls?utf8=%E2%9C%93&q=is%3Apr+milestone%3A%22Release+6.11%22+is%3Amerged + +.. _GitHub release page: https://github.com/mantidproject/mantid/releases/tag/v6.11.0 diff --git a/docs/source/release/v6.11.0/indirect_geometry.rst b/docs/source/release/v6.11.0/indirect_geometry.rst new file mode 100644 index 000000000000..d6555582e173 --- /dev/null +++ b/docs/source/release/v6.11.0/indirect_geometry.rst @@ -0,0 +1,29 @@ +========================= +Indirect Geometry Changes +========================= + +.. contents:: Table of Contents + :local: + +New Features +------------ +.. amalgamate:: Indirect/New_features + + +Bugfixes +-------- +.. amalgamate:: Indirect/Bugfixes + + +Algorithms +---------- + +New features +############ +.. amalgamate:: Indirect/Algorithms/New_features + +Bugfixes +############ +.. amalgamate:: Indirect/Algorithms/Bugfixes + +:ref:`Release 6.11.0 ` \ No newline at end of file diff --git a/docs/source/release/v6.11.0/inelastic.rst b/docs/source/release/v6.11.0/inelastic.rst new file mode 100644 index 000000000000..ea654401e4e4 --- /dev/null +++ b/docs/source/release/v6.11.0/inelastic.rst @@ -0,0 +1,29 @@ +================= +Inelastic Changes +================= + +.. contents:: Table of Contents + :local: + +New Features +------------ +.. amalgamate:: Inelastic/New_features + + +Bugfixes +-------- +.. amalgamate:: Inelastic/Bugfixes + + +Algorithms +---------- + +New features +############ +.. amalgamate:: Inelastic/Algorithms/New_features + +Bugfixes +############ +.. amalgamate:: Inelastic/Algorithms/Bugfixes + +:ref:`Release 6.11.0 ` \ No newline at end of file diff --git a/docs/source/release/v6.11.0/mantidworkbench.rst b/docs/source/release/v6.11.0/mantidworkbench.rst new file mode 100644 index 000000000000..7fa80fef1c68 --- /dev/null +++ b/docs/source/release/v6.11.0/mantidworkbench.rst @@ -0,0 +1,42 @@ +======================== +Mantid Workbench Changes +======================== + +.. contents:: Table of Contents + :local: + +New Features +------------ +.. amalgamate:: Workbench/New_features + + +Bugfixes +-------- +.. amalgamate:: Workbench/Bugfixes + + +InstrumentViewer +---------------- + +New features +############ +.. amalgamate:: Workbench/InstrumentViewer/New_features + +Bugfixes +############ +.. amalgamate:: Workbench/InstrumentViewer/Bugfixes + + +SliceViewer +----------- + +New features +############ +.. amalgamate:: Workbench/SliceViewer/New_features + +Bugfixes +############ +.. amalgamate:: Workbench/SliceViewer/Bugfixes + + +:ref:`Release 6.11.0 ` \ No newline at end of file diff --git a/docs/source/release/v6.11.0/muon.rst b/docs/source/release/v6.11.0/muon.rst new file mode 100644 index 000000000000..5f55449fa1c2 --- /dev/null +++ b/docs/source/release/v6.11.0/muon.rst @@ -0,0 +1,56 @@ +============ +Muon Changes +============ + +.. contents:: Table of Contents + :local: + + +Frequency Domain Analysis +------------------------- + +Bugfixes +############ +.. amalgamate:: Muon/FDA/Bugfixes + + +Muon Analysis +------------- + +Bugfixes +############ +.. amalgamate:: Muon/Muon_Analysis/Bugfixes + + +Muon Analysis and Frequency Domain Analysis +------------------------------------------- + +Bugfixes +############ +.. amalgamate:: Muon/MA_FDA/Bugfixes + + +ALC +--- + +Bugfixes +############ +.. amalgamate:: Muon/ALC/Bugfixes + + +Elemental Analysis +------------------ + +Bugfixes +############ +.. amalgamate:: Muon/Elemental_Analysis/Bugfixes + + +Algorithms +---------- + +Bugfixes +############ +.. amalgamate:: Muon/Algorithms/Bugfixes + +:ref:`Release 6.11.0 ` \ No newline at end of file diff --git a/docs/source/release/v6.11.0/reflectometry.rst b/docs/source/release/v6.11.0/reflectometry.rst new file mode 100644 index 000000000000..54de31f55897 --- /dev/null +++ b/docs/source/release/v6.11.0/reflectometry.rst @@ -0,0 +1,16 @@ +===================== +Reflectometry Changes +===================== + +.. contents:: Table of Contents + :local: + +New Features +------------ +.. amalgamate:: Reflectometry/New_features + +Bugfixes +-------- +.. amalgamate:: Reflectometry/Bugfixes + +:ref:`Release 6.11.0 ` \ No newline at end of file diff --git a/docs/source/release/v6.11.0/sans.rst b/docs/source/release/v6.11.0/sans.rst new file mode 100644 index 000000000000..9d9c04715a2f --- /dev/null +++ b/docs/source/release/v6.11.0/sans.rst @@ -0,0 +1,16 @@ +============ +SANS Changes +============ + +.. contents:: Table of Contents + :local: + +New Features +------------ +.. amalgamate:: SANS/New_features + +Bugfixes +-------- +.. amalgamate:: SANS/Bugfixes + +:ref:`Release 6.11.0 ` \ No newline at end of file From 1dbb347c117eb94c55508a1130cd336ebabb2674 Mon Sep 17 00:00:00 2001 From: adriazalvarez Date: Fri, 10 May 2024 11:13:01 +0100 Subject: [PATCH 02/58] create MVP tabs passing the unique_ptr of the model --- .../Inelastic/Manipulation/DataManipulation.h | 2 +- .../DataManipulationInterface.cpp | 20 ++++++++++++------- .../Manipulation/DataManipulationInterface.h | 7 ++++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulation.h b/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulation.h index b2cf95b63401..5f53180cf7c8 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulation.h +++ b/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulation.h @@ -69,7 +69,7 @@ private slots: virtual void runComplete(bool error) { (void)error; }; private: - virtual void setFileExtensionsByName(bool filter) { UNUSED_ARG(filter); }; + virtual void setFileExtensionsByName(bool filter) { (void)filter; }; std::unique_ptr m_plotOptionsPresenter; bool m_tabRunning; diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.cpp b/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.cpp index 2c09249784fa..b248b26f29cd 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.cpp +++ b/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.cpp @@ -10,8 +10,6 @@ #include "DataManipulationInterface.h" #include "Common/Settings.h" -#include "ElwinPresenter.h" -#include "IqtPresenter.h" #include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/ExperimentInfo.h" @@ -19,8 +17,16 @@ #include "MantidGeometry/Instrument.h" #include "MantidKernel/ConfigService.h" #include "MantidKernel/FacilityInfo.h" + +#include "ElwinModel.h" +#include "ElwinPresenter.h" +#include "IqtModel.h" +#include "IqtPresenter.h" +#include "MomentsModel.h" #include "MomentsPresenter.h" +#include "SqwModel.h" #include "SqwPresenter.h" +#include "SymmetriseModel.h" #include "SymmetrisePresenter.h" #include @@ -59,11 +65,11 @@ void DataManipulationInterface::initLayout() { m_uiForm.pbSettings->setIcon(Settings::icon()); // Create the tabs - addMVPTab("Symmetrise"); - addMVPTab("S(Q, w)"); - addMVPTab("Moments"); - addMVPTab("Elwin"); - addMVPTab("Iqt"); + addMVPTab("Symmetrise"); + addMVPTab("S(Q, w)"); + addMVPTab("Moments"); + addMVPTab("Elwin"); + addMVPTab("Iqt"); connect(m_uiForm.pbSettings, SIGNAL(clicked()), this, SLOT(settings())); // Connect "?" (Help) Button diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.h b/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.h index 7a535e351a81..da9629f38c61 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.h +++ b/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.h @@ -79,7 +79,7 @@ private slots: * @param name Name to be displayed on tab */ - template void addMVPTab(const QString &name) { + template void addMVPTab(const QString &name) { QWidget *tabWidget = new QWidget(m_uiForm.twIDRTabs); QVBoxLayout *tabLayout = new QVBoxLayout(tabWidget); tabWidget->setLayout(tabLayout); @@ -93,7 +93,9 @@ private slots: tabScrollArea->setWidget(tabContent); tabScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - DataManipulation *tabIDRContent = new TabPresenter(tabContent, new TabView(tabContent)); + std::unique_ptr tabModel = std::make_unique(); + + DataManipulation *tabIDRContent = new TabPresenter(tabContent, new TabView(tabContent), std::move(tabModel)); tabIDRContent->setupTab(); tabContent->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -113,7 +115,6 @@ private slots: // All indirect tabs QMap> m_tabs; - QString m_dataDir; ///< default data search directory QString m_saveDir; ///< default data save directory }; From e3460e4388547ca9e46f3854c80061a5aebad057 Mon Sep 17 00:00:00 2001 From: adriazalvarez Date: Fri, 10 May 2024 11:14:41 +0100 Subject: [PATCH 03/58] Initialize elwin presenter passing model pointer --- .../Inelastic/Manipulation/ElwinPresenter.cpp | 6 +++--- .../Inelastic/Manipulation/ElwinPresenter.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/ElwinPresenter.cpp b/qt/scientific_interfaces/Inelastic/Manipulation/ElwinPresenter.cpp index 3f84b79b6ac6..15bc0892f921 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/ElwinPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/Manipulation/ElwinPresenter.cpp @@ -41,9 +41,9 @@ class ScopedFalse { namespace MantidQt::CustomInterfaces { using namespace Inelastic; -ElwinPresenter::ElwinPresenter(QWidget *parent, IElwinView *view) - : DataManipulation(parent), m_view(view), m_model(std::make_unique()), - m_dataModel(std::make_unique()), m_selectedSpectrum(0) { +ElwinPresenter::ElwinPresenter(QWidget *parent, IElwinView *view, std::unique_ptr model) + : DataManipulation(parent), m_view(view), m_model(std::move(model)), m_dataModel(std::make_unique()), + m_selectedSpectrum(0) { m_view->subscribePresenter(this); setOutputPlotOptionsPresenter( std::make_unique(m_view->getPlotOptions(), PlotWidget::Spectra)); diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/ElwinPresenter.h b/qt/scientific_interfaces/Inelastic/Manipulation/ElwinPresenter.h index 6c9ff2ee06de..d89b5cd7dc74 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/ElwinPresenter.h +++ b/qt/scientific_interfaces/Inelastic/Manipulation/ElwinPresenter.h @@ -42,7 +42,7 @@ class IElwinPresenter { class MANTIDQT_INELASTIC_DLL ElwinPresenter : public DataManipulation, public IElwinPresenter { public: - ElwinPresenter(QWidget *parent, IElwinView *view); + ElwinPresenter(QWidget *parent, IElwinView *view, std::unique_ptr model); ElwinPresenter(QWidget *parent, IElwinView *view, std::unique_ptr model, std::unique_ptr dataModel); ~ElwinPresenter(); From afbd907be3f53bc9cd8046c9212e710a800d773b Mon Sep 17 00:00:00 2001 From: adriazalvarez Date: Fri, 10 May 2024 11:15:31 +0100 Subject: [PATCH 04/58] Initialize moments presenter passing model pointer --- .../Inelastic/Manipulation/MomentsModel.h | 29 ++++++++++++++----- .../Manipulation/MomentsPresenter.cpp | 4 +-- .../Inelastic/Manipulation/MomentsPresenter.h | 5 ++-- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/MomentsModel.h b/qt/scientific_interfaces/Inelastic/Manipulation/MomentsModel.h index 4e733218d266..bbba77242f6e 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/MomentsModel.h +++ b/qt/scientific_interfaces/Inelastic/Manipulation/MomentsModel.h @@ -14,18 +14,31 @@ using namespace Mantid::API; namespace MantidQt { namespace CustomInterfaces { -class MANTIDQT_INELASTIC_DLL MomentsModel { +class MANTIDQT_INELASTIC_DLL IMomentsModel { + +public: + virtual ~IMomentsModel() = default; + virtual IAlgorithm_sptr setupAlgorithm() = 0; + virtual void setInputWorkspace(const std::string &workspace) = 0; + virtual void setEMin(double eMin) = 0; + virtual void setEMax(double eMax) = 0; + virtual void setScale(bool scale) = 0; + virtual void setScaleValue(double scaleValue) = 0; + virtual std::string getOutputWorkspace() = 0; +}; + +class MANTIDQT_INELASTIC_DLL MomentsModel : public IMomentsModel { public: MomentsModel(); ~MomentsModel() = default; - IAlgorithm_sptr setupAlgorithm(); - void setInputWorkspace(const std::string &workspace); - void setEMin(double eMin); - void setEMax(double eMax); - void setScale(bool scale); - void setScaleValue(double scaleValue); - std::string getOutputWorkspace(); + IAlgorithm_sptr setupAlgorithm() override; + void setInputWorkspace(const std::string &workspace) override; + void setEMin(double eMin) override; + void setEMax(double eMax) override; + void setScale(bool scale) override; + void setScaleValue(double scaleValue) override; + std::string getOutputWorkspace() override; private: std::string m_inputWorkspace; diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/MomentsPresenter.cpp b/qt/scientific_interfaces/Inelastic/Manipulation/MomentsPresenter.cpp index a7a0c6f76def..ada9cfbc6956 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/MomentsPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/Manipulation/MomentsPresenter.cpp @@ -26,8 +26,8 @@ namespace MantidQt::CustomInterfaces { //---------------------------------------------------------------------------------------------- /** Constructor */ -MomentsPresenter::MomentsPresenter(QWidget *parent, IMomentsView *view) - : DataManipulation(parent), m_model(std::make_unique()), m_view(view) { +MomentsPresenter::MomentsPresenter(QWidget *parent, IMomentsView *view, std::unique_ptr model) + : DataManipulation(parent), m_view(view), m_model(std::move(model)) { m_view->subscribePresenter(this); setOutputPlotOptionsPresenter( std::make_unique(m_view->getPlotOptions(), PlotWidget::Spectra, "0,2,4")); diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/MomentsPresenter.h b/qt/scientific_interfaces/Inelastic/Manipulation/MomentsPresenter.h index ca942981f952..6eb9822559c2 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/MomentsPresenter.h +++ b/qt/scientific_interfaces/Inelastic/Manipulation/MomentsPresenter.h @@ -40,7 +40,7 @@ class IMomentsPresenter { class MANTIDQT_INELASTIC_DLL MomentsPresenter : public DataManipulation, public IMomentsPresenter { public: - MomentsPresenter(QWidget *parent, IMomentsView *view); + MomentsPresenter(QWidget *parent, IMomentsView *view, std::unique_ptr model); ~MomentsPresenter() = default; void setup() override; @@ -62,8 +62,9 @@ class MANTIDQT_INELASTIC_DLL MomentsPresenter : public DataManipulation, public private: void plotNewData(std::string const &filename); void setFileExtensionsByName(bool filter) override; - std::unique_ptr m_model; + IMomentsView *m_view; + std::unique_ptr m_model; }; } // namespace CustomInterfaces } // namespace MantidQt From 3e3773f697b038f408b6128af255dd8ed3b8009f Mon Sep 17 00:00:00 2001 From: adriazalvarez Date: Fri, 10 May 2024 11:16:18 +0100 Subject: [PATCH 05/58] Initialize Iqt presenter passing model pointer --- .../Inelastic/Manipulation/IqtModel.h | 37 ++++++++++++++----- .../Inelastic/Manipulation/IqtPresenter.cpp | 4 +- .../Inelastic/Manipulation/IqtPresenter.h | 4 +- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/IqtModel.h b/qt/scientific_interfaces/Inelastic/Manipulation/IqtModel.h index 340f8cebf096..52c541000bdc 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/IqtModel.h +++ b/qt/scientific_interfaces/Inelastic/Manipulation/IqtModel.h @@ -17,20 +17,37 @@ using namespace Mantid::API; namespace MantidQt { namespace CustomInterfaces { -class MANTIDQT_INELASTIC_DLL IqtModel { +class MANTIDQT_INELASTIC_DLL IIqtModel { + +public: + virtual ~IIqtModel() = default; + virtual void setupTransformToIqt(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner, + std::string const &outputWorkspace) = 0; + virtual void setSampleWorkspace(std::string const &sampleWorkspace) = 0; + virtual void setResWorkspace(std::string const &resWorkspace) = 0; + virtual void setNIterations(std::string const &nIterations) = 0; + virtual void setEnergyMin(double energyMin) = 0; + virtual void setEnergyMax(double energyMax) = 0; + virtual void setNumBins(double numBins) = 0; + virtual void setCalculateErrors(bool calculateErrors) = 0; + virtual void setEnforceNormalization(bool enforceNormalization) = 0; +}; + +class MANTIDQT_INELASTIC_DLL IqtModel : public IIqtModel { public: IqtModel(); ~IqtModel() = default; - void setupTransformToIqt(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner, std::string const &outputWorkspace); - void setSampleWorkspace(std::string const &sampleWorkspace); - void setResWorkspace(std::string const &resWorkspace); - void setNIterations(std::string const &nIterations); - void setEnergyMin(double energyMin); - void setEnergyMax(double energyMax); - void setNumBins(double numBins); - void setCalculateErrors(bool calculateErrors); - void setEnforceNormalization(bool enforceNormalization); + void setupTransformToIqt(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner, + std::string const &outputWorkspace) override; + void setSampleWorkspace(std::string const &sampleWorkspace) override; + void setResWorkspace(std::string const &resWorkspace) override; + void setNIterations(std::string const &nIterations) override; + void setEnergyMin(double energyMin) override; + void setEnergyMax(double energyMax) override; + void setNumBins(double numBins) override; + void setCalculateErrors(bool calculateErrors) override; + void setEnforceNormalization(bool enforceNormalization) override; private: std::string m_sampleWorkspace; diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/IqtPresenter.cpp b/qt/scientific_interfaces/Inelastic/Manipulation/IqtPresenter.cpp index b3998034a483..9de6de8a29ef 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/IqtPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/Manipulation/IqtPresenter.cpp @@ -28,8 +28,8 @@ Mantid::Kernel::Logger g_log("Iqt"); namespace MantidQt { namespace CustomInterfaces { -IqtPresenter::IqtPresenter(QWidget *parent, IIqtView *view) - : DataManipulation(parent), m_view(view), m_model(std::make_unique()), m_selectedSpectrum(0) { +IqtPresenter::IqtPresenter(QWidget *parent, IIqtView *view, std::unique_ptr model) + : DataManipulation(parent), m_view(view), m_model(std::move(model)), m_selectedSpectrum(0) { m_view->subscribePresenter(this); setOutputPlotOptionsPresenter( std::make_unique(m_view->getPlotOptions(), PlotWidget::SpectraTiled)); diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/IqtPresenter.h b/qt/scientific_interfaces/Inelastic/Manipulation/IqtPresenter.h index 929c7296a7b8..e1420c9727c4 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/IqtPresenter.h +++ b/qt/scientific_interfaces/Inelastic/Manipulation/IqtPresenter.h @@ -33,7 +33,7 @@ using namespace Mantid::API; class MANTIDQT_INELASTIC_DLL IqtPresenter : public DataManipulation, public IIqtPresenter { public: - IqtPresenter(QWidget *parent, IIqtView *view); + IqtPresenter(QWidget *parent, IIqtView *view, std::unique_ptr model); ~IqtPresenter() = default; void setup() override; @@ -67,7 +67,7 @@ class MANTIDQT_INELASTIC_DLL IqtPresenter : public DataManipulation, public IIqt void setRunIsRunning(bool running); IIqtView *m_view; - std::unique_ptr m_model; + std::unique_ptr m_model; int m_selectedSpectrum; From d627fbb106ebfad016bbaf9a4d255bba4d9d7369 Mon Sep 17 00:00:00 2001 From: adriazalvarez Date: Fri, 10 May 2024 11:17:19 +0100 Subject: [PATCH 06/58] Initialize sqw presenter passing model pointer --- .../Inelastic/Manipulation/SqwModel.h | 63 +++++++++++++------ .../Inelastic/Manipulation/SqwPresenter.cpp | 4 +- .../Inelastic/Manipulation/SqwPresenter.h | 4 +- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/SqwModel.h b/qt/scientific_interfaces/Inelastic/Manipulation/SqwModel.h index 664c4d0b294d..00248621a2c4 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/SqwModel.h +++ b/qt/scientific_interfaces/Inelastic/Manipulation/SqwModel.h @@ -18,30 +18,57 @@ using namespace Mantid::API; namespace MantidQt { namespace CustomInterfaces { -class MANTIDQT_INELASTIC_DLL SqwModel { +class MANTIDQT_INELASTIC_DLL ISqwModel { + +public: + virtual ~ISqwModel() = default; + virtual void setupRebinAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner) = 0; + virtual void setupSofQWAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner) = 0; + virtual void setupAddSampleLogAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner) = 0; + virtual void setInputWorkspace(const std::string &workspace) = 0; + virtual void setQMin(double qMin) = 0; + virtual void setQWidth(double qWidth) = 0; + virtual void setQMax(double qMax) = 0; + virtual void setEMin(double eMin) = 0; + virtual void setEWidth(double eWidth) = 0; + virtual void setEMax(double eMax) = 0; + virtual void setEFixed(const double eFixed) = 0; + virtual void setRebinInEnergy(bool scale) = 0; + virtual std::string getEFixedFromInstrument(std::string const &instrumentName, std::string analyser, + std::string const &reflection) = 0; + virtual std::string getOutputWorkspace() = 0; + virtual MatrixWorkspace_sptr getRqwWorkspace() = 0; + virtual UserInputValidator validate(std::tuple const qRange, + std::tuple const eRange) = 0; + virtual MatrixWorkspace_sptr loadInstrumentWorkspace(const std::string &instrumentName, const std::string &analyser, + const std::string &reflection) = 0; +}; + +class MANTIDQT_INELASTIC_DLL SqwModel : public ISqwModel { public: SqwModel(); ~SqwModel() = default; - void setupRebinAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner); - void setupSofQWAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner); - void setupAddSampleLogAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner); - void setInputWorkspace(const std::string &workspace); - void setQMin(double qMin); - void setQWidth(double qWidth); - void setQMax(double qMax); - void setEMin(double eMin); - void setEWidth(double eWidth); - void setEMax(double eMax); - void setEFixed(const double eFixed); - void setRebinInEnergy(bool scale); + void setupRebinAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner) override; + void setupSofQWAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner) override; + void setupAddSampleLogAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner) override; + void setInputWorkspace(const std::string &workspace) override; + void setQMin(double qMin) override; + void setQWidth(double qWidth) override; + void setQMax(double qMax) override; + void setEMin(double eMin) override; + void setEWidth(double eWidth) override; + void setEMax(double eMax) override; + void setEFixed(const double eFixed) override; + void setRebinInEnergy(bool scale) override; std::string getEFixedFromInstrument(std::string const &instrumentName, std::string analyser, - std::string const &reflection); - std::string getOutputWorkspace(); - MatrixWorkspace_sptr getRqwWorkspace(); - UserInputValidator validate(std::tuple const qRange, std::tuple const eRange); + std::string const &reflection) override; + std::string getOutputWorkspace() override; + MatrixWorkspace_sptr getRqwWorkspace() override; + UserInputValidator validate(std::tuple const qRange, + std::tuple const eRange) override; MatrixWorkspace_sptr loadInstrumentWorkspace(const std::string &instrumentName, const std::string &analyser, - const std::string &reflection); + const std::string &reflection) override; private: std::string m_inputWorkspace; diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/SqwPresenter.cpp b/qt/scientific_interfaces/Inelastic/Manipulation/SqwPresenter.cpp index 7fe5dad0c9b1..e35c3638439b 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/SqwPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/Manipulation/SqwPresenter.cpp @@ -34,8 +34,8 @@ namespace MantidQt::CustomInterfaces { //---------------------------------------------------------------------------------------------- /** Constructor */ -SqwPresenter::SqwPresenter(QWidget *parent, ISqwView *view) - : DataManipulation(parent), m_model(std::make_unique()), m_view(view) { +SqwPresenter::SqwPresenter(QWidget *parent, ISqwView *view, std::unique_ptr model) + : DataManipulation(parent), m_view(view), m_model(std::move(model)) { m_view->subscribePresenter(this); setOutputPlotOptionsPresenter( std::make_unique(m_view->getPlotOptions(), PlotWidget::SpectraSliceSurface)); diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/SqwPresenter.h b/qt/scientific_interfaces/Inelastic/Manipulation/SqwPresenter.h index 7f3d75d16449..a9c54a23d9ca 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/SqwPresenter.h +++ b/qt/scientific_interfaces/Inelastic/Manipulation/SqwPresenter.h @@ -42,7 +42,7 @@ class ISqwPresenter { class MANTIDQT_INELASTIC_DLL SqwPresenter : public DataManipulation, public ISqwPresenter { public: - SqwPresenter(QWidget *parent, ISqwView *view); + SqwPresenter(QWidget *parent, ISqwView *view, std::unique_ptr model); ~SqwPresenter() = default; void setup() override; @@ -70,8 +70,8 @@ class MANTIDQT_INELASTIC_DLL SqwPresenter : public DataManipulation, public ISqw void plotRqwContour(); void setFileExtensionsByName(bool filter) override; - std::unique_ptr m_model; ISqwView *m_view; + std::unique_ptr m_model; }; } // namespace CustomInterfaces } // namespace MantidQt From 013c71eb3997d11515896f5b8b9cfe138e63ac42 Mon Sep 17 00:00:00 2001 From: adriazalvarez Date: Fri, 10 May 2024 11:18:25 +0100 Subject: [PATCH 07/58] Initialize symmetrise presenter passing model pointer --- .../Inelastic/Manipulation/SymmetriseModel.h | 33 ++++++++++++++----- .../Manipulation/SymmetrisePresenter.cpp | 5 +-- .../Manipulation/SymmetrisePresenter.h | 4 +-- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/SymmetriseModel.h b/qt/scientific_interfaces/Inelastic/Manipulation/SymmetriseModel.h index 8812aa30e844..e04eb1d2a787 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/SymmetriseModel.h +++ b/qt/scientific_interfaces/Inelastic/Manipulation/SymmetriseModel.h @@ -17,20 +17,35 @@ using namespace Mantid::API; namespace MantidQt { namespace CustomInterfaces { -class MANTIDQT_INELASTIC_DLL SymmetriseModel { +class MANTIDQT_INELASTIC_DLL ISymmetriseModel { + +public: + virtual ~ISymmetriseModel() = default; + virtual void setupPreviewAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner, + std::vector const &spectraRange) = 0; + virtual std::string setupSymmetriseAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner) = 0; + virtual void reflectNegativeToPositive() = 0; + virtual void setWorkspaceName(std::string const &workspaceName) = 0; + virtual void setEMin(double value) = 0; + virtual void setEMax(double value) = 0; + virtual void setIsPositiveReflect(bool value) = 0; + virtual bool getIsPositiveReflect() const = 0; +}; + +class MANTIDQT_INELASTIC_DLL SymmetriseModel : public ISymmetriseModel { public: SymmetriseModel(); ~SymmetriseModel() = default; void setupPreviewAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner, - std::vector const &spectraRange); - std::string setupSymmetriseAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner); - void reflectNegativeToPositive(); - void setWorkspaceName(std::string const &workspaceName); - void setEMin(double value); - void setEMax(double value); - void setIsPositiveReflect(bool value); - bool getIsPositiveReflect() const; + std::vector const &spectraRange) override; + std::string setupSymmetriseAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner) override; + void reflectNegativeToPositive() override; + void setWorkspaceName(std::string const &workspaceName) override; + void setEMin(double value) override; + void setEMax(double value) override; + void setIsPositiveReflect(bool value) override; + bool getIsPositiveReflect() const override; private: std::string m_inputWorkspace; diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/SymmetrisePresenter.cpp b/qt/scientific_interfaces/Inelastic/Manipulation/SymmetrisePresenter.cpp index 46a0e6f8fbd3..1932c9dce657 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/SymmetrisePresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/Manipulation/SymmetrisePresenter.cpp @@ -26,9 +26,10 @@ namespace CustomInterfaces { //---------------------------------------------------------------------------------------------- /** Constructor */ -SymmetrisePresenter::SymmetrisePresenter(QWidget *parent, ISymmetriseView *view) +SymmetrisePresenter::SymmetrisePresenter(QWidget *parent, ISymmetriseView *view, + std::unique_ptr model) : DataManipulation(parent), m_adsInstance(Mantid::API::AnalysisDataService::Instance()), m_view(view), - m_model(std::make_unique()), m_isPreview(false) { + m_model(std::move(model)), m_isPreview(false) { m_view->subscribePresenter(this); setOutputPlotOptionsPresenter( std::make_unique(m_view->getPlotOptions(), PlotWidget::Spectra)); diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/SymmetrisePresenter.h b/qt/scientific_interfaces/Inelastic/Manipulation/SymmetrisePresenter.h index cf80ec728504..284855513e30 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/SymmetrisePresenter.h +++ b/qt/scientific_interfaces/Inelastic/Manipulation/SymmetrisePresenter.h @@ -51,7 +51,7 @@ class ISymmetrisePresenter { */ class MANTIDQT_INELASTIC_DLL SymmetrisePresenter : public DataManipulation, public ISymmetrisePresenter { public: - SymmetrisePresenter(QWidget *parent, ISymmetriseView *view); + SymmetrisePresenter(QWidget *parent, ISymmetriseView *view, std::unique_ptr model); ~SymmetrisePresenter() override; void setup() override; @@ -74,7 +74,7 @@ class MANTIDQT_INELASTIC_DLL SymmetrisePresenter : public DataManipulation, publ Mantid::API::AnalysisDataServiceImpl &m_adsInstance; ISymmetriseView *m_view; - std::unique_ptr m_model; + std::unique_ptr m_model; // wether batch algorunner is running preview or run buttons bool m_isPreview; }; From 9ab025dbcfeeb2de625cf4e96d9db8f7f3b07488 Mon Sep 17 00:00:00 2001 From: adriazalvarez Date: Fri, 10 May 2024 11:21:17 +0100 Subject: [PATCH 08/58] Initialize tab widgets explicitly --- qt/scientific_interfaces/Inelastic/Manipulation/ElwinView.cpp | 2 +- qt/scientific_interfaces/Inelastic/Manipulation/IqtView.cpp | 2 +- qt/scientific_interfaces/Inelastic/Manipulation/MomentsView.cpp | 2 +- qt/scientific_interfaces/Inelastic/Manipulation/SqwView.cpp | 2 +- .../Inelastic/Manipulation/SymmetriseView.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/ElwinView.cpp b/qt/scientific_interfaces/Inelastic/Manipulation/ElwinView.cpp index 06a2932593ce..e2d7486c48be 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/ElwinView.cpp +++ b/qt/scientific_interfaces/Inelastic/Manipulation/ElwinView.cpp @@ -27,7 +27,7 @@ Mantid::Kernel::Logger g_log("Elwin"); namespace MantidQt::CustomInterfaces { using namespace Inelastic; -ElwinView::ElwinView(QWidget *parent) : m_presenter(), m_elwTree(nullptr) { +ElwinView::ElwinView(QWidget *parent) : QWidget(parent), m_presenter(), m_elwTree(nullptr) { // Create Editor Factories m_dblEdFac = new DoubleEditorFactory(this); diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/IqtView.cpp b/qt/scientific_interfaces/Inelastic/Manipulation/IqtView.cpp index e5b279dcb890..d58717490805 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/IqtView.cpp +++ b/qt/scientific_interfaces/Inelastic/Manipulation/IqtView.cpp @@ -79,7 +79,7 @@ std::tuple calculateBinParameters(std::string const &wsNa namespace MantidQt::CustomInterfaces { -IqtView::IqtView(QWidget *parent) : m_presenter(), m_iqtTree(nullptr) { +IqtView::IqtView(QWidget *parent) : QWidget(parent), m_presenter(), m_iqtTree(nullptr) { m_uiForm.setupUi(parent); m_dblEdFac = new DoubleEditorFactory(this); m_dblManager = new QtDoublePropertyManager(); diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/MomentsView.cpp b/qt/scientific_interfaces/Inelastic/Manipulation/MomentsView.cpp index 84b950b7d9fc..3401a3a9f070 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/MomentsView.cpp +++ b/qt/scientific_interfaces/Inelastic/Manipulation/MomentsView.cpp @@ -24,7 +24,7 @@ namespace MantidQt::CustomInterfaces { //---------------------------------------------------------------------------------------------- /** Constructor */ -MomentsView::MomentsView(QWidget *parent) : m_presenter() { +MomentsView::MomentsView(QWidget *parent) : QWidget(parent), m_presenter() { m_uiForm.setupUi(parent); m_dblManager = new QtDoublePropertyManager(); m_dblEdFac = new DoubleEditorFactory(this); diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/SqwView.cpp b/qt/scientific_interfaces/Inelastic/Manipulation/SqwView.cpp index cf8d7333ca49..014c6d3a8919 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/SqwView.cpp +++ b/qt/scientific_interfaces/Inelastic/Manipulation/SqwView.cpp @@ -33,7 +33,7 @@ namespace MantidQt::CustomInterfaces { //---------------------------------------------------------------------------------------------- /** Constructor */ -SqwView::SqwView(QWidget *parent) : m_presenter() { +SqwView::SqwView(QWidget *parent) : QWidget(parent), m_presenter() { m_uiForm.setupUi(parent); m_uiForm.rqwPlot2D->setCanvasColour(QColor(240, 240, 240)); diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/SymmetriseView.cpp b/qt/scientific_interfaces/Inelastic/Manipulation/SymmetriseView.cpp index 6f4858fc93e5..132248baedbb 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/SymmetriseView.cpp +++ b/qt/scientific_interfaces/Inelastic/Manipulation/SymmetriseView.cpp @@ -31,7 +31,7 @@ namespace MantidQt::CustomInterfaces { //---------------------------------------------------------------------------------------------- /** Constructor */ -SymmetriseView::SymmetriseView(QWidget *parent) : m_presenter() { +SymmetriseView::SymmetriseView(QWidget *parent) : QWidget(parent), m_presenter() { m_uiForm.setupUi(parent); m_dblManager = new QtDoublePropertyManager(); From 710cc464219d7812ed1a2e7b597b4990209738e6 Mon Sep 17 00:00:00 2001 From: adriazalvarez Date: Fri, 10 May 2024 14:19:47 +0100 Subject: [PATCH 09/58] Convert to const some members of sqw and moments models --- .../Inelastic/Manipulation/MomentsModel.cpp | 2 +- .../Inelastic/Manipulation/MomentsModel.h | 4 ++-- .../Inelastic/Manipulation/SqwModel.cpp | 10 +++++----- .../Inelastic/Manipulation/SqwModel.h | 20 +++++++++---------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/MomentsModel.cpp b/qt/scientific_interfaces/Inelastic/Manipulation/MomentsModel.cpp index e494cad87aa2..56c8605759b6 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/MomentsModel.cpp +++ b/qt/scientific_interfaces/Inelastic/Manipulation/MomentsModel.cpp @@ -52,6 +52,6 @@ void MomentsModel::setScale(bool scale) { m_scale = scale; } void MomentsModel::setScaleValue(double scaleValue) { m_scaleValue = scaleValue; } -std::string MomentsModel::getOutputWorkspace() { return m_outputWorkspaceName; } +std::string MomentsModel::getOutputWorkspace() const { return m_outputWorkspaceName; } } // namespace MantidQt::CustomInterfaces diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/MomentsModel.h b/qt/scientific_interfaces/Inelastic/Manipulation/MomentsModel.h index bbba77242f6e..db1f380e564e 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/MomentsModel.h +++ b/qt/scientific_interfaces/Inelastic/Manipulation/MomentsModel.h @@ -24,7 +24,7 @@ class MANTIDQT_INELASTIC_DLL IMomentsModel { virtual void setEMax(double eMax) = 0; virtual void setScale(bool scale) = 0; virtual void setScaleValue(double scaleValue) = 0; - virtual std::string getOutputWorkspace() = 0; + virtual std::string getOutputWorkspace() const = 0; }; class MANTIDQT_INELASTIC_DLL MomentsModel : public IMomentsModel { @@ -38,7 +38,7 @@ class MANTIDQT_INELASTIC_DLL MomentsModel : public IMomentsModel { void setEMax(double eMax) override; void setScale(bool scale) override; void setScaleValue(double scaleValue) override; - std::string getOutputWorkspace() override; + std::string getOutputWorkspace() const override; private: std::string m_inputWorkspace; diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/SqwModel.cpp b/qt/scientific_interfaces/Inelastic/Manipulation/SqwModel.cpp index ddb21d7978e6..1941eea5e91a 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/SqwModel.cpp +++ b/qt/scientific_interfaces/Inelastic/Manipulation/SqwModel.cpp @@ -114,16 +114,16 @@ void SqwModel::setEFixed(const double eFixed) { m_eFixed = eFixed; } void SqwModel::setRebinInEnergy(bool scale) { m_rebinInEnergy = scale; } -std::string SqwModel::getOutputWorkspace() { return m_baseName + "_sqw"; } +std::string SqwModel::getOutputWorkspace() const { return m_baseName + "_sqw"; } -MatrixWorkspace_sptr SqwModel::getRqwWorkspace() { +MatrixWorkspace_sptr SqwModel::getRqwWorkspace() const { auto const outputName = m_inputWorkspace.substr(0, m_inputWorkspace.size() - 4) + "_rqw"; convertToSpectrumAxis(m_inputWorkspace, outputName); return getADSWorkspace(outputName); } UserInputValidator SqwModel::validate(std::tuple const qRange, - std::tuple const eRange) { + std::tuple const eRange) const { double const tolerance = 1e-10; @@ -145,7 +145,7 @@ UserInputValidator SqwModel::validate(std::tuple const qRange, } std::string SqwModel::getEFixedFromInstrument(std::string const &instrumentName, std::string analyser, - std::string const &reflection) { + std::string const &reflection) const { // In the IRIS IPF there is no fmica component if (instrumentName == "IRIS" && analyser == "fmica") @@ -179,7 +179,7 @@ std::string SqwModel::getEFixedFromInstrument(std::string const &instrumentName, * @param reflection Relection being used (optional) */ MatrixWorkspace_sptr SqwModel::loadInstrumentWorkspace(const std::string &instrumentName, const std::string &analyser, - const std::string &reflection) { + const std::string &reflection) const { std::string idfdirectory = Mantid::Kernel::ConfigService::Instance().getString("instrumentDefinition.directory"); auto const ipfFilename = idfdirectory + instrumentName + "_" + analyser + "_" + reflection + "_Parameters.xml"; diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/SqwModel.h b/qt/scientific_interfaces/Inelastic/Manipulation/SqwModel.h index 00248621a2c4..99e490e7581d 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/SqwModel.h +++ b/qt/scientific_interfaces/Inelastic/Manipulation/SqwModel.h @@ -35,13 +35,13 @@ class MANTIDQT_INELASTIC_DLL ISqwModel { virtual void setEFixed(const double eFixed) = 0; virtual void setRebinInEnergy(bool scale) = 0; virtual std::string getEFixedFromInstrument(std::string const &instrumentName, std::string analyser, - std::string const &reflection) = 0; - virtual std::string getOutputWorkspace() = 0; - virtual MatrixWorkspace_sptr getRqwWorkspace() = 0; + std::string const &reflection) const = 0; + virtual std::string getOutputWorkspace() const = 0; + virtual MatrixWorkspace_sptr getRqwWorkspace() const = 0; virtual UserInputValidator validate(std::tuple const qRange, - std::tuple const eRange) = 0; + std::tuple const eRange) const = 0; virtual MatrixWorkspace_sptr loadInstrumentWorkspace(const std::string &instrumentName, const std::string &analyser, - const std::string &reflection) = 0; + const std::string &reflection) const = 0; }; class MANTIDQT_INELASTIC_DLL SqwModel : public ISqwModel { @@ -62,13 +62,13 @@ class MANTIDQT_INELASTIC_DLL SqwModel : public ISqwModel { void setEFixed(const double eFixed) override; void setRebinInEnergy(bool scale) override; std::string getEFixedFromInstrument(std::string const &instrumentName, std::string analyser, - std::string const &reflection) override; - std::string getOutputWorkspace() override; - MatrixWorkspace_sptr getRqwWorkspace() override; + std::string const &reflection) const override; + std::string getOutputWorkspace() const override; + MatrixWorkspace_sptr getRqwWorkspace() const override; UserInputValidator validate(std::tuple const qRange, - std::tuple const eRange) override; + std::tuple const eRange) const override; MatrixWorkspace_sptr loadInstrumentWorkspace(const std::string &instrumentName, const std::string &analyser, - const std::string &reflection) override; + const std::string &reflection) const override; private: std::string m_inputWorkspace; From 47d0d9c08dc45f1009966ae8da484d4c449571dd Mon Sep 17 00:00:00 2001 From: Jonathan Haigh Date: Mon, 13 May 2024 11:30:06 +0100 Subject: [PATCH 10/58] added section to packaging documentation --- dev-docs/source/Packaging.rst | 55 ++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/dev-docs/source/Packaging.rst b/dev-docs/source/Packaging.rst index b90ef13e116f..88ac9edccf34 100644 --- a/dev-docs/source/Packaging.rst +++ b/dev-docs/source/Packaging.rst @@ -118,6 +118,59 @@ The ``--package-suffix`` argument is an optional string to append to the name of the final package. We generally pick ``Unstable`` for installers not built by the CI pipeline to indicate it has been built outside of the standard process. +.. _build_packages_from_branch: + +Build packages from branch using Jenkins +---------------------------------------- + +Developers can build packages to test branches using the ``build_packages_from_branch`` `Jenkins job `_. This job provides the ability to, + +- Run system tests on Windows, Mac, Linux, or all three. +- Build a packages on Windows, Mac, Linux, or all three. +- Publish the package(s) to a given Anaconda channel and label. +- Publish the package(s) to a given Github repository under a specified tag. + +for a given branch of mantid. The branch can be form the main mantid repo or from a remote. + +Options +####### + +- ``BUILD_DEVEL`` [``none``, ``all``, ``linux-64``, ``win-64``, ``osx-64``]: Run the system tests for this OS. +- ``BUILD_PACKAGE`` [``none``, ``all``, ``linux-64``, ``win-64``, ``osx-64``]: Build a package on this OS. +- ``PACKAGE_SUFFIX``: String to append onto the standalone package name, useful for distinguishing builds. By default this is ``Unstable``. +- ``PUBLISH_TO_ANACONDA``: Set true to publish to the given Anaconda channel and label. +- ``PUBLISH_TO_GITHUB``: Set true to publish to the Github repository using the specified tag. +- ``ANACONDA_CHANNEL``: Anaconda channel to upload the package to. By default this is ``mantid``. +- ``ANACONDA_CHANNEL_LABEL``: Label attached to the uploaded package. By default this is ``unstable``. +- ``GITHUB_RELEASES_REPO``: Repository to store the release. By Default this is ``mantidproject/mantid``. +- ``GITHUB_RELEASES_TAG``: Name of the tag for the release; only to be used for release candidate builds. +- ``ANACONDA_TOKEN_CREDENTIAL_ID`` [``anaconda-cloud-token``, ``anaconda-token-ornl``]: One of two credentials to use for publishing to Anaconda. +- ``GH_ORGANIZATION_OR_USERNAME``: Name of the organisation or Github user name who owns the repository with the code to build. By default this is ``mantidproject``, if you are building from a fork this will need to change to your username. +- ``BRANCH_NAME``: Name of the branch to build to packages from. + +Example +####### + +Say I've implemented a new file searching method on a branch ``1234_new_file_search`` and I want to test this on IDAaaS, one of the easiest ways to do this would be to build the packages and upload them to Anaconda using the pipeline. These are the steps I'd take to do this. + +1. Go to the ``build_packages_from_branch`` `Jenkins job `_. +2. If needed click ``login`` in the top right of the window. +3. Go to ``Build with parameters`` in the side bar. +4. Fill out the following options: + + - ``BUILD_DEVEL`` = ``none`` + - ``BUILD_PACKAGE`` = ``linux-64`` + - ``PUBLISH_TO_ANACONDA`` = true + - ``ANACONDA_CHANNEL_LABEL`` = ``new_file_system_test`` + - ``ANACONDA_TOKEN_CREDENTIAL_ID`` = ``anaconda-cloud-token`` + - ``BRANCH_NAME`` = ``1234_new_file_search`` + +5. Click ``Build``. This will take you back to the main job page, the build just set off will be the most recent (highest number) build on the left hand side. +6. Once the job has successfully completed, check `the Mantid Anaconda page `_ to make sure it has uploaded. +7. Head to IDAaaS (or any linux system) and run ``mamba install -c mantid/label/new_file_system_test mantidworkbench`` in a new environment to install the test package. + +Most often, you won't need to upload the packages to Anaconda, this is most useful in cases where installing standalone packages is inconvenient. Standalone package builds created by the jenkins job can be found under the jenkins job build artifacts, this is near the top of the page. Say you built a package for Windows using the jenkins job, you should find a ``mantidworkbench`` exe file in the build artifacts. + .. _conda: https://conda.io .. _mantid-conda-recipes: https://github.com/mantidproject/mantid/tree/main/conda @@ -130,4 +183,4 @@ by the CI pipeline to indicate it has been built outside of the standard process .. _download-page: https://download.mantidproject.org .. _nsis: https://sourceforge.net/projects/nsis/ .. _dmg: https://en.wikipedia.org/wiki/Apple_Disk_Image -.. _standalone-scripts: https://github.com/mantidproject/mantid/blob/main/installers/conda +.. _build_packages_from_branch_job: https://builds.mantidproject.org/job/build_packages_from_branch/ From ba7f7f4d1b9b0a4f1f45d2913cad47526045a81b Mon Sep 17 00:00:00 2001 From: Jonathan Haigh <35813666+jhaigh0@users.noreply.github.com> Date: Mon, 13 May 2024 13:21:20 +0100 Subject: [PATCH 11/58] review suggestions Co-authored-by: Gui Maciel Pereira <80104863+GuiMacielPereira@users.noreply.github.com> --- dev-docs/source/Packaging.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dev-docs/source/Packaging.rst b/dev-docs/source/Packaging.rst index 88ac9edccf34..52e042c55f01 100644 --- a/dev-docs/source/Packaging.rst +++ b/dev-docs/source/Packaging.rst @@ -130,7 +130,7 @@ Developers can build packages to test branches using the ``build_packages_from_b - Publish the package(s) to a given Anaconda channel and label. - Publish the package(s) to a given Github repository under a specified tag. -for a given branch of mantid. The branch can be form the main mantid repo or from a remote. +for a given branch of mantid. The branch can be from the main mantid repo or from a remote. Options ####### @@ -146,7 +146,7 @@ Options - ``GITHUB_RELEASES_TAG``: Name of the tag for the release; only to be used for release candidate builds. - ``ANACONDA_TOKEN_CREDENTIAL_ID`` [``anaconda-cloud-token``, ``anaconda-token-ornl``]: One of two credentials to use for publishing to Anaconda. - ``GH_ORGANIZATION_OR_USERNAME``: Name of the organisation or Github user name who owns the repository with the code to build. By default this is ``mantidproject``, if you are building from a fork this will need to change to your username. -- ``BRANCH_NAME``: Name of the branch to build to packages from. +- ``BRANCH_NAME``: Name of the branch to build the packages from. Example ####### @@ -165,7 +165,7 @@ Say I've implemented a new file searching method on a branch ``1234_new_file_sea - ``ANACONDA_TOKEN_CREDENTIAL_ID`` = ``anaconda-cloud-token`` - ``BRANCH_NAME`` = ``1234_new_file_search`` -5. Click ``Build``. This will take you back to the main job page, the build just set off will be the most recent (highest number) build on the left hand side. +5. Click ``Build``. This will take you back to the main job page, the build just set off will be the most recent (highest number) build on the left hand side. It is a good idea to make note of the build number / copy the link somewhere safe. If the build is for testing a pr, make suer to add the link to the testing instructions. 6. Once the job has successfully completed, check `the Mantid Anaconda page `_ to make sure it has uploaded. 7. Head to IDAaaS (or any linux system) and run ``mamba install -c mantid/label/new_file_system_test mantidworkbench`` in a new environment to install the test package. From 7b514e67efb035a848a2148b39ca658eb0540fad Mon Sep 17 00:00:00 2001 From: Jonathan Haigh <35813666+jhaigh0@users.noreply.github.com> Date: Mon, 13 May 2024 14:52:32 +0100 Subject: [PATCH 12/58] Update dev-docs/source/Packaging.rst Co-authored-by: Gui Maciel Pereira <80104863+GuiMacielPereira@users.noreply.github.com> --- dev-docs/source/Packaging.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-docs/source/Packaging.rst b/dev-docs/source/Packaging.rst index 52e042c55f01..dee319a1951c 100644 --- a/dev-docs/source/Packaging.rst +++ b/dev-docs/source/Packaging.rst @@ -165,7 +165,7 @@ Say I've implemented a new file searching method on a branch ``1234_new_file_sea - ``ANACONDA_TOKEN_CREDENTIAL_ID`` = ``anaconda-cloud-token`` - ``BRANCH_NAME`` = ``1234_new_file_search`` -5. Click ``Build``. This will take you back to the main job page, the build just set off will be the most recent (highest number) build on the left hand side. It is a good idea to make note of the build number / copy the link somewhere safe. If the build is for testing a pr, make suer to add the link to the testing instructions. +5. Click ``Build``. This will take you back to the main job page, the build just set off will be the most recent (highest number) build on the left hand side. It is a good idea to make note of the build number / copy the link somewhere safe. If the build is for testing a pr, make sure to add the link to the testing instructions. 6. Once the job has successfully completed, check `the Mantid Anaconda page `_ to make sure it has uploaded. 7. Head to IDAaaS (or any linux system) and run ``mamba install -c mantid/label/new_file_system_test mantidworkbench`` in a new environment to install the test package. From 64d57434781177ae6009494d3af066f147874fc2 Mon Sep 17 00:00:00 2001 From: Conor Finn Date: Mon, 13 May 2024 11:01:05 +0100 Subject: [PATCH 13/58] Add note about missing wavelength tooltips This is a known issue, but low priority for the SANS group right now. RE #35085 --- dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst b/dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst index b95e3faa256f..7edbc1ba6508 100644 --- a/dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst +++ b/dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst @@ -263,3 +263,5 @@ Display have clear tooltips. #. In the settings, hover over a random selection of buttons and text boxes to check tooltips are still there. Users rely on the tooltips a lot and really do notice each missing one. + *Note: The* ``Wavelength`` *section of the settings is missing its tooltips. We and the users are aware of this so an + issue should not be made when it is discovered.* From dd2f39da195e8132b99bc2da2cf2c09fac79a583 Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 25 Apr 2024 16:28:51 +0100 Subject: [PATCH 14/58] Remove qt connection from IETPresenter to DataReductionTab --- .../Indirect/Reduction/DataReductionTab.cpp | 3 +++ .../Indirect/Reduction/DataReductionTab.h | 2 ++ .../Indirect/Reduction/ILLEnergyTransfer.cpp | 3 +-- .../Indirect/Reduction/ILLEnergyTransfer.h | 3 ++- .../Indirect/Reduction/ISISCalibration.cpp | 7 ++----- .../Indirect/Reduction/ISISCalibration.h | 3 ++- .../Indirect/Reduction/ISISDiagnostics.cpp | 5 +---- .../Indirect/Reduction/ISISDiagnostics.h | 3 ++- .../Indirect/Reduction/ISISEnergyTransferPresenter.cpp | 4 +--- .../Indirect/Reduction/ISISEnergyTransferPresenter.h | 2 +- .../Indirect/Reduction/Transmission.cpp | 4 +--- qt/scientific_interfaces/Indirect/Reduction/Transmission.h | 2 +- 12 files changed, 19 insertions(+), 22 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.cpp b/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.cpp index 6cca6a1770c2..40b2ecc9db83 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.cpp @@ -28,6 +28,7 @@ namespace MantidQt::CustomInterfaces { DataReductionTab::DataReductionTab(IDataReduction *idrUI, QObject *parent) : InelasticTab(parent), m_idrUI(idrUI), m_tabRunning(false) { connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(tabExecutionComplete(bool))); + connect(this, SIGNAL(newInstrumentConfiguration()), this, SLOT(handleNewInstrumentConfiguration())); } DataReductionTab::~DataReductionTab() = default; @@ -75,6 +76,8 @@ void DataReductionTab::tabExecutionComplete(bool error) { } } +void IndirectDataReductionTab::handleNewInstrumentConfiguration() { updateInstrumentConfiguration(); } + /** * Gets the current instrument workspace * diff --git a/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.h b/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.h index 26b4856f21ff..5ad49aeb6c49 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.h +++ b/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.h @@ -88,9 +88,11 @@ public slots: private slots: void tabExecutionComplete(bool error); + void handleNewInstrumentConfiguration(); private: virtual void setFileExtensionsByName(bool filter) { UNUSED_ARG(filter); }; + virtual void updateInstrumentConfiguration() = 0; std::unique_ptr m_plotOptionsPresenter; bool m_tabRunning; diff --git a/qt/scientific_interfaces/Indirect/Reduction/ILLEnergyTransfer.cpp b/qt/scientific_interfaces/Indirect/Reduction/ILLEnergyTransfer.cpp index 8a6f3efe154f..4a35cdbc7b29 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ILLEnergyTransfer.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/ILLEnergyTransfer.cpp @@ -33,7 +33,6 @@ namespace MantidQt::CustomInterfaces { ILLEnergyTransfer::ILLEnergyTransfer(IDataReduction *idrUI, QWidget *parent) : DataReductionTab(idrUI, parent) { m_uiForm.setupUi(parent); - connect(this, SIGNAL(newInstrumentConfiguration()), this, SLOT(setInstrumentDefault())); connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(algorithmComplete(bool))); connect(m_uiForm.pbRun, SIGNAL(clicked()), this, SLOT(runClicked())); @@ -334,7 +333,7 @@ void ILLEnergyTransfer::save() { /** * Called when the instrument has changed, used to update default values. */ -void ILLEnergyTransfer::setInstrumentDefault() { +void ILLEnergyTransfer::updateInstrumentConfiguration() { auto const instrument = getInstrumentDetail("instrument"); // Set instrument in run file widgets diff --git a/qt/scientific_interfaces/Indirect/Reduction/ILLEnergyTransfer.h b/qt/scientific_interfaces/Indirect/Reduction/ILLEnergyTransfer.h index 49bacb416f01..2fa0d00eec8d 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ILLEnergyTransfer.h +++ b/qt/scientific_interfaces/Indirect/Reduction/ILLEnergyTransfer.h @@ -30,7 +30,6 @@ public slots: private slots: void algorithmComplete(bool error); - void setInstrumentDefault(); void runClicked(); void setRunEnabled(bool enabled); @@ -38,6 +37,8 @@ private slots: QString const &message = "Run", QString const &tooltip = ""); private: + void updateInstrumentConfiguration() override; + Ui::ILLEnergyTransfer m_uiForm; double m_backScaling = 1.; double m_backCalibScaling = 1.; diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISCalibration.cpp b/qt/scientific_interfaces/Indirect/Reduction/ISISCalibration.cpp index a2b06c600533..f65296be9993 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISCalibration.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISCalibration.cpp @@ -129,9 +129,6 @@ ISISCalibration::ISISCalibration(IDataReduction *idrUI, QWidget *parent) auto resPeak = m_uiForm.ppResolution->addRangeSelector("ResPeak"); resPeak->setColour(Qt::red); - // Update instrument information when a new instrument config is selected - connect(this, SIGNAL(newInstrumentConfiguration()), this, SLOT(setDefaultInstDetails())); - // Update property map when a range selector is moved connectRangeSelectors(); // Update range selector positions when a value in the double manager changes @@ -373,7 +370,7 @@ bool ISISCalibration::validate() { /** * Sets default spectra, peak and background ranges. */ -void ISISCalibration::setDefaultInstDetails() { +void ISISCalibration::updateInstrumentConfiguration() { try { setDefaultInstDetails(getInstrumentDetails()); } catch (std::exception const &ex) { @@ -466,7 +463,7 @@ void ISISCalibration::calPlotRaw() { setPeakRangeLimits(dataX.front(), dataX.back()); setBackgroundRangeLimits(dataX.front(), dataX.back()); - setDefaultInstDetails(); + updateInstrumentConfiguration(); m_uiForm.ppCalibration->replot(); diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISCalibration.h b/qt/scientific_interfaces/Indirect/Reduction/ISISCalibration.h index acbc8ecda747..972ca6f30d72 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISCalibration.h +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISCalibration.h @@ -60,7 +60,6 @@ private slots: void calSetDefaultResolution(const Mantid::API::MatrixWorkspace_const_sptr &ws); void resCheck(bool state); ///< handles checking/unchecking of "Create RES /// File" checkbox - void setDefaultInstDetails(); void pbRunEditing(); //< Called when a user starts to type / edit the runs to load. void pbRunFinding(); //< Called when the FileFinder starts finding the files. void pbRunFinished(); //< Called when the FileFinder has finished finding the @@ -75,6 +74,8 @@ private slots: QString const &message = "Run", QString const &tooltip = ""); private: + void updateInstrumentConfiguration() override; + void setDefaultInstDetails(QMap const &instrumentDetails); void connectRangeSelectors(); void disconnectRangeSelectors(); diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISDiagnostics.cpp b/qt/scientific_interfaces/Indirect/Reduction/ISISDiagnostics.cpp index 062cca04cc90..31564506a641 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISDiagnostics.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISDiagnostics.cpp @@ -91,9 +91,6 @@ ISISDiagnostics::ISISDiagnostics(IDataReduction *idrUI, QWidget *parent) : DataR // SIGNAL/SLOT CONNECTIONS - // Update instrument information when a new instrument config is selected - connect(this, SIGNAL(newInstrumentConfiguration()), this, SLOT(setDefaultInstDetails())); - // Update properties when a range selector is changed connect(peakRangeSelector, SIGNAL(selectionChanged(double, double)), this, SLOT(rangeSelectorDropped(double, double))); @@ -245,7 +242,7 @@ void ISISDiagnostics::algorithmComplete(bool error) { /** * Sets default spectra, peak and background ranges. */ -void ISISDiagnostics::setDefaultInstDetails() { +void ISISDiagnostics::updateInstrumentConfiguration() { try { setDefaultInstDetails(getInstrumentDetails()); } catch (std::exception const &ex) { diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISDiagnostics.h b/qt/scientific_interfaces/Indirect/Reduction/ISISDiagnostics.h index 8947fc8adfbb..b19c5339fc6f 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISDiagnostics.h +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISDiagnostics.h @@ -58,7 +58,6 @@ private slots: void sliceCalib(bool state); void rangeSelectorDropped(double /*min*/, double /*max*/); void doublePropertyChanged(QtProperty * /*prop*/, double /*val*/); - void setDefaultInstDetails(); void sliceAlgDone(bool error); void pbRunEditing(); //< Called when a user starts to type / edit the runs to load. void pbRunFinding(); //< Called when the FileFinder starts finding the files. @@ -73,6 +72,8 @@ private slots: QString const &message = "Run", QString const &tooltip = ""); private: + void updateInstrumentConfiguration() override; + void setDefaultInstDetails(QMap const &instrumentDetails); void setFileExtensionsByName(bool filter) override; diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp index e8e7efeb4e7d..320b2a428bbc 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp @@ -37,8 +37,6 @@ IETPresenter::IETPresenter(IDataReduction *idrUI, IIETView *view, std::unique_pt setOutputPlotOptionsPresenter( std::make_unique(m_view->getPlotOptionsView(), PlotWidget::SpectraSliceSurface)); - - connect(this, SIGNAL(newInstrumentConfiguration()), this, SLOT(setInstrumentDefault())); } void IETPresenter::setup() {} @@ -75,7 +73,7 @@ InstrumentData IETPresenter::getInstrumentData() { instrumentDetails["save-ascii-choice"] == "true", instrumentDetails["fold-frames-choice"] == "true"); } -void IETPresenter::setInstrumentDefault() { +void IETPresenter::updateInstrumentConfiguration() { if (validateInstrumentDetails()) { InstrumentData instrumentDetails = getInstrumentData(); auto const instrumentName = instrumentDetails.getInstrument(); diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h index a3dc46588a53..9875a1790563 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h @@ -46,10 +46,10 @@ public slots: private slots: void algorithmComplete(bool error); void plotRawComplete(bool error); - void setInstrumentDefault(); private: bool validateInstrumentDetails(); + void updateInstrumentConfiguration() override; InstrumentData getInstrumentData(); diff --git a/qt/scientific_interfaces/Indirect/Reduction/Transmission.cpp b/qt/scientific_interfaces/Indirect/Reduction/Transmission.cpp index b4229dc37ba1..7fb3481b1916 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/Transmission.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/Transmission.cpp @@ -33,8 +33,6 @@ Transmission::Transmission(IDataReduction *idrUI, QWidget *parent) : DataReducti setOutputPlotOptionsPresenter( std::make_unique(m_uiForm.ipoPlotOptions, PlotWidget::Spectra, "0-2")); - connect(this, SIGNAL(newInstrumentConfiguration()), this, SLOT(setInstrument())); - // Update the preview plot when the algorithm is complete connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(transAlgDone(bool))); @@ -115,7 +113,7 @@ void Transmission::transAlgDone(bool error) { m_uiForm.pbSave->setEnabled(true); } -void Transmission::setInstrument() { +void Transmission::updateInstrumentConfiguration() { try { setInstrument(getInstrumentDetail("instrument")); } catch (std::exception const &ex) { diff --git a/qt/scientific_interfaces/Indirect/Reduction/Transmission.h b/qt/scientific_interfaces/Indirect/Reduction/Transmission.h index bcfdb9a8aaeb..977e3fe152c3 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/Transmission.h +++ b/qt/scientific_interfaces/Indirect/Reduction/Transmission.h @@ -28,7 +28,6 @@ class MANTIDQT_INDIRECT_DLL Transmission : public DataReductionTab { private slots: void transAlgDone(bool error); - void setInstrument(); void runClicked(); void saveClicked(); @@ -40,6 +39,7 @@ private slots: private: void setInstrument(QString const &instrumentName); + void updateInstrumentConfiguration() override; Ui::Transmission m_uiForm; }; From 6fb4e7def5de06db61af566c009b82c963a696f4 Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 25 Apr 2024 16:33:04 +0100 Subject: [PATCH 15/58] Remove validate from slots section --- .../Indirect/Reduction/ISISEnergyTransferPresenter.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h index 9875a1790563..6844eb93fe6d 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h @@ -33,6 +33,7 @@ class MANTIDQT_INDIRECT_DLL IETPresenter : public DataReductionTab, public IIETP void setup() override; void run() override; + bool validate() override; void notifySaveClicked() override; void notifyRunClicked() override; @@ -40,9 +41,6 @@ class MANTIDQT_INDIRECT_DLL IETPresenter : public DataReductionTab, public IIETP void notifySaveCustomGroupingClicked(std::string const &customGrouping) override; void notifyRunFinished() override; -public slots: - bool validate() override; - private slots: void algorithmComplete(bool error); void plotRawComplete(bool error); From 7ba5945d1a59ab491745f9ff0898f64568de4d76 Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 25 Apr 2024 17:12:14 +0100 Subject: [PATCH 16/58] Move algorithm runner into DataReductionTab --- .../Indirect/Reduction/DataReduction.h | 10 +++++++++- .../Indirect/Reduction/DataReductionTab.cpp | 7 +++++++ .../Indirect/Reduction/DataReductionTab.h | 5 ++++- .../Indirect/Reduction/ISISEnergyTransferPresenter.cpp | 6 ++++-- .../Indirect/Reduction/ISISEnergyTransferPresenter.h | 3 ++- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h b/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h index 2c75fdd49e70..4df8cfa139a3 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h +++ b/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h @@ -12,7 +12,8 @@ #include "MantidAPI/MatrixWorkspace.h" #include "MantidGeometry/IComponent.h" -#include "MantidQtWidgets/Common/QtAlgorithmRunner.h" +#include "MantidQtWidgets/Common/AlgorithmRunner.h" +#include "MantidQtWidgets/Common/QtJobRunner.h" #include #include @@ -166,7 +167,14 @@ private slots: tabScrollArea->setWidget(tabContent); tabScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); +<<<<<<< HEAD:qt/scientific_interfaces/Indirect/Reduction/DataReduction.h DataReductionTab *tabIDRContent = new TabPresenter(this, new TabView(tabContent), std::make_unique()); +======= + auto jobRunner = std::make_unique(); + auto algorithmRunner = std::make_unique(std::move(jobRunner)); + IndirectDataReductionTab *tabIDRContent = + new TabPresenter(this, new TabView(tabContent), std::make_unique(), std::move(algorithmRunner)); +>>>>>>> 555213b9f43 (Move algorithm runner into DataReductionTab):qt/scientific_interfaces/Indirect/Reduction/IndirectDataReduction.h tabIDRContent->setupTab(); tabContent->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); diff --git a/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.cpp b/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.cpp index 40b2ecc9db83..c8295a415fbf 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.cpp @@ -31,6 +31,13 @@ DataReductionTab::DataReductionTab(IDataReduction *idrUI, QObject *parent) connect(this, SIGNAL(newInstrumentConfiguration()), this, SLOT(handleNewInstrumentConfiguration())); } +DataReductionTab::DataReductionTab(IDataReduction *idrUI, + std::unique_ptr algorithmRunner) + : InelasticTab(), m_idrUI(idrUI), m_tabRunning(false), m_algorithmRunner(std::move(algorithmRunner)) { + connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(tabExecutionComplete(bool))); + connect(this, SIGNAL(newInstrumentConfiguration()), this, SLOT(handleNewInstrumentConfiguration())); +} + DataReductionTab::~DataReductionTab() = default; void DataReductionTab::setOutputPlotOptionsPresenter(std::unique_ptr presenter) { diff --git a/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.h b/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.h index 5ad49aeb6c49..b831ea98e0cf 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.h +++ b/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.h @@ -7,6 +7,7 @@ #pragma once #include "../DllConfig.h" +#include "Common/AlgorithmRunner.h" #include "Common/InelasticTab.h" #include "Common/InstrumentConfig.h" #include "Common/OutputPlotOptionsPresenter.h" @@ -46,6 +47,7 @@ class MANTIDQT_INDIRECT_DLL DataReductionTab : public InelasticTab { public: DataReductionTab(IDataReduction *idrUI, QObject *parent = nullptr); + DataReductionTab(IDataReduction *idrUI, std::unique_ptr algorithmRunner); ~DataReductionTab() override; /// Set the presenter for the output plotting options @@ -84,7 +86,8 @@ public slots: QString reflection = ""); protected: - IDataReduction *m_idrUI; + IDataReduction * m_idrUI; + std::unique_ptr m_algorithmRunner; private slots: void tabExecutionComplete(bool error); diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp index 320b2a428bbc..97bc9f6037cb 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp @@ -16,6 +16,7 @@ #include "MantidAPI/WorkspaceGroup.h" #include "MantidKernel/ConfigService.h" +#include "MantidQtWidgets/Common/QtJobRunner.h" #include "MantidQtWidgets/Common/UserInputValidator.h" #include @@ -31,8 +32,9 @@ using namespace MantidQt::CustomInterfaces::InterfaceUtils; namespace MantidQt::CustomInterfaces { -IETPresenter::IETPresenter(IDataReduction *idrUI, IIETView *view, std::unique_ptr model) - : DataReductionTab(idrUI), m_view(view), m_model(std::move(model)) { +IETPresenter::IETPresenter(IDataReduction *idrUI, IIETView *view, std::unique_ptr model, + std::unique_ptr algorithmRunner) + : DataReductionTab(idrUI, std::move(algorithmRunner)), m_view(view), m_model(std::move(model)) { m_view->subscribePresenter(this); setOutputPlotOptionsPresenter( diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h index 6844eb93fe6d..509f6ece00da 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h @@ -29,7 +29,8 @@ class MANTIDQT_INDIRECT_DLL IETPresenter : public DataReductionTab, public IIETP Q_OBJECT public: - IETPresenter(IDataReduction *idrUI, IIETView *view, std::unique_ptr model); + IETPresenter(IDataReduction * idrUI, IIETView *view, std::unique_ptr model, + std::unique_ptr algorithmRunner); void setup() override; void run() override; From 17b0dbbc19dc8039a4fa7671eb34547f8fb9ecb5 Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 25 Apr 2024 17:32:31 +0100 Subject: [PATCH 17/58] Execute ISISEnergyTransfer algorithm using algorithm runner --- .../Reduction/ISISEnergyTransferModel.cpp | 20 ++++++------------- .../Reduction/ISISEnergyTransferModel.h | 12 +++++++---- .../Reduction/ISISEnergyTransferPresenter.cpp | 7 ++++--- .../Reduction/ISISEnergyTransferPresenter.h | 7 ++++--- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferModel.cpp b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferModel.cpp index 864b72139d84..23405b183b36 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferModel.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferModel.cpp @@ -17,7 +17,7 @@ using namespace Mantid::API; using namespace MantidQt::MantidWidgets::WorkspaceUtils; namespace MantidQt::CustomInterfaces { -IETModel::IETModel() : m_outputWorkspaces() {} +IETModel::IETModel() : m_outputGroupName(), m_outputWorkspaces() {} std::vector IETModel::validateRunData(IETRunData const &runData) { std::vector errors; @@ -119,8 +119,8 @@ std::string IETModel::getOutputGroupName(InstrumentData const &instData, std::st return instrument + inputText + "_" + analyser + "_" + reflection + "_Reduced"; } -std::string IETModel::runIETAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner, - InstrumentData const &instData, IETRunData &runData) { +std::unique_ptr IETModel::energyTransferProperties(InstrumentData const &instData, + IETRunData &runData) { auto properties = runData.groupingProperties(); setInstrumentProperties(*properties, instData); @@ -130,17 +130,9 @@ std::string IETModel::runIETAlgorithm(MantidQt::API::BatchAlgorithmRunner *batch setRebinProperties(*properties, runData.getRebinData()); setAnalysisProperties(*properties, runData.getAnalysisData()); - std::string outputGroupName = getOutputGroupName(instData, runData.getInputData().getInputText()); - setOutputProperties(*properties, runData.getOutputData(), outputGroupName); - - auto reductionAlg = AlgorithmManager::Instance().create("ISISIndirectEnergyTransfer"); - reductionAlg->initialize(); - API::IConfiguredAlgorithm_sptr configuredAlg = - std::make_shared(std::move(reductionAlg), std::move(properties)); - - batchAlgoRunner->executeAlgorithmAsync(std::move(configuredAlg)); - - return outputGroupName; + m_outputGroupName = getOutputGroupName(instData, runData.getInputData().getInputText()); + setOutputProperties(*properties, runData.getOutputData(), m_outputGroupName); + return properties; } std::vector IETModel::validatePlotData(IETPlotData const &plotParams) { diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferModel.h b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferModel.h index 54860df647b8..49586c3c164f 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferModel.h +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferModel.h @@ -27,8 +27,8 @@ class MANTIDQT_INDIRECT_DLL IIETModel { virtual std::vector validateRunData(IETRunData const &runData) = 0; virtual std::vector validatePlotData(IETPlotData const &plotData) = 0; - virtual std::string runIETAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner, - InstrumentData const &instData, IETRunData &runParams) = 0; + virtual std::unique_ptr energyTransferProperties(InstrumentData const &instData, + IETRunData &runParams) = 0; virtual std::deque plotRawAlgorithmQueue(InstrumentData const &instData, IETPlotData const &plotData) const = 0; @@ -41,6 +41,7 @@ class MANTIDQT_INDIRECT_DLL IIETModel { virtual std::vector groupWorkspaces(std::string const &groupName, std::string const &instrument, std::string const &groupOption, bool const shouldGroup) = 0; + virtual std::string outputGroupName() const = 0; virtual std::vector outputWorkspaceNames() const = 0; }; @@ -54,8 +55,8 @@ class MANTIDQT_INDIRECT_DLL IETModel : public IIETModel { std::vector validateRunData(IETRunData const &runData) override; std::vector validatePlotData(IETPlotData const &plotData) override; - std::string runIETAlgorithm(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner, InstrumentData const &instData, - IETRunData &runParams) override; + std::unique_ptr energyTransferProperties(InstrumentData const &instData, + IETRunData &runParams) override; std::deque plotRawAlgorithmQueue(InstrumentData const &instData, IETPlotData const &plotData) const override; @@ -79,6 +80,8 @@ class MANTIDQT_INDIRECT_DLL IETModel : public IIETModel { std::string const &outputGroupName); std::string getOutputGroupName(InstrumentData const &instData, std::string const &inputFiles); + [[nodiscard]] inline std::string outputGroupName() const noexcept override { return m_outputGroupName; } + [[nodiscard]] inline std::vector outputWorkspaceNames() const noexcept override { return m_outputWorkspaces; } @@ -97,6 +100,7 @@ class MANTIDQT_INDIRECT_DLL IETModel : public IIETModel { plotRawAlgorithmQueue(std::string const &rawFile, std::string const &basename, std::string const &instrumentName, std::vector const &detectorList, IETBackgroundData const &backgroundData) const; + std::string m_outputGroupName; std::vector m_outputWorkspaces; }; } // namespace CustomInterfaces diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp index 97bc9f6037cb..8affe8a650c2 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp @@ -36,6 +36,7 @@ IETPresenter::IETPresenter(IDataReduction *idrUI, IIETView *view, std::unique_pt std::unique_ptr algorithmRunner) : DataReductionTab(idrUI, std::move(algorithmRunner)), m_view(view), m_model(std::move(model)) { m_view->subscribePresenter(this); + m_algorithmRunner->subscribe(this); setOutputPlotOptionsPresenter( std::make_unique(m_view->getPlotOptionsView(), PlotWidget::SpectraSliceSurface)); @@ -181,7 +182,7 @@ void IETPresenter::run() { m_view->setRunButtonText("Running..."); m_view->setEnableOutputOptions(false); - m_outputGroupName = m_model->runIETAlgorithm(m_batchAlgoRunner, instrumentData, runData); + m_algorithmRunner->execute("ISISIndirectEnergyTransfer", m_model->energyTransferProperties(instrumentData, runData)); } void IETPresenter::algorithmComplete(bool error) { @@ -192,8 +193,8 @@ void IETPresenter::algorithmComplete(bool error) { if (!error) { InstrumentData instrumentData = getInstrumentData(); auto const outputWorkspaceNames = - m_model->groupWorkspaces(m_outputGroupName, instrumentData.getInstrument(), m_view->getGroupOutputOption(), - m_view->getGroupOutputCheckbox()); + m_model->groupWorkspaces(m_model->outputGroupName(), instrumentData.getInstrument(), + m_view->getGroupOutputOption(), m_view->getGroupOutputCheckbox()); m_pythonExportWsName = outputWorkspaceNames[0]; setOutputPlotOptionsWorkspaces(outputWorkspaceNames); diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h index 509f6ece00da..ae5211055df4 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h @@ -6,6 +6,7 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once +#include "Common/IAlgorithmRunnerSubscriber.h" #include "DllConfig.h" #include "ISISEnergyTransferData.h" #include "ISISEnergyTransferModel.h" @@ -25,7 +26,9 @@ class MANTIDQT_INDIRECT_DLL IIETPresenter { virtual void notifyRunFinished() = 0; }; -class MANTIDQT_INDIRECT_DLL IETPresenter : public DataReductionTab, public IIETPresenter { +class MANTIDQT_INDIRECT_DLL IETPresenter : public DataReductionTab, + public IIETPresenter, + public IAlgorithmRunnerSubscriber { Q_OBJECT public: @@ -54,8 +57,6 @@ private slots: void setFileExtensionsByName(bool filter) override; - std::string m_outputGroupName; - IIETView *m_view; std::unique_ptr m_model; }; From 582f8d0562f35d7557719a6b7c04df2be0fdef4d Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 25 Apr 2024 17:55:23 +0100 Subject: [PATCH 18/58] Handle algorithm complete and error for ISISIET algorithm --- .../Reduction/ISISEnergyTransferPresenter.cpp | 21 +++++++++++-------- .../Reduction/ISISEnergyTransferPresenter.h | 4 +++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp index 8affe8a650c2..9ac1d1f47c87 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp @@ -25,8 +25,6 @@ #include using namespace Mantid::API; -using MantidQt::API::BatchAlgorithmRunner; - using namespace MantidQt::MantidWidgets::WorkspaceUtils; using namespace MantidQt::CustomInterfaces::InterfaceUtils; @@ -176,7 +174,6 @@ void IETPresenter::run() { InstrumentData instrumentData = getInstrumentData(); IETRunData runData = m_view->getRunData(); - connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(algorithmComplete(bool))); disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(plotRawComplete(bool))); m_view->setRunButtonText("Running..."); @@ -185,12 +182,11 @@ void IETPresenter::run() { m_algorithmRunner->execute("ISISIndirectEnergyTransfer", m_model->energyTransferProperties(instrumentData, runData)); } -void IETPresenter::algorithmComplete(bool error) { - disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(algorithmComplete(bool))); - m_view->setRunButtonText("Run"); - m_view->setEnableOutputOptions(!error); +void IETPresenter::notifyAlgorithmComplete(API::IConfiguredAlgorithm_sptr &algorithm) { + if (algorithm->algorithm()->name() == "ISISIndirectEnergyTransfer") { + m_view->setRunButtonText("Run"); + m_view->setEnableOutputOptions(true); - if (!error) { InstrumentData instrumentData = getInstrumentData(); auto const outputWorkspaceNames = m_model->groupWorkspaces(m_model->outputGroupName(), instrumentData.getInstrument(), @@ -202,6 +198,14 @@ void IETPresenter::algorithmComplete(bool error) { } } +void IETPresenter::notifyAlgorithmError(API::IConfiguredAlgorithm_sptr &algorithm, std::string const &message) { + (void)algorithm; + (void)message; + m_view->setRunButtonText("Run"); + m_view->setEnableOutputOptions(false); + m_view->setPlotTimeIsPlotting(false); +} + void IETPresenter::notifyPlotRawClicked() { InstrumentData instrumentData = getInstrumentData(); IETPlotData plotParams = m_view->getPlotData(); @@ -210,7 +214,6 @@ void IETPresenter::notifyPlotRawClicked() { if (errors.empty()) { m_view->setPlotTimeIsPlotting(true); - disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(algorithmComplete(bool))); connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(plotRawComplete(bool))); m_batchAlgoRunner->setQueue(m_model->plotRawAlgorithmQueue(instrumentData, plotParams)); diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h index ae5211055df4..e808d32b3ce3 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h @@ -45,8 +45,10 @@ class MANTIDQT_INDIRECT_DLL IETPresenter : public DataReductionTab, void notifySaveCustomGroupingClicked(std::string const &customGrouping) override; void notifyRunFinished() override; + void notifyAlgorithmComplete(API::IConfiguredAlgorithm_sptr &algorithm) override; + void notifyAlgorithmError(API::IConfiguredAlgorithm_sptr &algorithm, std::string const &message) override; + private slots: - void algorithmComplete(bool error); void plotRawComplete(bool error); private: From 8ba329f492e400b41e8afa36f845b6faf94de56f Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 25 Apr 2024 20:29:49 +0100 Subject: [PATCH 19/58] Make possible to execute queue of algorithms --- .../Reduction/ISISEnergyTransferPresenter.cpp | 27 ++++++------------- .../Reduction/ISISEnergyTransferPresenter.h | 3 --- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp index 9ac1d1f47c87..16e8aefe02d1 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp @@ -174,8 +174,6 @@ void IETPresenter::run() { InstrumentData instrumentData = getInstrumentData(); IETRunData runData = m_view->getRunData(); - disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(plotRawComplete(bool))); - m_view->setRunButtonText("Running..."); m_view->setEnableOutputOptions(false); @@ -195,6 +193,12 @@ void IETPresenter::notifyAlgorithmComplete(API::IConfiguredAlgorithm_sptr &algor setOutputPlotOptionsWorkspaces(outputWorkspaceNames); m_view->setSaveEnabled(!outputWorkspaceNames.empty()); + } else if (algorithm->algorithm()->name() == "GroupDetectors") { + m_view->setPlotTimeIsPlotting(false); + auto const filename = m_view->getFirstFilename(); + std::filesystem::path fileInfo(filename); + auto const name = fileInfo.filename().string(); + m_plotter->plotSpectra(name + "_grp", "0", SettingsHelper::externalPlotErrorBars()); } } @@ -214,10 +218,8 @@ void IETPresenter::notifyPlotRawClicked() { if (errors.empty()) { m_view->setPlotTimeIsPlotting(true); - connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(plotRawComplete(bool))); - - m_batchAlgoRunner->setQueue(m_model->plotRawAlgorithmQueue(instrumentData, plotParams)); - m_batchAlgoRunner->executeBatchAsync(); + m_algorithmRunner->setAlgorithmQueue(m_model->plotRawAlgorithmQueue(instrumentData, plotParams)); + m_algorithmRunner->executeQueue(); } else { m_view->setPlotTimeIsPlotting(false); for (auto const &error : errors) { @@ -227,19 +229,6 @@ void IETPresenter::notifyPlotRawClicked() { } } -void IETPresenter::plotRawComplete(bool error) { - disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(plotRawComplete(bool))); - - if (!error) { - auto const filename = m_view->getFirstFilename(); - std::filesystem::path fileInfo(filename); - auto const name = fileInfo.filename().string(); - m_plotter->plotSpectra(name + "_grp", "0", SettingsHelper::externalPlotErrorBars()); - } - - m_view->setPlotTimeIsPlotting(false); -} - void IETPresenter::notifySaveClicked() { IETSaveData saveData = m_view->getSaveData(); for (auto const &workspaceName : m_model->outputWorkspaceNames()) diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h index e808d32b3ce3..a532be901c33 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h @@ -48,9 +48,6 @@ class MANTIDQT_INDIRECT_DLL IETPresenter : public DataReductionTab, void notifyAlgorithmComplete(API::IConfiguredAlgorithm_sptr &algorithm) override; void notifyAlgorithmError(API::IConfiguredAlgorithm_sptr &algorithm, std::string const &message) override; -private slots: - void plotRawComplete(bool error); - private: bool validateInstrumentDetails(); void updateInstrumentConfiguration() override; From 661303c95860cbb82501a385202a6a740464b988 Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 25 Apr 2024 20:35:40 +0100 Subject: [PATCH 20/58] IETPresenter is no longer a QObject --- .../Indirect/Reduction/CMakeLists.txt | 7 +++---- .../Indirect/Reduction/ISISEnergyTransferModel.cpp | 9 ++++++--- .../Indirect/Reduction/ISISEnergyTransferModel.h | 8 ++++---- .../Indirect/Reduction/ISISEnergyTransferPresenter.cpp | 6 ++---- .../Indirect/Reduction/ISISEnergyTransferPresenter.h | 1 - 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Reduction/CMakeLists.txt b/qt/scientific_interfaces/Indirect/Reduction/CMakeLists.txt index d2a82a980b4f..ffdee641c54e 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/CMakeLists.txt +++ b/qt/scientific_interfaces/Indirect/Reduction/CMakeLists.txt @@ -6,16 +6,16 @@ set(SRC_FILES ILLEnergyTransfer.cpp ISISCalibration.cpp ISISDiagnostics.cpp - ISISEnergyTransferValidator.cpp ISISEnergyTransferModel.cpp - ISISEnergyTransferView.cpp ISISEnergyTransferPresenter.cpp + ISISEnergyTransferValidator.cpp + ISISEnergyTransferView.cpp ReductionAlgorithmUtils.cpp Transmission.cpp ) set(INC_FILES ISISEnergyTransferData.h ISISEnergyTransferValidator.h ISISEnergyTransferModelUtils.h - ISISEnergyTransferModel.h ReductionAlgorithmUtils.h + ISISEnergyTransferModel.h ISISEnergyTransferPresenter.h ReductionAlgorithmUtils.h ) set(MOC_FILES @@ -25,7 +25,6 @@ set(MOC_FILES ISISCalibration.h ISISDiagnostics.h ISISEnergyTransferView.h - ISISEnergyTransferPresenter.h Transmission.h ) diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferModel.cpp b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferModel.cpp index 23405b183b36..0c709b4d27fd 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferModel.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferModel.cpp @@ -119,8 +119,8 @@ std::string IETModel::getOutputGroupName(InstrumentData const &instData, std::st return instrument + inputText + "_" + analyser + "_" + reflection + "_Reduced"; } -std::unique_ptr IETModel::energyTransferProperties(InstrumentData const &instData, - IETRunData &runData) { +MantidQt::API::IConfiguredAlgorithm_sptr IETModel::energyTransferAlgorithm(InstrumentData const &instData, + IETRunData &runData) { auto properties = runData.groupingProperties(); setInstrumentProperties(*properties, instData); @@ -132,7 +132,10 @@ std::unique_ptr IETModel::energyTransferProperties(Instru m_outputGroupName = getOutputGroupName(instData, runData.getInputData().getInputText()); setOutputProperties(*properties, runData.getOutputData(), m_outputGroupName); - return properties; + + auto reductionAlg = AlgorithmManager::Instance().create("ISISIndirectEnergyTransfer"); + reductionAlg->initialize(); + return std::make_shared(std::move(reductionAlg), std::move(properties)); } std::vector IETModel::validatePlotData(IETPlotData const &plotParams) { diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferModel.h b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferModel.h index 49586c3c164f..b90f2a88908a 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferModel.h +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferModel.h @@ -27,8 +27,8 @@ class MANTIDQT_INDIRECT_DLL IIETModel { virtual std::vector validateRunData(IETRunData const &runData) = 0; virtual std::vector validatePlotData(IETPlotData const &plotData) = 0; - virtual std::unique_ptr energyTransferProperties(InstrumentData const &instData, - IETRunData &runParams) = 0; + virtual MantidQt::API::IConfiguredAlgorithm_sptr energyTransferAlgorithm(InstrumentData const &instData, + IETRunData &runParams) = 0; virtual std::deque plotRawAlgorithmQueue(InstrumentData const &instData, IETPlotData const &plotData) const = 0; @@ -55,8 +55,8 @@ class MANTIDQT_INDIRECT_DLL IETModel : public IIETModel { std::vector validateRunData(IETRunData const &runData) override; std::vector validatePlotData(IETPlotData const &plotData) override; - std::unique_ptr energyTransferProperties(InstrumentData const &instData, - IETRunData &runParams) override; + MantidQt::API::IConfiguredAlgorithm_sptr energyTransferAlgorithm(InstrumentData const &instData, + IETRunData &runParams) override; std::deque plotRawAlgorithmQueue(InstrumentData const &instData, IETPlotData const &plotData) const override; diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp index 16e8aefe02d1..aeda05154825 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp @@ -177,7 +177,7 @@ void IETPresenter::run() { m_view->setRunButtonText("Running..."); m_view->setEnableOutputOptions(false); - m_algorithmRunner->execute("ISISIndirectEnergyTransfer", m_model->energyTransferProperties(instrumentData, runData)); + m_algorithmRunner->execute(m_model->energyTransferAlgorithm(instrumentData, runData)); } void IETPresenter::notifyAlgorithmComplete(API::IConfiguredAlgorithm_sptr &algorithm) { @@ -217,9 +217,7 @@ void IETPresenter::notifyPlotRawClicked() { if (errors.empty()) { m_view->setPlotTimeIsPlotting(true); - - m_algorithmRunner->setAlgorithmQueue(m_model->plotRawAlgorithmQueue(instrumentData, plotParams)); - m_algorithmRunner->executeQueue(); + m_algorithmRunner->execute(m_model->plotRawAlgorithmQueue(instrumentData, plotParams)); } else { m_view->setPlotTimeIsPlotting(false); for (auto const &error : errors) { diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h index a532be901c33..f11af271e7f9 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h @@ -29,7 +29,6 @@ class MANTIDQT_INDIRECT_DLL IIETPresenter { class MANTIDQT_INDIRECT_DLL IETPresenter : public DataReductionTab, public IIETPresenter, public IAlgorithmRunnerSubscriber { - Q_OBJECT public: IETPresenter(IDataReduction * idrUI, IIETView *view, std::unique_ptr model, From c7047eb1f9e1c7b873032693aef79262bdb4aa6a Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 26 Apr 2024 10:09:54 +0100 Subject: [PATCH 21/58] Store last executed algorithm in AlgorithmRunner --- .../Reduction/ISISEnergyTransferPresenter.cpp | 20 +++++++++---------- .../Reduction/ISISEnergyTransferPresenter.h | 3 +-- .../inc/MantidQtWidgets/Common/IJobRunner.h | 1 + .../inc/MantidQtWidgets/Common/QtJobRunner.h | 1 + qt/widgets/common/src/QtJobRunner.cpp | 2 ++ 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp index aeda05154825..231fafae8578 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp @@ -180,8 +180,14 @@ void IETPresenter::run() { m_algorithmRunner->execute(m_model->energyTransferAlgorithm(instrumentData, runData)); } -void IETPresenter::notifyAlgorithmComplete(API::IConfiguredAlgorithm_sptr &algorithm) { - if (algorithm->algorithm()->name() == "ISISIndirectEnergyTransfer") { +void IETPresenter::notifyBatchComplete(API::IConfiguredAlgorithm_sptr &lastAlgorithm, bool error) { + if (error) { + m_view->setRunButtonText("Run"); + m_view->setEnableOutputOptions(false); + m_view->setPlotTimeIsPlotting(false); + return; + } + if (lastAlgorithm->algorithm()->name() == "ISISIndirectEnergyTransfer") { m_view->setRunButtonText("Run"); m_view->setEnableOutputOptions(true); @@ -193,7 +199,7 @@ void IETPresenter::notifyAlgorithmComplete(API::IConfiguredAlgorithm_sptr &algor setOutputPlotOptionsWorkspaces(outputWorkspaceNames); m_view->setSaveEnabled(!outputWorkspaceNames.empty()); - } else if (algorithm->algorithm()->name() == "GroupDetectors") { + } else if (lastAlgorithm->algorithm()->name() == "GroupDetectors") { m_view->setPlotTimeIsPlotting(false); auto const filename = m_view->getFirstFilename(); std::filesystem::path fileInfo(filename); @@ -202,14 +208,6 @@ void IETPresenter::notifyAlgorithmComplete(API::IConfiguredAlgorithm_sptr &algor } } -void IETPresenter::notifyAlgorithmError(API::IConfiguredAlgorithm_sptr &algorithm, std::string const &message) { - (void)algorithm; - (void)message; - m_view->setRunButtonText("Run"); - m_view->setEnableOutputOptions(false); - m_view->setPlotTimeIsPlotting(false); -} - void IETPresenter::notifyPlotRawClicked() { InstrumentData instrumentData = getInstrumentData(); IETPlotData plotParams = m_view->getPlotData(); diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h index f11af271e7f9..7da1fe46c9f2 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h @@ -44,8 +44,7 @@ class MANTIDQT_INDIRECT_DLL IETPresenter : public DataReductionTab, void notifySaveCustomGroupingClicked(std::string const &customGrouping) override; void notifyRunFinished() override; - void notifyAlgorithmComplete(API::IConfiguredAlgorithm_sptr &algorithm) override; - void notifyAlgorithmError(API::IConfiguredAlgorithm_sptr &algorithm, std::string const &message) override; + void notifyBatchComplete(API::IConfiguredAlgorithm_sptr &lastAlgorithm, bool error) override; private: bool validateInstrumentDetails(); diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/IJobRunner.h b/qt/widgets/common/inc/MantidQtWidgets/Common/IJobRunner.h index a9d94ab67761..d4221c1540b5 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/IJobRunner.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/IJobRunner.h @@ -45,5 +45,6 @@ class EXPORT_OPT_MANTIDQT_COMMON IJobRunner { virtual void executeAlgorithmQueue() = 0; virtual void executeAlgorithm(MantidQt::API::IConfiguredAlgorithm_sptr algorithm) = 0; virtual void cancelAlgorithmQueue() = 0; + virtual std::size_t queueLength() = 0; }; } // namespace MantidQt::API diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/QtJobRunner.h b/qt/widgets/common/inc/MantidQtWidgets/Common/QtJobRunner.h index 2b92ef10503f..0708232369b9 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/QtJobRunner.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/QtJobRunner.h @@ -29,6 +29,7 @@ class EXPORT_OPT_MANTIDQT_COMMON QtJobRunner : public QObject, public IJobRunner void executeAlgorithmQueue() override; void executeAlgorithm(MantidQt::API::IConfiguredAlgorithm_sptr algorithm) override; void cancelAlgorithmQueue() override; + std::size_t queueLength() override; private slots: void onBatchComplete(bool error); diff --git a/qt/widgets/common/src/QtJobRunner.cpp b/qt/widgets/common/src/QtJobRunner.cpp index e512b4e010c9..80ffbb27ea5f 100644 --- a/qt/widgets/common/src/QtJobRunner.cpp +++ b/qt/widgets/common/src/QtJobRunner.cpp @@ -35,6 +35,8 @@ void QtJobRunner::executeAlgorithm(IConfiguredAlgorithm_sptr algorithm) { m_batchAlgoRunner.executeAlgorithmAsync(std::move(algorithm)); } +std::size_t QtJobRunner::queueLength() { return m_batchAlgoRunner.queueLength(); } + void QtJobRunner::cancelAlgorithmQueue() { m_batchAlgoRunner.cancelBatch(); } void QtJobRunner::connectBatchAlgoRunnerSlots() { From 4664706503d2ab8ec1b81d126f861d38ddb4cc0f Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 26 Apr 2024 10:44:24 +0100 Subject: [PATCH 22/58] Tidy up changes in IET Presenter --- .../Reduction/ISISEnergyTransferPresenter.cpp | 68 ++++++++++++++----- .../Reduction/ISISEnergyTransferPresenter.h | 3 + 2 files changed, 53 insertions(+), 18 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp index 231fafae8578..0f92d702dd28 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp @@ -28,6 +28,25 @@ using namespace Mantid::API; using namespace MantidQt::MantidWidgets::WorkspaceUtils; using namespace MantidQt::CustomInterfaces::InterfaceUtils; +namespace { +constexpr auto REDUCTION_ALG_NAME = "ISISIndirectEnergyTransfer"; +constexpr auto PLOT_PREPROCESS_ALG_NAME = "GroupDetectors"; + +enum class AlgorithmType { REDUCTION, PLOT_RAW_PREPROCESS }; + +AlgorithmType algorithmType(MantidQt::API::IConfiguredAlgorithm_sptr &configuredAlg) { + auto const &name = configuredAlg->algorithm()->name(); + if (name == REDUCTION_ALG_NAME) { + return AlgorithmType::REDUCTION; + } else if (name == PLOT_PREPROCESS_ALG_NAME) { + return AlgorithmType::PLOT_RAW_PREPROCESS; + } else { + throw std::logic_error("ISIS Energy Transfer tab error: callback from invalid algorithm " + name); + } +} + +} // namespace + namespace MantidQt::CustomInterfaces { IETPresenter::IETPresenter(IDataReduction *idrUI, IIETView *view, std::unique_ptr model, @@ -181,31 +200,44 @@ void IETPresenter::run() { } void IETPresenter::notifyBatchComplete(API::IConfiguredAlgorithm_sptr &lastAlgorithm, bool error) { - if (error) { + if (!lastAlgorithm || error) { m_view->setRunButtonText("Run"); m_view->setEnableOutputOptions(false); m_view->setPlotTimeIsPlotting(false); return; } - if (lastAlgorithm->algorithm()->name() == "ISISIndirectEnergyTransfer") { - m_view->setRunButtonText("Run"); - m_view->setEnableOutputOptions(true); + switch (algorithmType(lastAlgorithm)) { + case AlgorithmType::REDUCTION: + handleReductionComplete(); + return; + case AlgorithmType::PLOT_RAW_PREPROCESS: + handlePlotRawPreProcessComplete(); + return; + default: + throw std::logic_error("Unexpected ISIS Energy Transfer tab error: callback from invalid algorithm batch."); + } +} - InstrumentData instrumentData = getInstrumentData(); - auto const outputWorkspaceNames = - m_model->groupWorkspaces(m_model->outputGroupName(), instrumentData.getInstrument(), - m_view->getGroupOutputOption(), m_view->getGroupOutputCheckbox()); - m_pythonExportWsName = outputWorkspaceNames[0]; +void IETPresenter::handleReductionComplete() { + m_view->setRunButtonText("Run"); + m_view->setEnableOutputOptions(true); - setOutputPlotOptionsWorkspaces(outputWorkspaceNames); - m_view->setSaveEnabled(!outputWorkspaceNames.empty()); - } else if (lastAlgorithm->algorithm()->name() == "GroupDetectors") { - m_view->setPlotTimeIsPlotting(false); - auto const filename = m_view->getFirstFilename(); - std::filesystem::path fileInfo(filename); - auto const name = fileInfo.filename().string(); - m_plotter->plotSpectra(name + "_grp", "0", SettingsHelper::externalPlotErrorBars()); - } + InstrumentData instrumentData = getInstrumentData(); + auto const outputWorkspaceNames = + m_model->groupWorkspaces(m_model->outputGroupName(), instrumentData.getInstrument(), + m_view->getGroupOutputOption(), m_view->getGroupOutputCheckbox()); + m_pythonExportWsName = outputWorkspaceNames[0]; + + setOutputPlotOptionsWorkspaces(outputWorkspaceNames); + m_view->setSaveEnabled(!outputWorkspaceNames.empty()); +} + +void IETPresenter::handlePlotRawPreProcessComplete() { + m_view->setPlotTimeIsPlotting(false); + auto const filename = m_view->getFirstFilename(); + std::filesystem::path fileInfo(filename); + auto const name = fileInfo.filename().string(); + m_plotter->plotSpectra(name + "_grp", "0", SettingsHelper::externalPlotErrorBars()); } void IETPresenter::notifyPlotRawClicked() { diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h index 7da1fe46c9f2..70334ab2d5c5 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h @@ -50,6 +50,9 @@ class MANTIDQT_INDIRECT_DLL IETPresenter : public DataReductionTab, bool validateInstrumentDetails(); void updateInstrumentConfiguration() override; + void handleReductionComplete(); + void handlePlotRawPreProcessComplete(); + InstrumentData getInstrumentData(); void setFileExtensionsByName(bool filter) override; From a1f923b49985ce162489ee773de01aa8b8c38c9d Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 26 Apr 2024 10:59:49 +0100 Subject: [PATCH 23/58] Rename AlgorithmRunner to QtAlgorithmRunner because it uses Qt signals --- qt/scientific_interfaces/Indirect/Common/InstrumentConfig.h | 1 + qt/scientific_interfaces/Indirect/Reduction/DataReduction.h | 2 +- qt/scientific_interfaces/Inelastic/Common/InelasticTab.h | 1 + qt/widgets/common/CMakeLists.txt | 2 ++ 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/qt/scientific_interfaces/Indirect/Common/InstrumentConfig.h b/qt/scientific_interfaces/Indirect/Common/InstrumentConfig.h index dff295daaf8a..37d8d9667006 100644 --- a/qt/scientific_interfaces/Indirect/Common/InstrumentConfig.h +++ b/qt/scientific_interfaces/Indirect/Common/InstrumentConfig.h @@ -12,6 +12,7 @@ #include "MantidAPI/MatrixWorkspace_fwd.h" #include "MantidQtWidgets/Common/InstrumentSelector.h" #include "MantidQtWidgets/Common/MantidWidget.h" +#include "MantidQtWidgets/Common/QtAlgorithmRunner.h" #include diff --git a/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h b/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h index 4df8cfa139a3..409c5ad2158d 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h +++ b/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h @@ -12,7 +12,7 @@ #include "MantidAPI/MatrixWorkspace.h" #include "MantidGeometry/IComponent.h" -#include "MantidQtWidgets/Common/AlgorithmRunner.h" +#include "MantidQtWidgets/Common/QtAlgorithmRunner.h" #include "MantidQtWidgets/Common/QtJobRunner.h" #include diff --git a/qt/scientific_interfaces/Inelastic/Common/InelasticTab.h b/qt/scientific_interfaces/Inelastic/Common/InelasticTab.h index 60afbbf93e2d..627bdcaae3e6 100644 --- a/qt/scientific_interfaces/Inelastic/Common/InelasticTab.h +++ b/qt/scientific_interfaces/Inelastic/Common/InelasticTab.h @@ -12,6 +12,7 @@ #include "MantidAPI/ITableWorkspace.h" #include "MantidKernel/DateAndTime.h" #include "MantidQtWidgets/Common/BatchAlgorithmRunner.h" +#include "MantidQtWidgets/Common/QtAlgorithmRunner.h" #include "MantidQtWidgets/Common/QtPropertyBrowser/QtIntPropertyManager" #include "MantidQtWidgets/Common/QtPropertyBrowser/QtTreePropertyBrowser" #include "MantidQtWidgets/Common/QtPropertyBrowser/qteditorfactory.h" diff --git a/qt/widgets/common/CMakeLists.txt b/qt/widgets/common/CMakeLists.txt index 873ee84f1519..2e82cd60959b 100644 --- a/qt/widgets/common/CMakeLists.txt +++ b/qt/widgets/common/CMakeLists.txt @@ -390,6 +390,7 @@ set(MOC_FILES inc/MantidQtWidgets/Common/OptionsPropertyWidget.h inc/MantidQtWidgets/Common/PropertyWidget.h inc/MantidQtWidgets/Common/PythonRunner.h + inc/MantidQtWidgets/Common/QtAlgorithmRunner.h inc/MantidQtWidgets/Common/QScienceSpinBox.h inc/MantidQtWidgets/Common/QtSignalChannel.h inc/MantidQtWidgets/Common/RepoTreeView.h @@ -521,6 +522,7 @@ set(INC_FILES inc/MantidQtWidgets/Common/QtAlgorithmRunner.h inc/MantidQtWidgets/Common/QSettingsHelper.h inc/MantidQtWidgets/Common/QStringUtils.h + inc/MantidQtWidgets/Common/QtAlgorithmRunner.h inc/MantidQtWidgets/Common/QtJSONUtils.h inc/MantidQtWidgets/Common/ScriptRepositoryView.h inc/MantidQtWidgets/Common/SelectionNotificationService.h From 29070bee4b17ae830e84a15ee108d992ba9aea3a Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 26 Apr 2024 11:41:08 +0100 Subject: [PATCH 24/58] Move AlgorithmRunner to MantidQtWidgets common --- .../Indirect/Reduction/DataReduction.h | 9 +++------ .../Indirect/Reduction/DataReductionTab.cpp | 2 +- .../Indirect/Reduction/DataReductionTab.h | 9 +++++---- .../Indirect/Reduction/ISISEnergyTransferPresenter.cpp | 2 +- .../Indirect/Reduction/ISISEnergyTransferPresenter.h | 10 +++++----- qt/widgets/common/CMakeLists.txt | 1 + 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h b/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h index 409c5ad2158d..ac96c525d057 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h +++ b/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h @@ -12,6 +12,7 @@ #include "MantidAPI/MatrixWorkspace.h" #include "MantidGeometry/IComponent.h" +#include "MantidQtWidgets/Common/AlgorithmRunner.h" #include "MantidQtWidgets/Common/QtAlgorithmRunner.h" #include "MantidQtWidgets/Common/QtJobRunner.h" @@ -167,14 +168,10 @@ private slots: tabScrollArea->setWidget(tabContent); tabScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); -<<<<<<< HEAD:qt/scientific_interfaces/Indirect/Reduction/DataReduction.h - DataReductionTab *tabIDRContent = new TabPresenter(this, new TabView(tabContent), std::make_unique()); -======= auto jobRunner = std::make_unique(); - auto algorithmRunner = std::make_unique(std::move(jobRunner)); - IndirectDataReductionTab *tabIDRContent = + auto algorithmRunner = std::make_unique(std::move(jobRunner)); + DataReductionTab *tabIDRContent = new TabPresenter(this, new TabView(tabContent), std::make_unique(), std::move(algorithmRunner)); ->>>>>>> 555213b9f43 (Move algorithm runner into DataReductionTab):qt/scientific_interfaces/Indirect/Reduction/IndirectDataReduction.h tabIDRContent->setupTab(); tabContent->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); diff --git a/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.cpp b/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.cpp index c8295a415fbf..608b7a3f7505 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.cpp @@ -32,7 +32,7 @@ DataReductionTab::DataReductionTab(IDataReduction *idrUI, QObject *parent) } DataReductionTab::DataReductionTab(IDataReduction *idrUI, - std::unique_ptr algorithmRunner) + std::unique_ptr algorithmRunner) : InelasticTab(), m_idrUI(idrUI), m_tabRunning(false), m_algorithmRunner(std::move(algorithmRunner)) { connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(tabExecutionComplete(bool))); connect(this, SIGNAL(newInstrumentConfiguration()), this, SLOT(handleNewInstrumentConfiguration())); diff --git a/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.h b/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.h index b831ea98e0cf..72cc28a7f3c1 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.h +++ b/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.h @@ -7,11 +7,12 @@ #pragma once #include "../DllConfig.h" -#include "Common/AlgorithmRunner.h" #include "Common/InelasticTab.h" #include "Common/InstrumentConfig.h" #include "Common/OutputPlotOptionsPresenter.h" +#include "MantidQtWidgets/Common/AlgorithmRunner.h" + // Suppress a warning coming out of code that isn't ours #if defined(__INTEL_COMPILER) #pragma warning disable 1125 @@ -47,7 +48,7 @@ class MANTIDQT_INDIRECT_DLL DataReductionTab : public InelasticTab { public: DataReductionTab(IDataReduction *idrUI, QObject *parent = nullptr); - DataReductionTab(IDataReduction *idrUI, std::unique_ptr algorithmRunner); + DataReductionTab(IDataReduction *idrUI, std::unique_ptr algorithmRunner); ~DataReductionTab() override; /// Set the presenter for the output plotting options @@ -86,8 +87,8 @@ public slots: QString reflection = ""); protected: - IDataReduction * m_idrUI; - std::unique_ptr m_algorithmRunner; + IDataReduction *m_idrUI; + std::unique_ptr m_algorithmRunner; private slots: void tabExecutionComplete(bool error); diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp index 0f92d702dd28..219005a1a85e 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.cpp @@ -50,7 +50,7 @@ AlgorithmType algorithmType(MantidQt::API::IConfiguredAlgorithm_sptr &configured namespace MantidQt::CustomInterfaces { IETPresenter::IETPresenter(IDataReduction *idrUI, IIETView *view, std::unique_ptr model, - std::unique_ptr algorithmRunner) + std::unique_ptr algorithmRunner) : DataReductionTab(idrUI, std::move(algorithmRunner)), m_view(view), m_model(std::move(model)) { m_view->subscribePresenter(this); m_algorithmRunner->subscribe(this); diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h index 70334ab2d5c5..95d73d05fe53 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h @@ -6,14 +6,14 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once -#include "Common/IAlgorithmRunnerSubscriber.h" #include "DllConfig.h" #include "ISISEnergyTransferData.h" #include "ISISEnergyTransferModel.h" #include "ISISEnergyTransferView.h" - #include "DataReductionTab.h" +#include "MantidQtWidgets/Common/IAlgorithmRunnerSubscriber.h" + namespace MantidQt { namespace CustomInterfaces { @@ -28,11 +28,11 @@ class MANTIDQT_INDIRECT_DLL IIETPresenter { class MANTIDQT_INDIRECT_DLL IETPresenter : public DataReductionTab, public IIETPresenter, - public IAlgorithmRunnerSubscriber { + public API::IAlgorithmRunnerSubscriber { public: - IETPresenter(IDataReduction * idrUI, IIETView *view, std::unique_ptr model, - std::unique_ptr algorithmRunner); + IETPresenter(IDataReduction *idrUI, IIETView *view, std::unique_ptr model, + std::unique_ptr algorithmRunner); void setup() override; void run() override; diff --git a/qt/widgets/common/CMakeLists.txt b/qt/widgets/common/CMakeLists.txt index 2e82cd60959b..619c82be64cf 100644 --- a/qt/widgets/common/CMakeLists.txt +++ b/qt/widgets/common/CMakeLists.txt @@ -5,6 +5,7 @@ set(SRC_FILES src/AlgorithmHistoryWindow.cpp src/AlgorithmInputHistory.cpp src/AlgorithmPropertiesWidget.cpp + src/AlgorithmRunner.cpp src/AlgorithmSelectorWidget.cpp src/AlgorithmRunner.cpp src/AlternateCSPythonLexer.cpp From 4964ff0f4f5ea12056214ce3dd05258f15d70a55 Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 26 Apr 2024 12:15:17 +0100 Subject: [PATCH 25/58] Remove unused includes and functions --- .../Indirect/Common/InstrumentConfig.h | 1 - .../Indirect/Reduction/DataReduction.cpp | 8 -------- .../Indirect/Reduction/DataReduction.h | 3 --- qt/scientific_interfaces/Inelastic/Common/InelasticTab.h | 1 - qt/widgets/common/inc/MantidQtWidgets/Common/IJobRunner.h | 1 - .../common/inc/MantidQtWidgets/Common/QtJobRunner.h | 1 - qt/widgets/common/src/QtJobRunner.cpp | 2 -- 7 files changed, 17 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Common/InstrumentConfig.h b/qt/scientific_interfaces/Indirect/Common/InstrumentConfig.h index 37d8d9667006..dff295daaf8a 100644 --- a/qt/scientific_interfaces/Indirect/Common/InstrumentConfig.h +++ b/qt/scientific_interfaces/Indirect/Common/InstrumentConfig.h @@ -12,7 +12,6 @@ #include "MantidAPI/MatrixWorkspace_fwd.h" #include "MantidQtWidgets/Common/InstrumentSelector.h" #include "MantidQtWidgets/Common/MantidWidget.h" -#include "MantidQtWidgets/Common/QtAlgorithmRunner.h" #include diff --git a/qt/scientific_interfaces/Indirect/Reduction/DataReduction.cpp b/qt/scientific_interfaces/Indirect/Reduction/DataReduction.cpp index f3760959f2b9..e9ae207a6c9d 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/DataReduction.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/DataReduction.cpp @@ -41,22 +41,14 @@ DECLARE_SUBWINDOW(DataReduction) DataReduction::DataReduction(QWidget *parent) : InelasticInterface(parent), m_settingsGroup("CustomInterfaces/DataReduction"), - m_algRunner(new MantidQt::API::QtAlgorithmRunner(this)), m_changeObserver(*this, &DataReduction::handleConfigChange), m_ipfFilename(""), m_idfDirectory(Mantid::Kernel::ConfigService::Instance().getString("instrumentDefinition.directory")), m_instDetails() { - // Signals to report load instrument algo result - connect(m_algRunner, SIGNAL(algorithmComplete(bool)), this, SLOT(instrumentLoadingDone(bool))); - Mantid::Kernel::ConfigService::Instance().addObserver(m_changeObserver); } DataReduction::~DataReduction() { Mantid::Kernel::ConfigService::Instance().removeObserver(m_changeObserver); - - // Make sure no algos are running after the window has been closed - m_algRunner->cancelRunningAlgorithm(); - saveSettings(); } diff --git a/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h b/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h index ac96c525d057..1e6d842bf6fc 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h +++ b/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h @@ -13,7 +13,6 @@ #include "MantidAPI/MatrixWorkspace.h" #include "MantidGeometry/IComponent.h" #include "MantidQtWidgets/Common/AlgorithmRunner.h" -#include "MantidQtWidgets/Common/QtAlgorithmRunner.h" #include "MantidQtWidgets/Common/QtJobRunner.h" #include @@ -190,8 +189,6 @@ private slots: Ui::DataReduction m_uiForm; /// The settings group QString m_settingsGroup; - /// Runner for insturment load algorithm - MantidQt::API::QtAlgorithmRunner *m_algRunner; // All indirect tabs QMap> m_tabs; diff --git a/qt/scientific_interfaces/Inelastic/Common/InelasticTab.h b/qt/scientific_interfaces/Inelastic/Common/InelasticTab.h index 627bdcaae3e6..60afbbf93e2d 100644 --- a/qt/scientific_interfaces/Inelastic/Common/InelasticTab.h +++ b/qt/scientific_interfaces/Inelastic/Common/InelasticTab.h @@ -12,7 +12,6 @@ #include "MantidAPI/ITableWorkspace.h" #include "MantidKernel/DateAndTime.h" #include "MantidQtWidgets/Common/BatchAlgorithmRunner.h" -#include "MantidQtWidgets/Common/QtAlgorithmRunner.h" #include "MantidQtWidgets/Common/QtPropertyBrowser/QtIntPropertyManager" #include "MantidQtWidgets/Common/QtPropertyBrowser/QtTreePropertyBrowser" #include "MantidQtWidgets/Common/QtPropertyBrowser/qteditorfactory.h" diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/IJobRunner.h b/qt/widgets/common/inc/MantidQtWidgets/Common/IJobRunner.h index d4221c1540b5..a9d94ab67761 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/IJobRunner.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/IJobRunner.h @@ -45,6 +45,5 @@ class EXPORT_OPT_MANTIDQT_COMMON IJobRunner { virtual void executeAlgorithmQueue() = 0; virtual void executeAlgorithm(MantidQt::API::IConfiguredAlgorithm_sptr algorithm) = 0; virtual void cancelAlgorithmQueue() = 0; - virtual std::size_t queueLength() = 0; }; } // namespace MantidQt::API diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/QtJobRunner.h b/qt/widgets/common/inc/MantidQtWidgets/Common/QtJobRunner.h index 0708232369b9..2b92ef10503f 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/QtJobRunner.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/QtJobRunner.h @@ -29,7 +29,6 @@ class EXPORT_OPT_MANTIDQT_COMMON QtJobRunner : public QObject, public IJobRunner void executeAlgorithmQueue() override; void executeAlgorithm(MantidQt::API::IConfiguredAlgorithm_sptr algorithm) override; void cancelAlgorithmQueue() override; - std::size_t queueLength() override; private slots: void onBatchComplete(bool error); diff --git a/qt/widgets/common/src/QtJobRunner.cpp b/qt/widgets/common/src/QtJobRunner.cpp index 80ffbb27ea5f..e512b4e010c9 100644 --- a/qt/widgets/common/src/QtJobRunner.cpp +++ b/qt/widgets/common/src/QtJobRunner.cpp @@ -35,8 +35,6 @@ void QtJobRunner::executeAlgorithm(IConfiguredAlgorithm_sptr algorithm) { m_batchAlgoRunner.executeAlgorithmAsync(std::move(algorithm)); } -std::size_t QtJobRunner::queueLength() { return m_batchAlgoRunner.queueLength(); } - void QtJobRunner::cancelAlgorithmQueue() { m_batchAlgoRunner.cancelBatch(); } void QtJobRunner::connectBatchAlgoRunnerSlots() { From f6972d0bc96f66b3c11c5882a9d56d4f46d9882f Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 26 Apr 2024 12:38:52 +0100 Subject: [PATCH 26/58] Update failing tests after introducing AlgorithmRunner --- .../Indirect/Reduction/DataReductionTab.cpp | 7 ++- .../Reduction/ISISEnergyTransferPresenter.h | 2 +- .../Reduction/ISISEnergyTransferModelTest.h | 49 +++++-------------- .../ISISEnergyTransferPresenterTest.h | 8 ++- .../Indirect/test/Reduction/MockObjects.h | 5 +- qt/widgets/common/CMakeLists.txt | 3 -- 6 files changed, 25 insertions(+), 49 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.cpp b/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.cpp index 608b7a3f7505..77a05629bfa9 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/DataReductionTab.cpp @@ -31,9 +31,8 @@ DataReductionTab::DataReductionTab(IDataReduction *idrUI, QObject *parent) connect(this, SIGNAL(newInstrumentConfiguration()), this, SLOT(handleNewInstrumentConfiguration())); } -DataReductionTab::DataReductionTab(IDataReduction *idrUI, - std::unique_ptr algorithmRunner) - : InelasticTab(), m_idrUI(idrUI), m_tabRunning(false), m_algorithmRunner(std::move(algorithmRunner)) { +DataReductionTab::DataReductionTab(IDataReduction *idrUI, std::unique_ptr algorithmRunner) + : InelasticTab(), m_idrUI(idrUI), m_algorithmRunner(std::move(algorithmRunner)), m_tabRunning(false) { connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(tabExecutionComplete(bool))); connect(this, SIGNAL(newInstrumentConfiguration()), this, SLOT(handleNewInstrumentConfiguration())); } @@ -83,7 +82,7 @@ void DataReductionTab::tabExecutionComplete(bool error) { } } -void IndirectDataReductionTab::handleNewInstrumentConfiguration() { updateInstrumentConfiguration(); } +void DataReductionTab::handleNewInstrumentConfiguration() { updateInstrumentConfiguration(); } /** * Gets the current instrument workspace diff --git a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h index 95d73d05fe53..392f4519ecf2 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h +++ b/qt/scientific_interfaces/Indirect/Reduction/ISISEnergyTransferPresenter.h @@ -6,11 +6,11 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once +#include "DataReductionTab.h" #include "DllConfig.h" #include "ISISEnergyTransferData.h" #include "ISISEnergyTransferModel.h" #include "ISISEnergyTransferView.h" -#include "DataReductionTab.h" #include "MantidQtWidgets/Common/IAlgorithmRunnerSubscriber.h" diff --git a/qt/scientific_interfaces/Indirect/test/Reduction/ISISEnergyTransferModelTest.h b/qt/scientific_interfaces/Indirect/test/Reduction/ISISEnergyTransferModelTest.h index 1235f02c413e..aeab12be3bc6 100644 --- a/qt/scientific_interfaces/Indirect/test/Reduction/ISISEnergyTransferModelTest.h +++ b/qt/scientific_interfaces/Indirect/test/Reduction/ISISEnergyTransferModelTest.h @@ -310,9 +310,7 @@ class ISISEnergyTransferModelTest : public CxxTest::TestSuite { TS_ASSERT_EQUALS(outputName, "instrument1234, 1235_analyser_reflection_Reduced"); } - void testRunIETAlgorithm() { - MantidQt::API::BatchAlgorithmRunner *batch = new MantidQt::API::BatchAlgorithmRunner(nullptr); - + void test_energyTransferAlgorithm() { IETInputData inputData("input_workspace1, input_workspace2", "input_workspace1, input_workspace2", true, false, true, "calibration_workspace"); IETConversionData conversionData(1.0, 1, 2); @@ -327,43 +325,18 @@ class ISISEnergyTransferModelTest : public CxxTest::TestSuite { InstrumentData instData("instrument", "analyser", "reflection"); - m_model->runIETAlgorithm(batch, instData, runData); - - // Wait for the algorithm to finish - std::this_thread::sleep_for(std::chrono::seconds(1)); - - TS_ASSERT_EQUALS(AnalysisDataService::Instance().doesExist("outputWS"), true); - if (AnalysisDataService::Instance().doesExist("outputWS")) { - ITableWorkspace_sptr outputWS = - Mantid::API::AnalysisDataService::Instance().retrieveWS("outputWS"); - - TS_ASSERT_EQUALS(outputWS->rowCount(), 1); - TS_ASSERT_EQUALS(outputWS->columnCount(), 18); - - TS_ASSERT_EQUALS(outputWS->getColumn(0)->name(), "Instrument"); - TS_ASSERT_EQUALS(outputWS->getColumn(1)->name(), "Analyser"); - TS_ASSERT_EQUALS(outputWS->getColumn(2)->name(), "Reflection"); + auto configuredAlg = m_model->energyTransferAlgorithm(instData, runData); + auto &runtimeProps = configuredAlg->getAlgorithmRuntimeProps(); + TS_ASSERT_EQUALS("instrument", runtimeProps.getPropertyValue("Instrument")); + TS_ASSERT_EQUALS("analyser", runtimeProps.getPropertyValue("Analyser")); + TS_ASSERT_EQUALS("reflection", runtimeProps.getPropertyValue("Reflection")); - TS_ASSERT_EQUALS(outputWS->getColumn(3)->name(), "InputFiles"); - TS_ASSERT_EQUALS(outputWS->getColumn(4)->name(), "SumFiles"); - TS_ASSERT_EQUALS(outputWS->getColumn(5)->name(), "LoadLogFiles"); - TS_ASSERT_EQUALS(outputWS->getColumn(6)->name(), "CalibrationWorkspace"); + TS_ASSERT_EQUALS("input_workspace1, input_workspace2", runtimeProps.getPropertyValue("InputFiles")); + TS_ASSERT_EQUALS("1", runtimeProps.getPropertyValue("SumFiles")); + TS_ASSERT_EQUALS("0", runtimeProps.getPropertyValue("LoadLogFiles")); - TS_ASSERT_EQUALS(outputWS->getColumn(7)->name(), "Efixed"); - TS_ASSERT_EQUALS(outputWS->getColumn(8)->name(), "SpectraRange"); - TS_ASSERT_EQUALS(outputWS->getColumn(9)->name(), "BackgroundRange"); - TS_ASSERT_EQUALS(outputWS->getColumn(10)->name(), "RebinString"); - - TS_ASSERT_EQUALS(outputWS->getColumn(11)->name(), "DetailedBalance"); - - TS_ASSERT_EQUALS(outputWS->getColumn(12)->name(), "UnitX"); - TS_ASSERT_EQUALS(outputWS->getColumn(13)->name(), "FoldMultipleFrames"); - TS_ASSERT_EQUALS(outputWS->getColumn(14)->name(), "OutputWorkspace"); - - TS_ASSERT_EQUALS(outputWS->getColumn(15)->name(), "GroupingMethod"); - TS_ASSERT_EQUALS(outputWS->getColumn(16)->name(), "GroupingString"); - TS_ASSERT_EQUALS(outputWS->getColumn(17)->name(), "GroupingFile"); - } + TS_ASSERT_EQUALS("1, 2", runtimeProps.getPropertyValue("SpectraRange")); + TS_ASSERT_EQUALS("0, 1", runtimeProps.getPropertyValue("BackgroundRange")); } void testValidateRunDetailedBalanceInvalid() { diff --git a/qt/scientific_interfaces/Indirect/test/Reduction/ISISEnergyTransferPresenterTest.h b/qt/scientific_interfaces/Indirect/test/Reduction/ISISEnergyTransferPresenterTest.h index 3c1eb04db95a..97c8f3459fdf 100644 --- a/qt/scientific_interfaces/Indirect/test/Reduction/ISISEnergyTransferPresenterTest.h +++ b/qt/scientific_interfaces/Indirect/test/Reduction/ISISEnergyTransferPresenterTest.h @@ -16,6 +16,7 @@ #include "MantidFrameworkTestHelpers/IndirectFitDataCreationHelper.h" #include "MantidKernel/WarningSuppressions.h" +#include "MantidQtWidgets/Common/MockAlgorithmRunner.h" using namespace MantidQt::CustomInterfaces; using namespace testing; @@ -33,6 +34,7 @@ class ISISEnergyTransferPresenterTest : public CxxTest::TestSuite { void setUp() override { auto model = std::make_unique>(); + auto algorithmRunner = std::make_unique>(); m_outputOptionsView = std::make_unique>(); m_instrumentConfig = std::make_unique>(); @@ -41,10 +43,12 @@ class ISISEnergyTransferPresenterTest : public CxxTest::TestSuite { ON_CALL(*m_view, getPlotOptionsView()).WillByDefault(Return(m_outputOptionsView.get())); m_model = model.get(); + m_algorithmRunner = algorithmRunner.get(); m_idrUI = std::make_unique>(); ON_CALL(*m_idrUI, getInstrumentConfiguration()).WillByDefault(Return(m_instrumentConfig.get())); - m_presenter = std::make_unique(m_idrUI.get(), m_view.get(), std::move(model)); + m_presenter = + std::make_unique(m_idrUI.get(), m_view.get(), std::move(model), std::move(algorithmRunner)); } void tearDown() override { @@ -52,6 +56,7 @@ class ISISEnergyTransferPresenterTest : public CxxTest::TestSuite { TS_ASSERT(Mock::VerifyAndClearExpectations(&m_instrumentConfig)); TS_ASSERT(Mock::VerifyAndClearExpectations(&m_view)); TS_ASSERT(Mock::VerifyAndClearExpectations(m_model)); + TS_ASSERT(Mock::VerifyAndClearExpectations(m_algorithmRunner)); TS_ASSERT(Mock::VerifyAndClearExpectations(&m_idrUI)); m_presenter.reset(); @@ -116,6 +121,7 @@ class ISISEnergyTransferPresenterTest : public CxxTest::TestSuite { std::unique_ptr> m_view; NiceMock *m_model; + NiceMock *m_algorithmRunner; std::unique_ptr> m_idrUI; std::unique_ptr> m_outputOptionsView; diff --git a/qt/scientific_interfaces/Indirect/test/Reduction/MockObjects.h b/qt/scientific_interfaces/Indirect/test/Reduction/MockObjects.h index b2564c259234..9e59989058b5 100644 --- a/qt/scientific_interfaces/Indirect/test/Reduction/MockObjects.h +++ b/qt/scientific_interfaces/Indirect/test/Reduction/MockObjects.h @@ -44,8 +44,8 @@ class MockIETModel : public IIETModel { MOCK_METHOD1(validateRunData, std::vector(IETRunData const &runData)); MOCK_METHOD1(validatePlotData, std::vector(IETPlotData const &plotData)); - MOCK_METHOD3(runIETAlgorithm, std::string(MantidQt::API::BatchAlgorithmRunner *batchAlgoRunner, - InstrumentData const &instData, IETRunData &runParams)); + MOCK_METHOD2(energyTransferAlgorithm, + MantidQt::API::IConfiguredAlgorithm_sptr(InstrumentData const &instData, IETRunData &runParams)); MOCK_CONST_METHOD2(plotRawAlgorithmQueue, std::deque(InstrumentData const &instData, IETPlotData const &plotData)); @@ -60,6 +60,7 @@ class MockIETModel : public IIETModel { MOCK_METHOD4(groupWorkspaces, std::vector(std::string const &groupName, std::string const &instrument, std::string const &groupOption, bool const shouldGroup)); + MOCK_CONST_METHOD0(outputGroupName, std::string()); MOCK_CONST_METHOD0(outputWorkspaceNames, std::vector()); }; diff --git a/qt/widgets/common/CMakeLists.txt b/qt/widgets/common/CMakeLists.txt index 619c82be64cf..873ee84f1519 100644 --- a/qt/widgets/common/CMakeLists.txt +++ b/qt/widgets/common/CMakeLists.txt @@ -5,7 +5,6 @@ set(SRC_FILES src/AlgorithmHistoryWindow.cpp src/AlgorithmInputHistory.cpp src/AlgorithmPropertiesWidget.cpp - src/AlgorithmRunner.cpp src/AlgorithmSelectorWidget.cpp src/AlgorithmRunner.cpp src/AlternateCSPythonLexer.cpp @@ -391,7 +390,6 @@ set(MOC_FILES inc/MantidQtWidgets/Common/OptionsPropertyWidget.h inc/MantidQtWidgets/Common/PropertyWidget.h inc/MantidQtWidgets/Common/PythonRunner.h - inc/MantidQtWidgets/Common/QtAlgorithmRunner.h inc/MantidQtWidgets/Common/QScienceSpinBox.h inc/MantidQtWidgets/Common/QtSignalChannel.h inc/MantidQtWidgets/Common/RepoTreeView.h @@ -523,7 +521,6 @@ set(INC_FILES inc/MantidQtWidgets/Common/QtAlgorithmRunner.h inc/MantidQtWidgets/Common/QSettingsHelper.h inc/MantidQtWidgets/Common/QStringUtils.h - inc/MantidQtWidgets/Common/QtAlgorithmRunner.h inc/MantidQtWidgets/Common/QtJSONUtils.h inc/MantidQtWidgets/Common/ScriptRepositoryView.h inc/MantidQtWidgets/Common/SelectionNotificationService.h From 1a05c17d9278a5b72f95a99a1077d8a35e1acf61 Mon Sep 17 00:00:00 2001 From: Applin Date: Tue, 30 Apr 2024 09:51:06 +0100 Subject: [PATCH 27/58] Create basics of FittingPresenter --- .../Inelastic/QENSFitting/CMakeLists.txt | 2 ++ .../QENSFitting/FittingPresenter.cpp | 13 +++++++++ .../Inelastic/QENSFitting/FittingPresenter.h | 29 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp create mode 100644 qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/CMakeLists.txt b/qt/scientific_interfaces/Inelastic/QENSFitting/CMakeLists.txt index 26a32f5edf41..b7b7fc9710bd 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/CMakeLists.txt +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/CMakeLists.txt @@ -21,6 +21,7 @@ set(SRC_FILES FitPlotView.cpp FitTab.cpp FittingModel.cpp + FittingPresenter.cpp FqFitAddWorkspaceDialog.cpp FqFitDataPresenter.cpp FqFitDataView.cpp @@ -58,6 +59,7 @@ set(INC_FILES FitPlotModel.h FitPlotPresenter.h FittingModel.h + FittingPresenter.h FitTabConstants.h FqFitDataPresenter.h FqFitModel.h diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp new file mode 100644 index 000000000000..1721466fcb5f --- /dev/null +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp @@ -0,0 +1,13 @@ +// Mantid Repository : https://github.com/mantidproject/mantid +// +// Copyright © 2024 ISIS Rutherford Appleton Laboratory UKRI, +// NScD Oak Ridge National Laboratory, European Spallation Source, +// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS +// SPDX - License - Identifier: GPL - 3.0 + +#include "FittingPresenter.h" + +namespace MantidQt::CustomInterfaces::Inelastic { + +FittingPresenter::FittingPresenter(std::unique_ptr model) : m_model(std::move(model)) {} + +} // namespace MantidQt::CustomInterfaces::Inelastic \ No newline at end of file diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h new file mode 100644 index 000000000000..b6b5d420c2f7 --- /dev/null +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h @@ -0,0 +1,29 @@ +// Mantid Repository : https://github.com/mantidproject/mantid +// +// Copyright © 2024 ISIS Rutherford Appleton Laboratory UKRI, +// NScD Oak Ridge National Laboratory, European Spallation Source, +// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS +// SPDX - License - Identifier: GPL - 3.0 + +#pragma once + +#include "FittingModel.h" + +#include "DllConfig.h" + +#include + +namespace MantidQt { +namespace CustomInterfaces { +namespace Inelastic { + +class MANTIDQT_INELASTIC_DLL FittingPresenter { +public: + FittingPresenter(std::unique_ptr model); + +private: + std::unique_ptr m_model; +}; + +} // namespace Inelastic +} // namespace CustomInterfaces +} // namespace MantidQt \ No newline at end of file From ae2b71031db20d00e1530f092857bd76f5ad68ef Mon Sep 17 00:00:00 2001 From: Applin Date: Tue, 30 Apr 2024 12:04:16 +0100 Subject: [PATCH 28/58] Move FittingModel and FitPropertyBrowser to FittingPresenter --- .../Inelastic/QENSFitting/FitDataPresenter.h | 2 - .../Inelastic/QENSFitting/FitTab.cpp | 149 ++++++---------- .../Inelastic/QENSFitting/FitTab.h | 35 ++-- .../Inelastic/QENSFitting/FittingModel.cpp | 2 +- .../Inelastic/QENSFitting/FittingModel.h | 2 +- .../QENSFitting/FittingPresenter.cpp | 161 +++++++++++++++++- .../Inelastic/QENSFitting/FittingPresenter.h | 75 +++++++- .../QENSFitting/FqFitDataPresenter.cpp | 10 +- .../QENSFitting/FqFitDataPresenter.h | 3 - .../Inelastic/QENSFitting/IFittingModel.h | 2 +- .../Inelastic/QENSFitting/TabFactory.cpp | 9 +- 11 files changed, 308 insertions(+), 142 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitDataPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitDataPresenter.h index d91e20bc218f..76f9e4162c84 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitDataPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitDataPresenter.h @@ -73,8 +73,6 @@ class MANTIDQT_INELASTIC_DLL FitDataPresenter : public IFitDataPresenter, public UNUSED_ARG(single); }; - virtual void subscribeFitPropertyBrowser(IInelasticFitPropertyBrowser *browser) { UNUSED_ARG(browser); }; - std::string tabName() const override; void handleAddData(MantidWidgets::IAddWorkspaceDialog const *dialog) override; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp index 1cf5ee5ff98d..0f4f734c0d79 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp @@ -21,8 +21,8 @@ namespace CustomInterfaces { namespace Inelastic { FitTab::FitTab(QWidget *parent, std::string const &tabName) - : InelasticTab(parent), m_uiForm(new Ui::FitTab), m_dataPresenter(), m_fittingModel(), m_plotPresenter(), - m_outOptionsPresenter(), m_fitPropertyBrowser(), m_fittingAlgorithm() { + : InelasticTab(parent), m_uiForm(new Ui::FitTab), m_dataPresenter(), m_fittingPresenter(), m_plotPresenter(), + m_outOptionsPresenter(), m_fittingAlgorithm() { m_uiForm->setupUi(parent); parent->setWindowTitle(QString::fromStdString(tabName)); } @@ -31,11 +31,7 @@ void FitTab::setup() { connect(m_uiForm->pbRun, SIGNAL(clicked()), this, SLOT(runTab())); updateResultOptions(); - connect(m_fitPropertyBrowser, SIGNAL(functionChanged()), this, SLOT(handleFunctionChanged())); -} - -void FitTab::subscribeFitBrowserToDataPresenter() { - m_dataPresenter->subscribeFitPropertyBrowser(m_fitPropertyBrowser); + // connect(m_fitPropertyBrowser, SIGNAL(functionChanged()), this, SLOT(handleFunctionChanged())); } void FitTab::setupOutputOptionsPresenter(bool const editResults) { @@ -49,7 +45,7 @@ void FitTab::setupPlotView(std::optional> const &xPlot auto model = std::make_unique(); m_plotPresenter = std::make_unique(this, m_uiForm->dockArea->m_fitPlotView, std::move(model)); m_plotPresenter->setFittingData(m_dataPresenter->getFittingData()); - m_plotPresenter->setFitOutput(m_fittingModel->getFitOutput()); + m_plotPresenter->setFitOutput(m_fittingPresenter->getFitOutput()); if (xPlotBounds) { m_plotPresenter->setXBounds(*xPlotBounds); } @@ -57,9 +53,9 @@ void FitTab::setupPlotView(std::optional> const &xPlot } void FitTab::setModelFitFunction() { - auto func = m_fitPropertyBrowser->getFitFunction(); + auto func = m_fittingPresenter->fitFunction(); m_plotPresenter->setFitFunction(func); - m_fittingModel->setFitFunction(func); + m_fittingPresenter->setFitFunction(func); } void FitTab::handleTableStartXChanged(double startX, WorkspaceID workspaceID, WorkspaceIndex spectrum) { @@ -76,6 +72,10 @@ void FitTab::handleTableEndXChanged(double endX, WorkspaceID workspaceID, Worksp } } +void FitTab::handleFunctionListChanged(const std::map &functionStrings) { + m_fittingPresenter->updateFunctionListInBrowser(functionStrings); +} + void FitTab::handleStartXChanged(double startX) { m_plotPresenter->setStartX(startX); m_dataPresenter->setStartX(startX, m_plotPresenter->getActiveWorkspaceID()); @@ -96,10 +96,10 @@ void FitTab::updateFitOutput(bool error) { disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(updateFitOutput(bool))); if (error) { - m_fittingModel->cleanFailedRun(m_fittingAlgorithm); + m_fittingPresenter->cleanFailedRun(m_fittingAlgorithm); m_fittingAlgorithm.reset(); } else { - m_fittingModel->addOutput(m_fittingAlgorithm); + m_fittingPresenter->addOutput(m_fittingAlgorithm); } } @@ -107,11 +107,11 @@ void FitTab::updateSingleFitOutput(bool error) { disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(updateSingleFitOutput(bool))); if (error) { - m_fittingModel->cleanFailedSingleRun(m_fittingAlgorithm, m_plotPresenter->getActiveWorkspaceID()); + m_fittingPresenter->cleanFailedSingleRun(m_fittingAlgorithm, m_plotPresenter->getActiveWorkspaceID()); m_fittingAlgorithm.reset(); } else { - m_fittingModel->addSingleFitOutput(m_fittingAlgorithm, m_plotPresenter->getActiveWorkspaceID(), - m_plotPresenter->getActiveWorkspaceIndex()); + m_fittingPresenter->addSingleFitOutput(m_fittingAlgorithm, m_plotPresenter->getActiveWorkspaceID(), + m_plotPresenter->getActiveWorkspaceIndex()); } } @@ -123,65 +123,17 @@ void FitTab::fitAlgorithmComplete(bool error) { m_plotPresenter->setFitSingleSpectrumIsFitting(false); enableFitButtons(true); enableOutputOptions(!error); - m_fitPropertyBrowser->setErrorsEnabled(!error); + m_fittingPresenter->setErrorsEnabled(!error); if (!error) { - updateFitBrowserParameterValuesFromAlg(); - updateFitStatus(); + m_fittingPresenter->updateFitBrowserParameterValuesFromAlg(m_fittingAlgorithm, + m_dataPresenter->getNumberOfDomains()); + m_fittingPresenter->updateFitStatus(m_fittingAlgorithm, m_dataPresenter->getNumberOfDomains()); setModelFitFunction(); } m_plotPresenter->updatePlots(); disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(fitAlgorithmComplete(bool))); } -void FitTab::updateFitBrowserParameterValues(const std::unordered_map ¶ms) { - auto fun = m_fittingModel->getFitFunction(); - if (fun) { - for (auto const &pair : params) { - fun->setParameter(pair.first, pair.second.value); - } - if (fun->getNumberDomains() > 1) { - m_fitPropertyBrowser->updateMultiDatasetParameters(*fun); - } else { - m_fitPropertyBrowser->updateParameters(*fun); - } - } -} - -void FitTab::updateFitBrowserParameterValuesFromAlg() { - updateFitBrowserParameterValues(); - if (m_fittingAlgorithm) { - QSignalBlocker blocker(m_fitPropertyBrowser); - if (m_fittingModel->getFittingMode() == FittingMode::SEQUENTIAL) { - auto const paramWsName = m_fittingAlgorithm->getPropertyValue("OutputParameterWorkspace"); - auto paramWs = AnalysisDataService::Instance().retrieveWS(paramWsName); - auto rowCount = static_cast(paramWs->rowCount()); - if (rowCount == static_cast(m_dataPresenter->getNumberOfDomains())) - m_fitPropertyBrowser->updateMultiDatasetParameters(*paramWs); - } else { - IFunction_sptr fun = m_fittingAlgorithm->getProperty("Function"); - if (fun->getNumberDomains() > 1) - m_fitPropertyBrowser->updateMultiDatasetParameters(*fun); - else - m_fitPropertyBrowser->updateParameters(*fun); - } - } -} -/** - * Updates the fit output status - */ -void FitTab::updateFitStatus() { - if (m_fittingModel->getFittingMode() == FittingMode::SIMULTANEOUS) { - std::string fit_status = m_fittingAlgorithm->getProperty("OutputStatus"); - double chi2 = m_fittingAlgorithm->getProperty("OutputChiSquared"); - const std::vector status(m_dataPresenter->getNumberOfDomains(), fit_status); - const std::vector chiSquared(m_dataPresenter->getNumberOfDomains(), chi2); - m_fitPropertyBrowser->updateFitStatusData(status, chiSquared); - } else { - const std::vector status = m_fittingAlgorithm->getProperty("OutputStatus"); - const std::vector chiSquared = m_fittingAlgorithm->getProperty("OutputChiSquared"); - m_fitPropertyBrowser->updateFitStatusData(status, chiSquared); - } -} /** * Plots the spectra corresponding to the selected parameters */ @@ -199,15 +151,15 @@ void FitTab::handleSingleFitClicked(WorkspaceID workspaceID, WorkspaceIndex spec m_plotPresenter->setFitSingleSpectrumIsFitting(true); enableFitButtons(false); enableOutputOptions(false); - m_fittingModel->setFittingMode(FittingMode::SIMULTANEOUS); - runSingleFit(m_fittingModel->getSingleFit(workspaceID, spectrum)); + m_fittingPresenter->setFittingMode(FittingMode::SIMULTANEOUS); + runSingleFit(m_fittingPresenter->getSingleFit(workspaceID, spectrum)); } } bool FitTab::validate() { UserInputValidator validator; m_dataPresenter->validate(validator); - m_fittingModel->validate(validator); + m_fittingPresenter->validate(validator); const auto error = validator.generateErrorMessage().toStdString(); if (!error.empty()) { @@ -222,8 +174,8 @@ bool FitTab::validate() { void FitTab::run() { enableFitButtons(false); enableOutputOptions(false); - m_fittingModel->setFittingMode(m_fitPropertyBrowser->getFittingMode()); - runFitAlgorithm(m_fittingModel->getFittingAlgorithm(m_fittingModel->getFittingMode())); + m_fittingPresenter->updateFittingModeFromBrowser(); + runFitAlgorithm(m_fittingPresenter->getFittingAlgorithm(m_fittingPresenter->getFittingMode())); } /** @@ -235,7 +187,7 @@ void FitTab::enableFitButtons(bool enable) { m_uiForm->pbRun->setText(enable ? "Run" : "Running..."); m_uiForm->pbRun->setEnabled(enable); m_plotPresenter->setFitSingleSpectrumEnabled(enable); - m_fitPropertyBrowser->setFitEnabled(enable); + m_fittingPresenter->setFitEnabled(enable); } /** @@ -245,8 +197,8 @@ void FitTab::enableFitButtons(bool enable) { */ void FitTab::enableOutputOptions(bool enable) { if (enable) { - m_outOptionsPresenter->setResultWorkspace(m_fittingModel->getResultWorkspace()); - setPDFWorkspace(m_fittingModel->getOutputBasename() + "_PDFs"); + m_outOptionsPresenter->setResultWorkspace(m_fittingPresenter->getResultWorkspace()); + setPDFWorkspace(m_fittingPresenter->getOutputBasename() + "_PDFs"); m_outOptionsPresenter->setPlotTypes("Result Group"); } else m_outOptionsPresenter->setMultiWorkspaceOptionsVisible(enable); @@ -262,7 +214,7 @@ void FitTab::enableOutputOptions(bool enable) { * @param workspaceName :: the name of the PDF workspace if it exists */ void FitTab::setPDFWorkspace(std::string const &workspaceName) { - auto const fabMinimizer = m_fitPropertyBrowser->minimizer() == "FABADA"; + auto const fabMinimizer = m_fittingPresenter->minimizer() == "FABADA"; auto const enablePDFOptions = WorkspaceUtils::doesExistInADS(workspaceName) && fabMinimizer; if (enablePDFOptions) { @@ -274,14 +226,10 @@ void FitTab::setPDFWorkspace(std::string const &workspaceName) { } void FitTab::updateParameterEstimationData() { - m_fitPropertyBrowser->updateParameterEstimationData( - m_dataPresenter->getDataForParameterEstimation(m_fitPropertyBrowser->getEstimationDataSelector())); - const bool isFit = m_fittingModel->isPreviouslyFit(m_plotPresenter->getActiveWorkspaceID(), - m_plotPresenter->getActiveWorkspaceIndex()); - // If we haven't fit the data yet we may update the guess - if (!isFit) { - m_fitPropertyBrowser->estimateFunctionParameters(); - } + m_fittingPresenter->updateParameterEstimationData( + m_dataPresenter->getDataForParameterEstimation(m_fittingPresenter->getEstimationDataSelector())); + m_fittingPresenter->estimateFunctionParameters(m_plotPresenter->getActiveWorkspaceID(), + m_plotPresenter->getActiveWorkspaceIndex()); } /* @@ -303,16 +251,16 @@ void FitTab::runSingleFit(IAlgorithm_sptr fitAlgorithm) { } void FitTab::setupFit(IAlgorithm_sptr fitAlgorithm) { - auto properties = m_fitPropertyBrowser->fitProperties(m_fittingModel->getFittingMode()); + auto properties = m_fittingPresenter->fitProperties(); m_fittingAlgorithm = fitAlgorithm; m_batchAlgoRunner->addAlgorithm(fitAlgorithm, std::move(properties)); connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(fitAlgorithmComplete(bool))); } void FitTab::updateDataReferences() { - m_fitPropertyBrowser->updateFunctionBrowserData(static_cast(m_dataPresenter->getNumberOfDomains()), - m_dataPresenter->getDatasets(), m_dataPresenter->getQValuesForData(), - m_dataPresenter->getResolutionsForFit()); + m_fittingPresenter->updateFunctionBrowserData(static_cast(m_dataPresenter->getNumberOfDomains()), + m_dataPresenter->getDatasets(), m_dataPresenter->getQValuesForData(), + m_dataPresenter->getResolutionsForFit()); setModelFitFunction(); } @@ -321,10 +269,10 @@ void FitTab::updateDataReferences() { * enabled/disabled. */ void FitTab::updateResultOptions() { - const bool isFit = m_fittingModel->isPreviouslyFit(m_plotPresenter->getActiveWorkspaceID(), - m_plotPresenter->getActiveWorkspaceIndex()); + const bool isFit = m_fittingPresenter->isPreviouslyFit(m_plotPresenter->getActiveWorkspaceID(), + m_plotPresenter->getActiveWorkspaceIndex()); if (isFit) - m_outOptionsPresenter->setResultWorkspace(m_fittingModel->getResultWorkspace()); + m_outOptionsPresenter->setResultWorkspace(m_fittingPresenter->getResultWorkspace()); m_outOptionsPresenter->setPlotEnabled(isFit); m_outOptionsPresenter->setEditResultEnabled(isFit); m_outOptionsPresenter->setSaveEnabled(isFit); @@ -334,7 +282,7 @@ std::string FitTab::tabName() const { return m_parentWidget->windowTitle().toStd void FitTab::handleDataChanged() { updateDataReferences(); - m_fittingModel->removeFittingData(); + m_fittingPresenter->removeFittingData(); m_plotPresenter->updateAvailableSpectra(); m_plotPresenter->updatePlots(); m_plotPresenter->updateGuessAvailability(); @@ -344,7 +292,7 @@ void FitTab::handleDataChanged() { void FitTab::handleDataAdded(IAddWorkspaceDialog const *dialog) { if (m_dataPresenter->addWorkspaceFromDialog(dialog)) { - m_fittingModel->addDefaultParameters(); + m_fittingPresenter->addDefaultParameters(); } updateDataReferences(); m_plotPresenter->appendLastDataToSelection(m_dataPresenter->createDisplayNames()); @@ -352,7 +300,7 @@ void FitTab::handleDataAdded(IAddWorkspaceDialog const *dialog) { } void FitTab::handleDataRemoved() { - m_fittingModel->removeDefaultParameters(); + m_fittingPresenter->removeDefaultParameters(); updateDataReferences(); m_plotPresenter->updateDataSelection(m_dataPresenter->createDisplayNames()); updateParameterEstimationData(); @@ -360,28 +308,27 @@ void FitTab::handleDataRemoved() { void FitTab::handlePlotSpectrumChanged() { auto const index = m_plotPresenter->getSelectedDomainIndex(); - m_fitPropertyBrowser->setCurrentDataset(index); + m_fittingPresenter->setCurrentDataset(index); } void FitTab::handleFwhmChanged(double fwhm) { - m_fittingModel->setFWHM(fwhm, m_plotPresenter->getActiveWorkspaceID()); - updateFitBrowserParameterValues(); + m_fittingPresenter->setFWHM(m_plotPresenter->getActiveWorkspaceID(), fwhm); + m_fittingPresenter->updateFitBrowserParameterValues(); m_plotPresenter->updateGuess(); } void FitTab::handleBackgroundChanged(double value) { - m_fittingModel->setBackground(value, m_plotPresenter->getActiveWorkspaceID()); - m_fitPropertyBrowser->setBackgroundA0(value); + m_fittingPresenter->setBackground(m_plotPresenter->getActiveWorkspaceID(), value); setModelFitFunction(); m_plotPresenter->updateGuess(); } void FitTab::handleFunctionChanged() { setModelFitFunction(); - m_fittingModel->removeFittingData(); + m_fittingPresenter->removeFittingData(); m_plotPresenter->updatePlots(); m_plotPresenter->updateFit(); - m_fittingModel->updateFitTypeString(); + m_fittingPresenter->updateFitTypeString(); } } // namespace Inelastic diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h index dc98712b6e4f..83863aef52a2 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h @@ -11,7 +11,7 @@ #include "FitDataPresenter.h" #include "FitOutputOptionsPresenter.h" #include "FitPlotPresenter.h" -#include "FittingModel.h" +#include "FittingPresenter.h" #include "FunctionBrowser/TemplateSubType.h" #include "InelasticFitPropertyBrowser.h" #include "ui_FitTab.h" @@ -34,6 +34,7 @@ class MANTIDQT_INELASTIC_DLL IFitTab { virtual void handleDataRemoved() = 0; virtual void handleTableStartXChanged(double startX, WorkspaceID workspaceID, WorkspaceIndex workspaceIndex) = 0; virtual void handleTableEndXChanged(double endX, WorkspaceID workspaceID, WorkspaceIndex workspaceIndex) = 0; + virtual void handleFunctionListChanged(const std::map &functionStrings) = 0; // Used by FitPlotPresenter virtual void handleSingleFitClicked(WorkspaceID workspaceID, WorkspaceIndex workspaceIndex) = 0; @@ -46,7 +47,7 @@ class MANTIDQT_INELASTIC_DLL IFitTab { // Used by FitOutputOptionsPresenter virtual void handlePlotSelectedSpectra() = 0; - // Used by InelasticFitPropertyBrowser + // Used by FittingModel virtual void handleFunctionChanged() = 0; }; @@ -57,8 +58,6 @@ class MANTIDQT_INELASTIC_DLL FitTab : public InelasticTab, public IFitTab { FitTab(QWidget *parent, std::string const &tabName); virtual ~FitTab() override = default; - template void setupFittingModel() { m_fittingModel = std::make_unique(); } - template void setupFitPropertyBrowser(std::vector const &hiddenProperties, bool const convolveMembers = false, TemplateBrowserCustomizations customizations = TemplateBrowserCustomizations()) { @@ -68,10 +67,15 @@ class MANTIDQT_INELASTIC_DLL FitTab : public InelasticTab, public IFitTab { m_uiForm->dockArea->m_fitPropertyBrowser->setFunctionTemplatePresenter(std::move(templatePresenter)); m_uiForm->dockArea->m_fitPropertyBrowser->init(); m_uiForm->dockArea->m_fitPropertyBrowser->setHiddenProperties(hiddenProperties); - m_fitPropertyBrowser = m_uiForm->dockArea->m_fitPropertyBrowser; - m_fitPropertyBrowser->setConvolveMembers(convolveMembers); + m_uiForm->dockArea->m_fitPropertyBrowser->setConvolveMembers(convolveMembers); if (convolveMembers) - m_fitPropertyBrowser->setOutputCompositeMembers(true); + m_uiForm->dockArea->m_fitPropertyBrowser->setOutputCompositeMembers(true); + } + + template void setupFittingPresenter() { + auto model = std::make_unique(); + m_fittingPresenter = + std::make_unique(this, m_uiForm->dockArea->m_fitPropertyBrowser, std::move(model)); } template void setupFitDataView() { @@ -79,13 +83,12 @@ class MANTIDQT_INELASTIC_DLL FitTab : public InelasticTab, public IFitTab { } template void setUpFitDataPresenter() { - m_dataPresenter = - std::make_unique(this, m_fittingModel->getFitDataModel(), m_uiForm->dockArea->m_fitDataView); + m_dataPresenter = std::make_unique(this, m_fittingPresenter->getFitDataModel(), + m_uiForm->dockArea->m_fitDataView); } void setupOutputOptionsPresenter(bool const editResults = false); void setupPlotView(std::optional> const &xPlotBounds = std::nullopt); - void subscribeFitBrowserToDataPresenter(); std::string tabName() const override; @@ -94,6 +97,7 @@ class MANTIDQT_INELASTIC_DLL FitTab : public InelasticTab, public IFitTab { void handleDataRemoved() override; void handleTableStartXChanged(double startX, WorkspaceID workspaceID, WorkspaceIndex workspaceIndex) override; void handleTableEndXChanged(double endX, WorkspaceID workspaceID, WorkspaceIndex workspaceIndex) override; + void handleFunctionListChanged(const std::map &functionStrings) override; void handleSingleFitClicked(WorkspaceID workspaceID, WorkspaceIndex workspaceIndex) override; void handlePlotSpectrumChanged() override; @@ -102,12 +106,12 @@ class MANTIDQT_INELASTIC_DLL FitTab : public InelasticTab, public IFitTab { void handlePlotSelectedSpectra() override; + void handleFunctionChanged() override; + public slots: void handleStartXChanged(double startX) override; void handleEndXChanged(double endX) override; - void handleFunctionChanged() override; - private slots: void updateFitOutput(bool error); void updateSingleFitOutput(bool error); @@ -128,20 +132,15 @@ private slots: void setModelFitFunction(); void updateParameterEstimationData(); - void updateFitStatus(); void updateDataReferences(); void updateResultOptions(); - void updateFitBrowserParameterValues(const std::unordered_map ¶meters = - std::unordered_map()); - void updateFitBrowserParameterValuesFromAlg(); std::unique_ptr m_uiForm; std::unique_ptr m_dataPresenter; - std::unique_ptr m_fittingModel; + std::unique_ptr m_fittingPresenter; std::unique_ptr m_plotPresenter; std::unique_ptr m_outOptionsPresenter; - InelasticFitPropertyBrowser *m_fitPropertyBrowser; Mantid::API::IAlgorithm_sptr m_fittingAlgorithm; }; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp index 2ab0f9cdd942..7fc2ebc0ab28 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp @@ -618,6 +618,6 @@ void FittingModel::cleanFailedSingleRun(const IAlgorithm_sptr &fittingAlgorithm, cleanTemporaries(base + "_0"); } -IFitDataModel *FittingModel::getFitDataModel() { return m_fitDataModel.get(); } +IFitDataModel *FittingModel::getFitDataModel() const { return m_fitDataModel.get(); } } // namespace MantidQt::CustomInterfaces::Inelastic diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h index 17afd61a0a01..c7982122e36e 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h @@ -95,7 +95,7 @@ class MANTIDQT_INELASTIC_DLL FittingModel : public IFittingModel { void addDefaultParameters() override; void removeDefaultParameters() override; - IFitDataModel *getFitDataModel() override; + IFitDataModel *getFitDataModel() const override; // Used for testing purposes [[nodiscard]] inline std::string getFitString() const noexcept { return m_fitString; } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp index 1721466fcb5f..75480e1611d9 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp @@ -5,9 +5,168 @@ // Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS // SPDX - License - Identifier: GPL - 3.0 + #include "FittingPresenter.h" +#include "IFitOutput.h" +#include "InelasticFitPropertyBrowser.h" namespace MantidQt::CustomInterfaces::Inelastic { -FittingPresenter::FittingPresenter(std::unique_ptr model) : m_model(std::move(model)) {} +FittingPresenter::FittingPresenter(IFitTab *tab, InelasticFitPropertyBrowser *browser, + std::unique_ptr model) + : m_tab(tab), m_fitPropertyBrowser(browser), m_model(std::move(model)) {} + +void FittingPresenter::validate(UserInputValidator &validator) { m_model->validate(validator); } + +void FittingPresenter::setFitFunction(Mantid::API::MultiDomainFunction_sptr function) { + m_model->setFitFunction(std::move(function)); +} + +void FittingPresenter::setFittingMode(FittingMode mode) { m_model->setFittingMode(mode); } + +FittingMode FittingPresenter::getFittingMode() const { return m_model->getFittingMode(); } + +void FittingPresenter::setErrorsEnabled(bool const enable) { m_fitPropertyBrowser->setErrorsEnabled(enable); } + +void FittingPresenter::setFitEnabled(bool const enable) { m_fitPropertyBrowser->setFitEnabled(enable); } + +void FittingPresenter::setCurrentDataset(FitDomainIndex index) { m_fitPropertyBrowser->setCurrentDataset(index); } + +MultiDomainFunction_sptr FittingPresenter::fitFunction() const { return m_fitPropertyBrowser->getFitFunction(); } + +std::string FittingPresenter::minimizer() const { return m_fitPropertyBrowser->minimizer(); } + +EstimationDataSelector FittingPresenter::getEstimationDataSelector() const { + return m_fitPropertyBrowser->getEstimationDataSelector(); +} + +void FittingPresenter::updateParameterEstimationData(DataForParameterEstimationCollection &&data) { + m_fitPropertyBrowser->updateParameterEstimationData(std::move(data)); +} + +void FittingPresenter::estimateFunctionParameters(WorkspaceID workspaceID, WorkspaceIndex spectrum) { + if (!m_model->isPreviouslyFit(workspaceID, spectrum)) { + m_fitPropertyBrowser->estimateFunctionParameters(); + } +} + +void FittingPresenter::updateFunctionBrowserData(int nData, const QList &datasets, + const std::vector &qValues, + const std::vector> &fitResolutions) { + m_fitPropertyBrowser->updateFunctionBrowserData(nData, datasets, qValues, fitResolutions); +} + +void FittingPresenter::updateFunctionListInBrowser(const std::map &functionStrings) { + m_fitPropertyBrowser->updateFunctionListInBrowser(functionStrings); +} + +void FittingPresenter::cleanFailedRun(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm) { + m_model->cleanFailedRun(fittingAlgorithm); +} + +void FittingPresenter::cleanFailedSingleRun(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, + WorkspaceID workspaceID) { + m_model->cleanFailedSingleRun(fittingAlgorithm, workspaceID); +} + +void FittingPresenter::removeFittingData() { m_model->removeFittingData(); } + +void FittingPresenter::addDefaultParameters() { m_model->addDefaultParameters(); } + +void FittingPresenter::removeDefaultParameters() { m_model->removeDefaultParameters(); } + +void FittingPresenter::addOutput(Mantid::API::IAlgorithm_sptr &fittingAlgorithm) { + m_model->addOutput(fittingAlgorithm); +} + +void FittingPresenter::addSingleFitOutput(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, WorkspaceID workspaceID, + WorkspaceIndex spectrum) { + m_model->addSingleFitOutput(fittingAlgorithm, workspaceID, spectrum); +} + +std::unique_ptr FittingPresenter::fitProperties() const { + return m_fitPropertyBrowser->fitProperties(m_model->getFittingMode()); +} + +Mantid::API::WorkspaceGroup_sptr FittingPresenter::getResultWorkspace() const { return m_model->getResultWorkspace(); } + +IFitOutput *FittingPresenter::getFitOutput() const { return m_model->getFitOutput(); } + +Mantid::API::IAlgorithm_sptr FittingPresenter::getFittingAlgorithm(FittingMode mode) const { + return m_model->getFittingAlgorithm(mode); +} + +Mantid::API::IAlgorithm_sptr FittingPresenter::getSingleFit(WorkspaceID workspaceID, WorkspaceIndex spectrum) const { + return m_model->getSingleFit(workspaceID, spectrum); +} + +std::string FittingPresenter::getOutputBasename() const { return m_model->getOutputBasename(); } + +IFitDataModel *FittingPresenter::getFitDataModel() const { return m_model->getFitDataModel(); } + +bool FittingPresenter::isPreviouslyFit(WorkspaceID workspaceID, WorkspaceIndex spectrum) const { + return m_model->isPreviouslyFit(workspaceID, spectrum); +} + +void FittingPresenter::setFWHM(WorkspaceID WorkspaceID, double fwhm) { m_model->setFWHM(fwhm, WorkspaceID); } + +void FittingPresenter::setBackground(WorkspaceID WorkspaceID, double background) { + m_model->setBackground(background, WorkspaceID); + m_fitPropertyBrowser->setBackgroundA0(background); +} + +void FittingPresenter::updateFittingModeFromBrowser() { + m_model->setFittingMode(m_fitPropertyBrowser->getFittingMode()); +} + +void FittingPresenter::updateFitBrowserParameterValues(const std::unordered_map ¶ms) { + auto fun = m_model->getFitFunction(); + if (fun) { + for (auto const &pair : params) { + fun->setParameter(pair.first, pair.second.value); + } + if (fun->getNumberDomains() > 1) { + m_fitPropertyBrowser->updateMultiDatasetParameters(*fun); + } else { + m_fitPropertyBrowser->updateParameters(*fun); + } + } +} + +void FittingPresenter::updateFitBrowserParameterValuesFromAlg(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, + std::size_t const &numberOfDomains) { + updateFitBrowserParameterValues(); + if (fittingAlgorithm) { + QSignalBlocker blocker(m_fitPropertyBrowser); + if (m_model->getFittingMode() == FittingMode::SEQUENTIAL) { + auto const paramWsName = fittingAlgorithm->getPropertyValue("OutputParameterWorkspace"); + auto paramWs = AnalysisDataService::Instance().retrieveWS(paramWsName); + auto rowCount = static_cast(paramWs->rowCount()); + if (rowCount == static_cast(numberOfDomains)) + m_fitPropertyBrowser->updateMultiDatasetParameters(*paramWs); + } else { + IFunction_sptr fun = fittingAlgorithm->getProperty("Function"); + if (fun->getNumberDomains() > 1) + m_fitPropertyBrowser->updateMultiDatasetParameters(*fun); + else + m_fitPropertyBrowser->updateParameters(*fun); + } + } +} + +void FittingPresenter::updateFitStatus(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, + std::size_t const &numberOfDomains) { + if (m_model->getFittingMode() == FittingMode::SIMULTANEOUS) { + std::string fit_status = fittingAlgorithm->getProperty("OutputStatus"); + double chi2 = fittingAlgorithm->getProperty("OutputChiSquared"); + const std::vector status(numberOfDomains, fit_status); + const std::vector chiSquared(numberOfDomains, chi2); + m_fitPropertyBrowser->updateFitStatusData(status, chiSquared); + } else { + const std::vector status = fittingAlgorithm->getProperty("OutputStatus"); + const std::vector chiSquared = fittingAlgorithm->getProperty("OutputChiSquared"); + m_fitPropertyBrowser->updateFitStatusData(status, chiSquared); + } +} + +void FittingPresenter::updateFitTypeString() { m_model->updateFitTypeString(); } } // namespace MantidQt::CustomInterfaces::Inelastic \ No newline at end of file diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h index b6b5d420c2f7..42763c51acec 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h @@ -6,21 +6,92 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once +#include "DllConfig.h" #include "FittingModel.h" -#include "DllConfig.h" +#include "MantidAPI/AlgorithmRuntimeProps.h" +#include "MantidAPI/IAlgorithm.h" +#include "MantidAPI/MultiDomainFunction.h" +#include "MantidAPI/WorkspaceGroup.h" +#include "MantidQtWidgets/Common/UserInputValidator.h" +#include #include +#include +#include +#include namespace MantidQt { namespace CustomInterfaces { namespace Inelastic { +class IFitDataModel; +class IFitOutput; +class IFitTab; +class InelasticFitPropertyBrowser; + class MANTIDQT_INELASTIC_DLL FittingPresenter { public: - FittingPresenter(std::unique_ptr model); + FittingPresenter(IFitTab *tab, InelasticFitPropertyBrowser *browser, std::unique_ptr model); + + void validate(UserInputValidator &validator); + + void setFitFunction(Mantid::API::MultiDomainFunction_sptr function); + + void setFittingMode(FittingMode mode); + FittingMode getFittingMode() const; + + void setErrorsEnabled(bool const enable); + void setFitEnabled(bool const enable); + void setCurrentDataset(FitDomainIndex index); + Mantid::API::MultiDomainFunction_sptr fitFunction() const; + std::string minimizer() const; + + EstimationDataSelector getEstimationDataSelector() const; + void updateParameterEstimationData(DataForParameterEstimationCollection &&data); + void estimateFunctionParameters(WorkspaceID workspaceID, WorkspaceIndex spectrum); + + void updateFunctionBrowserData(int nData, const QList &datasets, + const std::vector &qValues, + const std::vector> &fitResolutions); + void updateFunctionListInBrowser(const std::map &functionStrings); + + void cleanFailedRun(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm); + void cleanFailedSingleRun(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, WorkspaceID workspaceID); + void removeFittingData(); + void addDefaultParameters(); + void removeDefaultParameters(); + + void addOutput(Mantid::API::IAlgorithm_sptr &fittingAlgorithm); + void addSingleFitOutput(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, WorkspaceID workspaceID, + WorkspaceIndex spectrum); + + std::unique_ptr fitProperties() const; + + Mantid::API::WorkspaceGroup_sptr getResultWorkspace() const; + IFitOutput *getFitOutput() const; + Mantid::API::IAlgorithm_sptr getFittingAlgorithm(FittingMode mode) const; + Mantid::API::IAlgorithm_sptr getSingleFit(WorkspaceID workspaceID, WorkspaceIndex spectrum) const; + std::string getOutputBasename() const; + + IFitDataModel *getFitDataModel() const; + + bool isPreviouslyFit(WorkspaceID workspaceID, WorkspaceIndex spectrum) const; + + void setFWHM(WorkspaceID WorkspaceID, double fwhm); + void setBackground(WorkspaceID WorkspaceID, double background); + + void updateFittingModeFromBrowser(); + void updateFitBrowserParameterValues(const std::unordered_map ¶ms = + std::unordered_map()); + void updateFitBrowserParameterValuesFromAlg(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, + std::size_t const &numberOfDomains); + void updateFitStatus(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, std::size_t const &numberOfDomains); + void updateFitTypeString(); private: + IFitTab *m_tab; + InelasticFitPropertyBrowser *m_fitPropertyBrowser; std::unique_ptr m_model; }; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FqFitDataPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FqFitDataPresenter.cpp index 99351ce1be97..ae210dc50575 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FqFitDataPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FqFitDataPresenter.cpp @@ -5,6 +5,7 @@ // Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS // SPDX - License - Identifier: GPL - 3.0 + #include "FqFitDataPresenter.h" +#include "FitTab.h" #include "FitTabConstants.h" #include "MantidAPI/TextAxis.h" #include "ParameterEstimation.h" @@ -197,11 +198,7 @@ namespace MantidQt::CustomInterfaces::Inelastic { FqFitDataPresenter::FqFitDataPresenter(IFitTab *tab, IFitDataModel *model, IFitDataView *view) : FitDataPresenter(tab, model, view), m_activeParameterType("Width"), m_activeWorkspaceID(WorkspaceID{0}), - m_adsInstance(Mantid::API::AnalysisDataService::Instance()), m_fitPropertyBrowser() {} - -void FqFitDataPresenter::subscribeFitPropertyBrowser(IInelasticFitPropertyBrowser *browser) { - m_fitPropertyBrowser = browser; -} + m_adsInstance(Mantid::API::AnalysisDataService::Instance()) {} bool FqFitDataPresenter::addWorkspaceFromDialog(MantidWidgets::IAddWorkspaceDialog const *dialog) { if (const auto fqFitDialog = dynamic_cast(dialog)) { @@ -236,8 +233,7 @@ void FqFitDataPresenter::addWorkspace(const std::string &workspaceName, const st if (workspace->y(0).size() == 1) throw std::invalid_argument("Workspace contains only one data point."); const auto hwhmWorkspace = createHWHMWorkspace(workspace, name, parameters.widthSpectra); - m_fitPropertyBrowser->updateFunctionListInBrowser(fqFitFunctionList); - + m_tab->handleFunctionListChanged(fqFitFunctionList); if (paramType == "Width") { const auto single_spectra = FunctionModelSpectra(std::to_string(parameters.widthSpectra[spectrum_index])); m_model->addWorkspace(hwhmWorkspace->getName(), single_spectra); diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FqFitDataPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FqFitDataPresenter.h index 6fc38bf568c8..a0464a8ec466 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FqFitDataPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FqFitDataPresenter.h @@ -10,7 +10,6 @@ #include "FqFitAddWorkspaceDialog.h" #include "FqFitDataView.h" #include "FunctionBrowser/SingleFunctionTemplateView.h" -#include "InelasticFitPropertyBrowser.h" namespace { struct FqFitParameters { @@ -40,7 +39,6 @@ class MANTIDQT_INELASTIC_DLL FqFitDataPresenter : public FitDataPresenter, publi void addWorkspace(const std::string &workspaceName, const std::string ¶mType, const int &spectrum_index) override; void setActiveWidth(std::size_t widthIndex, WorkspaceID dataIndex, bool single = true) override; void setActiveEISF(std::size_t eisfIndex, WorkspaceID dataIndex, bool single = true) override; - void subscribeFitPropertyBrowser(IInelasticFitPropertyBrowser *browser) override; void handleAddClicked() override; void handleWorkspaceChanged(FqFitAddWorkspaceDialog *dialog, const std::string &workspace) override; @@ -62,7 +60,6 @@ class MANTIDQT_INELASTIC_DLL FqFitDataPresenter : public FitDataPresenter, publi WorkspaceID m_activeWorkspaceID; Mantid::API::AnalysisDataServiceImpl &m_adsInstance; - IInelasticFitPropertyBrowser *m_fitPropertyBrowser; }; } // namespace Inelastic diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h index 84efebf727c0..2ad2ee2a6f63 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h @@ -72,7 +72,7 @@ class MANTIDQT_INELASTIC_DLL IFittingModel { virtual void removeFittingData() = 0; virtual void addDefaultParameters() = 0; virtual void removeDefaultParameters() = 0; - virtual IFitDataModel *getFitDataModel() = 0; + virtual IFitDataModel *getFitDataModel() const = 0; }; } // namespace Inelastic diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/TabFactory.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/TabFactory.cpp index 743084f25124..5dd77847d5cc 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/TabFactory.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/TabFactory.cpp @@ -40,9 +40,9 @@ TabFactory::TabFactory(QTabWidget *tabWidget) : m_tabWidget(tabWidget) {} FitTab *TabFactory::makeMSDFitTab(int const index) const { auto tab = new FitTab(m_tabWidget->widget(index), MSDFit::TAB_NAME); - tab->setupFittingModel(); tab->setupFitPropertyBrowser( MSDFit::HIDDEN_PROPS); + tab->setupFittingPresenter(); tab->setupFitDataView(); tab->setupOutputOptionsPresenter(); tab->setUpFitDataPresenter(); @@ -52,10 +52,10 @@ FitTab *TabFactory::makeMSDFitTab(int const index) const { FitTab *TabFactory::makeIqtFitTab(int const index) const { auto tab = new FitTab(m_tabWidget->widget(index), IqtFit::TAB_NAME); - tab->setupFittingModel(); auto browserCustomizations = packBrowserCustomizations(IqtFit::templateSubTypes()); tab->setupFitPropertyBrowser( IqtFit::HIDDEN_PROPS, false, std::move(browserCustomizations)); + tab->setupFittingPresenter(); tab->setupFitDataView(); tab->setupOutputOptionsPresenter(true); tab->setUpFitDataPresenter(); @@ -65,10 +65,10 @@ FitTab *TabFactory::makeIqtFitTab(int const index) const { FitTab *TabFactory::makeConvFitTab(int const index) const { auto tab = new FitTab(m_tabWidget->widget(index), ConvFit::TAB_NAME); - tab->setupFittingModel(); auto browserCustomizations = packBrowserCustomizations(ConvFit::templateSubTypes()); tab->setupFitPropertyBrowser( ConvFit::HIDDEN_PROPS, true, std::move(browserCustomizations)); + tab->setupFittingPresenter(); tab->setupFitDataView(); tab->setupOutputOptionsPresenter(true); tab->setUpFitDataPresenter(); @@ -78,13 +78,12 @@ FitTab *TabFactory::makeConvFitTab(int const index) const { FitTab *TabFactory::makeFqFitTab(int const index) const { auto tab = new FitTab(m_tabWidget->widget(index), FqFit::TAB_NAME); - tab->setupFittingModel(); tab->setupFitPropertyBrowser( FqFit::HIDDEN_PROPS); + tab->setupFittingPresenter(); tab->setupFitDataView(); tab->setupOutputOptionsPresenter(); tab->setUpFitDataPresenter(); - tab->subscribeFitBrowserToDataPresenter(); tab->setupPlotView(FqFit::X_BOUNDS); return tab; } From 526cc0e262a4e2a7bdbe8e2688f5cdf05733d494 Mon Sep 17 00:00:00 2001 From: Applin Date: Tue, 30 Apr 2024 12:18:31 +0100 Subject: [PATCH 29/58] Subscribe FittingPresenter to FitPropertyBrowser --- .../Inelastic/QENSFitting/FitTab.cpp | 2 -- .../Inelastic/QENSFitting/FittingPresenter.cpp | 7 ++++++- .../Inelastic/QENSFitting/FittingPresenter.h | 9 ++++++++- .../InelasticFitPropertyBrowser.cpp | 18 +++++++++++++----- .../QENSFitting/InelasticFitPropertyBrowser.h | 8 ++++++++ 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp index 0f4f734c0d79..f75a010ad7fa 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp @@ -30,8 +30,6 @@ FitTab::FitTab(QWidget *parent, std::string const &tabName) void FitTab::setup() { connect(m_uiForm->pbRun, SIGNAL(clicked()), this, SLOT(runTab())); updateResultOptions(); - - // connect(m_fitPropertyBrowser, SIGNAL(functionChanged()), this, SLOT(handleFunctionChanged())); } void FitTab::setupOutputOptionsPresenter(bool const editResults) { diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp index 75480e1611d9..c9ef7ec558ff 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp @@ -5,6 +5,7 @@ // Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS // SPDX - License - Identifier: GPL - 3.0 + #include "FittingPresenter.h" +#include "FitTab.h" #include "IFitOutput.h" #include "InelasticFitPropertyBrowser.h" @@ -12,7 +13,11 @@ namespace MantidQt::CustomInterfaces::Inelastic { FittingPresenter::FittingPresenter(IFitTab *tab, InelasticFitPropertyBrowser *browser, std::unique_ptr model) - : m_tab(tab), m_fitPropertyBrowser(browser), m_model(std::move(model)) {} + : m_tab(tab), m_fitPropertyBrowser(browser), m_model(std::move(model)) { + m_fitPropertyBrowser->subscribePresenter(this); +} + +void FittingPresenter::notifyFunctionChanged() { m_tab->handleFunctionChanged(); } void FittingPresenter::validate(UserInputValidator &validator) { m_model->validate(validator); } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h index 42763c51acec..1aef71ac4646 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h @@ -30,10 +30,17 @@ class IFitOutput; class IFitTab; class InelasticFitPropertyBrowser; -class MANTIDQT_INELASTIC_DLL FittingPresenter { +class MANTIDQT_INELASTIC_DLL IFittingPresenter { +public: + virtual void notifyFunctionChanged() = 0; +}; + +class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter { public: FittingPresenter(IFitTab *tab, InelasticFitPropertyBrowser *browser, std::unique_ptr model); + void notifyFunctionChanged() override; + void validate(UserInputValidator &validator); void setFitFunction(Mantid::API::MultiDomainFunction_sptr function); diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/InelasticFitPropertyBrowser.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/InelasticFitPropertyBrowser.cpp index e7a60197127a..8f7757ab675f 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/InelasticFitPropertyBrowser.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/InelasticFitPropertyBrowser.cpp @@ -6,6 +6,7 @@ // SPDX - License - Identifier: GPL - 3.0 + #include "InelasticFitPropertyBrowser.h" #include "FitStatusWidget.h" +#include "FittingPresenter.h" #include "FunctionBrowser/FunctionTemplateView.h" #include "FunctionBrowser/ITemplatePresenter.h" #include "FunctionBrowser/SingleFunctionTemplateView.h" @@ -55,11 +56,13 @@ struct ScopedSignalBlocker { */ InelasticFitPropertyBrowser::InelasticFitPropertyBrowser(QWidget *parent) : QDockWidget(parent), m_mainLayout(), m_functionBrowser(), m_fitOptionsBrowser(), m_templatePresenter(), - m_fitStatusWidget(), m_functionWidget(), m_browserSwitcher(), m_fitStatus(), m_fitChiSquared() { + m_fitStatusWidget(), m_functionWidget(), m_browserSwitcher(), m_fitStatus(), m_fitChiSquared(), m_presenter() { setFeatures(QDockWidget::DockWidgetFloatable); setWindowTitle("Fit Function"); } +void InelasticFitPropertyBrowser::subscribePresenter(IFittingPresenter *presenter) { m_presenter = presenter; } + void InelasticFitPropertyBrowser::initFunctionBrowser() { // this object is added as a child to the stacked widget m_templateBrowser // which is a child of this class so the lifetime of this pointer is handled @@ -69,10 +72,10 @@ void InelasticFitPropertyBrowser::initFunctionBrowser() { // Process internally connect(m_functionBrowser, SIGNAL(globalsChanged()), this, SLOT(updateFitType())); // Re-emit - connect(m_functionBrowser, SIGNAL(functionStructureChanged()), this, SIGNAL(functionChanged())); + connect(m_functionBrowser, SIGNAL(functionStructureChanged()), this, SLOT(notifyFunctionChanged())); connect(m_functionBrowser, SIGNAL(parameterChanged(std::string const &, std::string const &)), this, - SIGNAL(functionChanged())); - connect(m_functionBrowser, SIGNAL(globalsChanged()), this, SIGNAL(functionChanged())); + SLOT(notifyFunctionChanged())); + connect(m_functionBrowser, SIGNAL(globalsChanged()), this, SLOT(notifyFunctionChanged())); connect(m_functionBrowser, SIGNAL(localParameterButtonClicked(std::string const &)), this, SIGNAL(localParameterEditRequested(std::string const &))); } @@ -185,7 +188,12 @@ void InelasticFitPropertyBrowser::setFunctionTemplatePresenter(std::unique_ptrinit(); - connect(m_templatePresenter->browser(), SIGNAL(functionStructureChanged()), this, SIGNAL(functionChanged())); + connect(m_templatePresenter->browser(), SIGNAL(functionStructureChanged()), this, SLOT(notifyFunctionChanged())); +} + +void InelasticFitPropertyBrowser::notifyFunctionChanged() { + m_presenter->notifyFunctionChanged(); + emit functionChanged(); } void InelasticFitPropertyBrowser::setFunction(std::string const &funStr) { diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/InelasticFitPropertyBrowser.h b/qt/scientific_interfaces/Inelastic/QENSFitting/InelasticFitPropertyBrowser.h index 35a800ed00c0..4f01b8c2f3f6 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/InelasticFitPropertyBrowser.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/InelasticFitPropertyBrowser.h @@ -42,6 +42,7 @@ using namespace MantidWidgets; class FunctionTemplateView; class FitStatusWidget; +class IFittingPresenter; class MANTIDQT_INELASTIC_DLL IInelasticFitPropertyBrowser { public: @@ -54,6 +55,8 @@ class MANTIDQT_INELASTIC_DLL InelasticFitPropertyBrowser : public QDockWidget, p public: InelasticFitPropertyBrowser(QWidget *parent = nullptr); + void subscribePresenter(IFittingPresenter *presenter); + void init(); void setFunctionTemplatePresenter(std::unique_ptr templatePresenter); void setFunction(std::string const &funStr); @@ -104,6 +107,9 @@ protected slots: void updateFitType(); void showFullFunctionBrowser(bool on); +private slots: + void notifyFunctionChanged(); + signals: void functionChanged(); void fitScheduled(); @@ -133,6 +139,8 @@ protected slots: std::vector m_fitStatus; std::vector m_fitChiSquared; + + IFittingPresenter *m_presenter; }; } // namespace Inelastic From f6ac1dc18903280f1f21a06b5f44277506f9935f Mon Sep 17 00:00:00 2001 From: Applin Date: Tue, 30 Apr 2024 15:22:00 +0100 Subject: [PATCH 30/58] Make updateFitStatus a private method --- qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp | 1 - .../Inelastic/QENSFitting/FittingPresenter.cpp | 1 + .../Inelastic/QENSFitting/FittingPresenter.h | 3 ++- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp index f75a010ad7fa..052c5f7db95c 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp @@ -125,7 +125,6 @@ void FitTab::fitAlgorithmComplete(bool error) { if (!error) { m_fittingPresenter->updateFitBrowserParameterValuesFromAlg(m_fittingAlgorithm, m_dataPresenter->getNumberOfDomains()); - m_fittingPresenter->updateFitStatus(m_fittingAlgorithm, m_dataPresenter->getNumberOfDomains()); setModelFitFunction(); } m_plotPresenter->updatePlots(); diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp index c9ef7ec558ff..df7577a200df 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp @@ -155,6 +155,7 @@ void FittingPresenter::updateFitBrowserParameterValuesFromAlg(const Mantid::API: m_fitPropertyBrowser->updateParameters(*fun); } } + updateFitStatus(fittingAlgorithm, numberOfDomains); } void FittingPresenter::updateFitStatus(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h index 1aef71ac4646..5154082c4a46 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h @@ -93,10 +93,11 @@ class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter { std::unordered_map()); void updateFitBrowserParameterValuesFromAlg(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, std::size_t const &numberOfDomains); - void updateFitStatus(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, std::size_t const &numberOfDomains); void updateFitTypeString(); private: + void updateFitStatus(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, std::size_t const &numberOfDomains); + IFitTab *m_tab; InelasticFitPropertyBrowser *m_fitPropertyBrowser; std::unique_ptr m_model; From 9239c44970432d42ac96c92ba619c159365e53f9 Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 2 May 2024 11:48:08 +0100 Subject: [PATCH 31/58] Pass AlgorithmRunner into FittingPresenter --- qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h | 8 ++++++-- .../Inelastic/QENSFitting/FittingPresenter.cpp | 6 ++++-- .../Inelastic/QENSFitting/FittingPresenter.h | 5 ++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h index 83863aef52a2..67d8ca34e9e4 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h @@ -14,6 +14,8 @@ #include "FittingPresenter.h" #include "FunctionBrowser/TemplateSubType.h" #include "InelasticFitPropertyBrowser.h" +#include "MantidQtWidgets/Common/AlgorithmRunner.h" +#include "MantidQtWidgets/Common/QtJobRunner.h" #include "ui_FitTab.h" #include @@ -73,9 +75,11 @@ class MANTIDQT_INELASTIC_DLL FitTab : public InelasticTab, public IFitTab { } template void setupFittingPresenter() { + auto jobRunner = std::make_unique(); + auto algorithmRunner = std::make_unique(std::move(jobRunner)); auto model = std::make_unique(); - m_fittingPresenter = - std::make_unique(this, m_uiForm->dockArea->m_fitPropertyBrowser, std::move(model)); + m_fittingPresenter = std::make_unique(this, m_uiForm->dockArea->m_fitPropertyBrowser, + std::move(model), std::move(algorithmRunner)); } template void setupFitDataView() { diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp index df7577a200df..394a7babf208 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp @@ -12,8 +12,10 @@ namespace MantidQt::CustomInterfaces::Inelastic { FittingPresenter::FittingPresenter(IFitTab *tab, InelasticFitPropertyBrowser *browser, - std::unique_ptr model) - : m_tab(tab), m_fitPropertyBrowser(browser), m_model(std::move(model)) { + std::unique_ptr model, + std::unique_ptr algorithmRunner) + : m_tab(tab), m_fitPropertyBrowser(browser), m_model(std::move(model)), + m_algorithmRunner(std::move(algorithmRunner)) { m_fitPropertyBrowser->subscribePresenter(this); } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h index 5154082c4a46..bca99323a178 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h @@ -13,6 +13,7 @@ #include "MantidAPI/IAlgorithm.h" #include "MantidAPI/MultiDomainFunction.h" #include "MantidAPI/WorkspaceGroup.h" +#include "MantidQtWidgets/Common/AlgorithmRunner.h" #include "MantidQtWidgets/Common/UserInputValidator.h" #include @@ -37,7 +38,8 @@ class MANTIDQT_INELASTIC_DLL IFittingPresenter { class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter { public: - FittingPresenter(IFitTab *tab, InelasticFitPropertyBrowser *browser, std::unique_ptr model); + FittingPresenter(IFitTab *tab, InelasticFitPropertyBrowser *browser, std::unique_ptr model, + std::unique_ptr algorithmRunner); void notifyFunctionChanged() override; @@ -101,6 +103,7 @@ class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter { IFitTab *m_tab; InelasticFitPropertyBrowser *m_fitPropertyBrowser; std::unique_ptr m_model; + std::unique_ptr m_algorithmRunner; }; } // namespace Inelastic From 0a8b6d88ef8a5006a92c082ead208c5d93e3c0ff Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 2 May 2024 12:29:56 +0100 Subject: [PATCH 32/58] Move call of fit algorithm to FittingPresenter --- .../Inelastic/QENSFitting/FitTab.cpp | 92 +++++-------------- .../Inelastic/QENSFitting/FitTab.h | 15 +-- .../QENSFitting/FittingPresenter.cpp | 48 ++++++++-- .../Inelastic/QENSFitting/FittingPresenter.h | 14 ++- 4 files changed, 73 insertions(+), 96 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp index 052c5f7db95c..948813ec9246 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp @@ -22,7 +22,7 @@ namespace Inelastic { FitTab::FitTab(QWidget *parent, std::string const &tabName) : InelasticTab(parent), m_uiForm(new Ui::FitTab), m_dataPresenter(), m_fittingPresenter(), m_plotPresenter(), - m_outOptionsPresenter(), m_fittingAlgorithm() { + m_outOptionsPresenter() { m_uiForm->setupUi(parent); parent->setWindowTitle(QString::fromStdString(tabName)); } @@ -90,46 +90,17 @@ void FitTab::handleEndXChanged(double endX) { m_dataPresenter->updateTableFromModel(); } -void FitTab::updateFitOutput(bool error) { - disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(updateFitOutput(bool))); +// void FitTab::updateSingleFitOutput(bool error) { +// disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(updateSingleFitOutput(bool))); - if (error) { - m_fittingPresenter->cleanFailedRun(m_fittingAlgorithm); - m_fittingAlgorithm.reset(); - } else { - m_fittingPresenter->addOutput(m_fittingAlgorithm); - } -} - -void FitTab::updateSingleFitOutput(bool error) { - disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(updateSingleFitOutput(bool))); - - if (error) { - m_fittingPresenter->cleanFailedSingleRun(m_fittingAlgorithm, m_plotPresenter->getActiveWorkspaceID()); - m_fittingAlgorithm.reset(); - } else { - m_fittingPresenter->addSingleFitOutput(m_fittingAlgorithm, m_plotPresenter->getActiveWorkspaceID(), - m_plotPresenter->getActiveWorkspaceIndex()); - } -} - -/** - * Performs necessary state changes when the fit algorithm was run - * and completed within this interface. - */ -void FitTab::fitAlgorithmComplete(bool error) { - m_plotPresenter->setFitSingleSpectrumIsFitting(false); - enableFitButtons(true); - enableOutputOptions(!error); - m_fittingPresenter->setErrorsEnabled(!error); - if (!error) { - m_fittingPresenter->updateFitBrowserParameterValuesFromAlg(m_fittingAlgorithm, - m_dataPresenter->getNumberOfDomains()); - setModelFitFunction(); - } - m_plotPresenter->updatePlots(); - disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(fitAlgorithmComplete(bool))); -} +// if (error) { +// m_fittingPresenter->cleanFailedSingleRun(m_fittingAlgorithm, m_plotPresenter->getActiveWorkspaceID()); +// m_fittingAlgorithm.reset(); +//} else { +// m_fittingPresenter->addSingleFitOutput(m_fittingAlgorithm, m_plotPresenter->getActiveWorkspaceID(), +// m_plotPresenter->getActiveWorkspaceIndex()); +//} +//} /** * Plots the spectra corresponding to the selected parameters @@ -148,8 +119,7 @@ void FitTab::handleSingleFitClicked(WorkspaceID workspaceID, WorkspaceIndex spec m_plotPresenter->setFitSingleSpectrumIsFitting(true); enableFitButtons(false); enableOutputOptions(false); - m_fittingPresenter->setFittingMode(FittingMode::SIMULTANEOUS); - runSingleFit(m_fittingPresenter->getSingleFit(workspaceID, spectrum)); + m_fittingPresenter->runSingleFit(workspaceID, spectrum); } } @@ -171,8 +141,7 @@ bool FitTab::validate() { void FitTab::run() { enableFitButtons(false); enableOutputOptions(false); - m_fittingPresenter->updateFittingModeFromBrowser(); - runFitAlgorithm(m_fittingPresenter->getFittingAlgorithm(m_fittingPresenter->getFittingMode())); + m_fittingPresenter->runFit(); } /** @@ -229,31 +198,6 @@ void FitTab::updateParameterEstimationData() { m_plotPresenter->getActiveWorkspaceIndex()); } -/* - * Runs the specified fit algorithm and calls the algorithmComplete - * method of this fit analysis tab once completed. - * - * @param fitAlgorithm The fit algorithm to run. - */ -void FitTab::runFitAlgorithm(IAlgorithm_sptr fitAlgorithm) { - connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(updateFitOutput(bool))); - setupFit(std::move(fitAlgorithm)); - m_batchAlgoRunner->executeBatchAsync(); -} - -void FitTab::runSingleFit(IAlgorithm_sptr fitAlgorithm) { - connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(updateSingleFitOutput(bool))); - setupFit(std::move(fitAlgorithm)); - m_batchAlgoRunner->executeBatchAsync(); -} - -void FitTab::setupFit(IAlgorithm_sptr fitAlgorithm) { - auto properties = m_fittingPresenter->fitProperties(); - m_fittingAlgorithm = fitAlgorithm; - m_batchAlgoRunner->addAlgorithm(fitAlgorithm, std::move(properties)); - connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(fitAlgorithmComplete(bool))); -} - void FitTab::updateDataReferences() { m_fittingPresenter->updateFunctionBrowserData(static_cast(m_dataPresenter->getNumberOfDomains()), m_dataPresenter->getDatasets(), m_dataPresenter->getQValuesForData(), @@ -328,6 +272,16 @@ void FitTab::handleFunctionChanged() { m_fittingPresenter->updateFitTypeString(); } +void FitTab::handleFitComplete(bool const error) { + m_plotPresenter->setFitSingleSpectrumIsFitting(false); + enableFitButtons(true); + enableOutputOptions(!error); + if (!error) { + m_plotPresenter->setFitFunction(m_fittingPresenter->fitFunction()); + } + m_plotPresenter->updatePlots(); +} + } // namespace Inelastic } // namespace CustomInterfaces } // namespace MantidQt diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h index 67d8ca34e9e4..d61f60c5bfed 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h @@ -49,8 +49,9 @@ class MANTIDQT_INELASTIC_DLL IFitTab { // Used by FitOutputOptionsPresenter virtual void handlePlotSelectedSpectra() = 0; - // Used by FittingModel + // Used by FittingPresenter virtual void handleFunctionChanged() = 0; + virtual void handleFitComplete(bool const error) = 0; }; class MANTIDQT_INELASTIC_DLL FitTab : public InelasticTab, public IFitTab { @@ -111,25 +112,17 @@ class MANTIDQT_INELASTIC_DLL FitTab : public InelasticTab, public IFitTab { void handlePlotSelectedSpectra() override; void handleFunctionChanged() override; + void handleFitComplete(bool const error) override; public slots: void handleStartXChanged(double startX) override; void handleEndXChanged(double endX) override; -private slots: - void updateFitOutput(bool error); - void updateSingleFitOutput(bool error); - void fitAlgorithmComplete(bool error); - private: void setup() override; bool validate() override; void run() override; - void runFitAlgorithm(Mantid::API::IAlgorithm_sptr fitAlgorithm); - void runSingleFit(Mantid::API::IAlgorithm_sptr fitAlgorithm); - void setupFit(Mantid::API::IAlgorithm_sptr fitAlgorithm); - void enableFitButtons(bool enable); void enableOutputOptions(bool enable); void setPDFWorkspace(std::string const &workspaceName); @@ -145,8 +138,6 @@ private slots: std::unique_ptr m_fittingPresenter; std::unique_ptr m_plotPresenter; std::unique_ptr m_outOptionsPresenter; - - Mantid::API::IAlgorithm_sptr m_fittingAlgorithm; }; } // namespace Inelastic diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp index 394a7babf208..6be06d2cb408 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp @@ -17,12 +17,45 @@ FittingPresenter::FittingPresenter(IFitTab *tab, InelasticFitPropertyBrowser *br : m_tab(tab), m_fitPropertyBrowser(browser), m_model(std::move(model)), m_algorithmRunner(std::move(algorithmRunner)) { m_fitPropertyBrowser->subscribePresenter(this); + m_algorithmRunner->subscribe(this); } void FittingPresenter::notifyFunctionChanged() { m_tab->handleFunctionChanged(); } void FittingPresenter::validate(UserInputValidator &validator) { m_model->validate(validator); } +void FittingPresenter::runFit() { + m_model->setFittingMode(m_fitPropertyBrowser->getFittingMode()); + auto alg = m_model->getFittingAlgorithm(m_model->getFittingMode()); + // connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(updateFitOutput(bool))); + auto properties = m_fitPropertyBrowser->fitProperties(m_model->getFittingMode()); + MantidQt::API::IConfiguredAlgorithm_sptr confAlg = + std::make_shared(alg, std::move(properties)); + m_algorithmRunner->execute(confAlg); +} + +void FittingPresenter::runSingleFit(WorkspaceID workspaceID, WorkspaceIndex spectrum) { + m_model->setFittingMode(FittingMode::SIMULTANEOUS); + auto alg = m_model->getSingleFit(workspaceID, spectrum); + // connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(updateSingleFitOutput(bool))); + auto properties = m_fitPropertyBrowser->fitProperties(m_model->getFittingMode()); + MantidQt::API::IConfiguredAlgorithm_sptr confAlg = + std::make_shared(alg, std::move(properties)); + m_algorithmRunner->execute(confAlg); +} + +void FittingPresenter::notifyBatchComplete(MantidQt::API::IConfiguredAlgorithm_sptr &lastAlgorithm, bool error) { + m_fitPropertyBrowser->setErrorsEnabled(!error); + if (!error) { + updateFitBrowserParameterValuesFromAlg(lastAlgorithm->algorithm()); + m_model->setFitFunction(m_fitPropertyBrowser->getFitFunction()); + m_model->addOutput(lastAlgorithm->algorithm()); + } else { + m_model->cleanFailedRun(lastAlgorithm->algorithm()); + } + m_tab->handleFitComplete(error); +} + void FittingPresenter::setFitFunction(Mantid::API::MultiDomainFunction_sptr function) { m_model->setFitFunction(std::move(function)); } @@ -120,10 +153,6 @@ void FittingPresenter::setBackground(WorkspaceID WorkspaceID, double background) m_fitPropertyBrowser->setBackgroundA0(background); } -void FittingPresenter::updateFittingModeFromBrowser() { - m_model->setFittingMode(m_fitPropertyBrowser->getFittingMode()); -} - void FittingPresenter::updateFitBrowserParameterValues(const std::unordered_map ¶ms) { auto fun = m_model->getFitFunction(); if (fun) { @@ -138,8 +167,7 @@ void FittingPresenter::updateFitBrowserParameterValues(const std::unordered_map< } } -void FittingPresenter::updateFitBrowserParameterValuesFromAlg(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, - std::size_t const &numberOfDomains) { +void FittingPresenter::updateFitBrowserParameterValuesFromAlg(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm) { updateFitBrowserParameterValues(); if (fittingAlgorithm) { QSignalBlocker blocker(m_fitPropertyBrowser); @@ -147,7 +175,7 @@ void FittingPresenter::updateFitBrowserParameterValuesFromAlg(const Mantid::API: auto const paramWsName = fittingAlgorithm->getPropertyValue("OutputParameterWorkspace"); auto paramWs = AnalysisDataService::Instance().retrieveWS(paramWsName); auto rowCount = static_cast(paramWs->rowCount()); - if (rowCount == static_cast(numberOfDomains)) + if (rowCount == static_cast(m_model->getFitDataModel()->getNumberOfDomains())) m_fitPropertyBrowser->updateMultiDatasetParameters(*paramWs); } else { IFunction_sptr fun = fittingAlgorithm->getProperty("Function"); @@ -157,14 +185,14 @@ void FittingPresenter::updateFitBrowserParameterValuesFromAlg(const Mantid::API: m_fitPropertyBrowser->updateParameters(*fun); } } - updateFitStatus(fittingAlgorithm, numberOfDomains); + updateFitStatus(fittingAlgorithm); } -void FittingPresenter::updateFitStatus(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, - std::size_t const &numberOfDomains) { +void FittingPresenter::updateFitStatus(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm) { if (m_model->getFittingMode() == FittingMode::SIMULTANEOUS) { std::string fit_status = fittingAlgorithm->getProperty("OutputStatus"); double chi2 = fittingAlgorithm->getProperty("OutputChiSquared"); + auto numberOfDomains = m_model->getFitDataModel()->getNumberOfDomains(); const std::vector status(numberOfDomains, fit_status); const std::vector chiSquared(numberOfDomains, chi2); m_fitPropertyBrowser->updateFitStatusData(status, chiSquared); diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h index bca99323a178..055c9d955f14 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h @@ -14,6 +14,8 @@ #include "MantidAPI/MultiDomainFunction.h" #include "MantidAPI/WorkspaceGroup.h" #include "MantidQtWidgets/Common/AlgorithmRunner.h" +#include "MantidQtWidgets/Common/ConfiguredAlgorithm.h" +#include "MantidQtWidgets/Common/IAlgorithmRunnerSubscriber.h" #include "MantidQtWidgets/Common/UserInputValidator.h" #include @@ -36,14 +38,18 @@ class MANTIDQT_INELASTIC_DLL IFittingPresenter { virtual void notifyFunctionChanged() = 0; }; -class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter { +class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter, + public MantidQt::API::IAlgorithmRunnerSubscriber { public: FittingPresenter(IFitTab *tab, InelasticFitPropertyBrowser *browser, std::unique_ptr model, std::unique_ptr algorithmRunner); void notifyFunctionChanged() override; + void notifyBatchComplete(MantidQt::API::IConfiguredAlgorithm_sptr &lastAlgorithm, bool error) override; void validate(UserInputValidator &validator); + void runFit(); + void runSingleFit(WorkspaceID workspaceID, WorkspaceIndex spectrum); void setFitFunction(Mantid::API::MultiDomainFunction_sptr function); @@ -90,15 +96,13 @@ class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter { void setFWHM(WorkspaceID WorkspaceID, double fwhm); void setBackground(WorkspaceID WorkspaceID, double background); - void updateFittingModeFromBrowser(); void updateFitBrowserParameterValues(const std::unordered_map ¶ms = std::unordered_map()); - void updateFitBrowserParameterValuesFromAlg(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, - std::size_t const &numberOfDomains); + void updateFitBrowserParameterValuesFromAlg(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm); void updateFitTypeString(); private: - void updateFitStatus(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, std::size_t const &numberOfDomains); + void updateFitStatus(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm); IFitTab *m_tab; InelasticFitPropertyBrowser *m_fitPropertyBrowser; From c01f21274f2126a0db19df9b66a52d791694006a Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 2 May 2024 16:00:29 +0100 Subject: [PATCH 33/58] Create IFitPlotModel class and change ownership to FittingModel --- .../Inelastic/QENSFitting/FitPlotModel.h | 81 +++++++++++++------ .../QENSFitting/FitPlotPresenter.cpp | 5 +- .../Inelastic/QENSFitting/FitPlotPresenter.h | 18 ++++- .../Inelastic/QENSFitting/FitTab.cpp | 4 +- .../Inelastic/QENSFitting/FittingModel.cpp | 7 +- .../Inelastic/QENSFitting/FittingModel.h | 3 + .../QENSFitting/FittingPresenter.cpp | 2 + .../Inelastic/QENSFitting/FittingPresenter.h | 2 + .../Inelastic/QENSFitting/IFittingModel.h | 4 + 9 files changed, 90 insertions(+), 36 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h index 4a37de146282..f8a556e5fcce 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h @@ -23,36 +23,65 @@ namespace CustomInterfaces { namespace Inelastic { using namespace MantidWidgets; -class MANTIDQT_INELASTIC_DLL FitPlotModel { +class MANTIDQT_INELASTIC_DLL IFitPlotModel { +public: + virtual Mantid::API::MatrixWorkspace_sptr getWorkspace() const = 0; + virtual Mantid::API::MatrixWorkspace_sptr getResultWorkspace() const = 0; + virtual Mantid::API::MatrixWorkspace_sptr getGuessWorkspace() const = 0; + virtual MantidWidgets::FunctionModelSpectra getSpectra(WorkspaceID workspaceID) const = 0; + + virtual WorkspaceID getActiveWorkspaceID() const = 0; + virtual WorkspaceIndex getActiveWorkspaceIndex() const = 0; + virtual FitDomainIndex getActiveDomainIndex() const = 0; + virtual WorkspaceID numberOfWorkspaces() const = 0; + virtual std::pair getRange() const = 0; + virtual std::pair getWorkspaceRange() const = 0; + virtual std::pair getResultRange() const = 0; + virtual boost::optional getFirstHWHM() const = 0; + virtual boost::optional getFirstPeakCentre() const = 0; + virtual boost::optional getFirstBackgroundLevel() const = 0; + virtual double calculateHWHMMaximum(double minimum) const = 0; + virtual double calculateHWHMMinimum(double maximum) const = 0; + virtual bool canCalculateGuess() const = 0; + + virtual void setActiveIndex(WorkspaceID workspaceID) = 0; + virtual void setActiveSpectrum(WorkspaceIndex spectrum) = 0; + + virtual void setFittingData(std::vector *fittingData) = 0; + virtual void setFitOutput(IFitOutput *fitOutput) = 0; + virtual void setFitFunction(Mantid::API::MultiDomainFunction_sptr function) = 0; +}; + +class MANTIDQT_INELASTIC_DLL FitPlotModel : public IFitPlotModel { public: FitPlotModel(); ~FitPlotModel(); - Mantid::API::MatrixWorkspace_sptr getWorkspace() const; - Mantid::API::MatrixWorkspace_sptr getResultWorkspace() const; - Mantid::API::MatrixWorkspace_sptr getGuessWorkspace() const; - MantidWidgets::FunctionModelSpectra getSpectra(WorkspaceID workspaceID) const; - - WorkspaceID getActiveWorkspaceID() const; - WorkspaceIndex getActiveWorkspaceIndex() const; - FitDomainIndex getActiveDomainIndex() const; - WorkspaceID numberOfWorkspaces() const; - std::pair getRange() const; - std::pair getWorkspaceRange() const; - std::pair getResultRange() const; - boost::optional getFirstHWHM() const; - boost::optional getFirstPeakCentre() const; - boost::optional getFirstBackgroundLevel() const; - double calculateHWHMMaximum(double minimum) const; - double calculateHWHMMinimum(double maximum) const; - bool canCalculateGuess() const; - - void setActiveIndex(WorkspaceID workspaceID); - void setActiveSpectrum(WorkspaceIndex spectrum); - - void setFittingData(std::vector *fittingData); - void setFitOutput(IFitOutput *fitOutput); - void setFitFunction(Mantid::API::MultiDomainFunction_sptr function); + Mantid::API::MatrixWorkspace_sptr getWorkspace() const override; + Mantid::API::MatrixWorkspace_sptr getResultWorkspace() const override; + Mantid::API::MatrixWorkspace_sptr getGuessWorkspace() const override; + MantidWidgets::FunctionModelSpectra getSpectra(WorkspaceID workspaceID) const override; + + WorkspaceID getActiveWorkspaceID() const override; + WorkspaceIndex getActiveWorkspaceIndex() const override; + FitDomainIndex getActiveDomainIndex() const override; + WorkspaceID numberOfWorkspaces() const override; + std::pair getRange() const override; + std::pair getWorkspaceRange() const override; + std::pair getResultRange() const override; + boost::optional getFirstHWHM() const override; + boost::optional getFirstPeakCentre() const override; + boost::optional getFirstBackgroundLevel() const override; + double calculateHWHMMaximum(double minimum) const override; + double calculateHWHMMinimum(double maximum) const override; + bool canCalculateGuess() const override; + + void setActiveIndex(WorkspaceID workspaceID) override; + void setActiveSpectrum(WorkspaceIndex spectrum) override; + + void setFittingData(std::vector *fittingData) override; + void setFitOutput(IFitOutput *fitOutput) override; + void setFitFunction(Mantid::API::MultiDomainFunction_sptr function) override; private: std::pair getGuessRange() const; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp index fee6f005ae42..e8b4d46d2c26 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp @@ -6,6 +6,7 @@ // SPDX - License - Identifier: GPL - 3.0 + #include "FitPlotPresenter.h" #include "Common/SettingsHelper.h" +#include "FitPlotModel.h" #include "FitPlotView.h" #include "FitTab.h" @@ -27,8 +28,8 @@ struct HoldRedrawing { using namespace Mantid::API; -FitPlotPresenter::FitPlotPresenter(IFitTab *tab, IFitPlotView *view, std::unique_ptr model) - : m_tab(tab), m_view(view), m_model(std::move(model)), m_plotter(std::make_unique()) { +FitPlotPresenter::FitPlotPresenter(IFitTab *tab, IFitPlotView *view, IFitPlotModel *model) + : m_tab(tab), m_view(view), m_model(model), m_plotter(std::make_unique()) { m_view->subscribePresenter(this); } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.h index 3435d9518ee9..0a455236408f 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.h @@ -6,16 +6,26 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once -#include "FitPlotModel.h" - #include "DllConfig.h" +#include "FitData.h" +#include "MantidAPI/IFunction_fwd.h" +#include "MantidAPI/MatrixWorkspace_fwd.h" +#include "MantidQtWidgets/Common/IndexTypes.h" #include "MantidQtWidgets/Plotting/ExternalPlotter.h" +#include +#include +#include + namespace MantidQt { namespace CustomInterfaces { namespace Inelastic { +using namespace MantidQt::MantidWidgets; + +class IFitOutput; class IFitTab; +class IFitPlotModel; class IFitPlotView; class MANTIDQT_INELASTIC_DLL IFitPlotPresenter { @@ -39,7 +49,7 @@ class MANTIDQT_INELASTIC_DLL IFitPlotPresenter { class MANTIDQT_INELASTIC_DLL FitPlotPresenter final : public IFitPlotPresenter { public: - FitPlotPresenter(IFitTab *tab, IFitPlotView *view, std::unique_ptr model); + FitPlotPresenter(IFitTab *tab, IFitPlotView *view, IFitPlotModel *model); void watchADS(bool watch); @@ -106,7 +116,7 @@ class MANTIDQT_INELASTIC_DLL FitPlotPresenter final : public IFitPlotPresenter { IFitTab *m_tab; IFitPlotView *m_view; - std::unique_ptr m_model; + IFitPlotModel *m_model; std::unique_ptr m_plotter; }; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp index 948813ec9246..dac8c0694fc5 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp @@ -40,8 +40,8 @@ void FitTab::setupOutputOptionsPresenter(bool const editResults) { } void FitTab::setupPlotView(std::optional> const &xPlotBounds) { - auto model = std::make_unique(); - m_plotPresenter = std::make_unique(this, m_uiForm->dockArea->m_fitPlotView, std::move(model)); + m_plotPresenter = std::make_unique(this, m_uiForm->dockArea->m_fitPlotView, + m_fittingPresenter->getFitPlotModel()); m_plotPresenter->setFittingData(m_dataPresenter->getFittingData()); m_plotPresenter->setFitOutput(m_fittingPresenter->getFitOutput()); if (xPlotBounds) { diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp index 7fc2ebc0ab28..ef42f688a19e 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp @@ -308,8 +308,9 @@ std::unordered_map fitModeToName = std::unordered_map< {{FittingMode::SEQUENTIAL, "Seq"}, {FittingMode::SIMULTANEOUS, "Sim"}}); FittingModel::FittingModel() - : m_fitDataModel(std::make_unique()), m_previousModelSelected(false), - m_fittingMode(FittingMode::SEQUENTIAL), m_fitOutput(std::make_unique()) {} + : m_fitDataModel(std::make_unique()), m_fitPlotModel(std::make_unique()), + m_previousModelSelected(false), m_fittingMode(FittingMode::SEQUENTIAL), + m_fitOutput(std::make_unique()) {} void FittingModel::validate(UserInputValidator &validator) const { if (auto const invalidFunction = isInvalidFunction()) @@ -620,4 +621,6 @@ void FittingModel::cleanFailedSingleRun(const IAlgorithm_sptr &fittingAlgorithm, IFitDataModel *FittingModel::getFitDataModel() const { return m_fitDataModel.get(); } +IFitPlotModel *FittingModel::getFitPlotModel() const { return m_fitPlotModel.get(); } + } // namespace MantidQt::CustomInterfaces::Inelastic diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h index c7982122e36e..966e5f37df58 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h @@ -6,6 +6,7 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once +#include "FitPlotModel.h" #include "IFitDataModel.h" #include "IFitOutput.h" #include "IFittingModel.h" @@ -96,6 +97,7 @@ class MANTIDQT_INELASTIC_DLL FittingModel : public IFittingModel { void removeDefaultParameters() override; IFitDataModel *getFitDataModel() const override; + IFitPlotModel *getFitPlotModel() const override; // Used for testing purposes [[nodiscard]] inline std::string getFitString() const noexcept { return m_fitString; } @@ -110,6 +112,7 @@ class MANTIDQT_INELASTIC_DLL FittingModel : public IFittingModel { std::string m_fitString = "FitString"; std::unique_ptr m_fitDataModel; + std::unique_ptr m_fitPlotModel; private: void removeWorkspaceFromFittingData(WorkspaceID const &workspaceIndex); diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp index 6be06d2cb408..63b946de02e0 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp @@ -142,6 +142,8 @@ std::string FittingPresenter::getOutputBasename() const { return m_model->getOut IFitDataModel *FittingPresenter::getFitDataModel() const { return m_model->getFitDataModel(); } +IFitPlotModel *FittingPresenter::getFitPlotModel() const { return m_model->getFitPlotModel(); } + bool FittingPresenter::isPreviouslyFit(WorkspaceID workspaceID, WorkspaceIndex spectrum) const { return m_model->isPreviouslyFit(workspaceID, spectrum); } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h index 055c9d955f14..e0af1b573d5c 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h @@ -29,6 +29,7 @@ namespace CustomInterfaces { namespace Inelastic { class IFitDataModel; +class IFitPlotModel; class IFitOutput; class IFitTab; class InelasticFitPropertyBrowser; @@ -90,6 +91,7 @@ class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter, std::string getOutputBasename() const; IFitDataModel *getFitDataModel() const; + IFitPlotModel *getFitPlotModel() const; bool isPreviouslyFit(WorkspaceID workspaceID, WorkspaceIndex spectrum) const; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h index 2ad2ee2a6f63..429abe6d7e1e 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h @@ -16,6 +16,9 @@ namespace CustomInterfaces { namespace Inelastic { using namespace MantidWidgets; +class IFitDataModel; +class IFitPlotModel; + extern std::unordered_map fitModeToName; /* IFitData - Specifies an interface for updating, querying and @@ -73,6 +76,7 @@ class MANTIDQT_INELASTIC_DLL IFittingModel { virtual void addDefaultParameters() = 0; virtual void removeDefaultParameters() = 0; virtual IFitDataModel *getFitDataModel() const = 0; + virtual IFitPlotModel *getFitPlotModel() const = 0; }; } // namespace Inelastic From bfb19918f5b8b3518819b1f3aa4b0dfe9ede6374 Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 2 May 2024 16:17:58 +0100 Subject: [PATCH 34/58] Combine addOutput methods into one method --- .../Inelastic/QENSFitting/FitOutput.cpp | 36 ++++++------------- .../Inelastic/QENSFitting/FitOutput.h | 6 +--- .../Inelastic/QENSFitting/FittingModel.cpp | 19 ++++------ .../Inelastic/QENSFitting/FittingModel.h | 2 -- .../QENSFitting/FittingPresenter.cpp | 18 ---------- .../Inelastic/QENSFitting/FittingPresenter.h | 6 ---- .../Inelastic/QENSFitting/IFitOutput.h | 7 +--- .../Inelastic/QENSFitting/IFittingModel.h | 2 -- 8 files changed, 18 insertions(+), 78 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitOutput.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitOutput.cpp index 5c5e3d9b53da..633b93f6253c 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitOutput.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitOutput.cpp @@ -60,17 +60,6 @@ std::vector getAxisLabels(const Mantid::API::MatrixWorkspace_sptr & return getAxisLabels(axis); return std::vector(); } - -std::unordered_map> -extractParametersFromTable(Mantid::API::ITableWorkspace_sptr tableWs) { - auto rowCount = tableWs->rowCount(); - TableRowExtractor extractRowFromTable(std::move(tableWs)); - std::unordered_map> parameterMap; - for (size_t rowIndex = 0; rowIndex < rowCount; ++rowIndex) { - parameterMap.emplace(rowIndex, extractRowFromTable(rowIndex)); - } - return parameterMap; -} } // namespace namespace MantidQt::CustomInterfaces::Inelastic { @@ -118,25 +107,20 @@ void FitOutput::clear() { void FitOutput::addOutput(const Mantid::API::WorkspaceGroup_sptr &resultGroup, Mantid::API::ITableWorkspace_sptr parameterTable, - const Mantid::API::WorkspaceGroup_sptr &resultWorkspace) { - m_parameters = extractParametersFromTable(parameterTable); + const Mantid::API::WorkspaceGroup_sptr &resultWorkspace, FitDomainIndex fitDomainIndex) { + TableRowExtractor extractRowFromTable(std::move(parameterTable)); m_resultGroup = resultGroup; m_resultWorkspace = resultWorkspace; - m_outputResultLocations.clear(); - for (size_t index = 0; index < resultGroup->size(); index++) { - m_outputResultLocations.emplace(index, ResultLocationNew(resultGroup, WorkspaceID{static_cast(index)})); + if (resultGroup->size() == 1u) { + m_parameters.insert_or_assign(fitDomainIndex.value, extractRowFromTable(0)); + m_outputResultLocations.insert_or_assign(fitDomainIndex.value, ResultLocationNew(resultGroup, WorkspaceID{0})); + return; } -} -void FitOutput::addSingleOutput(const Mantid::API::WorkspaceGroup_sptr &resultGroup, - Mantid::API::ITableWorkspace_sptr parameterTable, - const Mantid::API::WorkspaceGroup_sptr &resultWorkspace, - FitDomainIndex fitDomainIndex) { - TableRowExtractor extractRowFromTable(std::move(parameterTable)); - m_parameters.insert_or_assign(fitDomainIndex.value, extractRowFromTable(0)); - m_outputResultLocations.insert_or_assign(fitDomainIndex.value, ResultLocationNew(resultGroup, WorkspaceID{0})); - m_resultWorkspace = resultWorkspace; - m_resultGroup = resultGroup; + for (size_t index = 0; index < resultGroup->size(); index++) { + m_parameters.insert_or_assign(index, extractRowFromTable(index)); + m_outputResultLocations.insert_or_assign(index, ResultLocationNew(resultGroup, WorkspaceID{index})); + } } } // namespace MantidQt::CustomInterfaces::Inelastic diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitOutput.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitOutput.h index afc6b7ce000c..39971932bcd7 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitOutput.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitOutput.h @@ -38,11 +38,7 @@ class MANTIDQT_INELASTIC_DLL FitOutput : public IFitOutput { void clear() override; bool isEmpty() const override; void addOutput(const Mantid::API::WorkspaceGroup_sptr &resultGroup, Mantid::API::ITableWorkspace_sptr parameterTable, - const Mantid::API::WorkspaceGroup_sptr &resultWorkspace) override; - - void addSingleOutput(const Mantid::API::WorkspaceGroup_sptr &resultGroup, - Mantid::API::ITableWorkspace_sptr parameterTable, - const Mantid::API::WorkspaceGroup_sptr &resultWorkspace, FitDomainIndex fitDomainIndex) override; + const Mantid::API::WorkspaceGroup_sptr &resultWorkspace, FitDomainIndex fitDomainIndex) override; private: std::weak_ptr m_resultGroup; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp index ef42f688a19e..681cd45a1a97 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp @@ -431,19 +431,12 @@ void FittingModel::addOutput(IAlgorithm_sptr fitAlgorithm) { auto group = getOutputGroup(fitAlgorithm); auto parameters = getOutputParameters(fitAlgorithm); auto result = getOutputResult(fitAlgorithm); - m_fitFunction = extractFirstInnerFunction(fitAlgorithm->getPropertyValue("Function")); - m_fitOutput->addOutput(group, parameters, result); - m_previousModelSelected = isPreviousModelSelected(); -} - -void FittingModel::addSingleFitOutput(const IAlgorithm_sptr &fitAlgorithm, WorkspaceID workspaceID, - WorkspaceIndex spectrum) { - auto group = getOutputGroup(fitAlgorithm); - auto parameters = getOutputParameters(fitAlgorithm); - auto result = getOutputResult(fitAlgorithm); - m_fitFunction = FunctionFactory::Instance().createInitialized(fitAlgorithm->getPropertyValue("Function")); - auto fitDomainIndex = m_fitDataModel->getDomainIndex(workspaceID, spectrum); - m_fitOutput->addSingleOutput(group, parameters, result, fitDomainIndex); + if (group->size() == 1u) { + m_fitFunction = FunctionFactory::Instance().createInitialized(fitAlgorithm->getPropertyValue("Function")); + } else { + m_fitFunction = extractFirstInnerFunction(fitAlgorithm->getPropertyValue("Function")); + } + m_fitOutput->addOutput(group, parameters, result, m_fitPlotModel->getActiveDomainIndex()); m_previousModelSelected = isPreviousModelSelected(); } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h index 966e5f37df58..7619746fdbea 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h @@ -72,8 +72,6 @@ class MANTIDQT_INELASTIC_DLL FittingModel : public IFittingModel { std::unordered_map getDefaultParameters(WorkspaceID workspaceID) const override; // IFitOutput - void addSingleFitOutput(const Mantid::API::IAlgorithm_sptr &fitAlgorithm, WorkspaceID workspaceID, - WorkspaceIndex spectrum) override; virtual void addOutput(Mantid::API::IAlgorithm_sptr fitAlgorithm) override; IFitOutput *getFitOutput() const override; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp index 63b946de02e0..4825b427103a 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp @@ -98,30 +98,12 @@ void FittingPresenter::updateFunctionListInBrowser(const std::mapupdateFunctionListInBrowser(functionStrings); } -void FittingPresenter::cleanFailedRun(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm) { - m_model->cleanFailedRun(fittingAlgorithm); -} - -void FittingPresenter::cleanFailedSingleRun(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, - WorkspaceID workspaceID) { - m_model->cleanFailedSingleRun(fittingAlgorithm, workspaceID); -} - void FittingPresenter::removeFittingData() { m_model->removeFittingData(); } void FittingPresenter::addDefaultParameters() { m_model->addDefaultParameters(); } void FittingPresenter::removeDefaultParameters() { m_model->removeDefaultParameters(); } -void FittingPresenter::addOutput(Mantid::API::IAlgorithm_sptr &fittingAlgorithm) { - m_model->addOutput(fittingAlgorithm); -} - -void FittingPresenter::addSingleFitOutput(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, WorkspaceID workspaceID, - WorkspaceIndex spectrum) { - m_model->addSingleFitOutput(fittingAlgorithm, workspaceID, spectrum); -} - std::unique_ptr FittingPresenter::fitProperties() const { return m_fitPropertyBrowser->fitProperties(m_model->getFittingMode()); } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h index e0af1b573d5c..fd40bf20b587 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h @@ -72,16 +72,10 @@ class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter, const std::vector> &fitResolutions); void updateFunctionListInBrowser(const std::map &functionStrings); - void cleanFailedRun(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm); - void cleanFailedSingleRun(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, WorkspaceID workspaceID); void removeFittingData(); void addDefaultParameters(); void removeDefaultParameters(); - void addOutput(Mantid::API::IAlgorithm_sptr &fittingAlgorithm); - void addSingleFitOutput(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, WorkspaceID workspaceID, - WorkspaceIndex spectrum); - std::unique_ptr fitProperties() const; Mantid::API::WorkspaceGroup_sptr getResultWorkspace() const; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/IFitOutput.h b/qt/scientific_interfaces/Inelastic/QENSFitting/IFitOutput.h index 9296e8e04bbf..cf0394e667d6 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/IFitOutput.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/IFitOutput.h @@ -55,12 +55,7 @@ class MANTIDQT_INELASTIC_DLL IFitOutput { virtual void addOutput(const Mantid::API::WorkspaceGroup_sptr &resultGroup, Mantid::API::ITableWorkspace_sptr parameterTable, - const Mantid::API::WorkspaceGroup_sptr &resultWorkspace) = 0; - - virtual void addSingleOutput(const Mantid::API::WorkspaceGroup_sptr &resultGroup, - Mantid::API::ITableWorkspace_sptr parameterTable, - const Mantid::API::WorkspaceGroup_sptr &resultWorkspace, - FitDomainIndex fitDomainIndex) = 0; + const Mantid::API::WorkspaceGroup_sptr &resultWorkspace, FitDomainIndex fitDomainIndex) = 0; }; } // namespace Inelastic diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h index 429abe6d7e1e..c23aafb83049 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h @@ -51,8 +51,6 @@ class MANTIDQT_INELASTIC_DLL IFittingModel { virtual bool isMultiFit() const = 0; // IFitOutput - virtual void addSingleFitOutput(const Mantid::API::IAlgorithm_sptr &fitAlgorithm, WorkspaceID workspaceID, - WorkspaceIndex spectrum) = 0; virtual void addOutput(Mantid::API::IAlgorithm_sptr fitAlgorithm) = 0; virtual IFitOutput *getFitOutput() const = 0; From 9c7e22dabe924399da6b5f4c5ee660daf735fed5 Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 2 May 2024 16:29:46 +0100 Subject: [PATCH 35/58] Combine cleanFailedRun methods --- .../Inelastic/QENSFitting/FittingModel.cpp | 15 +++++++++------ .../Inelastic/QENSFitting/FittingModel.h | 1 - .../Inelastic/QENSFitting/IFittingModel.h | 1 - 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp index 681cd45a1a97..cc80e9b31f32 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp @@ -597,6 +597,15 @@ std::string FittingModel::getOutputBasename() const { return cutLastOf(sequentia void FittingModel::cleanFailedRun(const IAlgorithm_sptr &fittingAlgorithm) { const auto prefix = "__" + fittingAlgorithm->name() + "_ws"; + + auto group = getOutputGroup(fittingAlgorithm); + if (group->size() == 1u) { + const auto base = prefix + std::to_string(m_fitPlotModel->getActiveWorkspaceID().value + 1); + removeFromADSIfExists(base); + cleanTemporaries(base + "_0"); + return; + } + for (WorkspaceID datasetIndex = 0; datasetIndex < m_fitDataModel->getNumberOfWorkspaces(); ++datasetIndex) { const auto base = prefix + std::to_string(datasetIndex.value + 1); removeFromADSIfExists(base); @@ -606,12 +615,6 @@ void FittingModel::cleanFailedRun(const IAlgorithm_sptr &fittingAlgorithm) { } } -void FittingModel::cleanFailedSingleRun(const IAlgorithm_sptr &fittingAlgorithm, WorkspaceID workspaceID) { - const auto base = "__" + fittingAlgorithm->name() + "_ws" + std::to_string(workspaceID.value + 1); - removeFromADSIfExists(base); - cleanTemporaries(base + "_0"); -} - IFitDataModel *FittingModel::getFitDataModel() const { return m_fitDataModel.get(); } IFitPlotModel *FittingModel::getFitPlotModel() const { return m_fitPlotModel.get(); } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h index 7619746fdbea..e704f1363daa 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h @@ -89,7 +89,6 @@ class MANTIDQT_INELASTIC_DLL FittingModel : public IFittingModel { std::string getOutputBasename() const override; void cleanFailedRun(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm) override; - void cleanFailedSingleRun(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, WorkspaceID workspaceID) override; void removeFittingData() override; void addDefaultParameters() override; void removeDefaultParameters() override; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h index c23aafb83049..e394226558d7 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h @@ -69,7 +69,6 @@ class MANTIDQT_INELASTIC_DLL IFittingModel { virtual std::string getOutputBasename() const = 0; virtual void cleanFailedRun(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm) = 0; - virtual void cleanFailedSingleRun(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm, WorkspaceID workspaceID) = 0; virtual void removeFittingData() = 0; virtual void addDefaultParameters() = 0; virtual void removeDefaultParameters() = 0; From 4503ed0844c23833a59caed79fb5b6feb7e09b7e Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 2 May 2024 16:31:18 +0100 Subject: [PATCH 36/58] Remove unused updateSingleFitOutput function --- .../Inelastic/QENSFitting/FitTab.cpp | 12 ------------ .../Inelastic/QENSFitting/FittingPresenter.cpp | 10 ---------- .../Inelastic/QENSFitting/FittingPresenter.h | 2 -- 3 files changed, 24 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp index dac8c0694fc5..85af6bdf4b90 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp @@ -90,18 +90,6 @@ void FitTab::handleEndXChanged(double endX) { m_dataPresenter->updateTableFromModel(); } -// void FitTab::updateSingleFitOutput(bool error) { -// disconnect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(updateSingleFitOutput(bool))); - -// if (error) { -// m_fittingPresenter->cleanFailedSingleRun(m_fittingAlgorithm, m_plotPresenter->getActiveWorkspaceID()); -// m_fittingAlgorithm.reset(); -//} else { -// m_fittingPresenter->addSingleFitOutput(m_fittingAlgorithm, m_plotPresenter->getActiveWorkspaceID(), -// m_plotPresenter->getActiveWorkspaceIndex()); -//} -//} - /** * Plots the spectra corresponding to the selected parameters */ diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp index 4825b427103a..c8a728632cfc 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp @@ -27,7 +27,6 @@ void FittingPresenter::validate(UserInputValidator &validator) { m_model->valida void FittingPresenter::runFit() { m_model->setFittingMode(m_fitPropertyBrowser->getFittingMode()); auto alg = m_model->getFittingAlgorithm(m_model->getFittingMode()); - // connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(updateFitOutput(bool))); auto properties = m_fitPropertyBrowser->fitProperties(m_model->getFittingMode()); MantidQt::API::IConfiguredAlgorithm_sptr confAlg = std::make_shared(alg, std::move(properties)); @@ -37,7 +36,6 @@ void FittingPresenter::runFit() { void FittingPresenter::runSingleFit(WorkspaceID workspaceID, WorkspaceIndex spectrum) { m_model->setFittingMode(FittingMode::SIMULTANEOUS); auto alg = m_model->getSingleFit(workspaceID, spectrum); - // connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(updateSingleFitOutput(bool))); auto properties = m_fitPropertyBrowser->fitProperties(m_model->getFittingMode()); MantidQt::API::IConfiguredAlgorithm_sptr confAlg = std::make_shared(alg, std::move(properties)); @@ -112,14 +110,6 @@ Mantid::API::WorkspaceGroup_sptr FittingPresenter::getResultWorkspace() const { IFitOutput *FittingPresenter::getFitOutput() const { return m_model->getFitOutput(); } -Mantid::API::IAlgorithm_sptr FittingPresenter::getFittingAlgorithm(FittingMode mode) const { - return m_model->getFittingAlgorithm(mode); -} - -Mantid::API::IAlgorithm_sptr FittingPresenter::getSingleFit(WorkspaceID workspaceID, WorkspaceIndex spectrum) const { - return m_model->getSingleFit(workspaceID, spectrum); -} - std::string FittingPresenter::getOutputBasename() const { return m_model->getOutputBasename(); } IFitDataModel *FittingPresenter::getFitDataModel() const { return m_model->getFitDataModel(); } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h index fd40bf20b587..599fcfff428e 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h @@ -80,8 +80,6 @@ class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter, Mantid::API::WorkspaceGroup_sptr getResultWorkspace() const; IFitOutput *getFitOutput() const; - Mantid::API::IAlgorithm_sptr getFittingAlgorithm(FittingMode mode) const; - Mantid::API::IAlgorithm_sptr getSingleFit(WorkspaceID workspaceID, WorkspaceIndex spectrum) const; std::string getOutputBasename() const; IFitDataModel *getFitDataModel() const; From 934b396d36e444b995f6af87d26081377ddaf787 Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 2 May 2024 16:44:08 +0100 Subject: [PATCH 37/58] Tidy up changes for running single fits --- .../QENSFitting/FitPlotPresenter.cpp | 4 +- .../Inelastic/QENSFitting/FitTab.cpp | 4 +- .../Inelastic/QENSFitting/FitTab.h | 4 +- .../Inelastic/QENSFitting/FittingModel.cpp | 4 +- .../Inelastic/QENSFitting/FittingModel.h | 2 +- .../QENSFitting/FittingPresenter.cpp | 65 ++++++++----------- .../Inelastic/QENSFitting/FittingPresenter.h | 13 ++-- .../Inelastic/QENSFitting/IFittingModel.h | 2 +- 8 files changed, 42 insertions(+), 56 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp index e8b4d46d2c26..3586f3cf35fc 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp @@ -289,9 +289,7 @@ void FitPlotPresenter::plotSpectrum(WorkspaceIndex spectrum) const { m_plotter->plotSpectra(m_model->getWorkspace()->getName(), std::to_string(spectrum.value), errorBars); } -void FitPlotPresenter::handleFitSingleSpectrum() { - m_tab->handleSingleFitClicked(m_model->getActiveWorkspaceID(), m_model->getActiveWorkspaceIndex()); -} +void FitPlotPresenter::handleFitSingleSpectrum() { m_tab->handleSingleFitClicked(); } void FitPlotPresenter::handleFWHMChanged(double minimum, double maximum) { m_tab->handleFwhmChanged(maximum - minimum); diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp index 85af6bdf4b90..758b9f0fa8ed 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp @@ -102,12 +102,12 @@ void FitTab::handlePlotSelectedSpectra() { m_outOptionsPresenter->setPlotting(false); } -void FitTab::handleSingleFitClicked(WorkspaceID workspaceID, WorkspaceIndex spectrum) { +void FitTab::handleSingleFitClicked() { if (validate()) { m_plotPresenter->setFitSingleSpectrumIsFitting(true); enableFitButtons(false); enableOutputOptions(false); - m_fittingPresenter->runSingleFit(workspaceID, spectrum); + m_fittingPresenter->runSingleFit(); } } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h index d61f60c5bfed..7594953712fd 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h @@ -39,7 +39,7 @@ class MANTIDQT_INELASTIC_DLL IFitTab { virtual void handleFunctionListChanged(const std::map &functionStrings) = 0; // Used by FitPlotPresenter - virtual void handleSingleFitClicked(WorkspaceID workspaceID, WorkspaceIndex workspaceIndex) = 0; + virtual void handleSingleFitClicked() = 0; virtual void handleStartXChanged(double startX) = 0; virtual void handleEndXChanged(double endX) = 0; virtual void handlePlotSpectrumChanged() = 0; @@ -104,7 +104,7 @@ class MANTIDQT_INELASTIC_DLL FitTab : public InelasticTab, public IFitTab { void handleTableEndXChanged(double endX, WorkspaceID workspaceID, WorkspaceIndex workspaceIndex) override; void handleFunctionListChanged(const std::map &functionStrings) override; - void handleSingleFitClicked(WorkspaceID workspaceID, WorkspaceIndex workspaceIndex) override; + void handleSingleFitClicked() override; void handlePlotSpectrumChanged() override; void handleFwhmChanged(double fwhm) override; void handleBackgroundChanged(double background) override; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp index cc80e9b31f32..c9d454675099 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp @@ -511,7 +511,9 @@ IAlgorithm_sptr FittingModel::getFittingAlgorithm(FittingMode mode) const { return createSimultaneousFit(getFitFunction()); } -IAlgorithm_sptr FittingModel::getSingleFit(WorkspaceID workspaceID, WorkspaceIndex spectrum) const { +IAlgorithm_sptr FittingModel::getSingleFittingAlgorithm() const { + const auto workspaceID = m_fitPlotModel->getActiveWorkspaceID(); + const auto spectrum = m_fitPlotModel->getActiveWorkspaceIndex(); const auto ws = m_fitDataModel->getWorkspace(workspaceID); const auto range = m_fitDataModel->getFittingRange(workspaceID, spectrum); const auto exclude = m_fitDataModel->getExcludeRegionVector(workspaceID, spectrum); diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h index e704f1363daa..4d6a2a98989d 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h @@ -84,7 +84,7 @@ class MANTIDQT_INELASTIC_DLL FittingModel : public IFittingModel { Mantid::API::WorkspaceGroup_sptr getResultWorkspace() const override; Mantid::API::WorkspaceGroup_sptr getResultGroup() const override; Mantid::API::IAlgorithm_sptr getFittingAlgorithm(FittingMode mode) const override; - Mantid::API::IAlgorithm_sptr getSingleFit(WorkspaceID workspaceID, WorkspaceIndex spectrum) const override; + Mantid::API::IAlgorithm_sptr getSingleFittingAlgorithm() const override; Mantid::API::IFunction_sptr getSingleFunction(WorkspaceID workspaceID, WorkspaceIndex spectrum) const override; std::string getOutputBasename() const override; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp index c8a728632cfc..86028f3f0b32 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp @@ -24,46 +24,10 @@ void FittingPresenter::notifyFunctionChanged() { m_tab->handleFunctionChanged(); void FittingPresenter::validate(UserInputValidator &validator) { m_model->validate(validator); } -void FittingPresenter::runFit() { - m_model->setFittingMode(m_fitPropertyBrowser->getFittingMode()); - auto alg = m_model->getFittingAlgorithm(m_model->getFittingMode()); - auto properties = m_fitPropertyBrowser->fitProperties(m_model->getFittingMode()); - MantidQt::API::IConfiguredAlgorithm_sptr confAlg = - std::make_shared(alg, std::move(properties)); - m_algorithmRunner->execute(confAlg); -} - -void FittingPresenter::runSingleFit(WorkspaceID workspaceID, WorkspaceIndex spectrum) { - m_model->setFittingMode(FittingMode::SIMULTANEOUS); - auto alg = m_model->getSingleFit(workspaceID, spectrum); - auto properties = m_fitPropertyBrowser->fitProperties(m_model->getFittingMode()); - MantidQt::API::IConfiguredAlgorithm_sptr confAlg = - std::make_shared(alg, std::move(properties)); - m_algorithmRunner->execute(confAlg); -} - -void FittingPresenter::notifyBatchComplete(MantidQt::API::IConfiguredAlgorithm_sptr &lastAlgorithm, bool error) { - m_fitPropertyBrowser->setErrorsEnabled(!error); - if (!error) { - updateFitBrowserParameterValuesFromAlg(lastAlgorithm->algorithm()); - m_model->setFitFunction(m_fitPropertyBrowser->getFitFunction()); - m_model->addOutput(lastAlgorithm->algorithm()); - } else { - m_model->cleanFailedRun(lastAlgorithm->algorithm()); - } - m_tab->handleFitComplete(error); -} - void FittingPresenter::setFitFunction(Mantid::API::MultiDomainFunction_sptr function) { m_model->setFitFunction(std::move(function)); } -void FittingPresenter::setFittingMode(FittingMode mode) { m_model->setFittingMode(mode); } - -FittingMode FittingPresenter::getFittingMode() const { return m_model->getFittingMode(); } - -void FittingPresenter::setErrorsEnabled(bool const enable) { m_fitPropertyBrowser->setErrorsEnabled(enable); } - void FittingPresenter::setFitEnabled(bool const enable) { m_fitPropertyBrowser->setFitEnabled(enable); } void FittingPresenter::setCurrentDataset(FitDomainIndex index) { m_fitPropertyBrowser->setCurrentDataset(index); } @@ -102,8 +66,26 @@ void FittingPresenter::addDefaultParameters() { m_model->addDefaultParameters(); void FittingPresenter::removeDefaultParameters() { m_model->removeDefaultParameters(); } -std::unique_ptr FittingPresenter::fitProperties() const { - return m_fitPropertyBrowser->fitProperties(m_model->getFittingMode()); +void FittingPresenter::runFit() { + m_model->setFittingMode(m_fitPropertyBrowser->getFittingMode()); + executeFit(m_model->getFittingAlgorithm(m_model->getFittingMode())); +} + +void FittingPresenter::runSingleFit() { + m_model->setFittingMode(FittingMode::SIMULTANEOUS); + executeFit(m_model->getSingleFittingAlgorithm()); +} + +void FittingPresenter::notifyBatchComplete(MantidQt::API::IConfiguredAlgorithm_sptr &lastAlgorithm, bool error) { + m_fitPropertyBrowser->setErrorsEnabled(!error); + if (!error) { + updateFitBrowserParameterValuesFromAlg(lastAlgorithm->algorithm()); + m_model->setFitFunction(m_fitPropertyBrowser->getFitFunction()); + m_model->addOutput(lastAlgorithm->algorithm()); + } else { + m_model->cleanFailedRun(lastAlgorithm->algorithm()); + } + m_tab->handleFitComplete(error); } Mantid::API::WorkspaceGroup_sptr FittingPresenter::getResultWorkspace() const { return m_model->getResultWorkspace(); } @@ -127,6 +109,13 @@ void FittingPresenter::setBackground(WorkspaceID WorkspaceID, double background) m_fitPropertyBrowser->setBackgroundA0(background); } +void FittingPresenter::executeFit(Mantid::API::IAlgorithm_sptr fitAlgorithm) { + auto properties = m_fitPropertyBrowser->fitProperties(m_model->getFittingMode()); + MantidQt::API::IConfiguredAlgorithm_sptr confAlg = + std::make_shared(fitAlgorithm, std::move(properties)); + m_algorithmRunner->execute(confAlg); +} + void FittingPresenter::updateFitBrowserParameterValues(const std::unordered_map ¶ms) { auto fun = m_model->getFitFunction(); if (fun) { diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h index 599fcfff428e..0fe69997e9d7 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h @@ -46,18 +46,11 @@ class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter, std::unique_ptr algorithmRunner); void notifyFunctionChanged() override; - void notifyBatchComplete(MantidQt::API::IConfiguredAlgorithm_sptr &lastAlgorithm, bool error) override; void validate(UserInputValidator &validator); - void runFit(); - void runSingleFit(WorkspaceID workspaceID, WorkspaceIndex spectrum); void setFitFunction(Mantid::API::MultiDomainFunction_sptr function); - void setFittingMode(FittingMode mode); - FittingMode getFittingMode() const; - - void setErrorsEnabled(bool const enable); void setFitEnabled(bool const enable); void setCurrentDataset(FitDomainIndex index); Mantid::API::MultiDomainFunction_sptr fitFunction() const; @@ -76,7 +69,9 @@ class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter, void addDefaultParameters(); void removeDefaultParameters(); - std::unique_ptr fitProperties() const; + void runFit(); + void runSingleFit(); + void notifyBatchComplete(MantidQt::API::IConfiguredAlgorithm_sptr &lastAlgorithm, bool error) override; Mantid::API::WorkspaceGroup_sptr getResultWorkspace() const; IFitOutput *getFitOutput() const; @@ -96,6 +91,8 @@ class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter, void updateFitTypeString(); private: + void executeFit(Mantid::API::IAlgorithm_sptr fitAlgorithm); + void updateFitStatus(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm); IFitTab *m_tab; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h index e394226558d7..d0a906997461 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h @@ -64,7 +64,7 @@ class MANTIDQT_INELASTIC_DLL IFittingModel { virtual Mantid::API::WorkspaceGroup_sptr getResultWorkspace() const = 0; virtual Mantid::API::WorkspaceGroup_sptr getResultGroup() const = 0; virtual Mantid::API::IAlgorithm_sptr getFittingAlgorithm(FittingMode mode) const = 0; - virtual Mantid::API::IAlgorithm_sptr getSingleFit(WorkspaceID workspaceID, WorkspaceIndex spectrum) const = 0; + virtual Mantid::API::IAlgorithm_sptr getSingleFittingAlgorithm() const = 0; virtual Mantid::API::IFunction_sptr getSingleFunction(WorkspaceID workspaceID, WorkspaceIndex spectrum) const = 0; virtual std::string getOutputBasename() const = 0; From 8781a1ee8afcc93533802fb63b5f725281e63209 Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 2 May 2024 16:50:51 +0100 Subject: [PATCH 38/58] Move class methods to correct private or public sections --- qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h | 8 ++------ .../Inelastic/QENSFitting/FittingPresenter.h | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h index 7594953712fd..a28f9b80ef14 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.h @@ -21,8 +21,6 @@ #include #include -#include - namespace MantidQt { namespace CustomInterfaces { namespace Inelastic { @@ -105,6 +103,8 @@ class MANTIDQT_INELASTIC_DLL FitTab : public InelasticTab, public IFitTab { void handleFunctionListChanged(const std::map &functionStrings) override; void handleSingleFitClicked() override; + void handleStartXChanged(double startX) override; + void handleEndXChanged(double endX) override; void handlePlotSpectrumChanged() override; void handleFwhmChanged(double fwhm) override; void handleBackgroundChanged(double background) override; @@ -114,10 +114,6 @@ class MANTIDQT_INELASTIC_DLL FitTab : public InelasticTab, public IFitTab { void handleFunctionChanged() override; void handleFitComplete(bool const error) override; -public slots: - void handleStartXChanged(double startX) override; - void handleEndXChanged(double endX) override; - private: void setup() override; bool validate() override; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h index 0fe69997e9d7..24eb00de1aa3 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h @@ -87,12 +87,12 @@ class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter, void updateFitBrowserParameterValues(const std::unordered_map ¶ms = std::unordered_map()); - void updateFitBrowserParameterValuesFromAlg(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm); void updateFitTypeString(); private: void executeFit(Mantid::API::IAlgorithm_sptr fitAlgorithm); + void updateFitBrowserParameterValuesFromAlg(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm); void updateFitStatus(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm); IFitTab *m_tab; From 1c8f06087d73ddf18a8fb6b1b3c6e100ff664af9 Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 3 May 2024 10:05:40 +0100 Subject: [PATCH 39/58] Get Inelastic tests to build again --- .../Inelastic/QENSFitting/FitPlotModel.cpp | 30 +++++++------- .../Inelastic/QENSFitting/FitPlotModel.h | 14 +++---- .../QENSFitting/FitPlotPresenter.cpp | 2 +- .../test/QENSFitting/FitOutputTest.h | 10 ++--- .../test/QENSFitting/FitPlotModelTest.h | 16 ++++---- .../test/QENSFitting/FitPlotPresenterTest.h | 5 ++- .../test/QENSFitting/FittingModelTest.h | 10 ++--- .../test/QENSFitting/FqFitDataPresenterTest.h | 7 ---- .../Inelastic/test/QENSFitting/MockObjects.h | 41 ++++++++++++++++++- 9 files changed, 84 insertions(+), 51 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp index d2d1265cb21e..10eb91722d72 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp @@ -45,26 +45,26 @@ IFunction_sptr firstFunctionWithParameter(IFunction_sptr function, const std::st return nullptr; } -boost::optional firstParameterValue(const IFunction_sptr &function, const std::string &category, - const std::string ¶meterName) { +std::optional firstParameterValue(const IFunction_sptr &function, const std::string &category, + const std::string ¶meterName) { if (!function) - return boost::none; + return std::nullopt; const auto functionWithParameter = firstFunctionWithParameter(function, category, parameterName); if (functionWithParameter) return functionWithParameter->getParameter(parameterName); - return boost::none; + return std::nullopt; } -boost::optional findFirstPeakCentre(const IFunction_sptr &function) { +std::optional findFirstPeakCentre(const IFunction_sptr &function) { return firstParameterValue(function, "Peak", "PeakCentre"); } -boost::optional findFirstFWHM(const IFunction_sptr &function) { +std::optional findFirstFWHM(const IFunction_sptr &function) { return firstParameterValue(function, "Peak", "FWHM"); } -boost::optional findFirstBackgroundLevel(const IFunction_sptr &function) { +std::optional findFirstBackgroundLevel(const IFunction_sptr &function) { return firstParameterValue(function, "Background", "A0"); } @@ -163,33 +163,33 @@ FitDomainIndex FitPlotModel::getActiveDomainIndex() const { return index; } -boost::optional FitPlotModel::getFirstHWHM() const { +std::optional FitPlotModel::getFirstHWHM() const { auto fwhm = findFirstFWHM(m_activeFunction); if (fwhm) { return *fwhm / 2.0; } - return boost::none; + return std::nullopt; } -boost::optional FitPlotModel::getFirstPeakCentre() const { return findFirstPeakCentre(m_activeFunction); } +std::optional FitPlotModel::getFirstPeakCentre() const { return findFirstPeakCentre(m_activeFunction); } -boost::optional FitPlotModel::getFirstBackgroundLevel() const { +std::optional FitPlotModel::getFirstBackgroundLevel() const { auto const spectra = getSpectra(m_activeWorkspaceID); if (spectra.empty()) - return boost::optional(); + return std::optional(); auto index = spectra.indexOf(m_activeWorkspaceIndex); if (!m_activeFunction || m_activeFunction->nFunctions() == 0) - return boost::optional(); + return std::optional(); return findFirstBackgroundLevel(m_activeFunction->getFunction(index.value)); } double FitPlotModel::calculateHWHMMaximum(double minimum) const { - const auto peakCentre = getFirstPeakCentre().get_value_or(0.); + const auto peakCentre = getFirstPeakCentre().value_or(0.); return peakCentre + (peakCentre - minimum); } double FitPlotModel::calculateHWHMMinimum(double maximum) const { - const auto peakCentre = getFirstPeakCentre().get_value_or(0.); + const auto peakCentre = getFirstPeakCentre().value_or(0.); return peakCentre - (maximum - peakCentre); } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h index f8a556e5fcce..fdf6779839fb 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h @@ -15,8 +15,8 @@ #include "MantidQtWidgets/Common/FunctionModelSpectra.h" #include "MantidQtWidgets/Common/IndexTypes.h" -#include #include +#include namespace MantidQt { namespace CustomInterfaces { @@ -37,9 +37,9 @@ class MANTIDQT_INELASTIC_DLL IFitPlotModel { virtual std::pair getRange() const = 0; virtual std::pair getWorkspaceRange() const = 0; virtual std::pair getResultRange() const = 0; - virtual boost::optional getFirstHWHM() const = 0; - virtual boost::optional getFirstPeakCentre() const = 0; - virtual boost::optional getFirstBackgroundLevel() const = 0; + virtual std::optional getFirstHWHM() const = 0; + virtual std::optional getFirstPeakCentre() const = 0; + virtual std::optional getFirstBackgroundLevel() const = 0; virtual double calculateHWHMMaximum(double minimum) const = 0; virtual double calculateHWHMMinimum(double maximum) const = 0; virtual bool canCalculateGuess() const = 0; @@ -69,9 +69,9 @@ class MANTIDQT_INELASTIC_DLL FitPlotModel : public IFitPlotModel { std::pair getRange() const override; std::pair getWorkspaceRange() const override; std::pair getResultRange() const override; - boost::optional getFirstHWHM() const override; - boost::optional getFirstPeakCentre() const override; - boost::optional getFirstBackgroundLevel() const override; + std::optional getFirstHWHM() const override; + std::optional getFirstPeakCentre() const override; + std::optional getFirstBackgroundLevel() const override; double calculateHWHMMaximum(double minimum) const override; double calculateHWHMMinimum(double maximum) const override; bool canCalculateGuess() const override; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp index 3586f3cf35fc..7aee6bd2979c 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp @@ -267,7 +267,7 @@ void FitPlotPresenter::updateHWHMSelector() { } void FitPlotPresenter::setHWHM(double hwhm) { - const auto centre = m_model->getFirstPeakCentre().get_value_or(0.); + const auto centre = m_model->getFirstPeakCentre().value_or(0.); m_view->setHWHMMaximum(centre + hwhm); m_view->setHWHMMinimum(centre - hwhm); } diff --git a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitOutputTest.h b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitOutputTest.h index ad0b016271fb..12610220e1f5 100644 --- a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitOutputTest.h +++ b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitOutputTest.h @@ -87,7 +87,7 @@ class FitOutputTest : public CxxTest::TestSuite { auto group = getWorkspaceOutput(fitAlgorithm, "OutputWorkspaceGroup"); auto parameters = getWorkspaceOutput(fitAlgorithm, "OutputParameterWorkspace"); auto result = getWorkspaceOutput(fitAlgorithm, "OutputWorkspace"); - m_model->addOutput(group, parameters, result); + m_model->addOutput(group, parameters, result, FitDomainIndex{0}); TS_ASSERT(!m_model->isEmpty()); } @@ -101,7 +101,7 @@ class FitOutputTest : public CxxTest::TestSuite { auto group = getWorkspaceOutput(fitAlgorithm, "OutputWorkspaceGroup"); auto parameters = getWorkspaceOutput(fitAlgorithm, "OutputParameterWorkspace"); auto result = getWorkspaceOutput(fitAlgorithm, "OutputWorkspace"); - m_model->addOutput(group, parameters, result); + m_model->addOutput(group, parameters, result, FitDomainIndex{0}); TS_ASSERT(m_model->isSpectrumFit(FitDomainIndex{0})); } @@ -118,7 +118,7 @@ class FitOutputTest : public CxxTest::TestSuite { auto group = getWorkspaceOutput(fitAlgorithm, "OutputWorkspaceGroup"); auto parameters = getWorkspaceOutput(fitAlgorithm, "OutputParameterWorkspace"); auto result = getWorkspaceOutput(fitAlgorithm, "OutputWorkspace"); - m_model->addOutput(group, parameters, result); + m_model->addOutput(group, parameters, result, FitDomainIndex{0}); TS_ASSERT(!m_model->isSpectrumFit(FitDomainIndex{6})); } @@ -131,7 +131,7 @@ class FitOutputTest : public CxxTest::TestSuite { auto group = getWorkspaceOutput(fitAlgorithm, "OutputWorkspaceGroup"); auto parameters = getWorkspaceOutput(fitAlgorithm, "OutputParameterWorkspace"); auto result = getWorkspaceOutput(fitAlgorithm, "OutputWorkspace"); - m_model->addOutput(group, parameters, result); + m_model->addOutput(group, parameters, result, FitDomainIndex{0}); auto params = m_model->getParameters(FitDomainIndex{0}); TS_ASSERT_EQUALS(params["f0.A0"].value, 0.00); } @@ -150,7 +150,7 @@ class FitOutputTest : public CxxTest::TestSuite { auto group = getWorkspaceOutput(fitAlgorithm, "OutputWorkspaceGroup"); auto parameters = getWorkspaceOutput(fitAlgorithm, "OutputParameterWorkspace"); auto result = getWorkspaceOutput(fitAlgorithm, "OutputWorkspace"); - m_model->addOutput(group, parameters, result); + m_model->addOutput(group, parameters, result, FitDomainIndex{0}); auto const index = FitDomainIndex{0}; auto resultLocation = ResultLocationNew(result, WorkspaceID{static_cast(index.value)}); TS_ASSERT_EQUALS(m_model->getResultLocation(index)->index, resultLocation.index); diff --git a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotModelTest.h b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotModelTest.h index 0df3d424e939..0421bb35961f 100644 --- a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotModelTest.h +++ b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotModelTest.h @@ -115,7 +115,7 @@ class FitPlotModelTest : public CxxTest::TestSuite { auto group = getWorkspaceOutput(alg, "OutputWorkspaceGroup"); auto parameters = getWorkspaceOutput(alg, "OutputParameterWorkspace"); auto result = getWorkspaceOutput(alg, "OutputWorkspace"); - m_fitOutput->addOutput(group, parameters, result); + m_fitOutput->addOutput(group, parameters, result, FitDomainIndex{0}); m_activeFunction = getFunction(getFitFunctionString("Name"), 1); m_model->setFitFunction(m_activeFunction); @@ -195,7 +195,7 @@ class FitPlotModelTest : public CxxTest::TestSuite { auto group = getWorkspaceOutput(alg, "OutputWorkspaceGroup"); auto parameters = getWorkspaceOutput(alg, "OutputParameterWorkspace"); auto result = getWorkspaceOutput(alg, "OutputWorkspace"); - m_fitOutput->addOutput(group, parameters, result); + m_fitOutput->addOutput(group, parameters, result, FitDomainIndex{0}); m_activeFunction = getFunction(getFitFunctionString("Name"), 1); m_model->setFitFunction(m_activeFunction); @@ -227,12 +227,12 @@ class FitPlotModelTest : public CxxTest::TestSuite { auto group = getWorkspaceOutput(alg, "OutputWorkspaceGroup"); auto parameters = getWorkspaceOutput(alg, "OutputParameterWorkspace"); auto result = getWorkspaceOutput(alg, "OutputWorkspace"); - m_fitOutput->addOutput(group, parameters, result); + m_fitOutput->addOutput(group, parameters, result, FitDomainIndex{0}); m_activeFunction = getFunction(getFitFunctionString("Name"), 1); m_model->setFitFunction(m_activeFunction); auto const hwhm = m_model->getFirstHWHM(); - auto const peakCentre = m_model->getFirstPeakCentre().get_value_or(0.); + auto const peakCentre = m_model->getFirstPeakCentre().value_or(0.); auto const minimum = peakCentre + *hwhm; TS_ASSERT_EQUALS(m_model->calculateHWHMMaximum(minimum), 0.99125); @@ -244,12 +244,12 @@ class FitPlotModelTest : public CxxTest::TestSuite { auto group = getWorkspaceOutput(alg, "OutputWorkspaceGroup"); auto parameters = getWorkspaceOutput(alg, "OutputParameterWorkspace"); auto result = getWorkspaceOutput(alg, "OutputWorkspace"); - m_fitOutput->addOutput(group, parameters, result); + m_fitOutput->addOutput(group, parameters, result, FitDomainIndex{0}); m_activeFunction = getFunction(getFitFunctionString("Name"), 1); m_model->setFitFunction(m_activeFunction); auto const hwhm = m_model->getFirstHWHM(); - auto const peakCentre = m_model->getFirstPeakCentre().get_value_or(0.); + auto const peakCentre = m_model->getFirstPeakCentre().value_or(0.); auto const maximum = peakCentre - *hwhm; TS_ASSERT_EQUALS(m_model->calculateHWHMMinimum(maximum), 1.00875); @@ -269,14 +269,14 @@ class FitPlotModelTest : public CxxTest::TestSuite { m_activeFunction = getFunction(getFitFunctionString("Name"), 1); m_model->setFitFunction(m_activeFunction); auto const fwhm = 0.0175; - TS_ASSERT_EQUALS(m_model->getFirstHWHM().get(), fwhm / 2); + TS_ASSERT_EQUALS(*m_model->getFirstHWHM(), fwhm / 2); } void test_that_setBackground_will_change_the_value_of_A0_in_the_fitting_function() { m_activeFunction = getFunction(getFitFunctionString("Name"), 1); m_model->setFitFunction(m_activeFunction); auto const background = 0.0; - TS_ASSERT_EQUALS(m_model->getFirstBackgroundLevel().get(), background); + TS_ASSERT_EQUALS(*m_model->getFirstBackgroundLevel(), background); } MatrixWorkspace_sptr m_workspace; diff --git a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotPresenterTest.h b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotPresenterTest.h index 1257d277cb1c..ab11a0cff1cb 100644 --- a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotPresenterTest.h +++ b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotPresenterTest.h @@ -56,9 +56,9 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { /// FittingModel is mocked instead - which is a good /// substitute anyway m_tab = std::make_unique>(); - auto model = std::make_unique(); + m_model = std::make_unique>(); m_view = std::make_unique>(); - m_presenter = std::make_unique(m_tab.get(), m_view.get(), std::move(model)); + m_presenter = std::make_unique(m_tab.get(), m_view.get(), m_model.get()); m_workspace = createWorkspaceWithInstrument(6, 5); m_ads = std::make_unique("WorkspaceName", m_workspace); @@ -365,6 +365,7 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { private: std::unique_ptr> m_tab; std::unique_ptr> m_view; + std::unique_ptr> m_model; std::unique_ptr m_presenter; MatrixWorkspace_sptr m_workspace; diff --git a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FittingModelTest.h b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FittingModelTest.h index d4540b90c6fc..a944f7732a9d 100644 --- a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FittingModelTest.h +++ b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FittingModelTest.h @@ -169,12 +169,12 @@ class FittingModelTest : public CxxTest::TestSuite { TS_ASSERT(m_model->getResultGroup()); } - void test_that_addSingleFitOutput_adds_the_output_of_a_single_fit_into_the_model() { + void test_that_addOutput_adds_the_output_of_a_single_fit_into_the_model() { addInstrumentWorkspaceToModel("__ConvFit", 6, 5, "0-5"); auto const modelWorkspace = m_model->getWorkspace(0); auto const alg = getExecutedFitAlgorithm(m_model, modelWorkspace, "__ConvFit"); - m_model->addSingleFitOutput(alg, WorkspaceID{0}, WorkspaceIndex{0}); + m_model->addOutput(alg); TS_ASSERT(m_model->getResultWorkspace()); TS_ASSERT(m_model->getResultGroup()); @@ -334,7 +334,7 @@ class FittingModelTest : public CxxTest::TestSuite { } void - test_that_cleanFailedSingleRun_removes_the_temporary_workspace_from_the_ADS_when_a_fit_fails_for_a_specific_workspaceIndex() { + test_that_cleanFailedRun_removes_the_temporary_workspace_from_the_ADS_when_a_fit_fails_for_a_single_workspaceIndex() { /// Fails the fit algorithm on purpose by providing an invalid function addInstrumentWorkspaceToModel("__ConvFit", 6, 5, "0-5"); auto const modelWorkspace = m_model->getWorkspace(0); @@ -345,7 +345,7 @@ class FittingModelTest : public CxxTest::TestSuite { alg->execute(); TS_ASSERT(ads.doesExist("__ConvolutionFitSequential_ws1")); - m_model->cleanFailedSingleRun(alg, 0); + m_model->cleanFailedRun(alg); TS_ASSERT(!ads.doesExist("__ConvolutionFitSequential_ws1")); } @@ -414,7 +414,7 @@ class FittingModelTest : public CxxTest::TestSuite { "false;name=Lorentzian,Amplitude=1,PeakCentre=0,FWHM=0." "0175)))"; setFittingFunction(m_model, function); - TS_ASSERT_THROWS_NOTHING(m_model->getSingleFit(WorkspaceID{0}, WorkspaceIndex{0})); + TS_ASSERT_THROWS_NOTHING(m_model->getSingleFittingAlgorithm()); } void test_getSingleFunction_does_not_throw() { diff --git a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FqFitDataPresenterTest.h b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FqFitDataPresenterTest.h index f7f9912f8644..a30121ce5b27 100644 --- a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FqFitDataPresenterTest.h +++ b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FqFitDataPresenterTest.h @@ -65,9 +65,6 @@ class FqFitDataPresenterTest : public CxxTest::TestSuite { m_presenter = std::make_unique(m_tab.get(), m_model.get(), m_view.get()); m_workspace = createWorkspaceWithTextAxis(6, getTextAxisLabels()); m_ads = std::make_unique("WorkspaceName", m_workspace); - - m_fitPropertyBrowser = std::make_unique>(); - m_presenter->subscribeFitPropertyBrowser(m_fitPropertyBrowser.get()); } void tearDown() override { @@ -75,21 +72,18 @@ class FqFitDataPresenterTest : public CxxTest::TestSuite { TS_ASSERT(Mock::VerifyAndClearExpectations(m_view.get())); TS_ASSERT(Mock::VerifyAndClearExpectations(m_model.get())); - TS_ASSERT(Mock::VerifyAndClearExpectations(m_fitPropertyBrowser.get())); m_presenter.reset(); m_model.reset(); m_view.reset(); m_dataTable.reset(); - m_fitPropertyBrowser.reset(); } void test_that_the_presenter_and_mock_objects_have_been_created() { TS_ASSERT(m_presenter); TS_ASSERT(m_model); TS_ASSERT(m_view); - TS_ASSERT(m_fitPropertyBrowser); } void test_addWorkspaceFromDialog_returns_false_if_the_dialog_is_not_fqfit() { @@ -138,5 +132,4 @@ class FqFitDataPresenterTest : public CxxTest::TestSuite { MatrixWorkspace_sptr m_workspace; std::unique_ptr m_ads; - std::unique_ptr> m_fitPropertyBrowser; }; diff --git a/qt/scientific_interfaces/Inelastic/test/QENSFitting/MockObjects.h b/qt/scientific_interfaces/Inelastic/test/QENSFitting/MockObjects.h index e423e2789ea5..fb7e0c4137f0 100644 --- a/qt/scientific_interfaces/Inelastic/test/QENSFitting/MockObjects.h +++ b/qt/scientific_interfaces/Inelastic/test/QENSFitting/MockObjects.h @@ -14,6 +14,8 @@ #include "Manipulation/ElwinPresenter.h" #include "Manipulation/ElwinView.h" #include "Manipulation/IElwinView.h" +#include "QENSFitting/FitOutput.h" +#include "QENSFitting/FitPlotModel.h" #include "QENSFitting/FitTab.h" #include "QENSFitting/FunctionBrowser/FunctionTemplateView.h" #include "QENSFitting/FunctionBrowser/ITemplatePresenter.h" @@ -23,11 +25,14 @@ #include "QENSFitting/IFitPlotView.h" #include "QENSFitting/InelasticFitPropertyBrowser.h" +#include "MantidAPI/IFunction_fwd.h" #include "MantidKernel/WarningSuppressions.h" +#include "MantidQtWidgets/Common/FunctionModelSpectra.h" #include "MantidQtWidgets/Common/IAddWorkspaceDialog.h" #include "MantidQtWidgets/Common/UserInputValidator.h" #include +#include #include #include #include @@ -47,8 +52,9 @@ class MockFitTab : public IFitTab { MOCK_METHOD0(handleDataRemoved, void()); MOCK_METHOD3(handleTableStartXChanged, void(double startX, WorkspaceID workspaceID, WorkspaceIndex workspaceIndex)); MOCK_METHOD3(handleTableEndXChanged, void(double endX, WorkspaceID workspaceID, WorkspaceIndex workspaceIndex)); + MOCK_METHOD1(handleFunctionListChanged, void(const std::map &functionStrings)); - MOCK_METHOD2(handleSingleFitClicked, void(WorkspaceID workspaceID, WorkspaceIndex workspaceIndex)); + MOCK_METHOD0(handleSingleFitClicked, void()); MOCK_METHOD1(handleStartXChanged, void(double startX)); MOCK_METHOD1(handleEndXChanged, void(double endX)); MOCK_METHOD0(handlePlotSpectrumChanged, void()); @@ -58,6 +64,39 @@ class MockFitTab : public IFitTab { MOCK_METHOD0(handlePlotSelectedSpectra, void()); MOCK_METHOD0(handleFunctionChanged, void()); + MOCK_METHOD1(handleFitComplete, void(bool const error)); +}; + +class MockFitPlotModel : public IFitPlotModel { +public: + virtual ~MockFitPlotModel() = default; + + MOCK_CONST_METHOD0(getWorkspace, Mantid::API::MatrixWorkspace_sptr()); + MOCK_CONST_METHOD0(getResultWorkspace, Mantid::API::MatrixWorkspace_sptr()); + MOCK_CONST_METHOD0(getGuessWorkspace, Mantid::API::MatrixWorkspace_sptr()); + MOCK_CONST_METHOD1(getSpectra, MantidQt::MantidWidgets::FunctionModelSpectra(WorkspaceID workspaceID)); + + MOCK_CONST_METHOD0(getActiveWorkspaceID, WorkspaceID()); + MOCK_CONST_METHOD0(getActiveWorkspaceIndex, WorkspaceIndex()); + MOCK_CONST_METHOD0(getActiveDomainIndex, FitDomainIndex()); + MOCK_CONST_METHOD0(numberOfWorkspaces, WorkspaceID()); + + MOCK_CONST_METHOD0(getRange, std::pair()); + MOCK_CONST_METHOD0(getWorkspaceRange, std::pair()); + MOCK_CONST_METHOD0(getResultRange, std::pair()); + MOCK_CONST_METHOD0(getFirstHWHM, std::optional()); + MOCK_CONST_METHOD0(getFirstPeakCentre, std::optional()); + MOCK_CONST_METHOD0(getFirstBackgroundLevel, std::optional()); + MOCK_CONST_METHOD1(calculateHWHMMaximum, double(double maximum)); + MOCK_CONST_METHOD1(calculateHWHMMinimum, double(double minimum)); + MOCK_CONST_METHOD0(canCalculateGuess, bool()); + + MOCK_METHOD1(setActiveIndex, void(WorkspaceID workspaceID)); + MOCK_METHOD1(setActiveSpectrum, void(WorkspaceIndex spectrum)); + + MOCK_METHOD1(setFittingData, void(std::vector *fittingData)); + MOCK_METHOD1(setFitOutput, void(IFitOutput *fitOutput)); + MOCK_METHOD1(setFitFunction, void(Mantid::API::MultiDomainFunction_sptr function)); }; class MockFitPlotView : public IFitPlotView { From 6e862c8c4dd1cd10c5eed5e0ae41216d797c2c10 Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 3 May 2024 10:41:43 +0100 Subject: [PATCH 40/58] Pass FitData raw pointer directly to FitPlotModel --- .../Inelastic/QENSFitting/FitDataPresenter.cpp | 2 -- .../Inelastic/QENSFitting/FitDataPresenter.h | 1 - .../Inelastic/QENSFitting/FitPlotModel.cpp | 7 +++---- .../Inelastic/QENSFitting/FitPlotModel.h | 4 +--- .../Inelastic/QENSFitting/FitPlotPresenter.cpp | 2 -- .../Inelastic/QENSFitting/FitPlotPresenter.h | 1 - .../Inelastic/QENSFitting/FitTab.cpp | 1 - .../Inelastic/QENSFitting/FittingModel.cpp | 6 +++--- .../Inelastic/test/QENSFitting/FitPlotModelTest.h | 3 +-- .../test/QENSFitting/FitPlotPresenterTest.h | 15 ++++----------- 10 files changed, 12 insertions(+), 30 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitDataPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitDataPresenter.cpp index 7bd5655e1683..ac7bf8480dbc 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitDataPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitDataPresenter.cpp @@ -22,8 +22,6 @@ FitDataPresenter::FitDataPresenter(IFitTab *tab, IFitDataModel *model, IFitDataV FitDataPresenter::~FitDataPresenter() { observeReplace(false); } -std::vector *FitDataPresenter::getFittingData() { return m_model->getFittingData(); } - IFitDataView const *FitDataPresenter::getView() const { return m_view; } std::string FitDataPresenter::tabName() const { return m_tab->tabName(); } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitDataPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitDataPresenter.h index 76f9e4162c84..861dba08df94 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitDataPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitDataPresenter.h @@ -36,7 +36,6 @@ class MANTIDQT_INELASTIC_DLL FitDataPresenter : public IFitDataPresenter, public public: FitDataPresenter(IFitTab *tab, IFitDataModel *model, IFitDataView *view); ~FitDataPresenter(); - std::vector *getFittingData(); virtual bool addWorkspaceFromDialog(MantidWidgets::IAddWorkspaceDialog const *dialog); void addWorkspace(const std::string &workspaceName, const FunctionModelSpectra &workspaceIndices); void setResolution(const std::string &name); diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp index 10eb91722d72..a873839855e8 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp @@ -83,8 +83,9 @@ namespace MantidQt::CustomInterfaces::Inelastic { using namespace Mantid::API; -FitPlotModel::FitPlotModel() - : m_fittingData(), m_fitOutput(), m_activeWorkspaceID{0}, m_activeWorkspaceIndex{0}, m_activeFunction() {} +FitPlotModel::FitPlotModel(std::vector *fittingData) + : m_fittingData(fittingData), m_fitOutput(), m_activeWorkspaceID{0}, m_activeWorkspaceIndex{0}, m_activeFunction() { +} FitPlotModel::~FitPlotModel() {} @@ -96,8 +97,6 @@ void FitPlotModel::setFitFunction(Mantid::API::MultiDomainFunction_sptr function m_activeFunction = std::move(function); } -void FitPlotModel::setFittingData(std::vector *fittingData) { m_fittingData = fittingData; } - void FitPlotModel::setFitOutput(IFitOutput *fitOutput) { m_fitOutput = fitOutput; } MatrixWorkspace_sptr FitPlotModel::getWorkspace() const { diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h index fdf6779839fb..2eaa2ab3c043 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h @@ -47,14 +47,13 @@ class MANTIDQT_INELASTIC_DLL IFitPlotModel { virtual void setActiveIndex(WorkspaceID workspaceID) = 0; virtual void setActiveSpectrum(WorkspaceIndex spectrum) = 0; - virtual void setFittingData(std::vector *fittingData) = 0; virtual void setFitOutput(IFitOutput *fitOutput) = 0; virtual void setFitFunction(Mantid::API::MultiDomainFunction_sptr function) = 0; }; class MANTIDQT_INELASTIC_DLL FitPlotModel : public IFitPlotModel { public: - FitPlotModel(); + FitPlotModel(std::vector *fittingData); ~FitPlotModel(); Mantid::API::MatrixWorkspace_sptr getWorkspace() const override; @@ -79,7 +78,6 @@ class MANTIDQT_INELASTIC_DLL FitPlotModel : public IFitPlotModel { void setActiveIndex(WorkspaceID workspaceID) override; void setActiveSpectrum(WorkspaceIndex spectrum) override; - void setFittingData(std::vector *fittingData) override; void setFitOutput(IFitOutput *fitOutput) override; void setFitFunction(Mantid::API::MultiDomainFunction_sptr function) override; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp index 7aee6bd2979c..d262f80d2a7d 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp @@ -72,8 +72,6 @@ void FitPlotPresenter::setEndX(double value) { m_view->setFitRangeMaximum(value) void FitPlotPresenter::setXBounds(std::pair const &bounds) { m_view->setFitRangeBounds(bounds); } -void FitPlotPresenter::setFittingData(std::vector *fittingData) { m_model->setFittingData(fittingData); } - void FitPlotPresenter::setFitOutput(IFitOutput *fitOutput) { m_model->setFitOutput(fitOutput); } void FitPlotPresenter::updateRangeSelectors() { diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.h index 0a455236408f..696cc1f5be04 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.h @@ -58,7 +58,6 @@ class MANTIDQT_INELASTIC_DLL FitPlotPresenter final : public IFitPlotPresenter { FitDomainIndex getSelectedDomainIndex() const; bool isCurrentlySelected(WorkspaceID workspaceID, WorkspaceIndex spectrum) const; - void setFittingData(std::vector *fittingData); void setFitOutput(IFitOutput *fitOutput); void setFitFunction(Mantid::API::MultiDomainFunction_sptr function); void setFitSingleSpectrumIsFitting(bool fitting); diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp index 758b9f0fa8ed..78e60e860e0a 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp @@ -42,7 +42,6 @@ void FitTab::setupOutputOptionsPresenter(bool const editResults) { void FitTab::setupPlotView(std::optional> const &xPlotBounds) { m_plotPresenter = std::make_unique(this, m_uiForm->dockArea->m_fitPlotView, m_fittingPresenter->getFitPlotModel()); - m_plotPresenter->setFittingData(m_dataPresenter->getFittingData()); m_plotPresenter->setFitOutput(m_fittingPresenter->getFitOutput()); if (xPlotBounds) { m_plotPresenter->setXBounds(*xPlotBounds); diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp index c9d454675099..b6a49e17a7f8 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp @@ -308,9 +308,9 @@ std::unordered_map fitModeToName = std::unordered_map< {{FittingMode::SEQUENTIAL, "Seq"}, {FittingMode::SIMULTANEOUS, "Sim"}}); FittingModel::FittingModel() - : m_fitDataModel(std::make_unique()), m_fitPlotModel(std::make_unique()), - m_previousModelSelected(false), m_fittingMode(FittingMode::SEQUENTIAL), - m_fitOutput(std::make_unique()) {} + : m_fitDataModel(std::make_unique()), + m_fitPlotModel(std::make_unique(m_fitDataModel->getFittingData())), m_previousModelSelected(false), + m_fittingMode(FittingMode::SEQUENTIAL), m_fitOutput(std::make_unique()) {} void FittingModel::validate(UserInputValidator &validator) const { if (auto const invalidFunction = isInvalidFunction()) diff --git a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotModelTest.h b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotModelTest.h index 0421bb35961f..fde438b758a7 100644 --- a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotModelTest.h +++ b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotModelTest.h @@ -80,11 +80,10 @@ class FitPlotModelTest : public CxxTest::TestSuite { void setUp() override { m_workspace = createWorkspaceWithInstrument(6, 5); m_ads = std::make_unique("Name", m_workspace); - m_model = std::make_unique(); m_fittingData = std::make_unique>(); m_fittingData->emplace_back(m_workspace, FunctionModelSpectra("0-5")); + m_model = std::make_unique(m_fittingData.get()); m_fitOutput = std::make_unique(); - m_model->setFittingData(m_fittingData.get()); m_model->setFitOutput(m_fitOutput.get()); } diff --git a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotPresenterTest.h b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotPresenterTest.h index ab11a0cff1cb..84a443b76847 100644 --- a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotPresenterTest.h +++ b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotPresenterTest.h @@ -62,10 +62,7 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { m_workspace = createWorkspaceWithInstrument(6, 5); m_ads = std::make_unique("WorkspaceName", m_workspace); - m_fittingData = std::make_unique>(); - m_fittingData->emplace_back(m_workspace, FunctionModelSpectra("0-5")); m_fitOutput = std::make_unique(); - m_presenter->setFittingData(m_fittingData.get()); m_presenter->setFitOutput(m_fitOutput.get()); } @@ -124,8 +121,6 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { } void test_that_handleSelectedFitDataChanged_will_disable_selectors_when_there_is_no_workspace() { - m_fittingData->clear(); - EXPECT_CALL(*m_view, enableSpectrumSelection(false)).Times(1); EXPECT_CALL(*m_view, enableFitRangeSelection(false)).Times(1); @@ -138,8 +133,8 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { } void test_that_handleSelectedFitDataChanged_will_set_the_minimum_and_maximum_of_the_fit_range() { - m_fittingData->at(0).setStartX(1.0); - m_fittingData->at(0).setEndX(2.0); + ON_CALL(*m_model, getRange()).WillByDefault(Return(std::pair{1.0, 2.0})); + EXPECT_CALL(*m_view, setFitRangeMinimum(1.0)).Times(1); EXPECT_CALL(*m_view, setFitRangeMaximum(2.0)).Times(1); @@ -164,8 +159,8 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { } void test_that_handlePlotSpectrumChanged_will_set_the_minimum_and_maximum_of_the_fit_range() { - m_fittingData->at(0).setStartX(1.0); - m_fittingData->at(0).setEndX(2.0); + ON_CALL(*m_model, getRange()).WillByDefault(Return(std::pair{1.0, 2.0})); + EXPECT_CALL(*m_view, setFitRangeMinimum(1.0)).Times(1); EXPECT_CALL(*m_view, setFitRangeMaximum(2.0)).Times(1); @@ -174,7 +169,6 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { void test_that_handlePlotCurrentPreview_will_display_an_error_message_if_there_is_no_input_workspace() { std::string const message("Workspace not found - data may not be loaded."); - m_fittingData->clear(); EXPECT_CALL(*m_view, displayMessage(message)).Times(1); @@ -370,6 +364,5 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { MatrixWorkspace_sptr m_workspace; std::unique_ptr m_ads; - std::unique_ptr> m_fittingData; std::unique_ptr m_fitOutput; }; From 2be5db949a805d83ddff553e65eed7f0b402de29 Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 3 May 2024 11:24:17 +0100 Subject: [PATCH 41/58] Update FitPlotPresenterTest --- .../QENSFitting/FitPlotPresenter.cpp | 2 +- .../test/QENSFitting/FitPlotPresenterTest.h | 62 +++++++++++++------ 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp index d262f80d2a7d..01bcbfa64a28 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp @@ -239,7 +239,7 @@ void FitPlotPresenter::updateGuessAvailability() { void FitPlotPresenter::handlePlotGuess(bool doPlotGuess) { if (doPlotGuess) { const auto guessWorkspace = m_model->getGuessWorkspace(); - if (guessWorkspace->x(0).size() >= 2) { + if (guessWorkspace && guessWorkspace->x(0).size() >= 2) { plotGuess(guessWorkspace); } } else { diff --git a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotPresenterTest.h b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotPresenterTest.h index 84a443b76847..d1006bf227c7 100644 --- a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotPresenterTest.h +++ b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotPresenterTest.h @@ -107,6 +107,9 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { } void test_that_handleSelectedFitDataChanged_will_set_the_available_spectra() { + ON_CALL(*m_model, getWorkspace()).WillByDefault(Return(m_workspace)); + ON_CALL(*m_model, getActiveWorkspaceID()).WillByDefault(Return(WorkspaceID{0})); + ON_CALL(*m_model, getSpectra(WorkspaceID{0})).WillByDefault(Return(FunctionModelSpectra("0-5"))); EXPECT_CALL(*m_view, setAvailableSpectra(WorkspaceIndex(0), WorkspaceIndex(5))).Times(1); @@ -114,6 +117,10 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { } void test_that_handleSelectedFitDataChanged_will_enable_selectors_when_workspace_presenter() { + ON_CALL(*m_model, getWorkspace()).WillByDefault(Return(m_workspace)); + ON_CALL(*m_model, getActiveWorkspaceID()).WillByDefault(Return(WorkspaceID{0})); + ON_CALL(*m_model, getSpectra(WorkspaceID{0})).WillByDefault(Return(FunctionModelSpectra("0-5"))); + EXPECT_CALL(*m_view, enableSpectrumSelection(true)).Times(1); EXPECT_CALL(*m_view, enableFitRangeSelection(true)).Times(1); @@ -121,6 +128,8 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { } void test_that_handleSelectedFitDataChanged_will_disable_selectors_when_there_is_no_workspace() { + ON_CALL(*m_model, getWorkspace()).WillByDefault(Return(nullptr)); + EXPECT_CALL(*m_view, enableSpectrumSelection(false)).Times(1); EXPECT_CALL(*m_view, enableFitRangeSelection(false)).Times(1); @@ -142,8 +151,12 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { } void test_that_handlePlotSpectrumChanged_will_set_the_active_spectrum() { - m_presenter->handlePlotSpectrumChanged(2); - TS_ASSERT_EQUALS(m_presenter->getActiveWorkspaceIndex(), 2); + auto workspaceIndex = WorkspaceIndex(2); + + EXPECT_CALL(*m_model, setActiveSpectrum(workspaceIndex)).Times(1); + EXPECT_CALL(*m_view, setPlotSpectrum(workspaceIndex)).Times(1); + + m_presenter->handlePlotSpectrumChanged(workspaceIndex); } void test_that_handlePlotSpectrumChanged_will_plot_the_input_when_there_is_only_an_input_workspace() { @@ -195,12 +208,20 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { } void test_that_handleHWHMMinimumChanged_will_set_the_hwhm_minimum() { - EXPECT_CALL(*m_view, setHWHMMinimum(-2.0)).Times(1); - m_presenter->handleHWHMMinimumChanged(2.0); + double hwhmMin{2.0}; + + ON_CALL(*m_model, calculateHWHMMinimum(hwhmMin)).WillByDefault(Return(-hwhmMin)); + EXPECT_CALL(*m_view, setHWHMMinimum(-hwhmMin)).Times(1); + + m_presenter->handleHWHMMinimumChanged(hwhmMin); } void test_that_handleHWHMMaximumChanged_will_set_the_hwhm_maximum() { - EXPECT_CALL(*m_view, setHWHMMaximum(-2.0)).Times(1); + double hwhmMax{2.0}; + + ON_CALL(*m_model, calculateHWHMMaximum(hwhmMax)).WillByDefault(Return(-hwhmMax)); + EXPECT_CALL(*m_view, setHWHMMaximum(-hwhmMax)).Times(1); + m_presenter->handleHWHMMaximumChanged(2.0); } @@ -209,21 +230,12 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { ///---------------------------------------------------------------------- void test_that_setActiveSpectrum_will_set_the_spectrum_in_view_and_model() { - EXPECT_CALL(*m_view, setPlotSpectrum(WorkspaceIndex{3})).Times(1); + auto const workspaceIndex = WorkspaceIndex{3}; - m_presenter->setActiveSpectrum(WorkspaceIndex{3}); + EXPECT_CALL(*m_model, setActiveSpectrum(workspaceIndex)).Times(1); + EXPECT_CALL(*m_view, setPlotSpectrum(workspaceIndex)).Times(1); - TS_ASSERT_EQUALS(m_presenter->getSelectedDomainIndex(), FitDomainIndex{3}); - } - - void test_that_isCurrentlySelected_returns_true_if_the_index_and_spectrum_given_are_selected() { - m_presenter->handleSelectedFitDataChanged(2); - TS_ASSERT(m_presenter->isCurrentlySelected(2, 0)); - } - - void test_that_isCurrentlySelected_returns_false_if_the_index_and_spectrum_given_are_not_selected() { - m_presenter->handleSelectedFitDataChanged(2); - TS_ASSERT(!m_presenter->isCurrentlySelected(0, 0)); + m_presenter->setActiveSpectrum(workspaceIndex); } void test_that_setFitSingleSpectrum_methods_calls_view() { @@ -254,6 +266,8 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { void test_that_updateRangeSelectors_will_update_the_background_selector() { auto const fitFunction = getFunctionWithWorkspaceName("WorkspaceName"); m_presenter->setFitFunction(fitFunction); + + ON_CALL(*m_model, getFirstBackgroundLevel()).WillByDefault(Return(0.0)); Expectation setVisible = EXPECT_CALL(*m_view, setBackgroundRangeVisible(true)).Times(1); EXPECT_CALL(*m_view, setBackgroundLevel(0.0)).Times(1).After(setVisible); @@ -264,6 +278,9 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { auto const fitFunction = getFunctionWithWorkspaceName("WorkspaceName"); m_presenter->setFitFunction(fitFunction); + ON_CALL(*m_model, getFirstHWHM()).WillByDefault(Return(0.00875)); + ON_CALL(*m_model, getFirstPeakCentre()).WillByDefault(Return(0.0)); + Expectation setVisible = EXPECT_CALL(*m_view, setHWHMRangeVisible(true)).Times(1); EXPECT_CALL(*m_view, setHWHMMinimum(-0.00875)).Times(1).After(setVisible); EXPECT_CALL(*m_view, setHWHMMaximum(0.00875)).Times(1).After(setVisible); @@ -299,7 +316,7 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { EXPECT_CALL(*m_view, clearDataSelection()).Times(1); EXPECT_CALL(*m_view, appendToDataSelection("DisplayName-0")).Times(1); EXPECT_CALL(*m_view, appendToDataSelection("DisplayName-1")).Times(1); - EXPECT_CALL(*m_view, setPlotSpectrum(WorkspaceIndex{0})).Times(2); + EXPECT_CALL(*m_view, setPlotSpectrum(WorkspaceIndex{0})).Times(1); TS_ASSERT_EQUALS(m_presenter->getActiveWorkspaceIndex(), WorkspaceIndex{0}); m_presenter->updateDataSelection({"DisplayName-0", "DisplayName-1"}); @@ -308,6 +325,11 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { void test_updateAvailableSpectra_uses_minmax_if_spectra_is_continuous() { auto spectra = FunctionModelSpectra("0-5"); auto minmax = spectra.getMinMax(); + + ON_CALL(*m_model, getWorkspace()).WillByDefault(Return(m_workspace)); + ON_CALL(*m_model, getActiveWorkspaceID()).WillByDefault(Return(WorkspaceID{0})); + ON_CALL(*m_model, getSpectra(WorkspaceID{0})).WillByDefault(Return(spectra)); + EXPECT_CALL(*m_view, setAvailableSpectra(minmax.first, minmax.second)).Times(1); m_presenter->updateAvailableSpectra(); @@ -334,6 +356,7 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { void test_updateGuess_enables_plot_guess_if_model_can_calculate_guess() { auto const fitFunction = getFunctionWithWorkspaceName("WorkspaceName"); m_presenter->setFitFunction(fitFunction); + ON_CALL(*m_model, canCalculateGuess()).WillByDefault(Return(true)); EXPECT_CALL(*m_view, enablePlotGuess(true)).Times(1); EXPECT_CALL(*m_view, isPlotGuessChecked()).Times(1); m_presenter->updateGuess(); @@ -347,6 +370,7 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { void test_updateGuessAvailability_enables_plot_guess_if_model_can_calculate_guess() { auto const fitFunction = getFunctionWithWorkspaceName("WorkspaceName"); m_presenter->setFitFunction(fitFunction); + ON_CALL(*m_model, canCalculateGuess()).WillByDefault(Return(true)); EXPECT_CALL(*m_view, enablePlotGuess(true)).Times(1); m_presenter->updateGuessAvailability(); } From 8e0a5ffa5091ee120ec3a94386dc695c9ba9ad9b Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 3 May 2024 11:35:53 +0100 Subject: [PATCH 42/58] Pass FitOutput directly into FitPlotModel --- .../Inelastic/QENSFitting/FitPlotModel.cpp | 8 +++----- .../Inelastic/QENSFitting/FitPlotModel.h | 4 +--- .../Inelastic/QENSFitting/FitPlotPresenter.cpp | 2 -- .../Inelastic/QENSFitting/FitPlotPresenter.h | 1 - qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp | 1 - .../Inelastic/QENSFitting/FittingModel.cpp | 7 ++++--- .../Inelastic/QENSFitting/FittingPresenter.cpp | 2 -- .../Inelastic/QENSFitting/FittingPresenter.h | 1 - .../Inelastic/test/QENSFitting/FitPlotModelTest.h | 3 +-- .../Inelastic/test/QENSFitting/FitPlotPresenterTest.h | 7 ------- 10 files changed, 9 insertions(+), 27 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp index a873839855e8..c0d31dcddad0 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp @@ -83,9 +83,9 @@ namespace MantidQt::CustomInterfaces::Inelastic { using namespace Mantid::API; -FitPlotModel::FitPlotModel(std::vector *fittingData) - : m_fittingData(fittingData), m_fitOutput(), m_activeWorkspaceID{0}, m_activeWorkspaceIndex{0}, m_activeFunction() { -} +FitPlotModel::FitPlotModel(std::vector *fittingData, IFitOutput *fitOutput) + : m_fittingData(fittingData), m_fitOutput(fitOutput), m_activeWorkspaceID{0}, m_activeWorkspaceIndex{0}, + m_activeFunction() {} FitPlotModel::~FitPlotModel() {} @@ -97,8 +97,6 @@ void FitPlotModel::setFitFunction(Mantid::API::MultiDomainFunction_sptr function m_activeFunction = std::move(function); } -void FitPlotModel::setFitOutput(IFitOutput *fitOutput) { m_fitOutput = fitOutput; } - MatrixWorkspace_sptr FitPlotModel::getWorkspace() const { if (m_activeWorkspaceID < m_fittingData->size()) return m_fittingData->at(m_activeWorkspaceID.value).workspace(); diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h index 2eaa2ab3c043..eb6fddd6e7b1 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h @@ -47,13 +47,12 @@ class MANTIDQT_INELASTIC_DLL IFitPlotModel { virtual void setActiveIndex(WorkspaceID workspaceID) = 0; virtual void setActiveSpectrum(WorkspaceIndex spectrum) = 0; - virtual void setFitOutput(IFitOutput *fitOutput) = 0; virtual void setFitFunction(Mantid::API::MultiDomainFunction_sptr function) = 0; }; class MANTIDQT_INELASTIC_DLL FitPlotModel : public IFitPlotModel { public: - FitPlotModel(std::vector *fittingData); + FitPlotModel(std::vector *fittingData, IFitOutput *fitOutput); ~FitPlotModel(); Mantid::API::MatrixWorkspace_sptr getWorkspace() const override; @@ -78,7 +77,6 @@ class MANTIDQT_INELASTIC_DLL FitPlotModel : public IFitPlotModel { void setActiveIndex(WorkspaceID workspaceID) override; void setActiveSpectrum(WorkspaceIndex spectrum) override; - void setFitOutput(IFitOutput *fitOutput) override; void setFitFunction(Mantid::API::MultiDomainFunction_sptr function) override; private: diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp index 01bcbfa64a28..18b0f93c2b48 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.cpp @@ -72,8 +72,6 @@ void FitPlotPresenter::setEndX(double value) { m_view->setFitRangeMaximum(value) void FitPlotPresenter::setXBounds(std::pair const &bounds) { m_view->setFitRangeBounds(bounds); } -void FitPlotPresenter::setFitOutput(IFitOutput *fitOutput) { m_model->setFitOutput(fitOutput); } - void FitPlotPresenter::updateRangeSelectors() { updateBackgroundSelector(); updateHWHMSelector(); diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.h index 696cc1f5be04..dd1333222168 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotPresenter.h @@ -58,7 +58,6 @@ class MANTIDQT_INELASTIC_DLL FitPlotPresenter final : public IFitPlotPresenter { FitDomainIndex getSelectedDomainIndex() const; bool isCurrentlySelected(WorkspaceID workspaceID, WorkspaceIndex spectrum) const; - void setFitOutput(IFitOutput *fitOutput); void setFitFunction(Mantid::API::MultiDomainFunction_sptr function); void setFitSingleSpectrumIsFitting(bool fitting); void setFitSingleSpectrumEnabled(bool enable); diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp index 78e60e860e0a..9563a1ad6cf9 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitTab.cpp @@ -42,7 +42,6 @@ void FitTab::setupOutputOptionsPresenter(bool const editResults) { void FitTab::setupPlotView(std::optional> const &xPlotBounds) { m_plotPresenter = std::make_unique(this, m_uiForm->dockArea->m_fitPlotView, m_fittingPresenter->getFitPlotModel()); - m_plotPresenter->setFitOutput(m_fittingPresenter->getFitOutput()); if (xPlotBounds) { m_plotPresenter->setXBounds(*xPlotBounds); } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp index b6a49e17a7f8..908f251c28ba 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp @@ -308,9 +308,10 @@ std::unordered_map fitModeToName = std::unordered_map< {{FittingMode::SEQUENTIAL, "Seq"}, {FittingMode::SIMULTANEOUS, "Sim"}}); FittingModel::FittingModel() - : m_fitDataModel(std::make_unique()), - m_fitPlotModel(std::make_unique(m_fitDataModel->getFittingData())), m_previousModelSelected(false), - m_fittingMode(FittingMode::SEQUENTIAL), m_fitOutput(std::make_unique()) {} + : m_fitDataModel(std::make_unique()), m_fitPlotModel(), m_fitOutput(std::make_unique()), + m_previousModelSelected(false), m_fittingMode(FittingMode::SEQUENTIAL) { + m_fitPlotModel = std::make_unique(m_fitDataModel->getFittingData(), m_fitOutput.get()); +} void FittingModel::validate(UserInputValidator &validator) const { if (auto const invalidFunction = isInvalidFunction()) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp index 86028f3f0b32..843d812548a3 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp @@ -90,8 +90,6 @@ void FittingPresenter::notifyBatchComplete(MantidQt::API::IConfiguredAlgorithm_s Mantid::API::WorkspaceGroup_sptr FittingPresenter::getResultWorkspace() const { return m_model->getResultWorkspace(); } -IFitOutput *FittingPresenter::getFitOutput() const { return m_model->getFitOutput(); } - std::string FittingPresenter::getOutputBasename() const { return m_model->getOutputBasename(); } IFitDataModel *FittingPresenter::getFitDataModel() const { return m_model->getFitDataModel(); } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h index 24eb00de1aa3..43c496d6207f 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h @@ -74,7 +74,6 @@ class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter, void notifyBatchComplete(MantidQt::API::IConfiguredAlgorithm_sptr &lastAlgorithm, bool error) override; Mantid::API::WorkspaceGroup_sptr getResultWorkspace() const; - IFitOutput *getFitOutput() const; std::string getOutputBasename() const; IFitDataModel *getFitDataModel() const; diff --git a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotModelTest.h b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotModelTest.h index fde438b758a7..7c8503bb28cb 100644 --- a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotModelTest.h +++ b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotModelTest.h @@ -82,9 +82,8 @@ class FitPlotModelTest : public CxxTest::TestSuite { m_ads = std::make_unique("Name", m_workspace); m_fittingData = std::make_unique>(); m_fittingData->emplace_back(m_workspace, FunctionModelSpectra("0-5")); - m_model = std::make_unique(m_fittingData.get()); m_fitOutput = std::make_unique(); - m_model->setFitOutput(m_fitOutput.get()); + m_model = std::make_unique(m_fittingData.get(), m_fitOutput.get()); } void tearDown() override { diff --git a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotPresenterTest.h b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotPresenterTest.h index d1006bf227c7..555f57488cef 100644 --- a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotPresenterTest.h +++ b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FitPlotPresenterTest.h @@ -51,10 +51,6 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { static void destroySuite(FitPlotPresenterTest *suite) { delete suite; } void setUp() override { - /// Note that the FitPlotModel could not be mocked as the - /// Presenter takes an FittingModel. This means the - /// FittingModel is mocked instead - which is a good - /// substitute anyway m_tab = std::make_unique>(); m_model = std::make_unique>(); m_view = std::make_unique>(); @@ -62,8 +58,6 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { m_workspace = createWorkspaceWithInstrument(6, 5); m_ads = std::make_unique("WorkspaceName", m_workspace); - m_fitOutput = std::make_unique(); - m_presenter->setFitOutput(m_fitOutput.get()); } void tearDown() override { @@ -388,5 +382,4 @@ class FitPlotPresenterTest : public CxxTest::TestSuite { MatrixWorkspace_sptr m_workspace; std::unique_ptr m_ads; - std::unique_ptr m_fitOutput; }; From 8d4dcc4382119ade2bf5d7e2021975cda8d24ea2 Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 3 May 2024 15:09:25 +0100 Subject: [PATCH 43/58] Create FittingPresenterTest file --- .../Inelastic/QENSFitting/FitOutput.cpp | 4 +- .../Inelastic/QENSFitting/FitOutput.h | 2 +- .../Inelastic/QENSFitting/FitPlotModel.cpp | 6 +- .../Inelastic/QENSFitting/FitPlotModel.h | 2 +- .../Inelastic/QENSFitting/FittingModel.cpp | 10 +-- .../Inelastic/QENSFitting/FittingModel.h | 9 ++- .../QENSFitting/FittingPresenter.cpp | 8 +-- .../Inelastic/QENSFitting/FittingPresenter.h | 17 +++-- .../Inelastic/QENSFitting/IFitOutput.h | 8 +-- .../Inelastic/QENSFitting/IFittingModel.h | 12 +++- .../InelasticFitPropertyBrowser.cpp | 6 ++ .../QENSFitting/InelasticFitPropertyBrowser.h | 61 +++++++++++----- .../Inelastic/test/QENSFitting/CMakeLists.txt | 3 +- .../test/QENSFitting/FittingModelTest.h | 2 +- .../test/QENSFitting/FittingPresenterTest.h | 45 ++++++++++++ .../Inelastic/test/QENSFitting/MockObjects.h | 72 +++++++++++++++++++ 16 files changed, 213 insertions(+), 54 deletions(-) create mode 100644 qt/scientific_interfaces/Inelastic/test/QENSFitting/FittingPresenterTest.h diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitOutput.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitOutput.cpp index 633b93f6253c..ac9116b34b54 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitOutput.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitOutput.cpp @@ -80,11 +80,11 @@ std::unordered_map FitOutput::getParameters(FitDoma } } -boost::optional FitOutput::getResultLocation(FitDomainIndex index) const { +std::optional FitOutput::getResultLocation(FitDomainIndex index) const { if (m_outputResultLocations.count(index.value) == 1) { return m_outputResultLocations.at(index.value); } - return boost::none; + return std::nullopt; } std::vector FitOutput::getResultParameterNames() const { diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitOutput.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitOutput.h index 39971932bcd7..77de6f5a5920 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitOutput.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitOutput.h @@ -30,7 +30,7 @@ class MANTIDQT_INELASTIC_DLL FitOutput : public IFitOutput { std::unordered_map getParameters(FitDomainIndex index) const override; - boost::optional getResultLocation(FitDomainIndex index) const override; + std::optional getResultLocation(FitDomainIndex index) const override; std::vector getResultParameterNames() const override; Mantid::API::WorkspaceGroup_sptr getLastResultWorkspace() const override; Mantid::API::WorkspaceGroup_sptr getLastResultGroup() const override; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp index c0d31dcddad0..f98f38efe94e 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp @@ -242,12 +242,12 @@ FitDomainIndex FitPlotModel::getDomainIndex(WorkspaceID workspaceID, WorkspaceIn return index; } -boost::optional FitPlotModel::getResultLocation(WorkspaceID workspaceID, - WorkspaceIndex spectrum) const { +std::optional FitPlotModel::getResultLocation(WorkspaceID workspaceID, + WorkspaceIndex spectrum) const { auto fitDomainIndex = getDomainIndex(workspaceID, spectrum); if (!m_fitOutput->isEmpty() && numberOfWorkspaces() > workspaceID) return m_fitOutput->getResultLocation(fitDomainIndex); - return boost::none; + return std::nullopt; } std::pair FitPlotModel::getGuessRange() const { diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h index eb6fddd6e7b1..9d0642af5d9e 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h @@ -84,7 +84,7 @@ class MANTIDQT_INELASTIC_DLL FitPlotModel : public IFitPlotModel { Mantid::API::IFunction_sptr getSingleFunction(WorkspaceID workspaceID, WorkspaceIndex spectrum) const; FitDomainIndex getDomainIndex(WorkspaceID workspaceID, WorkspaceIndex spectrum) const; - boost::optional getResultLocation(WorkspaceID workspaceID, WorkspaceIndex spectrum) const; + std::optional getResultLocation(WorkspaceID workspaceID, WorkspaceIndex spectrum) const; size_t numberOfSpectra(WorkspaceID workspaceID) const; Mantid::API::MatrixWorkspace_sptr createGuessWorkspace(const Mantid::API::MatrixWorkspace_sptr &inputWorkspace, diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp index 908f251c28ba..3ef307c7e81e 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp @@ -384,14 +384,14 @@ bool FittingModel::isPreviouslyFit(WorkspaceID workspaceID, WorkspaceIndex spect return m_fitOutput->isSpectrumFit(domainIndex); } -boost::optional FittingModel::isInvalidFunction() const { +std::optional FittingModel::isInvalidFunction() const { if (!m_activeFunction) return std::string("No fit function has been defined"); const auto composite = std::dynamic_pointer_cast(m_activeFunction); if (composite && (composite->nFunctions() == 0 || composite->nParams() == 0)) return std::string("No fitting functions have been defined."); - return boost::none; + return std::nullopt; } std::vector FittingModel::getFitParameterNames() const { @@ -484,12 +484,12 @@ std::string FittingModel::getResultXAxisUnit() const { return "MomentumTransfer" std::string FittingModel::getResultLogName() const { return "axis-1"; } -boost::optional FittingModel::getResultLocation(WorkspaceID workspaceID, - WorkspaceIndex spectrum) const { +std::optional FittingModel::getResultLocation(WorkspaceID workspaceID, + WorkspaceIndex spectrum) const { auto fitDomainIndex = m_fitDataModel->getDomainIndex(workspaceID, spectrum); if (!m_fitOutput->isEmpty() && m_fitDataModel->getNumberOfWorkspaces() > workspaceID) return m_fitOutput->getResultLocation(fitDomainIndex); - return boost::none; + return std::nullopt; } WorkspaceGroup_sptr FittingModel::getResultWorkspace() const { return m_fitOutput->getLastResultWorkspace(); } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h index 4d6a2a98989d..7197f5940aaf 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h @@ -18,8 +18,7 @@ #include "MantidQtWidgets/Common/FunctionModelSpectra.h" #include "MantidQtWidgets/Common/UserInputValidator.h" -#include -#include +#include namespace MantidQt { namespace CustomInterfaces { @@ -47,7 +46,7 @@ class MANTIDQT_INELASTIC_DLL FittingModel : public IFittingModel { FittingModel(); virtual ~FittingModel() = default; - void validate(UserInputValidator &validator) const; + void validate(UserInputValidator &validator) const override; // Functions that interact with FitDataModel void clearWorkspaces() override; @@ -58,7 +57,7 @@ class MANTIDQT_INELASTIC_DLL FittingModel : public IFittingModel { // IFittingModel bool isPreviouslyFit(WorkspaceID workspaceID, WorkspaceIndex spectrum) const override; - virtual boost::optional isInvalidFunction() const override; + virtual std::optional isInvalidFunction() const override; std::vector getFitParameterNames() const override; void setFitFunction(Mantid::API::MultiDomainFunction_sptr function) override; void setFWHM(double fwhm, WorkspaceID WorkspaceID) override; @@ -80,7 +79,7 @@ class MANTIDQT_INELASTIC_DLL FittingModel : public IFittingModel { FittingMode getFittingMode() const override; void updateFitTypeString() override; - boost::optional getResultLocation(WorkspaceID workspaceID, WorkspaceIndex spectrum) const override; + std::optional getResultLocation(WorkspaceID workspaceID, WorkspaceIndex spectrum) const override; Mantid::API::WorkspaceGroup_sptr getResultWorkspace() const override; Mantid::API::WorkspaceGroup_sptr getResultGroup() const override; Mantid::API::IAlgorithm_sptr getFittingAlgorithm(FittingMode mode) const override; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp index 843d812548a3..542d4d8f46bd 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp @@ -6,14 +6,15 @@ // SPDX - License - Identifier: GPL - 3.0 + #include "FittingPresenter.h" #include "FitTab.h" +#include "FittingModel.h" #include "IFitOutput.h" #include "InelasticFitPropertyBrowser.h" namespace MantidQt::CustomInterfaces::Inelastic { -FittingPresenter::FittingPresenter(IFitTab *tab, InelasticFitPropertyBrowser *browser, - std::unique_ptr model, - std::unique_ptr algorithmRunner) +FittingPresenter::FittingPresenter(IFitTab *tab, IInelasticFitPropertyBrowser *browser, + std::unique_ptr model, + std::unique_ptr algorithmRunner) : m_tab(tab), m_fitPropertyBrowser(browser), m_model(std::move(model)), m_algorithmRunner(std::move(algorithmRunner)) { m_fitPropertyBrowser->subscribePresenter(this); @@ -131,7 +132,6 @@ void FittingPresenter::updateFitBrowserParameterValues(const std::unordered_map< void FittingPresenter::updateFitBrowserParameterValuesFromAlg(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm) { updateFitBrowserParameterValues(); if (fittingAlgorithm) { - QSignalBlocker blocker(m_fitPropertyBrowser); if (m_model->getFittingMode() == FittingMode::SEQUENTIAL) { auto const paramWsName = fittingAlgorithm->getPropertyValue("OutputParameterWorkspace"); auto paramWs = AnalysisDataService::Instance().retrieveWS(paramWsName); diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h index 43c496d6207f..2bd76042b8e5 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.h @@ -7,7 +7,9 @@ #pragma once #include "DllConfig.h" -#include "FittingModel.h" +#include "IFitOutput.h" +#include "IFittingModel.h" +#include "ParameterEstimation.h" #include "MantidAPI/AlgorithmRuntimeProps.h" #include "MantidAPI/IAlgorithm.h" @@ -15,6 +17,7 @@ #include "MantidAPI/WorkspaceGroup.h" #include "MantidQtWidgets/Common/AlgorithmRunner.h" #include "MantidQtWidgets/Common/ConfiguredAlgorithm.h" +#include "MantidQtWidgets/Common/FunctionModelDataset.h" #include "MantidQtWidgets/Common/IAlgorithmRunnerSubscriber.h" #include "MantidQtWidgets/Common/UserInputValidator.h" @@ -32,7 +35,7 @@ class IFitDataModel; class IFitPlotModel; class IFitOutput; class IFitTab; -class InelasticFitPropertyBrowser; +class IInelasticFitPropertyBrowser; class MANTIDQT_INELASTIC_DLL IFittingPresenter { public: @@ -42,8 +45,8 @@ class MANTIDQT_INELASTIC_DLL IFittingPresenter { class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter, public MantidQt::API::IAlgorithmRunnerSubscriber { public: - FittingPresenter(IFitTab *tab, InelasticFitPropertyBrowser *browser, std::unique_ptr model, - std::unique_ptr algorithmRunner); + FittingPresenter(IFitTab *tab, IInelasticFitPropertyBrowser *browser, std::unique_ptr model, + std::unique_ptr algorithmRunner); void notifyFunctionChanged() override; @@ -95,9 +98,9 @@ class MANTIDQT_INELASTIC_DLL FittingPresenter : public IFittingPresenter, void updateFitStatus(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm); IFitTab *m_tab; - InelasticFitPropertyBrowser *m_fitPropertyBrowser; - std::unique_ptr m_model; - std::unique_ptr m_algorithmRunner; + IInelasticFitPropertyBrowser *m_fitPropertyBrowser; + std::unique_ptr m_model; + std::unique_ptr m_algorithmRunner; }; } // namespace Inelastic diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/IFitOutput.h b/qt/scientific_interfaces/Inelastic/QENSFitting/IFitOutput.h index cf0394e667d6..4005f66280e5 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/IFitOutput.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/IFitOutput.h @@ -7,13 +7,13 @@ #pragma once #include "DllConfig.h" +#include "MantidAPI/IAlgorithm.h" +#include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/WorkspaceGroup.h" #include "MantidQtWidgets/Common/IndexTypes.h" -#include "MantidAPI/ITableWorkspace.h" - -#include "MantidAPI/IAlgorithm.h" +#include namespace MantidQt { namespace CustomInterfaces { @@ -45,7 +45,7 @@ class MANTIDQT_INELASTIC_DLL IFitOutput { virtual std::unordered_map getParameters(FitDomainIndex index) const = 0; - virtual boost::optional getResultLocation(FitDomainIndex index) const = 0; + virtual std::optional getResultLocation(FitDomainIndex index) const = 0; virtual std::vector getResultParameterNames() const = 0; virtual Mantid::API::WorkspaceGroup_sptr getLastResultWorkspace() const = 0; virtual Mantid::API::WorkspaceGroup_sptr getLastResultGroup() const = 0; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h index d0a906997461..df20d001f506 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/IFittingModel.h @@ -7,9 +7,13 @@ #pragma once #include "DllConfig.h" +#include "IFitOutput.h" #include "MantidAPI/IFunction_fwd.h" #include "MantidQtWidgets/Common/FittingMode.h" #include "MantidQtWidgets/Common/IndexTypes.h" +#include "MantidQtWidgets/Common/UserInputValidator.h" + +#include namespace MantidQt { namespace CustomInterfaces { @@ -28,7 +32,7 @@ class MANTIDQT_INELASTIC_DLL IFittingModel { public: virtual ~IFittingModel(){}; virtual bool isPreviouslyFit(WorkspaceID workspaceID, WorkspaceIndex spectrum) const = 0; - virtual boost::optional isInvalidFunction() const = 0; + virtual std::optional isInvalidFunction() const = 0; virtual std::vector getFitParameterNames() const = 0; virtual Mantid::API::MultiDomainFunction_sptr getFitFunction() const = 0; virtual std::unordered_map getParameterValues(WorkspaceID workspaceID, @@ -44,6 +48,8 @@ class MANTIDQT_INELASTIC_DLL IFittingModel { WorkspaceIndex spectrum) const = 0; virtual std::unordered_map getDefaultParameters(WorkspaceID workspaceID) const = 0; + virtual void validate(MantidQt::CustomInterfaces::UserInputValidator &validator) const = 0; + // Functions that interact with FitDataModel virtual void clearWorkspaces() = 0; virtual Mantid::API::MatrixWorkspace_sptr getWorkspace(WorkspaceID workspaceID) const = 0; @@ -59,8 +65,8 @@ class MANTIDQT_INELASTIC_DLL IFittingModel { virtual FittingMode getFittingMode() const = 0; virtual void updateFitTypeString() = 0; - virtual boost::optional getResultLocation(WorkspaceID workspaceID, - WorkspaceIndex spectrum) const = 0; + virtual std::optional getResultLocation(WorkspaceID workspaceID, + WorkspaceIndex spectrum) const = 0; virtual Mantid::API::WorkspaceGroup_sptr getResultWorkspace() const = 0; virtual Mantid::API::WorkspaceGroup_sptr getResultGroup() const = 0; virtual Mantid::API::IAlgorithm_sptr getFittingAlgorithm(FittingMode mode) const = 0; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/InelasticFitPropertyBrowser.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/InelasticFitPropertyBrowser.cpp index 8f7757ab675f..278983a6147a 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/InelasticFitPropertyBrowser.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/InelasticFitPropertyBrowser.cpp @@ -294,10 +294,12 @@ int InelasticFitPropertyBrowser::getNumberOfDatasets() const { } void InelasticFitPropertyBrowser::updateParameters(const IFunction &fun) { + this->blockSignals(true); if (isFullFunctionBrowserActive()) m_functionBrowser->updateParameters(fun); else m_templatePresenter->updateParameters(fun); + this->blockSignals(false); } void InelasticFitPropertyBrowser::updateFunctionListInBrowser( @@ -306,17 +308,21 @@ void InelasticFitPropertyBrowser::updateFunctionListInBrowser( } void InelasticFitPropertyBrowser::updateMultiDatasetParameters(const IFunction &fun) { + this->blockSignals(true); if (isFullFunctionBrowserActive()) m_functionBrowser->updateMultiDatasetParameters(fun); else m_templatePresenter->updateMultiDatasetParameters(fun); + this->blockSignals(false); } void InelasticFitPropertyBrowser::updateMultiDatasetParameters(const ITableWorkspace ¶mTable) { + this->blockSignals(true); if (isFullFunctionBrowserActive()) m_functionBrowser->updateMultiDatasetParameters(paramTable); else m_templatePresenter->updateMultiDatasetParameters(paramTable); + this->blockSignals(false); } void InelasticFitPropertyBrowser::updateFitStatusData(const std::vector &status, diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/InelasticFitPropertyBrowser.h b/qt/scientific_interfaces/Inelastic/QENSFitting/InelasticFitPropertyBrowser.h index 4f01b8c2f3f6..2adf8d26bcdd 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/InelasticFitPropertyBrowser.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/InelasticFitPropertyBrowser.h @@ -47,7 +47,34 @@ class IFittingPresenter; class MANTIDQT_INELASTIC_DLL IInelasticFitPropertyBrowser { public: virtual ~IInelasticFitPropertyBrowser() = default; + + virtual void subscribePresenter(IFittingPresenter *presenter) = 0; + + virtual MultiDomainFunction_sptr getFitFunction() const = 0; + virtual std::string minimizer(bool withProperties = false) const = 0; + + virtual std::unique_ptr fitProperties(FittingMode const &fittingMode) const = 0; + + virtual void setFitEnabled(bool enable) = 0; + virtual void setCurrentDataset(FitDomainIndex i) = 0; + virtual void setErrorsEnabled(bool enabled) = 0; + virtual void setBackgroundA0(double value) = 0; + + virtual EstimationDataSelector getEstimationDataSelector() const = 0; + virtual void updateParameterEstimationData(DataForParameterEstimationCollection &&data) = 0; + virtual void estimateFunctionParameters() = 0; + + virtual FittingMode getFittingMode() const = 0; + + virtual void updateParameters(const IFunction &fun) = 0; + virtual void updateMultiDatasetParameters(const IFunction &fun) = 0; + virtual void updateMultiDatasetParameters(const ITableWorkspace ¶ms) = 0; + virtual void updateFunctionListInBrowser(const std::map &functionStrings) = 0; + virtual void updateFunctionBrowserData(int nData, const QList &datasets, + const std::vector &qValues, + const std::vector> &fitResolutions) = 0; + virtual void updateFitStatusData(const std::vector &status, const std::vector &chiSquared) = 0; }; class MANTIDQT_INELASTIC_DLL InelasticFitPropertyBrowser : public QDockWidget, public IInelasticFitPropertyBrowser { Q_OBJECT @@ -55,15 +82,15 @@ class MANTIDQT_INELASTIC_DLL InelasticFitPropertyBrowser : public QDockWidget, p public: InelasticFitPropertyBrowser(QWidget *parent = nullptr); - void subscribePresenter(IFittingPresenter *presenter); + void subscribePresenter(IFittingPresenter *presenter) override; void init(); void setFunctionTemplatePresenter(std::unique_ptr templatePresenter); void setFunction(std::string const &funStr); int getNumberOfDatasets() const; QString getSingleFunctionStr() const; - MultiDomainFunction_sptr getFitFunction() const; - std::string minimizer(bool withProperties = false) const; + MultiDomainFunction_sptr getFitFunction() const override; + std::string minimizer(bool withProperties = false) const override; int maxIterations() const; int getPeakRadius() const; std::string costFunction() const; @@ -72,27 +99,27 @@ class MANTIDQT_INELASTIC_DLL InelasticFitPropertyBrowser : public QDockWidget, p std::string fitEvaluationType() const; std::string fitType() const; bool ignoreInvalidData() const; - std::unique_ptr fitProperties(FittingMode const &fittingMode) const; - void updateParameters(const IFunction &fun); - void updateMultiDatasetParameters(const IFunction &fun); - void updateMultiDatasetParameters(const ITableWorkspace ¶ms); + std::unique_ptr fitProperties(FittingMode const &fittingMode) const override; + void updateParameters(const IFunction &fun) override; + void updateMultiDatasetParameters(const IFunction &fun) override; + void updateMultiDatasetParameters(const ITableWorkspace ¶ms) override; void updateFitStatus(const FitDomainIndex index); - void updateFitStatusData(const std::vector &status, const std::vector &chiSquared); - FittingMode getFittingMode() const; + void updateFitStatusData(const std::vector &status, const std::vector &chiSquared) override; + FittingMode getFittingMode() const override; void setConvolveMembers(bool convolveEnabled); void setOutputCompositeMembers(bool outputEnabled); - void setFitEnabled(bool enable); - void setCurrentDataset(FitDomainIndex i); + void setFitEnabled(bool enable) override; + void setCurrentDataset(FitDomainIndex i) override; FitDomainIndex currentDataset() const; void updateFunctionBrowserData(int nData, const QList &datasets, const std::vector &qValues, - const std::vector> &fitResolutions); + const std::vector> &fitResolutions) override; void updatePlotGuess(const MatrixWorkspace_const_sptr &sampleWorkspace); - void setErrorsEnabled(bool enabled); - EstimationDataSelector getEstimationDataSelector() const; - void updateParameterEstimationData(DataForParameterEstimationCollection &&data); - void estimateFunctionParameters(); - void setBackgroundA0(double value); + void setErrorsEnabled(bool enabled) override; + EstimationDataSelector getEstimationDataSelector() const override; + void updateParameterEstimationData(DataForParameterEstimationCollection &&data) override; + void estimateFunctionParameters() override; + void setBackgroundA0(double value) override; void setHiddenProperties(const std::vector &); void updateFunctionListInBrowser(const std::map &functionStrings) override; diff --git a/qt/scientific_interfaces/Inelastic/test/QENSFitting/CMakeLists.txt b/qt/scientific_interfaces/Inelastic/test/QENSFitting/CMakeLists.txt index 263231a6ceac..3ffd4a8baab5 100644 --- a/qt/scientific_interfaces/Inelastic/test/QENSFitting/CMakeLists.txt +++ b/qt/scientific_interfaces/Inelastic/test/QENSFitting/CMakeLists.txt @@ -14,8 +14,9 @@ set(TEST_FILES FitOutputOptionsPresenterTest.h FitPlotModelTest.h FitPlotPresenterTest.h - InelasticFitPropertyBrowserTest.h FittingModelTest.h + FittingPresenterTest.h + InelasticFitPropertyBrowserTest.h IqtFitModelTest.h ParameterEstimationTest.h ) diff --git a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FittingModelTest.h b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FittingModelTest.h index a944f7732a9d..1eb3183a16f7 100644 --- a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FittingModelTest.h +++ b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FittingModelTest.h @@ -384,7 +384,7 @@ class FittingModelTest : public CxxTest::TestSuite { void test_getResultLocation_returns_none_when_out_of_index() { addInstrumentWorkspaceToModel("__ConvFit", 6, 5, "0-5"); addFitOutputDataToModel(); - TS_ASSERT_EQUALS(m_model->getResultLocation(WorkspaceID{1}, WorkspaceIndex{0}), boost::none); + TS_ASSERT(!m_model->getResultLocation(WorkspaceID{1}, WorkspaceIndex{0})); } void test_getResultWorkspace_does_not_throw() { diff --git a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FittingPresenterTest.h b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FittingPresenterTest.h new file mode 100644 index 000000000000..0e0761e40e6e --- /dev/null +++ b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FittingPresenterTest.h @@ -0,0 +1,45 @@ +// Mantid Repository : https://github.com/mantidproject/mantid +// +// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, +// NScD Oak Ridge National Laboratory, European Spallation Source, +// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS +// SPDX - License - Identifier: GPL - 3.0 + +#pragma once + +#include +#include + +#include "MantidQtWidgets/Common/MockAlgorithmRunner.h" +#include "MockObjects.h" +#include "QENSFitting/FittingPresenter.h" + +#include + +using namespace testing; + +class FittingPresenterTest : public CxxTest::TestSuite { +public: + static FittingPresenterTest *createSuite() { return new FittingPresenterTest(); } + + static void destroySuite(FittingPresenterTest *suite) { delete suite; } + + void setUp() override { + m_tab = std::make_unique>(); + auto model = std::make_unique>(); + m_model = model.get(); + m_browser = std::make_unique>(); + auto algorithmRunner = std::make_unique>(); + m_algorithmRunner = algorithmRunner.get(); + m_presenter = + std::make_unique(m_tab.get(), m_browser.get(), std::move(model), std::move(algorithmRunner)); + } + + void test_1() {} + +private: + std::unique_ptr> m_tab; + NiceMock *m_model; + std::unique_ptr> m_browser; + NiceMock *m_algorithmRunner; + std::unique_ptr m_presenter; +}; diff --git a/qt/scientific_interfaces/Inelastic/test/QENSFitting/MockObjects.h b/qt/scientific_interfaces/Inelastic/test/QENSFitting/MockObjects.h index fb7e0c4137f0..293044d456a1 100644 --- a/qt/scientific_interfaces/Inelastic/test/QENSFitting/MockObjects.h +++ b/qt/scientific_interfaces/Inelastic/test/QENSFitting/MockObjects.h @@ -23,10 +23,12 @@ #include "QENSFitting/IFitOutputOptionsModel.h" #include "QENSFitting/IFitOutputOptionsView.h" #include "QENSFitting/IFitPlotView.h" +#include "QENSFitting/IFittingModel.h" #include "QENSFitting/InelasticFitPropertyBrowser.h" #include "MantidAPI/IFunction_fwd.h" #include "MantidKernel/WarningSuppressions.h" +#include "MantidQtWidgets/Common/FunctionModelDataset.h" #include "MantidQtWidgets/Common/FunctionModelSpectra.h" #include "MantidQtWidgets/Common/IAddWorkspaceDialog.h" #include "MantidQtWidgets/Common/UserInputValidator.h" @@ -229,6 +231,55 @@ class MockFitOutputOptionsModel : public IFitOutputOptionsModel { void(std::string const &inputName, std::string const &singleBinName, std::string const &outputName)); }; +class MockFittingModel : public IFittingModel { +public: + MOCK_CONST_METHOD2(isPreviouslyFit, bool(WorkspaceID workspaceID, WorkspaceIndex spectrum)); + MOCK_CONST_METHOD0(isInvalidFunction, std::optional()); + MOCK_CONST_METHOD0(getFitParameterNames, std::vector()); + MOCK_CONST_METHOD0(getFitFunction, Mantid::API::MultiDomainFunction_sptr()); + MOCK_CONST_METHOD2(getParameterValues, + std::unordered_map(WorkspaceID workspaceID, WorkspaceIndex spectrum)); + + MOCK_METHOD1(setFitFunction, void(Mantid::API::MultiDomainFunction_sptr function)); + MOCK_METHOD2(setFWHM, void(double fwhm, WorkspaceID WorkspaceID)); + MOCK_METHOD2(setBackground, void(double fwhm, WorkspaceID WorkspaceID)); + MOCK_METHOD3(setDefaultParameterValue, void(const std::string &name, double value, WorkspaceID workspaceID)); + + MOCK_CONST_METHOD2(getFitParameters, + std::unordered_map(WorkspaceID workspaceID, WorkspaceIndex spectrum)); + MOCK_CONST_METHOD1(getDefaultParameters, std::unordered_map(WorkspaceID workspaceID)); + + MOCK_CONST_METHOD1(validate, void(MantidQt::CustomInterfaces::UserInputValidator &validator)); + + MOCK_METHOD0(clearWorkspaces, void()); + MOCK_CONST_METHOD1(getWorkspace, Mantid::API::MatrixWorkspace_sptr(WorkspaceID workspaceID)); + MOCK_CONST_METHOD0(getNumberOfWorkspaces, WorkspaceID()); + MOCK_CONST_METHOD0(isMultiFit, bool()); + + MOCK_METHOD1(addOutput, void(Mantid::API::IAlgorithm_sptr fitAlgorithm)); + MOCK_CONST_METHOD0(getFitOutput, IFitOutput *()); + + MOCK_METHOD1(setFittingMode, void(FittingMode mode)); + MOCK_CONST_METHOD0(getFittingMode, FittingMode()); + + MOCK_METHOD0(updateFitTypeString, void()); + MOCK_CONST_METHOD2(getResultLocation, + std::optional(WorkspaceID workspaceID, WorkspaceIndex spectrum)); + MOCK_CONST_METHOD0(getResultWorkspace, Mantid::API::WorkspaceGroup_sptr()); + MOCK_CONST_METHOD0(getResultGroup, Mantid::API::WorkspaceGroup_sptr()); + MOCK_CONST_METHOD1(getFittingAlgorithm, Mantid::API::IAlgorithm_sptr(FittingMode mode)); + MOCK_CONST_METHOD0(getSingleFittingAlgorithm, Mantid::API::IAlgorithm_sptr()); + MOCK_CONST_METHOD2(getSingleFunction, Mantid::API::IFunction_sptr(WorkspaceID workspaceID, WorkspaceIndex spectrum)); + MOCK_CONST_METHOD0(getOutputBasename, std::string()); + + MOCK_METHOD1(cleanFailedRun, void(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm)); + MOCK_METHOD0(removeFittingData, void()); + MOCK_METHOD0(addDefaultParameters, void()); + MOCK_METHOD0(removeDefaultParameters, void()); + MOCK_CONST_METHOD0(getFitDataModel, IFitDataModel *()); + MOCK_CONST_METHOD0(getFitPlotModel, IFitPlotModel *()); +}; + class MockFitDataModel : public IFitDataModel { public: virtual ~MockFitDataModel() = default; @@ -402,7 +453,28 @@ class MockInelasticFitPropertyBrowser : public IInelasticFitPropertyBrowser { public: virtual ~MockInelasticFitPropertyBrowser() = default; + MOCK_METHOD1(subscribePresenter, void(IFittingPresenter *presenter)); + MOCK_CONST_METHOD0(getFitFunction, Mantid::API::MultiDomainFunction_sptr()); + MOCK_CONST_METHOD1(minimizer, std::string(bool withProperties)); + MOCK_CONST_METHOD1(fitProperties, + std::unique_ptr(FittingMode const &fittingMode)); + MOCK_METHOD1(setFitEnabled, void(bool enable)); + MOCK_METHOD1(setCurrentDataset, void(FitDomainIndex i)); + MOCK_METHOD1(setErrorsEnabled, void(bool enabled)); + MOCK_METHOD1(setBackgroundA0, void(double value)); + MOCK_CONST_METHOD0(getEstimationDataSelector, EstimationDataSelector()); + MOCK_METHOD1(updateParameterEstimationData, void(DataForParameterEstimationCollection &&data)); + MOCK_METHOD0(estimateFunctionParameters, void()); + MOCK_CONST_METHOD0(getFittingMode, FittingMode()); + MOCK_METHOD1(updateParameters, void(const IFunction &fun)); + MOCK_METHOD1(updateMultiDatasetParameters, void(const IFunction &fun)); + MOCK_METHOD1(updateMultiDatasetParameters, void(const ITableWorkspace ¶ms)); MOCK_METHOD1(updateFunctionListInBrowser, void(const std::map &functionStrings)); + MOCK_METHOD4(updateFunctionBrowserData, + void(int nData, const QList &datasets, const std::vector &qValues, + const std::vector> &fitResolutions)); + MOCK_METHOD2(updateFitStatusData, + void(const std::vector &status, const std::vector &chiSquared)); }; class MockElwinView : public IElwinView { From 1e046a71d4ce8b804ce4e5c5557886c2d73d8c67 Mon Sep 17 00:00:00 2001 From: Applin Date: Fri, 3 May 2024 16:22:31 +0100 Subject: [PATCH 44/58] Add tests for FittingPresenter --- .../QENSFitting/FittingPresenter.cpp | 2 +- .../test/QENSFitting/FittingPresenterTest.h | 209 +++++++++++++++++- 2 files changed, 209 insertions(+), 2 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp index 542d4d8f46bd..c4c9dd14950c 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingPresenter.cpp @@ -145,8 +145,8 @@ void FittingPresenter::updateFitBrowserParameterValuesFromAlg(const Mantid::API: else m_fitPropertyBrowser->updateParameters(*fun); } + updateFitStatus(fittingAlgorithm); } - updateFitStatus(fittingAlgorithm); } void FittingPresenter::updateFitStatus(const Mantid::API::IAlgorithm_sptr &fittingAlgorithm) { diff --git a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FittingPresenterTest.h b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FittingPresenterTest.h index 0e0761e40e6e..5143ee4ebe07 100644 --- a/qt/scientific_interfaces/Inelastic/test/QENSFitting/FittingPresenterTest.h +++ b/qt/scientific_interfaces/Inelastic/test/QENSFitting/FittingPresenterTest.h @@ -30,13 +30,220 @@ class FittingPresenterTest : public CxxTest::TestSuite { m_browser = std::make_unique>(); auto algorithmRunner = std::make_unique>(); m_algorithmRunner = algorithmRunner.get(); + m_presenter = std::make_unique(m_tab.get(), m_browser.get(), std::move(model), std::move(algorithmRunner)); } - void test_1() {} + void tearDown() override { + TS_ASSERT(Mock::VerifyAndClearExpectations(m_tab.get())); + TS_ASSERT(Mock::VerifyAndClearExpectations(m_model)); + TS_ASSERT(Mock::VerifyAndClearExpectations(m_browser.get())); + TS_ASSERT(Mock::VerifyAndClearExpectations(m_algorithmRunner)); + + m_presenter.reset(); + m_tab.reset(); + m_browser.reset(); + } + + void test_notifyFunctionChanged_calls_the_tab() { + EXPECT_CALL(*m_tab, handleFunctionChanged()).Times(1); + m_presenter->notifyFunctionChanged(); + } + + void test_validate_calls_the_model_validate() { + UserInputValidator validator; + EXPECT_CALL(*m_model, validate(_)).Times(1); + + m_presenter->validate(validator); + } + + void test_setFitFunction_calls_the_model() { + auto function = std::make_shared(); + EXPECT_CALL(*m_model, setFitFunction(function)).Times(1); + + m_presenter->setFitFunction(function); + } + + void test_setFitEnabled_calls_the_browser() { + EXPECT_CALL(*m_browser, setFitEnabled(true)).Times(1); + m_presenter->setFitEnabled(true); + } + + void test_setCurrentDataset_calls_the_browser() { + auto const domainIndex = FitDomainIndex{1}; + EXPECT_CALL(*m_browser, setCurrentDataset(domainIndex)).Times(1); + + m_presenter->setCurrentDataset(domainIndex); + } + + void test_fitFunction_gets_the_function_from_the_browser() { + std::string minimizerStr("FABADA"); + ON_CALL(*m_browser, minimizer(false)).WillByDefault(Return(minimizerStr)); + + TS_ASSERT_EQUALS(minimizerStr, m_presenter->minimizer()); + } + + void test_estimateFunctionParameters_will_not_estimate_if_there_is_a_previous_fit() { + auto workspaceID = WorkspaceID(0); + auto workspaceIndex = WorkspaceIndex(0); + + ON_CALL(*m_model, isPreviouslyFit(workspaceID, workspaceIndex)).WillByDefault(Return(true)); + // Expect not called + EXPECT_CALL(*m_browser, estimateFunctionParameters()).Times(0); + + m_presenter->estimateFunctionParameters(workspaceID, workspaceIndex); + } + + void test_estimateFunctionParameters_will_estimate_if_there_is_not_a_previous_fit() { + auto workspaceID = WorkspaceID(0); + auto workspaceIndex = WorkspaceIndex(0); + + ON_CALL(*m_model, isPreviouslyFit(workspaceID, workspaceIndex)).WillByDefault(Return(false)); + EXPECT_CALL(*m_browser, estimateFunctionParameters()).Times(1); + + m_presenter->estimateFunctionParameters(workspaceID, workspaceIndex); + } + + void test_removeFittingData_calls_the_model() { + EXPECT_CALL(*m_model, removeFittingData()).Times(1); + m_presenter->removeFittingData(); + } + + void test_addDefaultParameters_calls_the_model() { + EXPECT_CALL(*m_model, addDefaultParameters()).Times(1); + m_presenter->addDefaultParameters(); + } + + void test_removeDefaultParameters_calls_the_model() { + EXPECT_CALL(*m_model, removeDefaultParameters()).Times(1); + m_presenter->removeDefaultParameters(); + } + + void test_runFit_sets_fitting_mode_and_gets_fitting_algorithm() { + FittingMode fittingMode = FittingMode::SIMULTANEOUS; + + EXPECT_CALL(*m_browser, getFittingMode()).Times(1).WillOnce(Return(fittingMode)); + EXPECT_CALL(*m_model, setFittingMode(fittingMode)).Times(1); + EXPECT_CALL(*m_model, getFittingAlgorithm(fittingMode)).Times(1); + mockExecuteFit(); + + m_presenter->runFit(); + } + + void test_runSingleFit_sets_fitting_mode_and_gets_single_fitting_algorithm() { + FittingMode fittingMode = FittingMode::SIMULTANEOUS; + + EXPECT_CALL(*m_model, setFittingMode(fittingMode)).Times(1); + EXPECT_CALL(*m_model, getSingleFittingAlgorithm()).Times(1); + mockExecuteFit(); + + m_presenter->runSingleFit(); + } + + void test_getResultWorkspace_calls_model_and_returns_result() { + Mantid::API::WorkspaceGroup_sptr expectedResult = std::make_shared(); + + EXPECT_CALL(*m_model, getResultWorkspace()).Times(1).WillOnce(Return(expectedResult)); + + auto result = m_presenter->getResultWorkspace(); + + TS_ASSERT_EQUALS(result, expectedResult); + } + + void test_getOutputBasename_calls_model_and_returns_output_basename() { + std::string expectedOutputBasename = "output_basename"; + + EXPECT_CALL(*m_model, getOutputBasename()).Times(1).WillOnce(Return(expectedOutputBasename)); + + auto outputBasename = m_presenter->getOutputBasename(); + + TS_ASSERT_EQUALS(outputBasename, expectedOutputBasename); + } + + void test_getFitDataModel_calls_model_and_returns_fit_data_model() { + IFitDataModel *expectedFitDataModel = nullptr; + + EXPECT_CALL(*m_model, getFitDataModel()).Times(1).WillOnce(Return(expectedFitDataModel)); + + auto fitDataModel = m_presenter->getFitDataModel(); + + TS_ASSERT_EQUALS(fitDataModel, expectedFitDataModel); + } + + void test_getFitPlotModel_calls_model_and_returns_fit_plot_model() { + IFitPlotModel *expectedFitPlotModel = nullptr; + + EXPECT_CALL(*m_model, getFitPlotModel()).Times(1).WillOnce(Return(expectedFitPlotModel)); + + auto fitPlotModel = m_presenter->getFitPlotModel(); + + TS_ASSERT_EQUALS(fitPlotModel, expectedFitPlotModel); + } + + void test_isPreviouslyFit_calls_model_and_returns_result() { + WorkspaceID workspaceID{0}; + WorkspaceIndex spectrum{1}; + bool expectedResult = true; + + EXPECT_CALL(*m_model, isPreviouslyFit(workspaceID, spectrum)).Times(1).WillOnce(Return(expectedResult)); + + TS_ASSERT_EQUALS(expectedResult, m_presenter->isPreviouslyFit(workspaceID, spectrum)); + } + + void test_setFWHM_calls_model_with_correct_arguments() { + WorkspaceID workspaceID{0}; + double fwhm = 1.0; + + EXPECT_CALL(*m_model, setFWHM(fwhm, workspaceID)).Times(1); + + m_presenter->setFWHM(workspaceID, fwhm); + } + + void test_setBackground_calls_model_and_browser_with_correct_arguments() { + WorkspaceID workspaceID{0}; + double background = 0.5; + + EXPECT_CALL(*m_model, setBackground(background, workspaceID)).Times(1); + EXPECT_CALL(*m_browser, setBackgroundA0(background)).Times(1); + + m_presenter->setBackground(workspaceID, background); + } + + void test_notifyBatchComplete_with_no_error() { + auto properties = std::make_unique(); + MantidQt::API::IConfiguredAlgorithm_sptr configuredAlgorithm = + std::make_shared(nullptr, std::move(properties)); + + EXPECT_CALL(*m_browser, setErrorsEnabled(true)).Times(1); + EXPECT_CALL(*m_model, setFitFunction(_)).Times(1); + EXPECT_CALL(*m_model, addOutput(_)).Times(1); + EXPECT_CALL(*m_tab, handleFitComplete(false)).Times(1); + + m_presenter->notifyBatchComplete(configuredAlgorithm, false); + } + + void test_notifyBatchComplete_with_error() { + auto properties = std::make_unique(); + MantidQt::API::IConfiguredAlgorithm_sptr configuredAlgorithm = + std::make_shared(nullptr, std::move(properties)); + + EXPECT_CALL(*m_browser, setErrorsEnabled(false)).Times(1); + EXPECT_CALL(*m_model, cleanFailedRun(_)).Times(1); + EXPECT_CALL(*m_tab, handleFitComplete(true)).Times(1); + + m_presenter->notifyBatchComplete(configuredAlgorithm, true); + } private: + void mockExecuteFit() { + ON_CALL(*m_model, getFittingMode()).WillByDefault(Return(FittingMode::SIMULTANEOUS)); + auto properties = std::make_unique(); + + EXPECT_CALL(*m_browser, fitProperties(FittingMode::SIMULTANEOUS)).WillOnce(Return(ByMove(std::move(properties)))); + EXPECT_CALL(*m_algorithmRunner, execute(A())).Times(1); + } + std::unique_ptr> m_tab; NiceMock *m_model; std::unique_ptr> m_browser; From 112e833968147a947850ebd19ab0cde77413103d Mon Sep 17 00:00:00 2001 From: Applin Date: Tue, 7 May 2024 16:08:53 +0100 Subject: [PATCH 45/58] Fix non-virtual destructor and other warnings --- .../Inelastic/QENSFitting/FitPlotModel.cpp | 2 -- .../Inelastic/QENSFitting/FitPlotModel.h | 5 +++-- .../Inelastic/QENSFitting/FittingModel.cpp | 5 +++-- .../Inelastic/QENSFitting/FittingModel.h | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp index f98f38efe94e..16ac81676bcc 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.cpp @@ -87,8 +87,6 @@ FitPlotModel::FitPlotModel(std::vector *fittingData, IFitOutput *fitOut : m_fittingData(fittingData), m_fitOutput(fitOutput), m_activeWorkspaceID{0}, m_activeWorkspaceIndex{0}, m_activeFunction() {} -FitPlotModel::~FitPlotModel() {} - void FitPlotModel::setActiveIndex(WorkspaceID workspaceID) { m_activeWorkspaceID = workspaceID; } void FitPlotModel::setActiveSpectrum(WorkspaceIndex spectrum) { m_activeWorkspaceIndex = spectrum; } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h index 9d0642af5d9e..a39c2ee7e080 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FitPlotModel.h @@ -25,6 +25,8 @@ using namespace MantidWidgets; class MANTIDQT_INELASTIC_DLL IFitPlotModel { public: + virtual ~IFitPlotModel() = default; + virtual Mantid::API::MatrixWorkspace_sptr getWorkspace() const = 0; virtual Mantid::API::MatrixWorkspace_sptr getResultWorkspace() const = 0; virtual Mantid::API::MatrixWorkspace_sptr getGuessWorkspace() const = 0; @@ -50,10 +52,9 @@ class MANTIDQT_INELASTIC_DLL IFitPlotModel { virtual void setFitFunction(Mantid::API::MultiDomainFunction_sptr function) = 0; }; -class MANTIDQT_INELASTIC_DLL FitPlotModel : public IFitPlotModel { +class MANTIDQT_INELASTIC_DLL FitPlotModel final : public IFitPlotModel { public: FitPlotModel(std::vector *fittingData, IFitOutput *fitOutput); - ~FitPlotModel(); Mantid::API::MatrixWorkspace_sptr getWorkspace() const override; Mantid::API::MatrixWorkspace_sptr getResultWorkspace() const override; diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp index 3ef307c7e81e..9a26f073828e 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.cpp @@ -308,8 +308,9 @@ std::unordered_map fitModeToName = std::unordered_map< {{FittingMode::SEQUENTIAL, "Seq"}, {FittingMode::SIMULTANEOUS, "Sim"}}); FittingModel::FittingModel() - : m_fitDataModel(std::make_unique()), m_fitPlotModel(), m_fitOutput(std::make_unique()), - m_previousModelSelected(false), m_fittingMode(FittingMode::SEQUENTIAL) { + : m_fitType("FitType"), m_fitString("FitString"), m_fitDataModel(std::make_unique()), + m_fitPlotModel(), m_previousModelSelected(false), m_fittingMode(FittingMode::SEQUENTIAL), + m_fitOutput(std::make_unique()), m_activeFunction(), m_fitFunction(), m_defaultParameters() { m_fitPlotModel = std::make_unique(m_fitDataModel->getFittingData(), m_fitOutput.get()); } diff --git a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h index 7197f5940aaf..c6d5bb706055 100644 --- a/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h +++ b/qt/scientific_interfaces/Inelastic/QENSFitting/FittingModel.h @@ -104,8 +104,8 @@ class MANTIDQT_INELASTIC_DLL FittingModel : public IFittingModel { Mantid::API::IAlgorithm_sptr createSimultaneousFit(const Mantid::API::MultiDomainFunction_sptr &function) const; virtual Mantid::API::MultiDomainFunction_sptr getMultiDomainFunction() const; virtual std::unordered_map mapDefaultParameterNames() const; - std::string m_fitType = "FitType"; - std::string m_fitString = "FitString"; + std::string m_fitType; + std::string m_fitString; std::unique_ptr m_fitDataModel; std::unique_ptr m_fitPlotModel; From e336403f9fdd7d2ac19eafbceb1068d36c3ff19d Mon Sep 17 00:00:00 2001 From: Ross Whitfield Date: Tue, 14 May 2024 10:42:12 +1000 Subject: [PATCH 46/58] Add log compression option to AlignAndFocusPowder --- .../src/AlignAndFocusPowder.cpp | 44 +++++++++++++++---- .../test/AlignAndFocusPowderTest.h | 34 ++++++++++++++ .../Diffraction/Powder/New_features/37352.rst | 1 + 3 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 docs/source/release/v6.11.0/Diffraction/Powder/New_features/37352.rst diff --git a/Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp b/Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp index 726032fd77ac..661a9ae8fab0 100644 --- a/Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp +++ b/Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp @@ -22,6 +22,7 @@ #include "MantidKernel/ConfigService.h" #include "MantidKernel/DateTimeValidator.h" #include "MantidKernel/EnabledWhenProperty.h" +#include "MantidKernel/EnumeratedString.h" #include "MantidKernel/InstrumentInfo.h" #include "MantidKernel/ListValidator.h" #include "MantidKernel/PropertyManager.h" @@ -70,6 +71,7 @@ const std::string RESONANCE_UPPER_LIMITS("ResonanceFilterUpperLimits"); const std::string COMPRESS_TOF_TOL("CompressTolerance"); const std::string COMPRESS_WALL_TOL("CompressWallClockTolerance"); const std::string COMPRESS_WALL_START("CompressStartTime"); +const std::string COMPRESS_MODE("CompressBinningMode"); const std::string L1("PrimaryFlightPath"); const std::string SPEC_IDS("SpectrumIDs"); const std::string L2("L2"); @@ -89,6 +91,11 @@ void getTofRange(const MatrixWorkspace_const_sptr &wksp, double &tmin, double &t wksp->getXMinMax(tmin, tmax); } } + +const std::vector binningModeNames{"Default", "Linear", "Logarithmic"}; +enum class BinningMode { DEFAULT, LINEAR, LOGARITHMIC, enum_count }; +typedef Mantid::Kernel::EnumeratedString BINMODE; + } // anonymous namespace // Register the class into the algorithm factory @@ -186,17 +193,14 @@ void AlignAndFocusPowder::init() { "Maximum values to filter absorption resonance. This must have same number of values as " "ResonanceFilterLowerLimits. Default behavior is to not filter."); - declareProperty(std::make_unique>(PropertyNames::COMPRESS_TOF_TOL, 1e-5, mustBePositive, - Direction::Input), - "Compress events (in " - "microseconds) within this " - "tolerance. (Default 1e-5)"); + declareProperty(std::make_unique>(PropertyNames::COMPRESS_TOF_TOL, 1e-5, Direction::Input), + "Compress events (in microseconds) within this tolerance. (Default 1e-5). If negative then do " + "logorithmic compression."); declareProperty(std::make_unique>(PropertyNames::COMPRESS_WALL_TOL, EMPTY_DBL(), mustBePositive, Direction::Input), "The tolerance (in seconds) on the wall-clock time for comparison. Unset " "means compressing all wall-clock times together disabling pulsetime " "resolution."); - auto dateValidator = std::make_shared(); dateValidator->allowEmpty(true); declareProperty(PropertyNames::COMPRESS_WALL_START, "", dateValidator, @@ -204,6 +208,10 @@ void AlignAndFocusPowder::init() { "starting filtering. Ignored if WallClockTolerance is not specified. " "Default is start of run", Direction::Input); + declareProperty(PropertyNames::COMPRESS_MODE, binningModeNames[size_t(BinningMode::DEFAULT)], + std::make_shared(binningModeNames), + "Optional. Binning behavior can be specified in the usual way through sign of tolerance " + "('Default'); or can be set to one of the allowed binning modes. "); declareProperty(PropertyNames::LORENTZ, false, "Multiply each spectrum by " "sin(theta) where theta is " @@ -382,8 +390,14 @@ void AlignAndFocusPowder::exec() { tmax = getProperty(PropertyNames::TOF_MAX); m_preserveEvents = getProperty(PropertyNames::PRESERVE_EVENTS); m_resampleX = getProperty(PropertyNames::RESAMPLEX); - const double compressEventsTolerance = getProperty(PropertyNames::COMPRESS_TOF_TOL); + double compressEventsTolerance = getProperty(PropertyNames::COMPRESS_TOF_TOL); const double wallClockTolerance = getProperty(PropertyNames::COMPRESS_WALL_TOL); + const BINMODE mode = getPropertyValue(PropertyNames::COMPRESS_MODE); + if (mode == BinningMode::LINEAR) + compressEventsTolerance = std::fabs(compressEventsTolerance); + else if (mode == BinningMode::LOGARITHMIC) + compressEventsTolerance = -1. * std::fabs(compressEventsTolerance); + // determine some bits about d-space and binning if (m_resampleX != 0) { // ignore the normal rebin parameters @@ -1223,7 +1237,7 @@ bool AlignAndFocusPowder::shouldCompressUnfocused(const double compressTolerance if (hasWallClockTolerance) return false; // compressing isn't an option - if (compressTolerance <= 0) + if (compressTolerance == 0) return false; if (const auto eventWS = std::dynamic_pointer_cast(m_outputW)) { @@ -1242,7 +1256,19 @@ bool AlignAndFocusPowder::shouldCompressUnfocused(const double compressTolerance // assume one frame although this is generically wrong // there are 3 fields in weighted events no time - const double sizeWeightedEventsEstimate = WEIGHTED_NOTIME_EVENT_BYTE_SIZE * tofRange / compressTolerance; + double sizeWeightedEventsEstimate; + if (compressTolerance > 0) // linear + sizeWeightedEventsEstimate = WEIGHTED_NOTIME_EVENT_BYTE_SIZE * tofRange / compressTolerance; + else { // log + if (tofmin_wksp < 0) + return false; // log compression cannot have negative TOF values + + if (tofmin_wksp == 0) + tofmin_wksp = compressTolerance; + + sizeWeightedEventsEstimate = + WEIGHTED_NOTIME_EVENT_BYTE_SIZE * log(tofmax_wksp / tofmin_wksp) / log1p(abs(compressTolerance)); + } double numEvents = static_cast(eventWS->getNumberEvents()); const auto eventType = eventWS->getEventType(); diff --git a/Framework/WorkflowAlgorithms/test/AlignAndFocusPowderTest.h b/Framework/WorkflowAlgorithms/test/AlignAndFocusPowderTest.h index aa3f8eb8fa8a..71937e4c8185 100644 --- a/Framework/WorkflowAlgorithms/test/AlignAndFocusPowderTest.h +++ b/Framework/WorkflowAlgorithms/test/AlignAndFocusPowderTest.h @@ -93,6 +93,8 @@ class AlignAndFocusPowderTest : public CxxTest::TestSuite { AnalysisDataService::Instance().remove(m_inputWS); // Test the output + auto eventWS = std::dynamic_pointer_cast(m_outWS); + TS_ASSERT_EQUALS(eventWS->getNumberEvents(), 870622); // [99] 1920.2339999999983, 41 TS_ASSERT_DELTA(m_outWS->x(0)[99], 1920.23400, 0.0001); TS_ASSERT_EQUALS(m_outWS->y(0)[99], 41.); @@ -421,6 +423,38 @@ class AlignAndFocusPowderTest : public CxxTest::TestSuite { AnalysisDataService::Instance().remove(m_outputWS); } + void testEventWksp_preserveEvents_logCompressTolerance() { + // Setup the event workspace + setUp_EventWorkspace("EventWksp_preserveEvents_logCompressTolerance"); + + // Set the inputs for doTestEventWksp + m_preserveEvents = true; + m_useGroupAll = false; + m_useResamplex = true; + m_compressTolerance = "-1e-5"; + + // Run the main test function + doTestEventWksp(); + + // Reset inputs to default values + m_compressTolerance = "0"; + + // Test the input + docheckEventInputWksp(); + AnalysisDataService::Instance().remove(m_inputWS); + + // Test the output: expected result shall be same as testEventWksp_preserveEvents but have fewer events + auto eventWS = std::dynamic_pointer_cast(m_outWS); + TS_ASSERT_EQUALS(eventWS->getNumberEvents(), 451436); + // [99] 1920.2339999999983, 41 + TS_ASSERT_DELTA(m_outWS->x(0)[99], 1920.23400, 0.0001); + TS_ASSERT_EQUALS(m_outWS->y(0)[99], 41.); + // [899] 673.0, 15013.033999999987 + TS_ASSERT_DELTA(m_outWS->x(0)[899], 15013.03400, 0.0001); + TS_ASSERT_EQUALS(m_outWS->y(0)[899], 673.0); + AnalysisDataService::Instance().remove(m_outputWS); + } + void testEventWksp_preserveEvents_removePromptPulse() { // Setup the event workspace setUp_EventWorkspace("EventWksp_preserveEvents_removePromptPulse"); diff --git a/docs/source/release/v6.11.0/Diffraction/Powder/New_features/37352.rst b/docs/source/release/v6.11.0/Diffraction/Powder/New_features/37352.rst new file mode 100644 index 000000000000..147a1ab0f35c --- /dev/null +++ b/docs/source/release/v6.11.0/Diffraction/Powder/New_features/37352.rst @@ -0,0 +1 @@ +- Added option to :ref:`AlignAndFocusPowder ` to support logarithmic compression From 41f5e262acab3811dc38df1204bc8a8bc1b17e34 Mon Sep 17 00:00:00 2001 From: Jonathan Haigh Date: Mon, 13 May 2024 14:03:30 +0100 Subject: [PATCH 47/58] set doc tests to false on dev docs only --- buildconfig/Jenkins/Conda/conda-buildscript | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/buildconfig/Jenkins/Conda/conda-buildscript b/buildconfig/Jenkins/Conda/conda-buildscript index 9a93777dc521..7c42529de7f1 100755 --- a/buildconfig/Jenkins/Conda/conda-buildscript +++ b/buildconfig/Jenkins/Conda/conda-buildscript @@ -117,10 +117,15 @@ create_and_activate_mantid_developer_env # Check whether this is an incremental build that only changes rst files if [ -d $BUILD_DIR ]; then - if ${SCRIPT_DIR}/../check_for_changes dev-docs-only || ${SCRIPT_DIR}/../check_for_changes user-docs-only; then + if ${SCRIPT_DIR}/../check_for_changes user-docs-only; then ENABLE_BUILD_CODE=false ENABLE_UNIT_TESTS=false ENABLE_SYSTEM_TESTS=false + elif ${SCRIPT_DIR}/../check_for_changes dev-docs-only; then + ENABLE_BUILD_CODE=false + ENABLE_UNIT_TESTS=false + ENABLE_SYSTEM_TESTS=false + ENABLE_DOC_TESTS=false fi rm -rf ${BUILD_DIR}/bin ${BUILD_DIR}/ExternalData ${BUILD_DIR}/Testing find $WORKSPACE \( -iname 'TEST-*.xml' -o -name 'Test.xml' \) -delete From f444b1b370288f77738711851e55749e53620870 Mon Sep 17 00:00:00 2001 From: adriazalvarez Date: Thu, 16 May 2024 15:55:45 +0100 Subject: [PATCH 48/58] Update reduction docs with missing info --- dev-docs/source/Testing/Indirect/DataReductionTests.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dev-docs/source/Testing/Indirect/DataReductionTests.rst b/dev-docs/source/Testing/Indirect/DataReductionTests.rst index 2accb59c69b9..119d0d7c96db 100644 --- a/dev-docs/source/Testing/Indirect/DataReductionTests.rst +++ b/dev-docs/source/Testing/Indirect/DataReductionTests.rst @@ -28,7 +28,7 @@ Data reduction #. Enter ``Input Runs`` 26173 #. Click ``Run`` #. This should generate a workspace with ``_calib`` at the end, delete this workspace -#. Change the ``Scale by factor`` value to 0.5 +#. Check the ``Scale by factor`` checkbox and change the value of the scale to 0.5. #. Click ``Run`` #. This should generate a workspace with ``_calib`` at the end #. Check the ``Create RES`` box @@ -41,6 +41,7 @@ Data reduction #. Make sure that you keep the ``_calib`` workspace, it is needed for the next test #. Enter ``Input Runs`` 59057-59059 and check ``Sum Files`` #. Set ``Reflection`` to 004 +#. Click ``Run`` #. This should produce a new ``_calib`` workspace, with ``004`` in the name. #. Before moving on, set ``Reflection`` to 002 @@ -57,13 +58,13 @@ Data reduction #. Check the ``Use Calib File`` box #. Change ``File`` to ``Workspace`` and choose the ``_calib`` workspace previously created (55878 from the previous test) #. Click ``Run`` -#. In the main GUI right-click on the ``iris26184_multi_graphite002_red`` workspace +#. In the main GUI right-click on the ``iris26184-26185_multi_graphite002_red`` workspace #. Choose ``Plot spectrum``, note the number of spectra, should be 51 #. Click ``Cancel`` #. In the ``Data reduction`` GUI, change the ``Detector Grouping`` to Groups #. Set ``Groups`` to 5 #. Click ``Run`` -#. In the main GUI right-click on the ``iris26184_multi_graphite002_red`` workspace +#. In the main GUI right-click on the ``iris26184-26185_multi_graphite002_red`` workspace #. Choose ``Plot spectrum``, note the number of spectra, should be 6 #. Choose ``Plot All``, this should result in a plot of all 6 spectra #. Open ``Interfaces`` > ``Inelastic`` > ``Data Manipulation`` and go to the ``S(Q, W)`` tab From d1c7b79ff3932a4fceb5af67c67dc97365098dd3 Mon Sep 17 00:00:00 2001 From: adriazalvarez Date: Fri, 17 May 2024 09:40:33 +0100 Subject: [PATCH 49/58] Fix typo in elwin instructions --- dev-docs/source/Testing/Inelastic/DataManipulationTests.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-docs/source/Testing/Inelastic/DataManipulationTests.rst b/dev-docs/source/Testing/Inelastic/DataManipulationTests.rst index 05549d370749..dfc009a55f29 100644 --- a/dev-docs/source/Testing/Inelastic/DataManipulationTests.rst +++ b/dev-docs/source/Testing/Inelastic/DataManipulationTests.rst @@ -31,7 +31,7 @@ Elwin tab #. Add the loaded workspaces #. Click ``Run`` #. This should result in three new workspaces again, this time with file ranges as their name -#. In the main GUI right-click on ``MAR27691-27698_graphite002_red_elwin_eq2`` and choose ``Plot Spectrum``, choose ``Plot All`` +#. In the main GUI right-click on ``MAR27691-27698_red_elwin_eq2`` and choose ``Plot Spectrum``, choose ``Plot All`` #. This should plot two lines of :math:`ln(Counts(microAmp.hour))^{-1}` vs :math:`Q2` .. _elwin_inelastic_test: From d34cc98c3be7452ce5deec6783c004a7a658ca61 Mon Sep 17 00:00:00 2001 From: Conor Finn Date: Wed, 15 May 2024 17:56:15 +0100 Subject: [PATCH 50/58] Clarify file numbers produced RE #37373 --- dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst b/dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst index 7edbc1ba6508..a77e255c6b87 100644 --- a/dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst +++ b/dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst @@ -124,8 +124,9 @@ Processing #. In the workspaces list, there should be a series of new workspaces; four group workspaces and four 1D workspaces. #. Check your default save directory. For each reduction two banks (HAB/main) should - be saved. In total there should be 12 workspaces (6 CanSAS ``.xml`` and 6 NXcanSAS ``.h5``) saved. For each row and - file type there should be a reduced file (with no suffix), a sample, and a can workspace. + be saved. In total there should be 11 workspaces saved. For each row and file type there should be a reduced file + (with no suffix) and a ``sample`` file. The ``first_time`` line should also produce a ``can`` workspace. This is + because both workspaces have the same ``can`` output and so the reduction only produces it once. #. Double-click the 1D workspaces and you should get a single line plot. #. Clear the newly created files and workspaces to make the next test easier #. Change the contents of the first cell in the first row to ``74045`` and click From 9021cb687ecd1a56ea5c5cc99d6a485e94b208c1 Mon Sep 17 00:00:00 2001 From: Conor Finn Date: Thu, 16 May 2024 09:28:28 +0100 Subject: [PATCH 51/58] Fix workspace counts RE #37373 --- dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst b/dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst index a77e255c6b87..219a3fda316e 100644 --- a/dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst +++ b/dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst @@ -124,9 +124,10 @@ Processing #. In the workspaces list, there should be a series of new workspaces; four group workspaces and four 1D workspaces. #. Check your default save directory. For each reduction two banks (HAB/main) should - be saved. In total there should be 11 workspaces saved. For each row and file type there should be a reduced file - (with no suffix) and a ``sample`` file. The ``first_time`` line should also produce a ``can`` workspace. This is - because both workspaces have the same ``can`` output and so the reduction only produces it once. + be saved. In total there should be 20 workspaces saved. For each row, file type, and bank there should be a + reduced file (with no suffix) and a ``sample`` file. The ``first_time`` line should also produce a ``can`` workspace + for each file type and bank. This is because both workspaces have the same ``can`` input run numbers and so the + reduction only calculates it once. #. Double-click the 1D workspaces and you should get a single line plot. #. Clear the newly created files and workspaces to make the next test easier #. Change the contents of the first cell in the first row to ``74045`` and click From f85b698d880b65f334179faf96ea53a0e2aaf8b5 Mon Sep 17 00:00:00 2001 From: Caila Finn <47181718+cailafinn@users.noreply.github.com> Date: Fri, 17 May 2024 10:38:50 +0100 Subject: [PATCH 52/58] Add missing commas Improve the grammar. RE #37373 --- dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst b/dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst index 219a3fda316e..b584db702182 100644 --- a/dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst +++ b/dev-docs/source/Testing/SANSGUI/ISISSANSGUITests.rst @@ -124,7 +124,7 @@ Processing #. In the workspaces list, there should be a series of new workspaces; four group workspaces and four 1D workspaces. #. Check your default save directory. For each reduction two banks (HAB/main) should - be saved. In total there should be 20 workspaces saved. For each row, file type, and bank there should be a + be saved. In total, there should be 20 workspaces saved. For each row, file type, and bank, there should be a reduced file (with no suffix) and a ``sample`` file. The ``first_time`` line should also produce a ``can`` workspace for each file type and bank. This is because both workspaces have the same ``can`` input run numbers and so the reduction only calculates it once. From ac196d0596be24f082a56e47a33bae395d9620ca Mon Sep 17 00:00:00 2001 From: Applin Date: Mon, 20 May 2024 09:14:08 +0100 Subject: [PATCH 53/58] Update FDA testing instructions --- dev-docs/source/Testing/MuonAnalysis_test_guides/Muon_FDA.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-docs/source/Testing/MuonAnalysis_test_guides/Muon_FDA.rst b/dev-docs/source/Testing/MuonAnalysis_test_guides/Muon_FDA.rst index f8dafb57342c..ebf41d929e2b 100644 --- a/dev-docs/source/Testing/MuonAnalysis_test_guides/Muon_FDA.rst +++ b/dev-docs/source/Testing/MuonAnalysis_test_guides/Muon_FDA.rst @@ -23,7 +23,7 @@ FFT Test - Change *Instrument* to **MUSR**, found in the *Home* tab - In the loading bar enter ``62260`` - Go to the **Transform** tab - - Set the workspace to "MUSR00062260; Group; bkwd; Asym; FD" + - Set the workspace to "MUSR00062260; Group; bkwd; Asymmetry; FD" - Click the calculate FFT button and a plot will appear - The plot window will show a broad peak - In the **Fitting** tab it will contain 3 workspace ending in `Re_unit_MHz` (real), `Im_unit_MHz` (imaginary) and `mod_unit_MHz` (modulus) @@ -36,7 +36,7 @@ FFT Test - The "padding" adds zeros to the end of the time domain data set, to improve the sampling of the FFT - Set the xrange for the plot to be from ``0`` to ``2`` by changing the x min and x max values below the plot - Set the "padding" to zero and press calculate - - The plots should be a nice peak, but it will have lots of straight lines + - The plot should still have a peak, but it will be less smooth - Set the "padding" to ``50`` and press calculate - The plot will now be nice and smooth - At the top of the plotting window change the unit from "Frequency" to "Field", the data will have different x axis From 6187fa7158bfc8e7b924a9c360f7e72f5ff1799f Mon Sep 17 00:00:00 2001 From: Applin Date: Mon, 20 May 2024 09:17:24 +0100 Subject: [PATCH 54/58] Update HIFI test instructions --- .../source/Testing/MuonAnalysis_test_guides/Muon_HIFI.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dev-docs/source/Testing/MuonAnalysis_test_guides/Muon_HIFI.rst b/dev-docs/source/Testing/MuonAnalysis_test_guides/Muon_HIFI.rst index 8a0790afad7f..17872c79bfec 100644 --- a/dev-docs/source/Testing/MuonAnalysis_test_guides/Muon_HIFI.rst +++ b/dev-docs/source/Testing/MuonAnalysis_test_guides/Muon_HIFI.rst @@ -54,8 +54,8 @@ HIFI Transverse Field Simultaneous Fitting - Click **Undo Fits** - Click the value for the **Frequency** parameter; A ``...`` should appear next to it, click it. A new window should appear - - Enter values for each run in the table as from ``0.0`` to ``1.1`` in - steps of ``0.1`` + - Enter a value of ``0.01`` for the first run in the table + - For each of the other runs in the table, enter values from ``0.1`` to ``1.1`` in steps of ``0.1`` - Click **Ok** - Click **Fit** - This time the fit should work with a significantly lower value for **Chi-squared** (``<10``) @@ -83,6 +83,7 @@ HIFI MultiPeriod Data - Go to the **Sequential Fitting** tab - Press ``Sequentially fit all`` - When its complete the table should update + - It is ok if some of the rows say "Failed". This happens because these rows need more iterations to converge. However, if you go to the Fitting tab and cycle through the datasets, you can see that the fits are still reasonably good. - Selecting rows will show you the data and fit for those rows - Go to the **Grouping** tab - The ``Period`` column in the group table will show a series of numbers (1, 2, 3 or 4) From 6166d8a1fcc6bfe68acb48e0bac78dc0e2ab6f3d Mon Sep 17 00:00:00 2001 From: Applin Date: Mon, 20 May 2024 09:31:26 +0100 Subject: [PATCH 55/58] Update PSI instructions to give location of dolly 1529 --- .../Muon Analysis Unscripted Testing Guide.rst | 4 ++-- .../Testing/MuonAnalysis_test_guides/Muon_Analysis_PSI.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dev-docs/source/Testing/MuonAnalysis_test_guides/Muon Analysis Unscripted Testing Guide.rst b/dev-docs/source/Testing/MuonAnalysis_test_guides/Muon Analysis Unscripted Testing Guide.rst index 76888a55ba01..232cc5c66850 100644 --- a/dev-docs/source/Testing/MuonAnalysis_test_guides/Muon Analysis Unscripted Testing Guide.rst +++ b/dev-docs/source/Testing/MuonAnalysis_test_guides/Muon Analysis Unscripted Testing Guide.rst @@ -39,9 +39,9 @@ Group 2: PSI data This group tests bin data from the PSI facility and introduces background corrections. Test instructions can be found at :ref:`Muon_Analysis_PSI-ref`. -You will need the following run: +You will need the following file from the unit test data: -- dolly 1529 +- deltat_tdc_dolly_1529.bin Group 3: HIFI data ^^^^^^^^^^^^^^^^^^ diff --git a/dev-docs/source/Testing/MuonAnalysis_test_guides/Muon_Analysis_PSI.rst b/dev-docs/source/Testing/MuonAnalysis_test_guides/Muon_Analysis_PSI.rst index 10526b4649bc..ed84b9592d0e 100644 --- a/dev-docs/source/Testing/MuonAnalysis_test_guides/Muon_Analysis_PSI.rst +++ b/dev-docs/source/Testing/MuonAnalysis_test_guides/Muon_Analysis_PSI.rst @@ -23,7 +23,7 @@ Loading Data Test - Open Muon Analysis - On the **Home** tab set the instrument to **PSI** - The load current run button should be greyed out -- Load **dolly 1529** using the **Browse** button +- Load **deltat_tdc_dolly_1529.bin** from the unit test data using the **Browse** button - Set `Rebin` to `Fixed` and enter a value of `5` - You will get 4 lines that all curve upwards - If you tick the `Plot raw` option the data will change From 8faaf84cf5eeb8f8696dde6ff44b00bbe9da8bff Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 23 May 2024 13:12:21 +0100 Subject: [PATCH 56/58] Use ADS Observer class to observe ADS in output options --- .../Common/OutputPlotOptionsPresenter.cpp | 37 ++++++------------- .../Common/OutputPlotOptionsPresenter.h | 17 ++++----- 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/Common/OutputPlotOptionsPresenter.cpp b/qt/scientific_interfaces/Inelastic/Common/OutputPlotOptionsPresenter.cpp index 745d9769ec69..8e43d545031c 100644 --- a/qt/scientific_interfaces/Inelastic/Common/OutputPlotOptionsPresenter.cpp +++ b/qt/scientific_interfaces/Inelastic/Common/OutputPlotOptionsPresenter.cpp @@ -37,22 +37,17 @@ namespace MantidQt::CustomInterfaces { OutputPlotOptionsPresenter::OutputPlotOptionsPresenter( IOutputPlotOptionsView *view, PlotWidget const &plotType, std::string const &fixedIndices, std::optional> const &availableActions) - : m_wsRemovedObserver(*this, &OutputPlotOptionsPresenter::onWorkspaceRemoved), - m_wsReplacedObserver(*this, &OutputPlotOptionsPresenter::onWorkspaceReplaced), m_view(view), - m_model(std::make_unique(availableActions)) { + : m_view(view), m_model(std::make_unique(availableActions)) { setupPresenter(plotType, fixedIndices); } /// Used by the unit tests so that m_plotter can be mocked OutputPlotOptionsPresenter::OutputPlotOptionsPresenter(IOutputPlotOptionsView *view, OutputPlotOptionsModel *model, PlotWidget const &plotType, std::string const &fixedIndices) - : m_wsRemovedObserver(*this, &OutputPlotOptionsPresenter::onWorkspaceRemoved), - m_wsReplacedObserver(*this, &OutputPlotOptionsPresenter::onWorkspaceReplaced), m_view(view), m_model(model) { + : m_view(view), m_model(model) { setupPresenter(plotType, fixedIndices); } -OutputPlotOptionsPresenter::~OutputPlotOptionsPresenter() { watchADS(false); } - void OutputPlotOptionsPresenter::setupPresenter(PlotWidget const &plotType, std::string const &fixedIndices) { watchADS(true); m_view->subscribePresenter(this); @@ -66,14 +61,8 @@ void OutputPlotOptionsPresenter::setupPresenter(PlotWidget const &plotType, std: } void OutputPlotOptionsPresenter::watchADS(bool on) { - auto ¬ificationCenter = AnalysisDataService::Instance().notificationCenter; - if (on) { - notificationCenter.addObserver(m_wsRemovedObserver); - notificationCenter.addObserver(m_wsReplacedObserver); - } else { - notificationCenter.removeObserver(m_wsReplacedObserver); - notificationCenter.removeObserver(m_wsRemovedObserver); - } + this->observeReplace(on); + this->observeDelete(on); } void OutputPlotOptionsPresenter::setPlotType(PlotWidget const &plotType) { @@ -94,19 +83,17 @@ void OutputPlotOptionsPresenter::setOptionsEnabled(bool enable) { m_view->setUnitComboBoxEnabled(enable); } -void OutputPlotOptionsPresenter::onWorkspaceRemoved(WorkspacePreDeleteNotification_ptr nf) { - // Ignore non matrix workspaces - if (auto const removedWorkspace = std::dynamic_pointer_cast(nf->object())) { - auto const removedName = removedWorkspace->getName(); - if (removedName == m_view->selectedWorkspace().toStdString()) - m_model->removeWorkspace(); - m_view->removeWorkspace(QString::fromStdString(removedName)); - } +void OutputPlotOptionsPresenter::deleteHandle(const std::string &wsName, const Workspace_sptr &workspace) { + (void)workspace; + if (wsName == m_view->selectedWorkspace().toStdString()) + m_model->removeWorkspace(); + m_view->removeWorkspace(QString::fromStdString(wsName)); } -void OutputPlotOptionsPresenter::onWorkspaceReplaced(WorkspaceBeforeReplaceNotification_ptr nf) { +void OutputPlotOptionsPresenter::replaceHandle(const std::string &wsName, const Workspace_sptr &workspace) { + (void)wsName; // Ignore non matrix workspaces - if (auto const newWorkspace = std::dynamic_pointer_cast(nf->newObject())) { + if (auto const newWorkspace = std::dynamic_pointer_cast(workspace)) { auto const newName = newWorkspace->getName(); if (newName == m_view->selectedWorkspace().toStdString()) handleWorkspaceChanged(newName); diff --git a/qt/scientific_interfaces/Inelastic/Common/OutputPlotOptionsPresenter.h b/qt/scientific_interfaces/Inelastic/Common/OutputPlotOptionsPresenter.h index df2ff4a1e448..1cdd75244917 100644 --- a/qt/scientific_interfaces/Inelastic/Common/OutputPlotOptionsPresenter.h +++ b/qt/scientific_interfaces/Inelastic/Common/OutputPlotOptionsPresenter.h @@ -11,9 +11,9 @@ #include "Common/OutputPlotOptionsModel.h" #include "Common/OutputPlotOptionsView.h" -#include "DllConfig.h" +#include "MantidAPI/AnalysisDataServiceObserver.h" -#include +#include "DllConfig.h" namespace MantidQt { namespace CustomInterfaces { @@ -30,7 +30,8 @@ class MANTIDQT_INELASTIC_DLL IOutputPlotOptionsPresenter { virtual void handlePlot3DClicked() = 0; }; -class MANTIDQT_INELASTIC_DLL OutputPlotOptionsPresenter final : public IOutputPlotOptionsPresenter { +class MANTIDQT_INELASTIC_DLL OutputPlotOptionsPresenter final : public IOutputPlotOptionsPresenter, + public AnalysisDataServiceObserver { public: OutputPlotOptionsPresenter(IOutputPlotOptionsView *view, PlotWidget const &plotType = PlotWidget::Spectra, @@ -39,7 +40,7 @@ class MANTIDQT_INELASTIC_DLL OutputPlotOptionsPresenter final : public IOutputPl /// Used by the unit tests so that the view and model can be mocked OutputPlotOptionsPresenter(IOutputPlotOptionsView *view, OutputPlotOptionsModel *model, PlotWidget const &plotType = PlotWidget::Spectra, std::string const &fixedIndices = ""); - ~OutputPlotOptionsPresenter(); + ~OutputPlotOptionsPresenter() = default; void handleWorkspaceChanged(std::string const &workspaceName) override; void handleSelectedUnitChanged(std::string const &unit) override; @@ -62,8 +63,8 @@ class MANTIDQT_INELASTIC_DLL OutputPlotOptionsPresenter final : public IOutputPl void setPlotting(bool plotting); void setOptionsEnabled(bool enable); - void onWorkspaceRemoved(Mantid::API::WorkspacePreDeleteNotification_ptr nf); - void onWorkspaceReplaced(Mantid::API::WorkspaceBeforeReplaceNotification_ptr nf); + void replaceHandle(const std::string &wsName, const Workspace_sptr &workspace) override; + void deleteHandle(const std::string &wsName, const Workspace_sptr &workspace) override; void setWorkspace(std::string const &plotWorkspace); void setUnit(std::string const &unit); @@ -71,10 +72,6 @@ class MANTIDQT_INELASTIC_DLL OutputPlotOptionsPresenter final : public IOutputPl bool validateWorkspaceSize(MantidAxis const &axisType); - // Observers for ADS Notifications - Poco::NObserver m_wsRemovedObserver; - Poco::NObserver m_wsReplacedObserver; - IOutputPlotOptionsView *m_view; std::unique_ptr m_model; PlotWidget m_plotType; From 1e0dc9efdaa1cea891d8f60bd1b96a9bb1424fa1 Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 23 May 2024 13:33:54 +0100 Subject: [PATCH 57/58] Store presenter as unique ptr to ensure it gets destructed --- .../Indirect/Reduction/DataReduction.cpp | 22 ++++++------- .../Indirect/Reduction/DataReduction.h | 31 +++++++++++-------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/qt/scientific_interfaces/Indirect/Reduction/DataReduction.cpp b/qt/scientific_interfaces/Indirect/Reduction/DataReduction.cpp index e9ae207a6c9d..1c57e2e57045 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/DataReduction.cpp +++ b/qt/scientific_interfaces/Indirect/Reduction/DataReduction.cpp @@ -58,7 +58,7 @@ std::string DataReduction::documentationPage() const { return "Indirect Data Red * Called when the user clicks the Python export button. */ void DataReduction::exportTabPython() { - QString tabName = m_uiForm.twIDRTabs->tabText(m_uiForm.twIDRTabs->currentIndex()); + auto const tabName = m_uiForm.twIDRTabs->tabText(m_uiForm.twIDRTabs->currentIndex()).toStdString(); m_tabs[tabName].second->exportPythonScript(); } @@ -413,35 +413,35 @@ void DataReduction::saveSettings() { */ void DataReduction::filterUiForFacility(const QString &facility) { g_log.information() << "Facility selected: " << facility.toStdString() << '\n'; - QStringList enabledTabs; + std::vector enabledTabs; QStringList disabledInstruments; // Add facility specific tabs and disable instruments if (facility == "ISIS") { - enabledTabs << "ISIS Energy Transfer" - << "ISIS Calibration" - << "ISIS Diagnostics"; + enabledTabs.emplace_back("ISIS Energy Transfer"); + enabledTabs.emplace_back("ISIS Calibration"); + enabledTabs.emplace_back("ISIS Diagnostics"); } else if (facility == "ILL") { - enabledTabs << "ILL Energy Transfer"; + enabledTabs.emplace_back("ILL Energy Transfer"); disabledInstruments << "IN10" << "IN13" << "IN16"; } // These tabs work at any facility (always at end of tabs) - enabledTabs << "Transmission"; + enabledTabs.emplace_back("Transmission"); // First remove all tabs while (m_uiForm.twIDRTabs->count() > 0) { // Disconnect the instrument changed signal - QString tabName = m_uiForm.twIDRTabs->tabText(0); + auto const tabName = m_uiForm.twIDRTabs->tabText(0).toStdString(); disconnect(this, SIGNAL(newInstrumentConfiguration()), m_tabs[tabName].second, SIGNAL(newInstrumentConfiguration())); // Remove the tab m_uiForm.twIDRTabs->removeTab(0); - g_log.debug() << "Removing tab " << tabName.toStdString() << '\n'; + g_log.debug() << "Removing tab " << tabName << '\n'; } // Add the required tabs @@ -451,9 +451,9 @@ void DataReduction::filterUiForFacility(const QString &facility) { SIGNAL(newInstrumentConfiguration())); // Add the tab - m_uiForm.twIDRTabs->addTab(m_tabs[enabledTab].first, enabledTab); + m_uiForm.twIDRTabs->addTab(m_tabs[enabledTab].first, QString::fromStdString(enabledTab)); - g_log.debug() << "Adding tab " << enabledTab.toStdString() << '\n'; + g_log.debug() << "Adding tab " << enabledTab << '\n'; } // Disable instruments as required diff --git a/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h b/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h index 1e6d842bf6fc..6fdd565a84c7 100644 --- a/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h +++ b/qt/scientific_interfaces/Indirect/Reduction/DataReduction.h @@ -15,6 +15,8 @@ #include "MantidQtWidgets/Common/AlgorithmRunner.h" #include "MantidQtWidgets/Common/QtJobRunner.h" +#include + #include #include @@ -117,7 +119,7 @@ private slots: * * @param name Name to be displayed on tab */ - template void addTab(const QString &name) { + template void addTab(const std::string &name) { QWidget *tabWidget = new QWidget(m_uiForm.twIDRTabs); QVBoxLayout *tabLayout = new QVBoxLayout(tabWidget); tabWidget->setLayout(tabLayout); @@ -127,7 +129,7 @@ private slots: tabScrollArea->setWidgetResizable(true); QWidget *tabContent = new QWidget(tabScrollArea); - tabContent->setObjectName("tab" + QString(name).remove(QRegExp("[ ,()]"))); + tabContent->setObjectName("tab" + QString::fromStdString(name).remove(QRegExp("[ ,()]"))); tabScrollArea->setWidget(tabContent); tabScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -141,7 +143,7 @@ private slots: m_tabs[name] = qMakePair(tabWidget, tabIDRContent); // Add all tabs to UI initially - m_uiForm.twIDRTabs->addTab(tabWidget, name); + m_uiForm.twIDRTabs->addTab(tabWidget, QString::fromStdString(name)); } /** @@ -153,7 +155,7 @@ private slots: * @param name Name to be displayed on tab */ - template void addMVPTab(const QString &name) { + template void addMVPTab(const std::string &name) { QWidget *tabWidget = new QWidget(m_uiForm.twIDRTabs); QVBoxLayout *tabLayout = new QVBoxLayout(tabWidget); tabWidget->setLayout(tabLayout); @@ -163,25 +165,26 @@ private slots: tabScrollArea->setWidgetResizable(true); QWidget *tabContent = new QWidget(tabScrollArea); - tabContent->setObjectName("tab" + QString(name).remove(QRegExp("[ ,()]"))); + tabContent->setObjectName("tab" + QString::fromStdString(name).remove(QRegExp("[ ,()]"))); tabScrollArea->setWidget(tabContent); tabScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); auto jobRunner = std::make_unique(); auto algorithmRunner = std::make_unique(std::move(jobRunner)); - DataReductionTab *tabIDRContent = - new TabPresenter(this, new TabView(tabContent), std::make_unique(), std::move(algorithmRunner)); + auto presenter = std::make_unique(this, new TabView(tabContent), std::make_unique(), + std::move(algorithmRunner)); - tabIDRContent->setupTab(); + presenter->setupTab(); tabContent->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - connect(tabIDRContent, SIGNAL(showMessageBox(const QString &)), this, SLOT(showMessageBox(const QString &))); + connect(presenter.get(), SIGNAL(showMessageBox(const QString &)), this, SLOT(showMessageBox(const QString &))); // Add to the cache - m_tabs[name] = qMakePair(tabWidget, tabIDRContent); + m_tabs[name] = qMakePair(tabWidget, presenter.get()); + m_presenters[name] = std::move(presenter); // Add all tabs to UI initially - m_uiForm.twIDRTabs->addTab(tabWidget, name); + m_uiForm.twIDRTabs->addTab(tabWidget, QString::fromStdString(name)); } friend class DataReductionTab; @@ -190,8 +193,10 @@ private slots: /// The settings group QString m_settingsGroup; - // All indirect tabs - QMap> m_tabs; + // All indirect tabs - this should be removed when the interface is in MVP + QMap> m_tabs; + /// A map to hold the presenter corresponding to each tab + std::unordered_map> m_presenters; /// Poco observer for changes in user directory settings Poco::NObserver m_changeObserver; From b51691cb069a740b391211e4b2e9b7d50ab6424b Mon Sep 17 00:00:00 2001 From: Applin Date: Thu, 23 May 2024 13:58:11 +0100 Subject: [PATCH 58/58] Store presenters as unique ptrs in Data Manipulation Interface class --- .../DataManipulationInterface.cpp | 66 ++----------------- .../Manipulation/DataManipulationInterface.h | 30 ++++----- 2 files changed, 15 insertions(+), 81 deletions(-) diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.cpp b/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.cpp index b248b26f29cd..0407c29d5da5 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.cpp +++ b/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.cpp @@ -4,9 +4,6 @@ // NScD Oak Ridge National Laboratory, European Spallation Source, // Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS // SPDX - License - Identifier: GPL - 3.0 + -//---------------------- -// Includes -//---------------------- #include "DataManipulationInterface.h" #include "Common/Settings.h" @@ -45,7 +42,7 @@ DECLARE_SUBWINDOW(DataManipulationInterface) DataManipulationInterface::DataManipulationInterface(QWidget *parent) : InelasticInterface(parent) {} -DataManipulationInterface::~DataManipulationInterface() {} +DataManipulationInterface::~DataManipulationInterface() = default; std::string DataManipulationInterface::documentationPage() const { return "Inelastic Data Manipulation"; } @@ -53,8 +50,8 @@ std::string DataManipulationInterface::documentationPage() const { return "Inela * Called when the user clicks the Python export button. */ void DataManipulationInterface::exportTabPython() { - QString tabName = m_uiForm.twIDRTabs->tabText(m_uiForm.twIDRTabs->currentIndex()); - m_tabs[tabName].second->exportPythonScript(); + auto const tabName = m_uiForm.twIDRTabs->tabText(m_uiForm.twIDRTabs->currentIndex()).toStdString(); + m_presenters[tabName]->exportPythonScript(); } /** @@ -79,27 +76,15 @@ void DataManipulationInterface::initLayout() { // Connect the "Manage User Directories" Button connect(m_uiForm.pbManageDirectories, SIGNAL(clicked()), this, SLOT(manageUserDirectories())); - auto const &facility = Mantid::Kernel::ConfigService::Instance().getFacility(); - filterUiForFacility(QString::fromStdString(facility.name())); - InelasticInterface::initLayout(); } void DataManipulationInterface::applySettings(std::map const &settings) { - for (auto tab = m_tabs.begin(); tab != m_tabs.end(); ++tab) { + for (auto tab = m_presenters.begin(); tab != m_presenters.end(); ++tab) { tab->second->filterInputData(settings.at("RestrictInput").toBool()); } } -/** - * This function is ran after initLayout(), and runPythonCode is unavailable - * before this function - * has run (because of the setup of the base class). For this reason, "setup" - * functions that require - * Python scripts are located here. - */ -void DataManipulationInterface::initLocalPython() {} - /** * Gets a parameter from an instrument component as a string. * @@ -140,47 +125,4 @@ void DataManipulationInterface::instrumentLoadingDone(bool error) { } } -/** - * Remove the Poco observer on the config service when the interfaces is closed. - * - * @param close Close event (unused) - */ -void DataManipulationInterface::closeEvent(QCloseEvent *close) { UNUSED_ARG(close); } - -/** - * Filters the displayed tabs based on the current facility. - * - * @param facility Name of facility - */ -void DataManipulationInterface::filterUiForFacility(const QString &facility) { - g_log.information() << "Facility selected: " << facility.toStdString() << '\n'; - QStringList enabledTabs; - QStringList disabledInstruments; - - // These tabs work at any facility (always at end of tabs) - enabledTabs << "Symmetrise" - << "S(Q, w)" - << "Moments" - << "Elwin" - << "Iqt"; - - // First remove all tabs - while (m_uiForm.twIDRTabs->count() > 0) { - QString tabName = m_uiForm.twIDRTabs->tabText(0); - - // Remove the tab - m_uiForm.twIDRTabs->removeTab(0); - - g_log.debug() << "Removing tab " << tabName.toStdString() << '\n'; - } - - // Add the required tabs - for (auto &enabledTab : enabledTabs) { - // Add the tab - m_uiForm.twIDRTabs->addTab(m_tabs[enabledTab].first, enabledTab); - - g_log.debug() << "Adding tab " << enabledTab.toStdString() << '\n'; - } -} - } // namespace MantidQt::CustomInterfaces diff --git a/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.h b/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.h index da9629f38c61..6d49de4dcbf4 100644 --- a/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.h +++ b/qt/scientific_interfaces/Inelastic/Manipulation/DataManipulationInterface.h @@ -12,6 +12,8 @@ #include "MantidGeometry/IComponent.h" +#include + #include #include @@ -43,16 +45,12 @@ class DataManipulationInterface : public InelasticInterface { /// Initialize the layout void initLayout() override; - /// Run Python-based initialisation commands - void initLocalPython() override; signals: /// Emitted when the instrument setup is changed void newInstrumentConfiguration(); private slots: - /// Shows/hides tabs based on facility - void filterUiForFacility(const QString &facility); /// Exports the current tab algorithms as a Python script void exportTabPython(); @@ -67,9 +65,6 @@ private slots: QString getInstrumentParameterFrom(const Mantid::Geometry::IComponent_const_sptr &comp, const std::string ¶m); - /// Set and show an instrument-specific widget - void closeEvent(QCloseEvent *close) override; - /** * Adds an MVP tab to the cache of tabs that can be shown. * @@ -79,7 +74,7 @@ private slots: * @param name Name to be displayed on tab */ - template void addMVPTab(const QString &name) { + template void addMVPTab(const std::string &name) { QWidget *tabWidget = new QWidget(m_uiForm.twIDRTabs); QVBoxLayout *tabLayout = new QVBoxLayout(tabWidget); tabWidget->setLayout(tabLayout); @@ -89,34 +84,31 @@ private slots: tabScrollArea->setWidgetResizable(true); QWidget *tabContent = new QWidget(tabScrollArea); - tabContent->setObjectName("tab" + QString(name).remove(QRegExp("[ ,()]"))); + tabContent->setObjectName("tab" + QString::fromStdString(name).remove(QRegExp("[ ,()]"))); tabScrollArea->setWidget(tabContent); tabScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); std::unique_ptr tabModel = std::make_unique(); - DataManipulation *tabIDRContent = new TabPresenter(tabContent, new TabView(tabContent), std::move(tabModel)); + auto presenter = std::make_unique(tabContent, new TabView(tabContent), std::move(tabModel)); - tabIDRContent->setupTab(); + presenter->setupTab(); tabContent->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - connect(tabIDRContent, SIGNAL(showMessageBox(const QString &)), this, SLOT(showMessageBox(const QString &))); + connect(presenter.get(), SIGNAL(showMessageBox(const QString &)), this, SLOT(showMessageBox(const QString &))); - // Add to the cache - m_tabs[name] = qMakePair(tabWidget, tabIDRContent); + m_presenters[name] = std::move(presenter); // Add all tabs to UI initially - m_uiForm.twIDRTabs->addTab(tabWidget, name); + m_uiForm.twIDRTabs->addTab(tabWidget, QString::fromStdString(name)); } friend class DataManipulation; /// The .ui form generated by Qt Designer Ui::DataManipulationInterface m_uiForm; - // All indirect tabs - QMap> m_tabs; - QString m_dataDir; ///< default data search directory - QString m_saveDir; ///< default data save directory + /// A map to hold the presenter corresponding to each tab + std::unordered_map> m_presenters; }; } // namespace CustomInterfaces