diff --git a/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt b/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt index 40265b835a28..e1615af4d6e2 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt +++ b/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt @@ -28,6 +28,7 @@ set ( SRC_FILES src/IndirectSimulation.cpp src/IndirectSimulationTab.cpp src/IndirectSqw.cpp + src/IndirectTab.cpp src/IndirectTransmission.cpp src/JumpFit.cpp src/MSDFit.cpp @@ -108,6 +109,7 @@ set ( INC_FILES inc/MantidQtCustomInterfaces/IndirectSimulationTab.h inc/MantidQtCustomInterfaces/IndirectSqw.h inc/MantidQtCustomInterfaces/IndirectTransmission.h + inc/MantidQtCustomInterfaces/IndirectTab.h inc/MantidQtCustomInterfaces/IReflPresenter.h inc/MantidQtCustomInterfaces/JumpFit.h inc/MantidQtCustomInterfaces/MSDFit.h @@ -191,6 +193,7 @@ set ( MOC_FILES inc/MantidQtCustomInterfaces/Background.h inc/MantidQtCustomInterfaces/IndirectSimulationTab.h inc/MantidQtCustomInterfaces/IndirectSqw.h inc/MantidQtCustomInterfaces/IndirectTransmission.h + inc/MantidQtCustomInterfaces/IndirectTab.h inc/MantidQtCustomInterfaces/JumpFit.h inc/MantidQtCustomInterfaces/MSDFit.h inc/MantidQtCustomInterfaces/Muon/ALCBaselineModellingPresenter.h diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h index e5bed025214c..80533e1201db 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h @@ -9,6 +9,7 @@ #include "MantidQtAPI/PythonRunner.h" #include "MantidQtAPI/QwtWorkspaceSpectrumData.h" #include "MantidQtCustomInterfaces/IndirectDataReduction.h" +#include "MantidQtCustomInterfaces/IndirectTab.h" #include "MantidQtMantidWidgets/RangeSelector.h" #include @@ -66,7 +67,7 @@ namespace CustomInterfaces File change history is stored at: Code Documentation is available at: */ - class DLLExport IndirectDataReductionTab : public QObject + class DLLExport IndirectDataReductionTab : public IndirectTab { Q_OBJECT @@ -74,99 +75,13 @@ namespace CustomInterfaces IndirectDataReductionTab(Ui::IndirectDataReduction& uiForm, QObject * parent = 0); virtual ~IndirectDataReductionTab(); - public slots: - void runTab(); - void setupTab(); - void validateTab(); - - protected slots: - /// Slot to handle when an algorithm finishes running - virtual void algorithmFinished(bool error); - protected: - /// Run the load algorithm with the given file name, output name and spectrum range - bool loadFile(const QString& filename, const QString& outputName, const int specMin = -1, const int specMax = -1); - Mantid::API::MatrixWorkspace_sptr loadInstrumentIfNotExist(std::string instrumentName, std::string analyser="", std::string reflection=""); /// Get information about the operation modes of an indirect instrument std::vector > > getInstrumentModes(std::string instrumentName); /// Function to get details about the instrument configuration defined on C2E tab std::map getInstrumentDetails(); - /// Function to plot a workspace to the miniplot using a workspace name - void plotMiniPlot(const QString& workspace, size_t index, const QString& plotID, const QString& curveID = ""); - /// Function to plot a workspace to the miniplot using a workspace pointer - void plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex, const QString& plotID, const QString& curveID = ""); - /// Function to replot a miniplot - void replot(const QString& plotID); - - /// Function to get the range of the curve displayed on the mini plot - std::pair getCurveRange(const QString& plotID); - /// Function to set the range of an axis on a plot - void setAxisRange(const QString& plotID, QwtPlot::Axis axis, std::pair range); - /// Function to autoscale a given axis based on the data in a curve - void setXAxisToCurve(const QString& plotID, const QString& curveID); - - /// Function to set the range limits of the plot - void setPlotRange(const QString& rsID, QtProperty* min, QtProperty* max, const std::pair& bounds); - /// Function to set the range selector on the mini plot - void setMiniPlotGuides(const QString& rsID, QtProperty* lower, QtProperty* upper, const std::pair& bounds); - - /// Function to run an algorithm on a seperate thread - void runAlgorithm(const Mantid::API::IAlgorithm_sptr algorithm); - - /// Parent QWidget (if applicable) - QWidget *m_parentWidget; - - /// Plot of the input - std::map m_plots; - /// Curve on the plot - std::map m_curves; - /// Range selector widget for mini plot - std::map m_rangeSelectors; - /// Tree of the properties - std::map m_propTrees; - - /// Internal list of the properties - QMap m_properties; - - /// Double manager to create properties - QtDoublePropertyManager* m_dblManager; - /// Boolean manager to create properties - QtBoolPropertyManager* m_blnManager; - /// Group manager to create properties - QtGroupPropertyManager* m_grpManager; - - /// Double editor facotry for the properties browser - DoubleEditorFactory* m_dblEdFac; - - /// Algorithm runner object to execute chains algorithms on a seperate thread from the GUI - MantidQt::API::BatchAlgorithmRunner *m_batchAlgoRunner; - - /// Use a Python runner for when we need the output of a script - MantidQt::API::PythonRunner m_pythonRunner; - - /// Validator for int inputs - QIntValidator *m_valInt; - /// Validator for double inputs - QDoubleValidator *m_valDbl; - /// Validator for positive double inputs - QDoubleValidator *m_valPosDbl; - - signals: - /// Send signal to parent window to show a message box to user - void showMessageBox(const QString& message); - /// Run a python script - void runAsPythonScript(const QString & code, bool no_output); - - private: - /// Overidden by child class. - virtual void setup() = 0; - /// Overidden by child class. - virtual void run() = 0; - /// Overidden by child class. - virtual bool validate() = 0; - protected: Ui::IndirectDataReduction m_uiForm; diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp index 437dd8812226..d496b7ccaed7 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp @@ -18,25 +18,9 @@ namespace CustomInterfaces //---------------------------------------------------------------------------------------------- /** Constructor */ - IndirectDataReductionTab::IndirectDataReductionTab(Ui::IndirectDataReduction& uiForm, QObject* parent) : QObject(parent), - m_plots(), m_curves(), m_rangeSelectors(), - m_properties(), - m_dblManager(new QtDoublePropertyManager()), m_blnManager(new QtBoolPropertyManager()), m_grpManager(new QtGroupPropertyManager()), - m_dblEdFac(new DoubleEditorFactory()), + IndirectDataReductionTab::IndirectDataReductionTab(Ui::IndirectDataReduction& uiForm, QObject* parent) : IndirectTab(parent), m_uiForm(uiForm) { - m_parentWidget = dynamic_cast(parent); - - m_batchAlgoRunner = new MantidQt::API::BatchAlgorithmRunner(m_parentWidget); - m_valInt = new QIntValidator(m_parentWidget); - m_valDbl = new QDoubleValidator(m_parentWidget); - m_valPosDbl = new QDoubleValidator(m_parentWidget); - - const double tolerance = 0.00001; - m_valPosDbl->setBottom(tolerance); - - connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(algorithmFinished(bool))); - connect(&m_pythonRunner, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool))); } //---------------------------------------------------------------------------------------------- @@ -46,54 +30,6 @@ namespace CustomInterfaces { } - void IndirectDataReductionTab::runTab() - { - if(validate()) - run(); - else - g_log.warning("Failed to validate indirect tab input!"); - } - - void IndirectDataReductionTab::setupTab() - { - setup(); - } - - void IndirectDataReductionTab::validateTab() - { - validate(); - } - - /** - * Run the load algorithm with the supplied filename and spectrum range - * - * @param filename :: The name of the file to load - * @param outputName :: The name of the output workspace - * @param specMin :: Lower spectra bound - * @param specMax :: Upper spectra bound - * @return If the algorithm was successful - */ - bool IndirectDataReductionTab::loadFile(const QString& filename, const QString& outputName, - const int specMin, const int specMax) - { - Algorithm_sptr load = AlgorithmManager::Instance().createUnmanaged("Load", -1); - load->initialize(); - - load->setProperty("Filename", filename.toStdString()); - load->setProperty("OutputWorkspace", outputName.toStdString()); - - if(specMin != -1) - load->setProperty("SpectrumMin", specMin); - - if(specMax != -1) - load->setProperty("SpectrumMax", specMax); - - load->execute(); - - //If reloading fails we're out of options - return load->isExecuted(); - } - /** * Loads an empty instrument into a workspace (__empty_INST) unless the workspace already exists. * @@ -230,187 +166,5 @@ namespace CustomInterfaces return instDetails; } - /** - * Gets the range of the curve plotted in the mini plot - * - * @param curveID :: The string index of the curve in the m_curves map - * @return A pair containing the maximum and minimum points of the curve - */ - std::pair IndirectDataReductionTab::getCurveRange(const QString& curveID) - { - size_t npts = m_curves[curveID]->data().size(); - - if( npts < 2 ) - throw std::invalid_argument("Too few points on data curve to determine range."); - - return std::make_pair(m_curves[curveID]->data().x(0), m_curves[curveID]->data().x(npts-1)); - } - - /** - * Set the range of an axis on a miniplot - * - * @param plotID :: Index of plot in m_plots map - * @param axis :: ID of axis to set range of - * @param range :: Pair of double values specifying range - */ - void IndirectDataReductionTab::setAxisRange(const QString& plotID, QwtPlot::Axis axis, - std::pair range) - { - m_plots[plotID]->setAxisScale(axis, range.first, range.second); - } - - /** - * Sets the X axis of a plot to match the range of x values on a curve - * - * @param plotID :: Index of plot in m_plots map - * @param curveID :: Index of curve in m_curves map - */ - void IndirectDataReductionTab::setXAxisToCurve(const QString& plotID, const QString& curveID) - { - auto range = getCurveRange(curveID); - setAxisRange(plotID, QwtPlot::xBottom, range); - } - - /** - * Plot a workspace to the miniplot given a workspace name and - * a specturm index. - * - * This method uses the analysis data service to retrieve the workspace. - * - * @param workspace :: The name of the workspace - * @param index :: The spectrum index of the workspace - * @param plotID :: String index of the plot in the m_plots map - * @param curveID :: String index of the curve in the m_curves map, defaults to plot ID - */ - void IndirectDataReductionTab::plotMiniPlot(const QString& workspace, size_t index, - const QString& plotID, const QString& curveID) - { - auto ws = AnalysisDataService::Instance().retrieveWS(workspace.toStdString()); - plotMiniPlot(ws, index, plotID, curveID); - } - - /** - * Replot a given mini plot - * - * @param plotID :: ID of plot in m_plots map - */ - void IndirectDataReductionTab::replot(const QString& plotID) - { - m_plots[plotID]->replot(); - } - - /** - * Plot a workspace to the miniplot given a workspace pointer and - * a specturm index. - * - * @param workspace :: Pointer to the workspace - * @param wsIndex :: The spectrum index of the workspace - * @param plotID :: String index of the plot in the m_plots map - * @param curveID :: String index of the curve in the m_curves map, defaults to plot ID - */ - void IndirectDataReductionTab::plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex, - const QString& plotID, const QString& curveID) - { - using Mantid::MantidVec; - - QString cID = curveID; - if(cID == "") - cID = plotID; - - //check if we can plot - if( wsIndex >= workspace->getNumberHistograms() || workspace->readX(0).size() < 2 ) - return; - - QwtWorkspaceSpectrumData wsData(*workspace, static_cast(wsIndex), false); - - if ( m_curves[cID] != NULL ) - { - m_curves[cID]->attach(0); - delete m_curves[cID]; - m_curves[cID] = NULL; - } - - size_t nhist = workspace->getNumberHistograms(); - if ( wsIndex >= nhist ) - { - emit showMessageBox("Error: Workspace index out of range."); - } - else - { - m_curves[cID] = new QwtPlotCurve(); - m_curves[cID]->setData(wsData); - m_curves[cID]->attach(m_plots[plotID]); - - m_plots[plotID]->replot(); - } - } - - /** - * Sets the edge bounds of plot to prevent the user inputting invalid values - * Also sets limits for range selector movement - * - * @param rsID :: The string index of the range selector in the map m_rangeSelectors - * @param min :: The lower bound property in the property browser - * @param max :: The upper bound property in the property browser - * @param bounds :: The upper and lower bounds to be set - */ - void IndirectDataReductionTab::setPlotRange(const QString& rsID, QtProperty* min, QtProperty* max, - const std::pair& bounds) - { - m_dblManager->setMinimum(min, bounds.first); - m_dblManager->setMaximum(min, bounds.second); - m_dblManager->setMinimum(max, bounds.first); - m_dblManager->setMaximum(max, bounds.second); - m_rangeSelectors[rsID]->setRange(bounds.first, bounds.second); - } - - /** - * Set the position of the guides on the mini plot - * - * @param rsID :: The string index of the range selector in the map m_rangeSelectors - * @param lower :: The lower bound property in the property browser - * @param upper :: The upper bound property in the property browser - * @param bounds :: The upper and lower bounds to be set - */ - void IndirectDataReductionTab::setMiniPlotGuides(const QString& rsID, QtProperty* lower, QtProperty* upper, - const std::pair& bounds) - { - m_dblManager->setValue(lower, bounds.first); - m_dblManager->setValue(upper, bounds.second); - m_rangeSelectors[rsID]->setMinimum(bounds.first); - m_rangeSelectors[rsID]->setMaximum(bounds.second); - } - - /** - * Runs an algorithm async - * - * @param algorithm :: The algorithm to be run - */ - void IndirectDataReductionTab::runAlgorithm(const Mantid::API::IAlgorithm_sptr algorithm) - { - algorithm->setRethrows(true); - - // There should never really be unexecuted algorithms in the queue, but it is worth warning in case of possible weirdness - size_t batchQueueLength = m_batchAlgoRunner->queueLength(); - if(batchQueueLength > 0) - g_log.warning() << "Batch queue already contains " << batchQueueLength << " algorithms!" << std::endl; - - m_batchAlgoRunner->addAlgorithm(algorithm); - m_batchAlgoRunner->executeBatchAsync(); - } - - /** - * Handles getting the results of an algorithm running async - * - * @param error :: True if execution failed, false otherwise - */ - void IndirectDataReductionTab::algorithmFinished(bool error) - { - if(error) - { - emit showMessageBox("Error running algorithm. \nSee results log for details."); - } - } - } // namespace CustomInterfaces } // namespace Mantid