Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SofaExporter] Move bindings from SofaPython #1095

Merged
merged 4 commits into from Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions CMakeLists.txt
Expand Up @@ -222,18 +222,18 @@ add_subdirectory(SofaGeneral)
add_subdirectory(SofaAdvanced)
add_subdirectory(SofaMisc)

## Modules
## in the consortium convention a module is a similar to a plugin the difference is that
## a module is hosted and managed by the consortium while plugins are hosted and managed by third parties.
add_subdirectory(modules)

# This is all the applications GUI stuff. As there is a dependency to this one
# In scene creator and SofaPython...it is located here.
add_subdirectory(SofaGui)

# SofaTest depends on SofaPython, so we add SofaPython before SofaTest.
# SofaTest, modules depend on SofaPython, so we add SofaPython before.
sofa_add_plugin( applications/plugins/SofaPython SofaPython )

## Modules
## in the consortium convention a module is a similar to a plugin the difference is that
## a module is hosted and managed by the consortium while plugins are hosted and managed by third parties.
add_subdirectory(modules)

## Scene creator option
option(SOFA_BUILD_SCENECREATOR "Compile the C++ API located in applications/plugins/SceneCreator" OFF)

Expand Down
4 changes: 0 additions & 4 deletions applications/plugins/SofaPython/Binding.cpp
Expand Up @@ -58,8 +58,6 @@
#include "Binding_SparseGridTopology.h"
#include "Binding_SubsetMultiMapping.h"
#include "Binding_VisualModel.h"
#include "Binding_OBJExporter.h"
#include "Binding_STLExporter.h"
#include "Binding_DataEngine.h"
#include "PythonFactory.h"

Expand Down Expand Up @@ -121,8 +119,6 @@ void bindSofaPythonModule(PyObject * module)
SP_ADD_CLASS_IN_FACTORY(GridTopology,sofa::component::topology::GridTopology)
SP_ADD_CLASS_IN_FACTORY(SparseGridTopology,sofa::component::topology::SparseGridTopology)
SP_ADD_CLASS_IN_FACTORY(RegularGridTopology,sofa::component::topology::RegularGridTopology)
SP_ADD_CLASS_IN_FACTORY(OBJExporter,sofa::component::misc::OBJExporter)
SP_ADD_CLASS_IN_FACTORY(STLExporter,sofa::component::misc::STLExporter)
SP_ADD_CLASS_IN_FACTORY(PythonScriptController,sofa::component::controller::PythonScriptController)
SP_ADD_CLASS_IN_FACTORY(PythonScriptDataEngine,sofa::component::controller::PythonScriptDataEngine)
SP_ADD_CLASS_IN_FACTORY(PointSetTopologyModifier,sofa::component::topology::PointSetTopologyModifier)
Expand Down
21 changes: 3 additions & 18 deletions applications/plugins/SofaPython/CMakeLists.txt
Expand Up @@ -38,8 +38,6 @@ set(HEADER_FILES
Binding_MeshTopology.h
Binding_MultiMapping.h
Binding_Node.h
Binding_OBJExporter.h
Binding_STLExporter.h
Binding_PythonScriptController.h
Binding_PythonScriptDataEngine.h
Binding_RegularGridTopology.h
Expand Down Expand Up @@ -100,8 +98,6 @@ set(SOURCE_FILES
Binding_MeshTopology.cpp
Binding_MultiMapping.cpp
Binding_Node.cpp
Binding_OBJExporter.cpp
Binding_STLExporter.cpp
Binding_PythonScriptController.cpp
Binding_PythonScriptDataEngine.cpp
Binding_RegularGridTopology.cpp
Expand Down Expand Up @@ -151,19 +147,6 @@ find_package(PythonLibs 2.7 REQUIRED)
find_package(SofaGui REQUIRED)
find_package(SofaGeneral REQUIRED)
find_package(SofaMisc REQUIRED)
find_package(SofaExporter)

if(SofaExporter_FOUND)
list(APPEND SOURCE_FILES
Binding_OBJExporter.cpp
Binding_STLExporter.cpp
)

list(APPEND HEADER_FILES
Binding_OBJExporter.h
Binding_STLExporter.h
)
endif()

GET_FILENAME_COMPONENT(LIBRARY_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX} NAME_WE)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
Expand All @@ -187,14 +170,16 @@ endif()

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${PYTHON_FILES})

target_compile_definitions(${PROJECT_NAME} PUBLIC "-DSOFA_HAVE_SOFAPYTHON")

