diff --git a/libsrc/occ/python_occ_basic.cpp b/libsrc/occ/python_occ_basic.cpp index 3c94fe1a..3384e3ef 100644 --- a/libsrc/occ/python_occ_basic.cpp +++ b/libsrc/occ/python_occ_basic.cpp @@ -49,6 +49,16 @@ DLL_HEADER void ExportNgOCCBasic(py::module &m) .def("__sub__", [](gp_Pnt p1, gp_Pnt p2) { return gp_Vec(p2, p1); }) .def("__add__", [](gp_Pnt p, gp_Vec v) { return p.Translated(v); }) // gp_Pnt(p.X()+v.X(), p.Y()+v.Y(), p.Z()+v.Z()); }) .def("__sub__", [](gp_Pnt p, gp_Vec v) { return p.Translated(-v); }) // gp_Pnt(p.X()-v.X(), p.Y()-v.Y(), p.Z()-v.Z()); }) + .def("__getitem__", [](const gp_Pnt& p, int index) + { + if(index == 0) + return p.X(); + if(index == 1) + return p.Y(); + if(index == 2) + return p.Z(); + throw std::out_of_range("Point index must be in range [0,3)!"); + }) ; py::class_(m, "gp_Vec", "3d OCC vector") diff --git a/libsrc/occ/python_occ_shapes.cpp b/libsrc/occ/python_occ_shapes.cpp index defe7b34..b6b68eb1 100644 --- a/libsrc/occ/python_occ_shapes.cpp +++ b/libsrc/occ/python_occ_shapes.cpp @@ -972,14 +972,22 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m) .def("Reversed", [](const TopoDS_Shape & shape) { return CastShape(shape.Reversed()); }) - .def("Extrude", [](const TopoDS_Shape & shape, double h) { + .def("Extrude", [](const TopoDS_Shape & shape, double h, + optional dir) { for (TopExp_Explorer e(shape, TopAbs_FACE); e.More(); e.Next()) { Handle(Geom_Surface) surf = BRep_Tool::Surface (TopoDS::Face(e.Current())); - gp_Vec du, dv; - gp_Pnt p; - surf->D1 (0,0,p,du,dv); - BRepPrimAPI_MakePrism builder(shape, h*du^dv, true); + gp_Vec edir; + if(dir.has_value()) + edir = *dir; + else + { + gp_Vec du, dv; + gp_Pnt p; + surf->D1 (0,0,p,du,dv); + edir = du^dv; + } + BRepPrimAPI_MakePrism builder(shape, h*edir, true); for (auto typ : { TopAbs_EDGE, TopAbs_VERTEX }) for (TopExp_Explorer e(shape, typ); e.More(); e.Next()) @@ -992,7 +1000,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m) return builder.Shape(); } throw Exception("no face found for extrusion"); - }, py::arg("h"), "extrude shape to thickness 'h', shape must contain a plane surface") + }, py::arg("h"), py::arg("dir")=nullopt, "extrude shape to thickness 'h', shape must contain a plane surface, optionally give an extrusion direction") .def("Extrude", [] (const TopoDS_Shape & face, gp_Vec vec) { return BRepPrimAPI_MakePrism (face, vec).Shape();