From 93bfefb475e822ea0ffdf22020ccb54a57249453 Mon Sep 17 00:00:00 2001
From: Owen Arnold <owen.arnold@stfc.ac.uk>
Date: Wed, 10 Jun 2015 08:56:34 +0100
Subject: [PATCH] refs #11872. Add Peaks Mode.

---
 .../CompositePeaksPresenter.h                 |  5 ++
 .../ConcretePeaksPresenter.h                  |  6 +-
 .../MantidQtSliceViewer/NullPeaksPresenter.h  |  2 +
 .../PeakOverlayMultiSphere.h                  |  6 +-
 .../inc/MantidQtSliceViewer/PeaksPresenter.h  | 11 ++-
 .../ProxyCompositePeaksPresenter.h            |  2 +
 .../src/CompositePeaksPresenter.cpp           | 38 +++++++++-
 .../src/ConcretePeaksPresenter.cpp            | 72 ++++++++++++++++---
 .../src/PeakOverlayMultiSphere.cpp            | 16 ++++-
 .../src/PeakOverlayMultiSphereFactory.cpp     | 24 ++++++-
 .../MantidQt/SliceViewer/src/PeaksViewer.cpp  |  6 +-
 .../src/ProxyCompositePeaksPresenter.cpp      |  5 ++
 .../test/ConcretePeaksPresenterTest.h         | 11 +++
 .../MantidQt/SliceViewer/test/MockObjects.h   |  4 +-
 14 files changed, 184 insertions(+), 24 deletions(-)

diff --git a/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/CompositePeaksPresenter.h b/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/CompositePeaksPresenter.h
index e861d3cdd02..c4d18500102 100644
--- a/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/CompositePeaksPresenter.h
+++ b/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/CompositePeaksPresenter.h
@@ -65,6 +65,7 @@ public:
       boost::shared_ptr<Mantid::API::IPeaksWorkspace> ) { /*Do nothing*/
   }
   virtual bool deletePeaksIn(PeakBoundingBox box);
+  virtual bool addPeakAt(double plotCoordsPointX, double plotCoordsPointY);
 
   /// Constructor
   CompositePeaksPresenter(ZoomablePeaksView *const zoomablePlottingWidget,
@@ -148,6 +149,10 @@ public:
   bool contentsDifferent(PeaksPresenter const * other) const;
   /// Enter the requested edit mode for the peaks workspace.
   void editCommand(EditMode editMode, boost::weak_ptr<const Mantid::API::IPeaksWorkspace> target);
+  /// Can we add peaks to this peaks workspace.
+  bool hasPeakAddModeFor(boost::weak_ptr<const Mantid::API::IPeaksWorkspace> target);
+  /// Can we add peaks
+  bool hasPeakAddMode() const;
 private:
   /// Updateable on demand method.
   void updatePeaksWorkspace(
diff --git a/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/ConcretePeaksPresenter.h b/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/ConcretePeaksPresenter.h
index c7449b78bbd..8b6ef42a7fc 100644
--- a/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/ConcretePeaksPresenter.h
+++ b/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/ConcretePeaksPresenter.h
@@ -58,7 +58,9 @@ public:
   virtual bool isHidden() const;
   virtual bool contentsDifferent(PeaksPresenter const *  other) const;
   virtual void peakEditMode(EditMode mode);
-  virtual bool deletePeaksIn(PeakBoundingBox box);
+  virtual bool deletePeaksIn(PeakBoundingBox plotCoordsBox);
+  virtual bool addPeakAt(double plotCoordsPointX, double plotCoordsPointY);
+  virtual bool hasPeakAddMode() const;
 
 private:
   /// Peak overlay view.
@@ -81,6 +83,8 @@ private:
   bool m_isHidden;
   /// Flag to indicate the current edit mode.
   EditMode m_editMode;
+  /// Can we add to this peaks workspace
+  bool m_hasAddPeaksMode;
 
   /// Configure peak transformations
   bool configureMappingTransform();
diff --git a/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/NullPeaksPresenter.h b/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/NullPeaksPresenter.h
index 59537027869..30acbb69a4c 100644
--- a/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/NullPeaksPresenter.h
+++ b/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/NullPeaksPresenter.h
@@ -54,6 +54,8 @@ public:
 
   void peakEditMode(EditMode){/*Do nothing*/}
   bool deletePeaksIn(PeakBoundingBox){return false;/*Do nothing. Delete nothing.*/}
+  bool addPeakAt(double, double){return false;/*Do nothing. Add nothing.*/}
+  bool hasPeakAddMode() const {return false; /*Do nothing.*/}
 };
 
 }
