pythonocc-core icon indicating copy to clipboard operation
pythonocc-core copied to clipboard

Guidance Needed: Passing TopoDS_Shape from C++ to Python using SWIG bindings

Open kieganlenihan opened this issue 2 years ago • 0 comments

I am currently working on a project where I need to pass a TopoDS_Shape object from C++ to a Python function. I have been using pythonocc-core for processing STEP files and am familiar with its functionality. My application is structured such that the C++ code handles reading in STEP files from file, and third party python libraries (built around pythonocc-core) are used for converting a BRep into a graph (along with some other functionality).

What I Have Tried

I have looked into the pythonocc-core SWIG bindings and found a typemap in src/SWIG_files/common/FunctionTransformers.i that seems to handle the conversion of TopoDS_Shape objects to Python objects.

%typemap(out) TopoDS_Shape {
    // ...
}

However, I am not entirely sure how to utilize this in my project. I am relatively new to interfacing C++ with Python, especially with complex objects like those in OpenCASCADE. I have used pybind11 in other parts of my project to pass tabular data into a python function from C++, but that problem didn't require type conversion.

Questions

  • Can I use the existing SWIG typemaps from pythonocc-core to convert a TopoDS_Shape object to a Python object directly in my C++ code?
  • If not, is there a recommended approach or example on how to pass TopoDS_Shape objects from C++ to Python using pythonocc-core?
  • Are there any examples or documentation available that could guide me through this process?

I would greatly appreciate any guidance or examples that the community could provide on this topic, as it is crucial for the progress of my project.

Thank you in advance for your time and help.

Environment

  • OS: MacOS 11.5.2
  • Python version: 3.11.4
  • pythonocc-core version: 7.7.0

kieganlenihan avatar Oct 31 '23 18:10 kieganlenihan