|
| 1 | +/****************************************************************************** |
| 2 | +* SofaPython3 plugin * |
| 3 | +* (c) 2021 CNRS, University of Lille, INRIA * |
| 4 | +* * |
| 5 | +* This program is free software; you can redistribute it and/or modify it * |
| 6 | +* under the terms of the GNU Lesser General Public License as published by * |
| 7 | +* the Free Software Foundation; either version 2.1 of the License, or (at * |
| 8 | +* your option) any later version. * |
| 9 | +* * |
| 10 | +* This program is distributed in the hope that it will be useful, but WITHOUT * |
| 11 | +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * |
| 12 | +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * |
| 13 | +* for more details. * |
| 14 | +* * |
| 15 | +* You should have received a copy of the GNU Lesser General Public License * |
| 16 | +* along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 17 | +******************************************************************************* |
| 18 | +* Contact information: contact@sofa-framework.org * |
| 19 | +******************************************************************************/ |
| 20 | +#include <SofaPython3/SofaTypes/Binding_Transform.h> |
| 21 | +#include <sofa/defaulttype/typeinfo/DataTypeInfo.h> |
| 22 | +#include <SofaPython3/SofaTypes/Binding_Vec.h> |
| 23 | +#include <SofaPython3/SofaTypes/Binding_Quat.h> |
| 24 | + |
| 25 | +namespace pyTransform |
| 26 | +{ |
| 27 | +template<class TReal> |
| 28 | +std::string __str__(const sofa::type::Transform<TReal>& self, bool repr) |
| 29 | +{ |
| 30 | + std::string s; |
| 31 | + if (repr) |
| 32 | + { |
| 33 | + s += "Transform" + sofa::defaulttype::DataTypeInfo<TReal>::name(); |
| 34 | + } |
| 35 | + s += "("; |
| 36 | + s += pyVec::__str__(self.getOrigin(), repr); |
| 37 | + s += std::string(", "); |
| 38 | + s += pyQuat::__str__(self.getOrientation(), repr); |
| 39 | + s += ")"; |
| 40 | + return s; |
| 41 | +} |
| 42 | +} |
| 43 | + |
| 44 | +namespace sofapython3::SofaTypes |
| 45 | +{ |
| 46 | + |
| 47 | +template<class TReal> |
| 48 | +void addTransform(py::module& m) |
| 49 | +{ |
| 50 | + const auto className = "Transform" + sofa::defaulttype::DataTypeInfo<TReal>::name(); |
| 51 | + py::class_<sofa::type::Transform<TReal>> p(m, className.c_str()); |
| 52 | + |
| 53 | + p.def("__str__", [](sofa::type::Transform<TReal>& self) |
| 54 | + { |
| 55 | + return pyTransform::__str__(self, false); |
| 56 | + }); |
| 57 | + p.def("__repr__", [](sofa::type::Transform<TReal>& self) |
| 58 | + { |
| 59 | + return pyTransform::__str__(self, false); |
| 60 | + }); |
| 61 | +} |
| 62 | + |
| 63 | +void moduleAddTransform(py::module& m) |
| 64 | +{ |
| 65 | + addTransform<SReal>(m); |
| 66 | +} |
| 67 | + |
| 68 | +} |
0 commit comments