diff --git a/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/PeakOverlayMultiSphere.h b/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/PeakOverlayMultiSphere.h
index 79241b6cb29..eba0110412c 100644
--- a/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/PeakOverlayMultiSphere.h
+++ b/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/PeakOverlayMultiSphere.h
@@ -147,12 +147,8 @@ namespace SliceViewer
     const QCursor m_defaultCursor;
 
    private slots:
-
     void erasePeaks(const QRect& rect);
-
-
-
-
+    void addPeakAt(int coordX, int coordY);
   };
 
 
diff --git a/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/PeaksPresenter.h b/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/PeaksPresenter.h
index 68a5d187cdf..b31d22617b8 100644
--- a/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/PeaksPresenter.h
+++ b/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/PeaksPresenter.h
@@ -12,6 +12,11 @@
 
 namespace Mantid
 {
+  namespace Kernel{
+    // Forward dec
+    class V3D;
+  }
+
   namespace Geometry {
     // Forward dec.
     class PeakTransform;
@@ -69,10 +74,12 @@ namespace SliceViewer
     virtual void zoomToPeak(const int peakIndex) = 0;
     virtual bool isHidden() const = 0;
     virtual bool contentsDifferent(PeaksPresenter const * other) const = 0;
-    virtual ~PeaksPresenter(){};
     virtual void reInitialize(boost::shared_ptr<Mantid::API::IPeaksWorkspace> peaksWS) = 0;
     virtual void peakEditMode(EditMode mode) = 0;
-    virtual bool deletePeaksIn(PeakBoundingBox box) = 0;
+    virtual bool deletePeaksIn(PeakBoundingBox plotCoordsBox) = 0;
+    virtual bool addPeakAt(double plotCoordsPointX, double plotCoordsPointY) =0;
+    virtual bool hasPeakAddMode() const = 0;
+    virtual ~PeaksPresenter(){};
   };
 
 
diff --git a/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/ProxyCompositePeaksPresenter.h b/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/ProxyCompositePeaksPresenter.h
index 9df243caba2..d6a839578a8 100644
--- a/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/ProxyCompositePeaksPresenter.h
+++ b/Code/Mantid/MantidQt/SliceViewer/inc/MantidQtSliceViewer/ProxyCompositePeaksPresenter.h
@@ -81,6 +81,8 @@ public:
   int getZoomedPeakIndex() const;
   /// Set the edit mode.
   void editCommand(EditMode editMode, boost::weak_ptr<const Mantid::API::IPeaksWorkspace> target);
+  /// Can we add HKL peaks to this workspace.
+  bool hasPeakAddModeFor(boost::weak_ptr<const Mantid::API::IPeaksWorkspace> target);
 
 private:
   /// Wrapped composite to delegate to.
diff --git a/Code/Mantid/MantidQt/SliceViewer/src/CompositePeaksPresenter.cpp b/Code/Mantid/MantidQt/SliceViewer/src/CompositePeaksPresenter.cpp
index 1e0e001bbb3..200ad1d8c22 100644
--- a/Code/Mantid/MantidQt/SliceViewer/src/CompositePeaksPresenter.cpp
+++ b/Code/Mantid/MantidQt/SliceViewer/src/CompositePeaksPresenter.cpp
@@ -13,7 +13,7 @@ CompositePeaksPresenter::CompositePeaksPresenter(
     ZoomablePeaksView *const zoomablePlottingWidget,
     PeaksPresenter_sptr defaultPresenter)
     : m_zoomablePlottingWidget(zoomablePlottingWidget),
-      m_default(defaultPresenter), m_owner(NULL), m_zoomedPeakIndex(-1) {
+      m_default(defaultPresenter), m_owner(NULL), m_zoomedPeakIndex(-1){
   if (m_zoomablePlottingWidget == NULL) {
     throw std::runtime_error("Zoomable Plotting Widget is NULL");
   }
@@ -698,6 +698,42 @@ bool CompositePeaksPresenter::deletePeaksIn(PeakBoundingBox box){
     return result;
 }
 
+bool CompositePeaksPresenter::hasPeakAddModeFor(boost::weak_ptr<const Mantid::API::IPeaksWorkspace> target){
+    bool hasMode  = false;
+    if(auto temp = target.lock()) {
+        auto it = this->getPresenterIteratorFromWorkspace(temp);
+        if(it != m_subjects.end()) {
+            hasMode = (*it)->hasPeakAddMode();
+        }
+    }
+    return hasMode;
+}
+
+bool CompositePeaksPresenter::hasPeakAddMode() const{
+    if (useDefault()) {
+      return m_default->hasPeakAddMode();
+    }
+    // Forward the request onwards
+    bool hasMode = false;
+    for (auto it = m_subjects.begin(); it != m_subjects.end(); ++it) {
+      hasMode |= (*it)->hasPeakAddMode();
+    }
+    return hasMode;
+}
+
+bool CompositePeaksPresenter::addPeakAt(double plotCoordsPointX, double plotCoordsPointY)
+{
+    if (useDefault()) {
+      return m_default->addPeakAt(plotCoordsPointX, plotCoordsPointY);
+    }
+    // Forward the request onwards
+    bool result = false;
+    for (auto it = m_subjects.begin(); it != m_subjects.end(); ++it) {
+      result |= (*it)->addPeakAt(plotCoordsPointX, plotCoordsPointY);
+    }
+    return result;
+}
+
 }
 }
 
diff --git a/Code/Mantid/MantidQt/SliceViewer/src/ConcretePeaksPresenter.cpp b/Code/Mantid/MantidQt/SliceViewer/src/ConcretePeaksPresenter.cpp
index e7a86d4994d..4d4b48f5f62 100644
--- a/Code/Mantid/MantidQt/SliceViewer/src/ConcretePeaksPresenter.cpp
+++ b/Code/Mantid/MantidQt/SliceViewer/src/ConcretePeaksPresenter.cpp
@@ -2,6 +2,8 @@
 #include "MantidQtSliceViewer/PeakEditMode.h"
 #include "MantidQtSliceViewer/UpdateableOnDemand.h"
 #include "MantidQtSliceViewer/ZoomableOnDemand.h"
+#include "MantidKernel/V3D.h"
+#include "MantidAPI/MultipleExperimentInfos.h"
 #include "MantidAPI/IPeaksWorkspace.h"
 #include "MantidGeometry/Crystal/IPeak.h"
 #include "MantidGeometry/Crystal/PeakShape.h"
@@ -54,6 +56,22 @@ std::vector<std::vector<double> > makeVertexesFromBox(const PeakBoundingBox &box
   vertexes[3]=vertex4;
   return vertexes;
 }
+
+/**
+ * Determine if we can add peaks a peaks workspace.
+ * @param peaksWS : To possibly add to
+ * @param frame : Frame of base MDWorkspace
+ * @return True only if we can add to the peaks workspace.
+ */
+bool canAddPeaksTo(IPeaksWorkspace const * const peaksWS,  Mantid::Kernel::SpecialCoordinateSystem frame){
+    /*
+     - PeaksWS Must have an oriented lattice, otherwise we can't add a self-consistent peak.
+     - PeaksWS Must not be integrated, because we have no concept of radius until each individual peak is integrated.
+     - The MDWorkspace must be in the HKL frame otherwise we cannot interpret plot cursor coordinates.
+     */
+    return peaksWS->sample().hasOrientedLattice() && !peaksWS->hasIntegratedPeaks() && frame == HKL;
+}
+
 }
 
 /**
@@ -75,6 +93,7 @@ coordinateToString(Mantid::Kernel::SpecialCoordinateSystem coordSystem) {
   }
 }
 
+
 /**
  * Produce the views for the internally held peaks workspace.
  * Indexes to peaks in the peaks workspace are used to reference the
@@ -161,10 +180,12 @@ ConcretePeaksPresenter::ConcretePeaksPresenter(
     : m_viewFactory(viewFactory), m_peaksWS(peaksWS),
       m_transformFactory(transformFactory),
       m_transform(transformFactory->createDefaultTransform()), m_slicePoint(),
-      m_owningPresenter(NULL), m_isHidden(false), m_editMode(SliceViewer::None) {
+      m_owningPresenter(NULL), m_isHidden(false), m_editMode(SliceViewer::None), m_hasAddPeaksMode(canAddPeaksTo(peaksWS.get(), m_transform->getCoordinateSystem())) {
   // Check that the workspaces appear to be compatible. Log if otherwise.
   checkWorkspaceCompatibilities(mdWS);
 
+
+
   this->initialize();
 }
 
@@ -534,6 +555,7 @@ bool ConcretePeaksPresenter::deletePeaksIn(PeakBoundingBox box) {
       left, right, top, bottom,
       slicePoint /*Use the current slice position, previously unknown.*/);
 
