diff --git a/MantidPlot/pymantidplot/__init__.py b/MantidPlot/pymantidplot/__init__.py index f77ce7c983d7da2f2fb6446947c212e40fcbedd5..3ea6a0189f54e0505309f7f71b712aba68fe14c9 100644 --- a/MantidPlot/pymantidplot/__init__.py +++ b/MantidPlot/pymantidplot/__init__.py @@ -300,7 +300,9 @@ def plotMD(source, plot_axis=-2, normalization=DEFAULT_MD_NORMALIZATION, error_b Args: source: Workspace(s) to plot plot_axis: Index of the plot axis (defaults to auto-select) - normalization: Type of normalization required (defaults to volume) + normalization: Type of normalization required (defaults to volume, options available: + MDNormalization.NoNormalization, MDNormalization.NumEventsNormalization, and + MDNormalization.VolumeNormalization). error_bars: Flag for error bar plotting. window: window used for plotting. If None a new one will be created clearWindow: if is True, the window specified will be cleared before adding new curve diff --git a/MantidPlot/src/ApplicationWindow.cpp b/MantidPlot/src/ApplicationWindow.cpp index d9455438c81ff03c2f0516cc79f00b0934b5c201..3fa69dd633f1932060d53fc279973fe2ed4731c0 100644 --- a/MantidPlot/src/ApplicationWindow.cpp +++ b/MantidPlot/src/ApplicationWindow.cpp @@ -10153,6 +10153,7 @@ void ApplicationWindow::showGraphContextMenu() { QMenu axes(this); QMenu colour(this); QMenu normalization(this); + QMenu normMD(this); QMenu exports(this); QMenu copy(this); QMenu prints(this); @@ -10218,6 +10219,27 @@ void ApplicationWindow::showGraphContextMenu() { noNorm->setChecked(!ag->isDistribution()); binNorm->setChecked(ag->isDistribution()); cm.insertItem(tr("&Normalization"), &normalization); + } else if (ag->normalizableMD()) { + QAction *noNormMD = new QAction(tr("N&one"), &normMD); + noNormMD->setCheckable(true); + connect(noNormMD, SIGNAL(activated()), ag, SLOT(noNormalizationMD())); + normMD.addAction(noNormMD); + + QAction *volNormMD = new QAction(tr("&Volume"), &normMD); + volNormMD->setCheckable(true); + connect(volNormMD, SIGNAL(activated()), ag, SLOT(volumeNormalizationMD())); + normMD.addAction(volNormMD); + + QAction *eventsNormMD = new QAction(tr("&Events"), &normMD); + eventsNormMD->setCheckable(true); + connect(eventsNormMD, SIGNAL(activated()), ag, SLOT(numEventsNormalizationMD())); + normMD.addAction(eventsNormMD); + + int normalization = ag->normalizationMD(); + noNormMD->setChecked(0 == normalization); + volNormMD->setChecked(1 == normalization); + eventsNormMD->setChecked(2 == normalization); + cm.insertItem("MD &Normalization", &normMD); } QMenu plotType(this); diff --git a/MantidPlot/src/Graph.cpp b/MantidPlot/src/Graph.cpp index f147c078e4ad2bfb4bfa4d86e70023fb3ff7fd4c..b90d59c0c2ba39d003eb0589957f4663b3ab805e 100644 --- a/MantidPlot/src/Graph.cpp +++ b/MantidPlot/src/Graph.cpp @@ -60,6 +60,7 @@ #include "MantidAPI/AnalysisDataService.h" #include "Mantid/MantidMatrixCurve.h" +#include "Mantid/MantidMDCurve.h" #include "MantidQtAPI/PlotAxis.h" #include "MantidQtAPI/QwtRasterDataMD.h" #include "MantidQtAPI/QwtWorkspaceSpectrumData.h" @@ -209,6 +210,9 @@ Graph::Graph(int x, int y, int width, int height, QWidget* parent, Qt::WFlags f) m_isDistribution = false; m_normalizable = false; + + m_normalizableMD = false; + m_normalizationMD = 0; } void Graph::notifyChanges() @@ -3412,12 +3416,15 @@ QString Graph::yAxisTitleFromFirstCurve() using namespace Mantid::API; QString wsName = firstCurve->workspaceName(); auto ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(wsName.toStdString()); - return MantidQt::API::PlotAxis(m_isDistribution, *ws).title(); - } - else - { - return axisTitle(0); + if (ws) + return MantidQt::API::PlotAxis(m_isDistribution, *ws).title(); + } else if (auto *firstCurve = dynamic_cast<MantidMDCurve*>(curve(0))) { + MantidQwtIMDWorkspaceData* data = firstCurve->mantidData(); + if (data) + return data->getYAxisLabel(); } + + return axisTitle(0); } void Graph::contextMenuEvent(QContextMenuEvent *e) @@ -5520,9 +5527,9 @@ void Graph::noNormalization() if(!m_isDistribution) return; // Nothing to do m_isDistribution = false; - updateDataCurves(); - d_plot->updateAxes(); - setYAxisTitle(yAxisTitleFromFirstCurve()); + + updateCurvesAndAxes(); + notifyChanges(); } @@ -5534,11 +5541,65 @@ void Graph::binWidthNormalization() if(m_isDistribution) return; // Nothing to do m_isDistribution = true; + + updateCurvesAndAxes(); + + notifyChanges(); +} + +/** + * Set 'None' normalization for MD plots + */ +void Graph::noNormalizationMD() +{ + if (!normalizableMD()) + return; + + setNormalizationMD(0); + + updateCurvesAndAxes(); + + notifyChanges(); +} + +/** + * Set volume normalization for MD plots + */ +void Graph::volumeNormalizationMD() +{ + if (!normalizableMD()) + return; + + setNormalizationMD(1); + + updateCurvesAndAxes(); + + notifyChanges(); +} + +/** + * Set number of events normalization for MD plots + */ +void Graph::numEventsNormalizationMD() +{ + if (!normalizableMD()) + return; + + setNormalizationMD(2); + + updateCurvesAndAxes(); + + notifyChanges(); +} + +/** + * Convenience method to use when updating the normalization types + * (whether Matrix or MD data normalizatio). + */ +void Graph::updateCurvesAndAxes() { updateDataCurves(); d_plot->updateAxes(); setYAxisTitle(yAxisTitleFromFirstCurve()); - - notifyChanges(); } void Graph::setWaterfallXOffset(int offset) @@ -5654,6 +5715,15 @@ void Graph::updateDataCurves() mc->invalidateBoundingRect(); mc->loadData(); } + else if (MantidMDCurve *mdc = dynamic_cast<MantidMDCurve*>(pc)) + { + //mdc->setDrawAsDistribution(m_isDistribution); + // yes, using int in Graph and ApplicationWindow instead of the proper enum, just so that + // IMDWorkspace.h does not need to be included in more places in MantidPlot + mdc->mantidData()->setNormalization(static_cast<Mantid::API::MDNormalization>(m_normalizationMD)); + mdc->invalidateBoundingRect(); + } + } QApplication::restoreOverrideCursor(); } diff --git a/MantidPlot/src/Graph.h b/MantidPlot/src/Graph.h index 9512139404943318a36ffc5dc9fa343d9fc82d7d..34ae08f03ca7eacf89224cf0b37a0bffcc81b19d 100644 --- a/MantidPlot/src/Graph.h +++ b/MantidPlot/src/Graph.h @@ -209,6 +209,20 @@ public slots: bool isDistribution() const { return m_isDistribution; } void setDistribution(const bool on) { m_isDistribution = on; } + void noNormalizationMD(); + void numEventsNormalizationMD(); + void volumeNormalizationMD(); + + /// normalizable in the MD sense, don't confuse with (bin width) normalizable(), + /// True if this is a plot MD + bool normalizableMD() const { return m_normalizableMD; } + void setNormalizableMD(const bool on) { m_normalizableMD = on; } + + /// when using MD curves (true == normalizbleMD()), what type of normalization + int normalizationMD() const { return m_normalizationMD; } + void setNormalizationMD(const int normalization) { m_normalizationMD = normalization; } + + //! Accessor method for #d_plot. Plot* plotWidget(){return d_plot;}; @@ -813,6 +827,8 @@ private: QString yAxisTitleFromFirstCurve(); + void updateCurvesAndAxes(); + Plot *d_plot; QwtPlotZoomer *d_zoomer[2]; TitlePicker *titlePicker; @@ -877,6 +893,12 @@ private: bool m_isDistribution; // True, if the graph can be plotted as distribution bool m_normalizable; + + // True if the graph is an MD plot and can be normalized (none, volume, events) + bool m_normalizableMD; + /// type of normalization for MD curves + int m_normalizationMD; + // x and y units of MantidCurves boost::shared_ptr<Mantid::Kernel::Unit> m_xUnits; boost::shared_ptr<Mantid::Kernel::Unit> m_yUnits; diff --git a/MantidPlot/src/Mantid/MantidUI.cpp b/MantidPlot/src/Mantid/MantidUI.cpp index d076bdf157480feeeb4f10b4ff922a8c1a7c90e4..f6ddf9efda70d0a46db18176e62f79426ebffe43 100644 --- a/MantidPlot/src/Mantid/MantidUI.cpp +++ b/MantidPlot/src/Mantid/MantidUI.cpp @@ -617,6 +617,9 @@ MultiLayer* MantidUI::plotMDList(const QStringList& wsNames, const int plotAxis, data->setPlotAxisChoice(plotAxis); data->setNormalization(normalization); + g->setNormalizableMD(true); + g->setNormalizationMD(normalization); + // Using information from the first graph if( i == 0 && isGraphNew ) g->setAutoScale();