Skip to content

Commit

Permalink
Add option to MWRunFiles to lock to inst
Browse files Browse the repository at this point in the history
Refs #11048
  • Loading branch information
DanNixon committed Feb 10, 2015
1 parent d76e7df commit c07e909
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
Expand Up @@ -29,7 +29,7 @@ namespace MantidQt
/// Constructor.
FindFilesThread(QObject *parent = NULL);
/// Set the various file-finding values / options.
void set(QString text, bool isForRunFiles, bool isOptional, const QString & algorithmProperty = "");
void set(QString text, bool isForRunFiles, bool isOptional, const QString & defaultInstrumentName = "", const QString & algorithmProperty = "");

/// Returns the error string. Empty if no error was caught.
std::string error() const { return m_error; }
Expand Down Expand Up @@ -60,6 +60,7 @@ namespace MantidQt
QString m_property;
bool m_isForRunFiles;
bool m_isOptional;
QString m_defaultInstrumentName;
};

/**
Expand Down Expand Up @@ -104,9 +105,12 @@ namespace MantidQt
Q_PROPERTY(QStringList fileExtensions READ getFileExtensions WRITE setFileExtensions)
Q_PROPERTY(bool extsAsSingleOption READ extsAsSingleOption WRITE extsAsSingleOption)
Q_PROPERTY(LiveButtonOpts liveButton READ liveButtonState WRITE liveButtonState)
Q_PROPERTY(QString instrumentOverride READ getInstrumentOverride WRITE setInstrumentOverride)
Q_ENUMS(ButtonOpts)
Q_ENUMS(LiveButtonOpts)

friend class DataSelector;

public:
/// options for bringing up the load file dialog
enum ButtonOpts
Expand Down Expand Up @@ -189,6 +193,10 @@ namespace MantidQt
void setNumberOfEntries(int number);
/// Inform the widget of a running instance of MonitorLiveData to be used in stopLiveListener()
void setLiveAlgorithm(const boost::shared_ptr<Mantid::API::IAlgorithm>& monitorLiveData);
/// Gets the instrument currently fixed to
QString getInstrumentOverride();
/// Overrides the value of default instrument
void setInstrumentOverride(const QString & instName);

signals:
/// Emitted when the file text changes
Expand Down Expand Up @@ -281,6 +289,8 @@ namespace MantidQt
QString m_fileFilter;
/// Thread to allow asynchronous finding of files.
FindFilesThread * m_thread;

QString m_defaultInstrumentName;
};
}
}
Expand Down
36 changes: 32 additions & 4 deletions Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp
Expand Up @@ -36,7 +36,7 @@ using namespace MantidQt::MantidWidgets;
*/
FindFilesThread::FindFilesThread(QObject *parent) :
QThread(parent), m_error(), m_filenames(), m_valueForProperty(), m_text(),
m_algorithm(), m_property(), m_isForRunFiles(), m_isOptional()
m_algorithm(), m_property(), m_isForRunFiles(), m_isOptional(), m_defaultInstrumentName()
{
}

Expand All @@ -48,11 +48,12 @@ FindFilesThread::FindFilesThread(QObject *parent) :
* @param isOptional :: whether or not the files are optional.
* @param algorithmProperty :: the algorithm and property to use as an alternative to FileFinder. Optional.
*/
void FindFilesThread::set(QString text, bool isForRunFiles, bool isOptional, const QString & algorithmProperty)
void FindFilesThread::set(QString text, bool isForRunFiles, bool isOptional, const QString & defaultInstrumentName, const QString & algorithmProperty)
{
m_text = text.trimmed().toStdString();
m_isForRunFiles = isForRunFiles;
m_isOptional = isOptional;
m_defaultInstrumentName = defaultInstrumentName;

QStringList elements = algorithmProperty.split("|");

Expand Down Expand Up @@ -102,7 +103,7 @@ void FindFilesThread::run()
// Else if we are loading run files, then use findRuns.
else if( m_isForRunFiles )
{
m_filenames = fileSearcher.findRuns(m_text);
m_filenames = fileSearcher.findRuns(m_text, m_defaultInstrumentName.toStdString());
m_valueForProperty = "";
for(auto cit = m_filenames.begin(); cit != m_filenames.end(); ++cit)
{
Expand Down Expand Up @@ -700,6 +701,33 @@ void MWRunFiles::setLiveAlgorithm(const IAlgorithm_sptr& monitorLiveData)
m_monitorLiveData = monitorLiveData;
}

/**
* Gets the instrument currently set by the override property.
*
* If no override is set then the instrument set by default instrument configurtion
* option will be used and this function returns an empty string.
*
* @return Name of instrument, empty if not set
*/
QString MWRunFiles::getInstrumentOverride()
{
return m_defaultInstrumentName;
}

/**
* Sets an instrument to fix the widget to.
*
* If an instrument name is geven then the widget will only look for files for that
* instrument, providing na empty string will remove this restriction and will search
* using the default instrument.
*
* @param instName Name of instrument, empty to disable override
*/
void MWRunFiles::setInstrumentOverride(const QString & instName)
{
m_defaultInstrumentName = instName;
}

/**
* Set the file text. This is different to setText in that it emits findFiles, as well
* changing the state of the text box widget to "modified = true" which is a prerequisite
Expand Down Expand Up @@ -741,7 +769,7 @@ void MWRunFiles::findFiles()

emit findingFiles();
// Set the values for the thread, and start it running.
m_thread->set(m_uiForm.fileEditor->text(), isForRunFiles(), this->isOptional(), m_algorithmProperty);
m_thread->set(m_uiForm.fileEditor->text(), isForRunFiles(), this->isOptional(), m_defaultInstrumentName, m_algorithmProperty);
m_thread->start();
}
else
Expand Down

0 comments on commit c07e909

Please sign in to comment.