+  // Tranform box from plot coordinates into orderd HKL, Qx,Qy,Qz etc, then find the visible peaks.
   std::vector<size_t> deletionIndexList = findVisiblePeakIndexes(accurateBox);
 
   // If we have things to remove, do that in one-step.
@@ -553,19 +575,53 @@ bool ConcretePeaksPresenter::deletePeaksIn(PeakBoundingBox box) {
     alg->setProperty("Rows", deletionIndexList);
     alg->execute();
 
-    // Refind visible peaks.
-    doFindPeaksInRegion();
-
-    // Reproduce the views.
+    // Reproduce the views. Proxy representations recreated for all peaks.
     this->produceViews();
 
-    // Give the new views the current slice point.
-    m_viewPeaks->setSlicePoint(this->m_slicePoint.slicePoint(),
-                               m_viewablePeaks);
+    // Refind visible peaks and Set the proxy representations to be visible or not.
+    doFindPeaksInRegion();
+
+    // Upstream controls need to be regenerated.
+    this->informOwnerUpdate();
   }
   return !deletionIndexList.empty();
 }
 
+bool ConcretePeaksPresenter::addPeakAt(double plotCoordsPointX, double plotCoordsPointY)
+{
+    V3D plotCoordsPoint(plotCoordsPointX, plotCoordsPointY, m_slicePoint.slicePoint());
+    V3D hkl = m_transform->transformBack(plotCoordsPoint);
+
+    Mantid::API::IPeaksWorkspace_sptr peaksWS =
+        boost::const_pointer_cast<Mantid::API::IPeaksWorkspace>(
+            this->m_peaksWS);
+
+    Mantid::API::IAlgorithm_sptr alg =
+        AlgorithmManager::Instance().create("AddPeakHKL");
+    alg->setChild(true);
+    alg->setRethrows(true);
+    alg->initialize();
+    alg->setProperty("Workspace", peaksWS);
+    alg->setProperty("HKL", std::vector<double>(hkl));
+    alg->execute();
+
+    // Reproduce the views. Proxy representations recreated for all peaks.
+    this->produceViews();
+
+    // Refind visible peaks and Set the proxy representations to be visible or not.
+    doFindPeaksInRegion();
+
+    // Upstream controls need to be regenerated.
+    this->informOwnerUpdate();
+
+    return alg->isExecuted();
+}
+
+bool ConcretePeaksPresenter::hasPeakAddMode() const
+{
+    return m_hasAddPeaksMode;
+}
+
 std::vector<size_t>
 ConcretePeaksPresenter::findVisiblePeakIndexes(const PeakBoundingBox &box) {
   std::vector<size_t> indexes;
diff --git a/Code/Mantid/MantidQt/SliceViewer/src/PeakOverlayMultiSphere.cpp b/Code/Mantid/MantidQt/SliceViewer/src/PeakOverlayMultiSphere.cpp
index c159b2f7095..7f107c89134 100644
--- a/Code/Mantid/MantidQt/SliceViewer/src/PeakOverlayMultiSphere.cpp
+++ b/Code/Mantid/MantidQt/SliceViewer/src/PeakOverlayMultiSphere.cpp
@@ -79,6 +79,18 @@ namespace MantidQt
         return m_plot->canvas()->width();
     }
 
