Skip to content
Open
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
15 changes: 9 additions & 6 deletions CMake/SofaPython3Tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,15 @@ function(SP3_add_python_module)

if (APPLE)
# In MacOS, the target dependency name is RPATH/site-packages/PackageName, so we need to add
# an RPATH to the directory that contains "site-packages"
# an RPATH to the directory that contains "site-packages" (e.g. "../.." for site-packages/Sofa/Core.so,
# "../../../.." for site-packages/Sofa/Component/SolidMechanics/Spring.so)
file(RELATIVE_PATH from_target_to_python_root "${TARGET_LIBRARY_OUTPUT_DIRECTORY}" "${CMAKE_BINARY_DIR}/lib/${SP3_PYTHON_PACKAGES_DIRECTORY}/..")
file(TO_CMAKE_PATH "${from_target_to_python_root}" from_target_to_python_root)
list(APPEND TARGET_DEPENDENCIES_RPATH
"$ORIGIN/../.."
"$$ORIGIN/../.."
"@loader_path/../.."
"@executable_path/../.."
"$ORIGIN/${from_target_to_python_root}"
"$$ORIGIN/${from_target_to_python_root}"
"@loader_path/${from_target_to_python_root}"
"@executable_path/${from_target_to_python_root}"
)
endif()

Expand Down Expand Up @@ -303,7 +306,7 @@ function(SP3_add_python_module)

if (APPLE)
set_target_properties(
${PROJECT_NAME}
${A_TARGET}
PROPERTIES
INSTALL_NAME_DIR "@rpath/${SP3_PYTHON_PACKAGES_DIRECTORY}/${DESTINATION}"
)
Expand Down
8 changes: 1 addition & 7 deletions bindings/BindingsConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@
@PACKAGE_GUARD@
@PACKAGE_INIT@

set(SP3_WITH_SOFAEXPORTER @SP3_WITH_SOFAEXPORTER@)

find_package(Sofa.Config QUIET REQUIRED)

sofa_find_package(SofaPython3 QUIET REQUIRED COMPONENTS
Bindings.Modules
Bindings.Component
Bindings.Sofa
Bindings.SofaGui
Bindings.SofaRuntime
Bindings.SofaTypes
)
if(SP3_WITH_SOFAEXPORTER)
sofa_find_package(SofaPython3 QUIET REQUIRED COMPONENTS Bindings.SofaExporter)
endif()

# If we are importing this config file and the target is not yet there this is indicating that
# target is an imported one. So we include it
if(NOT TARGET @PROJECT_NAME@)
Expand Down
6 changes: 1 addition & 5 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
project(Bindings)

set(BINDINGS_MODULE_LIST Sofa SofaRuntime SofaTypes Modules)
set(BINDINGS_MODULE_LIST Sofa SofaRuntime SofaTypes Component)

if(SP3_WITH_SOFAGUI)
list(APPEND BINDINGS_MODULE_LIST SofaGui)
endif()

if(SP3_WITH_SOFAEXPORTER)
list(APPEND BINDINGS_MODULE_LIST SofaExporter)
endif()

