Skip to content
Snippets Groups Projects
Commit 78f773da authored by Michael Wedel's avatar Michael Wedel
Browse files

Refs #13905. Added CrystalStructure to API::Sample

It's very similar to the way OrientedLattice is handled, except a unique_ptr is used to store the object.
parent f9e5a621
No related branches found
No related tags found
No related merge requests found
...@@ -15,6 +15,7 @@ namespace Mantid { ...@@ -15,6 +15,7 @@ namespace Mantid {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Geometry { namespace Geometry {
class OrientedLattice; class OrientedLattice;
class CrystalStructure;
} }
namespace API { namespace API {
...@@ -103,6 +104,14 @@ public: ...@@ -103,6 +104,14 @@ public:
bool hasOrientedLattice() const; bool hasOrientedLattice() const;
//@} //@}
/** @name Access the sample's crystal structure */
//@{
const Geometry::CrystalStructure &getCrystalStructure() const;
void setCrystalStructure(const Geometry::CrystalStructure &newCrystalStructure);
bool hasCrystalStructure() const;
void clearCrystalStructure();
//@}
// Required for SANS work until we define a proper // Required for SANS work until we define a proper
// sample object from the raw file information // sample object from the raw file information
/**@name Legacy functions */ /**@name Legacy functions */
...@@ -137,6 +146,9 @@ private: ...@@ -137,6 +146,9 @@ private:
/// Pointer to the OrientedLattice of the sample, NULL if not set. /// Pointer to the OrientedLattice of the sample, NULL if not set.
Geometry::OrientedLattice *m_lattice; Geometry::OrientedLattice *m_lattice;
/// CrystalStructure of the sample
std::unique_ptr<Geometry::CrystalStructure> m_crystalStructure;
/// Vector of child samples /// Vector of child samples
std::vector<boost::shared_ptr<Sample>> m_samples; std::vector<boost::shared_ptr<Sample>> m_samples;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "MantidAPI/Sample.h" #include "MantidAPI/Sample.h"
#include "MantidAPI/SampleEnvironment.h" #include "MantidAPI/SampleEnvironment.h"
#include "MantidGeometry/IComponent.h" #include "MantidGeometry/IComponent.h"
#include "MantidGeometry/Crystal/CrystalStructure.h"
#include "MantidGeometry/Crystal/OrientedLattice.h" #include "MantidGeometry/Crystal/OrientedLattice.h"
#include "MantidGeometry/Objects/ShapeFactory.h" #include "MantidGeometry/Objects/ShapeFactory.h"
#include "MantidKernel/Strings.h" #include "MantidKernel/Strings.h"
...@@ -22,8 +23,9 @@ using Geometry::ShapeFactory; ...@@ -22,8 +23,9 @@ using Geometry::ShapeFactory;
* Default constructor. Required for cow_ptr. * Default constructor. Required for cow_ptr.
*/ */
Sample::Sample() Sample::Sample()
: m_name(), m_shape(), m_environment(), m_lattice(NULL), m_samples(), : m_name(), m_shape(), m_environment(), m_lattice(NULL),
m_geom_id(0), m_thick(0.0), m_height(0.0), m_width(0.0) {} m_crystalStructure(), m_samples(), m_geom_id(0), m_thick(0.0),
m_height(0.0), m_width(0.0) {}
/** /**
* Copy constructor * Copy constructor
...@@ -31,11 +33,16 @@ Sample::Sample() ...@@ -31,11 +33,16 @@ Sample::Sample()
*/ */
Sample::Sample(const Sample &copy) Sample::Sample(const Sample &copy)
: m_name(copy.m_name), m_shape(copy.m_shape), : m_name(copy.m_name), m_shape(copy.m_shape),
m_environment(copy.m_environment), m_lattice(NULL), m_environment(copy.m_environment), m_lattice(NULL), m_crystalStructure(),
m_samples(copy.m_samples), m_geom_id(copy.m_geom_id), m_samples(copy.m_samples), m_geom_id(copy.m_geom_id),
m_thick(copy.m_thick), m_height(copy.m_height), m_width(copy.m_width) { m_thick(copy.m_thick), m_height(copy.m_height), m_width(copy.m_width) {
if (copy.m_lattice) if (copy.m_lattice)
m_lattice = new OrientedLattice(copy.getOrientedLattice()); m_lattice = new OrientedLattice(copy.getOrientedLattice());
if (copy.hasCrystalStructure()) {
m_crystalStructure.reset(
new Geometry::CrystalStructure(copy.getCrystalStructure()));
}
} }
/// Destructor /// Destructor
...@@ -64,6 +71,12 @@ Sample &Sample::operator=(const Sample &rhs) { ...@@ -64,6 +71,12 @@ Sample &Sample::operator=(const Sample &rhs) {
else else
m_lattice = NULL; m_lattice = NULL;
m_crystalStructure.reset();
if (rhs.hasCrystalStructure()) {
m_crystalStructure.reset(
new Geometry::CrystalStructure(rhs.getCrystalStructure()));
}
return *this; return *this;
} }
...@@ -161,6 +174,29 @@ void Sample::setOrientedLattice(OrientedLattice *latt) { ...@@ -161,6 +174,29 @@ void Sample::setOrientedLattice(OrientedLattice *latt) {
/** @return true if the sample has an OrientedLattice */ /** @return true if the sample has an OrientedLattice */
bool Sample::hasOrientedLattice() const { return (m_lattice != NULL); } bool Sample::hasOrientedLattice() const { return (m_lattice != NULL); }
const Geometry::CrystalStructure &Sample::getCrystalStructure() const {
if (!hasCrystalStructure()) {
throw std::runtime_error(
"Sample::getCrystalStructure - No CrystalStructure has been defined.");
}
return *m_crystalStructure;
}
/// Resets the internal pointer to the new CrystalStructure (it's copied).
void Sample::setCrystalStructure(
const Geometry::CrystalStructure &newCrystalStructure) {
m_crystalStructure.reset(new Geometry::CrystalStructure(newCrystalStructure));
}
/// Returns true if the sample actually holds a CrystalStructure.
bool Sample::hasCrystalStructure() const {
return m_crystalStructure.operator bool();
}
/// Destroys the internally stored CrystalStructure-object.
void Sample::clearCrystalStructure() { m_crystalStructure.reset(); }
/** /**
* Set the geometry flag that is specfied in the raw file within the SPB_STRUCT * Set the geometry flag that is specfied in the raw file within the SPB_STRUCT
* 1 = cylinder, 2 = flat plate, 3 = disc, 4 = single crystal * 1 = cylinder, 2 = flat plate, 3 = disc, 4 = single crystal
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "MantidAPI/Sample.h" #include "MantidAPI/Sample.h"
#include "MantidAPI/SampleEnvironment.h" #include "MantidAPI/SampleEnvironment.h"
#include "MantidGeometry/Crystal/CrystalStructure.h"
#include "MantidGeometry/Crystal/OrientedLattice.h" #include "MantidGeometry/Crystal/OrientedLattice.h"
#include "MantidKernel/Exception.h" #include "MantidKernel/Exception.h"
#include "MantidTestHelpers/ComponentCreationHelper.h" #include "MantidTestHelpers/ComponentCreationHelper.h"
...@@ -199,6 +200,57 @@ public: ...@@ -199,6 +200,57 @@ public:
delete latticeA; delete latticeA;
} }
void test_setCrystalStructure() {
Sample sample;
TS_ASSERT(!sample.hasCrystalStructure());
TS_ASSERT_THROWS(sample.getCrystalStructure(), std::runtime_error);
CrystalStructure structure("3 4 5 90 90 90", "C m m m",
"Fe 0.12 0.23 0.121");
TS_ASSERT_THROWS_NOTHING(sample.setCrystalStructure(structure));
TS_ASSERT(sample.hasCrystalStructure());
CrystalStructure fromSample = sample.getCrystalStructure();
TS_ASSERT(fromSample.spaceGroup());
TS_ASSERT_EQUALS(fromSample.spaceGroup()->hmSymbol(), "C m m m");
}
void test_clearCrystalStructure() {
Sample sample;
TS_ASSERT(!sample.hasCrystalStructure());
TS_ASSERT_THROWS(sample.getCrystalStructure(), std::runtime_error);
CrystalStructure structure("3 4 5 90 90 90", "C m m m",
"Fe 0.12 0.23 0.121");
sample.setCrystalStructure(structure);
TS_ASSERT(sample.hasCrystalStructure());
TS_ASSERT_THROWS_NOTHING(sample.clearCrystalStructure());
TS_ASSERT(!sample.hasCrystalStructure());
}
void test_crystalStructureCopyConstructorAndAssignment() {
Sample sampleA;
CrystalStructure structure("3 4 5 90 90 90", "C m m m",
"Fe 0.12 0.23 0.121");
sampleA.setCrystalStructure(structure);
TS_ASSERT(sampleA.hasCrystalStructure());
Sample sampleB = sampleA;
TS_ASSERT(sampleB.hasCrystalStructure());
CrystalStructure fromA = sampleA.getCrystalStructure();
CrystalStructure fromB = sampleB.getCrystalStructure();
TS_ASSERT_EQUALS(fromA.spaceGroup()->hmSymbol(), fromB.spaceGroup()->hmSymbol());
Sample sampleC(sampleA);
CrystalStructure fromC = sampleC.getCrystalStructure();
TS_ASSERT_EQUALS(fromA.spaceGroup()->hmSymbol(), fromC.spaceGroup()->hmSymbol());
}
void test_Material_Returns_The_Correct_Value() { void test_Material_Returns_The_Correct_Value() {
Material vanBlock("vanBlock", Material vanBlock("vanBlock",
Mantid::PhysicalConstants::getNeutronAtom(23, 0), 0.072); Mantid::PhysicalConstants::getNeutronAtom(23, 0), 0.072);
......
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