From ea6f4d0713c0fedd80e1028482707595dc837c72 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Fri, 6 Aug 2021 21:33:54 +0200 Subject: [PATCH] Offset in workplane --- libsrc/occ/python_occ_shapes.cpp | 46 ++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/libsrc/occ/python_occ_shapes.cpp b/libsrc/occ/python_occ_shapes.cpp index b66d8676..ab3ac396 100644 --- a/libsrc/occ/python_occ_shapes.cpp +++ b/libsrc/occ/python_occ_shapes.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -152,14 +153,52 @@ public: localpos.Rotate(localpos.Location(), angle*M_PI/180); return shared_from_this(); } + + auto Rectangle (double l, double w) + { + Line (l); + Rotate (90); + Line(w); + Rotate (90); + Line (l); + Rotate (90); + Line(w); + Rotate (90); + wires.push_back (wire_builder.Wire()); + wire_builder = BRepBuilderAPI_MakeWire(); + return shared_from_this(); + } auto Close () { LineTo (startpnt.X(), startpnt.Y()); wires.push_back (wire_builder.Wire()); wire_builder = BRepBuilderAPI_MakeWire(); + return shared_from_this(); } - + + auto Reverse() + { + wires.back().Reverse(); + return shared_from_this(); + } + + auto Offset(double d) + { + TopoDS_Wire wire = wires.back(); + wires.pop_back(); + BRepOffsetAPI_MakeOffset builder; + builder.AddWire(wire); + cout << "call builder" << endl; + builder.Perform(d); + cout << "perform is back" << endl; + auto shape = builder.Shape(); + cout << "builder is back" << endl; + cout << "Offset got shape type " << shape.ShapeType() << endl; + wires.push_back (TopoDS::Wire(shape.Reversed())); + return shared_from_this(); + } + TopoDS_Wire Last() { return wires.back(); @@ -409,7 +448,7 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m) gp_Vec du, dv; gp_Pnt p; surf->D1 (0,0,p,du,dv); - return BRepPrimAPI_MakePrism (shape, du^dv).Shape(); + return BRepPrimAPI_MakePrism (shape, h*du^dv).Shape(); } throw Exception("no face found for extrusion"); }) @@ -901,6 +940,9 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m) .def("Rotate", &WorkPlane::Rotate) .def("Line", [](WorkPlane&wp,double l) { return wp.Line(l); }) .def("Line", [](WorkPlane&wp,double h,double v) { return wp.Line(h,v); }) + .def("Rectangle", &WorkPlane::Rectangle) + .def("Offset", &WorkPlane::Offset) + .def("Reverse", &WorkPlane::Reverse) .def("Close", &WorkPlane::Close) .def("Last", &WorkPlane::Last) .def("Face", &WorkPlane::Face)