diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp b/Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp index 318c5c760200..83a2629c2a9f 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp @@ -1266,7 +1266,7 @@ void MantidDockWidget::plotSpectra() // An empty map will be returned if the user clicks cancel in the spectrum selection if (toPlot.empty()) return; - m_mantidUI->plot1D(toPlot, true, false); + m_mantidUI->plot1D(toPlot, true, MantidQt::DistributionDefault, false); } /// Plots a single spectrum from each selected workspace @@ -1276,7 +1276,7 @@ void MantidDockWidget::plotSpectraDistribution() // An empty map will be returned if the user clicks cancel in the spectrum selection if (toPlot.empty()) return; - m_mantidUI->plot1D(toPlot, true, false, true ); + m_mantidUI->plot1D(toPlot, true, MantidQt::DistributionTrue, false); } /// Plots a single spectrum from each selected workspace with errors @@ -1286,7 +1286,7 @@ void MantidDockWidget::plotSpectraErr() // An empty map will be returned if the user clicks cancel in the spectrum selection if (toPlot.empty()) return; - m_mantidUI->plot1D(toPlot, true, true); + m_mantidUI->plot1D(toPlot, true, MantidQt::DistributionDefault, true); } /// Plots a single spectrum from each selected workspace with erros @@ -1296,7 +1296,7 @@ void MantidDockWidget::plotSpectraDistributionErr() // An empty map will be returned if the user clicks cancel in the spectrum selection if (toPlot.empty()) return; - m_mantidUI->plot1D(toPlot, true, true, true ); + m_mantidUI->plot1D(toPlot, true, MantidQt::DistributionTrue, true); } /** diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp index 9dd7430eac6c..25e7de71a4ca 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp @@ -996,7 +996,7 @@ void MantidUI::copyRowToGraph() { MantidMatrix* m = dynamic_cast(appWindow()->activeWindow()); if (!m || !m->isA("MantidMatrix")) return; - plotSelectedRows(m,false); + plotSelectedRows(m,MantidQt::DistributionDefault,false); } @@ -1018,7 +1018,7 @@ void MantidUI::copyRowToGraphErr() { MantidMatrix* m = dynamic_cast(appWindow()->activeWindow()); if (!m || !m->isA("MantidMatrix")) return; - plotSelectedRows(m,true); + plotSelectedRows(m,MantidQt::DistributionDefault,true); } @@ -1026,7 +1026,7 @@ void MantidUI::copyRowsToWaterfall() { const MantidMatrix* const m = dynamic_cast(appWindow()->activeWindow()); if (!m || !m->isA("MantidMatrix")) return; - MultiLayer* ml = plotSelectedRows(m,false); + MultiLayer* ml = plotSelectedRows(m, MantidQt::DistributionDefault, false); if (ml) convertToWaterfall(ml); } @@ -1034,7 +1034,8 @@ void MantidUI::plotWholeAsWaterfall() { const MantidMatrix* const m = dynamic_cast(appWindow()->activeWindow()); if (!m || !m->isA("MantidMatrix")) return; - MultiLayer* ml = plotSpectraRange(m->workspaceName(),0,m->numRows()-1,false); + MultiLayer* ml = plotSpectraRange(m->workspaceName(),0,m->numRows()-1, + MantidQt::DistributionDefault, false); if (ml) convertToWaterfall(ml); } @@ -2250,13 +2251,13 @@ void MantidUI::menuMantidMatrixAboutToShow() MultiLayer* MantidUI::plotInstrumentSpectrum(const QString& wsName, int spec) { QMessageBox::information(appWindow(),"OK",wsName+" "+QString::number(spec)); - return plotSpectraRange(wsName, spec, spec, false); + return plotSpectraRange(wsName, spec, spec, MantidQt::DistributionDefault, false); } /// Catches the signal from InstrumentWindow to plot a spectrum. MultiLayer* MantidUI::plotInstrumentSpectrumList(const QString& wsName, std::set spec) { - return plot1D(wsName, spec, false); + return plot1D(wsName, spec, true, MantidQt::DistributionDefault, false); } /** @@ -2968,7 +2969,7 @@ Plots the spectra from the given workspaces @param clearWindow :: Whether to clear specified plotWindow before plotting. Ignored if plotWindow == NULL */ MultiLayer* MantidUI::plot1D(const QStringList& ws_names, const QList& indexList, bool spectrumPlot, bool errs, - Graph::CurveType style, MultiLayer* plotWindow, bool clearWindow) + Graph::CurveType style, MultiLayer* plotWindow, bool clearWindow) { // Convert the list into a map (with the same workspace as key in each case) QMultiMap pairs; @@ -2990,19 +2991,20 @@ MultiLayer* MantidUI::plot1D(const QStringList& ws_names, const QList& inde } // Pass over to the overloaded method - return plot1D(pairs,spectrumPlot,errs,false,style,plotWindow, clearWindow); + return plot1D(pairs,spectrumPlot,MantidQt::DistributionDefault, errs,style,plotWindow, clearWindow); } /** Create a 1D graph from the specified list of workspaces/spectra. @param toPlot :: Map of form ws -> [spectra_list] @param spectrumPlot :: True if indices should be interpreted as row indices +@param distr :: if true, workspace plot as y data/bin width @param errs :: If true include the errors on the graph -@param distr :: if true, workspace is a distribution @param plotWindow :: Window to plot to. If NULL a new one will be created @param clearWindow :: Whether to clear specified plotWindow before plotting. Ignored if plotWindow == NULL @return NULL if failure. Otherwise, if plotWindow == NULL - created window, if not NULL - plotWindow */ -MultiLayer* MantidUI::plot1D(const QMultiMap >& toPlot, bool spectrumPlot, bool errs, bool distr, - MultiLayer* plotWindow, bool clearWindow) +MultiLayer* MantidUI::plot1D(const QMultiMap >& toPlot, bool spectrumPlot, + MantidQt::DistributionFlag distr, bool errs, + MultiLayer* plotWindow, bool clearWindow) { // Convert the list into a map (with the same workspace as key in each case) QMultiMap pairs; @@ -3018,21 +3020,21 @@ MultiLayer* MantidUI::plot1D(const QMultiMap >& toPlot, bool s } // Pass over to the overloaded method - return plot1D(pairs,spectrumPlot,errs,distr,Graph::Unspecified,plotWindow, clearWindow); + return plot1D(pairs,spectrumPlot,distr,errs,Graph::Unspecified,plotWindow, clearWindow); } /** Create a 1d graph from the specified spectra in a MatrixWorkspace @param wsName :: Workspace name @param indexList :: List of indices to plot for each workspace @param spectrumPlot :: True if indices should be interpreted as row indices +@param distr :: if true, workspace plot as y data/bin width @param errs :: If true include the errors on the graph -@param distr :: if true, workspace is a distribution @param plotWindow :: Window to plot to. If NULL a new one will be created @param clearWindow :: Whether to clear specified plotWindow before plotting. Ignored if plotWindow == NULL @return NULL if failure. Otherwise, if plotWindow == NULL - created window, if not NULL - plotWindow */ -MultiLayer* MantidUI::plot1D(const QString& wsName, const std::set& indexList, bool spectrumPlot, bool errs, - bool distr, MultiLayer* plotWindow, bool clearWindow) +MultiLayer* MantidUI::plot1D(const QString& wsName, const std::set& indexList, bool spectrumPlot, + MantidQt::DistributionFlag distr, bool errs, MultiLayer* plotWindow, bool clearWindow) { // Convert the list into a map (with the same workspace as key in each case) QMultiMap pairs; @@ -3044,21 +3046,22 @@ MultiLayer* MantidUI::plot1D(const QString& wsName, const std::set& indexLi } // Pass over to the overloaded method - return plot1D(pairs,spectrumPlot,errs,distr,Graph::Unspecified,plotWindow, clearWindow); + return plot1D(pairs,spectrumPlot,distr,errs,Graph::Unspecified,plotWindow, clearWindow); } /** Create a 1d graph form a set of workspace-spectrum pairs @param toPlot :: A list of workspace/spectra to be shown in the graph @param spectrumPlot :: True if indices should be interpreted as row indices +@param distr :: if true, workspace plot as y data/bin width @param errs :: If true include the errors to the graph -@param distr :: if true, workspace is a distribution @param style :: curve style for plot @param plotWindow :: Window to plot to. If NULL a new one will be created @param clearWindow :: Whether to clear specified plotWindow before plotting. Ignored if plotWindow == NULL @return NULL if failure. Otherwise, if plotWindow == NULL - created window, if not NULL - plotWindow */ -MultiLayer* MantidUI::plot1D(const QMultiMap& toPlot, bool spectrumPlot, bool errs, bool distr, - Graph::CurveType style, MultiLayer* plotWindow, bool clearWindow) +MultiLayer* MantidUI::plot1D(const QMultiMap& toPlot, bool spectrumPlot, + MantidQt::DistributionFlag distr, bool errs, + Graph::CurveType style, MultiLayer* plotWindow, bool clearWindow) { if(toPlot.size() == 0) return NULL; @@ -3120,16 +3123,26 @@ MultiLayer* MantidUI::plot1D(const QMultiMap& toPlot, bool spectrum ml->setName(appWindow()->generateUniqueName(plotTitle + "-")); m_lastShown1DPlotWin = ml; - Graph *g = ml->activeGraph(); - + // Do we plot a distribution or not + bool plotAsDistribution(false); + if(distr == MantidQt::DistributionDefault) + { + plotAsDistribution = false; + } + else + { + plotAsDistribution = (distr == MantidQt::DistributionTrue); + } + // Try to add curves to the plot + Graph *g = ml->activeGraph(); MantidMatrixCurve::IndexDir indexType = (spectrumPlot) ? MantidMatrixCurve::Spectrum : MantidMatrixCurve::Bin; MantidMatrixCurve* firstCurve(NULL); for(QMultiMap::const_iterator it=toPlot.begin();it!=toPlot.end();++it) { try { - auto * wsCurve = new MantidMatrixCurve(it.key(),g,it.value(),indexType,errs,distr,style); + auto * wsCurve = new MantidMatrixCurve(it.key(),g,it.value(),indexType,errs,plotAsDistribution,style); if(!firstCurve) firstCurve = wsCurve; } catch (Mantid::Kernel::Exception::NotFoundError&) @@ -3313,7 +3326,8 @@ MultiLayer* MantidUI::drawSingleColorFillPlot(const QString & wsName, Graph::Cur @param errs :: If true include the errors to the graph @param distr :: if true, workspace is a distribution */ -MultiLayer* MantidUI::plotSpectraRange(const QString& wsName, int i0, int i1, bool errs, bool distr) +MultiLayer* MantidUI::plotSpectraRange(const QString& wsName, int i0, int i1, + MantidQt::DistributionFlag distr, bool errs) { if (i0 < 0 || i1 < 0) return 0; /** For instrument with one to many spectra-detector mapping, @@ -3324,20 +3338,22 @@ MultiLayer* MantidUI::plotSpectraRange(const QString& wsName, int i0, int i1, bo for(int i=i0;i<=i1;i++) indexList.insert(i); - return plot1D(wsName,indexList,true, errs,distr); + return plot1D(wsName,indexList,true, distr, errs); } /** Create a graph and plot the selected rows of a MantidMatrix @param m :: Mantid matrix -@param errs :: True if the errors to be plotted @param distr :: if true, workspace is a distribution +@param errs :: True if the errors to be plotted */ -MultiLayer* MantidUI::plotSelectedRows(const MantidMatrix * const m, bool errs, bool distr) +MultiLayer* MantidUI::plotSelectedRows(const MantidMatrix * const m, + MantidQt::DistributionFlag distr, + bool errs) { const QList& rows = m->getSelectedRows(); std::set rowSet(rows.constBegin(),rows.constEnd()); - return plot1D(m->workspaceName(),rowSet,true,errs,distr); + return plot1D(m->workspaceName(),rowSet,true,distr, errs); } /** @@ -3351,10 +3367,11 @@ MultiLayer *MantidUI::plotSelectedColumns(const MantidMatrix * const m, bool err const QList& cols = m->getSelectedColumns(); std::set colSet(cols.constBegin(),cols.constEnd()); - return plot1D(m->workspaceName(),colSet,false,errs,false); + return plot1D(m->workspaceName(),colSet,false,MantidQt::DistributionFalse, errs); } -Table* MantidUI::createTableFromBins(const QString& wsName, Mantid::API::MatrixWorkspace_const_sptr workspace, const QList& bins, bool errs, int fromRow, int toRow) +Table* MantidUI::createTableFromBins(const QString& wsName, Mantid::API::MatrixWorkspace_const_sptr workspace, + const QList& bins, bool errs, int fromRow, int toRow) { if (bins.empty()) return NULL; diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.h b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.h index 290247f2e296..88c37990af51 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.h +++ b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.h @@ -16,7 +16,10 @@ #include "MantidAPI/IPeaksWorkspace.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/Workspace.h" + #include "MantidQtAPI/AlgorithmDialog.h" +#include "MantidQtAPI/QwtWorkspaceSpectrumData.h" + #include #include @@ -188,7 +191,9 @@ class MantidUI:public QObject MultiLayer* createGraphFromTable(Table* t, int type = 0); // Shows 1D graphs of the spectra (rows) selected in a MantidMatrix - MultiLayer* plotSelectedRows(const MantidMatrix * const m, bool errs = true, bool distr = false); + MultiLayer* plotSelectedRows(const MantidMatrix * const m, + MantidQt::DistributionFlag distr = MantidQt::DistributionDefault, + bool errs = true); // Shows 1D graphs of the columns (bins) selected in a MantidMatrix MultiLayer* plotSelectedColumns(const MantidMatrix * const m, bool errs = true); @@ -206,22 +211,25 @@ class MantidUI:public QObject public slots: // Create a 1d graph form specified MatrixWorkspace and index MultiLayer* plot1D(const QStringList& wsnames, const QList& indexList, bool spectrumPlot, - bool errs=true, Graph::CurveType style = Graph::Unspecified, - MultiLayer* plotWindow = NULL, bool clearWindow = false); + bool errs=true, Graph::CurveType style = Graph::Unspecified, + MultiLayer* plotWindow = NULL, bool clearWindow = false); MultiLayer* plot1D(const QString& wsName, const std::set& indexList, bool spectrumPlot, - bool errs=false, bool distr=false, - MultiLayer* plotWindow = NULL, bool clearWindow = false); + MantidQt::DistributionFlag distr = MantidQt::DistributionDefault, + bool errs=false, + MultiLayer* plotWindow = NULL, bool clearWindow = false); MultiLayer* plot1D(const QMultiMap& toPlot, bool spectrumPlot, - bool errs=false, bool distr=false, - Graph::CurveType style = Graph::Unspecified, - MultiLayer* plotWindow = NULL, bool clearWindow = false); + MantidQt::DistributionFlag distr = MantidQt::DistributionDefault, + bool errs=false, + Graph::CurveType style = Graph::Unspecified, + MultiLayer* plotWindow = NULL, bool clearWindow = false); MultiLayer* plot1D(const QMultiMap >& toPlot, bool spectrumPlot, - bool errs=false, bool distr=false, - MultiLayer* plotWindow = NULL, bool clearWindow = false); - + MantidQt::DistributionFlag distr = MantidQt::DistributionDefault, + bool errs=false, + MultiLayer* plotWindow = NULL, bool clearWindow = false); + /// Draw a color fill plot for each of the listed workspaces void drawColorFillPlots(const QStringList & wsNames, Graph::CurveType curveType = Graph::ColorMap); /// Draw a color fill plot for the named workspace @@ -229,7 +237,9 @@ class MantidUI:public QObject MultiLayer* window = NULL); // Create a 1d graph form specified spectra in a MatrixWorkspace - MultiLayer* plotSpectraRange(const QString& wsName, int i0, int i1, bool errs=true, bool distr=false); + MultiLayer* plotSpectraRange(const QString& wsName, int i0, int i1, + MantidQt::DistributionFlag distr = MantidQt::DistributionDefault, + bool errs=true); // Set properties of a 1d graph which plots data from a workspace static void setUpBinGraph(MultiLayer* ml, const QString& wsName, Mantid::API::MatrixWorkspace_const_sptr workspace);