mirror of
https://github.com/NGSolve/netgen.git
synced 2025-03-19 13:07:56 +05:00
add From_PyOCC function to convert swig pyocc shape to netgen.occ
This commit is contained in:
parent
8478ff5078
commit
36c9201ffc
@ -690,6 +690,33 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m)
|
|||||||
OCCGeometry::global_shape_property_indices.Clear();
|
OCCGeometry::global_shape_property_indices.Clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
struct SwigTypeInfo
|
||||||
|
{
|
||||||
|
const char* name; // SWIG's type name string
|
||||||
|
// Other fields...
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SwigPyObject{
|
||||||
|
PyObject_HEAD
|
||||||
|
void *ptr;
|
||||||
|
SwigTypeInfo* ty; // SWIG type information
|
||||||
|
int own; // ownership flag
|
||||||
|
};
|
||||||
|
|
||||||
|
m.def("From_PyOCC", [](py::object shape)
|
||||||
|
{
|
||||||
|
py::object py_this = shape.attr("this");
|
||||||
|
PyObject* obj = py_this.ptr();
|
||||||
|
SwigPyObject* swig_obj = reinterpret_cast<SwigPyObject*>(obj);
|
||||||
|
cout << "swig type = " << swig_obj->ty->name << endl;
|
||||||
|
if (!swig_obj->ptr || !swig_obj->ty || !swig_obj->ty->name) {
|
||||||
|
throw std::runtime_error("SWIG object does not contain a valid pointer");
|
||||||
|
}
|
||||||
|
if(strcmp(swig_obj->ty->name, "_p_TopoDS_Shape") != 0)
|
||||||
|
throw std::runtime_error("Does not contain TopoDS_Shape from pyocc!");
|
||||||
|
return py::cast(static_cast<TopoDS_Shape*>(swig_obj->ptr));
|
||||||
|
}, py::return_value_policy::reference, py::keep_alive<0,1>());
|
||||||
|
|
||||||
py::class_<TopoDS_Shape> (m, "TopoDS_Shape")
|
py::class_<TopoDS_Shape> (m, "TopoDS_Shape")
|
||||||
.def("__str__", [] (const TopoDS_Shape & shape)
|
.def("__str__", [] (const TopoDS_Shape & shape)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user