Skip to content
Snippets Groups Projects
Commit 0a0b9c13 authored by Gemma Guest's avatar Gemma Guest
Browse files

Set the correct facility for the reflectometry GUI

The reflectometry GUI sets the default instrument in the config service
when it starts up to one of the ISIS reflectometers. This commit adds a
check that the facility is ISIS and if not it sets the facility to ISIS.
This avoids confusion where you essentially have invalid config. It also
avoids confusion where e.g. loading runs from the default archive might
not work because the archive may be a different facility.

I have also added code to save the new config settings to file. Again
this is to avoid confusion between what users see in mantid and what is
in the saved settings. It is particularly confusing otherwise because
Workbench will write settings to file when it closes but MantidPlot will not.

Re #27241
parent 0993721b
No related branches found
No related tags found
No related merge requests found
...@@ -222,9 +222,7 @@ std::string MainWindowPresenter::instrumentName() const { ...@@ -222,9 +222,7 @@ std::string MainWindowPresenter::instrumentName() const {
} }
void MainWindowPresenter::updateInstrument(const std::string &instrumentName) { void MainWindowPresenter::updateInstrument(const std::string &instrumentName) {
Mantid::Kernel::ConfigService::Instance().setString("default.instrument", setDefaultInstrument(instrumentName);
instrumentName);
g_log.information() << "Instrument changed to " << instrumentName;
// Load a workspace for this instrument so we can get the actual instrument // Load a workspace for this instrument so we can get the actual instrument
auto loadAlg = auto loadAlg =
...@@ -246,6 +244,24 @@ void MainWindowPresenter::updateInstrument(const std::string &instrumentName) { ...@@ -246,6 +244,24 @@ void MainWindowPresenter::updateInstrument(const std::string &instrumentName) {
m_slitCalculator->setCurrentInstrumentName(instrumentName); m_slitCalculator->setCurrentInstrumentName(instrumentName);
m_slitCalculator->processInstrumentHasBeenChanged(); m_slitCalculator->processInstrumentHasBeenChanged();
} }
void MainWindowPresenter::setDefaultInstrument(
const std::string &requiredInstrument) {
auto &config = Mantid::Kernel::ConfigService::Instance();
auto currentFacility = config.getString("default.facility");
auto requiredFacility = "ISIS";
if (currentFacility != requiredFacility) {
config.setString("default.facility", requiredFacility);
g_log.notice() << "Facility changed to " << requiredFacility;
}
auto currentInstrument = config.getString("default.instrument");
if (currentInstrument != requiredInstrument) {
config.setString("default.instrument", requiredInstrument);
g_log.notice() << "Instrument changed to " << requiredInstrument;
}
}
} // namespace ISISReflectometry } // namespace ISISReflectometry
} // namespace CustomInterfaces } // namespace CustomInterfaces
} // namespace MantidQt } // namespace MantidQt
...@@ -83,6 +83,7 @@ private: ...@@ -83,6 +83,7 @@ private:
std::string const &instrument); std::string const &instrument);
void changeInstrument(std::string const &instrumentName); void changeInstrument(std::string const &instrumentName);
void updateInstrument(const std::string &instrumentName); void updateInstrument(const std::string &instrumentName);
void setDefaultInstrument(const std::string &newInstrument);
void disableSaveAndLoadBatch(); void disableSaveAndLoadBatch();
void enableSaveAndLoadBatch(); void enableSaveAndLoadBatch();
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
// SPDX - License - Identifier: GPL - 3.0 + // SPDX - License - Identifier: GPL - 3.0 +
#include "QtRunsTableView.h" #include "QtRunsTableView.h"
#include "Common/IndexOf.h" #include "Common/IndexOf.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/UsageService.h" #include "MantidKernel/UsageService.h"
#include "MantidQtIcons/Icon.h" #include "MantidQtIcons/Icon.h"
#include "MantidQtWidgets/Common/AlgorithmHintStrategy.h" #include "MantidQtWidgets/Common/AlgorithmHintStrategy.h"
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "../ReflMockObjects.h" #include "../ReflMockObjects.h"
#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/FrameworkManager.h"
#include "MantidGeometry/Instrument_fwd.h" #include "MantidGeometry/Instrument_fwd.h"
#include "MantidKernel/ConfigService.h"
#include "MantidQtWidgets/Common/MockSlitCalculator.h" #include "MantidQtWidgets/Common/MockSlitCalculator.h"
#include "MockMainWindowView.h" #include "MockMainWindowView.h"
...@@ -49,6 +50,18 @@ public: ...@@ -49,6 +50,18 @@ public:
ON_CALL(m_view, batches()).WillByDefault(Return(m_batchViews)); ON_CALL(m_view, batches()).WillByDefault(Return(m_batchViews));
} }
void setUp() override {
auto &config = Mantid::Kernel::ConfigService::Instance();
backup_facility = config.getString("default.facility");
backup_instrument = config.getString("default.instrument");
}
void tearDown() override {
auto &config = Mantid::Kernel::ConfigService::Instance();
config.setString("default.facility", backup_facility);
config.setString("default.instrument", backup_instrument);
}
void testPresenterSubscribesToView() { void testPresenterSubscribesToView() {
EXPECT_CALL(m_view, subscribe(_)).Times(1); EXPECT_CALL(m_view, subscribe(_)).Times(1);
auto presenter = makePresenter(); auto presenter = makePresenter();
...@@ -282,6 +295,26 @@ public: ...@@ -282,6 +295,26 @@ public:
verifyAndClear(); verifyAndClear();
} }
void testUpdateInstrumentSetsFacilityInConfig() {
auto presenter = makePresenter();
auto const instrument = setupInstrument(presenter, "POLREF");
auto &config = Mantid::Kernel::ConfigService::Instance();
config.setString("default.facility", "OLD_FACILITY");
presenter.notifyUpdateInstrumentRequested();
TS_ASSERT_EQUALS(config.getString("default.facility"), "ISIS");
verifyAndClear();
}
void testUpdateInstrumentSetsInstrumentInConfig() {
auto presenter = makePresenter();
auto const instrument = setupInstrument(presenter, "POLREF");
auto &config = Mantid::Kernel::ConfigService::Instance();
config.setString("default.instrument", "OLD_INSTRUMENT");
presenter.notifyUpdateInstrumentRequested();
TS_ASSERT_EQUALS(config.getString("default.instrument"), instrument);
verifyAndClear();
}
private: private:
NiceMock<MockMainWindowView> m_view; NiceMock<MockMainWindowView> m_view;
NiceMock<MockMessageHandler> m_messageHandler; NiceMock<MockMessageHandler> m_messageHandler;
...@@ -428,6 +461,10 @@ private: ...@@ -428,6 +461,10 @@ private:
TS_ASSERT_EQUALS(presenter.m_batchPresenters[index].get(), TS_ASSERT_EQUALS(presenter.m_batchPresenters[index].get(),
m_batchPresenters[index]); m_batchPresenters[index]);
} }
private:
std::string backup_facility;
std::string backup_instrument;
}; };
#endif // MANTID_CUSTOMINTERFACES_MAINWINDOWPRESENTERTEST_H_ #endif // MANTID_CUSTOMINTERFACES_MAINWINDOWPRESENTERTEST_H_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment