diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.cpp index 2e83543df2121779416985b6fcf2cff00d6d0c82..b7c574d73ece8b32aef19b66bbc49ec87b5fec24 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.cpp @@ -13,10 +13,6 @@ #include "GUI/Runs/IRunsPresenter.h" #include "GUI/Save/ISavePresenter.h" #include "IBatchView.h" -#include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/IAlgorithm_fwd.h" -#include "MantidAPI/MatrixWorkspace.h" -#include "MantidKernel/ConfigService.h" #include "MantidQtWidgets/Common/HelpWindow.h" namespace MantidQt { @@ -24,14 +20,6 @@ namespace CustomInterfaces { namespace ISISReflectometry { using API::IConfiguredAlgorithm_sptr; -using Mantid::API::AlgorithmManager; -using Mantid::API::IAlgorithm_sptr; -using Mantid::API::MatrixWorkspace_sptr; - -// unnamed namespace -namespace { -Mantid::Kernel::Logger g_log("Reflectometry GUI"); -} /** Constructor * @param view :: [input] The view we are managing @@ -56,7 +44,7 @@ BatchPresenter::BatchPresenter( m_eventPresenter(std::move(eventPresenter)), m_experimentPresenter(std::move(experimentPresenter)), m_instrumentPresenter(std::move(instrumentPresenter)), - m_savePresenter(std::move(savePresenter)), m_instrument(), + m_savePresenter(std::move(savePresenter)), m_jobRunner(new BatchJobRunner(std::move(model))) { m_view->subscribe(this); @@ -84,13 +72,18 @@ bool BatchPresenter::requestClose() const { return true; } void BatchPresenter::notifyInstrumentChangedRequested( const std::string &instrumentName) { - notifyInstrumentChanged(instrumentName); + m_mainPresenter->notifyInstrumentChangedRequested(instrumentName); +} + +void BatchPresenter::notifyInstrumentChanged( + const std::string &instrumentName) { + m_runsPresenter->notifyInstrumentChanged(instrumentName); + m_experimentPresenter->notifyInstrumentChanged(instrumentName); + m_instrumentPresenter->notifyInstrumentChanged(instrumentName); } -void BatchPresenter::notifyRestoreDefaultsRequested() { - // We need to reload the instrument parameters file so that we can get - // up-to-date defaults - updateInstrument(m_instrument->getName()); +void BatchPresenter::notifyUpdateInstrumentRequested() { + m_mainPresenter->notifyUpdateInstrumentRequested(); } void BatchPresenter::notifySettingsChanged() { settingsChanged(); } @@ -263,41 +256,12 @@ void BatchPresenter::anyBatchAutoreductionPaused() { m_runsPresenter->anyBatchAutoreductionPaused(); } -void BatchPresenter::notifyInstrumentChanged( - const std::string &instrumentName) { - updateInstrument(instrumentName); - m_runsPresenter->notifyInstrumentChanged(instrumentName); - m_experimentPresenter->notifyInstrumentChanged(instrumentName); - m_instrumentPresenter->notifyInstrumentChanged(instrumentName); -} - -void BatchPresenter::updateInstrument(const std::string &instrumentName) { - Mantid::Kernel::ConfigService::Instance().setString("default.instrument", - instrumentName); - g_log.information() << "Instrument changed to " << instrumentName; - - // Load a workspace for this instrument so we can get the actual instrument - auto loadAlg = - AlgorithmManager::Instance().createUnmanaged("LoadEmptyInstrument"); - loadAlg->setChild(true); - loadAlg->initialize(); - loadAlg->setProperty("InstrumentName", instrumentName); - loadAlg->setProperty("OutputWorkspace", - "__Reflectometry_GUI_Empty_Instrument"); - loadAlg->execute(); - MatrixWorkspace_sptr instWorkspace = loadAlg->getProperty("OutputWorkspace"); - m_instrument = instWorkspace->getInstrument(); -} - Mantid::Geometry::Instrument_const_sptr BatchPresenter::instrument() const { - return m_instrument; + return m_mainPresenter->instrument(); } std::string BatchPresenter::instrumentName() const { - if (m_instrument) - return m_instrument->getName(); - - return std::string(); + return m_mainPresenter->instrumentName(); } void BatchPresenter::settingsChanged() { m_runsPresenter->settingsChanged(); } diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.h index 36d29b86827323bf5736c5370fea8fae80ea37e4..1290e6bee479661963cc90e4a12a5ab9f74aa2da 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.h @@ -16,7 +16,6 @@ #include "IBatchJobRunner.h" #include "IBatchPresenter.h" #include "IBatchView.h" -#include "MantidGeometry/Instrument.h" #include "MantidQtWidgets/Common/WorkspaceObserver.h" #include <memory> @@ -61,8 +60,10 @@ public: void notifyAutoreductionResumed() override; void notifyAutoreductionPaused() override; void notifyAutoreductionCompleted() override; - void notifyInstrumentChangedRequested(const std::string &instName) override; - void notifyRestoreDefaultsRequested() override; + void + notifyInstrumentChangedRequested(const std::string &instrumentName) override; + void notifyInstrumentChanged(const std::string &instrumentName) override; + void notifyUpdateInstrumentRequested() override; void notifySettingsChanged() override; void anyBatchAutoreductionResumed() override; void anyBatchAutoreductionPaused() override; @@ -93,8 +94,6 @@ private: void pauseAutoreduction(); void autoreductionPaused(); void autoreductionCompleted(); - void notifyInstrumentChanged(const std::string &instName); - void updateInstrument(const std::string &instName); void settingsChanged(); IBatchView *m_view; @@ -104,7 +103,6 @@ private: std::unique_ptr<IExperimentPresenter> m_experimentPresenter; std::unique_ptr<IInstrumentPresenter> m_instrumentPresenter; std::unique_ptr<ISavePresenter> m_savePresenter; - Mantid::Geometry::Instrument_const_sptr m_instrument; friend class Encoder; friend class Decoder; diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/IBatchPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/IBatchPresenter.h index 1ca16ba26574d85936c4017b573b623c0e5e551c..a9d95e7f9e62894cd15fa8389b324f851324c256 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/IBatchPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/IBatchPresenter.h @@ -37,8 +37,9 @@ public: virtual void notifyAutoreductionPaused() = 0; virtual void notifyAutoreductionCompleted() = 0; virtual void - notifyInstrumentChangedRequested(const std::string &instName) = 0; - virtual void notifyRestoreDefaultsRequested() = 0; + notifyInstrumentChangedRequested(const std::string &instrumentName) = 0; + virtual void notifyInstrumentChanged(const std::string &instrumentName) = 0; + virtual void notifyUpdateInstrumentRequested() = 0; virtual void notifySettingsChanged() = 0; virtual void anyBatchAutoreductionResumed() = 0; virtual void anyBatchAutoreductionPaused() = 0; diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp index 30980dcf88c7f1ac38a640f41c5d7a545a26c821..da1697c206f616269e8c42c7694a0c9a0d2649ea 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp @@ -42,9 +42,9 @@ void ExperimentPresenter::notifySettingsChanged() { } void ExperimentPresenter::notifyRestoreDefaultsRequested() { - // Notify main presenter first to make sure instrument is up to date - m_mainPresenter->notifyRestoreDefaultsRequested(); - restoreDefaults(); + // Trigger a reload of the instrument to get up-to-date settings. + // After the instrument is updated, the defaults will be restored. + m_mainPresenter->notifyUpdateInstrumentRequested(); } void ExperimentPresenter::notifySummationTypeChanged() { diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp index cae48f22badc668165292d20a709527bc28e0277..f1f555cb04e56fb4ac85e05cc2a789af028b2d5a 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp @@ -45,9 +45,9 @@ void InstrumentPresenter::notifySettingsChanged() { } void InstrumentPresenter::notifyRestoreDefaultsRequested() { - // Notify main presenter first to make sure instrument is up to date - m_mainPresenter->notifyRestoreDefaultsRequested(); - restoreDefaults(); + // Trigger a reload of the instrument to get up-to-date settings. + // After the instrument is updated, the defaults will be restored. + m_mainPresenter->notifyUpdateInstrumentRequested(); } Instrument const &InstrumentPresenter::instrument() const { return m_model; } diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/IMainWindowPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/IMainWindowPresenter.h index 7d203a743bdd1321f92bbdc841ef52fcebbb5743..cadb4fab3ffe9fdc2f308e6dc1fb5231e9cb5b72 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/IMainWindowPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/IMainWindowPresenter.h @@ -28,6 +28,11 @@ public: virtual void notifyAutoreductionPaused() = 0; virtual void reductionResumed() = 0; virtual void reductionPaused() = 0; + virtual void + notifyInstrumentChangedRequested(std::string const &instrumentName) = 0; + virtual void notifyUpdateInstrumentRequested() = 0; + virtual Mantid::Geometry::Instrument_const_sptr instrument() const = 0; + virtual std::string instrumentName() const = 0; virtual ~IMainWindowPresenter() = default; }; } // namespace ISISReflectometry diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp index ff254b190e60c1da379744c2add6327e3342f893..71c098055b2418f437be1b8599f9cecc4ba82baa 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp @@ -11,6 +11,9 @@ #include "GUI/Common/IMessageHandler.h" #include "GUI/Runs/IRunsPresenter.h" #include "IMainWindowView.h" +#include "MantidAPI/AlgorithmManager.h" +#include "MantidAPI/MatrixWorkspace.h" +#include "MantidKernel/ConfigService.h" #include "MantidQtWidgets/Common/HelpWindow.h" #include "MantidQtWidgets/Common/QtJSONUtils.h" #include "Reduction/Batch.h" @@ -21,6 +24,14 @@ namespace MantidQt { namespace CustomInterfaces { namespace ISISReflectometry { +using Mantid::API::AlgorithmManager; +using Mantid::API::MatrixWorkspace_sptr; + +// unnamed namespace +namespace { +Mantid::Kernel::Logger g_log("Reflectometry GUI"); +} + /** Constructor * @param view :: [input] The view we are managing * @param messageHandler :: Interface to a class that displays messages to @@ -32,7 +43,8 @@ MainWindowPresenter::MainWindowPresenter( IMainWindowView *view, IMessageHandler *messageHandler, std::unique_ptr<IBatchPresenterFactory> batchPresenterFactory) : m_view(view), m_messageHandler(messageHandler), - m_batchPresenterFactory(std::move(batchPresenterFactory)) { + m_batchPresenterFactory(std::move(batchPresenterFactory)), + m_instrument() { view->subscribe(this); for (auto *batchView : m_view->batches()) addNewBatch(batchView); @@ -83,6 +95,20 @@ void MainWindowPresenter::reductionResumed() { disableSaveAndLoadBatch(); } // Called on autoreduction normal reduction void MainWindowPresenter::reductionPaused() { enableSaveAndLoadBatch(); } +void MainWindowPresenter::notifyInstrumentChangedRequested( + std::string const &instrumentName) { + // Re-load instrument with the new name + updateInstrument(instrumentName); +} + +void MainWindowPresenter::notifyUpdateInstrumentRequested() { + // An instrument should have been set up before any calls to this function. + if (!instrument()) + throw std::runtime_error("Internal error: instrument has not been set"); + // Re-load instrument with the existing name. + updateInstrument(instrumentName()); +} + void MainWindowPresenter::notifyHelpPressed() { showHelp(); } bool MainWindowPresenter::isAnyBatchProcessing() const { @@ -147,6 +173,39 @@ void MainWindowPresenter::disableSaveAndLoadBatch() { void MainWindowPresenter::enableSaveAndLoadBatch() { m_view->enableSaveAndLoadBatch(); } + +Mantid::Geometry::Instrument_const_sptr +MainWindowPresenter::instrument() const { + return m_instrument; +} + +std::string MainWindowPresenter::instrumentName() const { + if (m_instrument) + return m_instrument->getName(); + + return std::string(); +} + +void MainWindowPresenter::updateInstrument(const std::string &instrumentName) { + Mantid::Kernel::ConfigService::Instance().setString("default.instrument", + instrumentName); + g_log.information() << "Instrument changed to " << instrumentName; + + // Load a workspace for this instrument so we can get the actual instrument + auto loadAlg = + AlgorithmManager::Instance().createUnmanaged("LoadEmptyInstrument"); + loadAlg->setChild(true); + loadAlg->initialize(); + loadAlg->setProperty("InstrumentName", instrumentName); + loadAlg->setProperty("OutputWorkspace", + "__Reflectometry_GUI_Empty_Instrument"); + loadAlg->execute(); + MatrixWorkspace_sptr instWorkspace = loadAlg->getProperty("OutputWorkspace"); + m_instrument = instWorkspace->getInstrument(); + + for (auto &batchPresenter : m_batchPresenters) + batchPresenter->notifyInstrumentChanged(instrumentName); +} } // namespace ISISReflectometry } // namespace CustomInterfaces } // namespace MantidQt diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h index 76056df6fb2456df58a36afac78453de355e7f0e..16de5b1ce81780168d7892361a1e244e96b645ff 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h @@ -11,6 +11,7 @@ #include "GUI/Batch/IBatchPresenter.h" #include "IMainWindowPresenter.h" #include "IMainWindowView.h" +#include "MantidGeometry/Instrument.h" #include <memory> namespace MantidQt { @@ -47,6 +48,11 @@ public: void notifyAutoreductionPaused() override; void reductionResumed() override; void reductionPaused() override; + void + notifyInstrumentChangedRequested(std::string const &instrumentName) override; + void notifyUpdateInstrumentRequested() override; + Mantid::Geometry::Instrument_const_sptr instrument() const override; + std::string instrumentName() const override; // MainWindowSubscriber overrides void notifyHelpPressed() override; @@ -62,8 +68,13 @@ protected: std::unique_ptr<IBatchPresenterFactory> m_batchPresenterFactory; private: + Mantid::Geometry::Instrument_const_sptr m_instrument; + void showHelp(); void addNewBatch(IBatchView *batchView); + void changeInstrument(std::string const &instrumentName); + void updateInstrument(const std::string &instrumentName); + void disableSaveAndLoadBatch(); void enableSaveAndLoadBatch(); diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Batch/BatchPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/Batch/BatchPresenterTest.h index d33be4f20634023a99654d644c7df32697dba49d..9cb4b2b72e06194eb698d37a6c7757658a62cf2d 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/Batch/BatchPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/Batch/BatchPresenterTest.h @@ -54,7 +54,16 @@ public: verifyAndClear(); } - void testChildPresentersUpdatedWhenInstrumentChanged() { + void testMainPresenterUpdatedWhenInstrumentChangedRequested() { + auto presenter = makePresenter(); + auto const instrument = std::string("POLREF"); + EXPECT_CALL(m_mainPresenter, notifyInstrumentChangedRequested(instrument)) + .Times(1); + presenter.notifyInstrumentChangedRequested(instrument); + verifyAndClear(); + } + + void testChildPresentersAreUpdatedWhenInstrumentChanged() { auto presenter = makePresenter(); auto const instrument = std::string("POLREF"); EXPECT_CALL(*m_runsPresenter, notifyInstrumentChanged(instrument)).Times(1); @@ -62,7 +71,15 @@ public: .Times(1); EXPECT_CALL(*m_instrumentPresenter, notifyInstrumentChanged(instrument)) .Times(1); - presenter.notifyInstrumentChangedRequested(instrument); + presenter.notifyInstrumentChanged(instrument); + verifyAndClear(); + } + + void testMainPresenterUpdatedWhenUpdateInstrumentRequested() { + auto presenter = makePresenter(); + auto const instrument = std::string("POLREF"); + EXPECT_CALL(m_mainPresenter, notifyUpdateInstrumentRequested()).Times(1); + presenter.notifyUpdateInstrumentRequested(); verifyAndClear(); } diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h index bf25dffe5f9f7dbc3c86e3e94d57315ce66f4dd1..7c79caf360900639f0ad97ae9004ebf20c48e409 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h @@ -473,35 +473,33 @@ public: verifyAndClear(); } - void testRestoreDefaultsNotifiesMainPresenter() { - auto defaultOptions = expectDefaults(makeEmptyExperiment()); - auto presenter = makePresenter(std::move(defaultOptions)); - EXPECT_CALL(m_mainPresenter, notifyRestoreDefaultsRequested()) - .Times(AtLeast(1)); + void testRestoreDefaultsUpdatesInstrument() { + auto presenter = makePresenter(); + EXPECT_CALL(m_mainPresenter, notifyUpdateInstrumentRequested()).Times(1); presenter.notifyRestoreDefaultsRequested(); verifyAndClear(); } - void testRestoreDefaultsUpdatesAnalysisModeInView() { + void testInstrumentChangedUpdatesAnalysisModeInView() { auto model = makeModelWithAnalysisMode(AnalysisMode::MultiDetector); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); EXPECT_CALL(m_view, setAnalysisMode("MultiDetectorAnalysis")).Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); verifyAndClear(); } - void testRestoreDefaultsUpdatesAnalysisModeInModel() { + void testInstrumentChangedUpdatesAnalysisModeInModel() { auto model = makeModelWithAnalysisMode(AnalysisMode::MultiDetector); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); TS_ASSERT_EQUALS(presenter.experiment().analysisMode(), AnalysisMode::MultiDetector); verifyAndClear(); } - void testRestoreDefaultsUpdatesReductionOptionsInView() { + void testInstrumentChangedUpdatesReductionOptionsInView() { auto model = makeModelWithReduction(SummationType::SumInQ, ReductionType::NonFlatSample, true); auto defaultOptions = expectDefaults(model); @@ -509,16 +507,16 @@ public: EXPECT_CALL(m_view, setSummationType("SumInQ")).Times(1); EXPECT_CALL(m_view, setReductionType("NonFlatSample")).Times(1); EXPECT_CALL(m_view, setIncludePartialBins(true)).Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); verifyAndClear(); } - void testRestoreDefaultsUpdatesReductionOptionsInModel() { + void testInstrumentChangedUpdatesReductionOptionsInModel() { auto model = makeModelWithReduction(SummationType::SumInQ, ReductionType::NonFlatSample, true); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); TS_ASSERT_EQUALS(presenter.experiment().summationType(), SummationType::SumInQ); TS_ASSERT_EQUALS(presenter.experiment().reductionType(), @@ -527,25 +525,25 @@ public: verifyAndClear(); } - void testRestoreDefaultsUpdatesDebugOptionsInView() { + void testInstrumentChangedUpdatesDebugOptionsInView() { auto model = makeModelWithDebug(true); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); EXPECT_CALL(m_view, setDebugOption(true)).Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); verifyAndClear(); } - void testRestoreDefaultsUpdatesDebugOptionsInModel() { + void testInstrumentChangedUpdatesDebugOptionsInModel() { auto model = makeModelWithDebug(true); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); TS_ASSERT_EQUALS(presenter.experiment().debug(), true); verifyAndClear(); } - void testRestoreDefaultsUpdatesPerThetaInView() { + void testInstrumentChangedUpdatesPerThetaInView() { auto perThetaDefaults = PerThetaDefaults( boost::none, TransmissionRunPair(), boost::none, RangeInQ(0.01, 0.03, 0.2), 0.7, std::string("390-415")); @@ -556,17 +554,17 @@ public: {"", "", "", "", "0.010000", "0.200000", "0.030000", "0.700000", "390-415"}}; EXPECT_CALL(m_view, setPerAngleOptions(expected)).Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); verifyAndClear(); } - void testRestoreDefaultsUpdatesPerThetaInModel() { + void testInstrumentChangedUpdatesPerThetaInModel() { auto model = makeModelWithPerThetaDefaults(PerThetaDefaults( boost::none, TransmissionRunPair(), boost::none, RangeInQ(0.01, 0.03, 0.2), 0.7, std::string("390-415"))); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); auto expected = PerThetaDefaults(boost::none, TransmissionRunPair(), boost::none, RangeInQ(0.01, 0.03, 0.2), 0.7, std::string("390-415")); @@ -576,22 +574,22 @@ public: verifyAndClear(); } - void testRestoreDefaultsUpdatesTransmissionRunRangeInView() { + void testInstrumentChangedUpdatesTransmissionRunRangeInView() { auto model = makeModelWithTransmissionRunRange(RangeInLambda{10.0, 12.0}); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); EXPECT_CALL(m_view, setTransmissionStartOverlap(10.0)).Times(1); EXPECT_CALL(m_view, setTransmissionEndOverlap(12.0)).Times(1); EXPECT_CALL(m_view, showTransmissionRangeValid()).Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); verifyAndClear(); } - void testRestoreDefaultsUpdatesTransmissionRunRangeInModel() { + void testInstrumentChangedUpdatesTransmissionRunRangeInModel() { auto model = makeModelWithTransmissionRunRange(RangeInLambda{10.0, 12.0}); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); auto const expected = RangeInLambda{10.0, 12.0}; TS_ASSERT_EQUALS( presenter.experiment().transmissionStitchOptions().overlapRange(), @@ -599,7 +597,7 @@ public: verifyAndClear(); } - void testRestoreDefaultsUpdatesCorrectionInView() { + void testInstrumentChangedUpdatesCorrectionInView() { auto model = makeModelWithCorrections( PolarizationCorrections(PolarizationCorrectionType::ParameterFile), FloodCorrections(FloodCorrectionType::ParameterFile)); @@ -607,17 +605,17 @@ public: auto presenter = makePresenter(std::move(defaultOptions)); EXPECT_CALL(m_view, setPolarizationCorrectionOption(true)).Times(1); EXPECT_CALL(m_view, setFloodCorrectionType("ParameterFile")).Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); verifyAndClear(); } - void testRestoreDefaultsUpdatesCorrectionInModel() { + void testInstrumentChangedUpdatesCorrectionInModel() { auto model = makeModelWithCorrections( PolarizationCorrections(PolarizationCorrectionType::ParameterFile), FloodCorrections(FloodCorrectionType::ParameterFile)); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); TS_ASSERT_EQUALS( presenter.experiment().polarizationCorrections().correctionType(), PolarizationCorrectionType::ParameterFile); @@ -626,12 +624,12 @@ public: verifyAndClear(); } - void testRestoreDefaultsDisconnectsNotificationsBackFromView() { + void testInstrumentChangedDisconnectsNotificationsBackFromView() { auto defaultOptions = expectDefaults(makeEmptyExperiment()); EXPECT_CALL(m_view, disconnectExperimentSettingsWidgets()).Times(1); EXPECT_CALL(m_view, connectExperimentSettingsWidgets()).Times(1); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); verifyAndClear(); } diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Instrument/InstrumentPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/Instrument/InstrumentPresenterTest.h index f129b02959db84da31db1b28c0c80d94d1cc2795..576ee0fa95845194192c51abcb8a2ff38391206b 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/Instrument/InstrumentPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/Instrument/InstrumentPresenterTest.h @@ -253,17 +253,14 @@ public: verifyAndClear(); } - void testRestoreDefaultsNotifiesMainPresenter() { - auto defaultOptions = - expectDefaults(ModelCreationHelper::makeEmptyInstrument()); - auto presenter = makePresenter(std::move(defaultOptions)); - EXPECT_CALL(m_mainPresenter, notifyRestoreDefaultsRequested()) - .Times(AtLeast(1)); + void testRestoreDefaultsUpdatesInstrument() { + auto presenter = makePresenter(); + EXPECT_CALL(m_mainPresenter, notifyUpdateInstrumentRequested()).Times(1); presenter.notifyRestoreDefaultsRequested(); verifyAndClear(); } - void testRestoreDefaultsUpdatesMonitorOptionsInView() { + void testInstrumentChangedUpdatesMonitorOptionsInView() { auto model = makeModelWithMonitorOptions(MonitorCorrections( 2, true, RangeInLambda(17.0, 18.0), RangeInLambda(4.0, 10.0))); auto defaultOptions = expectDefaults(model); @@ -274,16 +271,16 @@ public: EXPECT_CALL(m_view, setMonitorBackgroundMax(18.0)).Times(1); EXPECT_CALL(m_view, setMonitorIntegralMin(4.0)).Times(1); EXPECT_CALL(m_view, setMonitorIntegralMax(10.0)).Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); verifyAndClear(); } - void testRestoreDefaultsUpdatesMonitorOptionsInModel() { + void testInstrumentChangedUpdatesMonitorOptionsInModel() { auto model = makeModelWithMonitorOptions(MonitorCorrections( 2, true, RangeInLambda(17.0, 18.0), RangeInLambda(4.0, 10.0))); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); TS_ASSERT_EQUALS(presenter.instrument().monitorIndex(), 2); TS_ASSERT_EQUALS(presenter.instrument().integratedMonitors(), true); TS_ASSERT_EQUALS(presenter.instrument().monitorBackgroundRange(), @@ -293,27 +290,27 @@ public: verifyAndClear(); } - void testRestoreDefaultsUpdatesWavelengthRangeInView() { + void testInstrumentChangedUpdatesWavelengthRangeInView() { auto model = makeModelWithWavelengthRange(RangeInLambda(1.5, 17.0)); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); EXPECT_CALL(m_view, setLambdaMin(1.5)).Times(1); EXPECT_CALL(m_view, setLambdaMax(17.0)).Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); verifyAndClear(); } - void testRestoreDefaultsUpdatesWavelengthRangeInModel() { + void testInstrumentChangedUpdatesWavelengthRangeInModel() { auto model = makeModelWithWavelengthRange(RangeInLambda(1.5, 17.0)); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); TS_ASSERT_EQUALS(presenter.instrument().wavelengthRange(), RangeInLambda(1.5, 17.0)); verifyAndClear(); } - void testRestoreDefaultsUpdatesUpdatesDetectorOptionsInView() { + void testInstrumentChangedUpdatesUpdatesDetectorOptionsInView() { auto model = makeModelWithDetectorCorrections( DetectorCorrections(true, DetectorCorrectionType::RotateAroundSample)); auto defaultOptions = expectDefaults(model); @@ -321,16 +318,16 @@ public: EXPECT_CALL(m_view, setCorrectDetectors(true)).Times(1); EXPECT_CALL(m_view, setDetectorCorrectionType("RotateAroundSample")) .Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); verifyAndClear(); } - void testRestoreDefaultsUpdatesUpdatesDetectorOptionsInModel() { + void testInstrumentChangedUpdatesUpdatesDetectorOptionsInModel() { auto model = makeModelWithDetectorCorrections( DetectorCorrections(true, DetectorCorrectionType::RotateAroundSample)); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.notifyInstrumentChanged("POLREF"); auto const expected = DetectorCorrections(true, DetectorCorrectionType::RotateAroundSample); TS_ASSERT_EQUALS(presenter.instrument().detectorCorrections(), expected); diff --git a/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h index de79e4a0ae20ca8fffc0e091a12ee5ff58fcaf32..c61a1b126aac7ae231d04485a2e4315138bf453b 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h @@ -188,6 +188,54 @@ public: verifyAndClear(); } + void testInstrumentChangedRequestedUpdatesInstrumentInModel() { + auto presenter = makePresenter(); + auto const instrument = std::string("POLREF"); + presenter.notifyInstrumentChangedRequested(instrument); + TS_ASSERT_EQUALS(presenter.instrumentName(), instrument); + verifyAndClear(); + } + + void testInstrumentChangedRequestedUpdatesInstrumentInChildPresenters() { + auto presenter = makePresenter(); + auto const instrument = std::string("POLREF"); + EXPECT_CALL(*m_batchPresenters[0], notifyInstrumentChanged(instrument)) + .Times(1); + EXPECT_CALL(*m_batchPresenters[1], notifyInstrumentChanged(instrument)) + .Times(1); + presenter.notifyInstrumentChangedRequested(instrument); + verifyAndClear(); + } + + void testUpdateInstrumentRequestedUpdatesInstrumentInChildPresenters() { + auto presenter = makePresenter(); + // must set the instrument to something valid first + presenter.notifyInstrumentChangedRequested("POLREF"); + auto const instrument = presenter.instrumentName(); + EXPECT_CALL(*m_batchPresenters[0], notifyInstrumentChanged(instrument)) + .Times(1); + EXPECT_CALL(*m_batchPresenters[1], notifyInstrumentChanged(instrument)) + .Times(1); + presenter.notifyUpdateInstrumentRequested(); + verifyAndClear(); + } + + void testUpdateInstrumentRequestedDoesNotChangeInstrumentName() { + auto presenter = makePresenter(); + // must set the instrument to something valid first + presenter.notifyInstrumentChangedRequested("POLREF"); + auto const instrument = presenter.instrumentName(); + presenter.notifyUpdateInstrumentRequested(); + TS_ASSERT_EQUALS(presenter.instrumentName(), instrument); + verifyAndClear(); + } + + void testUpdateInstrumentRequestedThrowsIfInstrumentNotSet() { + auto presenter = makePresenter(); + TS_ASSERT_THROWS_ANYTHING(presenter.notifyUpdateInstrumentRequested()); + verifyAndClear(); + } + private: NiceMock<MockMainWindowView> m_view; NiceMock<MockMessageHandler> m_messageHandler; diff --git a/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MockMainWindowPresenter.h b/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MockMainWindowPresenter.h index 4ad7add0e1cd8f34faac080a12f336d647254570..d5a0fb68d952faa1f9387729fed4792d5efd2db2 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MockMainWindowPresenter.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MockMainWindowPresenter.h @@ -22,6 +22,10 @@ public: MOCK_METHOD0(notifyAutoreductionPaused, void()); MOCK_METHOD0(reductionResumed, void()); MOCK_METHOD0(reductionPaused, void()); + MOCK_METHOD1(notifyInstrumentChangedRequested, void(std::string const &)); + MOCK_METHOD0(notifyUpdateInstrumentRequested, void()); + MOCK_CONST_METHOD0(instrument, Mantid::Geometry::Instrument_const_sptr()); + MOCK_CONST_METHOD0(instrumentName, std::string()); ~MockMainWindowPresenter() override{}; }; diff --git a/qt/scientific_interfaces/test/ISISReflectometry/ReflMockObjects.h b/qt/scientific_interfaces/test/ISISReflectometry/ReflMockObjects.h index 6cbca70fd637580997ee78c0975b057378f83dec..e918840f1b93bc3f88897a9d7cb849251a7ef08a 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/ReflMockObjects.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/ReflMockObjects.h @@ -65,6 +65,8 @@ public: MOCK_METHOD0(reductionPaused, void()); MOCK_METHOD1(notifyInstrumentChangedRequested, void(const std::string &)); + MOCK_METHOD1(notifyInstrumentChanged, void(const std::string &)); + MOCK_METHOD0(notifyUpdateInstrumentRequested, void()); MOCK_METHOD0(notifyRestoreDefaultsRequested, void()); MOCK_METHOD0(notifySettingsChanged, void()); MOCK_CONST_METHOD0(isProcessing, bool());