From dbc78d93189d4416f152b0931e9804e6fa4c2a75 Mon Sep 17 00:00:00 2001
From: Nick Draper <nick.draper@stfc.ac.uk>
Date: Fri, 6 Mar 2020 09:26:18 +0000
Subject: [PATCH] Remove the dodgy passing of algorithms in *Dialog methods

re #28093
---
 Framework/API/inc/MantidAPI/AlgorithmManager.h     |  1 -
 Framework/API/src/AlgorithmManager.cpp             | 12 ------------
 Framework/API/test/AlgorithmManagerTest.h          | 14 --------------
 .../inc/MantidAlgorithms/RecordPythonScript.h      |  2 +-
 .../mantid/api/src/Exports/AlgorithmManager.cpp    |  3 ---
 Framework/PythonInterface/mantid/simpleapi.py      |  2 +-
 MantidPlot/CMakeLists.txt                          |  6 +++++-
 MantidPlot/src/Mantid/MantidUI.cpp                 |  4 +---
 MantidPlot/src/Mantid/MantidUI.h                   |  2 +-
 MantidPlot/src/qti.sip                             |  7 +++++--
 10 files changed, 14 insertions(+), 39 deletions(-)

diff --git a/Framework/API/inc/MantidAPI/AlgorithmManager.h b/Framework/API/inc/MantidAPI/AlgorithmManager.h
index eb892ae5f1e..9958a6a491d 100644
--- a/Framework/API/inc/MantidAPI/AlgorithmManager.h
+++ b/Framework/API/inc/MantidAPI/AlgorithmManager.h
@@ -53,7 +53,6 @@ public:
 
   IAlgorithm_sptr getAlgorithm(AlgorithmID id) const;
   void removeById(AlgorithmID id);
-  IAlgorithm_sptr newestInstanceOf(const std::string &algorithmName) const;
 
   std::vector<IAlgorithm_const_sptr> runningInstances() const;
   std::vector<IAlgorithm_const_sptr>
diff --git a/Framework/API/src/AlgorithmManager.cpp b/Framework/API/src/AlgorithmManager.cpp
index 76d5cf8a159..f6b18db76dc 100644
--- a/Framework/API/src/AlgorithmManager.cpp
+++ b/Framework/API/src/AlgorithmManager.cpp
@@ -205,18 +205,6 @@ void AlgorithmManagerImpl::notifyAlgorithmStarting(AlgorithmID id) {
   notificationCenter.postNotification(new AlgorithmStartingNotification(alg));
 }
 
-/// Returns the most recently created instance of the named algorithm (or null
-/// if not found)
-IAlgorithm_sptr
-AlgorithmManagerImpl::newestInstanceOf(const std::string &algorithmName) const {
-  for (auto it = m_managed_algs.rbegin(); it != m_managed_algs.rend(); ++it) {
-    if ((*it)->name() == algorithmName)
-      return *it;
-  }
-
-  return IAlgorithm_sptr();
-}
-
 /// Returns all running (& managed) occurances of the named algorithm, oldest
 /// first
 std::vector<IAlgorithm_const_sptr> AlgorithmManagerImpl::runningInstancesOf(
diff --git a/Framework/API/test/AlgorithmManagerTest.h b/Framework/API/test/AlgorithmManagerTest.h
index 3504b241881..232d2994967 100644
--- a/Framework/API/test/AlgorithmManagerTest.h
+++ b/Framework/API/test/AlgorithmManagerTest.h
@@ -329,20 +329,6 @@ public:
     mgr.setMaxAlgorithms(5);
   }
 
