Skip to content

Commit

Permalink
add glfw as a py3 loadable module (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredroy authored Nov 16, 2023
1 parent b85d7e5 commit 5c1ef79
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
5 changes: 5 additions & 0 deletions SofaGLFW/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ if(Sofa.GUI.Common_FOUND)
target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.GUI.Common)
endif()

find_package(SofaPython3 QUIET)
if(SofaPython3_FOUND)
add_subdirectory(bindings)
endif()

add_definitions("-DSOFAGLFW_RESOURCES_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/resources\"")

sofa_create_package_with_targets(
Expand Down
20 changes: 20 additions & 0 deletions SofaGLFW/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
project(Bindings_SofaGLFW)

set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/Module_SofaGLFW.cpp
)

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

SP3_add_python_module(
TARGET ${PROJECT_NAME}
PACKAGE SofaGLFW
MODULE SofaGLFW
DESTINATION /
SOURCES ${SOURCE_FILES}
DEPENDS SofaPython3::Plugin SofaPython3::Bindings.Sofa SofaGLFW

)
message("-- SofaPython3 bindings for SofaGLFW will be created.")
36 changes: 36 additions & 0 deletions SofaGLFW/bindings/Module_SofaGLFW.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2021 INRIA, USTL, UJF, CNRS, MGH *
* *
* 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: [email protected] *
******************************************************************************/

#include <pybind11/pybind11.h>

#include <SofaGLFW/init.h>


namespace py { using namespace pybind11; }

namespace sofaglfw::python3
{

PYBIND11_MODULE(SofaGLFW, m)
{
sofaglfw::init();
}

} // namespace sofaglfw::python3
9 changes: 6 additions & 3 deletions SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ sofa::gui::common::BaseGUI* SofaGLFWGUI::CreateGUI(const char* name, sofa::simul
{
return nullptr;
}

gui->setScene(groot, filename);


if(groot)
{
gui->setScene(groot, filename);
}

return gui;
}

Expand Down

0 comments on commit 5c1ef79

Please sign in to comment.