-
Notifications
You must be signed in to change notification settings - Fork 121
/
CreateSampleShape.cpp
60 lines (55 loc) · 1.83 KB
/
CreateSampleShape.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//--------------------------------
// Includes
//--------------------------------
#include "MantidDataHandling/CreateSampleShape.h"
#include "MantidGeometry/Objects/ShapeFactory.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidKernel/Material.h"
#include "MantidAPI/Sample.h"
#include "MantidKernel/MandatoryValidator.h"
namespace Mantid {
namespace DataHandling {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(CreateSampleShape)
using namespace Mantid::DataHandling;
using namespace Mantid::API;
/**
* Initialize the algorithm
*/
void CreateSampleShape::init() {
using namespace Mantid::Kernel;
declareProperty(make_unique<WorkspaceProperty<MatrixWorkspace>>(
"InputWorkspace", "", Direction::Input),
"The workspace with which to associate the sample ");
declareProperty("ShapeXML", "",
boost::make_shared<MandatoryValidator<std::string>>(),
"The XML that describes the shape");
}
/**
* Execute the algorithm
*/
void CreateSampleShape::exec() {
// Get the input workspace
MatrixWorkspace_sptr workspace = getProperty("InputWorkspace");
// Get the XML definition
std::string shapeXML = getProperty("ShapeXML");
Geometry::ShapeFactory sFactory;
// Create the object
auto shape = sFactory.createShape(shapeXML);
// Check it's valid and attach it to the workspace sample but preserve any
// material
if (shape->hasValidShape()) {
const auto mat = workspace->sample().getMaterial();
shape->setMaterial(mat);
workspace->mutableSample().setShape(*shape);
} else {
std::ostringstream msg;
msg << "Object has invalid shape. TopRule = " << shape->topRule()
<< ", number of surfaces = " << shape->getSurfacePtr().size() << "\n";
throw std::runtime_error(msg.str());
}
// Done!
progress(1);
}
}
}