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

Refs #10702. Extracting crystal system names into PointGroup.h

This way it's easier to convert between strings/enum in different places.
parent 48cced74
No related branches found
No related tags found
No related merge requests found
......@@ -183,26 +183,7 @@ void PawleyParameterFunction::setProfileFunction(
*/
void
PawleyParameterFunction::setCrystalSystem(const std::string &crystalSystem) {
std::string crystalSystemLC = boost::algorithm::to_lower_copy(crystalSystem);
if (crystalSystemLC == "cubic") {
m_crystalSystem = PointGroup::Cubic;
} else if (crystalSystemLC == "tetragonal") {
m_crystalSystem = PointGroup::Tetragonal;
} else if (crystalSystemLC == "hexagonal") {
m_crystalSystem = PointGroup::Hexagonal;
} else if (crystalSystemLC == "trigonal") {
m_crystalSystem = PointGroup::Trigonal;
} else if (crystalSystemLC == "orthorhombic") {
m_crystalSystem = PointGroup::Orthorhombic;
} else if (crystalSystemLC == "monoclinic") {
m_crystalSystem = PointGroup::Monoclinic;
} else if (crystalSystemLC == "triclinic") {
m_crystalSystem = PointGroup::Triclinic;
} else {
throw std::invalid_argument("Not a valid crystal system: '" +
crystalSystem + "'.");
}
m_crystalSystem = Geometry::getCrystalSystemFromString(crystalSystem);
createCrystalSystemParameters(m_crystalSystem);
}
......
......@@ -75,6 +75,14 @@ typedef std::multimap<PointGroup::CrystalSystem, PointGroup_sptr>
PointGroupCrystalSystemMap;
MANTID_GEOMETRY_DLL PointGroupCrystalSystemMap getPointGroupsByCrystalSystem();
MANTID_GEOMETRY_DLL
std::string
getCrystalSystemAsString(const PointGroup::CrystalSystem &crystalSystem);
MANTID_GEOMETRY_DLL
PointGroup::CrystalSystem
getCrystalSystemFromString(const std::string &crystalSystem);
} // namespace Mantid
} // namespace Geometry
......
......@@ -3,6 +3,7 @@
#include <set>
#include <boost/make_shared.hpp>
#include <boost/algorithm/string.hpp>
#include <iostream>
#include "MantidGeometry/Crystal/PointGroupFactory.h"
......@@ -182,5 +183,50 @@ PointGroupCrystalSystemMap getPointGroupsByCrystalSystem() {
return map;
}
/// Return a human-readable string for the given crystal system
std::string
getCrystalSystemAsString(const PointGroup::CrystalSystem &crystalSystem) {
switch (crystalSystem) {
case PointGroup::Cubic:
return "Cubic";
case PointGroup::Tetragonal:
return "Tetragonal";
case PointGroup::Hexagonal:
return "Hexagonal";
case PointGroup::Trigonal:
return "Trigonal";
case PointGroup::Orthorhombic:
return "Orthorhombic";
case PointGroup::Monoclinic:
return "Monoclinic";
default:
return "Triclinic";
}
}
PointGroup::CrystalSystem
getCrystalSystemFromString(const std::string &crystalSystem) {
std::string crystalSystemLC = boost::algorithm::to_lower_copy(crystalSystem);
if (crystalSystemLC == "cubic") {
return PointGroup::Cubic;
} else if (crystalSystemLC == "tetragonal") {
return PointGroup::Tetragonal;
} else if (crystalSystemLC == "hexagonal") {
return PointGroup::Hexagonal;
} else if (crystalSystemLC == "trigonal") {
return PointGroup::Trigonal;
} else if (crystalSystemLC == "orthorhombic") {
return PointGroup::Orthorhombic;
} else if (crystalSystemLC == "monoclinic") {
return PointGroup::Monoclinic;
} else if (crystalSystemLC == "triclinic") {
return PointGroup::Triclinic;
} else {
throw std::invalid_argument("Not a valid crystal system: '" +
crystalSystem + "'.");
}
}
} // namespace Mantid
} // namespace Geometry
......@@ -193,6 +193,38 @@ public:
checkPointGroupPerformance(pg);
}
void testCrystalSystemNames()
{
TS_ASSERT_EQUALS(getCrystalSystemFromString("Cubic"), PointGroup::Cubic);
TS_ASSERT_EQUALS(getCrystalSystemFromString("cubic"), PointGroup::Cubic);
TS_ASSERT_EQUALS(getCrystalSystemFromString("CUBIC"), PointGroup::Cubic);
TS_ASSERT_EQUALS(getCrystalSystemFromString("CuBiC"), PointGroup::Cubic);
TS_ASSERT_EQUALS(getCrystalSystemFromString("Tetragonal"), PointGroup::Tetragonal);
TS_ASSERT_EQUALS(getCrystalSystemFromString("Hexagonal"), PointGroup::Hexagonal);
TS_ASSERT_EQUALS(getCrystalSystemFromString("Trigonal"), PointGroup::Trigonal);
TS_ASSERT_EQUALS(getCrystalSystemFromString("Orthorhombic"), PointGroup::Orthorhombic);
TS_ASSERT_EQUALS(getCrystalSystemFromString("Monoclinic"), PointGroup::Monoclinic);
TS_ASSERT_EQUALS(getCrystalSystemFromString("Triclinic"), PointGroup::Triclinic);
TS_ASSERT_THROWS(getCrystalSystemFromString("DoesNotExist"), std::invalid_argument);
TS_ASSERT_EQUALS(getCrystalSystemFromString(getCrystalSystemAsString(PointGroup::Cubic)),
PointGroup::Cubic);
TS_ASSERT_EQUALS(getCrystalSystemFromString(getCrystalSystemAsString(PointGroup::Tetragonal)),
PointGroup::Tetragonal);
TS_ASSERT_EQUALS(getCrystalSystemFromString(getCrystalSystemAsString(PointGroup::Hexagonal)),
PointGroup::Hexagonal);
TS_ASSERT_EQUALS(getCrystalSystemFromString(getCrystalSystemAsString(PointGroup::Trigonal)),
PointGroup::Trigonal);
TS_ASSERT_EQUALS(getCrystalSystemFromString(getCrystalSystemAsString(PointGroup::Orthorhombic)),
PointGroup::Orthorhombic);
TS_ASSERT_EQUALS(getCrystalSystemFromString(getCrystalSystemAsString(PointGroup::Monoclinic)),
PointGroup::Monoclinic);
TS_ASSERT_EQUALS(getCrystalSystemFromString(getCrystalSystemAsString(PointGroup::Triclinic)),
PointGroup::Triclinic);
}
private:
void checkPointGroupPerformance(const PointGroup_sptr &pointGroup)
{
......
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