From 40a81b427f7a89e6605a04ccb73603ebd68e41c0 Mon Sep 17 00:00:00 2001
From: Owen Arnold <owen.arnold@stfc.ac.uk>
Date: Tue, 9 Oct 2012 16:38:41 +0100
Subject: [PATCH] refs #5923. Uses version number in query.

This works, but needs a little refactoring to improve readability.
---
 Code/Mantid/Build/CMake/CommonSetup.cmake     |  1 +
 Code/Mantid/Framework/Kernel/CMakeLists.txt   |  5 ++
 .../Kernel/inc/MantidKernel/ParaViewVersion.h | 48 +++++++++++++++++++
 Code/Mantid/Framework/Kernel/src/.gitignore   |  1 +
 .../Framework/Kernel/src/ConfigService.cpp    | 35 ++++++++++++--
 .../Kernel/src/ParaViewVersion.cpp.in         | 17 +++++++
 6 files changed, 103 insertions(+), 4 deletions(-)
 create mode 100644 Code/Mantid/Framework/Kernel/inc/MantidKernel/ParaViewVersion.h
 create mode 100644 Code/Mantid/Framework/Kernel/src/ParaViewVersion.cpp.in

diff --git a/Code/Mantid/Build/CMake/CommonSetup.cmake b/Code/Mantid/Build/CMake/CommonSetup.cmake
index 86835de4f1c..8bf9015b310 100644
--- a/Code/Mantid/Build/CMake/CommonSetup.cmake
+++ b/Code/Mantid/Build/CMake/CommonSetup.cmake
@@ -79,6 +79,7 @@ set ( CMAKE_INCLUDE_PATH ${MAIN_CMAKE_INCLUDE_PATH} )
 set ( MtdVersion_WC_LAST_CHANGED_REV 0 )
 set ( MtdVersion_WC_LAST_CHANGED_DATE Unknown )
 set ( NOT_GIT_REPO "Not" )
+set ( Compatible_ParaView_Version "3.14" )
 
 find_package ( Git )
 if ( GIT_FOUND )
diff --git a/Code/Mantid/Framework/Kernel/CMakeLists.txt b/Code/Mantid/Framework/Kernel/CMakeLists.txt
index 59285a41410..7885be6d701 100644
--- a/Code/Mantid/Framework/Kernel/CMakeLists.txt
+++ b/Code/Mantid/Framework/Kernel/CMakeLists.txt
@@ -52,6 +52,7 @@ set ( SRC_FILES
 	src/NDRandomNumberGenerator.cpp
 	src/NeutronAtom.cpp
 	src/NexusTestHelper.cpp
+    src/ParaViewVersion.cpp
 	src/ProgressBase.cpp
 	src/ProgressText.cpp
 	src/Property.cpp
@@ -173,6 +174,7 @@ set ( INC_FILES
 	inc/MantidKernel/NeutronAtom.h
 	inc/MantidKernel/NexusTestHelper.h
 	inc/MantidKernel/NullValidator.h
+    inc/MantidKernel/ParaViewVersion.h
 	inc/MantidKernel/PhysicalConstants.h
 	inc/MantidKernel/ProgressBase.h
 	inc/MantidKernel/ProgressText.h
@@ -354,6 +356,9 @@ if ( NOT NOT_GIT_REPO OR NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/MantidVersio
   configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/../../Build/CMake/PatchVersionNumber.cmake.in
                    ${CMAKE_CURRENT_SOURCE_DIR}/../../Build/CMake/PatchVersionNumber.cmake
   )
+  configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/src/ParaViewVersion.cpp.in
+                   ${CMAKE_CURRENT_SOURCE_DIR}/src/ParaViewVersion.cpp
+  )
 endif ()
 
 ###########################################################################
diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/ParaViewVersion.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/ParaViewVersion.h
new file mode 100644
index 00000000000..a58813d1c80
--- /dev/null
+++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/ParaViewVersion.h
@@ -0,0 +1,48 @@
+#ifndef MANTID_KERNEL_PARAVIEW_VERSION_H_
+#define MANTID_KERNEL_PARAVIEW_VERSION_H_
+
+//----------------------------------------------------------------------
+// Includes
+//----------------------------------------------------------------------
+#include "MantidKernel/DllConfig.h"
+#include <string>
+
+namespace Mantid
+{
+namespace Kernel
+{
+/** Class containing static methods to return the ParaView version number.
+
+    Copyright &copy; 2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
+
+    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://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+ */
+class MANTID_KERNEL_DLL ParaViewVersion
+{
+public:
+  static std::string targetVersion();     ///< The version number major.minor
+
+private:
+  ParaViewVersion(); ///< Private, unimplemented constructor. Not a class that can be instantiated.
+};
+
+} // namespace Kernel
+} // namespace Mantid
+
+#endif /* MANTID_KERNEL_PARAVIEW_VERSION_H_ */
diff --git a/Code/Mantid/Framework/Kernel/src/.gitignore b/Code/Mantid/Framework/Kernel/src/.gitignore
index fd0beea5aa7..a81090024ef 100644
--- a/Code/Mantid/Framework/Kernel/src/.gitignore
+++ b/Code/Mantid/Framework/Kernel/src/.gitignore
@@ -1 +1,2 @@
 MantidVersion.cpp
+ParaViewVersion.cpp
\ No newline at end of file
diff --git a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp
index ffbc88c2dc4..135a714b574 100644
--- a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp
+++ b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp
@@ -3,6 +3,7 @@
 //----------------------------------------------------------------------
 #include "MantidKernel/ConfigService.h"
 #include "MantidKernel/MantidVersion.h"
+#include "MantidKernel/ParaViewVersion.h"
 #include "MantidKernel/Strings.h"
 #include "MantidKernel/Logger.h"
 #include "MantidKernel/FilterChannel.h"
@@ -1709,13 +1710,39 @@ bool ConfigServiceImpl::quickParaViewCheck() const
     }
     std::vector<std::string> args;
     args.push_back("-V");