+    void PeakOverlayMultiSphere::addPeakAt(int coordX, int coordY) {
+
+        QwtScaleMap xMap = m_plot->canvasMap(m_plotXIndex);
+        QwtScaleMap yMap = m_plot->canvasMap(m_plotYIndex);
+
+        const double plotX = xMap.invTransform(double(coordX));
+        const double plotY = yMap.invTransform(double(coordY));
+
+        m_presenter->addPeakAt(plotX, plotY);
+    }
+
+
     void PeakOverlayMultiSphere::erasePeaks(const QRect &rect)
     {
         QwtScaleMap xMap = m_plot->canvasMap(m_plotXIndex);
@@ -255,7 +267,9 @@ namespace MantidQt
     void PeakOverlayMultiSphere::peakAdditionMode() {
         QApplication::restoreOverrideCursor();
         auto* temp = m_tool;
-        m_tool = new MantidQt::MantidWidgets::InputControllerPick(this);
+        auto* addTool = new MantidQt::MantidWidgets::InputControllerPick(this);
+        connect(addTool,SIGNAL(pickPointAt(int,int)),this,SLOT(addPeakAt(int,int)));
+        m_tool = addTool;
         delete temp;
     }
 
diff --git a/Code/Mantid/MantidQt/SliceViewer/src/PeakOverlayMultiSphereFactory.cpp b/Code/Mantid/MantidQt/SliceViewer/src/PeakOverlayMultiSphereFactory.cpp
index 0969d819081..9141c0d2a3c 100644
--- a/Code/Mantid/MantidQt/SliceViewer/src/PeakOverlayMultiSphereFactory.cpp
+++ b/Code/Mantid/MantidQt/SliceViewer/src/PeakOverlayMultiSphereFactory.cpp
@@ -1,9 +1,11 @@
 #include "MantidQtSliceViewer/PeakOverlayMultiSphereFactory.h"
 #include "MantidQtSliceViewer/PeakOverlayMultiSphere.h"
 #include "MantidQtSliceViewer/PeaksPresenter.h"
+#include "MantidDataObjects/PeakShapeSpherical.h"
 #include <boost/make_shared.hpp>
 
 using namespace Mantid::API;
+using namespace Mantid::DataObjects;
 
 namespace MantidQt
 {
@@ -18,7 +20,7 @@ namespace MantidQt
         m_peaksWS(peaksWS),
         m_FOM(0)
     {
-      if (m_peaksWS->hasIntegratedPeaks())
+      if (m_peaksWS->hasIntegratedPeaks()) // TODO depends on the shape.
       {
     	  try
     	  {
@@ -54,9 +56,25 @@ namespace MantidQt
       for(size_t i = 0; i < physicalPeaks.size(); ++i)
       {
         const Mantid::Geometry::IPeak& peak = m_peaksWS->getPeak(static_cast<int>(i));
+        const Mantid::Geometry::PeakShape& peakShape = peak.getPeakShape();
         auto position = transform->transformPeak(peak);
-        physicalPeaks[i] = boost::make_shared<PhysicalSphericalPeak>(position, m_peakRadius[i], m_backgroundInnerRadius[i], m_backgroundOuterRadius[i]);
-      }
+        if(const PeakShapeSpherical* sphericalShape = dynamic_cast<const PeakShapeSpherical*>(&peakShape)){
+            auto radius = sphericalShape->radius();
+            auto optOuterRadius = sphericalShape->backgroundOuterRadius();
+            auto optInnerRadius = sphericalShape->backgroundInnerRadius();
+
+            auto outerRadius = optOuterRadius.is_initialized() ? optOuterRadius.get() : radius;
+            auto innerRadius = optInnerRadius.is_initialized() ? optInnerRadius.get() : radius;
+
+            physicalPeaks[i] = boost::make_shared<PhysicalSphericalPeak>(position, radius, innerRadius, outerRadius);
+
+        } else {
+            // This method of doing things is effectivlely deprecated now since we have the PeakShape. I will eventually strip this out.
+            physicalPeaks[i] = boost::make_shared<PhysicalSphericalPeak>(position, m_peakRadius[i], m_backgroundInnerRadius[i], m_backgroundOuterRadius[i]);
+
+        }
+
+       }
 
       // Make the overlay widget.
       return boost::make_shared<PeakOverlayMultiSphere>(presenter, m_plot, m_parent, physicalPeaks, m_plotXIndex, m_plotYIndex, this->m_peakColour, this->m_backColour);
diff --git a/Code/Mantid/MantidQt/SliceViewer/src/PeaksViewer.cpp b/Code/Mantid/MantidQt/SliceViewer/src/PeaksViewer.cpp
index 6568d34bc91..9834d2c3118 100644
--- a/Code/Mantid/MantidQt/SliceViewer/src/PeaksViewer.cpp
+++ b/Code/Mantid/MantidQt/SliceViewer/src/PeaksViewer.cpp
@@ -56,9 +56,10 @@ void PeaksViewer::setPresenter(
     Mantid::API::IPeaksWorkspace_const_sptr ws = *it;
     auto backgroundColour = m_presenter->getBackgroundColour(ws);
     auto foregroundColour = m_presenter->getForegroundColour(ws);
+    bool canAddPeaks = m_presenter->hasPeakAddModeFor(ws);
 
     auto widget = new PeaksWorkspaceWidget(
-        ws, coordinateSystem, foregroundColour, backgroundColour, ws->getSpecialCoordinateSystem() == Mantid::Kernel::HKL ,  this);
+        ws, coordinateSystem, foregroundColour, backgroundColour, canAddPeaks ,  this);
 
     connect(widget, SIGNAL(peakColourChanged(
                         Mantid::API::IPeaksWorkspace_const_sptr, QColor)),
@@ -258,7 +259,6 @@ void PeaksViewer::performUpdate() {
     // Now find the PeaksWorkspaceWidget corresponding to this workspace name.
     QList<PeaksWorkspaceWidget *> children =
         qFindChildren<PeaksWorkspaceWidget *>(this);
-    Mantid::API::IPeaksWorkspace_sptr targetPeaksWorkspace;
     for (int i = 0; i < children.size(); ++i) {
       PeaksWorkspaceWidget *candidateWidget = children.at(i);
       Mantid::API::IPeaksWorkspace_const_sptr candidateWorkspace =
@@ -277,6 +277,8 @@ void PeaksViewer::performUpdate() {
           }
         }
       }
+      // We also update the widget in case the workspace has changed for added/deleted peaks
+      candidateWidget->workspaceUpdate();
     }
   }
 }
diff --git a/Code/Mantid/MantidQt/SliceViewer/src/ProxyCompositePeaksPresenter.cpp b/Code/Mantid/MantidQt/SliceViewer/src/ProxyCompositePeaksPresenter.cpp
index a7eb1927ecc..aa1278d6da7 100644
--- a/Code/Mantid/MantidQt/SliceViewer/src/ProxyCompositePeaksPresenter.cpp
+++ b/Code/Mantid/MantidQt/SliceViewer/src/ProxyCompositePeaksPresenter.cpp
@@ -152,5 +152,10 @@ void ProxyCompositePeaksPresenter::editCommand(EditMode editMode, boost::weak_pt
 {
     m_compositePresenter->editCommand(editMode, target);
 }
+
+bool ProxyCompositePeaksPresenter::hasPeakAddModeFor(boost::weak_ptr<const Mantid::API::IPeaksWorkspace> target){
+    return m_compositePresenter->hasPeakAddModeFor(target);
+}
+
 }
 }
diff --git a/Code/Mantid/MantidQt/SliceViewer/test/ConcretePeaksPresenterTest.h b/Code/Mantid/MantidQt/SliceViewer/test/ConcretePeaksPresenterTest.h
index 8a8f8f46b8d..fb1b5863f6b 100644
--- a/Code/Mantid/MantidQt/SliceViewer/test/ConcretePeaksPresenterTest.h
+++ b/Code/Mantid/MantidQt/SliceViewer/test/ConcretePeaksPresenterTest.h
@@ -234,6 +234,7 @@ public:
     // Create a mock transform object.
     auto pMockTransform = new NiceMock<MockPeakTransform>;
     PeakTransform_sptr mockTransform(pMockTransform);
+    EXPECT_CALL(*pMockTransform, getCoordinateSystem()).WillRepeatedly(Return(Mantid::Kernel::QLab));
 
     // Create a mock transform factory.
     auto pMockTransformFactory = new NiceMock<MockPeakTransformFactory>;
@@ -281,6 +282,7 @@ public:
     auto pMockTransform = new NiceMock<MockPeakTransform>;
     PeakTransform_sptr mockTransform(pMockTransform);
     EXPECT_CALL(*pMockTransform, transformPeak(_)).WillRepeatedly(Return(V3D()));
+    EXPECT_CALL(*pMockTransform, getCoordinateSystem()).WillRepeatedly(Return(Mantid::Kernel::QLab));
 
     // Create a mock transform factory.
     auto pMockTransformFactory = new NiceMock<MockPeakTransformFactory>;
@@ -322,6 +324,7 @@ public:
     // Create a mock transform object.
     auto pMockTransform = new NiceMock<MockPeakTransform>;
     PeakTransform_sptr mockTransform(pMockTransform);
+    EXPECT_CALL(*pMockTransform, getCoordinateSystem()).WillRepeatedly(Return(Mantid::Kernel::HKL));
     EXPECT_CALL(*pMockTransform, getFriendlyName()).WillOnce(Return("HKL"));
     EXPECT_CALL(*pMockTransform, transformPeak(_)).WillRepeatedly(Return(V3D()));
 
@@ -371,6 +374,7 @@ public:
     // Create a mock transform factory.
     auto pMockTransformFactory = new NiceMock<MockPeakTransformFactory>;
     PeakTransformFactory_sptr peakTransformFactory(pMockTransformFactory);
+    EXPECT_CALL(*pMockTransform, getCoordinateSystem()).WillRepeatedly(Return(Mantid::Kernel::QLab));
     EXPECT_CALL(*pMockTransformFactory, createDefaultTransform()).WillOnce(Return(mockTransform));
     EXPECT_CALL(*pMockTransformFactory, createTransform(_,_)).WillOnce(Return(mockTransform));
 
@@ -405,6 +409,7 @@ public:
      // Create a mock transform object.
     auto pMockTransform = new NiceMock<MockPeakTransform>;
     PeakTransform_sptr mockTransform(pMockTransform);
+    EXPECT_CALL(*pMockTransform, getCoordinateSystem()).WillRepeatedly(Return(Mantid::Kernel::QLab));
     EXPECT_CALL(*pMockTransform, transformPeak(_)).WillRepeatedly(Return(V3D()));
 
     // Create a mock transform factory.
@@ -830,8 +835,14 @@ public:
       TSM_ASSERT_EQUALS("No peaks should have been removed yet", 3, peaksWS->getNumberPeaks());
       TSM_ASSERT("Point sits on peak radius. We should delete peak.", presenter->deletePeaksIn(cursorRegion));
       TSM_ASSERT_EQUALS("One peaks should remain", 1, peaksWS->getNumberPeaks());
+  }
 
