|
| 1 | +/****************************************************************************** |
| 2 | +* SOFA, Simulation Open-Framework Architecture * |
| 3 | +* (c) 2021 INRIA, USTL, UJF, CNRS, MGH * |
| 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: [email protected] * |
| 19 | +******************************************************************************/ |
| 20 | + |
| 21 | +#include <SofaPython3/Sofa/Types/Binding_BoundingBox.h> |
| 22 | + |
| 23 | +#include <sofa/core/objectmodel/BaseData.h> |
| 24 | +#include <sofa/core/objectmodel/Data.h> |
| 25 | +#include <sofa/type/BoundingBox.h> |
| 26 | +#include <SofaPython3/PythonFactory.h> |
| 27 | +#include <pybind11/stl.h> |
| 28 | +#include <pybind11/operators.h> |
| 29 | +using sofa::type::RGBAColor; |
| 30 | + |
| 31 | +namespace py { using namespace pybind11; } |
| 32 | + |
| 33 | +namespace sofapython3 { |
| 34 | + |
| 35 | +void moduleAddRGBAColor(py::module& m) |
| 36 | +{ |
| 37 | + py::class_<sofa::type::RGBAColor> c(m, "RGBAColor"); |
| 38 | + c.doc() = R"doc(A color)doc"; |
| 39 | + |
| 40 | + c.def(py::init<>()); // empty ctor |
| 41 | + c.def(py::init<const RGBAColor &>()); // copy ctor |
| 42 | + c.def(py::init([](double r, double g, double b, double a) { |
| 43 | + return std::make_unique<sofa::type::RGBAColor>( r,g,b,a ); |
| 44 | + })); |
| 45 | + |
| 46 | + c.def(py::init([](std::array<double,4>& v) { |
| 47 | + return std::make_unique<sofa::type::RGBAColor>( v[0], v[1], v[2], v[3] ); |
| 48 | + })); |
| 49 | + |
| 50 | + c.def("r", [](const RGBAColor& color) { return color.r(); }); |
| 51 | + c.def("g", [](const RGBAColor& color) { return color.g(); }); |
| 52 | + c.def("b", [](const RGBAColor& color) { return color.b(); }); |
| 53 | + c.def("a", [](const RGBAColor& color) { return color.a(); }); |
| 54 | + |
| 55 | + c.def("lighten", [](const RGBAColor& color, const SReal factor){ |
| 56 | + return RGBAColor::lighten(color, factor); |
| 57 | + }); |
| 58 | + |
| 59 | + c.def("__str__", [](const RGBAColor& color){ |
| 60 | + std::stringstream tmp; |
| 61 | + tmp << "RGBAColor(" << color.r() << "," << color.g() << "," << color.b() << "," << color.a() << ")"; |
| 62 | + return tmp.str(); |
| 63 | + }); |
| 64 | + |
| 65 | + c.def("__repr__", [](const RGBAColor& color){ |
| 66 | + std::stringstream tmp; |
| 67 | + tmp << "RGBAColor(" << color.r() << "," << color.g() << "," << color.b() << "," << color.a() << ")"; |
| 68 | + return tmp.str(); |
| 69 | + }); |
| 70 | + |
| 71 | + // Dark magic to define comparison operator using the c++ == and != operator. |
| 72 | + c.def(pybind11::self==pybind11::self); |
| 73 | + c.def(pybind11::self!=pybind11::self); |
| 74 | +} |
| 75 | + |
| 76 | +} // namespace sofapython3 |
| 77 | + |
0 commit comments