From 5ad4375c8db97c528a3e46fa21ce76e23b0cadf8 Mon Sep 17 00:00:00 2001
From: Ricardo Ferraz Leal <ricardo.leal@ill.eu>
Date: Fri, 16 May 2014 10:28:28 +0200
Subject: [PATCH] Re #9249 Added move and get component by name

---
 .../inc/MantidDataHandling/LoadHelper.h       |  3 ++
 .../Framework/DataHandling/src/LoadHelper.cpp | 35 +++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadHelper.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadHelper.h
index bf34c77e49f..45fc5fe1141 100644
--- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadHelper.h
+++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadHelper.h
@@ -3,6 +3,7 @@
 
 #include "MantidKernel/System.h"
 #include "MantidNexus/NexusClasses.h"
+#include "MantidKernel/V3D.h"
 
 namespace Mantid {
 namespace DataHandling {
@@ -54,6 +55,8 @@ public:
 	    		std::string& parent_class,
 	    		int indent);
 	std::string dateTimeInIsoFormat(std::string);
+	void moveComponent(API::MatrixWorkspace_sptr ws, const std::string &componentName,const Kernel::V3D& newPos);
+	Kernel::V3D getComponentPosition(API::MatrixWorkspace_sptr ws, const std::string &componentName);
 };
 
 } // namespace DataHandling
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadHelper.cpp b/Code/Mantid/Framework/DataHandling/src/LoadHelper.cpp
index 7e487bd6197..ec01bd6f85d 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadHelper.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadHelper.cpp
@@ -3,6 +3,7 @@
  *WIKI*/
 
 #include "MantidDataHandling/LoadHelper.h"
+#include "MantidGeometry/Instrument/ComponentHelper.h"
 
 namespace Mantid {
 namespace DataHandling {
@@ -322,5 +323,39 @@ std::string LoadHelper::dateTimeInIsoFormat(std::string dateToParse) {
 	}
 }
 
+
+void LoadHelper::moveComponent(API::MatrixWorkspace_sptr ws, const std::string &componentName,const V3D& newPos) {
+
+	try {
+
+		Geometry::Instrument_const_sptr instrument = ws->getInstrument();
+		Geometry::IComponent_const_sptr component = instrument->getComponentByName(componentName);
+
+		//g_log.debug() << tube->getName() << " : t = " << theta << " ==> t = " << newTheta << "\n";
+		Geometry::ParameterMap& pmap = ws->instrumentParameters();
+		Geometry::ComponentHelper::moveComponent(*component, pmap, newPos, Geometry::ComponentHelper::Absolute);
+
+	} catch (Mantid::Kernel::Exception::NotFoundError&) {
+		throw std::runtime_error(
+				"Error when trying to move the "  + componentName +  " : NotFoundError");
+	} catch (std::runtime_error &) {
+		throw std::runtime_error(
+				"Error when trying to move the "  + componentName +  " : runtime_error");
+	}
+
+}
+
+V3D LoadHelper::getComponentPosition(API::MatrixWorkspace_sptr ws, const std::string &componentName) {
+	try {
+			Geometry::Instrument_const_sptr instrument = ws->getInstrument();
+			Geometry::IComponent_const_sptr component = instrument->getComponentByName(componentName);
+			V3D pos = component->getPos();
+			return pos;
+		} catch (Mantid::Kernel::Exception::NotFoundError&) {
+			throw std::runtime_error(
+					"Error when trying to move the "  + componentName +  " : NotFoundError");
+		}
+}
+
 } // namespace DataHandling
 } // namespace Mantid
-- 
GitLab