From 8cfbdfa77fb3d65b47c89b417a3204ff3b10e27c Mon Sep 17 00:00:00 2001
From: Anton Piccardo-Selg <anton.piccardo-selg@tessella.com>
Date: Thu, 8 Oct 2015 16:06:14 +0100
Subject: [PATCH] Refs #13872 Added UnknownFrame

---
 Framework/Geometry/CMakeLists.txt             |  2 +
 .../MDGeometry/MDFrameFactory.h               | 11 ++++
 .../MDGeometry/MDHistoDimension.h             |  4 +-
 .../MantidGeometry/MDGeometry/UnknownFrame.h  | 51 +++++++++++++++++++
 .../src/MDGeometry/MDFrameFactory.cpp         | 30 +++++++++--
 .../Geometry/src/MDGeometry/UnknownFrame.cpp  | 18 +++++++
 Framework/Geometry/test/MDFrameFactoryTest.h  | 17 ++++---
 Framework/Geometry/test/QLabTest.h            |  6 +--
 Framework/Geometry/test/QSampleTest.h         |  6 +--
 Framework/MDAlgorithms/src/LoadMD.cpp         |  3 +-
 10 files changed, 129 insertions(+), 19 deletions(-)
 create mode 100644 Framework/Geometry/inc/MantidGeometry/MDGeometry/UnknownFrame.h
 create mode 100644 Framework/Geometry/src/MDGeometry/UnknownFrame.cpp

diff --git a/Framework/Geometry/CMakeLists.txt b/Framework/Geometry/CMakeLists.txt
index 646e3bced03..ed3948fe974 100644
--- a/Framework/Geometry/CMakeLists.txt
+++ b/Framework/Geometry/CMakeLists.txt
@@ -74,6 +74,7 @@ set ( SRC_FILES
 	src/MDGeometry/NullImplicitFunction.cpp
 	src/MDGeometry/QLab.cpp
 	src/MDGeometry/QSample.cpp
+	src/MDGeometry/UnknownFrame.cpp
 	src/Math/Acomp.cpp
 	src/Math/Algebra.cpp
 	src/Math/BnId.cpp
@@ -217,6 +218,7 @@ set ( INC_FILES
 	inc/MantidGeometry/MDGeometry/NullImplicitFunction.h
 	inc/MantidGeometry/MDGeometry/QLab.h
 	inc/MantidGeometry/MDGeometry/QSample.h
+	inc/MantidGeometry/MDGeometry/UnknownFrame.h
 	inc/MantidGeometry/Math/Acomp.h
 	inc/MantidGeometry/Math/Algebra.h
 	inc/MantidGeometry/Math/BnId.h
diff --git a/Framework/Geometry/inc/MantidGeometry/MDGeometry/MDFrameFactory.h b/Framework/Geometry/inc/MantidGeometry/MDGeometry/MDFrameFactory.h
index b42e611109f..bf09984478c 100644
--- a/Framework/Geometry/inc/MantidGeometry/MDGeometry/MDFrameFactory.h
+++ b/Framework/Geometry/inc/MantidGeometry/MDGeometry/MDFrameFactory.h
@@ -7,6 +7,7 @@
 #include "MantidGeometry/MDGeometry/QLab.h"
 #include "MantidGeometry/MDGeometry/QSample.h"
 #include "MantidGeometry/MDGeometry/HKL.h"
+#include "MantidGeometry/MDGeometry/UnknownFrame.h"
 #include "MantidGeometry/DllConfig.h"
 #include <memory>
 
@@ -98,6 +99,16 @@ public:
   bool canInterpret(const MDFrameArgument &argument) const;
 };
 
+/// Unknown Frame derived MDFrameFactory type
+class MANTID_GEOMETRY_DLL UnknownFrameFactory : public MDFrameFactory {
+private:
+  UnknownFrame *createRaw(const MDFrameArgument &argument) const;
+
+public:
+  bool canInterpret(const MDFrameArgument &argument) const;
+};
+
+
 /// Make a complete factory chain
 MDFrameFactory_uptr MANTID_GEOMETRY_DLL makeMDFrameFactoryChain();
 
diff --git a/Framework/Geometry/inc/MantidGeometry/MDGeometry/MDHistoDimension.h b/Framework/Geometry/inc/MantidGeometry/MDGeometry/MDHistoDimension.h
index d51620b258a..baf7a07bbc9 100644
--- a/Framework/Geometry/inc/MantidGeometry/MDGeometry/MDHistoDimension.h
+++ b/Framework/Geometry/inc/MantidGeometry/MDGeometry/MDHistoDimension.h
@@ -5,7 +5,7 @@
 #include "MantidKernel/Exception.h"
 #include "MantidGeometry/MDGeometry/IMDDimension.h"
 #include "MantidGeometry/MDGeometry/MDFrame.h"
-#include "MantidGeometry/MDGeometry/GeneralFrame.h"
+#include "MantidGeometry/MDGeometry/UnknownFrame.h"
 #include "MantidKernel/MDUnit.h"
 #include "MantidKernel/MDUnitFactory.h"
 #include "MantidKernel/VMD.h"
@@ -35,7 +35,7 @@ public:
                    const Kernel::UnitLabel &units, coord_t min, coord_t max,
                    size_t numBins)
       : m_name(name), m_dimensionId(ID),
