diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IReflPresenter.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IReflPresenter.h index 06539eaf39e507e623d31751745dcc3185f97da2..977f9456efa9bd064e8ae194374b0429372b4980 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IReflPresenter.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IReflPresenter.h @@ -63,6 +63,8 @@ namespace MantidQt TransferFlag, ImportTableFlag, ExportTableFlag, + PlotRowFlag, + PlotGroupFlag, }; //Tell the presenter something happened diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/QtReflMainView.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/QtReflMainView.h index 9b4e0064a8865fc31767406c2985da72d46f9d10..cb15c86c458d0d423921e2970244fe704dd0dd4b 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/QtReflMainView.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/QtReflMainView.h @@ -62,6 +62,9 @@ namespace MantidQt virtual void giveUserCritical(std::string prompt, std::string title); virtual void showAlgorithmDialog(const std::string& algorithm); + //Plotting + virtual void plotWorkspaces(const std::set<std::string>& workspaces); + //Set the status of the progress bar virtual void setProgressRange(int min, int max); virtual void setProgress(int progress); @@ -118,6 +121,8 @@ namespace MantidQt void on_actionImportTable_triggered(); void on_actionExportTable_triggered(); void on_actionHelp_triggered(); + void on_actionPlotRow_triggered(); + void on_actionPlotGroup_triggered(); void on_comboSearchInstrument_currentIndexChanged(int index); void on_comboProcessInstrument_currentIndexChanged(int index); diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainView.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainView.h index e92a8ca7fe73bd05dea03908dcf1af9f7edfa9fd..3ae6fd78dfa3817cb05ed81adff28764d81864ad 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainView.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainView.h @@ -54,6 +54,9 @@ namespace MantidQt virtual void giveUserCritical(std::string prompt, std::string title) = 0; virtual void showAlgorithmDialog(const std::string& algorithm) = 0; + //Plotting + virtual void plotWorkspaces(const std::set<std::string>& workspaces) = 0; + //Set the status of the progress bar virtual void setProgressRange(int min, int max) = 0; virtual void setProgress(int progress) = 0; diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainViewPresenter.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainViewPresenter.h index 1eb2e75c182d67e4cda86fe86cef52541cd1a9cb..616a89c5ef131c146dcabb40a9405b9f7d51a330 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainViewPresenter.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainViewPresenter.h @@ -70,7 +70,7 @@ namespace MantidQt boost::shared_ptr<ReflTransferStrategy> m_transferStrategy; //process selected rows - virtual void process(); + void process(); //Reduce a row void reduceRow(int rowNo); //prepare a run or list of runs for processing @@ -94,34 +94,37 @@ namespace MantidQt //Stitch some rows void stitchRows(std::set<int> rows); //insert a row in the model before the given index - virtual void insertRow(int index); + void insertRow(int index); //add row(s) to the model - virtual void appendRow(); - virtual void prependRow(); + void appendRow(); + void prependRow(); //delete row(s) from the model - virtual void deleteRow(); + void deleteRow(); //clear selected row(s) in the model - virtual void clearSelected(); + void clearSelected(); //copy selected rows to clipboard - virtual void copySelected(); + void copySelected(); //copy selected rows to clipboard and then delete them - virtual void cutSelected(); + void cutSelected(); //paste clipboard into selected rows - virtual void pasteSelected(); + void pasteSelected(); //group selected rows together - virtual void groupRows(); + void groupRows(); //expand selection to group - virtual void expandSelection(); + void expandSelection(); //table io methods - virtual void newTable(); - virtual void openTable(); - virtual void saveTable(); - virtual void saveTableAs(); - virtual void importTable(); - virtual void exportTable(); + void newTable(); + void openTable(); + void saveTable(); + void saveTableAs(); + void importTable(); + void exportTable(); //searching - virtual void search(); - virtual void transfer(); + void search(); + void transfer(); + //plotting + void plotRow(); + void plotGroup(); //options void showOptionsDialog(); void initOptions(); diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainWidget.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainWidget.ui index b7f3b8cc187fc239eec512e9d67cf50fe021f877..fed9132ab6db547f8d2dcb1b9407008599d103be 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainWidget.ui +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainWidget.ui @@ -223,6 +223,9 @@ <addaction name="actionProcess"/> <addaction name="actionExpandSelection"/> <addaction name="separator"/> + <addaction name="actionPlotRow"/> + <addaction name="actionPlotGroup"/> + <addaction name="separator"/> <addaction name="actionAppendRow"/> <addaction name="actionDeleteRow"/> <addaction name="separator"/> @@ -374,6 +377,9 @@ <addaction name="actionProcess"/> <addaction name="actionExpandSelection"/> <addaction name="separator"/> + <addaction name="actionPlotRow"/> + <addaction name="actionPlotGroup"/> + <addaction name="separator"/> <addaction name="actionPrependRow"/> <addaction name="actionAppendRow"/> <addaction name="separator"/> @@ -649,6 +655,36 @@ <string>F1</string> </property> </action> + <action name="actionPlotRow"> + <property name="icon"> + <iconset resource="../../../../MantidPlot/icons/icons.qrc"> + <normaloff>:/graph.png</normaloff>:/graph.png</iconset> + </property> + <property name="text"> + <string>Plot Selected Rows</string> + </property> + <property name="toolTip"> + <string>Plot the selected rows</string> + </property> + <property name="whatsThis"> + <string>Creates a plot of the IvsQ workspaces produced by the selected rows.</string> + </property> + </action> + <action name="actionPlotGroup"> + <property name="icon"> + <iconset resource="../../../../MantidPlot/icons/icons.qrc"> + <normaloff>:/trajectory.png</normaloff>:/trajectory.png</iconset> + </property> + <property name="text"> + <string>Plot Selected Groups</string> + </property> + <property name="toolTip"> + <string>Plot the selected groups</string> + </property> + <property name="whatsThis"> + <string>Creates a plot of the stitched IvsQ workspaces produced by any groups any selected rows are in.</string> + </property> + </action> </widget> <tabstops> <tabstop>comboSearchInstrument</tabstop> diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/QtReflMainView.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/QtReflMainView.cpp index bec40479a80df61e559e84c3a161ba1522b59c99..447c556521bf3cb077a45bfa02fa4a6ac118b34f 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/QtReflMainView.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/QtReflMainView.cpp @@ -278,6 +278,22 @@ namespace MantidQt MantidQt::API::HelpWindow::showPage(this, QString("qthelp://org.mantidproject/doc/interfaces/ISIS_Reflectometry.html")); } + /** + This slot notifies the presenter that the "plot selected rows" button has been pressed + */ + void QtReflMainView::on_actionPlotRow_triggered() + { + m_presenter->notify(IReflPresenter::PlotRowFlag); + } + + /** + This slot notifies the presenter that the "plot selected groups" button has been pressed + */ + void QtReflMainView::on_actionPlotGroup_triggered() + { + m_presenter->notify(IReflPresenter::PlotGroupFlag); + } + /** This slot notifies the presenter that the table has been updated/changed by the user */ @@ -303,6 +319,9 @@ namespace MantidQt menu->addAction(ui.actionProcess); menu->addAction(ui.actionExpandSelection); menu->addSeparator(); + menu->addAction(ui.actionPlotRow); + menu->addAction(ui.actionPlotGroup); + menu->addSeparator(); menu->addAction(ui.actionPrependRow); menu->addAction(ui.actionAppendRow); menu->addSeparator(); @@ -407,6 +426,24 @@ namespace MantidQt runPythonCode(QString::fromStdString(pythonSrc.str())); } + /** + Plot a workspace + */ + void QtReflMainView::plotWorkspaces(const std::set<std::string>& workspaces) + { + if(workspaces.empty()) + return; + + std::stringstream pythonSrc; + pythonSrc << "base_graph = None\n"; + for(auto ws = workspaces.begin(); ws != workspaces.end(); ++ws) + pythonSrc << "base_graph = plotSpectrum(\"" << *ws << "\", 0, True, window = base_graph)\n"; + + pythonSrc << "base_graph.activeLayer().logLogAxes()\n"; + + runPythonCode(QString::fromStdString(pythonSrc.str())); + } + /** Set the range of the progress bar @param min : The minimum value of the bar diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/ReflMainViewPresenter.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/ReflMainViewPresenter.cpp index 867c289f24a6889b2184abd8400b385415157e70..238e29e058c6be3f2ece0ca2f2cf7e7a3297538c 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/ReflMainViewPresenter.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/ReflMainViewPresenter.cpp @@ -1046,6 +1046,8 @@ namespace MantidQt case IReflPresenter::TransferFlag: transfer(); break; case IReflPresenter::ImportTableFlag: importTable(); break; case IReflPresenter::ExportTableFlag: exportTable(); break; + case IReflPresenter::PlotRowFlag: plotRow(); break; + case IReflPresenter::PlotGroupFlag: plotGroup(); break; } //Not having a 'default' case is deliberate. gcc issues a warning if there's a flag we aren't handling. } @@ -1393,6 +1395,81 @@ namespace MantidQt } } + /** Plots any currently selected rows */ + void ReflMainViewPresenter::plotRow() + { + auto selectedRows = m_view->getSelectedRows(); + + if(selectedRows.empty()) + return; + + std::set<std::string> workspaces, notFound; + for(auto row = selectedRows.begin(); row != selectedRows.end(); ++row) + { + const std::string wsName = "IvsQ_" + getRunNumber(prepareRunWorkspace(m_model->data(m_model->index(*row, COL_RUNS)).toString().toStdString())); + if(AnalysisDataService::Instance().doesExist(wsName)) + workspaces.insert(wsName); + else + notFound.insert(wsName); + } + + if(!notFound.empty()) + m_view->giveUserWarning( + "The following workspaces were not plotted because they were not found:\n" + + boost::algorithm::join(notFound, "\n") + + "\n\nPlease check that the rows you are trying to plot have been fully processed.", + "Error plotting rows."); + + m_view->plotWorkspaces(workspaces); + } + + /** Plots any currently selected groups */ + void ReflMainViewPresenter::plotGroup() + { + auto selectedRows = m_view->getSelectedRows(); + + if(selectedRows.empty()) + return; + + std::set<int> selectedGroups; + for(auto row = selectedRows.begin(); row != selectedRows.end(); ++row) + selectedGroups.insert(m_model->data(m_model->index(*row, COL_GROUP)).toInt()); + + //Now, get the names of the stitched workspace, one per group + std::map<int,std::vector<std::string>> runsByGroup; + const int numRows = m_model->rowCount(); + for(int row = 0; row < numRows; ++row) + { + int group = m_model->data(m_model->index(row, COL_GROUP)).toInt(); + + //Skip groups we don't care about + if(selectedGroups.find(group) == selectedGroups.end()) + continue; + + //Add this to the list of runs + runsByGroup[group].push_back(getRunNumber(prepareRunWorkspace(m_model->data(m_model->index(row, COL_RUNS)).toString().toStdString()))); + } + + std::set<std::string> workspaces, notFound; + for(auto runsMap = runsByGroup.begin(); runsMap != runsByGroup.end(); ++runsMap) + { + const std::string wsName = "IvsQ_" + boost::algorithm::join(runsMap->second, "_"); + if(AnalysisDataService::Instance().doesExist(wsName)) + workspaces.insert(wsName); + else + notFound.insert(wsName); + } + + if(!notFound.empty()) + m_view->giveUserWarning( + "The following workspaces were not plotted because they were not found:\n" + + boost::algorithm::join(notFound, "\n") + + "\n\nPlease check that the groups you are trying to plot have been fully processed.", + "Error plotting groups."); + + m_view->plotWorkspaces(workspaces); + } + /** Shows the Refl Options dialog */ void ReflMainViewPresenter::showOptionsDialog() { diff --git a/Code/Mantid/MantidQt/CustomInterfaces/test/ReflMainViewMockObjects.h b/Code/Mantid/MantidQt/CustomInterfaces/test/ReflMainViewMockObjects.h index af9ae20786299092516997c62a4c973cc998bc6a..1c2e058bef04768a62a3128fd29df26c813a3317 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/test/ReflMainViewMockObjects.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/test/ReflMainViewMockObjects.h @@ -35,6 +35,7 @@ public: MOCK_METHOD2(giveUserWarning, void(std::string, std::string)); MOCK_METHOD1(showAlgorithmDialog, void(const std::string&)); + MOCK_METHOD1(plotWorkspaces, void(const std::set<std::string>&)); //IO MOCK_CONST_METHOD0(getWorkspaceToOpen, std::string()); diff --git a/Code/Mantid/MantidQt/CustomInterfaces/test/ReflMainViewPresenterTest.h b/Code/Mantid/MantidQt/CustomInterfaces/test/ReflMainViewPresenterTest.h index 5963ba6cd317cec5902d694894a2d6cd29105755..cd5fc7c00910286eca66358d239f6608d3c59b26 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/test/ReflMainViewPresenterTest.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/test/ReflMainViewPresenterTest.h @@ -1204,6 +1204,58 @@ public: EXPECT_CALL(mockView, showAlgorithmDialog("SaveReflTBL")); presenter.notify(IReflPresenter::ExportTableFlag); } + + void testPlotRowWarn() + { + MockView mockView; + ReflMainViewPresenter presenter(&mockView); + + createPrefilledWorkspace("TestWorkspace"); + createTOFWorkspace("TOF_12345", "12345"); + EXPECT_CALL(mockView, getWorkspaceToOpen()).Times(1).WillRepeatedly(Return("TestWorkspace")); + presenter.notify(IReflPresenter::OpenTableFlag); + + std::set<int> rowlist; + rowlist.insert(0); + + //We should be warned + EXPECT_CALL(mockView, giveUserWarning(_,_)); + + //The user hits "plot rows" with the first row selected + EXPECT_CALL(mockView, getSelectedRows()).Times(1).WillRepeatedly(Return(rowlist)); + presenter.notify(IReflPresenter::PlotRowFlag); + + //Tidy up + AnalysisDataService::Instance().remove("TestWorkspace"); + AnalysisDataService::Instance().remove("TOF_12345"); + } + + void testPlotGroupWarn() + { + MockView mockView; + ReflMainViewPresenter presenter(&mockView); + + createPrefilledWorkspace("TestWorkspace"); + createTOFWorkspace("TOF_12345", "12345"); + createTOFWorkspace("TOF_12346", "12346"); + EXPECT_CALL(mockView, getWorkspaceToOpen()).Times(1).WillRepeatedly(Return("TestWorkspace")); + presenter.notify(IReflPresenter::OpenTableFlag); + + std::set<int> rowlist; + rowlist.insert(0); + + //We should be warned + EXPECT_CALL(mockView, giveUserWarning(_,_)); + + //The user hits "plot groups" with the first row selected + EXPECT_CALL(mockView, getSelectedRows()).Times(1).WillRepeatedly(Return(rowlist)); + presenter.notify(IReflPresenter::PlotGroupFlag); + + //Tidy up + AnalysisDataService::Instance().remove("TestWorkspace"); + AnalysisDataService::Instance().remove("TOF_12345"); + AnalysisDataService::Instance().remove("TOF_12346"); + } }; #endif /* MANTID_CUSTOMINTERFACES_REFLMAINVIEWPRESENTERTEST_H */ diff --git a/Code/Mantid/docs/source/interfaces/ISIS_Reflectometry.rst b/Code/Mantid/docs/source/interfaces/ISIS_Reflectometry.rst index 0a0bad429fbe8809abcb17dee86b1ed6a21ad194..367b67496b4a43786f97e4358c5c02767d7826dd 100644 --- a/Code/Mantid/docs/source/interfaces/ISIS_Reflectometry.rst +++ b/Code/Mantid/docs/source/interfaces/ISIS_Reflectometry.rst @@ -92,6 +92,12 @@ This table details the behaviour of the actions in the tool bar, from left to ri | | group as a row you have selected are added to your | | | selection. | +------------------+----------------------------------------------------------+ +| Plot Selected | Creates a plot of the IvsQ workspaces generated by any of| +| Rows | the selected rows. | ++------------------+----------------------------------------------------------+ +| Plot Selected | Creates a plot of the stitched IvsQ workspaces generated | +| Groups | by any of the selected groups. | ++------------------+----------------------------------------------------------+ | Insert Row | Adds a new row after the first selected row, or at the | | | end of the table if no rows are selected. | +------------------+----------------------------------------------------------+