Newer
Older
Gigg, Martyn Anthony
committed
//--------------------------------
// Includes
//--------------------------------
#include "MantidDataHandling/CreateSampleShape.h"
Gigg, Martyn Anthony
committed
#include "MantidAPI/MatrixWorkspace.h"
Gigg, Martyn Anthony
committed
#include "MantidAPI/Sample.h"
Gigg, Martyn Anthony
committed
namespace Mantid
{
namespace DataHandling
{
// Register the algorithm into the AlgorithmFactory
Gigg, Martyn Anthony
committed
DECLARE_ALGORITHM(CreateSampleShape)
Gigg, Martyn Anthony
committed
}
}
using namespace Mantid::DataHandling;
Gigg, Martyn Anthony
committed
using namespace Mantid::API;
Gigg, Martyn Anthony
committed
/**
* Initialize the algorithm
*/
void CreateSampleShape::init()
{
this->setWikiSummary("Create a shape object to model the sample.");
this->setOptionalMessage("Create a shape object to model the sample.");
Gigg, Martyn Anthony
committed
using namespace Mantid::Kernel;
Steve Williams
committed
declareProperty(
new WorkspaceProperty<MatrixWorkspace>("InputWorkspace","",Direction::Input),
"The workspace with which to associate the sample ");
declareProperty("ShapeXML","",new MandatoryValidator<std::string>(),
"The XML that describes the shape" );
Gigg, Martyn Anthony
committed
}
/**
* Execute the algorithm
*/
void CreateSampleShape::exec()
Gigg, Martyn Anthony
committed
{
// Get the input workspace
Gigg, Martyn Anthony
committed
MatrixWorkspace_sptr workspace = getProperty("InputWorkspace");
Gigg, Martyn Anthony
committed
// Get the XML definition
std::string shapeXML = getProperty("ShapeXML");
Geometry::ShapeFactory sFactory;
Gigg, Martyn Anthony
committed
// Create the object
Gigg, Martyn Anthony
committed
boost::shared_ptr<Geometry::Object> shape_sptr = sFactory.createShape(shapeXML);
Gigg, Martyn Anthony
committed
// Check it's valid and attach it to the workspace sample
if( shape_sptr->hasValidShape() )
{
workspace->mutableSample().setShape(*shape_sptr);
}
else
{
g_log.warning() << "Object has invalid shape. TopRule = " << shape_sptr->topRule()
<< ", number of surfaces = " << shape_sptr->getSurfacePtr().size() << "\n";
throw std::runtime_error("Shape object is invalid, cannot attach it to workspace.");
}
// Done!
Sofia Antony
committed
progress(1);