10#include <boost/python/class.hpp>
11#include <boost/python/enum.hpp>
12#include <boost/python/register_ptr_to_python.hpp>
13#include <boost/python/tuple.hpp>
26const std::string deprecatedName(
const Unit &self) {
27 if (PyErr_Warn(PyExc_DeprecationWarning,
"'name' is deprecated, use 'caption' instead.") < 0)
28 throw boost::python::error_already_set();
36const std::string deprecatedLabel(
const Unit &self) {
37 if (PyErr_Warn(PyExc_DeprecationWarning,
"'unit.label()' is deprecated, use 'str(unit.symbol())' instead.") < 0)
38 throw boost::python::error_already_set();
42template <
class T> tuple quickConversionWrapper(
const Unit &self,
const T &destUnitName) {
43 double wavelengthFactor = 0;
44 double wavelengthPower = 0;
45 bool converted = self.
quickConversion(destUnitName, wavelengthFactor, wavelengthPower);
47 throw std::runtime_error(
"Quick conversion is not possible from unit:" + std::string(self.
unitID()) +
48 " to the desired unit.");
50 return boost::python::make_tuple<double>(wavelengthFactor, wavelengthPower);
56 register_ptr_to_python<std::shared_ptr<Unit>>();
58 enum_<Mantid::Kernel::UnitParams>(
"UnitParams")
67 class_<Unit, boost::noncopyable>(
"Unit", no_init)
68 .def(
"name", &deprecatedName, arg(
"self"),
"Return the full name of the unit (deprecated, use caption)")
69 .def(
"caption", &
Unit::caption, arg(
"self"),
"Return the full name of the unit")
70 .def(
"label", &deprecatedLabel, arg(
"self"),
71 "Returns a plain-text label to be used "
72 "as the symbol for the unit (deprecated, "
75 "Returns a UnitLabel object that holds "
76 "information on the symbol to use for unit")
78 "Returns the string ID of the unit. This may/may not match "
80 .def(
"quickConversion", &quickConversionWrapper<Unit>, (arg(
"self"), arg(
"destUnitName")),
81 "Check whether the unit can be converted to another via a "
83 .def(
"quickConversion", &quickConversionWrapper<std::string>, (arg(
"self"), arg(
"destination")),
84 "Check whether the unit can be converted to another via a "
#define GET_POINTER_SPECIALIZATION(TYPE)
const AsciiString & ascii() const
Return an ascii label for unit.
The base units (abstract) class.
virtual const UnitLabel label() const =0
A label for the unit to be printed on axes,.
virtual const std::string caption() const =0
The full name of the unit.
virtual const std::string unitID() const =0
The name of the unit.
bool quickConversion(const Unit &destination, double &factor, double &power) const
Is conversion by constant multiplication possible?
std::shared_ptr< Unit > Unit_sptr
Shared pointer to the Unit base class.