diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py index eac83b7e2b43..92a6ebdad781 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py @@ -12,7 +12,7 @@ def category(self): def PyInit(self): self.declareProperty(WorkspaceProperty('InputWorkspace', '', direction=Direction.Input), - doc='Input workspace') + doc='Input workspace in HWHM') valid_functions = ['ChudleyElliot', 'HallRoss', 'FickDiffusion', 'TeixeiraWater'] self.declareProperty(name='Function', defaultValue=valid_functions[0], @@ -51,9 +51,6 @@ def PyExec(self): spectrum_ws = "__" + self._in_ws ExtractSingleSpectrum(InputWorkspace=self._in_ws, OutputWorkspace=spectrum_ws, WorkspaceIndex=self._width) - # Convert to HWHM - Scale(InputWorkspace=spectrum_ws, Factor=0.5, OutputWorkspace=spectrum_ws) - if self._verbose: logger.notice('Cropping from Q= ' + str(self._q_min) + ' to ' + str(self._q_max)) in_run = mtd[self._in_ws].getRun() @@ -105,7 +102,8 @@ def PyExec(self): # Run fit function if self._out_name is "": - self._out_name = self._in_ws[:-10] + '_' + self._jump_function + 'fit' + ws_suffix_index = self._in_ws.rfind('_') + self._out_name = self._in_ws[:ws_suffix_index] + '_' + self._jump_function + '_fit' Fit(Function=function, InputWorkspace=spectrum_ws, CreateOutput=True, Output=self._out_name, StartX=self._q_min, EndX=self._q_max) @@ -142,6 +140,7 @@ def _setup(self): self._plot = self.getProperty('Plot').value self._save = self.getProperty('Save').value + def _process_output(self, workspace): if self._save: from mantid.simpleapi import SaveNexusProcessed @@ -158,5 +157,6 @@ def _process_output(self, workspace): mtd_plot = import_mantidplot() mtd_plot.plotSpectrum(workspace, [0, 1, 2], True) + # Register algorithm with Mantid AlgorithmFactory.subscribe(JumpFit) diff --git a/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt b/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt index d01e47d1aa4b..9a245f1e4e48 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt +++ b/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt @@ -27,9 +27,10 @@ set ( SRC_FILES src/IndirectNeutron.cpp src/IndirectSimulation.cpp src/IndirectSimulationTab.cpp - src/IndirectSqw.cpp + src/IndirectSqw.cpp src/IndirectSymmetrise.cpp - src/IndirectTransmission.cpp + src/IndirectTab.cpp + src/IndirectTransmission.cpp src/JumpFit.cpp src/MSDFit.cpp src/MantidEV.cpp @@ -106,7 +107,8 @@ set ( INC_FILES inc/MantidQtCustomInterfaces/IndirectSimulationTab.h inc/MantidQtCustomInterfaces/IndirectSqw.h inc/MantidQtCustomInterfaces/IndirectSymmetrise.h - inc/MantidQtCustomInterfaces/IndirectTransmission.h + inc/MantidQtCustomInterfaces/IndirectTransmission.h + inc/MantidQtCustomInterfaces/IndirectTab.h inc/MantidQtCustomInterfaces/IReflPresenter.h inc/MantidQtCustomInterfaces/JumpFit.h inc/MantidQtCustomInterfaces/MSDFit.h @@ -189,6 +191,7 @@ set ( MOC_FILES inc/MantidQtCustomInterfaces/Background.h inc/MantidQtCustomInterfaces/IndirectSqw.h inc/MantidQtCustomInterfaces/IndirectSymmetrise.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/IndirectBayesTab.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectBayesTab.h index 7edd490264de..64417fcb83bd 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectBayesTab.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectBayesTab.h @@ -2,6 +2,7 @@ #define MANTID_CUSTOMINTERFACES_INDIRECTBAYESTAB_H_ #include "MantidAPI/MatrixWorkspace.h" +#include "MantidQtCustomInterfaces/IndirectTab.h" #include "MantidQtMantidWidgets/RangeSelector.h" #include "MantidQtAPI/AlgorithmRunner.h" #include "MantidQtAPI/QwtWorkspaceSpectrumData.h" @@ -72,7 +73,7 @@ namespace MantidQt /// precision for integer properties in bayes tabs static const unsigned int INT_DECIMALS = 0; - class DLLExport IndirectBayesTab : public QWidget + class DLLExport IndirectBayesTab : public IndirectTab { Q_OBJECT @@ -83,10 +84,8 @@ namespace MantidQt /// Returns a URL for the wiki help page for this interface QString tabHelpURL(); - /// Base methods implemented in derived classes + /// Base methods implemented in derived classes virtual QString help() = 0; - virtual bool validate() = 0; - virtual void run() = 0; virtual void loadSettings(const QSettings& settings) = 0; signals: @@ -95,54 +94,24 @@ namespace MantidQt /// Send signal to parent window to show a message box to user void showMessageBox(const QString& message); - protected slots: - /// Slot for when the min range on the range selector changes - virtual void minValueChanged(double min) = 0; - /// Slot for when the min range on the range selector changes - virtual void maxValueChanged(double max) = 0; - /// Slot to handle when a user edits a property + protected slots: + /// Slot to update the guides when the range properties change virtual void updateProperties(QtProperty* prop, double val) = 0; protected: - /// Function to plot a workspace to the miniplot using a workspace name - void plotMiniPlot(const QString& workspace, size_t index); - /// Function to plot a workspace to the miniplot using a workspace pointer - void plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex); - /// Function to set the range selector on the mini plot - void setMiniPlotGuides(QtProperty* lower, QtProperty* upper, const std::pair& bounds); /// Function to run a string as python code void runPythonScript(const QString& pyInput); /// Function to read an instrument's resolution from the IPF using a string - bool getInstrumentResolution(const QString& filename, std::pair& res); + bool getInstrumentResolution(const QString& filename, std::pair& res); /// Function to read an instrument's resolution from the IPF using a workspace pointer bool getInstrumentResolution(Mantid::API::MatrixWorkspace_const_sptr ws, std::pair& res); - /// Function to set the range limits of the plot - void setPlotRange(QtProperty* min, QtProperty* max, const std::pair& bounds); /// Function to set the position of the lower guide on the plot - void updateLowerGuide(QtProperty* lower, QtProperty* upper, double value); + void updateLowerGuide(MantidQt::MantidWidgets::RangeSelector* rs, QtProperty* lower, QtProperty* upper, double value); /// Function to set the position of the upper guide on the plot - void updateUpperGuide(QtProperty* lower, QtProperty* upper, double value); - /// Function to get the range of the curve displayed on the mini plot - std::pair getCurveRange(); - /// Run an algorithm async - void runAlgorithm(const Mantid::API::IAlgorithm_sptr algorithm); - - /// Plot of the input - QwtPlot* m_plot; - /// Curve on the plot - QwtPlotCurve* m_curve; - /// Range selector widget for mini plot - MantidQt::MantidWidgets::RangeSelector* m_rangeSelector; + void updateUpperGuide(MantidQt::MantidWidgets::RangeSelector* rs, QtProperty* lower, QtProperty* upper, double value); + /// Tree of the properties QtTreePropertyBrowser* m_propTree; - /// Internal list of the properties - QMap m_properties; - /// Double manager to create properties - QtDoublePropertyManager* m_dblManager; - /// Double editor facotry for the properties browser - DoubleEditorFactory* m_dblEdFac; - /// Algorithm runner object to execute algorithms on a seperate thread from the gui - MantidQt::API::AlgorithmRunner* m_algRunner; }; } // namespace CustomInterfaces diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h index 46a1691884b6..1d9a5208d410 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 @@ -41,7 +42,9 @@ namespace MantidQt { namespace CustomInterfaces { - /** IndirectDataReductionTab : TODO: DESCRIPTION + /** IndirectDataReductionTab + + This class defines common functionality of tabs used in the Indirect Data Reduction interface. @author Samuel Jackson @date 13/08/2013 @@ -66,7 +69,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 @@ -76,105 +79,24 @@ namespace CustomInterfaces 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=""); /// 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); - std::map getRangesFromInstrument(QString instName = "", QString analyser = "", QString reflection = ""); - /// 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; - - /// If algorithms are currently running on this tab - bool m_tabRunning; - - /// 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; - Ui::IndirectDataReduction m_uiForm; 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); /// Update the Run button on the IDR main window void updateRunButton(bool enabled = true, QString message = "Run", QString tooltip = ""); /// Emitted when the instrument setup is changed void newInstrumentConfiguration(); 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; + bool m_tabRunning; QString getInstrumentParameterFrom(Mantid::Geometry::IComponent_const_sptr comp, std::string param); diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectTab.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectTab.h new file mode 100644 index 000000000000..68ba60cde341 --- /dev/null +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectTab.h @@ -0,0 +1,167 @@ +#ifndef MANTID_CUSTOMINTERFACES_INDIRECTTAB_H_ +#define MANTID_CUSTOMINTERFACES_INDIRECTTAB_H_ + +#include "MantidAPI/AlgorithmManager.h" +#include "MantidAPI/AnalysisDataService.h" +#include "MantidKernel/System.h" +#include "MantidQtAPI/AlgorithmRunner.h" +#include "MantidQtAPI/BatchAlgorithmRunner.h" +#include "MantidQtAPI/PythonRunner.h" +#include "MantidQtAPI/QwtWorkspaceSpectrumData.h" +#include "MantidQtMantidWidgets/RangeSelector.h" + +#include +#include +#include +#include + +#include +#include + +// Suppress a warning coming out of code that isn't ours +#if defined(__INTEL_COMPILER) + #pragma warning disable 1125 +#elif defined(__GNUC__) + #if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 6 ) + #pragma GCC diagnostic push + #endif + #pragma GCC diagnostic ignored "-Woverloaded-virtual" +#endif +#include "DoubleEditorFactory.h" +#if defined(__INTEL_COMPILER) + #pragma warning enable 1125 +#elif defined(__GNUC__) + #if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 6 ) + #pragma GCC diagnostic pop + #endif +#endif + +namespace MantidQt +{ +namespace CustomInterfaces +{ + /** IndirectTab : TODO: DESCRIPTION + + @author Dan Nixon + @date 08/10/2014 + + Copyright © 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + + 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 . + + File change history is stored at: + Code Documentation is available at: + */ + class DLLExport IndirectTab : public QObject + { + Q_OBJECT + + public: + IndirectTab(QObject* parent = 0); + virtual ~IndirectTab(); + + public slots: + void runTab(); + void setupTab(); + bool 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); + + /// 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); + + protected: + /// Overidden by child class. + virtual void setup() = 0; + /// Overidden by child class. + virtual void run() = 0; + /// Overidden by child class. + virtual bool validate() = 0; + + }; +} // namespace CustomInterfaces +} // namespace Mantid + +#endif /* MANTID_CUSTOMINTERFACES_INDIRECTTAB_H_ */ diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/JumpFit.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/JumpFit.h index a42bbe8bd48d..fbde3aabb082 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/JumpFit.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/JumpFit.h @@ -17,8 +17,10 @@ namespace MantidQt // Inherited methods from IndirectBayesTab QString help() { return "JumpFit"; }; + void setup(); bool validate(); void run(); + void runImpl(bool verbose = false, bool plot = false, bool save = false); /// Load default settings into the interface void loadSettings(const QSettings& settings); @@ -27,21 +29,26 @@ namespace MantidQt void handleSampleInputReady(const QString& filename); /// Slot to handle plotting a different spectrum of the workspace void handleWidthChange(const QString& text); - /// Slot for when the min range on the range selector changes - virtual void minValueChanged(double min); - /// Slot for when the min range on the range selector changes - virtual void maxValueChanged(double max); + /// Slot for when the range on the range selector changes + void qRangeChanged(double min, double max); /// Slot to update the guides when the range properties change void updateProperties(QtProperty* prop, double val); /// Find all spectra with width data in the workspace void findAllWidths(Mantid::API::MatrixWorkspace_const_sptr ws); + /// Handles plotting results of algorithm on miniplot + void fitAlgDone(bool error); + /// Handles running preview algorithm + void runPreviewAlgorithm(); private: // The UI form Ui::JumpFit m_uiForm; + // Map of axis labels to spectrum number std::map m_spectraList; + Mantid::API::IAlgorithm_sptr fitAlg; + }; } // namespace CustomInterfaces } // namespace MantidQt diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/JumpFit.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/JumpFit.ui index 7ba4749fa6f7..ae6a514a585d 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/JumpFit.ui +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/JumpFit.ui @@ -24,7 +24,7 @@ - + 0 @@ -110,7 +110,55 @@ - + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Data + + + + + + + color: rgb(255, 0, 0); + + + Fit + + + + + + + color: rgb(0, 255, 0); + + + Diff + + + + + + diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Quasi.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Quasi.h index eefcaad95e9c..f574f325c3d6 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Quasi.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Quasi.h @@ -17,6 +17,7 @@ namespace MantidQt // Inherited methods from IndirectBayesTab QString help() { return "Quasi"; }; + void setup(); bool validate(); void run(); /// Load default settings into the interface @@ -24,9 +25,9 @@ namespace MantidQt private slots: /// Slot for when the min range on the range selector changes - virtual void minValueChanged(double min); + void minValueChanged(double min); /// Slot for when the min range on the range selector changes - virtual void maxValueChanged(double max); + void maxValueChanged(double max); /// Slot to update the guides when the range properties change void updateProperties(QtProperty* prop, double val); /// Slot to handle when a new sample file is available diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ResNorm.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ResNorm.h index d84a5506743a..1ed67276dacf 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ResNorm.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ResNorm.h @@ -17,6 +17,7 @@ namespace MantidQt // Inherited methods from IndirectBayesTab QString help() { return "ResNorm"; }; + void setup(); bool validate(); void run(); /// Load default settings into the interface @@ -26,9 +27,9 @@ namespace MantidQt /// Handle when the vanadium input is ready void handleVanadiumInputReady(const QString& filename); /// Slot for when the min range on the range selector changes - virtual void minValueChanged(double min); + void minValueChanged(double min); /// Slot for when the min range on the range selector changes - virtual void maxValueChanged(double max); + void maxValueChanged(double max); /// Slot to update the guides when the range properties change void updateProperties(QtProperty* prop, double val); diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Stretch.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Stretch.h index 998ce12dc601..b35d2dec4adf 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Stretch.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Stretch.h @@ -17,6 +17,7 @@ namespace MantidQt // Inherited methods from IndirectBayesTab QString help() { return "Stretch"; }; + void setup(); bool validate(); void run(); /// Load default settings into the interface @@ -24,9 +25,9 @@ namespace MantidQt private slots: /// Slot for when the min range on the range selector changes - virtual void minValueChanged(double min); + void minValueChanged(double min); /// Slot for when the min range on the range selector changes - virtual void maxValueChanged(double max); + void maxValueChanged(double max); /// Slot to update the guides when the range properties change void updateProperties(QtProperty* prop, double val); /// Slot to handle when a new sample file is available diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayes.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayes.cpp index 8f791ef1f140..073f0c610255 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayes.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayes.cpp @@ -110,9 +110,9 @@ void IndirectBayes::runClicked() { int tabIndex = m_uiForm.indirectBayesTabs->currentIndex(); - if(m_bayesTabs[tabIndex]->validate()) + if(m_bayesTabs[tabIndex]->validateTab()) { - m_bayesTabs[tabIndex]->run(); + m_bayesTabs[tabIndex]->runTab(); } } diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayesTab.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayesTab.cpp index 5ce3ff31c499..0e3a0cbdfe8f 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayesTab.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayesTab.cpp @@ -4,6 +4,8 @@ #include "MantidQtAPI/UserSubWindow.h" #include "MantidQtCustomInterfaces/IndirectBayesTab.h" +using MantidQt::MantidWidgets::RangeSelector; + namespace MantidQt { namespace CustomInterfaces @@ -12,23 +14,13 @@ namespace MantidQt //---------------------------------------------------------------------------------------------- /** Constructor */ - IndirectBayesTab::IndirectBayesTab(QWidget * parent) : QWidget(parent), - m_plot(new QwtPlot(parent)), m_curve(new QwtPlotCurve()), m_rangeSelector(new MantidWidgets::RangeSelector(m_plot)), - m_propTree(new QtTreePropertyBrowser()), m_properties(), m_dblManager(new QtDoublePropertyManager()), - m_dblEdFac(new DoubleEditorFactory()), - m_algRunner(new MantidQt::API::AlgorithmRunner(parent)) + IndirectBayesTab::IndirectBayesTab(QWidget * parent) : IndirectTab(parent), + m_propTree(new QtTreePropertyBrowser()) { m_propTree->setFactoryForManager(m_dblManager, m_dblEdFac); - m_rangeSelector->setInfoOnly(false); - connect(m_rangeSelector, SIGNAL(minValueChanged(double)), this, SLOT(minValueChanged(double))); - connect(m_rangeSelector, SIGNAL(maxValueChanged(double)), this, SLOT(maxValueChanged(double))); + // Connect double maneger signals connect(m_dblManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(updateProperties(QtProperty*, double))); - - // initilise plot - m_plot->setCanvasBackground(Qt::white); - m_plot->setAxisFont(QwtPlot::xBottom, parent->font()); - m_plot->setAxisFont(QwtPlot::yLeft, parent->font()); } //---------------------------------------------------------------------------------------------- @@ -40,18 +32,18 @@ namespace MantidQt /** * Method to build a URL to the appropriate page on the wiki for this tab. - * + * * @return The URL to the wiki page */ QString IndirectBayesTab::tabHelpURL() - { + { return "http://www.mantidproject.org/IndirectBayes:" + help(); } /** * Emits a signal to run a python script using the method in the parent * UserSubWindow - * + * * @param pyInput :: A string of python code to execute */ void IndirectBayesTab::runPythonScript(const QString& pyInput) @@ -60,74 +52,7 @@ namespace MantidQt } /** - * Runs an algorithm async - * - * @param algorithm :: The algorithm to be run - */ - void IndirectBayesTab::runAlgorithm(const Mantid::API::IAlgorithm_sptr algorithm) - { - algorithm->setRethrows(true); - m_algRunner->startAlgorithm(algorithm); - } - - /** - * 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 - */ - void IndirectBayesTab::plotMiniPlot(const QString& workspace, size_t index) - { - auto ws = Mantid::API::AnalysisDataService::Instance().retrieveWS(workspace.toStdString()); - plotMiniPlot(ws, index); - } - - /** - * 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 - */ - void IndirectBayesTab::plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex) - { - using Mantid::MantidVec; - - //check if we can plot - if( wsIndex >= workspace->getNumberHistograms() || workspace->readX(0).size() < 2 ) - { - return; - } - - QwtWorkspaceSpectrumData wsData(*workspace, static_cast(wsIndex), false); - - if ( m_curve != NULL ) - { - m_curve->attach(0); - delete m_curve; - m_curve = NULL; - } - - size_t nhist = workspace->getNumberHistograms(); - if ( wsIndex >= nhist ) - { - emit showMessageBox("Error: Workspace index out of range."); - } - else - { - m_curve = new QwtPlotCurve(); - m_curve->setData(wsData); - m_curve->attach(m_plot); - - m_plot->replot(); - } - } - - /** - * Checks the workspace's intrument for a resolution parameter to use as + * Checks the workspace's intrument for a resolution parameter to use as * a default for the energy range on the mini plot * * @param workspace :: Name of the workspace to use @@ -140,7 +65,7 @@ namespace MantidQt } /** - * Checks the workspace's intrument for a resolution parameter to use as + * Checks the workspace's intrument for a resolution parameter to use as * a default for the energy range on the mini plot * * @param ws :: Pointer to the workspace to use @@ -167,90 +92,39 @@ namespace MantidQt return false; } - /** - * Gets the range of the curve plotted in the mini plot - * - * @return A pair containing the maximum and minimum points of the curve - */ - std::pair IndirectBayesTab::getCurveRange() - { - size_t npts = m_curve->data().size(); - - if( npts < 2 ) - throw std::invalid_argument("Too few points on data curve to determine range."); - - return std::make_pair(m_curve->data().x(0), m_curve->data().x(npts-1)); - } - - /** - * Sets the edge bounds of plot to prevent the user inputting invalid values - * - * @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 IndirectBayesTab::setPlotRange(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_rangeSelector->setRange(bounds.first, bounds.second); - } - - /** - * Set the position of the guides on the mini plot - * - * @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 IndirectBayesTab::setMiniPlotGuides(QtProperty* lower, QtProperty* upper, const std::pair& bounds) - { - m_dblManager->setValue(lower, bounds.first); - m_dblManager->setValue(upper, bounds.second); - m_rangeSelector->setMinimum(bounds.first); - m_rangeSelector->setMaximum(bounds.second); - } - /** * Set the position of the lower guide on the mini plot - * + * + * @param rs :: Range selector to update * @param lower :: The lower guide property in the property browser * @param upper :: The upper guide property in the property browser * @param value :: The value of the lower guide */ - void IndirectBayesTab::updateLowerGuide(QtProperty* lower, QtProperty* upper, double value) + void IndirectBayesTab::updateLowerGuide(RangeSelector* rs, QtProperty* lower, QtProperty* upper, double value) { // Check if the user is setting the max less than the min if(value > m_dblManager->value(upper)) - { m_dblManager->setValue(lower, m_dblManager->value(upper)); - } else - { - m_rangeSelector->setMinimum(value); - } + rs->setMinimum(value); } /** * Set the position of the upper guide on the mini plot - * + * + * @param rs :: Range selector to update * @param lower :: The lower guide property in the property browser * @param upper :: The upper guide property in the property browser * @param value :: The value of the upper guide */ - void IndirectBayesTab::updateUpperGuide(QtProperty* lower, QtProperty* upper, double value) + void IndirectBayesTab::updateUpperGuide(RangeSelector* rs, QtProperty* lower, QtProperty* upper, double value) { // Check if the user is setting the min greater than the max if(value < m_dblManager->value(lower)) - { m_dblManager->setValue(upper, m_dblManager->value(lower)); - } else - { - m_rangeSelector->setMaximum(value); - } + rs->setMaximum(value); } + } } // namespace MantidQt diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp index c8e14b377739..c079ecba2bdc 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp @@ -18,31 +18,10 @@ namespace CustomInterfaces //---------------------------------------------------------------------------------------------- /** Constructor */ - IndirectDataReductionTab::IndirectDataReductionTab(Ui::IndirectDataReduction& uiForm, QObject* parent) : QObject(parent), - m_plots(), m_curves(), m_rangeSelectors(), - m_tabRunning(false), - m_properties(), - m_dblManager(new QtDoublePropertyManager()), - m_blnManager(new QtBoolPropertyManager()), - m_grpManager(new QtGroupPropertyManager()), - m_dblEdFac(new DoubleEditorFactory()), - m_batchAlgoRunner(NULL), + 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_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(tabExecutionComplete(bool))); - - connect(&m_pythonRunner, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool))); } //---------------------------------------------------------------------------------------------- @@ -66,16 +45,6 @@ namespace CustomInterfaces } } - void IndirectDataReductionTab::setupTab() - { - setup(); - } - - void IndirectDataReductionTab::validateTab() - { - validate(); - } - /** * Slot used to update the run button when an algorithm that was strted by the Run button complete. * @@ -84,7 +53,6 @@ namespace CustomInterfaces void IndirectDataReductionTab::tabExecutionComplete(bool error) { UNUSED_ARG(error); - if(m_tabRunning) { m_tabRunning = false; @@ -92,36 +60,6 @@ namespace CustomInterfaces } } - /** - * 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. * @@ -232,192 +170,6 @@ namespace CustomInterfaces return value; } - /** - * 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 ) - { - g_log.error("Spectrum index out of range for this workspace"); - 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."); - } - } - /** * Gets default peak and background ranges for an instrument in time of flight. * diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectTab.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectTab.cpp new file mode 100644 index 000000000000..037feb9d98df --- /dev/null +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectTab.cpp @@ -0,0 +1,279 @@ +#include "MantidQtCustomInterfaces/IndirectTab.h" + +#include "MantidAPI/AlgorithmManager.h" +#include "MantidKernel/Logger.h" + +using namespace Mantid::API; +using namespace Mantid::Geometry; + +namespace +{ + Mantid::Kernel::Logger g_log("IndirectTab"); +} + +namespace MantidQt +{ +namespace CustomInterfaces +{ + //---------------------------------------------------------------------------------------------- + /** Constructor + */ + IndirectTab::IndirectTab(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()) + { + 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))); + } + + //---------------------------------------------------------------------------------------------- + /** Destructor + */ + IndirectTab::~IndirectTab() + { + } + + void IndirectTab::runTab() + { + if(validate()) + run(); + else + g_log.warning("Failed to validate indirect tab input!"); + } + + void IndirectTab::setupTab() + { + setup(); + } + + bool IndirectTab::validateTab() + { + return 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 IndirectTab::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(); + } + + /** + * 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 IndirectTab::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 IndirectTab::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 IndirectTab::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 IndirectTab::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 IndirectTab::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 IndirectTab::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 IndirectTab::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 IndirectTab::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 IndirectTab::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 IndirectTab::algorithmFinished(bool error) + { + if(error) + { + emit showMessageBox("Error running algorithm. \nSee results log for details."); + } + } + +} // namespace CustomInterfaces +} // namespace Mantid diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/JumpFit.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/JumpFit.cpp index 72a58b75b3a2..5f50250b1995 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/JumpFit.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/JumpFit.cpp @@ -7,23 +7,34 @@ #include #include +using namespace Mantid::API; + namespace MantidQt { namespace CustomInterfaces { - JumpFit::JumpFit(QWidget * parent) : + JumpFit::JumpFit(QWidget * parent) : IndirectBayesTab(parent) { m_uiForm.setupUi(parent); - //add the plot to the ui form - m_uiForm.plotSpace->addWidget(m_plot); - //add the properties browser to the ui form + // Create the plot + m_plots["JumpFitPlot"] = new QwtPlot(m_parentWidget); + m_plots["JumpFitPlot"]->setCanvasBackground(Qt::white); + m_plots["JumpFitPlot"]->setAxisFont(QwtPlot::xBottom, parent->font()); + m_plots["JumpFitPlot"]->setAxisFont(QwtPlot::yLeft, parent->font()); + m_uiForm.plotSpace->addWidget(m_plots["JumpFitPlot"]); + + // Create range selector + m_rangeSelectors["JumpFitQ"] = new MantidWidgets::RangeSelector(m_plots["JumpFitPlot"]); + connect(m_rangeSelectors["JumpFitQ"], SIGNAL(selectionChangedLazy(double, double)), this, SLOT(qRangeChanged(double, double))); + + // Add the properties browser to the ui form m_uiForm.treeSpace->addWidget(m_propTree); m_properties["QMin"] = m_dblManager->addProperty("QMin"); m_properties["QMax"] = m_dblManager->addProperty("QMax"); - + m_dblManager->setDecimals(m_properties["QMin"], NUM_DECIMALS); m_dblManager->setDecimals(m_properties["QMax"], NUM_DECIMALS); @@ -36,11 +47,18 @@ namespace MantidQt connect(m_uiForm.dsSample, SIGNAL(dataReady(const QString&)), this, SLOT(handleSampleInputReady(const QString&))); // Connect width selector to handler method connect(m_uiForm.cbWidth, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(handleWidthChange(const QString&))); + + // Connect algorithm runner to completion handler function + connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(fitAlgDone(bool))); } + void JumpFit::setup() + { + } + /** * Validate the form to check the program can be run - * + * * @return :: Whether the form was valid */ bool JumpFit::validate() @@ -68,9 +86,35 @@ namespace MantidQt * Collect the settings on the GUI and build a python * script that runs JumpFit */ - void JumpFit::run() + void JumpFit::run() { - using namespace Mantid::API; + bool verbose = m_uiForm.chkVerbose->isChecked(); + bool save = m_uiForm.chkSave->isChecked(); + bool plot = m_uiForm.chkPlot->isChecked(); + + runImpl(verbose, plot, save); + } + + /** + * Runs the JumpFit algorithm with preview parameters to update the preview plot. + */ + void JumpFit::runPreviewAlgorithm() + { + runImpl(); + } + + /** + * Runs algorithm. + * + * @param verbose Enable/disable verbose option + * @param plot Enable/disable plotting + * @param save Enable/disable saving + */ + void JumpFit::runImpl(bool verbose, bool plot, bool save) + { + // Do noting with invalid data + if(!m_uiForm.dsSample->isValid()) + return; // Fit function to use QString fitFunction("ChudleyElliot"); @@ -97,7 +141,7 @@ namespace MantidQt std::string widthText = m_uiForm.cbWidth->currentText().toStdString(); long width = m_spectraList[widthText]; - IAlgorithm_sptr fitAlg = AlgorithmManager::Instance().create("JumpFit"); + fitAlg = AlgorithmManager::Instance().create("JumpFit"); fitAlg->initialize(); fitAlg->setProperty("InputWorkspace", ws); @@ -107,20 +151,53 @@ namespace MantidQt fitAlg->setProperty("QMin", m_dblManager->value(m_properties["QMin"])); fitAlg->setProperty("QMax", m_dblManager->value(m_properties["QMax"])); - bool verbose = m_uiForm.chkVerbose->isChecked(); - bool save = m_uiForm.chkSave->isChecked(); - bool plot = m_uiForm.chkPlot->isChecked(); - fitAlg->setProperty("Plot", plot); fitAlg->setProperty("Verbose", verbose); + fitAlg->setProperty("Plot", plot); fitAlg->setProperty("Save", save); - runAlgorithm(fitAlg); - } + if(m_batchAlgoRunner->queueLength() < 1) + runAlgorithm(fitAlg); + } + + /** + * Handles the JumpFit algorithm finishing, used to plot fit in miniplot. + * + * @param error True if the algorithm failed, false otherwise + */ + void JumpFit::fitAlgDone(bool error) + { + // Ignore errors + if(error) + return; + + std::string outWsName = fitAlg->getPropertyValue("Output") + "_Workspace"; + MatrixWorkspace_sptr outputWorkspace = AnalysisDataService::Instance().retrieveWS(outWsName); + TextAxis* axis = dynamic_cast(outputWorkspace->getAxis(1)); + + for(unsigned int histIndex = 0; histIndex < outputWorkspace->getNumberHistograms(); histIndex++) + { + QString specName = QString::fromStdString(axis->label(histIndex)); + + if(specName == "Calc") + { + plotMiniPlot(outputWorkspace, histIndex, "JumpFitPlot", specName); + m_curves[specName]->setPen(QColor(Qt::red)); + } + + if(specName == "Diff") + { + plotMiniPlot(outputWorkspace, histIndex, "JumpFitPlot", specName); + m_curves[specName]->setPen(QColor(Qt::green)); + } + } + + replot("JumpFitPlot"); + } /** * Set the data selectors to use the default save directory * when browsing for input files. - * + * * @param settings :: The current settings */ void JumpFit::loadSettings(const QSettings& settings) @@ -131,47 +208,65 @@ namespace MantidQt /** * Plots the loaded file to the miniplot and sets the guides * and the range - * + * * @param filename :: The name of the workspace to plot */ void JumpFit::handleSampleInputReady(const QString& filename) { + // Disable things that run the preview algorithm + disconnect(m_dblManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(runPreviewAlgorithm())); + disconnect(m_uiForm.cbFunction, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(runPreviewAlgorithm())); + disconnect(m_uiForm.cbWidth, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(runPreviewAlgorithm())); + + // Scale to convert to HWHM + IAlgorithm_sptr scaleAlg = AlgorithmManager::Instance().create("Scale"); + scaleAlg->initialize(); + scaleAlg->setProperty("InputWorkspace", filename.toStdString()); + scaleAlg->setProperty("OutputWorkspace", filename.toStdString()); + scaleAlg->setProperty("Factor", 0.5); + scaleAlg->execute(); + auto ws = Mantid::API::AnalysisDataService::Instance().retrieve(filename.toStdString()); auto mws = boost::dynamic_pointer_cast(ws); findAllWidths(mws); - + if(m_spectraList.size() > 0) { m_uiForm.cbWidth->setEnabled(true); std::string currentWidth = m_uiForm.cbWidth->currentText().toStdString(); - plotMiniPlot(filename, m_spectraList[currentWidth]); + plotMiniPlot(filename, m_spectraList[currentWidth], "JumpFitPlot", "RawPlotCurve"); + std::pair res; - std::pair range = getCurveRange(); + std::pair range = getCurveRange("RawPlotCurve"); - //Use the values from the instrument parameter file if we can + // Use the values from the instrument parameter file if we can if(getInstrumentResolution(filename, res)) - { - setMiniPlotGuides(m_properties["QMin"], m_properties["QMax"], res); - } + setMiniPlotGuides("JumpFitQ", m_properties["QMin"], m_properties["QMax"], res); else - { - setMiniPlotGuides(m_properties["QMin"], m_properties["QMax"], range); - } + setMiniPlotGuides("JumpFitQ", m_properties["QMin"], m_properties["QMax"], range); - setPlotRange(m_properties["QMin"], m_properties["QMax"], range); + setPlotRange("JumpFitQ", m_properties["QMin"], m_properties["QMax"], range); } else { m_uiForm.cbWidth->setEnabled(false); emit showMessageBox("Workspace doesn't appear to contain any width data"); } + + // Update preview plot + runPreviewAlgorithm(); + + // Re-enable things that run the preview algorithm + connect(m_dblManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(runPreviewAlgorithm())); + connect(m_uiForm.cbFunction, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(runPreviewAlgorithm())); + connect(m_uiForm.cbWidth, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(runPreviewAlgorithm())); } /** - * Find all of the spectra in the workspace that have width data - * + * Find all of the spectra in the workspace that have width data + * * @param ws :: The workspace to search */ void JumpFit::findAllWidths(Mantid::API::MatrixWorkspace_const_sptr ws) @@ -184,7 +279,7 @@ namespace MantidQt auto axis = dynamic_cast(ws->getAxis(1)); std::string title = axis->label(i); - //check if the axis labels indicate this spectrum is width data + //check if the axis labels indicate this spectrum is width data size_t qLinesWidthIndex = title.find(".Width"); size_t convFitWidthIndex = title.find(".FWHM"); @@ -196,7 +291,7 @@ namespace MantidQt { std::string cbItemName = ""; size_t substrIndex = 0; - + if (qLinesWidth) { substrIndex = qLinesWidthIndex; @@ -209,7 +304,7 @@ namespace MantidQt cbItemName = title.substr(0, substrIndex); m_spectraList[cbItemName] = static_cast(i); m_uiForm.cbWidth->addItem(QString(cbItemName.c_str())); - + //display widths f1.f1, f2.f1 and f2.f2 if (m_uiForm.cbWidth->count() == 3) { @@ -221,7 +316,7 @@ namespace MantidQt /** * Plots the loaded file to the miniplot when the selected spectrum changes - * + * * @param text :: The name spectrum index to plot */ void JumpFit::handleWidthChange(const QString& text) @@ -233,29 +328,21 @@ namespace MantidQt { if(validate()) { - plotMiniPlot(sampleName, m_spectraList[text.toStdString()]); + plotMiniPlot(sampleName, m_spectraList[text.toStdString()], "JumpFitPlot", "RawPlotCurve"); } } } /** - * Updates the property manager when the lower guide is moved on the mini plot + * Updates the property manager when the range selector is moved on the mini plot. * * @param min :: The new value of the lower guide - */ - void JumpFit::minValueChanged(double min) - { - m_dblManager->setValue(m_properties["QMin"], min); - } - - /** - * Updates the property manager when the upper guide is moved on the mini plot - * * @param max :: The new value of the upper guide */ - void JumpFit::maxValueChanged(double max) + void JumpFit::qRangeChanged(double min, double max) { - m_dblManager->setValue(m_properties["QMax"], max); + m_dblManager->setValue(m_properties["QMin"], min); + m_dblManager->setValue(m_properties["QMax"], max); } /** @@ -268,11 +355,11 @@ namespace MantidQt { if(prop == m_properties["QMin"]) { - updateLowerGuide(m_properties["QMin"], m_properties["QMax"], val); + updateLowerGuide(m_rangeSelectors["JumpFitQ"], m_properties["QMin"], m_properties["QMax"], val); } else if (prop == m_properties["QMax"]) { - updateUpperGuide(m_properties["QMin"], m_properties["QMax"], val); + updateUpperGuide(m_rangeSelectors["JumpFitQ"], m_properties["QMin"], m_properties["QMax"], val); } } } // namespace CustomInterfaces diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Quasi.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Quasi.cpp index f8384fb0cec5..f66a6cd58f53 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/Quasi.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Quasi.cpp @@ -1,3 +1,4 @@ +#include "MantidAPI/TextAxis.h" #include "MantidQtCustomInterfaces/Quasi.h" #include "MantidQtCustomInterfaces/UserInputValidator.h" @@ -10,10 +11,19 @@ namespace MantidQt { m_uiForm.setupUi(parent); - //add the plot to the ui form - m_uiForm.plotSpace->addWidget(m_plot); + // Create the plot + m_plots["QuasiPlot"] = new QwtPlot(m_parentWidget); + m_plots["QuasiPlot"]->setCanvasBackground(Qt::white); + m_plots["QuasiPlot"]->setAxisFont(QwtPlot::xBottom, parent->font()); + m_plots["QuasiPlot"]->setAxisFont(QwtPlot::yLeft, parent->font()); + m_uiForm.plotSpace->addWidget(m_plots["QuasiPlot"]); - //add the properties browser to the ui form + // Create range selector + m_rangeSelectors["QuasiERange"] = new MantidWidgets::RangeSelector(m_plots["QuasiPlot"]); + connect(m_rangeSelectors["QuasiERange"], SIGNAL(minValueChanged(double)), this, SLOT(minValueChanged(double))); + connect(m_rangeSelectors["QuasiERange"], SIGNAL(maxValueChanged(double)), this, SLOT(maxValueChanged(double))); + + // Add the properties browser to the UI form m_uiForm.treeSpace->addWidget(m_propTree); m_properties["EMin"] = m_dblManager->addProperty("EMin"); @@ -61,6 +71,10 @@ namespace MantidQt m_uiForm.mwFixWidthDat->readSettings(settings.group()); } + void Quasi::setup() + { + } + /** * Validate the form to check the program can be run * @@ -101,6 +115,8 @@ namespace MantidQt */ void Quasi::run() { + using namespace Mantid::API; + // Using 1/0 instead of True/False for compatibility with underlying Fortran code // in some places QString verbose("False"); @@ -120,6 +136,9 @@ namespace MantidQt QString sampleName = m_uiForm.dsSample->getCurrentDataName(); QString resName = m_uiForm.dsResolution->getCurrentDataName(); + // Should be either "red", "sqw" or "res" + QString resType = resName.right(3); + QString program = m_uiForm.cbProgram->currentText(); if(program == "Lorentzians") @@ -151,7 +170,7 @@ namespace MantidQt QString fitOps = "[" + elasticPeak + ", '" + background + "', " + fixedWidth + ", " + useResNorm + "]"; - //Collect input from the properties browser + // Collect input from the properties browser QString eMin = m_properties["EMin"]->valueText(); QString eMax = m_properties["EMax"]->valueText(); QString eRange = "[" + eMin + "," + eMax + "]"; @@ -160,7 +179,7 @@ namespace MantidQt QString resBins = m_properties["ResBinning"]->valueText(); QString nBins = "[" + sampleBins + "," + resBins + "]"; - //Output options + // Output options if(m_uiForm.chkVerbose->isChecked()) { verbose = "True"; } if(m_uiForm.chkSave->isChecked()) { save = "True"; } QString plot = m_uiForm.cbPlot->currentText(); @@ -170,6 +189,39 @@ namespace MantidQt " Save="+save+", Plot='"+plot+"', Verbose="+verbose+")\n"; runPythonScript(pyInput); + + // Get the correct workspace name based on the type of resolution file + if(program == "QL") + { + if(resType == "res") + program += "r"; + else + program += "d"; + } + + // Update mini plot + QString outWsName = sampleName.left(sampleName.size() - 3) + program + "_Workspace_0"; + MatrixWorkspace_sptr outputWorkspace = AnalysisDataService::Instance().retrieveWS(outWsName.toStdString()); + TextAxis* axis = dynamic_cast(outputWorkspace->getAxis(1)); + + for(size_t histIndex = 0; histIndex < outputWorkspace->getNumberHistograms(); histIndex++) + { + QString specName = QString::fromStdString(axis->label(histIndex)); + + if(specName.contains("fit")) + { + plotMiniPlot(outputWorkspace, histIndex, "QuasiPlot", specName); + m_curves[specName]->setPen(QColor(Qt::red)); + } + + if(specName.contains("diff")) + { + plotMiniPlot(outputWorkspace, histIndex, "QuasiPlot", specName); + m_curves[specName]->setPen(QColor(Qt::green)); + } + } + + replot("QuasiPlot"); } /** @@ -180,10 +232,10 @@ namespace MantidQt */ void Quasi::handleSampleInputReady(const QString& filename) { - plotMiniPlot(filename, 0); - std::pair range = getCurveRange(); - setMiniPlotGuides(m_properties["EMin"], m_properties["EMax"], range); - setPlotRange(m_properties["EMin"], m_properties["EMax"], range); + plotMiniPlot(filename, 0, "QuasiPlot", "RawPlotCurve"); + std::pair range = getCurveRange("RawPlotCurve"); + setMiniPlotGuides("QuasiERange", m_properties["EMin"], m_properties["EMax"], range); + setPlotRange("QuasiERange", m_properties["EMin"], m_properties["EMax"], range); } /** @@ -216,11 +268,11 @@ namespace MantidQt { if(prop == m_properties["EMin"]) { - updateLowerGuide(m_properties["EMin"], m_properties["EMax"], val); + updateLowerGuide(m_rangeSelectors["QuasiERange"], m_properties["EMin"], m_properties["EMax"], val); } else if (prop == m_properties["EMax"]) { - updateUpperGuide(m_properties["EMin"], m_properties["EMax"], val); + updateUpperGuide(m_rangeSelectors["QuasiERange"], m_properties["EMin"], m_properties["EMax"], val); } } diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/ResNorm.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/ResNorm.cpp index 5ab1d38bd4f2..7665cb062e51 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/ResNorm.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/ResNorm.cpp @@ -10,10 +10,21 @@ namespace MantidQt { m_uiForm.setupUi(parent); - //add the plot to the ui form - m_uiForm.plotSpace->addWidget(m_plot); - //add the properties browser to the ui form + // Create the plot + m_plots["ResNormPlot"] = new QwtPlot(m_parentWidget); + m_plots["ResNormPlot"]->setCanvasBackground(Qt::white); + m_plots["ResNormPlot"]->setAxisFont(QwtPlot::xBottom, parent->font()); + m_plots["ResNormPlot"]->setAxisFont(QwtPlot::yLeft, parent->font()); + m_uiForm.plotSpace->addWidget(m_plots["ResNormPlot"]); + + // Create range selector + m_rangeSelectors["ResNormERange"] = new MantidWidgets::RangeSelector(m_plots["ResNormPlot"]); + connect(m_rangeSelectors["ResNormERange"], SIGNAL(minValueChanged(double)), this, SLOT(minValueChanged(double))); + connect(m_rangeSelectors["ResNormERange"], SIGNAL(maxValueChanged(double)), this, SLOT(maxValueChanged(double))); + + // Add the properties browser to the ui form m_uiForm.treeSpace->addWidget(m_propTree); + m_properties["EMin"] = m_dblManager->addProperty("EMin"); m_properties["EMax"] = m_dblManager->addProperty("EMax"); m_properties["VanBinning"] = m_dblManager->addProperty("Van Binning"); @@ -34,6 +45,10 @@ namespace MantidQt connect(m_uiForm.dsVanadium, SIGNAL(dataReady(const QString&)), this, SLOT(handleVanadiumInputReady(const QString&))); } + void ResNorm::setup() + { + } + /** * Validate the form to check the program can be run * @@ -110,9 +125,9 @@ namespace MantidQt */ void ResNorm::handleVanadiumInputReady(const QString& filename) { - plotMiniPlot(filename, 0); + plotMiniPlot(filename, 0, "ResNormPlot", "RawPlotCurve"); std::pair res; - std::pair range = getCurveRange(); + std::pair range = getCurveRange("RawPlotCurve"); //Use the values from the instrument parameter file if we can if(getInstrumentResolution(filename, res)) @@ -121,14 +136,14 @@ namespace MantidQt res.first = res.first * 10; res.second = res.second * 10; - setMiniPlotGuides(m_properties["EMin"], m_properties["EMax"], res); + setMiniPlotGuides("ResNormERange", m_properties["EMin"], m_properties["EMax"], res); } else { - setMiniPlotGuides(m_properties["EMin"], m_properties["EMax"], range); + setMiniPlotGuides("ResNormERange", m_properties["EMin"], m_properties["EMax"], range); } - setPlotRange(m_properties["EMin"], m_properties["EMax"], range); + setPlotRange("ResNormERange", m_properties["EMin"], m_properties["EMax"], range); } /** @@ -161,11 +176,11 @@ namespace MantidQt { if(prop == m_properties["EMin"]) { - updateLowerGuide(m_properties["EMin"], m_properties["EMax"], val); + updateLowerGuide(m_rangeSelectors["ResNormERange"], m_properties["EMin"], m_properties["EMax"], val); } else if (prop == m_properties["EMax"]) { - updateUpperGuide(m_properties["EMin"], m_properties["EMax"], val); + updateUpperGuide(m_rangeSelectors["ResNormERange"], m_properties["EMin"], m_properties["EMax"], val); } } } // namespace CustomInterfaces diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Stretch.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Stretch.cpp index e75822650e92..83f8217d2830 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/Stretch.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Stretch.cpp @@ -1,6 +1,11 @@ #include "MantidQtCustomInterfaces/Stretch.h" #include "MantidQtCustomInterfaces/UserInputValidator.h" +namespace +{ + Mantid::Kernel::Logger g_log("Stretch"); +} + namespace MantidQt { namespace CustomInterfaces @@ -10,9 +15,19 @@ namespace MantidQt { m_uiForm.setupUi(parent); - //add the plot to the ui form - m_uiForm.plotSpace->addWidget(m_plot); - //add the properties browser to the ui form + // Create the plot + m_plots["StretchPlot"] = new QwtPlot(m_parentWidget); + m_plots["StretchPlot"]->setCanvasBackground(Qt::white); + m_plots["StretchPlot"]->setAxisFont(QwtPlot::xBottom, parent->font()); + m_plots["StretchPlot"]->setAxisFont(QwtPlot::yLeft, parent->font()); + m_uiForm.plotSpace->addWidget(m_plots["StretchPlot"]); + + // Create range selector + m_rangeSelectors["StretchERange"] = new MantidWidgets::RangeSelector(m_plots["StretchPlot"]); + connect(m_rangeSelectors["StretchERange"], SIGNAL(minValueChanged(double)), this, SLOT(minValueChanged(double))); + connect(m_rangeSelectors["StretchERange"], SIGNAL(maxValueChanged(double)), this, SLOT(maxValueChanged(double))); + + // Add the properties browser to the ui form m_uiForm.treeSpace->addWidget(m_propTree); m_properties["EMin"] = m_dblManager->addProperty("EMin"); @@ -48,6 +63,10 @@ namespace MantidQt connect(m_uiForm.chkSequentialFit, SIGNAL(toggled(bool)), m_uiForm.cbPlot, SLOT(setEnabled(bool))); } + void Stretch::setup() + { + } + /** * Validate the form to check the program can be run * @@ -75,6 +94,8 @@ namespace MantidQt */ void Stretch::run() { + using namespace Mantid::API; + QString save("False"); QString verbose("False"); @@ -138,10 +159,10 @@ namespace MantidQt */ void Stretch::handleSampleInputReady(const QString& filename) { - plotMiniPlot(filename, 0); - std::pair range = getCurveRange(); - setMiniPlotGuides(m_properties["EMin"], m_properties["EMax"], range); - setPlotRange(m_properties["EMin"], m_properties["EMax"], range); + plotMiniPlot(filename, 0, "StretchPlot", "RawPlotCurve"); + std::pair range = getCurveRange("RawPlotCurve"); + setMiniPlotGuides("StretchERange", m_properties["EMin"], m_properties["EMax"], range); + setPlotRange("StretchERange", m_properties["EMin"], m_properties["EMax"], range); } /** @@ -174,11 +195,11 @@ namespace MantidQt { if(prop == m_properties["EMin"]) { - updateLowerGuide(m_properties["EMin"], m_properties["EMax"], val); + updateLowerGuide(m_rangeSelectors["StretchERange"], m_properties["EMin"], m_properties["EMax"], val); } else if (prop == m_properties["EMax"]) { - updateUpperGuide(m_properties["EMin"], m_properties["EMax"], val); + updateUpperGuide(m_rangeSelectors["StretchERange"], m_properties["EMin"], m_properties["EMax"], val); } }