From 01202b12a8fce26b01549220fda0773a2ec79137 Mon Sep 17 00:00:00 2001 From: Frederick Roy Date: Mon, 26 May 2025 14:50:02 +0900 Subject: [PATCH] add bindings to retrieve config directories --- .../SofaPython3/Sofa/Helper/Binding_Utils.cpp | 50 +++++++++++++++++++ .../SofaPython3/Sofa/Helper/Binding_Utils.h | 30 +++++++++++ .../SofaPython3/Sofa/Helper/CMakeLists.txt | 2 + .../Sofa/Helper/Submodule_Helper.cpp | 2 + 4 files changed, 84 insertions(+) create mode 100644 bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_Utils.cpp create mode 100644 bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_Utils.h diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_Utils.cpp b/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_Utils.cpp new file mode 100644 index 000000000..6996b56c6 --- /dev/null +++ b/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_Utils.cpp @@ -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 . * +******************************************************************************* +* Contact information: contact@sofa-framework.org * +******************************************************************************/ + +#include + +#include +#include + +#include + +/// Makes an alias for the pybind11 namespace to increase readability. +namespace py { using namespace pybind11; } + +namespace sofapython3 +{ + +void moduleAddUtils(py::module &m) { + py::class_ utils(m, "Utils"); + utils.doc() = "Utility class with convenient functions."; + + const auto GetSofaUserLocalDirectoryDoc = R"doc( + Get the directory where is stored the sofa configuration. + )doc"; + utils.def_static("GetSofaUserLocalDirectory", &sofa::helper::Utils::getSofaUserLocalDirectory, GetSofaUserLocalDirectoryDoc); + + const auto GetSofaDataDirectoryDoc = R"doc( + Get the directory where is stored the sofa output data such as screenshots. + )doc"; + utils.def_static("GetSofaDataDirectory", &sofa::helper::Utils::getSofaDataDirectory, GetSofaDataDirectoryDoc); +} + + +} diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_Utils.h b/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_Utils.h new file mode 100644 index 000000000..33085e1e6 --- /dev/null +++ b/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_Utils.h @@ -0,0 +1,30 @@ +/****************************************************************************** +* 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 . * +******************************************************************************* +* Contact information: contact@sofa-framework.org * +******************************************************************************/ + +#pragma once + +#include + +namespace sofapython3 +{ + + void moduleAddUtils(pybind11::module &m); + +} diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Helper/CMakeLists.txt b/bindings/Sofa/src/SofaPython3/Sofa/Helper/CMakeLists.txt index 33abea3c9..b65f18044 100644 --- a/bindings/Sofa/src/SofaPython3/Sofa/Helper/CMakeLists.txt +++ b/bindings/Sofa/src/SofaPython3/Sofa/Helper/CMakeLists.txt @@ -1,6 +1,7 @@ project(Bindings.Sofa.Helper) set(HEADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/Binding_Utils.h ${CMAKE_CURRENT_SOURCE_DIR}/Binding_Vector.h ${CMAKE_CURRENT_SOURCE_DIR}/System/Submodule_System.h ${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageHandler.h @@ -10,6 +11,7 @@ set(HEADER_FILES set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/Submodule_Helper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageHandler.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Binding_Utils.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Binding_Vector.cpp ${CMAKE_CURRENT_SOURCE_DIR}/System/Submodule_System.cpp ${CMAKE_CURRENT_SOURCE_DIR}/System/Binding_FileRepository.cpp diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Helper/Submodule_Helper.cpp b/bindings/Sofa/src/SofaPython3/Sofa/Helper/Submodule_Helper.cpp index 19f33fb49..4c80cb148 100644 --- a/bindings/Sofa/src/SofaPython3/Sofa/Helper/Submodule_Helper.cpp +++ b/bindings/Sofa/src/SofaPython3/Sofa/Helper/Submodule_Helper.cpp @@ -25,6 +25,7 @@ #include #include #include +#include /// Makes an alias for the pybind11 namespace to increase readability. namespace py { using namespace pybind11; } @@ -151,6 +152,7 @@ PYBIND11_MODULE(Helper, helper) moduleAddMessageHandler(helper); moduleAddVector(helper); moduleAddSystem(helper); + moduleAddUtils(helper); auto atexit = py::module_::import("atexit"); atexit.attr("register")(py::cpp_function([]() {