Migrate export_step / export_stl / export_brep off FreeCAD, onto build123d + OCP — Phase 1: Rewrite _primitive_to_shape to use OCP constructors #41

Closed
opened 2026-06-24 03:24:30 +00:00 by Mark · 0 comments
Owner

Phase 1: Rewrite _primitive_to_shape to use OCP constructors

Goal: Replace pc2cad.py:3592 _primitive_to_shape(FreeCAD, Part, primitive)
with an OCP-only equivalent that does not take FreeCAD/Part as parameters.
This is the per-primitive shape constructor every boolean and export op
funnels through, so it is the choke point.

Approach:

  • Sphere → BRepPrimAPI_MakeSphere(center, radius).Shape()
  • Cylinder → BRepPrimAPI_MakeCylinder(axis_point, axis_dir, radius, height).Shape()
  • Cone → BRepPrimAPI_MakeCone(...) (derive base/apex from primitive)
  • Plane (polygon face) → BRepBuilderAPI_MakeFace from the polygon's
    Poly_Triangulation or from the inlier-hull polygon as a TopoDS_Wire
    on a plane.
  • New signature: _primitive_to_shape(primitive: Primitive) -> TopoDS_Shape.
    Drop the FreeCAD, Part params.

Files: pc2cad.py:3592-3690 (rewrite _primitive_to_shape),
pc2cad.py:3583-3591 (delete _freecad_import).

Acceptance:

  • New function exists, old signature gone, no FreeCAD import.
  • git grep "def _primitive_to_shape" pc2cad.py shows the new signature.
  • All 8 boolean call sites (lines 3831, 4040, etc.) updated to the new
    signature; lint passes.
  • All existing tests still pass (no behavioural change yet — just signature).


Decomposed from pc2cad#23

## Phase 1: Rewrite `_primitive_to_shape` to use OCP constructors **Goal:** Replace `pc2cad.py:3592 _primitive_to_shape(FreeCAD, Part, primitive)` with an OCP-only equivalent that does not take FreeCAD/Part as parameters. This is the per-primitive shape constructor every boolean and export op funnels through, so it is the choke point. **Approach:** - Sphere → `BRepPrimAPI_MakeSphere(center, radius).Shape()` - Cylinder → `BRepPrimAPI_MakeCylinder(axis_point, axis_dir, radius, height).Shape()` - Cone → `BRepPrimAPI_MakeCone(...)` (derive base/apex from primitive) - Plane (polygon face) → `BRepBuilderAPI_MakeFace` from the polygon's `Poly_Triangulation` or from the inlier-hull polygon as a `TopoDS_Wire` on a plane. - New signature: `_primitive_to_shape(primitive: Primitive) -> TopoDS_Shape`. Drop the FreeCAD, Part params. **Files:** `pc2cad.py:3592-3690` (rewrite `_primitive_to_shape`), `pc2cad.py:3583-3591` (delete `_freecad_import`). **Acceptance:** - New function exists, old signature gone, no FreeCAD import. - `git grep "def _primitive_to_shape" pc2cad.py` shows the new signature. - All 8 boolean call sites (lines 3831, 4040, etc.) updated to the new signature; lint passes. - All existing tests still pass (no behavioural change yet — just signature). --- --- _Decomposed from [pc2cad#23](https://forgejo.tail018ac4.ts.net/Mark/pc2cad/issues/23)_
Mark closed this issue 2026-07-05 17:53:59 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/pc2cad#41
No description provided.