Skip to content

Commit

Permalink
Modify AlgorithmDialog to add observers just before execution
Browse files Browse the repository at this point in the history
Refs #10377
  • Loading branch information
DanNixon committed Nov 10, 2014
1 parent e253d3d commit ab5d65d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
14 changes: 8 additions & 6 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Expand Up @@ -1386,15 +1386,12 @@ void MantidUI::showAlgorithmDialog(const QString & algName, int version)
* @param paramList :: A list of algorithm properties to be passed to Algorithm::setProperties
* @param obs :: A pointer to an instance of AlgorithmObserver which will be attached to the finish notification
*/
void MantidUI::showAlgorithmDialog(QString algName, QHash<QString,QString> paramList,Mantid::API::AlgorithmObserver* obs)
void MantidUI::showAlgorithmDialog(QString algName, QHash<QString,QString> paramList, Mantid::API::AlgorithmObserver *obs)
{
//Get latest version of the algorithm
Mantid::API::IAlgorithm_sptr alg = this->createAlgorithm(algName, -1);
if( !alg ) return;
if (obs)
{
obs->observeFinish(alg);
}

for(QHash<QString,QString>::Iterator it = paramList.begin(); it != paramList.end(); ++it)
{
alg->setPropertyValue(it.key().toStdString(),it.value().toStdString());
Expand All @@ -1408,6 +1405,11 @@ void MantidUI::showAlgorithmDialog(QString algName, QHash<QString,QString> param
connect(dlg, SIGNAL(accepted()), this, SLOT(loadFileDialogAccept()));
}

if (obs)
{
dlg->addAlgorithmObserver(obs);
}

dlg->show();
dlg->raise();
dlg->activateWindow();
Expand All @@ -1428,7 +1430,7 @@ void MantidUI::executeAlgorithm(Mantid::API::IAlgorithm_sptr alg)
* @param paramList :: A list of algorithm properties to be passed to Algorithm::setProperties
* @param obs :: A pointer to an instance of AlgorithmObserver which will be attached to the finish notification
*/
void MantidUI::executeAlgorithm(const QString & algName, const QString & paramList,Mantid::API::AlgorithmObserver* obs)
void MantidUI::executeAlgorithm(const QString & algName, const QString & paramList, Mantid::API::AlgorithmObserver* obs)
{
//Get latest version of the algorithm
Mantid::API::IAlgorithm_sptr alg = this->createAlgorithm(algName, -1);
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.h
Expand Up @@ -377,12 +377,12 @@ class MantidUI:public QObject

// Execute algorithm given name and version
void showAlgorithmDialog(const QString & algName, int version = -1);
//Execute an algorithm with the given parameter list
void showAlgorithmDialog(QString algName, QHash<QString, QString> paramList, Mantid::API::AlgorithmObserver* obs = NULL);
// Execute an algorithm with the given parameter list
void showAlgorithmDialog(QString algName, QHash<QString, QString> paramList, Mantid::API::AlgorithmObserver *obs = NULL);
// Execute an algorithm
void executeAlgorithm(Mantid::API::IAlgorithm_sptr alg);
// Execute a named algorithm using the given parameters
void executeAlgorithm(const QString & algName, const QString & paramList,Mantid::API::AlgorithmObserver* obs);
void executeAlgorithm(const QString & algName, const QString & paramList, Mantid::API::AlgorithmObserver* obs);

// Find the name of the first input workspace for an algorithm
QString findInputWorkspaceProperty(Mantid::API::IAlgorithm_sptr algorithm) const;
Expand Down
6 changes: 6 additions & 0 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/AlgorithmDialog.h
Expand Up @@ -23,6 +23,7 @@
// Could have forward declared this but it makes it easier to use from
// inheriting classes if it is included here
#include "MantidAPI/IAlgorithm.h"
#include "MantidAPI/AlgorithmObserver.h"

#include <QDialog>
#include <QString>
Expand Down Expand Up @@ -246,6 +247,8 @@ protected slots:
void setOptionalMessage(const QString & message);
/// Set comma-separated-list of enabled parameter names
void addEnabledAndDisableLists(const QStringList & enabled, const QStringList & disabled);
/// Add an AlgorithmObserver to the algorithm
void addAlgorithmObserver(Mantid::API::AlgorithmObserver *observer);

protected:

Expand Down Expand Up @@ -300,6 +303,9 @@ protected slots:

/// A map to keep track of replace workspace button presses
QHash<QPushButton*, int> m_wsbtn_tracker;

/// A list of AlgorithmObservers to add to the algorithm prior to execution
std::vector<Mantid::API::AlgorithmObserver *> m_observers;
//@}
};

Expand Down
18 changes: 18 additions & 0 deletions Code/Mantid/MantidQt/API/src/AlgorithmDialog.cpp
Expand Up @@ -31,6 +31,7 @@
#include <QCheckBox>
#include <QtGui>

#include <Poco/AbstractObserver.h>
#include <Poco/ActiveResult.h>

using namespace MantidQt::API;
Expand Down Expand Up @@ -761,7 +762,12 @@ void AlgorithmDialog::executeAlgorithmAsync()
{
try
{
// Add AlgorithmObservers to the algorithm
for(auto it = m_observers.begin(); it != m_observers.end(); ++it)
(*it)->observeAll(m_algorithm);

m_algorithm->executeAsync();
m_observers.clear();
}
catch (Poco::NoThreadAvailableException &)
{
Expand Down Expand Up @@ -1042,3 +1048,15 @@ void AlgorithmDialog::setPreviousValue(QWidget* widget, const QString& propName)
QString("Cannot set value for ") + widget->metaObject()->className() +
". Update AlgorithmDialog::setValue() to cope with this widget.");
}

/**
* Observer the execution of the algorithm using an AlgorithmObserver.
*
* All notifications will be observed.
*
* @Param observer Pointer to the AlgorithmObserver to add.
*/
void AlgorithmDialog::addAlgorithmObserver(Mantid::API::AlgorithmObserver *observer)
{
m_observers.push_back(observer);
}

0 comments on commit ab5d65d

Please sign in to comment.