From 09906e9b96eecb05fefd45e6711573a3fe71937f Mon Sep 17 00:00:00 2001
From: Lamar Moore <lamar.moore@stfc.ac.uk>
Date: Wed, 19 Sep 2018 12:21:01 +0100
Subject: [PATCH] Fix broken unit tests #23073

---
 .../test/ResizeRectangularDetectorTest.h         |  8 ++++----
 .../DataHandling/src/MoveInstrumentComponent.cpp |  8 ++++----
 .../DataHandling/test/LoadIDFFromNexusTest.h     |  2 +-
 Framework/Geometry/src/Instrument.cpp            | 16 ++++++++--------
 .../Geometry/src/Instrument/ComponentInfo.cpp    |  6 +++++-
 .../src/Instrument/ParComponentFactory.cpp       |  4 ++--
 .../src/Instrument/RectangularDetector.cpp       |  2 +-
 7 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/Framework/Algorithms/test/ResizeRectangularDetectorTest.h b/Framework/Algorithms/test/ResizeRectangularDetectorTest.h
index 615951f4318..61ecad7f8be 100644
--- a/Framework/Algorithms/test/ResizeRectangularDetectorTest.h
+++ b/Framework/Algorithms/test/ResizeRectangularDetectorTest.h
@@ -6,8 +6,8 @@
 #include "MantidAlgorithms/ResizeRectangularDetector.h"
 #include "MantidDataObjects/EventWorkspace.h"
 #include "MantidGeometry/Instrument.h"
+#include "MantidGeometry/Instrument/GridDetectorPixel.h"
 #include "MantidGeometry/Instrument/RectangularDetector.h"
-#include "MantidGeometry/Instrument/RectangularDetectorPixel.h"
 #include "MantidKernel/System.h"
 #include "MantidKernel/Timer.h"
 #include "MantidKernel/V3D.h"
@@ -58,11 +58,11 @@ public:
     TS_ASSERT_DELTA(det->xstep(), 0.008 * 2, 1e-6);
 
     // Check that accessing through spectrumInfo.detector() also works
-    const RectangularDetectorPixel *recDetPix;
+    const GridDetectorPixel *recDetPix;
     const auto &spectrumInfo = ws->spectrumInfo();
     const auto &pixel = spectrumInfo.detector(11);
-    recDetPix = dynamic_cast<const RectangularDetectorPixel *>(
-        det->getAtXY(1, 1).get());
+    recDetPix =
+        dynamic_cast<const GridDetectorPixel *>(det->getAtXY(1, 1).get());
     TSM_ASSERT("getDetector() returns a RectangularDetectorPixel", recDetPix);
     pos = pixel.getPos();
     TS_ASSERT_EQUALS(pos, V3D(0.008 * 2, 0.008 * 0.5, 5.0));
diff --git a/Framework/DataHandling/src/MoveInstrumentComponent.cpp b/Framework/DataHandling/src/MoveInstrumentComponent.cpp
index 2129c287ec5..8f9ccf029d4 100644
--- a/Framework/DataHandling/src/MoveInstrumentComponent.cpp
+++ b/Framework/DataHandling/src/MoveInstrumentComponent.cpp
@@ -2,7 +2,7 @@
 #include "MantidDataObjects/PeaksWorkspace.h"
 #include "MantidDataObjects/Workspace2D.h"
 #include "MantidGeometry/Instrument/ComponentInfo.h"
