diff --git a/CMakeLists.txt b/CMakeLists.txt index 24529cf0..5e2f8370 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,9 @@ if(MSVC) # With C++17 (/std:c++17), to get MSVC to behave, you need /permissive- # see https://github.com/pybind/pybind11/issues/1616 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-") + + # use M_PI in cmath.h + add_definitions("-D_USE_MATH_DEFINES") endif() set(CMAKE_CXX_STANDARD 17) @@ -172,13 +175,23 @@ if (SP3_LINK_TO_USER_SITE AND SP3_PYTHON_PACKAGES_LINK_DIRECTORY) install(DIRECTORY DESTINATION ${SP3_PYTHON_PACKAGES_LINK_DIRECTORY}) foreach(directory ${directories}) if(IS_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_DIRECTORY}/${directory}) - install(CODE "\ + if(WIN32) + install(CODE "\ execute_process( \ - COMMAND ${CMAKE_COMMAND} -E create_symlink \ + COMMAND ${CMAKE_COMMAND} -E copy_directory \ ${CMAKE_INSTALL_PREFIX}/${LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_DIRECTORY}/${directory}/ \ ${SP3_PYTHON_PACKAGES_LINK_DIRECTORY}/${directory} \ )" ) + else() + install(CODE "\ + execute_process( \ + COMMAND ${CMAKE_COMMAND} -E create_symlink \ + ${CMAKE_INSTALL_PREFIX}/${LIBRARY_OUTPUT_DIRECTORY}/${SP3_PYTHON_PACKAGES_DIRECTORY}/${directory}/ \ + ${SP3_PYTHON_PACKAGES_LINK_DIRECTORY}/${directory} \ + )" + ) + endif() endif() endforeach() endif() diff --git a/Plugin/src/SofaPython3/DataHelper.h b/Plugin/src/SofaPython3/DataHelper.h index 6a46f0a1..75cd2a7b 100644 --- a/Plugin/src/SofaPython3/DataHelper.h +++ b/Plugin/src/SofaPython3/DataHelper.h @@ -205,12 +205,10 @@ class SOFAPYTHON3_API PythonTrampoline template class py_shared_ptr : public sofa::core::sptr { public: - py_shared_ptr(T *ptr) : sofa::core::sptr(ptr) - { - auto nptr = dynamic_cast(ptr); - if(nptr) - nptr->setInstance( py::cast(ptr) ) ; - } + using Base = typename sofa::core::sptr; + using Base::Base; + py_shared_ptr(const py_shared_ptr& other, T* ptr) : sofa::core::sptr(ptr) {} + py_shared_ptr(T* ptr) : sofa::core::sptr(ptr) {} }; SOFAPYTHON3_API void setItem2D(py::array a, py::slice slice, py::object o); diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Controller.cpp b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Controller.cpp index a49dedae..f57669cf 100644 --- a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Controller.cpp +++ b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Controller.cpp @@ -26,6 +26,7 @@ along with sofaqtquick. If not, see . ********************************************************************/ #include +#include #include "Binding_Controller.h" #include "Binding_Controller_doc.h" @@ -42,39 +43,6 @@ namespace sofapython3 { using sofa::core::objectmodel::Event; - void Controller::init() { - } - - void Controller::reinit() { - } - - Controller::Controller() { - } - - Controller::~Controller() { - } - - class Controller_Trampoline : public Controller, public PythonTrampoline - { - public: - Controller_Trampoline() = default; - - ~Controller_Trampoline() override = default; - - std::string getClassName() const override - { - return pyobject->ob_type->tp_name; - } - - void init() override ; - void reinit() override ; - void handleEvent(Event* event) override ; - - private: - void callScriptMethod(const py::object& self, Event* event, - const std::string & methodName); - }; - void Controller_Trampoline::init() { PythonEnvironment::gil acquire {"Controller_init"}; @@ -120,39 +88,36 @@ namespace sofapython3 callScriptMethod(self, event, "onEvent"); } - - void moduleAddController(py::module &m) { py::class_> f(m, "Controller", py::dynamic_attr(), - py::multiple_inheritance(), sofapython3::doc::controller::Controller); f.def(py::init([](py::args& /*args*/, py::kwargs& kwargs) { - auto c = new Controller_Trampoline(); - c->f_listening.setValue(true); - - for(auto kv : kwargs) - { - std::string key = py::cast(kv.first); - py::object value = py::reinterpret_borrow(kv.second); - - if( key == "name") - c->setName(py::cast(kv.second)); - try { - BindingBase::SetAttr(*c, key, value); - } catch (py::attribute_error& /*e*/) { - /// kwargs are used to set datafields to their initial values, - /// but they can also be used as simple python attributes, unrelated to SOFA. - /// thus we catch & ignore the py::attribute_error thrown by SetAttr - } - } - return c; - })); + auto c = new Controller_Trampoline(); + c->f_listening.setValue(true); + + for(auto kv : kwargs) + { + std::string key = py::cast(kv.first); + py::object value = py::reinterpret_borrow(kv.second); + + if( key == "name") + c->setName(py::cast(kv.second)); + try { + BindingBase::SetAttr(*c, key, value); + } catch (py::attribute_error& /*e*/) { + /// kwargs are used to set datafields to their initial values, + /// but they can also be used as simple python attributes, unrelated to SOFA. + /// thus we catch & ignore the py::attribute_error thrown by SetAttr + } + } + return c; + })); f.def("init", &Controller::init); f.def("reinit", &Controller::reinit); diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Controller.h b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Controller.h index 6edc7a6e..bd1acdaa 100644 --- a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Controller.h +++ b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Controller.h @@ -26,16 +26,11 @@ along with sofaqtquick. If not, see . ********************************************************************/ #pragma once - #include "Binding_BaseObject.h" +#include #include -template class pybind11::class_>; - - namespace sofapython3 { using sofa::core::behavior::BaseController; @@ -44,14 +39,30 @@ class Controller : public BaseController { public: SOFA_CLASS(Controller, BaseController); - void init() override ; - void reinit() override; + void init() override {}; + void reinit() override {}; - Controller(); - ~Controller() override; + Controller() {}; + ~Controller() override {}; }; void moduleAddController(py::module &m); +class Controller_Trampoline : public Controller +{ +public: + Controller_Trampoline() = default; + + ~Controller_Trampoline() override = default; + + void init() override; + void reinit() override; + void handleEvent(sofa::core::objectmodel::Event* event) override; + +private: + void callScriptMethod(const py::object& self, sofa::core::objectmodel::Event* event, + const std::string& methodName); +}; + } /// namespace sofapython3