Skip to content

Commit

Permalink
run calib in separate thread, adjust test without thread, re #12610
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeMPouzols committed Aug 18, 2015
1 parent 3bf947c commit 4b84e93
Show file tree
Hide file tree
Showing 7 changed files with 323 additions and 91 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ set ( INC_FILES
inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h
inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffCalibSettings.h
inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h
inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresWorker.h
inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h
inc/MantidQtCustomInterfaces/Homer.h
inc/MantidQtCustomInterfaces/Indirect/AbsorptionCorrections.h
Expand Down Expand Up @@ -221,6 +222,8 @@ set ( SRC_UNITY_IGNORE_FILES )
set ( MOC_FILES inc/MantidQtCustomInterfaces/Background.h
inc/MantidQtCustomInterfaces/DataComparison.h
inc/MantidQtCustomInterfaces/DirectConvertToEnergy.h
inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h
inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresWorker.h
inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h
inc/MantidQtCustomInterfaces/Homer.h
inc/MantidQtCustomInterfaces/Indirect/AbsorptionCorrections.h
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#ifndef MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_ENGGDIFFRACTIONPRESWORKER_H_
#define MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_ENGGDIFFRACTIONPRESWORKER_H_

#include "MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h"

#include <QThread>

namespace MantidQt {
namespace CustomInterfaces {

/**
Worker to run long tasks for the presenter of the EnggDiffraction
GUI. It has a finished() signal, and it is expected to emit it when
the hard/long-work methods finish.
Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD
Oak Ridge National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class EnggDiffWorker : public QObject {
Q_OBJECT

public:
EnggDiffWorker(EnggDiffractionPresenter *pres,
const std::string &outFilename, const std::string &vanNo,
const std::string &ceriaNo)
: m_pres(pres), m_outFilename(outFilename), m_vanNo(vanNo),
m_ceriaNo(ceriaNo) {}

private slots:

/**
* Calculate a new calibration. Connect this from a thread started()
* signal.
*/
void calibrate() {
m_pres->doNewCalibration(m_outFilename, m_vanNo, m_ceriaNo);
emit finished();
}

signals:
void finished();

private:
EnggDiffractionPresenter *m_pres;
/// parameters for calibration
std::string m_outFilename, m_vanNo, m_ceriaNo;
};

} // namespace CustomInterfaces
} // namespace MantidQt

#endif // MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_ENGGDIFFRACTIONPRESWORKER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

#include <boost/scoped_ptr.hpp>

#include <QObject>

class QThread;

namespace MantidQt {
namespace CustomInterfaces {

Expand Down Expand Up @@ -41,7 +45,10 @@ File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
// needs to be dll-exported for the tests
class DLLExport EnggDiffractionPresenter : public IEnggDiffractionPresenter {
class DLLExport EnggDiffractionPresenter : public QObject,
public IEnggDiffractionPresenter {
// Q_OBJECT for 'connect' with thread/worker
Q_OBJECT

public:
/// Default constructor - normally used from the concrete view
Expand All @@ -50,6 +57,10 @@ class DLLExport EnggDiffractionPresenter : public IEnggDiffractionPresenter {

virtual void notify(IEnggDiffractionPresenter::Notification notif);

// this is the hard work that a worker / thread will run
void doNewCalibration(const std::string &outFilename,
const std::string &vanNo, const std::string &ceriaNo);

protected:
void initialize();

Expand All @@ -63,10 +74,17 @@ class DLLExport EnggDiffractionPresenter : public IEnggDiffractionPresenter {
void processInstChange();
void processShutDown();

protected slots:
void calibrationFinished();

private:
std::string buildCalibrateSuggestedFilename(const std::string &vanNo,
const std::string &ceriaNo) const;

virtual void startAsynCalibWorker(const std::string &outFilename,
const std::string &vanNo,
const std::string &ceriaNo);

void doCalib(const EnggDiffCalibSettings &cs, const std::string &vanNo,
const std::string &ceriaNo, const std::string &outFilename);

Expand Down Expand Up @@ -100,6 +118,11 @@ class DLLExport EnggDiffractionPresenter : public IEnggDiffractionPresenter {
/// whether to allow users to give the output calibration filename
const static bool g_askUserCalibFilename;

QThread *m_workerThread;

/// true if the last calibration completed successfully
bool m_calibFinishedOK;

/// Associated view for this presenter (MVP pattern)
IEnggDiffractionView *const m_view;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</layout>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox_2">
<widget class="QGroupBox" name="groupBox_current_calib">
<property name="title">
<string>Current calibration:</string>
</property>
Expand Down Expand Up @@ -160,7 +160,7 @@
</spacer>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<widget class="QGroupBox" name="groupBox_make_new_calib">
<property name="title">
<string>Make new calibration</string>
</property>
Expand Down

0 comments on commit 4b84e93

Please sign in to comment.