From 4d1f96f461b82f8ebe8a7ad37ecd04aff6f8619c Mon Sep 17 00:00:00 2001
From: Michael Reuter <reuterma@ornl.gov>
Date: Mon, 19 Mar 2012 16:19:14 -0400
Subject: [PATCH] Refs #4988. Disallow more than one MDWorkspace on
 SplatterPlot.

---
 .../SplatterPlotView.h                        |  1 +
 .../ViewWidgets/src/SplatterPlotView.cpp      | 24 +++++++++++++++++--
 .../ViewWidgets/src/ViewBase.cpp              |  5 ++++
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/SplatterPlotView.h b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/SplatterPlotView.h
index cd78425c35c..4a175586334 100644
--- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/SplatterPlotView.h
+++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/SplatterPlotView.h
@@ -98,6 +98,7 @@ private:
   /// Destroy all peak sources.
   void destroyPeakSources();
 
+  bool noOverlay; ///< Flag to respond to overlay situation correctly
   QList<QPointer<pqPipelineSource> > peaksSource; ///< A list of peaks sources
   QPointer<pqPipelineRepresentation> splatRepr; ///< The splatter plot representation
   QPointer<pqPipelineSource> splatSource; ///< The splatter plot source
diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/SplatterPlotView.cpp b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/SplatterPlotView.cpp
index 066ed485869..a0c511c0262 100644
--- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/SplatterPlotView.cpp
+++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/SplatterPlotView.cpp
@@ -11,6 +11,8 @@
 #include "vtkProperty.h"
 #include "vtkSMPropertyHelper.h"
 
+#include <QMessageBox>
+
 namespace Mantid
 {
 namespace Vates
@@ -20,6 +22,7 @@ namespace SimpleGui
 
 SplatterPlotView::SplatterPlotView(QWidget *parent) : ViewBase(parent)
 {
+  this->noOverlay = false;
   this->ui.setupUi(this);
 
   // Set the threshold button to create a threshold filter on data
@@ -62,9 +65,25 @@ void SplatterPlotView::render()
   pqPipelineSource *src = NULL;
   src = pqActiveObjects::instance().activeSource();
 
-  int renderType = VTK_SURFACE;
   pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder();
 
+  // Do not allow overplotting of MDWorkspaces
+  if (!this->isPeaksWorkspace(src) && NULL != this->splatSource)
+  {
+    QMessageBox::warning(this, QApplication::tr("Overplotting Warning"),
+                         QApplication::tr("SplatterPlot mode does not allow "\
+                                          "more that one MDEventWorkspace to "\
+                                          "be plotted."));
+    // Need to destroy source since we tried to load it and set the active
+    // back to something. In this case we'll choose the splatter plot filter.
+    builder->destroy(src);
+    pqActiveObjects::instance().setActiveSource(this->splatSource);
+    this->noOverlay = true;
+    return;
+  }
+
+  int renderType = VTK_SURFACE;
+
   if (!this->isPeaksWorkspace(src))
   {
     this->origSrc = src;
@@ -120,10 +139,11 @@ void SplatterPlotView::onThresholdButtonClicked()
 
 void SplatterPlotView::checkView()
 {
-  if (this->peaksSource.isEmpty())
+  if (!this->noOverlay && this->peaksSource.isEmpty())
   {
     ViewBase::checkView();
   }
+  this->noOverlay = false;
 }
 
 void SplatterPlotView::resetCamera()
diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp
index 76721dd953f..ac4ff0bfd2e 100644
--- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp
+++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp
@@ -298,6 +298,11 @@ unsigned int ViewBase::getNumSources()
  */
 void ViewBase::handleTimeInfo(vtkSMDoubleVectorProperty *dvp, bool doUpdate)
 {
+  if (NULL == dvp)
+  {
+    // This is a normal filter and therefore has no timesteps.
+    return;
+  }
   const int numTimesteps = static_cast<int>(dvp->GetNumberOfElements());
   if (0 != numTimesteps)
   {
-- 
GitLab