Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions OCP_specific.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <Standard_Handle.hxx>
#include <type_traits>
#include <memory>
#include <fmt/format.h>

namespace py = pybind11;

Expand Down Expand Up @@ -46,6 +47,13 @@ inline void copy_if_copy_constructible(T& t1, T& t2){

};

template <typename T> inline opencascade::handle<T> cast_pyobject(const py::object &arg){
if(py::isinstance(arg, py::type::of<T>()))
return opencascade::handle(py::cast<T*>(arg));
else
throw py::value_error(fmt::format("Cannot convert the argument to the required type {}", typeid(T).name()));
};

template<typename T, template<typename> typename Deleter = std::default_delete>
struct shared_ptr : public std::shared_ptr<T>{
explicit shared_ptr(T* t = nullptr) : std::shared_ptr<T>(t, Deleter<T>()) {};
Expand Down
1 change: 1 addition & 0 deletions environment.devenv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies:
{% else %}
- cxx-compiler
- tbb-devel # [win]
- fmt
- pip:
- git+https://github.com/CadQuery/pybind11-stubgen.git
{% endif %}
33 changes: 32 additions & 1 deletion ocp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ modules = [
"Quantity",
"Storage",
"FSD",
"MMgt",
"TCollection",
"TColStd",
"Message",
Expand Down Expand Up @@ -493,6 +492,20 @@ void register_template_NCollection_Vector(py::object &m, const char *name){
[Modules.TCollection]

exclude_methods = ["TCollection_ExtendedString::ToUTF8CString"]
include_body_post = """py::implicitly_convertible<std::string, TCollection_HAsciiString>();
py::implicitly_convertible<std::string, TCollection_AsciiString>();"""

[[Modules.TCollection.Classes.TCollection_HAsciiString.additional_constructors]]

body = "[](const std::string &s){ return TCollection_HAsciiString(s.c_str()); }"
help = "std::strings based constructor"
arguments = ["aString"]

[[Modules.TCollection.Classes.TCollection_AsciiString.additional_constructors]]

body = "[](const std::string &s){ return TCollection_AsciiString(s.c_str()); }"
help = "std::strings based constructor"
arguments = ["aString"]

[Modules.TColStd]

Expand Down Expand Up @@ -1090,6 +1103,12 @@ struct __GLXFBConfigRec {};"""

exclude_classes = ["StepData_EnumTool"]

[Modules.StepData.Classes.StepData_SelectType.additional_methods.SetValue]

body = "[](StepData_SelectType &self , py::object& ent){self.SetValue(cast_pyobject<Standard_Transient>(ent));}"
help = "SetValue supporting python objects"
arguments = ["ent"]

[Modules.LDOM]

exclude_classes = ["LDOMString","LDOM_MemManager","LDOM_BasicText"]
Expand Down Expand Up @@ -1279,6 +1298,18 @@ using rapidjson::BasicOStreamWrapper;"""

"Interface_ValueInterpret.hxx" = "#include <Interface_TypedValue.hxx>"

[Modules.Interface.Classes.Interface_InterfaceModel.additional_methods.AddEntity]

body = "[](Interface_InterfaceModel &self , py::object& ent){self.AddEntity(cast_pyobject<Standard_Transient>(ent));}"
help = "AddEntity supporting python objects"
arguments = ["anent"]

[Modules.Interface.Classes.Interface_InterfaceModel.additional_methods.AddWithRefs]

body = "[](Interface_InterfaceModel &self , py::object& ent){self.AddWithRefs(cast_pyobject<Standard_Transient>(ent));}"
help = "AddWithRefs supporting python objects"
arguments = ["anent"]

[Modules.IVtkVTK]

include_header_pre = """#include <vtkRenderer.h>
Expand Down
3 changes: 2 additions & 1 deletion templates/CMakeLists.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ message( STATUS "Python lib: ${Python_LIBRARIES}" )

SET(PYTHON_SP_DIR "site-packages" CACHE PATH "Python site-packages directory (for installing)")

find_package( fmt REQUIRED )
find_package( pybind11 REQUIRED )
find_package( VTK REQUIRED
COMPONENTS
Expand All @@ -34,7 +35,7 @@ add_library( {{ name }} MODULE ${CPP_FILES} )
target_include_directories( {{ name }} PRIVATE ${OpenCASCADE_INCLUDE_DIR} )

target_link_libraries( {{ name }} PRIVATE ${OpenCASCADE_LIBRARIES} )
target_link_libraries( {{ name }} PRIVATE pybind11::pybind11 VTK::WrappingPythonCore VTK::RenderingCore VTK::CommonDataModel VTK::CommonExecutionModel)
target_link_libraries( {{ name }} PRIVATE pybind11::pybind11 VTK::WrappingPythonCore VTK::RenderingCore VTK::CommonDataModel VTK::CommonExecutionModel fmt::fmt)

set_target_properties( {{ name }}
PROPERTIES
Expand Down