diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ConvFit.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ConvFit.h index 96fbdb315a13774da530e60db0b15e89f79a749d..dbdd88c2c61cf6b43028b087c5d221a80c83a336 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ConvFit.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ConvFit.h @@ -45,6 +45,9 @@ private slots: void singleFitComplete(bool error); void fitFunctionSelected(const QString &); void algorithmComplete(bool error); + void saveClicked(); + void plotClicked(); + void plotCurrentPreview(); private: boost::shared_ptr<Mantid::API::CompositeFunction> @@ -63,11 +66,13 @@ private: void updatePlotOptions(); QString convertFuncToShort(const QString &); QString convertBackToShort(const std::string &original); + Ui::ConvFit m_uiForm; QtStringPropertyManager *m_stringManager; QtTreePropertyBrowser *m_cfTree; QMap<QtProperty *, QtProperty *> m_fixedProps; Mantid::API::MatrixWorkspace_sptr m_cfInputWS; + Mantid::API::MatrixWorkspace_sptr m_previewPlotData; QString m_cfInputWSName; bool m_confitResFileType; Mantid::API::IAlgorithm_sptr m_singleFitAlg; diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ConvFit.ui b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ConvFit.ui index c997de2f86eacfb29fd7b8ade6e586b162fb79a6..6fb0d4ae1ef6469beeee4d10cfd187785a771b2f 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ConvFit.ui +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ConvFit.ui @@ -290,6 +290,13 @@ </property> </spacer> </item> + <item> + <widget class="QPushButton" name="pbPlotPreview"> + <property name="text"> + <string>Plot Current Preview</string> + </property> + </widget> + </item> </layout> </item> <item> @@ -391,11 +398,6 @@ <height>0</height> </size> </property> - <item> - <property name="text"> - <string>None</string> - </property> - </item> <item> <property name="text"> <string>All</string> @@ -413,6 +415,16 @@ </item> </widget> </item> + <item> + <widget class="QPushButton" name="pbPlot"> + <property name="text"> + <string>Plot</string> + </property> + <property name="enabled"> + <bool>false</bool> + </property> + </widget> + </item> <item> <spacer name="horizontalSpacer_1"> <property name="orientation"> @@ -427,9 +439,12 @@ </spacer> </item> <item> - <widget class="QCheckBox" name="ckSave"> + <widget class="QPushButton" name="pbSave"> <property name="text"> - <string>Save Result</string> + <string>Save</string> + </property> + <property name="enabled"> + <bool>false</bool> </property> </widget> </item> diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectTab.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectTab.h index c39d6fee9ad49772a2e67ef0b837f38f6889ed38..d898ba3c539f34c9dcc18012ee65067decf034d9 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectTab.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/IndirectTab.h @@ -148,6 +148,11 @@ protected: QString runPythonCode(QString vode, bool no_output = false); + /// Checks the ADS for a workspace named `workspaceName`, + /// opens a warning box for plotting/saving if none found + bool checkADSForPlotSaveWorkspace(const std::string &workspaceName, + const bool &plotting); + /// Parent QWidget (if applicable) QWidget *m_parentWidget; diff --git a/MantidQt/CustomInterfaces/src/Indirect/ConvFit.cpp b/MantidQt/CustomInterfaces/src/Indirect/ConvFit.cpp index 96acea2d2550d0db1caf647da4240fe9e9b1f44e..a6595211ee11da597cc5c56c542aabf12f46046e 100644 --- a/MantidQt/CustomInterfaces/src/Indirect/ConvFit.cpp +++ b/MantidQt/CustomInterfaces/src/Indirect/ConvFit.cpp @@ -210,6 +210,12 @@ void ConvFit::setup() { SLOT(showTieCheckbox(QString))); showTieCheckbox(m_uiForm.cbFitType->currentText()); + // Post Plot and Save + connect(m_uiForm.pbSave, SIGNAL(clicked()), this, SLOT(saveClicked())); + connect(m_uiForm.pbPlot, SIGNAL(clicked()), this, SLOT(plotClicked())); + connect(m_uiForm.pbPlotPreview, SIGNAL(clicked()), this, + SLOT(plotCurrentPreview())); + m_previousFit = m_uiForm.cbFitType->currentText(); updatePlotOptions(); @@ -294,6 +300,80 @@ void ConvFit::run() { m_batchAlgoRunner->executeBatchAsync(); } +/** + * Handles saving the workspace when save is clicked + */ +void ConvFit::saveClicked() { + // check workspace exists + const auto resultName = m_baseName.toStdString() + "_Result"; + const auto wsFound = checkADSForPlotSaveWorkspace(resultName, false); + // process workspace after check + if (wsFound) { + QString saveDir = QString::fromStdString( + Mantid::Kernel::ConfigService::Instance().getString( + "defaultsave.directory")); + // Check validity of save path + QString QresultWsName = QString::fromStdString(resultName); + const auto fullPath = saveDir.append(QresultWsName).append(".nxs"); + addSaveWorkspaceToQueue(QresultWsName, fullPath); + m_batchAlgoRunner->executeBatchAsync(); + } else { + return; + } +} + +/** + * Handles plotting the workspace when plot is clicked + */ +void ConvFit::plotClicked() { + + // check workspace exists + const auto resultName = m_baseName.toStdString() + "_Result"; + const auto wsFound = checkADSForPlotSaveWorkspace(resultName, true); + if (wsFound) { + MatrixWorkspace_sptr resultWs = + AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(resultName); + const auto plot = m_uiForm.cbPlotType->currentText().toStdString(); + + // Handle plot result + if (!(plot.compare("None") == 0)) { + if (plot.compare("All") == 0) { + const auto specEnd = (int)resultWs->getNumberHistograms(); + for (int i = 0; i < specEnd; i++) { + IndirectTab::plotSpectrum(QString::fromStdString(resultWs->getName()), + i, i); + } + } else { + const auto specNumber = m_uiForm.cbPlotType->currentIndex(); + IndirectTab::plotSpectrum(QString::fromStdString(resultWs->getName()), + specNumber, specNumber); + } + } + } else { + return; + } +} + +/** + * Plots the current spectrum displayed in the preview plot + */ +void ConvFit::plotCurrentPreview() { + if (!m_cfInputWS) { + return; + } + if (m_cfInputWS->getName().compare(m_previewPlotData->getName()) == 0) { + // Plot only the sample curve + const auto workspaceIndex = m_uiForm.spPlotSpectrum->value(); + IndirectTab::plotSpectrum( + QString::fromStdString(m_previewPlotData->getName()), workspaceIndex, + workspaceIndex); + } else { + // Plot Sample, Fit and Diff curve + IndirectTab::plotSpectrum( + QString::fromStdString(m_previewPlotData->getName()), 0, 2); + } +} + /** * Handles completion of the ConvolutionFitSequential algorithm. * @@ -306,41 +386,10 @@ void ConvFit::algorithmComplete(bool error) { if (error) return; - std::string resultName = m_baseName.toStdString() + "_Result"; + const auto resultName = m_baseName.toStdString() + "_Result"; MatrixWorkspace_sptr resultWs = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(resultName); - const bool save = m_uiForm.ckSave->isChecked(); - - // Handle Save file - if (save) { - QString saveDir = QString::fromStdString( - Mantid::Kernel::ConfigService::Instance().getString( - "defaultsave.directory")); - // Check validity of save path - QString QresultWsName = QString::fromStdString(resultWs->getName()); - QString fullPath = saveDir.append(QresultWsName).append(".nxs"); - addSaveWorkspaceToQueue(QresultWsName, fullPath); - } - - std::string plot = m_uiForm.cbPlotType->currentText().toStdString(); - - // Handle plot result - if (!(plot.compare("None") == 0)) { - if (plot.compare("All") == 0) { - int specEnd = (int)resultWs->getNumberHistograms(); - for (int i = 0; i < specEnd; i++) { - IndirectTab::plotSpectrum(QString::fromStdString(resultWs->getName()), - i, i); - } - } else { - // -1 to account for None in dropDown - int specNumber = m_uiForm.cbPlotType->currentIndex() - 1; - IndirectTab::plotSpectrum(QString::fromStdString(resultWs->getName()), - specNumber, specNumber); - } - } - // Obtain WorkspaceGroup from ADS std::string groupName = m_baseName.toStdString() + "_Workspaces"; WorkspaceGroup_sptr groupWs = @@ -408,6 +457,8 @@ void ConvFit::algorithmComplete(bool error) { } m_batchAlgoRunner->executeBatchAsync(); updatePlot(); + m_uiForm.pbSave->setEnabled(true); + m_uiForm.pbPlot->setEnabled(true); } /** @@ -1006,6 +1057,7 @@ void ConvFit::updatePlot() { int specNo = m_uiForm.spPlotSpectrum->text().toInt(); m_uiForm.ppPlot->clear(); + m_previewPlotData = m_cfInputWS; m_uiForm.ppPlot->addSpectrum("Sample", m_cfInputWS, specNo); try { @@ -1040,6 +1092,7 @@ void ConvFit::updatePlot() { MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>( outputGroup->getItem(specNo - m_runMin)); if (ws) { + m_previewPlotData = ws; m_uiForm.ppPlot->addSpectrum("Fit", ws, 1, Qt::red); m_uiForm.ppPlot->addSpectrum("Diff", ws, 2, Qt::blue); if (m_uiForm.ckPlotGuess->isChecked()) { @@ -1197,6 +1250,9 @@ void ConvFit::singleFitComplete(bool error) { // Plot the line on the mini plot m_uiForm.ppPlot->removeSpectrum("Guess"); const auto resultName = m_singleFitOutputName + "_Workspace"; + m_previewPlotData = + AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( + resultName.toStdString()); m_uiForm.ppPlot->addSpectrum("Fit", resultName, 1, Qt::red); m_uiForm.ppPlot->addSpectrum("Diff", resultName, 2, Qt::blue); @@ -1532,7 +1588,7 @@ void ConvFit::fitFunctionSelected(const QString &functionName) { double oneLValues[3] = {0.0, 0.0, 0.0}; // previous values for one lorentzian fit bool previouslyOneL = false; - // If the previosu fit was One Lorentzian and the new fit is Two Lorentzian + // If the previous fit was One Lorentzian and the new fit is Two Lorentzian // preserve the values of One Lorentzian Fit if (m_previousFit.compare("One Lorentzian") == 0 && m_uiForm.cbFitType->currentText().compare("Two Lorentzians") == 0) { @@ -1666,7 +1722,6 @@ void ConvFit::updatePlotOptions() { const bool deltaFunction = m_blnManager->value(m_properties["UseDeltaFunc"]); const int fitFunctionType = m_uiForm.cbFitType->currentIndex(); QStringList plotOptions; - plotOptions << "None"; if (deltaFunction && fitFunctionType < 3) { plotOptions << "Height"; diff --git a/MantidQt/CustomInterfaces/src/Indirect/IndirectTab.cpp b/MantidQt/CustomInterfaces/src/Indirect/IndirectTab.cpp index 3e0ec98cedd96e0a27d00d003bd23562ad55e974..8daaf18e71d72d73360fc30e63b9896c859c3284 100644 --- a/MantidQt/CustomInterfaces/src/Indirect/IndirectTab.cpp +++ b/MantidQt/CustomInterfaces/src/Indirect/IndirectTab.cpp @@ -11,6 +11,7 @@ #include "MantidQtMantidWidgets/RangeSelector.h" #include <boost/algorithm/string/find.hpp> +#include <QMessageBox> using namespace Mantid::API; using namespace Mantid::Geometry; @@ -529,5 +530,29 @@ QString IndirectTab::runPythonCode(QString code, bool no_output) { return m_pythonRunner.runPythonCode(code, no_output); } +/** + * Checks if the ADS contains a workspace and opens a message box if not + * @param workspaceName The name of the workspace to look for + * @param plotting if true use plotting error message, false use saving error + * message + * @return False if no workpsace found, True if workspace found + */ +bool IndirectTab::checkADSForPlotSaveWorkspace(const std::string &workspaceName, + const bool &plotting) { + const auto workspaceExists = + AnalysisDataService::Instance().doesExist(workspaceName); + if (workspaceExists) { + return true; + } else { + const std::string plotSave = plotting ? "plotting" : "saving"; + const auto errorMessage = "Error while " + plotSave + + ":\nThe workspace \"" + workspaceName + + "\" could not be found."; + const char *textMessage = errorMessage.c_str(); + QMessageBox::warning(NULL, tr("Workspace not found"), tr(textMessage)); + return false; + } +} + } // namespace CustomInterfaces } // namespace Mantid diff --git a/docs/source/release/v3.8.0/indirect_inelastic.rst b/docs/source/release/v3.8.0/indirect_inelastic.rst index b5fa2eaf4afd99c3075aaed7c3a8d390d14125f1..fe2ea71daf436c25810ca27c896e7d8a028c37e6 100644 --- a/docs/source/release/v3.8.0/indirect_inelastic.rst +++ b/docs/source/release/v3.8.0/indirect_inelastic.rst @@ -41,8 +41,10 @@ Elwin - When using multiple input files, the naming convention for the outputworkspace contains the `first-final` run number. An example of this would be `osi92764-92767_graphite002_red_elwin_elf` for OSIRIS run between 92764-92767 -Jump Fit -~~~~~~~~ +ConvFit +~~~~~~~ + +- Plotting and saving is now performed after the algorithm is run. These are push buttons at the bottom of the interface which are enabled post algorithm completion Simulations ###########