mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-12 14:10:34 +05:00
[occ] Specify extrusion direction, add getitem to gp_Pnt to iterate
This commit is contained in:
parent
ed0f8b8a53
commit
c1d768a5b3
@ -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_<gp_Vec>(m, "gp_Vec", "3d OCC vector")
|
||||
|
@ -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<gp_Vec> 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();
|
||||
|
Loading…
Reference in New Issue
Block a user