-        m_frame(new GeneralFrame("Unknown frame", units)), m_min(min),
+        m_frame(new UnknownFrame("Unknown frame", units)), m_min(min),
         m_max(max), m_numBins(numBins),
         m_binWidth((max - min) / static_cast<coord_t>(numBins)) {
     if (max < min) {
diff --git a/Framework/Geometry/inc/MantidGeometry/MDGeometry/UnknownFrame.h b/Framework/Geometry/inc/MantidGeometry/MDGeometry/UnknownFrame.h
new file mode 100644
index 00000000000..e067c165eba
--- /dev/null
+++ b/Framework/Geometry/inc/MantidGeometry/MDGeometry/UnknownFrame.h
@@ -0,0 +1,51 @@
+#ifndef MANTID_GEOMETRY_UNKNOWN_H_
+#define MANTID_GEOMETRY_UNKNOWN_H_
+
+#include "MantidKernel/MDUnit.h"
+#include "MantidKernel/System.h"
+#include "MantidKernel/UnitLabel.h"
+#include "MantidGeometry/MDGeometry/GeneralFrame.h"
+#include "MantidGeometry/DllConfig.h"
+#include <memory>
+
+namespace Mantid {
+namespace Geometry {
+
+/** UnknownFrame : Unknown MDFrame
+
+  Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
+  National Laboratory & European Spallation Source
+
+  This file is part of Mantid.
+
+  Mantid is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  Mantid is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+  File change history is stored at: <https://github.com/mantidproject/mantid>
+  Code Documentation is available at: <http://doxygen.mantidproject.org>
+*/
+class MANTID_GEOMETRY_DLL UnknownFrame : public GeneralFrame {
+public:
+  UnknownFrame(const std::string &frameName, const Kernel::UnitLabel &unit);
+  UnknownFrame(const std::string &frameName,
+               std::unique_ptr<Mantid::Kernel::MDUnit> unit);
+  virtual ~UnknownFrame();
+
+  // Type name
+  static const std::string UnknownFrameName;
+};
+
+} // namespace Geometry
+} // namespace Mantid
+
+#endif /* MANTID_GEOMETRY_QLAB_H_ */
diff --git a/Framework/Geometry/src/MDGeometry/MDFrameFactory.cpp b/Framework/Geometry/src/MDGeometry/MDFrameFactory.cpp
index d3f58ceb35d..692a4d8ed43 100644
--- a/Framework/Geometry/src/MDGeometry/MDFrameFactory.cpp
+++ b/Framework/Geometry/src/MDGeometry/MDFrameFactory.cpp
@@ -19,8 +19,12 @@ GeneralFrameFactory::createRaw(const MDFrameArgument &argument) const {
 }
 
 /// Indicate an ability to intepret the string
-bool GeneralFrameFactory::canInterpret(const MDFrameArgument &) const {
-  return true; // This can interpret everything
+bool GeneralFrameFactory::canInterpret(const MDFrameArgument &argument) const {
+  auto canInterpret = true;
+  if (argument.frameString == UnknownFrame::UnknownFrameName) {
+    canInterpret = false;
+  }
+  return canInterpret;
 }
 
 QLab *QLabFrameFactory::createRaw(const MDFrameArgument &) const {
@@ -61,6 +65,25 @@ bool HKLFrameFactory::canInterpret(const MDFrameArgument &argument) const {
   return argument.frameString == HKL::HKLName && compatibleUnit;
 }
 
+
+UnknownFrame*
+UnknownFrameFactory::createRaw(const MDFrameArgument &argument) const {
+  using namespace Mantid::Kernel;
+
+  // Try to generate a proper md unit, don't just assume a label unit.
+  auto unitFactoryChain = Kernel::makeMDUnitFactoryChain();
+  auto mdUnit = unitFactoryChain->create(argument.unitString);
+
+  return new UnknownFrame(argument.frameString, MDUnit_uptr(mdUnit->clone()));
+}
+
+/// Indicate an ability to intepret the string
+bool UnknownFrameFactory::canInterpret(const MDFrameArgument &) const {
+  return true; // This can interpret everything
+}
+
+
+
 MDFrameFactory_uptr makeMDFrameFactoryChain() {
   typedef MDFrameFactory_uptr FactoryType;
   auto first = FactoryType(new QLabFrameFactory);
@@ -68,7 +91,8 @@ MDFrameFactory_uptr makeMDFrameFactoryChain() {
       .setSuccessor(FactoryType(new HKLFrameFactory))
       // Make sure that GeneralFrameFactory is the last in the chain to give a
       // fall-through option
-      .setSuccessor(FactoryType(new GeneralFrameFactory));
+      .setSuccessor(FactoryType(new GeneralFrameFactory))
+      .setSuccessor(FactoryType(new UnknownFrameFactory));
   return first;
 }
 
diff --git a/Framework/Geometry/src/MDGeometry/UnknownFrame.cpp b/Framework/Geometry/src/MDGeometry/UnknownFrame.cpp
new file mode 100644
index 00000000000..dcbea9544a9
--- /dev/null
+++ b/Framework/Geometry/src/MDGeometry/UnknownFrame.cpp
@@ -0,0 +1,18 @@
+#include "MantidGeometry/MDGeometry/UnknownFrame.h"
+
+namespace Mantid {
+namespace Geometry {
+
+UnknownFrame::UnknownFrame(const std::string &frameName,
+                           std::unique_ptr<Kernel::MDUnit> unit)
+    : GeneralFrame(frameName, std::move(unit)) {}
+
+UnknownFrame::UnknownFrame(const std::string &frameName,
+                           const Kernel::UnitLabel &unit)
+    : GeneralFrame(frameName, unit) {}
+
+UnknownFrame::~UnknownFrame() {}
+
+const std::string UnknownFrame::UnknownFrameName = "Unknown frame";
+}
+}
diff --git a/Framework/Geometry/test/MDFrameFactoryTest.h b/Framework/Geometry/test/MDFrameFactoryTest.h
index 586309b4705..e50d8015a1a 100644
--- a/Framework/Geometry/test/MDFrameFactoryTest.h
+++ b/Framework/Geometry/test/MDFrameFactoryTest.h
@@ -9,6 +9,7 @@
 #include "MantidGeometry/MDGeometry/QLab.h"
 #include "MantidGeometry/MDGeometry/QSample.h"
 #include "MantidGeometry/MDGeometry/HKL.h"
+#include "MantidGeometry/MDGeometry/UnknownFrame.h"
 #include "MantidKernel/UnitLabelTypes.h"
 #include "MantidKernel/MDUnit.h"
 
@@ -65,7 +66,7 @@ public:
 
     std::unique_ptr<MDFrame> product = factory.create(argument);
     TSM_ASSERT("Should be creating a QLab frame",
-               dynamic_cast<QLab *>(product.get()));
+               dynamic_cast<Mantid::Geometry::QLab *>(product.get()));
   }
 
   void test_QSampleFrameFactory() {
@@ -82,7 +83,7 @@ public:
 
     std::unique_ptr<MDFrame> product = factory.create(argument);
     TSM_ASSERT("Should be creating a QSample frame",
-               dynamic_cast<QSample *>(product.get()));
+               dynamic_cast<Mantid::Geometry::QSample *>(product.get()));
   }
 
   void test_HKLFrameFactory_interpretation() {
@@ -112,7 +113,7 @@ public:
         MDFrameArgument(HKL::HKLName, Units::Symbol::InverseAngstrom));
 
     TSM_ASSERT("Should be creating a HKL frame, in inverse angstroms",
-               dynamic_cast<HKL *>(product.get()));
+               dynamic_cast<Mantid::Geometry::HKL *>(product.get()));
 
     TSM_ASSERT_EQUALS("Units carried across incorrectly",
                       Units::Symbol::InverseAngstrom, product->getUnitLabel());
@@ -124,7 +125,7 @@ public:
     std::unique_ptr<MDFrame> product =
         factory.create(MDFrameArgument(HKL::HKLName, Units::Symbol::RLU));
     TSM_ASSERT("Should be creating a HKL frame, in rlu",
-               dynamic_cast<HKL *>(product.get()));
+               dynamic_cast<Mantid::Geometry::HKL *>(product.get()));
 
     TSM_ASSERT_EQUALS("Units carried across incorrectly", Units::Symbol::RLU,
                       product->getUnitLabel());