-  void test_newestInstanceOf() {
-    auto &am = AlgorithmManager::Instance();
-    am.clear();
-    auto first = am.create("AlgTest");
-    TS_ASSERT_EQUALS(am.newestInstanceOf("AlgTest"), first);
-    auto second = am.create("AlgTest");
-    TS_ASSERT_EQUALS(am.newestInstanceOf("AlgTest"), second);
-    TS_ASSERT(!am.newestInstanceOf("AlgTestSecond"));
-    // Create a different algorithm
-    am.create("AlgTestSecond");
-    // Make sure we still get back the latest instance of other algorithm
-    TS_ASSERT_EQUALS(am.newestInstanceOf("AlgTest"), second);
-  }
-
   void test_runningInstancesOf() {
     AlgorithmManager::Instance().clear();
     // Had better return empty at this point
diff --git a/Framework/Algorithms/inc/MantidAlgorithms/RecordPythonScript.h b/Framework/Algorithms/inc/MantidAlgorithms/RecordPythonScript.h
index 65041e49b70..58a844e0c5e 100644
--- a/Framework/Algorithms/inc/MantidAlgorithms/RecordPythonScript.h
+++ b/Framework/Algorithms/inc/MantidAlgorithms/RecordPythonScript.h
@@ -13,7 +13,7 @@
 namespace Mantid {
 namespace Algorithms {
 
-/** RecordPythonScript : TODO: DESCRIPTION
+/** RecordPythonScript : 
 
   An Algorithm to generate a Python script file to reproduce the history of a
   workspace.
diff --git a/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmManager.cpp b/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmManager.cpp
index 9c4b374f962..1c244daaf1e 100644
--- a/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmManager.cpp
+++ b/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmManager.cpp
@@ -116,9 +116,6 @@ void export_AlgorithmManager() {
            "Return the algorithm instance identified by the given id.")
       .def("removeById", &removeById, (arg("self"), arg("id_holder")),
            "Remove an algorithm from the managed list")
-      .def("newestInstanceOf", &AlgorithmManagerImpl::newestInstanceOf,
-           (arg("self"), arg("algorithm_name")),
-           "Returns the newest created instance of the named algorithm")
       .def("runningInstancesOf", &runningInstancesOf,
            (arg("self"), arg("algorithm_name")),
            "Returns a list of managed algorithm instances that are "
diff --git a/Framework/PythonInterface/mantid/simpleapi.py b/Framework/PythonInterface/mantid/simpleapi.py
index 0edcbd34fa2..d8b913adcf4 100644
--- a/Framework/PythonInterface/mantid/simpleapi.py
+++ b/Framework/PythonInterface/mantid/simpleapi.py
@@ -1315,7 +1315,7 @@ def set_properties_dialog(algm_object, *args, **kwargs):
 
     # finally run the configured dialog
     import mantidplot
-    dialog_accepted = mantidplot.createScriptInputDialog(algm_object.name(), presets, message,
+    dialog_accepted = mantidplot.createScriptInputDialog(algm_object, presets, message,
                                                          enabled_list, disabled_list)
     if not dialog_accepted:
         raise RuntimeError('Algorithm input cancelled')
diff --git a/MantidPlot/CMakeLists.txt b/MantidPlot/CMakeLists.txt
index 1a778bbf120..00060cba8c4 100644
--- a/MantidPlot/CMakeLists.txt
+++ b/MantidPlot/CMakeLists.txt
@@ -823,6 +823,10 @@ target_include_directories(MantidPlot PRIVATE
 target_compile_options( MantidPlot PRIVATE
   $<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,8.0>>:-Wno-cast-function-type> )
 
+set (BOOST_LIBRARIES_MANTIDPLOT ${Boost_LIBRARIES})
+find_package(BoostPython REQUIRED)
+set (BOOST_LIBRARIES_MANTIDPLOT "${BOOST_LIBRARIES_MANTIDPLOT};${Boost_LIBRARIES}")
+
 # Library dependencies
 target_link_libraries(MantidPlot
                       LINK_PRIVATE
@@ -835,7 +839,7 @@ target_link_libraries(MantidPlot
                       MantidQtWidgetsInstrumentViewQt4
                       MantidQtWidgetsSliceViewerQt4
                       MantidQtWidgetsSpectrumViewerQt4
-                      ${Boost_LIBRARIES}
+                      ${BOOST_LIBRARIES_MANTIDPLOT}
                       ${POCO_LIBRARIES}
                       ${GSL_LIBRARIES}
                       ${MUPARSER_LIBRARIES}
diff --git a/MantidPlot/src/Mantid/MantidUI.cpp b/MantidPlot/src/Mantid/MantidUI.cpp
index e5e637dc062..b90cee8621f 100644
--- a/MantidPlot/src/Mantid/MantidUI.cpp
+++ b/MantidPlot/src/Mantid/MantidUI.cpp
@@ -2363,13 +2363,11 @@ MantidMatrix *MantidUI::getMantidMatrix(const QString &wsName) {
   return m;
 }
 
-bool MantidUI::createScriptInputDialog(const QString &alg_name,
+bool MantidUI::createScriptInputDialog(const IAlgorithm_sptr &alg,
                                        const QString &preset_values,
                                        const QString &optional_msg,
                                        const QStringList &enabled,
                                        const QStringList &disabled) {
-  IAlgorithm_sptr alg =
-      AlgorithmManager::Instance().newestInstanceOf(alg_name.toStdString());
   if (!alg) {
     return false;
   }
diff --git a/MantidPlot/src/Mantid/MantidUI.h b/MantidPlot/src/Mantid/MantidUI.h
index 93f5ce9ddb6..0004c772027 100644
--- a/MantidPlot/src/Mantid/MantidUI.h
+++ b/MantidPlot/src/Mantid/MantidUI.h
@@ -377,7 +377,7 @@ public:
   MantidMatrix *getMantidMatrix(const QString &wsName);
 
   void setIsRunning(bool running);
-  bool createScriptInputDialog(const QString &alg_name,
+  bool createScriptInputDialog(const Mantid::API::IAlgorithm_sptr &alg,
                                const QString &preset_values,
                                const QString &optional_msg,
                                const QStringList &enabled,
diff --git a/MantidPlot/src/qti.sip b/MantidPlot/src/qti.sip
index 8b981b19ef6..7f5cf59d396 100644
--- a/MantidPlot/src/qti.sip
+++ b/MantidPlot/src/qti.sip
@@ -1466,6 +1466,7 @@ class MantidUI: QObject
 {
 %TypeHeaderCode
 #include "src/Mantid/MantidUI.h"
+#include <boost/python/extract.hpp>
 %End
 %ConvertToSubClassCode
 // we have to do this to override casting in qt/qobject.sip (PyQt 3.16)
@@ -1510,8 +1511,10 @@ public:
   Table* createDetectorTable(const QString & wsName);
 
   void setIsRunning(bool running);
-  bool createScriptInputDialog(const QString &, const QString &, const QString&, const QStringList&, const QStringList&);
-
+  bool createScriptInputDialog(SIP_PYOBJECT, const QString &, const QString&, const QStringList&, const QStringList&);
+%MethodCode
+  sipCpp->createScriptInputDialog(boost::python::extract<Mantid::API::IAlgorithm_sptr>(a0), *a1, *a2, *a3, *a4);
+%End
    MantidQt::MantidWidgets::FitPropertyBrowser* fitFunctionBrowser();
 private:
   MantidUI(const MantidUI &);
-- 
GitLab