Skip to content

Commit

Permalink
Use an enumeration for distribution settings.
Browse files Browse the repository at this point in the history
Currently reproduces what it did before.
Refs #10639
  • Loading branch information
martyngigg committed Nov 27, 2014
1 parent 76f841b commit 936ea4f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 45 deletions.
8 changes: 4 additions & 4 deletions Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
}

/**
Expand Down
75 changes: 46 additions & 29 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Expand Up @@ -996,7 +996,7 @@ void MantidUI::copyRowToGraph()
{
MantidMatrix* m = dynamic_cast<MantidMatrix*>(appWindow()->activeWindow());
if (!m || !m->isA("MantidMatrix")) return;
plotSelectedRows(m,false);
plotSelectedRows(m,MantidQt::DistributionDefault,false);

}

Expand All @@ -1018,23 +1018,24 @@ void MantidUI::copyRowToGraphErr()
{
MantidMatrix* m = dynamic_cast<MantidMatrix*>(appWindow()->activeWindow());
if (!m || !m->isA("MantidMatrix")) return;
plotSelectedRows(m,true);
plotSelectedRows(m,MantidQt::DistributionDefault,true);

}

void MantidUI::copyRowsToWaterfall()
{
const MantidMatrix* const m = dynamic_cast<MantidMatrix*>(appWindow()->activeWindow());
if (!m || !m->isA("MantidMatrix")) return;
MultiLayer* ml = plotSelectedRows(m,false);
MultiLayer* ml = plotSelectedRows(m, MantidQt::DistributionDefault, false);
if (ml) convertToWaterfall(ml);
}

void MantidUI::plotWholeAsWaterfall()
{
const MantidMatrix* const m = dynamic_cast<MantidMatrix*>(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);
}

Expand Down Expand Up @@ -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<int> spec)
{
return plot1D(wsName, spec, false);
return plot1D(wsName, spec, true, MantidQt::DistributionDefault, false);
}

/**
Expand Down Expand Up @@ -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<int>& 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<QString,int> pairs;
Expand All @@ -2990,19 +2991,20 @@ MultiLayer* MantidUI::plot1D(const QStringList& ws_names, const QList<int>& 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<QString, set<int> >& toPlot, bool spectrumPlot, bool errs, bool distr,
MultiLayer* plotWindow, bool clearWindow)
MultiLayer* MantidUI::plot1D(const QMultiMap<QString, set<int> >& 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<QString,int> pairs;
Expand All @@ -3018,21 +3020,21 @@ MultiLayer* MantidUI::plot1D(const QMultiMap<QString, set<int> >& 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<int>& indexList, bool spectrumPlot, bool errs,
bool distr, MultiLayer* plotWindow, bool clearWindow)
MultiLayer* MantidUI::plot1D(const QString& wsName, const std::set<int>& 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<QString,int> pairs;
Expand All @@ -3044,21 +3046,22 @@ MultiLayer* MantidUI::plot1D(const QString& wsName, const std::set<int>& 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<QString,int>& toPlot, bool spectrumPlot, bool errs, bool distr,
Graph::CurveType style, MultiLayer* plotWindow, bool clearWindow)
MultiLayer* MantidUI::plot1D(const QMultiMap<QString,int>& toPlot, bool spectrumPlot,
MantidQt::DistributionFlag distr, bool errs,
Graph::CurveType style, MultiLayer* plotWindow, bool clearWindow)
{
if(toPlot.size() == 0) return NULL;

Expand Down Expand Up @@ -3120,16 +3123,26 @@ MultiLayer* MantidUI::plot1D(const QMultiMap<QString,int>& 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<QString,int>::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&)
Expand Down Expand Up @@ -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,
Expand All @@ -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<int>& rows = m->getSelectedRows();
std::set<int> rowSet(rows.constBegin(),rows.constEnd());

return plot1D(m->workspaceName(),rowSet,true,errs,distr);
return plot1D(m->workspaceName(),rowSet,true,distr, errs);
}

/**
Expand All @@ -3351,10 +3367,11 @@ MultiLayer *MantidUI::plotSelectedColumns(const MantidMatrix * const m, bool err
const QList<int>& cols = m->getSelectedColumns();
std::set<int> 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<int>& bins, bool errs, int fromRow, int toRow)
Table* MantidUI::createTableFromBins(const QString& wsName, Mantid::API::MatrixWorkspace_const_sptr workspace,
const QList<int>& bins, bool errs, int fromRow, int toRow)
{
if (bins.empty()) return NULL;

Expand Down
34 changes: 22 additions & 12 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.h
Expand Up @@ -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 <Poco/NObserver.h>

#include <QDockWidget>
Expand Down Expand Up @@ -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);

Expand All @@ -206,30 +211,35 @@ class MantidUI:public QObject
public slots:
// Create a 1d graph form specified MatrixWorkspace and index
MultiLayer* plot1D(const QStringList& wsnames, const QList<int>& 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<int>& 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<QString,int>& 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<QString,std::set<int> >& 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
MultiLayer* drawSingleColorFillPlot(const QString & wsName, Graph::CurveType curveType = Graph::ColorMap,
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);
Expand Down

0 comments on commit 936ea4f

Please sign in to comment.