# This will set rpaths relative to SP3 plugin library
if(UNIX)
set(CMAKE_INSTALL_RPATH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
@PACKAGE_GUARD@
@PACKAGE_INIT@

set(SP3_WITH_SOFAEXPORTER @SP3_WITH_SOFAEXPORTER@)

find_package(Sofa.Config QUIET REQUIRED)
sofa_find_package(SofaPython3 QUIET REQUIRED COMPONENTS Plugin Bindings.Sofa)

# Required by Bindings.Modules.SofaBaseTopology
sofa_find_package(Sofa.Component.Topology.Container.Grid QUIET REQUIRED)

# Required by Bindings.Modules.SofaDeformable
sofa_find_package(Sofa.Component.SolidMechanics.Spring QUIET REQUIRED)

# Required by Bindings.Modules.SofaLinearSolver
sofa_find_package(Sofa.Component.LinearSolver.Iterative QUIET REQUIRED)
# SOFA modules bound by the Bindings.Component.* targets that were built
set(SP3_BOUND_SOFA_COMPONENT_MODULES "@COMPONENTBINDINGS_SOFA_MODULES@")
foreach(sofa_module ${SP3_BOUND_SOFA_COMPONENT_MODULES})
sofa_find_package(${sofa_module} QUIET REQUIRED)
endforeach()

# If we are importing this config file and the target is not yet there this is indicating that
# target is an imported one. So we include it
Expand Down
84 changes: 84 additions & 0 deletions bindings/Component/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
project(Bindings.Component)

# Python bindings for SOFA's Sofa.Component.* modules.
#
# The directory layout mirrors SOFA's Sofa/Component tree: the bindings of the SOFA module
# Sofa.Component.<Area>.<Sub> live in <Area>/<Sub>/ and are compiled into the python module
# Sofa.Component.<Area>.<Sub> (i.e. site-packages/Sofa/Component/<Area>/<Sub>.<ext>).
#
# A binding is only built when the SOFA module it binds is available.

# - Create the python module binding a SOFA Sofa.Component.* module.
#
# SP3_add_component_binding(<SOFA module name> SOURCES ... HEADERS ... [DEPENDS ...])
# The target name is the current PROJECT_NAME (Bindings.Component.<Area>.<Sub>), the python module is
# the last part of the SOFA module name, installed in the python package made of the other parts.
function(SP3_add_component_binding sofa_module)
cmake_parse_arguments(A "" "" "SOURCES;HEADERS;DEPENDS" ${ARGN})

string(REPLACE "." ";" module_path "${sofa_module}")
list(POP_BACK module_path module_name)
string(REPLACE ";" "/" module_destination "${module_path}")

SP3_add_python_module(
TARGET ${PROJECT_NAME}
PACKAGE Bindings.Component
MODULE ${module_name}
DESTINATION ${module_destination}
SOURCES ${A_SOURCES}
HEADERS ${A_HEADERS}
DEPENDS ${sofa_module} ${A_DEPENDS} SofaPython3::Plugin SofaPython3::Bindings.Sofa.Core
)
set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "Bindings/Component")
set_property(GLOBAL APPEND PROPERTY SP3_COMPONENT_BINDING_TARGETS ${PROJECT_NAME})
set_property(GLOBAL APPEND PROPERTY SP3_COMPONENT_BINDING_SOFA_MODULES ${sofa_module})
endfunction()

if (NOT TARGET SofaPython3::Plugin)
find_package(SofaPython3 REQUIRED COMPONENTS Plugin Bindings.Sofa)
endif()

set(COMPONENTBINDINGS_MODULE_LIST
Constraint/Lagrangian/Solver
LinearSolver/Iterative
LinearSystem
SolidMechanics/FEM/Elastic
SolidMechanics/Spring
Topology/Container/Grid
)
if(SP3_WITH_SOFAEXPORTER)
list(APPEND COMPONENTBINDINGS_MODULE_LIST IO/Mesh)
endif()

set_property(GLOBAL PROPERTY SP3_COMPONENT_BINDING_TARGETS "")
set_property(GLOBAL PROPERTY SP3_COMPONENT_BINDING_SOFA_MODULES "")
foreach(binding_dir ${COMPONENTBINDINGS_MODULE_LIST})
string(REPLACE "/" "." sofa_module "Sofa.Component.${binding_dir}")
sofa_find_package(${sofa_module} QUIET)
if(${sofa_module}_FOUND)
message(STATUS "Adding binding module ${sofa_module}")
add_subdirectory(${binding_dir})
else()
message(STATUS "${sofa_module} not found: its python bindings will not be compiled.")
endif()
endforeach()
get_property(COMPONENTBINDINGS_TARGETS GLOBAL PROPERTY SP3_COMPONENT_BINDING_TARGETS)
get_property(COMPONENTBINDINGS_SOFA_MODULES GLOBAL PROPERTY SP3_COMPONENT_BINDING_SOFA_MODULES)

add_library(${PROJECT_NAME} INTERFACE)
add_library(SofaPython3::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME} INTERFACE ${COMPONENTBINDINGS_TARGETS})

# Deprecated names (Sofa.SofaDeformable, SofaExporter, Bindings.Modules, ...)
add_subdirectory(legacy)

if(SP3_BUILD_TEST)
add_subdirectory(tests)
endif()

