BCad fork

OCCT usage in bcad
Login

OCCT usage in bcad

Overview

bcad uses Open CASCADE Technology (OCCT) for 3D geometry modelling, 2D/3D visualisation, and data exchange (STEP/STL/DXF). OCCT is accessed at three distinct levels:

Layer Component Language OCCT access
1 bcad/binterpreter/scl_context.py, scl.py, scl_shape.py, scl_writer.py, scl_cache.py, boccviewer.py, offscreen_display.py Python OCC.Core.* via pythonocc-core
2 cpp/bcad_text_shaper/, cpp/bcad_hull/ C++ #include <*.hxx> + SWIG bindings
3 cpp/pythonocc-core/ (Tesselator, Visualization) C++ Embedded in pythonocc-core itself

1. Python-level modules (OCC.Core.*)

All OCC.Core.* modules imported by bcad's own .py files (bcad/binterpreter/):

OCC.Core module Used in OCCT toolkit
AIS scl_context, boccviewer, scl_shape TKV3d
Approx scl_context TKGeomBase
Aspect boccviewer, offscreen_display TKService
Bnd scl, scl_context, boccviewer TKMath
BRep scl_shape, scl, scl_context, offscreen_display TKBRep
BRepAdaptor scl_context TKBRep
BRepAlgoAPI scl_context, scl_writer TKBO
BRepBndLib scl, scl_context, boccviewer TKTopAlgo
BRepBuilderAPI scl_shape, scl, scl_context, boccviewer TKTopAlgo
BRepCheck scl_context TKTopAlgo
BRepGProp scl, scl_context TKTopAlgo
BRepIntCurveSurface boccviewer TKTopAlgo
BRepLib scl_context TKTopAlgo
BRepMesh scl_context, boccviewer TKMesh
BRepOffset scl_context TKOffset
BRepOffsetAPI scl_context TKOffset
BRepPrimAPI scl_context TKPrim
BRepTools boccviewer TKBRep
ChFi2d scl_context TKFillet
Geom scl_context, boccviewer TKG3d
Geom2d boccviewer TKG2d
GeomAbs scl_context TKMath
GeomAPI scl_context TKGeomAlgo
gp scl_context, boccviewer, scl, scl_shape, offscreen_display TKMath
Graphic3d boccviewer TKService
GProp scl, scl_context TKG3d
IFSelect scl_context, scl_writer TKXSBase
Interface scl_writer TKXSBase
Message scl_context TKernel
NCollection scl_context, scl TKernel
Prs3d scl_context, boccviewer, offscreen_display TKV3d
Quantity scl_shape, scl_context, boccviewer, scl_writer, offscreen_display TKernel
ShapeUpgrade scl_context TKShHealing
StdPrs scl_context, scl TKV3d
STEPCAFControl scl_context, scl_writer TKXDESTEP
STEPControl scl_writer TKSTEP
TCollection boccviewer TKernel
TColgp scl_context TKMath
TDF scl_context TKLCAF
TDocStd scl_context, scl_writer TKLCAF
TopAbs scl_context, boccviewer, scl_shape, scl_cache, scl_writer, offscreen_display TKG3d
TopExp scl_context, scl_shape, scl_cache, scl_writer TKBRep
TopLoc scl_context TKMath
TopoDS scl_context, scl, scl_shape, scl_writer, offscreen_display TKBRep
TopTools scl_context TKBRep
V3d scl_context, boccviewer TKV3d
Visualization boccviewer TKV3d
XCAFDoc scl_context, scl_writer TKXCAF

Additionally, the convenience layer OCC.Extend.* and OCC.Display.* are used:

Module Used in Purpose
OCC.Extend.TopologyUtils scl_context, scl, scl_writer TopologyExplorer, discretize_edge
OCC.Extend.ShapeFactory scl_context make_wire
OCC.Extend.DataExchange scl_context, scl_writer read_stl_file, write_stl_file
OCC.Display.OCCViewer scl_context, scl_shape rgb_color helper

2. C++ native extensions

bcad_text_shaper (text → BRep)

CMake (cpp/bcad_text_shaper/CMakeLists.txt:96):

target_link_libraries(_bcad_text_shaper PRIVATE
    TKMath TKG2d TKBRep TKGeomBase TKTopAlgo TKernel TKShHealing
)

OCCT headers used:

Header Toolkit
<gp_Pnt.hxx>, <gp_Vec.hxx>, <gp_Trsf.hxx> TKMath
<TColgp_Array1OfPnt.hxx> TKMath
<Geom_BezierCurve.hxx> TKG3d
<GC_MakeSegment.hxx> TKGeomBase
<BRepBuilderAPI_MakeEdge.hxx>, _MakeWire, _MakeFace, _Transform TKTopAlgo
<BRep_Builder.hxx> TKBRep
<TopoDS_Compound.hxx>, <TopoDS_Wire.hxx>, <TopoDS_Face.hxx>, <TopoDS_Shape.hxx> TKBRep
<BRepBndLib.hxx> TKTopAlgo
<Bnd_Box.hxx> TKMath
<ShapeFix_Face.hxx> TKShHealing
<BRepAdaptor_Surface.hxx> TKBRep
<GeomAbs_SurfaceType.hxx> TKMath

SWIG typemap: TopoDS_Shape, TopoDS_Compound (heap-copied with SWIG_POINTER_OWN).

bcad_hull (convex hull)

CMake (cpp/bcad_hull/CMakeLists.txt:58):

target_link_libraries(_bcad_hull PRIVATE TKernel)

Only <gp_Pnt.hxx> (TKMath) is used — TKernel is pulled transitively by pythonocc's type system (Standard integer types, handles).


3. pythonocc-core embedded C++

pythonocc-core (cpp/pythonocc-core/) contributes its own C++ code that uses OCCT directly. This code does not exist in the final pythonocc-core pip/conda package used at runtime — it's part of bcad's custom pythonocc-core fork. The affected toolkits are listed in cpp/pythonocc-core/CMakeLists.txt:

Component C++ files OCCT toolkits used (indirect)
Tesselator ShapeTesselator.cpp/.h TKBRep, TKTopAlgo, TKMath, TKMesh, TKernel
Visualization Visualization.cpp/.h, Display3d.cpp TKService, TKV3d, TKOpenGl, BRepPrimAPI (TKPrim)
MeshDataSource MeshDataSource.cpp/.h TKMesh, TKernel
Addons (Font3d) Addons.h, Font3d.cpp TKService, TKV3d, TKernel

These components are compiled into OCC.Core.Tesselator, OCC.Visualization, OCC.Core.MeshVS, and OCC.Addons respectively.


4. Toolkit summary

OCCT toolkits directly used by bcad

These are toolkits that bcad's own code (Python + C++ extensions) explicitly imports or links against:

Toolkit Level Modules/Symbols used
TKernel Python + C++ Message, NCollection, Quantity, TCollection, Standard types
TKMath Python + C++ gp, Bnd, GeomAbs, TColgp, TopLoc
TKBRep Python + C++ TopoDS, TopExp, TopTools, BRep, BRepAdaptor, BRepTools
TKG2d Python + C++ Geom2d
TKG3d Python Geom, GProp, TopAbs
TKGeomBase C++ GC_MakeSegment, Approx
TKGeomAlgo Python GeomAPI
TKTopAlgo Python + C++ BRepBuilderAPI, BRepCheck, BRepLib, BRepGProp, BRepIntCurveSurface, BRepBndLib
TKPrim Python BRepPrimAPI
TKBO Python BRepAlgoAPI
TKOffset Python BRepOffsetAPI, BRepOffset
TKFillet Python ChFi2d
TKMesh Python BRepMesh
TKShHealing Python + C++ ShapeUpgrade, ShapeFix
TKService Python Aspect, Graphic3d
TKV3d Python AIS, Prs3d, StdPrs, V3d, Visualization
TKXSBase Python Interface, IFSelect
TKSTEP Python STEPControl
TKXDESTEP Python STEPCAFControl
TKXCAF Python XCAFDoc
TKLCAF Python TDF, TDocStd

Total: 21 toolkits directly referenced.

Toolkits pulled in transitively by pythonocc-core but NOT used by bcad directly

These are linked by pythonocc-core's CMake but are not (and likely cannot be) triggered by bcad's own code. They are included because pythonocc-core builds a monolithic set of SWIG wrappers:

Not used Available via pythonocc
TKBool (TopOpeBRep, BRepAlgo) boolean operations legacy
TKFeat (LocOpe, BRepFeat) feature-based modelling
TKGeomAlgo (most of it) geometric intersection algorithms
TKDE, TKDESTEP, TKDEIGES Data Exchange framework
TKSTL STL I/O
TKVRML, TKDEVRML VRML I/O
TKDEOBJ, TKDEGLTF, TKDEPLY OBJ/GLTF/PLY I/O
TKDECascade DE cascade format
TKRWMesh RWMesh framework
TKOpenGl OpenGL driver (used if Python viewer is active)
TKMeshVS MeshVS display
TKCDF, TKCAF OCAF framework (CDF, TNaming)
TKVCAF OCAF visualization
TKBin, TKXml, variants OCAF persistence
TKTObj OCAF topological naming objects
TKXMesh XBRep mesh
TKSTEP209, TKSTEPAttr, TKSTEPBase STEP sub-frameworks
TKXDEIGES IGES CAF control
TKXmlXCAF, TKBinXCAF XCAF persistence
TKXDE, TKXDECascade DE framework
TKVAF view-dependent attributes

