Skip to content
Snippets Groups Projects
CreateSampleShape.cpp 1.79 KiB
Newer Older
//--------------------------------
// Includes
//--------------------------------
#include "MantidDataHandling/CreateSampleShape.h"
Nick Draper's avatar
Nick Draper committed
#include "MantidGeometry/Objects/ShapeFactory.h"

namespace Mantid
{
namespace DataHandling
{
  // Register the algorithm into the AlgorithmFactory
  this->setWikiSummary("Create a shape object to model the sample.");
  this->setOptionalMessage("Create a shape object to model the sample.");

  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" );
  MatrixWorkspace_sptr workspace = getProperty("InputWorkspace");
  // Get the XML definition
  std::string shapeXML = getProperty("ShapeXML");
  Geometry::ShapeFactory sFactory;
  boost::shared_ptr<Geometry::Object> shape_sptr = sFactory.createShape(shapeXML);
  // 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!