sofa_create_component_in_package_with_targets(
COMPONENT_NAME ${PROJECT_NAME}
COMPONENT_VERSION ${SofaPython3_VERSION}
PACKAGE_NAME SofaPython3
TARGETS ${PROJECT_NAME}
)
16 changes: 16 additions & 0 deletions bindings/Component/Constraint/Lagrangian/Solver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
project(Bindings.Component.Constraint.Lagrangian.Solver)

set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Sofa/Component/Constraint/Lagrangian/Solver/Binding_ConstraintSolver.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Sofa/Component/Constraint/Lagrangian/Solver/Binding_ConstraintSolver_doc.h
)

set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Sofa/Component/Constraint/Lagrangian/Solver/Binding_ConstraintSolver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Sofa/Component/Constraint/Lagrangian/Solver/Module_Solver.cpp
)

SP3_add_component_binding(Sofa.Component.Constraint.Lagrangian.Solver
SOURCES ${SOURCE_FILES}
HEADERS ${HEADER_FILES}
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*******************************************************************************
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <SofaPython3/SofaConstraintSolver/Binding_ConstraintSolver.h>
#include <SofaPython3/SofaConstraintSolver/Binding_ConstraintSolver_doc.h>
#include <SofaPython3/Sofa/Component/Constraint/Lagrangian/Solver/Binding_ConstraintSolver.h>
#include <SofaPython3/Sofa/Component/Constraint/Lagrangian/Solver/Binding_ConstraintSolver_doc.h>
#include <pybind11/pybind11.h>
#include <pybind11/eigen.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
******************************************************************************/

#include <pybind11/pybind11.h>
#include <SofaPython3/SofaConstraintSolver/Binding_ConstraintSolver.h>
#include <SofaPython3/Sofa/Component/Constraint/Lagrangian/Solver/Binding_ConstraintSolver.h>

namespace sofapython3
{

PYBIND11_MODULE(SofaConstraintSolver, m)
PYBIND11_MODULE(Solver, m)
{
m.doc() = "Implements the solver for constraint problems";

Expand Down
19 changes: 19 additions & 0 deletions bindings/Component/IO/Mesh/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
project(Bindings.Component.IO.Mesh)

set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Sofa/Component/IO/Mesh/Binding_STLExporter.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Sofa/Component/IO/Mesh/Binding_STLExporter_doc.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Sofa/Component/IO/Mesh/Binding_VisualModelOBJExporter.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Sofa/Component/IO/Mesh/Binding_VisualModelOBJExporter_doc.h
)

set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Sofa/Component/IO/Mesh/Binding_STLExporter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Sofa/Component/IO/Mesh/Binding_VisualModelOBJExporter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Sofa/Component/IO/Mesh/Module_Mesh.cpp
)

SP3_add_component_binding(Sofa.Component.IO.Mesh
SOURCES ${SOURCE_FILES}
HEADERS ${HEADER_FILES}
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
******************************************************************************/

#include <SofaPython3/Sofa/Core/Binding_Base.h>
#include <SofaExporter/Binding_STLExporter.h>
#include <SofaExporter/Binding_STLExporter_doc.h>
#include <SofaPython3/Sofa/Component/IO/Mesh/Binding_STLExporter.h>
#include <SofaPython3/Sofa/Component/IO/Mesh/Binding_STLExporter_doc.h>

#include <SofaPython3/PythonFactory.h>
#include <SofaPython3/Sofa/Core/Binding_BaseComponent.h>
Expand All @@ -41,7 +41,7 @@ void moduleAddSTLExporter(py::module &m)
return py::cast(dynamic_cast<STLExporter*>(object));
});

py::class_<STLExporter, sofa::core::objectmodel::BaseComponent, py_shared_ptr<STLExporter>> p(m, "STLExporter", sofapython3::doc::SofaExporter::STLExporter::docstring);
py::class_<STLExporter, sofa::core::objectmodel::BaseComponent, py_shared_ptr<STLExporter>> p(m, "STLExporter", sofapython3::doc::io::mesh::STLExporter::docstring);

p.def("write", &STLExporter::write);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#pragma once


