From 25307c9b04428041155ed27029ddb8d715dd3d1f Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Wed, 11 Feb 2015 10:34:58 +0000 Subject: [PATCH] Implement Regex based fix for MWRunFiles Refs #11048 --- .../inc/MantidQtMantidWidgets/MWRunFiles.h | 3 +- .../MantidQt/MantidWidgets/src/MWRunFiles.cpp | 40 ++++++++++++++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MWRunFiles.h b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MWRunFiles.h index f5d5b103efa5..ce42e952f78d 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MWRunFiles.h +++ b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MWRunFiles.h @@ -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 & defaultInstrumentName = "", const QString & algorithmProperty = ""); + void set(QString text, bool isForRunFiles, bool isOptional, const QString & algorithmProperty = ""); /// Returns the error string. Empty if no error was caught. std::string error() const { return m_error; } @@ -60,7 +60,6 @@ namespace MantidQt QString m_property; bool m_isForRunFiles; bool m_isOptional; - QString m_defaultInstrumentName; }; /** diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp index 3be6b72c96bb..1410da0b8e49 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp +++ b/Code/Mantid/MantidQt/MantidWidgets/src/MWRunFiles.cpp @@ -20,6 +20,7 @@ #include #include +#include using namespace Mantid::Kernel; using namespace Mantid::API; @@ -36,7 +37,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_defaultInstrumentName() + m_algorithm(), m_property(), m_isForRunFiles(), m_isOptional() { } @@ -48,12 +49,11 @@ 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 & defaultInstrumentName, const QString & algorithmProperty) +void FindFilesThread::set(QString text, bool isForRunFiles, bool isOptional, const QString & algorithmProperty) { m_text = text.trimmed().toStdString(); m_isForRunFiles = isForRunFiles; m_isOptional = isOptional; - m_defaultInstrumentName = defaultInstrumentName; QStringList elements = algorithmProperty.split("|"); @@ -103,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_defaultInstrumentName.toStdString()); + m_filenames = fileSearcher.findRuns(m_text); m_valueForProperty = ""; for(auto cit = m_filenames.begin(); cit != m_filenames.end(); ++cit) { @@ -768,8 +768,38 @@ 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_defaultInstrumentName, m_algorithmProperty); + QString searchText = m_uiForm.fileEditor->text(); + + // If we have an override instrument then add it in appropriate places to the search text + if (!m_defaultInstrumentName.isEmpty()) + { + // Regex to match a selection of run numbers as defined here: mantidproject.org/MultiFileLoading + // Also allowing spaces between delimiters as this seems to work fine + boost::regex runNumbers("([0-9]+)([:+-] ?[0-9]+)? ?(:[0-9]+)?", boost::regex::extended); + // Regex to match a list of run numbers delimited by commas + boost::regex runNumberList("([0-9]+)(, ?[0-9]+)*", boost::regex::extended); + + // See if we can just prepend the instrument and be done + if (boost::regex_match(searchText.toStdString(), runNumbers)) + { + searchText = m_defaultInstrumentName + searchText; + } + // If it is a list we need to prepend the instrument to all run numbers + else if (boost::regex_match(searchText.toStdString(), runNumberList)) + { + QStringList runNumbers = searchText.split(",", QString::SkipEmptyParts); + QStringList newRunNumbers; + + for(auto it = runNumbers.begin(); it != runNumbers.end(); ++it) + newRunNumbers << m_defaultInstrumentName + (*it).simplified(); + + searchText = newRunNumbers.join(","); + } + } + + m_thread->set(searchText, isForRunFiles(), this->isOptional(), m_algorithmProperty); m_thread->start(); } else