tpaviot / pythonocc-generator Goto Github PK
View Code? Open in Web Editor NEWSWIG wrapper generator for pythonocc from OpenCascade Technology C++ source code
License: GNU General Public License v3.0
SWIG wrapper generator for pythonocc from OpenCascade Technology C++ source code
License: GNU General Public License v3.0
See tpaviot/pythonocc-core#342
I would like to help in this effort as much as possible, but I will need guidance. Is it possible to make any movement on this without OCE supporting 7.0.1?
Today I've been making my first getting more familiar with the SWIG generator.
I've ran the generator over the OCE 0.17 release.
Such to index, what issues we'll have to overcome before generating bindings for OCE 0.17
This led to identifying five issues: #2 , #3 , #4 , #5
By looking into make's build targets, I've done something like:
make _BOPAlgo
make _BRepBndLib
make _XBRepMesh
make _IntAna2d
make _TColQuantity
make _Hatch
make _IntCurveSurface
make _LProp
make _Intrv
make _TopCnx
make _Approx
make _Select3D
to build all targets, even though some modules obviously won't be able to build.
I've tracked the generated errors ( see below ) as a start to help working towards pythonocc-core 0.17.
Well, its not that clear to what extent I might be able to contribute, but sure documenting the process of migrating to another OCE release might be useful.
I'm not sure whether building pythonocc 0.16 required the following flag:
-DCMAKE_CXX_FLAGS=-stdlib=libstdc++
there is more code in OCE now using the stdlib, which is a good thing I guess.
So perhaps this flag should be added to CMakeList.txt?
@tpaviot , 2 errors stand out:
Scanning dependencies of target _Visual3d
[100%] Building CXX object CMakeFiles/_Visual3d.dir/Darwin/x86_64-MinSizeRel-64/Visual3dPYTHON_wrap.cxx.o
Linking CXX shared module Darwin/x86_64-MinSizeRel-64/_Visual3d.so
Undefined symbols for architecture x86_64:
"Visual3d_HSequenceOfView::ShallowCopy() const", referenced from:
_wrap_Visual3d_HSequenceOfView_ShallowCopy(_object*, _object*) in Visual3dPYTHON_wrap.cxx.o
"Visual3d_HSequenceOfLight::ShallowCopy() const", referenced from:
_wrap_Visual3d_HSequenceOfLight_ShallowCopy(_object*, _object*) in Visual3dPYTHON_wrap.cxx.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [Darwin/x86_64-MinSizeRel-64/_Visual3d.so] Error 1
make[2]: *** [CMakeFiles/_Visual3d.dir/all] Error 2
make[1]: *** [CMakeFiles/_Visual3d.dir/rule] Error 2
make: *** [_Visual3d] Error 2
Swig source
Here's a list of the modules that didnt complete compilation:
* Undefined symbols for architecture x86_64:
"Visual3d_HSequenceOfView::ShallowCopy() const", referenced from:
_wrap_Visual3d_HSequenceOfView_ShallowCopy(_object*, _object*) in Visual3dPYTHON_wrap.cxx.o
* Undefined symbols for architecture x86_64:
"Graphic3d_HSequenceOfStructure::ShallowCopy() const", referenced from:
_wrap_Graphic3d_HSequenceOfStructure_ShallowCopy(_object*, _object*) in Graphic3dPYTHON_wrap.cxx.o
* Undefined symbols for architecture x86_64:
"IFSelect_HSeqOfSelection::ShallowCopy() const", referenced from:
_wrap_IFSelect_HSeqOfSelection_ShallowCopy(_object*, _object*) in IFSelectPYTHON_wrap.cxx.o
ld: symbol(s) not found for architecture x86_64
* Undefined symbols for architecture x86_64:
"TShort_HSequenceOfShortReal::ShallowCopy() const", referenced from:
_wrap_TShort_HSequenceOfShortReal_ShallowCopy(_object*, _object*) in TShortPYTHON_wrap.cxx.o
ld: symbol(s) not found for architecture x86_64
* Undefined symbols for architecture x86_64:
"TColGeom_HSequenceOfCurve::ShallowCopy() const", referenced from:
_wrap_TColGeom_HSequenceOfCurve_ShallowCopy(_object*, _object*) in TColGeomPYTHON_wrap.cxx.o
"TColGeom_HSequenceOfBoundedCurve::ShallowCopy() const", referenced from:
_wrap_TColGeom_HSequenceOfBoundedCurve_ShallowCopy(_object*, _object*) in TColGeomPYTHON_wrap.cxx.o
ld: symbol(s) not found for architecture x86_64
Scanning dependencies of target _Visualization
Building CXX object CMakeFiles/_Visualization.dir/Darwin/x86_64-MinSizeRel-64/VisualizationPYTHON_wrap.cxx.o
In file included from /Users/jelleferinga/GIT/pythonocc-core-occ-690/build/Darwin/x86_64-MinSizeRel-64/VisualizationPYTHON_wrap.cxx:3057:
/Users/jelleferinga/GIT/pythonocc-core-occ-690/src/Visualization/Visualization.h:28:10: fatal error: 'Graphic3d.hxx' file not found
^
Building CXX object CMakeFiles/_ShapeAlgo.dir/Darwin/x86_64-MinSizeRel-64/ShapeAlgoPYTHON_wrap.cxx.o
/Users/jelleferinga/GIT/pythonocc-core-occ-690/build/Darwin/x86_64-MinSizeRel-64/ShapeAlgoPYTHON_wrap.cxx:2208:3: error: unterminated
conditional directive
# ifdef PyWeakref_Chec
^
/Users/jelleferinga/GIT/pythonocc-core-occ-690/build/Darwin/x86_64-MinSizeRel-64/ShapeAlgoPYTHON_wrap.cxx:2206:2: error: unterminated
conditional directive
#ifdef SWIGPYTHON_BUILTIN
^
/Users/jelleferinga/GIT/pythonocc-core-occ-690/build/Darwin/x86_64-MinSizeRel-64/ShapeAlgoPYTHON_wrap.cxx:2208:23: error: expected '}'
# ifdef PyWeakref_Chec
^
/Users/jelleferinga/GIT/pythonocc-core-occ-690/build/Darwin/x86_64-MinSizeRel-64/ShapeAlgoPYTHON_wrap.cxx:2200:1: note: to match this
'{'
{
^
/Users/jelleferinga/GIT/pythonocc-core-occ-690/build/Darwin/x86_64-MinSizeRel-64/ShapeAlgoPYTHON_wrap.cxx:2208:23: error: expected '}'
# ifdef PyWeakref_Chec
^
/Users/jelleferinga/GIT/pythonocc-core-occ-690/build/Darwin/x86_64-MinSizeRel-64/ShapeAlgoPYTHON_wrap.cxx:1393:12: note: to match this
'{'
extern "C" {
^
affected modules: _BRepClass3d.so, BRepApprox.so
possible: _ChFi3d
multiprocessing.Pool would helps to speed up generating the SWIG files linearly
Hi, I’m not familiar with SWIG and I’m trying really hard to understand how to create a configuration file to wrap OCCT for c#.
Would this python generator, able to generate code for c# as well?
Thanks in advance and thanks for all the hard work you’ve invested for the community.
erros are than caught in context of the pythonocc module they're related to.
otherwise, you need to capture stderr by copy/pasting from the terminal, which isnt particularly ergonomics.
possible even more important is capturing stderr from building pythonocc, after new SWIG wrappers have been generated. possible something amongs these lines:
_BRepFill
is a pythonocc targethere's a pythonic way to do so redirect stdout & stderr in a context manager / with statement
Follow Issue #30. Related to tpaviot/pythonocc-core#576
Issue dealing with the process of wrapping occt 7.2.0 using SWIG and expose related objects through pythonocc.
I'm currently being porting the pythonocc wrapper to occt 7.2.0 version. This requires many changes to both SWIG files (automatically generated using the pythonocc-generator project), and to most of the pythonocc python scripts impacted by API changes.
Changes to the generator are available in this repository, branch https://github.com/tpaviot/pythonocc-generator/tree/wip/occt7x-wrapper . In this branch, support for SMESH and Addon has been temporarily removed. They should be back as soon as the basis is working.
I ran the generator over all occt 7.2.0 header files, resulting SWIG files are available on the branch wip/occt7x-support https://github.com/tpaviot/pythonocc-core/tree/wip/occt7x-support SWIG files are here https://github.com/tpaviot/pythonocc-core/tree/wip/occt7x-support/src/SWIG_files/wrapper
The related pythonocc-core branch should compile, on Linux, using occt7.2.0. I had to add a few missing includes, see https://github.com/tpaviot/oce/commits/review/occt-720-patches
After a $ make install
, I can run the unittest suite. Currently pass, see the output below:
pythonocc-core/test$ python run_tests.py
testAutoImportOfDependentModules (core_wrapper_features_unittest.TestWrapperFeatures)
Test: automatic import of dependent modules ... ok
testProtectedConstructor (core_wrapper_features_unittest.TestWrapperFeatures)
Test: protected constructor ... ok
testStandardBooleanByRefPassedReturned (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
testTopoDS_byref_arguments (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_array_iterator (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_const_Standard_Integer_byref (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_const_Standard_Real_byref (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_default_constructor_DEFINE_STANDARD_ALLOC (core_wrapper_features_unittest.TestWrapperFeatures)
OCE classes the defines standard alllocator can be instanciated ... ok
test_deprecation_downcasts (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_deprecation_get_handle (core_wrapper_features_unittest.TestWrapperFeatures)
Handles are now completely transparent. The GetHandle method is ... ok
test_deprecation_get_object (core_wrapper_features_unittest.TestWrapperFeatures)
Handles are now completely transparent. The GetObject method is ... ok
test_deprecation_handle_class (core_wrapper_features_unittest.TestWrapperFeatures)
Handles are now completely transparent. The Handle_* constructor is ... ok
test_deprecation_warning (core_wrapper_features_unittest.TestWrapperFeatures)
since pythonocc-0.18.2. import OCC.* changed to import OCC.Core.* ... ok
test_dict (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_downcast_curve (core_wrapper_features_unittest.TestWrapperFeatures)
Test if a GeomCurve can be DownCasted to a GeomLine ... ERROR
test_dump_to_string (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_eq_operator (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_ft1 (core_wrapper_features_unittest.TestWrapperFeatures)
Test: Standard_Integer & by reference transformator ... ok
test_gp_Quaternion (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_gp_Vec_operators (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_handle_standard_transient_copy (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_handling_exceptions (core_wrapper_features_unittest.TestWrapperFeatures)
asserts that handling of OCC exceptions is handled correctly in pythonocc ... ok
test_hash (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_hash_eq_operator (core_wrapper_features_unittest.TestWrapperFeatures)
test that the == wrapper is ok ... ok
test_in_place_operators (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_inherit_topods_shape (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_list (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_local_properties (core_wrapper_features_unittest.TestWrapperFeatures)
Get and modify class local properties ... ok
test_memory_handle_getobject (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_neq_operator (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_pickle_from_file (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_repr_for_null_topods_shapes (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_repr_overload (core_wrapper_features_unittest.TestWrapperFeatures)
Test if repr string is properly returned ... ok
test_return_enum (core_wrapper_features_unittest.TestWrapperFeatures)
Check that returned enums are properly handled, wether they're returned ... FAIL
test_shape_conversion_as_py_none (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_standard_boolean_byref (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_standard_integer_by_ref_passed_returned (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_static_method (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_sub_class (core_wrapper_features_unittest.TestWrapperFeatures)
Test: subclass ... ok
test_topology (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_traverse_box_topology (core_wrapper_features_unittest.TestWrapperFeatures) ... ok
test_axis (core_geometry_unittest.TestGeometry)
Test: axis ... ok
test_bezier_surfaces (core_geometry_unittest.TestGeometry)
Test: Bezier surfaces ... ok
test_bspline (core_geometry_unittest.TestGeometry)
Test: bspline ... ERROR
test_circles2d_from_curves (core_geometry_unittest.TestGeometry)
Test: circles2d from curves ... ok
test_curves2d_from_curves (core_geometry_unittest.TestGeometry)
Test: curves 2d from curves ... ok
test_curves2d_from_offset (core_geometry_unittest.TestGeometry)
Test: curves 2d from offset ... ok
test_distances (core_geometry_unittest.TestGeometry)
Test: distances ... ok
test_parabola (core_geometry_unittest.TestGeometry)
Test: parabola ... ok
test_pipes (core_geometry_unittest.TestGeometry)
Test: pipes ... ok
test_point_from_curve (core_geometry_unittest.TestGeometry)
Test: point from curve ... ok
test_point_from_projections (core_geometry_unittest.TestGeometry)
Test: point from projections ... ok
test_points_from_intersection (core_geometry_unittest.TestGeometry)
Test: points from intersection ... /home/thomas/Devel/pythonocc-core/test/core_geometry_unittest.py:203: DeprecationWarning: IsNull is a deprecated function. Use is None instead
self.assertFalse(aSurface.IsNull())
ok
test_project_point_on_curve (core_geometry_unittest.TestGeometry)
Test: project point on curve ... Q1: at Distance :4.079132288244904
Q2: at Distance :7.833305801192616
ok
test_surface_from_curves (core_geometry_unittest.TestGeometry)
Test: surfaces from curves ... ERROR
test_surfaces_from_offsets (core_geometry_unittest.TestGeometry)
Test: surfaces from offsets ... ok
test_surfaces_from_revolution (core_geometry_unittest.TestGeometry)
Test: surfaces from revolution ... ok
test_export_to_3js_JSON (core_visualization_unittest.TestTesselator) ... ok
test_export_to_x3d (core_visualization_unittest.TestTesselator)
3rd test : export a sphere to X3D file format ... ok
test_export_to_x3d_TriangleSet (core_visualization_unittest.TestTesselator)
3rd test : export a sphere to an X3D TriangleSet triangle mesh ... ok
test_tesselate_box (core_visualization_unittest.TestTesselator)
1st test : tesselation of a box ... ok
test_tesselate_torus (core_visualization_unittest.TestTesselator)
2st test : tesselation of a torus ... ok
test_tesselate_torus_with_bad_quality (core_visualization_unittest.TestTesselator)
2st test : tesselation of a torus ... ok
test_tesselate_torus_with_edges (core_visualization_unittest.TestTesselator)
2st test : tesselation of a torus ... ok
test_create_doc (core_ocaf_unittest.TestOCAF)
Creates an OCAF app and an empty document ... /home/thomas/Devel/pythonocc-core/test/core_ocaf_unittest.py:55: DeprecationWarning: IsNull is a deprecated function. Use is None instead
self.assertFalse(doc.IsNull())
ok
test_read_step_file (core_ocaf_unittest.TestOCAF)
Reads the previous step file ... ok
test_write_step_file (core_ocaf_unittest.TestOCAF)
Exports a colored box into a STEP file ...
*******************************************************************
****** Statistics on Transfer (Write) ******
*******************************************************************
****** Transfer Mode = 0 I.E. As Is ******
****** Transferring Shape, ShapeType = 2 ******
** WorkSession : Sending all data
Step File Name : ./test_io/test_ocaf_generated.stp(391 ents) Write Done
ok
test_threejs_edge (core_webgl_unittest.TestWebGL)
Test: threejs 10 random boxes ... ## threejs r100 webgl renderer
discretize an edge
discretize an edge
ok
test_threejs_random_boxes (core_webgl_unittest.TestWebGL)
Test: threejs 10 random boxes ... ## threejs r100 webgl renderer
/ mesh shape shpbdb26cd837994f2e84f2767e8c628ad4, 12 triangles ok
test_threejs_render_torus (core_webgl_unittest.TestWebGL)
Render a simple torus in threejs ... ## threejs r100 webgl renderer
| mesh shape shp32a5625a99984a4e99a67e194e539ad0, 1352 triangles ok
test_threejs_wire (core_webgl_unittest.TestWebGL)
Test: threejs 10 random boxes ... ## threejs r100 webgl renderer
discretize a wire
ok
test_x3d_edge (core_webgl_unittest.TestWebGL)
Test: threejs 10 random boxes ... ## x3dom webgl renderer
X3D exporter, discretize an edge
X3D exporter, discretize an edge
ok
test_x3d_wire (core_webgl_unittest.TestWebGL)
Test: threejs 10 random boxes ... ## x3dom webgl renderer
X3D exporter, discretize a wire
ok
test_x3dom_random_mesh_quality (core_webgl_unittest.TestWebGL)
Test: threejs 10 random boxes ... ## threejs r100 webgl renderer
- mesh shape shpb450cedef7e24e6ea22ca665ed107302, 2048 triangles ok
test_x3dom_render_torus (core_webgl_unittest.TestWebGL)
Render a simple torus using x3dom ... ## x3dom webgl renderer
ok
test_discretize_edge (core_extend_topology_unittest.TestExtendTopology) ... ok
test_discretize_wire (core_extend_topology_unittest.TestExtendTopology) ... ok
test_edge_face (core_extend_topology_unittest.TestExtendTopology) ... ok
test_edge_wire (core_extend_topology_unittest.TestExtendTopology) ... ok
test_edges_out_of_scope (core_extend_topology_unittest.TestExtendTopology) ... ok
test_face_solid (core_extend_topology_unittest.TestExtendTopology) ... ok
test_kept_reference (core_extend_topology_unittest.TestExtendTopology)
did we keep a reference after looping several time through a list ... ok
test_loop_edges (core_extend_topology_unittest.TestExtendTopology) ... ok
test_loop_faces (core_extend_topology_unittest.TestExtendTopology) ... ok
test_nested_iteration (core_extend_topology_unittest.TestExtendTopology)
check nested looping ... ok
test_number_of_topological_entities (core_extend_topology_unittest.TestExtendTopology) ... ok
test_vertex_edge (core_extend_topology_unittest.TestExtendTopology) ... FAIL
test_vertex_face (core_extend_topology_unittest.TestExtendTopology) ... ok
test_wire_face (core_extend_topology_unittest.TestExtendTopology) ... ok
test_wires_out_of_scope (core_extend_topology_unittest.TestExtendTopology) ... ok
======================================================================
ERROR: test_downcast_curve (core_wrapper_features_unittest.TestWrapperFeatures)
Test if a GeomCurve can be DownCasted to a GeomLine
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/thomas/Devel/pythonocc-core/test/core_wrapper_features_unittest.py", line 524, in test_downcast_curve
line = Geom_Line.DownCast(curve)
File "/home/thomas/miniconda3/envs/occt620/lib/python3.6/site-packages/OCC/Core/Geom.py", line 3698, in DownCast
return Handle_Geom_Line_DownCast(t)
TypeError: in method 'Handle_Geom_Line_DownCast', argument 1 of type 'Handle_Standard_Transient const &'
======================================================================
ERROR: test_bspline (core_geometry_unittest.TestGeometry)
Test: bspline
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/thomas/Devel/pythonocc-core/test/core_geometry_unittest.py", line 266, in test_bspline
harray.SetValue(1, gp_Pnt2d(7 + 0, 0))
TypeError: in method 'TColgp_Array1OfPnt2d_SetValue', argument 1 of type 'NCollection_Array1< gp_Pnt2d > *'
======================================================================
ERROR: test_surface_from_curves (core_geometry_unittest.TestGeometry)
Test: surfaces from curves
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/thomas/Devel/pythonocc-core/test/core_geometry_unittest.py", line 411, in test_surface_from_curves
SPL3 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(10, 0, 0)))
File "/home/thomas/miniconda3/envs/occt620/lib/python3.6/site-packages/OCC/Core/Geom.py", line 5149, in DownCast
return Handle_Geom_BSplineCurve_DownCast(t)
TypeError: in method 'Handle_Geom_BSplineCurve_DownCast', argument 1 of type 'Handle_Standard_Transient const &'
======================================================================
FAIL: test_return_enum (core_wrapper_features_unittest.TestWrapperFeatures)
Check that returned enums are properly handled, wether they're returned
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/thomas/Devel/pythonocc-core/test/core_wrapper_features_unittest.py", line 539, in test_return_enum
self.assertEqual(los1.First(), BRepCheck_Multiple3DCurve)
AssertionError: <Swig Object of type 'BRepCheck_Status *' at 0x7fa61c8dfe40> != 5
======================================================================
FAIL: test_vertex_edge (core_extend_topology_unittest.TestExtendTopology)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/thomas/Devel/pythonocc-core/test/core_extend_topology_unittest.py", line 126, in test_vertex_edge
self.assertEqual(len(edges_from_vert), topo.number_of_edges_from_vertex(vert))
AssertionError: 3 != 6
----------------------------------------------------------------------
Ran 90 tests in 2.171s
FAILED (failures=2, errors=3)
The most important change from 6.9.x to 7.x is an intensive use of c++ templates. OCCT left a way to ensure backward compatibility, that's why despite this huge API refactoring most of the pythonocc-core unittest amazingly pass without any major change.
However @rainman110 I need your help. I think that the OccHandle.i file you contribued needs to be updated. Indeed it's not possible to DownCast
anymore. For instance, in the unittest suite, the line Geom_BSplineCurve.DownCast
raises an exception. It's the same each time I try to DownCast something.
Ping @jf--- @adam-urbanczyk @trelau for information
A screenshot including an AIS_Manipulator, available from occt 7.x series
python can accept stub files that describe the type ( in / output ) of a function or method.
this is incredible useful, since IDE's such as pycharm will be able to check ~80/90% of your code, rather than ~40/50% as of today. also, python linters can work with the type checking to test the code for correctness.
It would be great for the code generator to produce type stub files ( *.pyi ). This way, the same python wrappers can be used whether python supports type hinting or not ( eg. if python_version >= 3.5 then copy the stub files )
Certainly when working with a larger code base, this is a huge help to develop robust software rapidly.
Typed languages have an important advantage when refactoring a large code base, you can do so much faster with more confidence.
Personally, this is an important motivation to move to py3k on short notice 😎
Currently, all headers including all dependencies are put into swig header files. This looks e.g. like:
%{
#include<gp_XYZ.hxx>
#include<gp_XY.hxx>
.
.
#include<gp...hxx>
#include<Standard_Transient.hxx>
.
.
#include<Standard_Atomic.hxx>
%}
This is not very modular. Assume, one of the gp_XXX includes has to be changed, it has to be done in all *_header.i that include the gp module.
My proposal is, to put all headers of one module in one jumbo header. For the gp module, we create a header gp_module.hxx:
#pragma once
#include<gp_XYZ.hxx>
#include<gp_XY.hxx>
.
.
#include<gp_XXX.hxx>
Then, the gp_headers.i file just looks like:
%{
#include<gp_module.hxx>
#include<Standard_module.hxx>
%}
Theoretically, this can also be used together with PCH to speed up compilation.
CppHeaderParser cannot parse fairly big list of file.
Therefore, it might be worthwhile to consider using libclang's python bindings as a parser.
As @rainman110 noticed, the GarbageCollector module is not imported anymore. Thus, object destructor method are never properly called. See tpaviot/pythonocc-core#199
The problem is, that depending on the computer, all wrapper files will be marked as changed and will have changed this line, even if everything else is the same.
This makes it IMHO impractical for version control.
A alternative would be a separate text file that contains the metadata,
It seems to be ignored by swig.
affected module: _XCAFPrs
Unable to find 'XSControl.i'
affected modules: _Select3D.so, _SelectBasics.so, IGESControl, STEPControl
@tpaviot Currently template use in the OCE is a problem when wrapping with SWIG. On the current master this problem is minor. This could be a major problem when moving to OCCT 7 or higher, due to the new type refactoring, almost all classes are represented as templates.
From the doc:
"In order to wrap a template, you need to give SWIG information about a particular template instantiation (e.g., vector, array, etc.). Second, an instantiation name such as vector is generally not a valid identifier name in most target languages. Thus, you will need to give the template instantiation a more suitable name such as intvector when creating a wrapper."
After declaring the template you need to instantiate it (for example for int and double):
template class List {
...
};
%template(intList) List;
%template(doubleList) List;
This means that is necessary to know before hand what are the possible cases for each template in order to generate the necessary wrapper code.
One possible workaround is to perform an static analysis on the code in order to "detect" the possible representations for the template.
Any thoughts?
At the moment, there is no way to create an empty TopoDS_Shape. This is however required in some cases.
Therefore, the disabled constructor has to be enabled again (see Modules.py=
Hi,
In an effort to (hopefully) help with adding support for OCCT version 7.6.1 (and also learn a bit more of the build process of pythonocc-core in general) I just wanted to share my attempts at recreating the SWIG bindings to support OCCT v7.6.1.
First of I modified the wrapper_generator.conf
file with the location of my pythonocc-core fork and opencascade headers.
Now, in my initial attempt at running the generate_wrapper.py
script failed when I ran into the following error:
[WARNI] [TypeHint] Skipping type NCollection_Vector<TopoDS_Face>, seems to be a template
self._free_functions_str, self._free_functions_pyi_str = process_methods(
File "C:\work\code\krande-pythonocc-generator\src\generate_wrapper.py", line 2396, in process_methods
ok_to_wrap, ok_hints = process_function(function, need_overload)
File "C:\work\code\krande-pythonocc-generator\src\generate_wrapper.py", line 2134, in process_function
parent_class_name = f["parent"]["name"]
TypeError: 'NoneType' object is not subscriptable
I traced the error back to the RWGltf
module, and thus removed it from the TKRWMesh
list inside the TOOLKIT_DataExchange
.
Second attempt at running the generate_wrapper.py
script was then successful.
Next I tried compiling pythonocc-core after updating the CMAKELIST.txt with the appropriate version of OCCT I wished to compile for.
In my compilation attempt I ran into an error related to Error: Template 'OSD_StreamBuffer' undefined
(excerpt below).
====================[ Build | all | RelWithDebInfo-VS ]=========================
"C:\Program Files\JetBrains\CLion 2021.3\bin\cmake\win\bin\cmake.exe" --build C:\work\code\krande-pythonocc-core\_build --target all
[1/910] Swig compile src/SWIG_files/wrapper/Plugin.i for python
[2/910] Swig compile src/SWIG_files/wrapper/FSD.i for python
[3/910] Swig compile src/SWIG_files/wrapper/OSD.i for python
FAILED: bin/OSDPYTHON_wrap.cxx bin/OSD.py C:/work/code/krande-pythonocc-core/_build/bin/OSDPYTHON_wrap.cxx C:/work/code/krande-pythonocc-core/_build/bin/OSD.py
cmd.exe /C "cd /D C:\work\code\krande-pythonocc-core\_build && "C:\Program Files\JetBrains\CLion 2021.3\bin\cmake\win\bin\cmake.exe" -E make_directory C:/work/code/krande-pythonocc-core/_build/CMakeFiles/_OSD.dir bin/ bin/ && "C:\Program Files\JetBrains\CLion 2021.3\bin\cmake\win\bin\cmake.exe" -E env SWIG_LIB=C:/ProgramData/chocolatey/lib/swig/tools/install/swigwin-4.0.2/Lib C:/ProgramData/chocolatey/bin/swig.exe -python -fvirtual -py3 -w302,401,402,412,314,509,512,504,325,503,520,350,351,383,389,394,395,404 -DCSFDB -DWIN32 -D_WINDOWS -outdir bin/ -c++ -interface _OSD -IC:/work/code/krande-pythonocc-core -IC:/work/code/krande-pythonocc-core/OPENGL_INCLUDE_DIR -IC:/AibelProgs/Miniconda3/envs/pyoccdev/Library/include/opencascade -IC:/work/code/krande-pythonocc-core/src/SWIG_files/headers -o bin//OSDPYTHON_wrap.cxx C:/work/code/krande-pythonocc-core/src/SWIG_files/wrapper/OSD.i"
C:\work\code\krande-pythonocc-core\src\SWIG_files\wrapper\OSD.i(347) : Error: Template 'OSD_StreamBuffer' undefined.
C:\work\code\krande-pythonocc-core\src\SWIG_files\wrapper\OSD.i(348) : Error: Template 'OSD_StreamBuffer' undefined.
C:\work\code\krande-pythonocc-core\src\SWIG_files\wrapper\OSD.i(349) : Error: Template 'OSD_StreamBuffer' undefined.
[4/910] Swig compile src/SWIG_files/wrapper/NCollection.i for python
[5/910] Swig compile src/SWIG_files/wrapper/AppBlend.i for python
[6/910] Swig compile src/SWIG_files/wrapper/Message.i for python
FAILED: bin/MessagePYTHON_wrap.cxx bin/Message.py C:/work/code/krande-pythonocc-core/_build/bin/MessagePYTHON_wrap.cxx C:/work/code/krande-pythonocc-core/_build/bin/Message.py
cmd.exe /C "cd /D C:\work\code\krande-pythonocc-core\_build && "C:\Program Files\JetBrains\CLion 2021.3\bin\cmake\win\bin\cmake.exe" -E make_directory C:/work/code/krande-pythonocc-core/_build/CMakeFiles/_Message.dir bin/ bin/ && "C:\Program Files\JetBrains\CLion 2021.3\bin\cmake\win\bin\cmake.exe" -E env SWIG_LIB=C:/ProgramData/chocolatey/lib/swig/tools/install/swigwin-4.0.2/Lib C:/ProgramData/chocolatey/bin/swig.exe -python -fvirtual -py3 -w302,401,402,412,314,509,512,504,325,503,520,350,351,383,389,394,395,404 -DCSFDB -DWIN32 -D_WINDOWS -outdir bin/ -c++ -interface _Message -IC:/work/code/krande-pythonocc-core -IC:/work/code/krande-pythonocc-core/OPENGL_INCLUDE_DIR -IC:/AibelProgs/Miniconda3/envs/pyoccdev/Library/include/opencascade -IC:/work/code/krande-pythonocc-core/src/SWIG_files/headers -o bin//MessagePYTHON_wrap.cxx C:/work/code/krande-pythonocc-core/src/SWIG_files/wrapper/Message.i"
C:\work\code\krande-pythonocc-core\src\SWIG_files\wrapper\OSD.i(347) : Error: Template 'OSD_StreamBuffer' undefined.
C:\work\code\krande-pythonocc-core\src\SWIG_files\wrapper\OSD.i(348) : Error: Template 'OSD_StreamBuffer' undefined.
C:\work\code\krande-pythonocc-core\src\SWIG_files\wrapper\OSD.i(349) : Error: Template 'OSD_StreamBuffer' undefined.
[7/910] Swig compile src/SWIG_files/wrapper/Plate.i for python
FAILED: bin/PlatePYTHON_wrap.cxx bin/Plate.py C:/work/code/krande-pythonocc-core/_build/bin/PlatePYTHON_wrap.cxx C:/work/code/krande-pythonocc-core/_build/bin/Plate.py
cmd.exe /C "cd /D C:\work\code\krande-pythonocc-core\_build && "C:\Program Files\JetBrains\CLion 2021.3\bin\cmake\win\bin\cmake.exe" -E make_directory C:/work/code/krande-pythonocc-core/_build/CMakeFiles/_Plate.dir bin/ bin/ && "C:\Program Files\JetBrains\CLion 2021.3\bin\cmake\win\bin\cmake.exe" -E env SWIG_LIB=C:/ProgramData/chocolatey/lib/swig/tools/install/swigwin-4.0.2/Lib C:/ProgramData/chocolatey/bin/swig.exe -python -fvirtual -py3 -w302,401,402,412,314,509,512,504,325,503,520,350,351,383,389,394,395,404 -DCSFDB -DWIN32 -D_WINDOWS -outdir bin/ -c++ -interface _Plate -IC:/work/code/krande-pythonocc-core -IC:/work/code/krande-pythonocc-core/OPENGL_INCLUDE_DIR -IC:/AibelProgs/Miniconda3/envs/pyoccdev/Library/include/opencascade -IC:/work/code/krande-pythonocc-core/src/SWIG_files/headers -o bin//PlatePYTHON_wrap.cxx C:/work/code/krande-pythonocc-core/src/SWIG_files/wrapper/Plate.i"
C:\work\code\krande-pythonocc-core\src\SWIG_files\wrapper\OSD.i(347) : Error: Template 'OSD_StreamBuffer' undefined.
C:\work\code\krande-pythonocc-core\src\SWIG_files\wrapper\OSD.i(348) : Error: Template 'OSD_StreamBuffer' undefined.
C:\work\code\krande-pythonocc-core\src\SWIG_files\wrapper\OSD.i(349) : Error: Template 'OSD_StreamBuffer' undefined.
[8/910] Swig compile src/SWIG_files/wrapper/LocalAnalysis.i for python
[9/910] Building CXX object CMakeFiles\_FSD.dir\bin\FSDPYTHON_wrap.cxx.obj
[10/910] Building CXX object CMakeFiles\_Plugin.dir\bin\PluginPYTHON_wrap.cxx.obj
I've tried removing references to the OSD module, but that only caused more errors, so it might suggest the solution lies elsewhere.
While I keep testing, I would appreciate any hints or feedback that would help solving this.
Best Regards
Kristoffer
# no such class
from OCC.Font import Font_BRepFont
though this class is there is OCE 0.16
'Font_FTFont.hxx', 'Font_FTLibrary.hxx', are excluded from being parsed when generating the wrapper, this is probably why this is missing?
It would be nice to be able to iterate over wrapped arrays using normal python idioms. I believe we could achieve this by %extend%
ing the array classes with 3 extra functions
__iter__
,
__next__
,
next
(See: http://stackoverflow.com/questions/13094421/what-is-the-interface-for-python-iterators)
This falls into the nice-to-have category, but I think is fairly simple to add to the wrapper generator. I might have a go at this next weekend if I get the time.
Scanning dependencies of target _Geom2dGcc
Building CXX object CMakeFiles/_Geom2dGcc.dir/Darwin/x86_64-MinSizeRel-64/Geom2dGccPYTHON_wrap.cxx.o
Linking CXX shared module Darwin/x86_64-MinSizeRel-64/_Geom2dGcc.so
Undefined symbols for architecture x86_64:
"Geom2dGcc_FunctionTanCuCuCu::Geom2dGcc_FunctionTanCuCuCu(Geom2dAdaptor_Curve const&, gp_Pnt2d const&, gp_Pnt2d const&)", referenced from:
wrap_new_Geom2dGcc_FunctionTanCuCuCu__SWIG_8(object, int, object) in Geom2dGccPYTHON_wrap.cxx.o
"Geom2dGcc_FunctionTanCuCuCu::Geom2dGcc_FunctionTanCuCuCu(gp_Lin2d const&, Geom2dAdaptor_Curve const&, gp_Pnt2d const&)", referenced from:
_wrap_new_Geom2dGcc_FunctionTanCuCuCu__SWIG_7(object, int, _object**) in Geom2dGccPYTHON_wrap.cxx.o
"Geom2dGcc_FunctionTanCuCuCu::Geom2dGcc_FunctionTanCuCuCu(gp_Circ2d const&, Geom2dAdaptor_Curve const&, gp_Pnt2d const&)", referenced from:
_wrap_new_Geom2dGcc_FunctionTanCuCuCu__SWIG_6(_object*, int, _object**) in Geom2dGccPYTHON_wrap.cxx.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [Darwin/x86_64-MinSizeRel-64/_Geom2dGcc.so] Error 1
make[2]: *** [CMakeFiles/_Geom2dGcc.dir/all] Error 2
make[1]: *** [CMakeFiles/_Geom2dGcc.dir/rule] Error 2
make: *** [_Geom2dGcc] Error 2
[100%] Swig source
Hi, I'm trying to understand the pythonocc-generator and I ran it's release 0.2 on the OCE release 0.16.1 and had some problems with it:
ChFiKPart
from the toolkit TKFillet
:[ 26%] Building CXX object CMakeFiles/_ChFiKPart.dir/src/SWIG_files/wrapper/ChFiKPartPYTHON_wrap.cxx.o
In file included from /local/bzfherrm/test/build/pythonocc/src/SWIG_files/wrapper/ChFiKPartPYTHON_wrap.cxx:4258:0:
/local/bzfherrm/test/install/oce/lib/oce-0.16/../../include/oce/ChFiKPart_ComputeData_Rotule.hxx:20:39: error: ‘TopOpeBRepDS_DataStructure’ was not declared in this scope
Standard_Boolean ChFiKPart_MakeRotule(TopOpeBRepDS_DataStructure& DStr,
^
[...]
git diff
on the related SWIG files ChFiKPart.i
gives:
diff --git a/src/SWIG_files/wrapper/ChFiKPart.i b/src/SWIG_files/wrapper/ChFiKPart.i
index 5646842..af2dcbc 100644
--- a/src/SWIG_files/wrapper/ChFiKPart.i
+++ b/src/SWIG_files/wrapper/ChFiKPart.i
@@ -2 +2 @@
-Copyright 2008-2014 Thomas Paviot ([email protected])
+Copyright 2008-2015 Thomas Paviot ([email protected])
@@ -44,0 +45 @@ class ChFiKPart_ComputeData {
+ %feature("compactdefaultargs") Compute;
@@ -62 +63 @@ class ChFiKPart_ComputeData {
- :type Iedge: Standard_Integer
+ :type Iedge: int
@@ -65,0 +67 @@ class ChFiKPart_ComputeData {
+ %feature("compactdefaultargs") ComputeCorner;
@@ -98,0 +101 @@ class ChFiKPart_ComputeData {
+ %feature("compactdefaultargs") ComputeCorner;
@@ -127,0 +131 @@ class ChFiKPart_ComputeData {
+ %feature("compactdefaultargs") ComputeCorner;
@@ -172,0 +177 @@ class ChFiKPart_DataMapIteratorOfRstMap : public TCollection_BasicMapIterator {
+ %feature("compactdefaultargs") ChFiKPart_DataMapIteratorOfRstMap;
@@ -175,0 +181 @@ class ChFiKPart_DataMapIteratorOfRstMap : public TCollection_BasicMapIterator {
+ %feature("compactdefaultargs") ChFiKPart_DataMapIteratorOfRstMap;
@@ -180,0 +187 @@ class ChFiKPart_DataMapIteratorOfRstMap : public TCollection_BasicMapIterator {
+ %feature("compactdefaultargs") Initialize;
@@ -185,0 +193 @@ class ChFiKPart_DataMapIteratorOfRstMap : public TCollection_BasicMapIterator {
+ %feature("compactdefaultargs") Key;
@@ -188,0 +197 @@ class ChFiKPart_DataMapIteratorOfRstMap : public TCollection_BasicMapIterator {
+ %feature("compactdefaultargs") Value;
@@ -211,0 +221 @@ class ChFiKPart_DataMapNodeOfRstMap : public TCollection_MapNode {
+ %feature("compactdefaultargs") ChFiKPart_DataMapNodeOfRstMap;
@@ -213 +223 @@ class ChFiKPart_DataMapNodeOfRstMap : public TCollection_MapNode {
- :type K: Standard_Integer &
+ :type K: int &
@@ -234 +244,2 @@ class ChFiKPart_DataMapNodeOfRstMap : public TCollection_MapNode {
- %feature("autodoc", " :rtype: Handle_Adaptor2d_HCurve2d
+ %feature("compactdefaultargs") Value;
+ %feature("autodoc", " :rtype: Handle_Adaptor2d_HCurve2d
@@ -295,0 +307 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
+ %feature("compactdefaultargs") ChFiKPart_RstMap;
@@ -297 +309 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
- :type NbBuckets: Standard_Integer
+ :type NbBuckets: int
@@ -300,0 +313 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
+ %feature("compactdefaultargs") Assign;
@@ -305,0 +319 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
+ %feature("compactdefaultargs") operator =;
@@ -310,0 +325 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
+ %feature("compactdefaultargs") ReSize;
@@ -312 +327 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
- :type NbBuckets: Standard_Integer
+ :type NbBuckets: int
@@ -315,0 +331 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
+ %feature("compactdefaultargs") Clear;
@@ -318,0 +335 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
+ %feature("compactdefaultargs") Bind;
@@ -320 +337 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
- :type K: Standard_Integer &
+ :type K: int &
@@ -325,0 +343 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
+ %feature("compactdefaultargs") IsBound;
@@ -327 +345 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
- :type K: Standard_Integer &
+ :type K: int &
@@ -330,0 +349 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
+ %feature("compactdefaultargs") UnBind;
@@ -332 +351 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
- :type K: Standard_Integer &
+ :type K: int &
@@ -335,0 +355 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
+ %feature("compactdefaultargs") Find;
@@ -337 +357 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
- :type K: Standard_Integer &
+ :type K: int &
@@ -340,0 +361 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
+ %feature("compactdefaultargs") ChangeFind;
@@ -342 +363 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
- :type K: Standard_Integer &
+ :type K: int &
@@ -345,0 +367 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
+ %feature("compactdefaultargs") Find1;
@@ -347 +369 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
- :type K: Standard_Integer &
+ :type K: int &
@@ -350,0 +373 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
+ %feature("compactdefaultargs") ChangeFind1;
@@ -352 +375 @@ class ChFiKPart_RstMap : public TCollection_BasicMap {
- :type K: Standard_Integer &
+ :type K: int &
and on ChFiKPart_headers.i
it shows that the order is different, which may cause the compiling error.
Am I using the python-generator in a wrong way? Thanks in advance for helping!
sven
It is derived from Standard_Transient and therefore must be wrapped in a handle.
In e.g. StepShape.i, some %wrap_handle(xxx) come too late. All %wrap_handle calls must be in front of the first class declaration.
Otherwise, methods as IsDone() or not defined.
I used the whole day to figure out the correct dependencies. Please find attached the following file.
dependencies.txt
Thus function is required for some OCAF demos and is a very useful function in general.
I think it was removed due to the template argument.
I'll check, what I can do with it.
Hi,
I grepped through Modules.py and it appears the Voxel package [1] is not wrapped. Just checking in whether there is a reason for this? I think manipulating this kind of data with numpy.ndarray
s would be quite a thrill :)
[1] https://www.opencascade.com/doc/occt-6.9.1/refman/html/package_voxel.html
Kind regards,
Thomas
indeed many Dump* methods use this type. Currently methods are renamed to DumpToString or DumpJsonToString, something generic has to be done, without renaming the method.
The bug is decribed here: tpaviot/pythonocc-core#93
I thought about this a while. I'd really like to make sure, that the issues you had memory wise should be catched already at compile time. I found a very simple solution to it:
In the arguments of the swig headers, we don't use opencascade::handle. Instead we use a new unknown type e.g. OccHandle_XXX. This type is only known, if it was defined in the other module.
A concrete example:
BRepBuilderAPI.i:
import Geom.i
BRepBuilderAPI_MakeEdge(OccHandle_Geom_Curve curve);
Geom.i
%wrap_handle(Geom_Curve)
#define OccHandle_Geom_Curve opencascade::handle<Geom_Curve>
class Geom_Curve
{
...
};
I tried this just now, and it seems to be working. When you don't include Geom.i, you'll get a compiler error.
I'm wondering how complex would it be to reuse the generator approach for other C++ libraries?
For example pivy.coin3d: coin3d/pivy#71
If you started from scratch, would you go with it again? Or would you rather push for more advanced SWIG support?
How time consuming is it compared to manual coding?
modules affected: _Visual3d.so, _Graphic3d.so, IFSelect.so, _TShort.so, _TColGeom.so, _TColGeom2d.so, _TColgp.so, _ProjLib.so, _ChFiDS.so, _Interface.so, _GeomPlate.so, _Units.so, _Geom.so, _TColStd.so, _Contap.so, _GeomFill.so, _Storage.so, _Interface.so
@tpaviot A few days ago there was an update on the OCE repo, upgrading OCCT to version 6.9.1. I compiled the code and it looks fine. I'm trying to update the generator, but there are some (a lot) of compile problems, I'm trying to fix them, if possible. When I have something new I'll let you know.
Problem Statement:
When getting the selected objects from the view, they are returned as a list of TopoDS_Shape. However, the objects that are returned are usually actually of a derived class from TopoDS_Shape such as TopoDS_Face or TopoDS_Solid. This is a nuisance when wanting to pass to methods that demand a specific subclass such as BRepTool_Surface which wants a TopDS_Face and not a TopDS_Shape. In this case I could not find a straightforward way of telling python that my TopoDS_Shape was in fact a TopoDS_Face. It is possible is to tell SWIG (see below ) that there is a class hierarchy with its base at TopoDS_Shape, and that when it is returning a TopDS_Shape, SWIG can then look at e.g. shape.ShapeType() to see what class of python wrapper to put the returned object into, rather than just wrapping it as a base TopoDS_Shape.
The benefit of this is that the python user will receive their objects wrapped in the correct derived class and not a base class for that genera of objects.
Proposed Solution:
This can be achieved using SWIG's typemap (out) capability: see the two blog posts below
http://stackoverflow.com/questions/27392602/swig-downcasting-from-base-to-derived
Otherwise, I get a compiler error on linux. Is there a possibility to modify include order?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.