Skip to content

Commit

Permalink
[SofaImGui] add python3-loadable module (#95)
Browse files Browse the repository at this point in the history
* add imgui as a py3 loadable module

* fix typo
  • Loading branch information
fredroy authored Nov 16, 2023
1 parent 5c1ef79 commit c5c72c1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
5 changes: 5 additions & 0 deletions SofaImGui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ target_link_libraries(${PROJECT_NAME} PUBLIC SofaGLFW Sofa.GL.Component.Renderin
set_target_properties(nfd PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(${PROJECT_NAME} PRIVATE nfd glfw)

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

sofa_create_package_with_targets(
PACKAGE_NAME ${PROJECT_NAME}
PACKAGE_VERSION ${Sofa_VERSION}
Expand Down
20 changes: 20 additions & 0 deletions SofaImGui/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
project(Bindings_SofaImGui)

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

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

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

)
message("-- SofaPython3 bindings for SofaImGui will be created.")
36 changes: 36 additions & 0 deletions SofaImGui/bindings/Module_SofaImGui.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 <SofaImGui/init.h>


namespace py { using namespace pybind11; }

namespace sofaimgui::python3
{

PYBIND11_MODULE(SofaImGui, m)
{
sofaimgui::init();
}

} // namespace sofaimgui::python3
7 changes: 5 additions & 2 deletions SofaImGui/src/SofaImGui/ImGuiGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ sofa::gui::common::BaseGUI* ImGuiGUI::CreateGUI(const char* name, sofa::simulati
{
return nullptr;
}

gui->setScene(groot, filename);

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

return gui;
}
Expand Down

0 comments on commit c5c72c1

Please sign in to comment.