diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingViewQtWidget.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingViewQtWidget.h index bb1ee8882eefd1b4116bba23b300512b9b0369a6..6361738c3f2fb5217e2bb8a239bf981f003bc21d 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingViewQtWidget.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffFittingViewQtWidget.h @@ -124,6 +124,8 @@ public: void setBankEmit() override; + void resetCanvas() override; + void setDataVector(std::vector<boost::shared_ptr<QwtData>> &data, bool focused, bool plotSinglePeaks) override; diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffFittingView.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffFittingView.h index 6360c77bee755b17e3a93dde9a5c7bb525cb8f49..cd3afd63a89ab79aa3dae677a00b0f838b2ed31a 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffFittingView.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffFittingView.h @@ -274,6 +274,11 @@ public: virtual void setDataVector(std::vector<boost::shared_ptr<QwtData>> &data, bool focused, bool plotSinglePeaks) = 0; + /** + * resets the canvas to avoid multiple plotting + */ + virtual void resetCanvas() = 0; + /** * Messages that this view wants to send to the logging system. * diff --git a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffFittingPresenter.cpp b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffFittingPresenter.cpp index 0995c6fe3f6c2ed812e6f6ec89768f473e94d2dc..07974bcc0bbd68d54f9d250209cc0a70ebf1c92e 100644 --- a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffFittingPresenter.cpp +++ b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffFittingPresenter.cpp @@ -485,23 +485,31 @@ void EnggDiffFittingPresenter::processLoad() { // while directory vector is not empty // if loaded here set a global variable true so doesnt load again? - MatrixWorkspace_sptr focusedWS; - const std::string focusedFile = m_view->getFittingRunNo(); - Poco::Path selectedfPath(focusedFile); + try { + MatrixWorkspace_sptr focusedWS; + const std::string focusedFile = m_view->getFittingRunNo(); + Poco::Path selectedfPath(focusedFile); - if (!focusedFile.empty() && selectedfPath.isFile()) { - runLoadAlg(focusedFile, focusedWS); - setDifcTzero(focusedWS); - convertUnits(g_focusedFittingWSName); - plotFocusedFile(false); + if (!focusedFile.empty() && selectedfPath.isFile()) { + runLoadAlg(focusedFile, focusedWS); + setDifcTzero(focusedWS); + convertUnits(g_focusedFittingWSName); + plotFocusedFile(false); - m_view->showStatus("Focused file loaded! (Click 'Select " - "Peak' to activate peak picker tool, hold Shift + Click " - "Peak, Click 'Add Peak')"); + m_view->showStatus( + "Focused file loaded! (Click 'Select " + "Peak' to activate peak picker tool, hold Shift + Click " + "Peak, Click 'Add Peak')"); - } else { - m_view->userWarning("No File Found", "Please select a valid focused file!"); - m_view->showStatus("Error while plotting the focused workspace"); + } else { + m_view->userWarning("No File Found", + "Please select a focused file to load"); + m_view->showStatus("Error while plotting the focused workspace"); + } + } catch (std::invalid_argument &ia) { + m_view->userWarning( + "Error loading file", + "Unable to load the selected focused file, Please try again."); } } @@ -1507,6 +1515,10 @@ void EnggDiffFittingPresenter::plotFitPeaksCurves() { try { + // detaches previous plots from canvas + m_view->resetCanvas(); + + // plots focused workspace plotFocusedFile(m_fittingFinishedOK); if (m_fittingFinishedOK) { diff --git a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffFittingViewQtWidget.cpp b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffFittingViewQtWidget.cpp index 45860194027df1bdc21d82a4c3c1f5b80d4d7745..5c5e66ee2623f841c038e2370ae297682b49e6c7 100644 --- a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffFittingViewQtWidget.cpp +++ b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffFittingViewQtWidget.cpp @@ -276,27 +276,33 @@ void EnggDiffFittingViewQtWidget::resetFittingMode() { m_fittingSingleRunMode = false; } +void EnggDiffFittingViewQtWidget::resetCanvas() { + // clear vector and detach curves to avoid plot crash + // when only plotting focused workspace + for (auto curves : m_fittedDataVector) { + if (curves) { + curves->detach(); + delete curves; + } + } + + if (m_fittedDataVector.size() > 0) + m_fittedDataVector.clear(); + + // set it as false as there will be no valid workspace to plot + m_ui.pushButton_plot_separate_window->setEnabled(false); +} + void EnggDiffFittingViewQtWidget::setDataVector( std::vector<boost::shared_ptr<QwtData>> &data, bool focused, bool plotSinglePeaks) { if (!plotSinglePeaks) { // clear vector and detach curves to avoid plot crash - // when only plotting focused workspace - for (auto curves : m_fittedDataVector) { - if (curves) { - curves->detach(); - delete curves; - } - } - - if (m_fittedDataVector.size() > 0) - m_fittedDataVector.clear(); - - // set it as false as there will be no valid workspace to plot - m_ui.pushButton_plot_separate_window->setEnabled(false); + resetCanvas(); } + // when only plotting focused workspace if (focused) { dataCurvesFactory(data, m_focusedDataVector, focused); } else {