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

Add ability to store/query processing state

This is based around the main isProcessing and isAutoreducing methods in the Batch presenter.
Also changed the instrument list initialisation in the Runs view to happen after the presenter has accepted the main presenter. This is because the notifications need to go via the main presenter.

Re #23041
parent cc6f2292
No related merge requests found
Showing with 64 additions and 41 deletions
......@@ -35,8 +35,8 @@ public:
virtual void autoreductionResumed() = 0;
virtual void setInstrumentName(std::string const &instrumentName) = 0;
virtual bool isAutoreducing() const = 0;
virtual bool isProcessing() const = 0;
virtual bool isAutoreducing() const = 0;
};
} // namespace CustomInterfaces
} // namespace MantidQt
......
......@@ -71,16 +71,15 @@ RunsPresenter::RunsPresenter(
m_progressView(progressableView),
m_makeRunsTablePresenter(std::move(makeRunsTablePresenter)),
m_mainPresenter(nullptr), m_messageHandler(messageHandler),
m_searcher(searcher), m_instrumentChanged(false),
m_thetaTolerance(thetaTolerance) {
m_searcher(searcher), m_instruments(instruments),
m_defaultInstrumentIndex(defaultInstrumentIndex),
m_instrumentChanged(false), m_thetaTolerance(thetaTolerance) {
assert(m_view != nullptr);
m_view->subscribe(this);
m_tablePresenter = m_makeRunsTablePresenter(m_view->table());
m_tablePresenter->acceptMainPresenter(this);
m_view->setInstrumentList(instruments, defaultInstrumentIndex);
if (!m_autoreduction)
m_autoreduction.reset(new ReflAutoreduction());
......@@ -101,6 +100,9 @@ RunsPresenter::~RunsPresenter() {
*/
void RunsPresenter::acceptMainPresenter(IReflBatchPresenter *mainPresenter) {
m_mainPresenter = mainPresenter;
// Must do this after setting main presenter or notifications don't get
// through
m_view->setInstrumentList(m_instruments, m_defaultInstrumentIndex);
// Register this presenter as the workspace receiver
// When doing so, the inner presenters will notify this
// presenter with the list of commands
......@@ -142,28 +144,23 @@ void RunsPresenter::notifyInstrumentChanged() {
}
void RunsPresenter::notifyInstrumentChanged(std::string const &instrumentName) {
if (m_mainPresenter)
m_mainPresenter->notifyInstrumentChanged(instrumentName);
m_mainPresenter->notifyInstrumentChanged(instrumentName);
}
void RunsPresenter::notifyReductionResumed() {
if (m_mainPresenter)
m_mainPresenter->notifyReductionResumed();
m_mainPresenter->notifyReductionResumed();
}
void RunsPresenter::notifyReductionPaused() {
if (m_mainPresenter)
m_mainPresenter->notifyReductionPaused();
m_mainPresenter->notifyReductionPaused();
}
void RunsPresenter::notifyAutoreductionResumed() {
if (m_mainPresenter)
m_mainPresenter->notifyAutoreductionResumed();
m_mainPresenter->notifyAutoreductionResumed();
}
void RunsPresenter::notifyAutoreductionPaused() {
if (isAutoreducing() && m_mainPresenter)
m_mainPresenter->notifyAutoreductionPaused();
m_mainPresenter->notifyAutoreductionPaused();
}
void RunsPresenter::notifyStartMonitor() { startMonitor(); }
......@@ -267,11 +264,17 @@ void RunsPresenter::autoreductionResumed() {
//}
}
if (setupNewAutoreduction(m_view->getSearchString()))
if (m_autoreduction->setupNewAutoreduction(m_view->getSearchString()))
checkForNewRuns();
updateWidgetEnabledState();
}
void RunsPresenter::autoreductionPaused() {}
void RunsPresenter::autoreductionPaused() {
m_view->stopTimer();
m_autoreduction->stop();
updateWidgetEnabledState();
}
/** Determines whether to start a new autoreduction. Starts a new one if the
* either the search number, transfer method or instrument has changed
......@@ -284,10 +287,6 @@ bool RunsPresenter::requireNewAutoreduction() const {
return searchNumChanged || m_instrumentChanged;
}
bool RunsPresenter::setupNewAutoreduction(const std::string &searchString) {
return m_autoreduction->setupNewAutoreduction(searchString);
}
/** Start a single autoreduction process. Called periodially to add and process
* any new runs in the table.
*/
......@@ -309,7 +308,7 @@ void RunsPresenter::autoreduceNewRuns() {
if (rowsToTransfer.size() > 0) {
transfer(rowsToTransfer, TransferMatch::Strict);
} else if (m_mainPresenter) {
} else {
m_mainPresenter->notifyAutoreductionCompleted();
}
}
......@@ -319,13 +318,12 @@ void RunsPresenter::stopAutoreduction() {
m_autoreduction->stop();
}
bool RunsPresenter::isAutoreducing() const {
return m_autoreduction->running();
bool RunsPresenter::isProcessing() const {
return m_mainPresenter->isProcessing();
}
bool RunsPresenter::isProcessing() const {
// TODO define this properly when we enable processing
return false;
bool RunsPresenter::isAutoreducing() const {
return m_mainPresenter->isAutoreducing();
}
void RunsPresenter::icatSearchComplete() {
......@@ -442,16 +440,15 @@ void RunsPresenter::transfer(const std::set<int> &rowsToTransfer,
*/
void RunsPresenter::updateWidgetEnabledState() const {
// Update the menus
// TODO: reinstate isProcessing when implemented
m_view->updateMenuEnabledState(false /*isProcessing()*/);
m_view->updateMenuEnabledState(isProcessing());
// Update components
m_view->setTransferButtonEnabled(/*!isProcessing() &&*/ !isAutoreducing());
m_view->setInstrumentComboEnabled(/*!isProcessing() &&*/ !isAutoreducing());
m_view->setAutoreducePauseButtonEnabled(isAutoreducing());
m_view->setInstrumentComboEnabled(!isProcessing() && !isAutoreducing());
m_view->setSearchTextEntryEnabled(!isAutoreducing());
m_view->setSearchButtonEnabled(!isAutoreducing());
m_view->setAutoreduceButtonEnabled(!isAutoreducing() /*&& !isProcessing()*/);
m_view->setAutoreduceButtonEnabled(!isAutoreducing() && !isProcessing());
m_view->setAutoreducePauseButtonEnabled(isAutoreducing());
m_view->setTransferButtonEnabled(!isProcessing() && !isAutoreducing());
}
/** Changes the current instrument in the data processor widget. Currently
......
......@@ -73,8 +73,8 @@ public:
void acceptMainPresenter(IReflBatchPresenter *mainPresenter) override;
void settingsChanged() override;
void setInstrumentName(std::string const &instrumentName) override;
bool isAutoreducing() const override;
bool isProcessing() const override;
bool isAutoreducing() const override;
void notifyInstrumentChanged(std::string const &instrumentName) override;
void notifyReductionResumed() override;
void notifyReductionPaused() override;
......@@ -118,6 +118,10 @@ private:
IReflMessageHandler *m_messageHandler;
/// The search implementation
boost::shared_ptr<IReflSearcher> m_searcher;
/// The list of instruments
std::vector<std::string> m_instruments;
/// The default index in the instrument list
int m_defaultInstrumentIndex;
/// Whether the instrument has been changed before a search was made with it
bool m_instrumentChanged;
/// The name to use for the live data workspace
......@@ -130,7 +134,6 @@ private:
void populateSearch(Mantid::API::IAlgorithm_sptr searchAlg);
/// autoreduction
bool requireNewAutoreduction() const;
bool setupNewAutoreduction(const std::string &searchString);
void checkForNewRuns();
void autoreduceNewRuns();
void stopAutoreduction();
......
......@@ -46,6 +46,7 @@ public:
virtual bool hasPerAngleOptions() const = 0;
/// Data processing check for all groups
virtual bool isProcessing() const = 0;
virtual bool isAutoreducing() const = 0;
virtual bool requestClose() const = 0;
virtual void settingsChanged() = 0;
};
......
......@@ -84,6 +84,7 @@ void ReflBatchPresenter::notifyAutoreductionCompleted() {
}
void ReflBatchPresenter::reductionResumed() {
m_isProcessing = true;
m_savePresenter->reductionResumed();
m_eventPresenter->reductionResumed();
m_experimentPresenter->reductionResumed();
......@@ -92,6 +93,7 @@ void ReflBatchPresenter::reductionResumed() {
}
void ReflBatchPresenter::reductionPaused() {
m_isProcessing = false;
m_savePresenter->reductionPaused();
m_eventPresenter->reductionPaused();
m_experimentPresenter->reductionPaused();
......@@ -110,10 +112,12 @@ void ReflBatchPresenter::reductionCompletedForRow(
}
void ReflBatchPresenter::autoreductionResumed() {
m_isAutoreducing = true;
m_runsPresenter->autoreductionResumed();
}
void ReflBatchPresenter::autoreductionPaused() {
m_isAutoreducing = false;
m_runsPresenter->autoreductionPaused();
}
......@@ -156,11 +160,16 @@ void ReflBatchPresenter::setInstrumentName(
}
/**
Checks whether or not data is currently being processed in the Runs Tab
Checks whether or not data is currently being processed in this batch
* @return : Bool on whether data is being processed
*/
bool ReflBatchPresenter::isProcessing() const {
return m_runsPresenter->isProcessing();
}
bool ReflBatchPresenter::isProcessing() const { return m_isProcessing; }
/**
Checks whether or not autoprocessing is currently running in this batch
* i.e. whether we are polling for new runs
* @return : Bool on whether data is being processed
*/
bool ReflBatchPresenter::isAutoreducing() const { return m_isAutoreducing; }
} // namespace CustomInterfaces
} // namespace MantidQt
......@@ -53,9 +53,10 @@ public:
MantidWidgets::DataProcessor::OptionsQMap
getOptionsForAngle(const double angle) const override;
void notifyInstrumentChanged(const std::string &instName) const override;
bool isProcessing() const override;
bool requestClose() const override;
void settingsChanged() override;
bool isProcessing() const override;
bool isAutoreducing() const override;
private:
void setInstrumentName(const std::string &instName) const;
......@@ -81,6 +82,10 @@ private:
std::unique_ptr<IInstrumentPresenter> m_instrumentPresenter;
/// The presenter of tab 'Save ASCII'
std::unique_ptr<ISavePresenter> m_savePresenter;
/// True if currently reducing runs
bool m_isProcessing;
/// True if autoprocessing is currently running (i.e. polling for new runs)
bool m_isAutoreducing;
};
} // namespace CustomInterfaces
} // namespace MantidQt
......
......@@ -45,7 +45,10 @@ Used by the view to tell the presenter something has changed
void ReflMainWindowPresenter::notifyHelpPressed() { showHelp(); }
bool ReflMainWindowPresenter::isProcessing() const {
// TODO Implement this once you have ownership of child presenters.
for (auto batchPresenter : m_batchPresenters) {
if (batchPresenter->isProcessing())
return true;
}
return false;
}
......
......@@ -91,6 +91,10 @@ public:
verifyAndClear();
}
void testReductionResumed() {}
void testReductionPaused() {}
void testNotifyAutoreductionResumed() {
auto presenter = makePresenter();
EXPECT_CALL(m_mainPresenter, notifyAutoreductionResumed());
......
......@@ -98,6 +98,7 @@ public:
MOCK_CONST_METHOD1(notifyInstrumentChanged, void(const std::string &));
/// Data processing check for all groups
MOCK_CONST_METHOD0(isProcessing, bool());
MOCK_CONST_METHOD0(isAutoreducing, bool());
MOCK_CONST_METHOD0(requestClose, bool());
MOCK_METHOD0(settingsChanged, void());
};
......
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