From 56e848eea930fd38e78d775f382182a3efda086e Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Sat, 24 Jul 2021 19:53:30 +0200 Subject: [PATCH] pywrapping occ --- libsrc/occ/python_occ.cpp | 63 ++++++++++++++++++++++++++++----------- tests/pytest/results.json | 2 +- 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/libsrc/occ/python_occ.cpp b/libsrc/occ/python_occ.cpp index ac19d5cb..71c286dd 100644 --- a/libsrc/occ/python_occ.cpp +++ b/libsrc/occ/python_occ.cpp @@ -224,6 +224,27 @@ DLL_HEADER void ExportNgOCC(py::module &m) .value("SHAPE", TopAbs_SHAPE) .export_values() ; + + py::class_(m, "gp_Pnt") + .def(py::init([] (py::tuple pnt) + { + return gp_Pnt(py::cast(pnt[0]), + py::cast(pnt[1]), + py::cast(pnt[2])); + })) + ; + + py::class_(m, "gp_Dir") + .def(py::init([] (py::tuple dir) + { + return gp_Dir(py::cast(dir[0]), + py::cast(dir[1]), + py::cast(dir[2])); + })) + ; + py::implicitly_convertible(); + py::implicitly_convertible(); + py::class_ (m, "TopoDS_Shape") .def("__str__", [] (const TopoDS_Shape & shape) @@ -246,7 +267,19 @@ DLL_HEADER void ExportNgOCC(py::module &m) { // https://dev.opencascade.org/doc/occt-7.3.0/overview/html/occt_user_guides__boolean_operations.html#occt_algorithms_10a + + /* + choose boolean operation: + https://uma.ensta-paris.fr/soft/XLiFE++/?module=doc&action=source&set=release&file=OpenCascade_8cpp_source.html + BRepAlgoAPI_BooleanOperation bop; + bop.SetArguments(args); bop.SetTools(tools); + bop.SetOperation(BOPAlgo_FUSE); + */ + + + BOPAlgo_MakerVolume aMV; + // aMV.SetOperation(BOPAlgo_CUT); // BOPAlgo_Section aMV; // only vertices + edges // BOPAlgo_Builder aMV; // BRepAlgoAPI_Cut aMV; @@ -256,7 +289,7 @@ DLL_HEADER void ExportNgOCC(py::module &m) // aBuilder.SetArguments(aLSObjects); aMV.SetArguments(aLSObjects); // aMV.SetIntersect(true); - aMV.Perform(); + aMV.Perform(); // howto perform BOPAlgo_CUT ??? // aMV.Build(); return aMV.Shape(); @@ -275,23 +308,17 @@ DLL_HEADER void ExportNgOCC(py::module &m) }); ; - m.def("Sphere", [] (py::tuple c, double r) - { - gp_Pnt cc { py::cast (c[0]), py::cast(c[1]), py::cast(c[2]) }; - return BRepPrimAPI_MakeSphere (cc, r).Shape(); - }); - m.def("Cylinder", [] (py::tuple pnt, py::tuple dir, double r, double h) - { - gp_Pnt cpnt { py::cast (pnt[0]), py::cast(pnt[1]), py::cast(pnt[2]) }; - gp_Dir cdir { py::cast (dir[0]), py::cast(dir[1]), py::cast(dir[2]) }; - return BRepPrimAPI_MakeCylinder (gp_Ax2(cpnt, cdir), r, h).Shape(); - }); - m.def("Box", [] (py::tuple p1, py::tuple p2) - { - gp_Pnt cp1 { py::cast (p1[0]), py::cast(p1[1]), py::cast(p1[2]) }; - gp_Pnt cp2 { py::cast (p2[0]), py::cast(p2[1]), py::cast(p2[2]) }; - return BRepPrimAPI_MakeBox (cp1, cp2).Shape(); - }); + m.def("Sphere", [] (gp_Pnt cc, double r) { + return BRepPrimAPI_MakeSphere (cc, r).Shape(); + }); + + m.def("Cylinder", [] (gp_Pnt cpnt, gp_Dir cdir, double r, double h) { + return BRepPrimAPI_MakeCylinder (gp_Ax2(cpnt, cdir), r, h).Shape(); + }); + + m.def("Box", [] (gp_Pnt cp1, gp_Pnt cp2) { + return BRepPrimAPI_MakeBox (cp1, cp2).Shape(); + }); m.def("LoadOCCGeometry",[] (const string & filename) { diff --git a/tests/pytest/results.json b/tests/pytest/results.json index 3f4457e9..595c6a87 100644 --- a/tests/pytest/results.json +++ b/tests/pytest/results.json @@ -2407,7 +2407,7 @@ ], "ne1d": 666, "ne2d": 4880, - "ne3d": 31729, + "ne3d": 31724, "quality_histogram": "[0, 0, 0, 0, 0, 0, 0, 2, 7, 22, 105, 239, 652, 1497, 3032, 4913, 6571, 7208, 5276, 1715]", "total_badness": 38119.574769 }