target_include_directories(${PROJECT_NAME}
PUBLIC ${PYTHON_INCLUDE_DIRS}
PUBLIC "$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/>"
PUBLIC "$<INSTALL_INTERFACE:include>"
)

target_link_libraries(${PROJECT_NAME} PUBLIC SofaSimulationCommon SofaUserInteraction SofaGuiCommon SofaComponentMisc SofaComponentGeneral ${PYTHON_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PRIVATE SofaExporter)

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
# dlopen() is used on Linux for a workaround (see PythonEnvironnement.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE dl)
Expand Down
17 changes: 17 additions & 0 deletions modules/SofaExporter/CMakeLists.txt
Expand Up @@ -42,8 +42,25 @@ list(APPEND SOURCE_FILES
src/SofaExporter/WriteTopology.cpp
)

find_package(SofaPython QUIET)
if(SofaPython_FOUND)
list(APPEND HEADER_FILES
src/SofaExporter/bindings/Binding_OBJExporter.h
src/SofaExporter/bindings/Binding_STLExporter.h
)
list(APPEND SOURCE_FILES
src/SofaExporter/bindings/Binding_OBJExporter.cpp
src/SofaExporter/bindings/Binding_STLExporter.cpp
)
else()
message(STATUS "SofaPython disabled, will not compile python bindings.")
endif()

add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES} ${EXTRA_FILES})
target_link_libraries(${PROJECT_NAME} PUBLIC SofaSimulationTree)
if(SofaPython_FOUND)
target_link_libraries(${PROJECT_NAME} PRIVATE SofaPython)
endif()
target_compile_definitions(${PROJECT_NAME} PRIVATE "-DSOFA_BUILD_EXPORTER")
target_compile_definitions(${PROJECT_NAME} PUBLIC "-DSOFA_HAVE_SOFAEXPORTER")
target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>")
Expand Down
Expand Up @@ -22,8 +22,8 @@


#include "Binding_OBJExporter.h"
#include "Binding_BaseObject.h"
#include "PythonToSofa.inl"
#include <SofaPython/Binding_BaseObject.h>
#include <SofaPython/PythonToSofa.inl>

using namespace sofa::component::misc;
using namespace sofa::core::objectmodel;
Expand Down
Expand Up @@ -22,7 +22,7 @@
#ifndef BINDING_OBJEXPORTER_H
#define BINDING_OBJEXPORTER_H

#include "PythonMacros.h"
#include <SofaPython/PythonMacros.h>

#include <SofaExporter/OBJExporter.h>

Expand Down
Expand Up @@ -22,8 +22,8 @@


#include "Binding_STLExporter.h"
#include "Binding_BaseObject.h"
#include "PythonToSofa.inl"
#include <SofaPython/Binding_BaseObject.h>
#include <SofaPython/PythonToSofa.inl>

using namespace sofa::component::misc;
using namespace sofa::core::objectmodel;
Expand Down
Expand Up @@ -22,7 +22,7 @@
#ifndef BINDING_STLEXPORTER_H
#define BINDING_STLEXPORTER_H

#include "PythonMacros.h"
#include <SofaPython/PythonMacros.h>

#include <SofaExporter/STLExporter.h>

Expand Down
20 changes: 20 additions & 0 deletions modules/SofaExporter/src/SofaExporter/initExporter.cpp
Expand Up @@ -23,6 +23,20 @@
#include <SofaExporter/config.h>

#include <sofa/core/ObjectFactory.h>

#if SOFA_HAVE_SOFAPYTHON
#include <SofaPython/PythonEnvironment.h>
#include <SofaPython/PythonFactory.h>

using sofa::simulation::PythonEnvironment ;
using sofa::PythonFactory ;

#include <SofaExporter/bindings/Binding_OBJExporter.h>
#include <SofaExporter/bindings/Binding_STLExporter.h>

#endif // SOFA_HAVE_SOFAPYTHON


using sofa::core::ObjectFactory;

namespace sofa
Expand All @@ -46,6 +60,12 @@ void initExternalModule()
if (first)
{
first = false;
#ifdef SOFA_HAVE_SOFAPYTHON
{
SP_ADD_CLASS_IN_FACTORY(OBJExporter,sofa::component::misc::OBJExporter)
SP_ADD_CLASS_IN_FACTORY(STLExporter,sofa::component::misc::STLExporter)
}
#endif
}
}

Expand Down