-#include "MantidGeometry/Instrument/RectangularDetectorPixel.h"
+#include "MantidGeometry/Instrument/GridDetectorPixel.h"
 #include "MantidKernel/Exception.h"
 
 namespace Mantid {
@@ -106,10 +106,10 @@ void MoveInstrumentComponent::exec() {
     throw std::invalid_argument("DetectorID or ComponentName must be given.");
   }
 
-  if (dynamic_cast<const Geometry::RectangularDetectorPixel *>(comp.get())) {
+  if (dynamic_cast<const Geometry::GridDetectorPixel *>(comp.get())) {
     // DetectorInfo makes changing positions possible but we keep the old
-    // behavior of ignoring position changes for RectangularDetectorPixel.
-    g_log.warning("Component is a RectangularDetectorPixel, moving is not "
+    // behavior of ignoring position changes for GridDetectorPixel.
+    g_log.warning("Component is a GridDetectorPixel, moving is not "
                   "possible, doing nothing.");
     return;
   }
diff --git a/Framework/DataHandling/test/LoadIDFFromNexusTest.h b/Framework/DataHandling/test/LoadIDFFromNexusTest.h
index 54d3e394a9c..756ce77ca97 100644
--- a/Framework/DataHandling/test/LoadIDFFromNexusTest.h
+++ b/Framework/DataHandling/test/LoadIDFFromNexusTest.h
@@ -98,7 +98,7 @@ public:
     const auto &ptrDetMain = detectorInfo.detector(detectorInfo.indexOf(5));
     TS_ASSERT_EQUALS(ptrDetMain.getID(), 5);
     TS_ASSERT_EQUALS(ptrDetMain.getName(), "main-detector-bank(2,0)");
-    TS_ASSERT_EQUALS(ptrDetMain.type(), "RectangularDetectorPixel");
+    TS_ASSERT_EQUALS(ptrDetMain.type(), "GridDetectorPixel");
     TS_ASSERT_DELTA(ptrDetMain.getPos().X(), -0.3035, 0.0001);
     TS_ASSERT_DELTA(ptrDetMain.getPos().Y(), -0.3124, 0.0001);
     TS_ASSERT_DELTA(detectorInfo.l2(detectorInfo.indexOf(5)), 4.1727, 0.0001);
diff --git a/Framework/Geometry/src/Instrument.cpp b/Framework/Geometry/src/Instrument.cpp
index 45a381c5ab3..6b37c1bd5aa 100644
--- a/Framework/Geometry/src/Instrument.cpp
+++ b/Framework/Geometry/src/Instrument.cpp
@@ -4,10 +4,10 @@
 #include "MantidGeometry/Instrument/ComponentInfo.h"
 #include "MantidGeometry/Instrument/DetectorGroup.h"
 #include "MantidGeometry/Instrument/DetectorInfo.h"
+#include "MantidGeometry/Instrument/GridDetectorPixel.h"
 #include "MantidGeometry/Instrument/InstrumentVisitor.h"
 #include "MantidGeometry/Instrument/ParComponentFactory.h"
 #include "MantidGeometry/Instrument/RectangularDetector.h"
-#include "MantidGeometry/Instrument/RectangularDetectorPixel.h"
 #include "MantidGeometry/Instrument/ReferenceFrame.h"
 #include "MantidKernel/EigenConversionHelpers.h"
 #include "MantidKernel/Exception.h"
@@ -1288,7 +1288,7 @@ boost::shared_ptr<ParameterMap> Instrument::makeLegacyParameterMap() const {
 
     const int64_t parentIndex = componentInfo.parent(i);
     const bool makeTransform = parentIndex != oldParentIndex;
-    bool isRectangularDetectorPixel = false;
+    bool isGridDetectorPixel = false;
 
     if (makeTransform) {
       oldParentIndex = parentIndex;
@@ -1305,15 +1305,15 @@ boost::shared_ptr<ParameterMap> Instrument::makeLegacyParameterMap() const {
       const boost::shared_ptr<const IDetector> &baseDet =
           std::get<1>(baseInstr.m_detectorCache[i]);
 
-      isRectangularDetectorPixel = bool(
-          boost::dynamic_pointer_cast<const RectangularDetectorPixel>(baseDet));
+      isGridDetectorPixel =
+          bool(boost::dynamic_pointer_cast<const GridDetectorPixel>(baseDet));
       if (detectorInfo.isMasked(i)) {
         pmap->forceUnsafeSetMasked(baseDet.get(), true);
       }
 
       if (makeTransform) {
-        // Special case: scaling for RectangularDetectorPixel.
-        if (isRectangularDetectorPixel) {
+        // Special case: scaling for GridDetectorPixel.
+        if (isGridDetectorPixel) {
 
           size_t panelIndex = componentInfo.parent(parentIndex);
           const auto panelID = componentInfo.componentID(panelIndex);
@@ -1347,9 +1347,9 @@ boost::shared_ptr<ParameterMap> Instrument::makeLegacyParameterMap() const {
 
     // Tolerance 1e-9 m as in Beamline::DetectorInfo::isEquivalent.
     if ((relPos - toVector3d(baseComponent->getRelativePos())).norm() >= 1e-9) {
-      if (isRectangularDetectorPixel) {
+      if (isGridDetectorPixel) {
         throw std::runtime_error("Cannot create legacy ParameterMap: Position "
-                                 "parameters for RectangularDetectorPixel are "
+                                 "parameters for GridDetectorPixel are "
                                  "not supported");
       }
       pmap->addV3D(componentId, ParameterMap::pos(), Kernel::toV3D(relPos));
diff --git a/Framework/Geometry/src/Instrument/ComponentInfo.cpp b/Framework/Geometry/src/Instrument/ComponentInfo.cpp
index 0e34702706f..ffc664a6598 100644
--- a/Framework/Geometry/src/Instrument/ComponentInfo.cpp
+++ b/Framework/Geometry/src/Instrument/ComponentInfo.cpp
@@ -387,7 +387,11 @@ BoundingBox ComponentInfo::boundingBox(const size_t componentIndex,
 
   BoundingBox absoluteBB;
   const auto compFlag = componentType(componentIndex);
-  const auto parentFlag = componentType(parent(componentIndex));
+
+  auto parentFlag = Beamline::ComponentType::Generic;
+  if (size() > 1)
+    parentFlag = componentType(parent(componentIndex));
+
   if (hasSource() && componentIndex == source()) {
     // Do nothing. Source is not considered part of the beamline for bounding
     // box calculations.
diff --git a/Framework/Geometry/src/Instrument/ParComponentFactory.cpp b/Framework/Geometry/src/Instrument/ParComponentFactory.cpp
index 63ac830ce3f..79971990683 100644
--- a/Framework/Geometry/src/Instrument/ParComponentFactory.cpp
+++ b/Framework/Geometry/src/Instrument/ParComponentFactory.cpp
@@ -3,10 +3,10 @@
 #include "MantidGeometry/Instrument/CompAssembly.h"
 #include "MantidGeometry/Instrument/Component.h"
 #include "MantidGeometry/Instrument/Detector.h"
+#include "MantidGeometry/Instrument/GridDetectorPixel.h"
 #include "MantidGeometry/Instrument/ObjCompAssembly.h"
 #include "MantidGeometry/Instrument/ObjComponent.h"
 #include "MantidGeometry/Instrument/RectangularDetector.h"
-#include "MantidGeometry/Instrument/RectangularDetectorPixel.h"
 #include "MantidGeometry/Instrument/StructuredDetector.h"
 #include <boost/make_shared.hpp>
 
@@ -24,7 +24,7 @@ namespace Geometry {
 boost::shared_ptr<IDetector>
 ParComponentFactory::createDetector(const IDetector *base,
                                     const ParameterMap *map) {
-  // Clone may be a Detector or RectangularDetectorPixel instance (or nullptr)
+  // Clone may be a Detector or GridDetectorPixel instance (or nullptr)
   auto clone = base->cloneParameterized(map);
   return boost::shared_ptr<IDetector>(clone);
 }
diff --git a/Framework/Geometry/src/Instrument/RectangularDetector.cpp b/Framework/Geometry/src/Instrument/RectangularDetector.cpp
index 42db9ece6eb..6a4d1b96041 100644
--- a/Framework/Geometry/src/Instrument/RectangularDetector.cpp
+++ b/Framework/Geometry/src/Instrument/RectangularDetector.cpp
@@ -179,7 +179,7 @@ void RectangularDetector::initialize(boost::shared_ptr<IObject> shape,
                                      int idstepbyrow, int idstep) {
 
   GridDetector::initialize(
-      shape, xpixels, xstart, ystep, ypixels, ystart, ystep, 0, 0, 0, idstart,
+      shape, xpixels, xstart, xstep, ypixels, ystart, ystep, 0, 0, 0, idstart,
       idfillbyfirst_y ? "yxz" : "xyz", idstepbyrow, idstep);
 }
 
-- 
GitLab