Mantid
Loading...
Searching...
No Matches
Component.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9#include <boost/python/class.hpp>
10#include <boost/python/overloads.hpp>
11
14using namespace boost::python;
15
16// forward declare
17namespace Mantid::Kernel {
18class Quat;
19class V3D;
20} // namespace Mantid::Kernel
21
22namespace {
23// Deprecation wrappers. Absolute/relative placement is available from the
24// index-based ComponentInfo access layer. See the 'Instrument Access via
25// SpectrumInfo, DetectorInfo, ComponentInfo' concept page. (The parameter and
26// description accessors are not deprecated yet, although ComponentInfo now has
27// an equivalent of each, taking a component index.)
28Mantid::Kernel::Quat getRotationDeprecated(const Component &self) {
29 if (PyErr_Warn(PyExc_DeprecationWarning,
30 "'Component.getRotation()' is deprecated in Mantid 7.0, "
31 "use 'ComponentInfo.rotation' instead. "
32 "For more information, see the instrument access layers concept page: "
33 "https://docs.mantidproject.org/nightly/concepts/InstrumentAccessLayers.html") < 0)
34 throw boost::python::error_already_set();
35 return self.getRotation();
36}
37
38Mantid::Kernel::V3D getRelativePosDeprecated(const Component &self) {
39 if (PyErr_Warn(PyExc_DeprecationWarning,
40 "'Component.getRelativePos' is deprecated in Mantid 7.0, "
41 "use 'ComponentInfo.relativePosition' instead. "
42 "For more information, see the instrument access layers concept page: "
43 "https://docs.mantidproject.org/nightly/concepts/InstrumentAccessLayers.html") < 0)
44 throw boost::python::error_already_set();
45 return self.getRelativePos();
46}
47
48GNU_DIAG_OFF("unused-local-typedef")
49// Ignore -Wconversion warnings coming from boost::python
50// Seen with GCC 7.1.1 and Boost 1.63.0
51GNU_DIAG_OFF("conversion")
52
53// Default parameter function overloads
54// cppcheck-suppress unknownMacro
55BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getParameterNames, Component::getParameterNames, 0, 1)
56BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_hasParameter, Component::hasParameter, 1, 2)
57BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getNumberParameter, Component::getNumberParameter, 1, 2)
58BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getBoolParameter, Component::getBoolParameter, 1, 2)
59BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getPositionParameter, Component::getPositionParameter, 1, 2)
60BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getRotationParameter, Component::getRotationParameter, 1, 2)
61BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getStringParameter, Component::getStringParameter, 1, 2)
62BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getIntParameter, Component::getIntParameter, 1, 2)
63BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getParameterType, Component::getParameterType, 1, 2)
64BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getParamShortDescription, Component::getParamShortDescription, 1, 2)
65BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getParamDescription, Component::getParamDescription, 1, 2)
66
67GNU_DIAG_ON("conversion")
68GNU_DIAG_ON("unused-local-typedef")
69} // namespace
71 class_<Component, bases<IComponent>, boost::noncopyable>("Component", no_init)
72 .def("getParameterNames", &Component::getParameterNames,
73 Component_getParameterNames((arg("self"), arg("recursive") = true)))
74 .def("hasParameter", &Component::hasParameter,
75 Component_hasParameter((arg("self"), arg("name"), arg("recursive") = true)))
76 .def("getNumberParameter", &Component::getNumberParameter,
77 Component_getNumberParameter((arg("self"), arg("pname"), arg("recursive") = true)))
78 .def("getBoolParameter", &Component::getBoolParameter,
79 Component_getBoolParameter((arg("self"), arg("pname"), arg("recursive") = true)))
80 .def("getPositionParameter", &Component::getPositionParameter,
81 Component_getPositionParameter((arg("self"), arg("pname"), arg("recursive") = true)))
82 .def("getRotationParameter", &Component::getRotationParameter,
83 Component_getRotationParameter((arg("self"), arg("pname"), arg("recursive") = true)))
84 .def("getStringParameter", &Component::getStringParameter,
85 Component_getStringParameter((arg("self"), arg("pname"), arg("recursive") = true)))
86 .def("getIntParameter", &Component::getIntParameter,
87 Component_getIntParameter((arg("self"), arg("pname"), arg("recursive") = true)))
88 //
89 .def("getRotation", &getRotationDeprecated, arg("self"),
90 "Returns the absolute rotation as a Quat (deprecated, use ComponentInfo.rotation)")
91 .def("getRelativePos", &getRelativePosDeprecated, arg("self"),
92 "Returns the relative position as a V3D (deprecated, use ComponentInfo.relativePosition)")
93 //
94 .def("getParamShortDescription", &Component::getParamShortDescription,
95 Component_getParamShortDescription((arg("self"), arg("pname"), arg("recursive") = true)))
96 .def("getParamDescription", &Component::getParamDescription,
97 Component_getParamDescription((arg("self"), arg("pname"), arg("recursive") = true)))
98
99 .def("getShortDescription", &Component::getShortDescription, arg("self"),
100 "Return the short description of current parameterized component")
101 .def("getDescription", &Component::getDescription, arg("self"),
102 "Return the description of current parameterized component")
103 .def("setDescription", &Component::setDescription, (arg("self"), arg("descr")),
104 "Set component's description, works only if the component is "
105 "parameterized component")
106
107 // HACK -- python should return parameters regardless of type. this is
108 // untill rows below do not work
109 .def("getParameterType", &Component::getParameterType,
110 Component_getParameterType((arg("self"), arg("pname"), arg("recursive") = true)))
111 .def("getFittingParameter", &Component::getFittingParameter, (arg("self"), arg("pname"), arg("xvalue")),
112 "Get fit parameter from the parameter map."
113 " The value of the parameter is determined from a look up table or a formula")
115 //.def("getParameter", &Component::getNumberParameter,
116 // Component_getNumberParameter())
117 //.def("getParameter", &Component::getBoolParameter,
118 // Component_getBoolParameter())
119 //.def("getParameter", &Component::getStringParameter,
120 // Component_getStringParameter())
121 //.def("getParameter", &Component::getPositionParameter,
122 // Component_getPositionParameter())
123 //.def("getParameter", &Component::getRotationParameter,
124 // Component_getRotationParameter())
125 ;
126}
void export_Component()
Definition Component.cpp:70
#define GNU_DIAG_ON(x)
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
Component is a wrapper for a Component which can modify some of its parameters, e....
Definition Component.h:42
Kernel::V3D getRelativePos() const override
Get the position relative to the parent IComponent (absolute if no parent)
Kernel::Quat getRotation() const override
Get the absolute orientation of the IComponent.
base class for Geometric IComponent
Definition IComponent.h:53
Class for quaternions.
Definition Quat.h:38
Class for 3D vectors.
Definition V3D.h:35