+  void test_haspeakaddmode(){
+      auto builder = createStandardBuild(5/*N Peaks*/, 1.0/*radius*/, QLab /*CHOSEN FRAME*/);
+      ConcretePeaksPresenter_sptr concretePeaksPresenter = builder.create();
+      TSM_ASSERT("No peak add mode. As is not in the HKL frame", !concretePeaksPresenter->hasPeakAddMode());
   }
+
 };
 
 
diff --git a/Code/Mantid/MantidQt/SliceViewer/test/MockObjects.h b/Code/Mantid/MantidQt/SliceViewer/test/MockObjects.h
index 53a2bf803a9..1a5a50c4feb 100644
--- a/Code/Mantid/MantidQt/SliceViewer/test/MockObjects.h
+++ b/Code/Mantid/MantidQt/SliceViewer/test/MockObjects.h
@@ -67,7 +67,9 @@ namespace
     MOCK_CONST_METHOD1(contentsDifferent,
           bool(const PeaksPresenter*  other));
     MOCK_METHOD1(deletePeaksIn, bool(PeakBoundingBox));
-    MOCK_METHOD1(peakEditMode, void(EditMode mode));
+    MOCK_METHOD1(peakEditMode, void(EditMode));
+    MOCK_METHOD2(addPeakAt, bool(double, double));
+    MOCK_CONST_METHOD0(hasPeakAddMode, bool());
     virtual ~MockPeaksPresenter(){}
   };
 
-- 
GitLab