diff --git a/libsrc/occ/python_occ.cpp b/libsrc/occ/python_occ.cpp index c3cdf742..7f4e2392 100644 --- a/libsrc/occ/python_occ.cpp +++ b/libsrc/occ/python_occ.cpp @@ -8,16 +8,30 @@ #include #include +#include #include +#include #include #include #include +#include #include #include #include // #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #if OCC_VERSION_MAJOR>=7 && OCC_VERSION_MINOR>=4 #define OCC_HAVE_DUMP_JSON @@ -264,6 +278,23 @@ DLL_HEADER void ExportNgOCC(py::module &m) py::cast(pnt[1]), py::cast(pnt[2])); })) + .def(py::init([] (double x, double y, double z) { + return gp_Pnt(x, y, z); + })) + .def_property("x", [](gp_Pnt&p) { return p.X(); }, [](gp_Pnt&p,double x) { p.SetX(x); }) + .def_property("y", [](gp_Pnt&p) { return p.Y(); }, [](gp_Pnt&p,double y) { p.SetY(y); }) + .def_property("z", [](gp_Pnt&p) { return p.Z(); }, [](gp_Pnt&p,double z) { p.SetZ(z); }) + ; + py::class_(m, "gp_Vec") + .def(py::init([] (py::tuple vec) + { + return gp_Vec(py::cast(vec[0]), + py::cast(vec[1]), + py::cast(vec[2])); + })) + .def(py::init([] (double x, double y, double z) { + return gp_Vec(x, y, z); + })) ; py::class_(m, "gp_Dir") @@ -274,7 +305,29 @@ DLL_HEADER void ExportNgOCC(py::module &m) py::cast(dir[2])); })) ; + + py::class_(m, "gp_Ax1") + .def(py::init([](gp_Pnt p, gp_Dir d) { + return gp_Ax1(p,d); + })) + ; + py::class_(m, "gp_Ax2") + .def(py::init([](gp_Pnt p, gp_Dir d) { + return gp_Ax2(p,d); + })) + ; + + py::class_(m, "gp_Trsf") + .def(py::init<>()) + .def("SetMirror", [] (gp_Trsf & trafo, const gp_Ax1 & ax) { trafo.SetMirror(ax); }) + .def("__call__", [] (gp_Trsf & trafo, const TopoDS_Shape & shape) { + return BRepBuilderAPI_Transform(shape, trafo).Shape(); + }) + ; + + py::implicitly_convertible(); + py::implicitly_convertible(); py::implicitly_convertible(); @@ -300,6 +353,21 @@ DLL_HEADER void ExportNgOCC(py::module &m) return sub; }) + .def("Properties", [] (const TopoDS_Shape & shape) + { + GProp_GProps props; + switch (shape.ShapeType()) + { + case TopAbs_FACE: + BRepGProp::SurfaceProperties (shape, props); break; + default: + throw Exception("Properties implemented only for FACE"); + } + double mass = props.Mass(); + gp_Pnt center = props.CentreOfMass(); + return tuple( py::cast(mass), py::cast(center) ); + }) + .def("bc", [](const TopoDS_Shape & shape, const string & name) { for (TopExp_Explorer e(shape, TopAbs_FACE); e.More(); e.Next()) @@ -410,11 +478,19 @@ DLL_HEADER void ExportNgOCC(py::module &m) 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("Cylinder", [] (gp_Ax2 ax, double r, double h) { + return BRepPrimAPI_MakeCylinder (ax, r, h).Shape(); + }); m.def("Box", [] (gp_Pnt cp1, gp_Pnt cp2) { return BRepPrimAPI_MakeBox (cp1, cp2).Shape(); }); + m.def("Prism", [] (const TopoDS_Shape & face, gp_Vec vec) { + return BRepPrimAPI_MakePrism (face, vec).Shape(); + }); + + m.def("Glue", [] (const std::vector shapes) -> TopoDS_Shape { BOPAlgo_Builder builder; @@ -471,6 +547,61 @@ DLL_HEADER void ExportNgOCC(py::module &m) return builder.Shape(); }); + + py::class_ (m, "Geom_TrimmedCurve") + ; + + m.def("Segment", [](gp_Pnt p1, gp_Pnt p2) { // ->Handle(Geom_TrimmedCurve) { + Handle(Geom_TrimmedCurve) curve = GC_MakeSegment(p1, p2); + // return curve; + return BRepBuilderAPI_MakeEdge(curve).Shape(); + }); + m.def("ArcOfCircle", [](gp_Pnt p1, gp_Pnt p2, gp_Pnt p3) { // ->Handle(Geom_TrimmedCurve) { + Handle(Geom_TrimmedCurve) curve = GC_MakeArcOfCircle(p1, p2, p3); + return BRepBuilderAPI_MakeEdge(curve).Shape(); + }); + + + m.def("Wire", [](std::vector edges) -> TopoDS_Shape { + BRepBuilderAPI_MakeWire builder; + for (auto s : edges) + { + switch (s.ShapeType()) + { + case TopAbs_EDGE: + builder.Add(TopoDS::Edge(s)); break; + case TopAbs_WIRE: + builder.Add(TopoDS::Wire(s)); break; + default: + throw Exception("can make wire only from edges and wires"); + } + } + return builder.Wire(); + }); + + m.def("Face", [](TopoDS_Shape wire) { + return BRepBuilderAPI_MakeFace(TopoDS::Wire(wire)).Shape(); + }); + + + m.def("MakeFillet", [](TopoDS_Shape shape, std::vector edges, double r) { + BRepFilletAPI_MakeFillet mkFillet(shape); + for (auto e : edges) + mkFillet.Add (r, TopoDS::Edge(e)); + return mkFillet.Shape(); + }); + + m.def("MakeThickSolid", [](TopoDS_Shape body, std::vector facestoremove, + double offset, double tol) { + + TopTools_ListOfShape faces; + for (auto f : facestoremove) + faces.Append(f); + + BRepOffsetAPI_MakeThickSolid maker; + maker.MakeThickSolidByJoin(body, faces, offset, tol); + return maker.Shape(); + }); m.def("LoadOCCGeometry",[] (const string & filename) {