Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bindings/SofaExporter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ project(Bindings.SofaExporter)
set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaExporter/Binding_STLExporter.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaExporter/Binding_STLExporter_doc.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaExporter/Binding_OBJExporter.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaExporter/Binding_OBJExporter_doc.h
)

set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaExporter/Binding_STLExporter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaExporter/Binding_OBJExporter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaExporter/Module_SofaExporter.cpp
)

Expand Down
47 changes: 47 additions & 0 deletions bindings/SofaExporter/src/SofaExporter/Binding_OBJExporter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/******************************************************************************
* SofaPython3 plugin *
* (c) 2021 CNRS, University of Lille, INRIA *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Contact information: contact@sofa-framework.org *
******************************************************************************/

#include <SofaPython3/Sofa/Core/Binding_Base.h>
#include <SofaExporter/Binding_OBJExporter.h>
#include <SofaExporter/Binding_OBJExporter_doc.h>

#include <SofaPython3/PythonFactory.h>
#include <SofaPython3/Sofa/Core/Binding_BaseObject.h>
#include <SofaExporter/OBJExporter.h>

using sofa::component::exporter::OBJExporter;

namespace py { using namespace pybind11; }

namespace sofapython3 {

void moduleAddOBJExporter(py::module &m)
{
PythonFactory::registerType<OBJExporter>([](sofa::core::objectmodel::Base* object)
{
return py::cast(dynamic_cast<OBJExporter*>(object));
});

py::class_<OBJExporter, sofa::core::objectmodel::BaseObject, py_shared_ptr<OBJExporter>> p(m, "OBJExporter");

p.def("write", &OBJExporter::write, sofapython3::doc::SofaExporter::OBJExporter::write::docstring);
}

} // namespace sofapython3
29 changes: 29 additions & 0 deletions bindings/SofaExporter/src/SofaExporter/Binding_OBJExporter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/******************************************************************************
* SofaPython3 plugin *
* (c) 2021 CNRS, University of Lille, INRIA *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Contact information: contact@sofa-framework.org *
******************************************************************************/

#pragma once

#include <pybind11/pybind11.h>

namespace sofapython3 {

void moduleAddOBJExporter(pybind11::module &m);

} /// namespace sofapython3
50 changes: 50 additions & 0 deletions bindings/SofaExporter/src/SofaExporter/Binding_OBJExporter_doc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/******************************************************************************
* SofaPython3 plugin *
* (c) 2021 CNRS, University of Lille, INRIA *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Contact information: contact@sofa-framework.org *
******************************************************************************/

#pragma once

namespace sofapython3::doc::SofaExporter::OBJExporter::write {

static auto docstring =
R"(
Exports an OBJ file
---------------------------------------

Will export a binary or ascii file depending on the binary flag of OBJExporter
Will auto-number the exported files

Example of use:
.. code-block:: python

import Sofa
import SofaExporter

# Create a new node
n = Sofa.Core.Node("root"")

# Add STLExporter
n.addObject("OBJExporter", name="exporter", ...)

# writes down the stl file
n.exporter.write()

)";

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace py = pybind11;

#include <SofaExporter/Binding_STLExporter.h>
#include <SofaExporter/Binding_OBJExporter.h>

namespace sofapython3
{
Expand All @@ -43,12 +44,14 @@ PYBIND11_MODULE(SofaExporter, m) {
:toctree: _autosummary/_autosummary

SofaExporter.STLExporter
SofaExporter.OBJExporter

)doc";

py::module::import("Sofa.Core");

moduleAddSTLExporter(m);
moduleAddOBJExporter(m);
}

} // namespace sofapython3
Expand Down