Total: ~25 toolkits not used (though some may appear in ldd output due to transitive linking in pythonocc-core's monolithic build).


5. Dependency graph

bcad Python code
  ├── OCC.Core.* (pythonocc-core SWIG bindings)
  │     ├── TKernel      (base types, handles, collections)
  │     ├── TKMath       (math primitives: gp_Pnt, Bnd_Box, etc.)
  │     ├── TKBRep       (TopoDS, TopExp, BRep topology)
  │     ├── TKG2d        (Geom2d curves)
  │     ├── TKG3d        (Geom, TopAbs)
  │     ├── TKGeomAlgo   (GeomAPI interpolation)
  │     ├── TKTopAlgo    (BRepBuilderAPI, BRepLib, BRepCheck)
  │     ├── TKPrim       (BRepPrimAPI — box, sphere, cylinder)
  │     ├── TKBO         (BRepAlgoAPI — fuse, cut, common)
  │     ├── TKOffset     (BRepOffsetAPI — offset, pipe, thru-sections)
  │     ├── TKFillet     (ChFi2d — 2D fillet)
  │     ├── TKMesh       (BRepMesh — triangulation)
  │     ├── TKShHealing  (ShapeUpgrade — face unification)
  │     ├── TKV3d        (AIS — interactive objects, 3D viewer)
  │     ├── TKService    (Aspect, Graphic3d — windowing, GPU)
  │     ├── TKXSBase     (IFSelect, Interface — STEP basics)
  │     ├── TKSTEP       (STEPControl — STEP export)
  │     ├── TKXDESTEP    (STEPCAFControl — STEP with colors)
  │     ├── TKXCAF       (XCAFDoc — document tool for CAF)
  │     └── TKLCAF       (TDF, TDocStd — document framework)
  │
  ├── OCC.Extend.* (pythonocc utilities)
  │     └── depends on: TopologyUtils, ShapeFactory, DataExchange
  │
  └── OCC.Display.OCCViewer (rgb_color helper)

bcad_text_shaper (C++ extension)
  ├── TKMath       (gp_Pnt, gp_Trsf, Bnd_Box, GeomAbs)
  ├── TKG2d        (Geom2d — via SWIG wrapper only)
  ├── TKBRep       (TopoDS compound/wire/face)
  ├── TKGeomBase   (GC_MakeSegment, approximators)
  ├── TKTopAlgo    (BRepBuilderAPI_MakeEdge/Wire/Face/Transform)
  ├── TKernel      (Standard types, handles)
  └── TKShHealing  (ShapeFix_Face — fix face orientation)

bcad_hull (C++ extension)
  └── TKernel      (only for type system compat with pythonocc)

6. Notes on unused-but-available toolkits

The largest groups of unused OCCT functionality:

  1. Data Exchange (STEP/IGES/STL/OBJ/GLTF/PLY/VRML) — bcad's STEP export uses only STEPControl_Writer + STEPCAFControl_Writer, which are in TKSTEP and TKXDESTEP. The full DE framework (TKDE, TKDECascade, TKDEIGES, etc.) is not needed.

  2. OCAF (Open CASCADE Application Framework) — bcad uses TDF, TDocStd, and XCAFDoc for STEP colour/metadata, which pulls in TKLCAF and TKXCAF. The full OCAF persistence stack (TKBin, TKXml, TKCAF, TKCDF) is not used except as transitive dependencies.

  3. Advanced modellingTKFeat (feature operations), TKBool (legacy boolean ops), TKGeomAlgo (most geometric intersection algorithms) are unused.

  4. MeshVSTKMeshVS is not used by bcad.

  5. OpenGL driverTKOpenGl is only needed if the interactive 3D viewer is active. For headless/offscreen rendering it can be excluded.


7. Reliability of automated dependency analysis

An automated tool can determine OCCT toolkit dependencies with ~90% accuracy by combining:

Method What it detects Reliability
Python AST scan OCC.Core.X imports High — exact, no false positives
C++ regex #include <*.hxx> Header dependencies High for direct includes
OCCT_Modules.cmake mirror Module → toolkit mapping High — OCCT's own manifest
ldd on .so Native lib deps High — OS-level linker deps
Transitive closure via SWIG .py Indirect module deps Medium — some .py wrappers import things unused at runtime

Known blind spots:

Verdict: automated analysis is feasible and practical for packaging/trimming decisions. The result should be treated as a recommendation — the final decision requires human review of the edge cases above.