-    Poco::Pipe outPipe;
-    Poco::ProcessHandle ph = Poco::Process::launch(cmd, args, 0, &outPipe, &outPipe);
+    Poco::Pipe outPipe, errorPipe;
+    Poco::ProcessHandle ph = Poco::Process::launch(cmd, args, 0, &outPipe, &errorPipe);
     const int rc = ph.wait();
     if(rc == 1)
     {
-      isAvailable = true;
-      this->g_log.notice("ParaView is available");
+      Poco::PipeInputStream stdErr(errorPipe);
+      std::stringstream errStream;
+      Poco::StreamCopier::copyStream(stdErr, errStream);
+      std::string givenVersion = errStream.str();
+      boost::smatch  match;
+      
+      boost::regex expression("(\\d+)\\.(\\d+)");
+      double givenVersionNumber;
+      if(boost::regex_search(givenVersion, match, expression))
+      {
+        Strings::convert(match[0], givenVersionNumber);
+      }
+
+      double targetVersionNumber;
+      Strings::convert(ParaViewVersion::targetVersion(), targetVersionNumber);
+      if (givenVersionNumber == targetVersionNumber)
+      {
+        isAvailable = true;
+        this->g_log.notice("ParaView is available");
+      }
+      else
+      {
+        std::stringstream messageStream;
+        messageStream << "The compatible version of ParaView is " << targetVersionNumber << " but the installed version is " << givenVersionNumber;
+
+        this->g_log.notice(messageStream.str());
+        this->g_log.notice("ParaView is not available");
+      }
     }
     else
     {
diff --git a/Code/Mantid/Framework/Kernel/src/ParaViewVersion.cpp.in b/Code/Mantid/Framework/Kernel/src/ParaViewVersion.cpp.in
new file mode 100644
index 00000000000..d8ce1fa6ab0
--- /dev/null
+++ b/Code/Mantid/Framework/Kernel/src/ParaViewVersion.cpp.in
@@ -0,0 +1,17 @@
+//----------------------------------------------------------------------
+// Includes
+//----------------------------------------------------------------------
+#include "MantidKernel/ParaViewVersion.h"
+
+namespace Mantid
+{
+namespace Kernel
+{
+
+std::string ParaViewVersion::targetVersion()
+{
+  return "@Compatible_ParaView_Version@";
+}
+
+} // namespace Kernel
+} // namespace Mantid
-- 
GitLab