Skip to content

Commit 09c18ed

Browse files
authored
add bindings to retrieve config directories (#499)
1 parent 673e953 commit 09c18ed

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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: [email protected] *
19+
******************************************************************************/
20+
21+
#include <pybind11/pybind11.h>
22+
23+
#include <SofaPython3/Sofa/Helper/Binding_Utils.h>
24+
#include <SofaPython3/PythonFactory.h>
25+
26+
#include <sofa/helper/Utils.h>
27+
28+
/// Makes an alias for the pybind11 namespace to increase readability.
29+
namespace py { using namespace pybind11; }
30+
31+
namespace sofapython3
32+
{
33+
34+
void moduleAddUtils(py::module &m) {
35+
py::class_<sofa::helper::Utils> utils(m, "Utils");
36+
utils.doc() = "Utility class with convenient functions.";
37+
38+
const auto GetSofaUserLocalDirectoryDoc = R"doc(
39+
Get the directory where is stored the sofa configuration.
40+
)doc";
41+
utils.def_static("GetSofaUserLocalDirectory", &sofa::helper::Utils::getSofaUserLocalDirectory, GetSofaUserLocalDirectoryDoc);
42+
43+
const auto GetSofaDataDirectoryDoc = R"doc(
44+
Get the directory where is stored the sofa output data such as screenshots.
45+
)doc";
46+
utils.def_static("GetSofaDataDirectory", &sofa::helper::Utils::getSofaDataDirectory, GetSofaDataDirectoryDoc);
47+
}
48+
49+
50+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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: [email protected] *
19+
******************************************************************************/
20+
21+
#pragma once
22+
23+
#include <pybind11/pybind11.h>
24+
25+
namespace sofapython3
26+
{
27+
28+
void moduleAddUtils(pybind11::module &m);
29+
30+
}

bindings/Sofa/src/SofaPython3/Sofa/Helper/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
project(Bindings.Sofa.Helper)
22

33
set(HEADER_FILES
4+
${CMAKE_CURRENT_SOURCE_DIR}/Binding_Utils.h
45
${CMAKE_CURRENT_SOURCE_DIR}/Binding_Vector.h
56
${CMAKE_CURRENT_SOURCE_DIR}/System/Submodule_System.h
67
${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageHandler.h
@@ -10,6 +11,7 @@ set(HEADER_FILES
1011
set(SOURCE_FILES
1112
${CMAKE_CURRENT_SOURCE_DIR}/Submodule_Helper.cpp
1213
${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageHandler.cpp
14+
${CMAKE_CURRENT_SOURCE_DIR}/Binding_Utils.cpp
1315
${CMAKE_CURRENT_SOURCE_DIR}/Binding_Vector.cpp
1416
${CMAKE_CURRENT_SOURCE_DIR}/System/Submodule_System.cpp
1517
${CMAKE_CURRENT_SOURCE_DIR}/System/Binding_FileRepository.cpp

bindings/Sofa/src/SofaPython3/Sofa/Helper/Submodule_Helper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <SofaPython3/Sofa/Helper/System/Submodule_System.h>
2626
#include <SofaPython3/Sofa/Helper/Binding_MessageHandler.h>
2727
#include <SofaPython3/Sofa/Helper/Binding_Vector.h>
28+
#include <SofaPython3/Sofa/Helper/Binding_Utils.h>
2829

2930
/// Makes an alias for the pybind11 namespace to increase readability.
3031
namespace py { using namespace pybind11; }
@@ -151,6 +152,7 @@ PYBIND11_MODULE(Helper, helper)
151152
moduleAddMessageHandler(helper);
152153
moduleAddVector(helper);
153154
moduleAddSystem(helper);
155+
moduleAddUtils(helper);
154156

155157
auto atexit = py::module_::import("atexit");
156158
atexit.attr("register")(py::cpp_function([]() {

0 commit comments

Comments
 (0)