@@ -133,13 +134,15 @@ public:
   void test_make_standard_chain() {
     MDFrameFactory_uptr chain = makeMDFrameFactoryChain();
     // Now lets try the chain of factories out
+    TS_ASSERT(dynamic_cast<UnknownFrame *>(
+        chain->create(MDFrameArgument(UnknownFrame::UnknownFrameName)).get()));
     TS_ASSERT(dynamic_cast<GeneralFrame *>(
         chain->create(MDFrameArgument("any_frame")).get()));
-    TS_ASSERT(dynamic_cast<QLab *>(
+    TS_ASSERT(dynamic_cast<Mantid::Geometry::QLab *>(
         chain->create(MDFrameArgument(QLab::QLabName)).get()));
-    TS_ASSERT(dynamic_cast<QSample *>(
+    TS_ASSERT(dynamic_cast<Mantid::Geometry::QSample *>(
         chain->create(MDFrameArgument(QSample::QSampleName)).get()));
-    TS_ASSERT(dynamic_cast<HKL *>(
+    TS_ASSERT(dynamic_cast<Mantid::Geometry::HKL *>(
         chain->create(MDFrameArgument(HKL::HKLName, Units::Symbol::RLU))
             .get()));
   }
diff --git a/Framework/Geometry/test/QLabTest.h b/Framework/Geometry/test/QLabTest.h
index 3d9ff44f4d5..818b837c998 100644
--- a/Framework/Geometry/test/QLabTest.h
+++ b/Framework/Geometry/test/QLabTest.h
@@ -17,18 +17,18 @@ public:
   static void destroySuite(QLabTest *suite) { delete suite; }
 
   void test_name() {
-    QLab frame;
+    Mantid::Geometry::QLab frame;
     TS_ASSERT_EQUALS(QLab::QLabName, frame.name());
   }
 
   void test_canConvertTo_unit() {
-    QLab frame;
+    Mantid::Geometry::QLab frame;
     InverseAngstromsUnit unit;
     TSM_ASSERT("Same unit type as is used for QLab", frame.canConvertTo(unit));
   }
 
   void test_cannotConvertTo_unit() {
-    QLab frame;
+    Mantid::Geometry::QLab frame;
     ReciprocalLatticeUnit unit;
     TSM_ASSERT("Not same unit type as is used for QLab",
                !frame.canConvertTo(unit));
diff --git a/Framework/Geometry/test/QSampleTest.h b/Framework/Geometry/test/QSampleTest.h
index acdce92642c..dd6b326c6ea 100644
--- a/Framework/Geometry/test/QSampleTest.h
+++ b/Framework/Geometry/test/QSampleTest.h
@@ -17,18 +17,18 @@ public:
   static void destroySuite(QSampleTest *suite) { delete suite; }
 
   void test_name() {
-    QSample frame;
+    Mantid::Geometry::QSample frame;
     TS_ASSERT_EQUALS(QSample::QSampleName, frame.name());
   }
 
   void test_canConvertTo_unit() {
-    QSample frame;
+    Mantid::Geometry::QSample frame;
     InverseAngstromsUnit unit;
     TSM_ASSERT("Same unit type as is used for QLab", frame.canConvertTo(unit));
   }
 
   void test_cannotConvertTo_unit() {
-    QSample frame;
+    Mantid::Geometry::QSample frame;
     ReciprocalLatticeUnit unit;
     TSM_ASSERT("Not same unit type as is used for QLab",
                !frame.canConvertTo(unit));
diff --git a/Framework/MDAlgorithms/src/LoadMD.cpp b/Framework/MDAlgorithms/src/LoadMD.cpp
index 876e8a6bb5d..c2f6e181f3a 100644
--- a/Framework/MDAlgorithms/src/LoadMD.cpp
+++ b/Framework/MDAlgorithms/src/LoadMD.cpp
@@ -7,6 +7,7 @@
 #include "MantidGeometry/MDGeometry/MDDimensionExtents.h"
 #include "MantidGeometry/MDGeometry/MDFrameFactory.h"
 #include "MantidGeometry/MDGeometry/MDFrame.h"
+#include "MantidGeometry/MDGeometry/UnknownFrame.h"
 #include "MantidKernel/CPUTimer.h"
 #include "MantidKernel/EnabledWhenProperty.h"
 #include "MantidKernel/Memory.h"
@@ -353,7 +354,7 @@ void LoadMD::loadDimensions2() {
     try {
       m_file->getAttr("frame", frame);
     } catch (std::exception &) {
-      frame = "Unknown frame";
+      frame = Mantid::Geometry::UnknownFrame::UnknownFrameName;
     }
     Geometry::MDFrame_const_uptr mdFrame =
         Geometry::makeMDFrameFactoryChain()->create(
-- 
GitLab