Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Framework/Crystal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ include_directories(inc)
target_link_libraries(
Crystal
PUBLIC Mantid::API Mantid::Geometry Mantid::Kernel
PRIVATE Mantid::DataObjects Mantid::Indexing Mantid::DataHandling
PRIVATE Mantid::DataObjects Mantid::Indexing
)

# Add the unit tests directory
Expand Down
1 change: 1 addition & 0 deletions Framework/Crystal/inc/MantidCrystal/RotateSampleShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class MANTID_CRYSTAL_DLL RotateSampleShape final : public API::Algorithm {
void exec() override;
void prepareGoniometerAxes(Goniometer &gon);
bool checkIsValidShape(const API::ExperimentInfo_sptr &ei, std::string &shapeXML, bool &isMeshShape);
void setSampleShape(API::ExperimentInfo &expt, const std::string &shapeXML, bool addTypeTag);
};

} // namespace Crystal
Expand Down
30 changes: 28 additions & 2 deletions Framework/Crystal/src/RotateSampleShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Run.h"
#include "MantidAPI/Sample.h"
#include "MantidDataHandling/CreateSampleShape.h"
#include "MantidGeometry/Instrument/Goniometer.h"
#include "MantidGeometry/Objects/MeshObject.h"
#include "MantidGeometry/Objects/ShapeFactory.h"
Expand Down Expand Up @@ -91,7 +90,34 @@ void RotateSampleShape::exec() {
meshShape->rotate(newSampleShapeRot);
} else {
shapeXML = Geometry::ShapeFactory().addGoniometerTag(newSampleShapeRot, shapeXML);
Mantid::DataHandling::CreateSampleShape::setSampleShape(*ei, shapeXML, false);
setSampleShape(*ei, shapeXML, false);
}
}

/**
* @brief Set the shape via an XML string on the given experiment
* @param expt A reference to the experiment holding the sample object
* @param shapeXML XML defining the object's shape
* @param addTypeTag true to wrap a \<type\> tag around the XML supplied(default)
*/
void RotateSampleShape::setSampleShape(API::ExperimentInfo &expt, const std::string &shapeXML, bool addTypeTag) {
Geometry::ShapeFactory sFactory;
// Create the object
auto shape = sFactory.createShape(shapeXML, addTypeTag);
// Check it's valid and attach it to the workspace sample but preserve any
// material
if (shape->hasValidShape()) {
const auto mat = expt.sample().getMaterial();
shape->setMaterial(mat);
expt.mutableSample().setShape(shape);
} else {
std::ostringstream msg;
msg << "Object has invalid shape.";
if (auto csgShape = dynamic_cast<Geometry::CSGObject *>(shape.get())) {
msg << " TopRule = " << csgShape->topRule() << ", number of surfaces = " << csgShape->getSurfacePtr().size()
<< "\n";
}
throw std::runtime_error(msg.str());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace DataHandling {
*/
class MANTID_DATAHANDLING_DLL CreateSampleShape final : public API::Algorithm {
public:
static void setSampleShape(API::ExperimentInfo &expt, const std::string &shapeXML, bool addTypeTag = true);
static void setSampleShape(API::ExperimentInfo &expt, const std::string &shapeXML);

public:
const std::string name() const override { return "CreateSampleShape"; }
Expand Down
5 changes: 2 additions & 3 deletions Framework/DataHandling/src/CreateSampleShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ using namespace Mantid::API;
* @brief Set the shape via an XML string on the given experiment
* @param expt A reference to the experiment holding the sample object
* @param shapeXML XML defining the object's shape
* @param addTypeTag true to wrap a \<type\> tag around the XML supplied(default)
*/
void CreateSampleShape::setSampleShape(API::ExperimentInfo &expt, const std::string &shapeXML, bool addTypeTag) {
void CreateSampleShape::setSampleShape(API::ExperimentInfo &expt, const std::string &shapeXML) {
Geometry::ShapeFactory sFactory;
// Create the object
auto shape = sFactory.createShape(shapeXML, addTypeTag);
auto shape = sFactory.createShape(shapeXML);
// Check it's valid and attach it to the workspace sample but preserve any
// material
if (shape->hasValidShape()) {
Expand Down