namespace sofapython3::doc::SofaExporter::STLExporter
namespace sofapython3::doc::io::mesh::STLExporter
{

static auto docstring =
Expand All @@ -35,7 +35,7 @@ static auto docstring =
.. code-block:: python

import Sofa
import SofaExporter
import Sofa.Component.IO.Mesh

# Create a new node
n = Sofa.Core.Node("root"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
******************************************************************************/

#include <SofaPython3/Sofa/Core/Binding_Base.h>
#include <SofaExporter/Binding_VisualModelOBJExporter.h>
#include <SofaExporter/Binding_VisualModelOBJExporter_doc.h>
#include <SofaPython3/Sofa/Component/IO/Mesh/Binding_VisualModelOBJExporter.h>
#include <SofaPython3/Sofa/Component/IO/Mesh/Binding_VisualModelOBJExporter_doc.h>

#include <SofaPython3/PythonFactory.h>
#include <SofaPython3/Sofa/Core/Binding_BaseComponent.h>
Expand All @@ -39,7 +39,7 @@ void moduleAddVisualModelOBJExporter(py::module &m)
return py::cast(dynamic_cast<VisualModelOBJExporter*>(object));
});

py::class_<VisualModelOBJExporter, sofa::core::objectmodel::BaseComponent, py_shared_ptr<VisualModelOBJExporter>> p(m, "VisualModelOBJExporter", sofapython3::doc::SofaExporter::VisualModelOBJExporter::docstring);
py::class_<VisualModelOBJExporter, sofa::core::objectmodel::BaseComponent, py_shared_ptr<VisualModelOBJExporter>> p(m, "VisualModelOBJExporter", sofapython3::doc::io::mesh::VisualModelOBJExporter::docstring);

p.def("write", &VisualModelOBJExporter::write);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#pragma once

namespace sofapython3::doc::SofaExporter::VisualModelOBJExporter {
namespace sofapython3::doc::io::mesh::VisualModelOBJExporter {

static auto docstring =
R"(
Expand All @@ -33,7 +33,7 @@ static auto docstring =
.. code-block:: python

import Sofa
import SofaExporter
import Sofa.Component.IO.Mesh

# Create a new node
n = Sofa.Core.Node("root"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@
#include <pybind11/eval.h>
namespace py = pybind11;

#include <SofaExporter/Binding_STLExporter.h>
#include <SofaExporter/Binding_VisualModelOBJExporter.h>
#include <SofaPython3/Sofa/Component/IO/Mesh/Binding_STLExporter.h>
#include <SofaPython3/Sofa/Component/IO/Mesh/Binding_VisualModelOBJExporter.h>

namespace sofapython3
{

PYBIND11_MODULE(SofaExporter, m) {
PYBIND11_MODULE(Mesh, m) {
m.doc() = R"doc(
Export in STL or OBJ from from a SOFA simulation

Example:
.. code-block:: python

import SofaExporter
import Sofa.Component.IO.Mesh

)doc";

Expand Down
16 changes: 16 additions & 0 deletions bindings/Component/LinearSolver/Iterative/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
project(Bindings.Component.LinearSolver.Iterative)

set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Sofa/Component/LinearSolver/Iterative/Binding_LinearSolver.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Sofa/Component/LinearSolver/Iterative/Binding_LinearSolver_doc.h
)

set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Sofa/Component/LinearSolver/Iterative/Binding_LinearSolver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/SofaPython3/Sofa/Component/LinearSolver/Iterative/Module_Iterative.cpp
)

SP3_add_component_binding(Sofa.Component.LinearSolver.Iterative
SOURCES ${SOURCE_FILES}
HEADERS ${HEADER_FILES}
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*******************************************************************************
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <SofaPython3/SofaLinearSolver/Binding_LinearSolver.h>
#include <SofaPython3/SofaLinearSolver/Binding_LinearSolver_doc.h>
#include <SofaPython3/Sofa/Component/LinearSolver/Iterative/Binding_LinearSolver.h>
#include <SofaPython3/Sofa/Component/LinearSolver/Iterative/Binding_LinearSolver_doc.h>
#include <pybind11/pybind11.h>

#include <SofaPython3/Sofa/Core/Binding_Base.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
******************************************************************************/

#include <pybind11/pybind11.h>
#include <SofaPython3/SofaLinearSolver/Binding_LinearSolver.h>
#include <SofaPython3/Sofa/Component/LinearSolver/Iterative/Binding_LinearSolver.h>

namespace sofapython3
{

PYBIND11_MODULE(SofaLinearSolver, m)
PYBIND11_MODULE(Iterative, m)
{
moduleAddLinearSolver(m);
}
Expand Down
Loading
Loading