From a85ce1976c1dfae5e64dc65976ad6f28f488cced Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 10 Nov 2019 11:14:04 +0100 Subject: [PATCH] add method to get wires of mesh boundaries --- src/Mod/MeshPart/App/AppMeshPartPy.cpp | 33 +++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Mod/MeshPart/App/AppMeshPartPy.cpp b/src/Mod/MeshPart/App/AppMeshPartPy.cpp index eb733cc2b707..a8977dc948b9 100644 --- a/src/Mod/MeshPart/App/AppMeshPartPy.cpp +++ b/src/Mod/MeshPart/App/AppMeshPartPy.cpp @@ -86,7 +86,10 @@ class Module : public Py::ExtensionModule "projectPointsOnMesh(list of points, Mesh, Vector, [float]) -> list of points\n" ); add_varargs_method("wireFromSegment",&Module::wireFromSegment, - "Create wire(s) from boundary of segment\n" + "Create wire(s) from boundary of a mesh segment\n" + ); + add_varargs_method("wireFromMesh",&Module::wireFromMesh, + "Create wire(s) from boundary of a mesh\n" ); add_keyword_method("meshFromShape",&Module::meshFromShape, "Create surface mesh from shape\n" @@ -442,6 +445,34 @@ class Module : public Py::ExtensionModule return wires; } + Py::Object wireFromMesh(const Py::Tuple& args) + { + PyObject *m; + if (!PyArg_ParseTuple(args.ptr(), "O!", &(Mesh::MeshPy::Type), &m)) + throw Py::Exception(); + + Mesh::MeshObject* mesh = static_cast(m)->getMeshObjectPtr(); + + std::list > bounds; + MeshCore::MeshAlgorithm algo(mesh->getKernel()); + algo.GetMeshBorders(bounds); + + Py::List wires; + std::list >::iterator bt; + + for (bt = bounds.begin(); bt != bounds.end(); ++bt) { + BRepBuilderAPI_MakePolygon mkPoly; + for (std::vector::reverse_iterator it = bt->rbegin(); it != bt->rend(); ++it) { + mkPoly.Add(gp_Pnt(it->x,it->y,it->z)); + } + if (mkPoly.IsDone()) { + PyObject* wire = new Part::TopoShapeWirePy(new Part::TopoShape(mkPoly.Wire())); + wires.append(Py::Object(wire, true)); + } + } + + return wires; + } Py::Object meshFromShape(const Py::Tuple& args, const Py::Dict& kwds) { PyObject *shape;