diff --git a/src/Mod/MeshPart/App/AppMeshPartPy.cpp b/src/Mod/MeshPart/App/AppMeshPartPy.cpp index f57064fd35..fa1f8ecc40 100644 --- a/src/Mod/MeshPart/App/AppMeshPartPy.cpp +++ b/src/Mod/MeshPart/App/AppMeshPartPy.cpp @@ -32,7 +32,10 @@ #include #include #include +#include +#include #include +#include #include #include #include @@ -58,6 +61,10 @@ public: " upVector ((x, y, z) tuple):\n" " MaxSize (float):\n" ); + add_varargs_method("projectShapeOnMesh",&Module::projectShapeOnMesh, + "Projects a shape onto a mesh with a given maximum distance\n" + "projectShapeOnMesh(shape, mesh, float) -> polygon" + ); add_varargs_method("wireFromSegment",&Module::wireFromSegment, "Create wire(s) from boundary of segment\n" ); @@ -194,6 +201,31 @@ private: MeshPart::MeshAlgos::LoftOnCurve(M,aShape,poly,Base::Vector3f(x,y,z),size); return Py::asObject(new Mesh::MeshPy(new Mesh::MeshObject(M))); } + Py::Object projectShapeOnMesh(const Py::Tuple& args) + { + PyObject *s, *m; + double maxDist; + if (!PyArg_ParseTuple(args.ptr(), "O!O!d", &Part::TopoShapePy::Type, &s, + &Mesh::MeshPy::Type, &m, + &maxDist)) + throw Py::Exception(); + TopoDS_Shape shape = static_cast(s)->getTopoShapePtr()->getShape(); + const Mesh::MeshObject* mesh = static_cast(m)->getMeshObjectPtr(); + MeshCore::MeshKernel kernel(mesh->getKernel()); + kernel.Transform(mesh->getTransform()); + + MeshProjection proj(kernel); + std::vector rSplitEdges; + proj.projectToMesh(shape, maxDist, rSplitEdges); + + Py::List list; + for (auto it : rSplitEdges) { + Py::Vector v(it.cPt); + list.append(v); + } + + return list; + } Py::Object wireFromSegment(const Py::Tuple& args) { PyObject *o, *m;