Skip to content
Snippets Groups Projects
Commit 5ad4375c authored by Ricardo Ferraz Leal's avatar Ricardo Ferraz Leal
Browse files

Re #9249 Added move and get component by name

parent 87a93c48
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "MantidKernel/System.h" #include "MantidKernel/System.h"
#include "MantidNexus/NexusClasses.h" #include "MantidNexus/NexusClasses.h"
#include "MantidKernel/V3D.h"
namespace Mantid { namespace Mantid {
namespace DataHandling { namespace DataHandling {
...@@ -54,6 +55,8 @@ public: ...@@ -54,6 +55,8 @@ public:
std::string& parent_class, std::string& parent_class,
int indent); int indent);
std::string dateTimeInIsoFormat(std::string); 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 } // namespace DataHandling
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
*WIKI*/ *WIKI*/
#include "MantidDataHandling/LoadHelper.h" #include "MantidDataHandling/LoadHelper.h"
#include "MantidGeometry/Instrument/ComponentHelper.h"
namespace Mantid { namespace Mantid {
namespace DataHandling { namespace DataHandling {
...@@ -322,5 +323,39 @@ std::string LoadHelper::dateTimeInIsoFormat(std::string dateToParse) { ...@@ -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 DataHandling
} // namespace Mantid } // namespace Mantid
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment