From 95fbd8a099cc496f739f833c3720aaabd8c275da Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 14 Jan 2018 15:52:08 +0100 Subject: [PATCH] add method to get u,v nodes of the tessellation of a face add method to get the nodes of the tessellation of an edge --- src/Mod/Part/App/TopoShapeEdgePy.xml | 12 ++++- src/Mod/Part/App/TopoShapeEdgePyImp.cpp | 65 +++++++++++++++++++++++++ src/Mod/Part/App/TopoShapeFacePy.xml | 11 ++++- src/Mod/Part/App/TopoShapeFacePyImp.cpp | 32 ++++++++++++ 4 files changed, 118 insertions(+), 2 deletions(-) diff --git a/src/Mod/Part/App/TopoShapeEdgePy.xml b/src/Mod/Part/App/TopoShapeEdgePy.xml index 7683fced33..a7dba7096b 100644 --- a/src/Mod/Part/App/TopoShapeEdgePy.xml +++ b/src/Mod/Part/App/TopoShapeEdgePy.xml @@ -114,7 +114,17 @@ Returns: - + + + +parameters([face]) --> list +Get the list of parameters of the tessellation of an edge. If the edge is part of +a face then this face is required as argument. +An exception is raised if the edge has no polygon. + + + + Float = parameterAt(Vertex) - Get the parameter at the given vertex if lying on the edge diff --git a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp index d24c6c0c17..aa631d0a6c 100644 --- a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp @@ -49,11 +49,17 @@ # include # include # include +# include +# include +# include +# include +# include # include # include # include # include # include +# include # include # include # include @@ -221,6 +227,65 @@ PyObject* TopoShapeEdgePy::valueAt(PyObject *args) return new Base::VectorPy(new Base::Vector3d(V.X(),V.Y(),V.Z())); } +PyObject* TopoShapeEdgePy::parameters(PyObject *args) +{ + PyObject* pyface = 0; + if (!PyArg_ParseTuple(args, "|O!", &(TopoShapeFacePy::Type), &pyface)) + return 0; + + const TopoDS_Edge& e = TopoDS::Edge(getTopoShapePtr()->getShape()); + TopLoc_Location aLoc; + Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(e, aLoc); + if (!aPoly.IsNull()) { + Py::List list; + if (!aPoly->HasParameters()) { + return Py::new_reference_to(list); + } + + const TColStd_Array1OfReal& aNodes = aPoly->Parameters(); + for (int i=aNodes.Lower(); i<=aNodes.Upper(); i++) { + list.append(Py::Float(aNodes(i))); + } + + return Py::new_reference_to(list); + } + else if (pyface) { + // build up map edge->face + const TopoDS_Shape& face = static_cast(pyface)->getTopoShapePtr()->getShape(); + TopTools_IndexedDataMapOfShapeListOfShape edge2Face; + TopExp::MapShapesAndAncestors(TopoDS::Face(face), TopAbs_EDGE, TopAbs_FACE, edge2Face); + if (edge2Face.Contains(e)) { + Handle(Poly_Triangulation) aPolyTria = BRep_Tool::Triangulation(TopoDS::Face(face),aLoc); + if (!aPolyTria.IsNull()) { + Handle(Poly_PolygonOnTriangulation) aPoly = BRep_Tool::PolygonOnTriangulation(e, aPolyTria, aLoc); + if (!aPoly.IsNull()) { + if (!aPoly->HasParameters()) { + Py::List list; + return Py::new_reference_to(list); + } + + Handle(TColStd_HArray1OfReal) aNodes = aPoly->Parameters(); + if (!aNodes.IsNull()) { + Py::List list; + for (int i=aNodes->Lower(); i<=aNodes->Upper(); i++) { + list.append(Py::Float(aNodes->Value(i))); + } + + return Py::new_reference_to(list); + } + } + } + } + else { + PyErr_SetString(PyExc_ValueError, "Edge is not part of the face"); + return 0; + } + } + + PyErr_SetString(PyExc_RuntimeError, "Edge has no polygon"); + return 0; +} + PyObject* TopoShapeEdgePy::parameterAt(PyObject *args) { PyObject* pnt; diff --git a/src/Mod/Part/App/TopoShapeFacePy.xml b/src/Mod/Part/App/TopoShapeFacePy.xml index 1bcab91a7f..3a19ea14c3 100644 --- a/src/Mod/Part/App/TopoShapeFacePy.xml +++ b/src/Mod/Part/App/TopoShapeFacePy.xml @@ -19,7 +19,16 @@ Offset the face by a given amount. Returns Compound of Wires. Deprecated - use makeOffset2D instead. - + + + +getUVNodes() --> list +Get the list of (u,v) nodes of the tessellation +An exception is raised if the face is not triangulated. + + + + Get the tangent in u and v isoparametric at the given point if defined diff --git a/src/Mod/Part/App/TopoShapeFacePyImp.cpp b/src/Mod/Part/App/TopoShapeFacePyImp.cpp index 304270db1e..64730029e7 100644 --- a/src/Mod/Part/App/TopoShapeFacePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeFacePyImp.cpp @@ -43,6 +43,7 @@ # include # include # include +# include # include # include # include @@ -56,6 +57,7 @@ # include # include # include +# include # include # include #endif @@ -433,6 +435,36 @@ PyObject* TopoShapeFacePy::normalAt(PyObject *args) } } +PyObject* TopoShapeFacePy::getUVNodes(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return 0; + + const TopoDS_Face& f = TopoDS::Face(getTopoShapePtr()->getShape()); + TopLoc_Location aLoc; + Handle (Poly_Triangulation) mesh = BRep_Tool::Triangulation(f,aLoc); + if (mesh.IsNull()) { + PyErr_SetString(PyExc_RuntimeError, "Face has no triangulation"); + return 0; + } + + Py::List list; + if (!mesh->HasUVNodes()) { + return Py::new_reference_to(list); + } + + const TColgp_Array1OfPnt2d& aNodesUV = mesh->UVNodes(); + for (int i=aNodesUV.Lower(); i<=aNodesUV.Upper(); i++) { + gp_Pnt2d pt2d = aNodesUV(i); + Py::Tuple uv(2); + uv.setItem(0, Py::Float(pt2d.X())); + uv.setItem(1, Py::Float(pt2d.Y())); + list.append(uv); + } + + return Py::new_reference_to(list); +} + PyObject* TopoShapeFacePy::tangentAt(PyObject *args) { double u,v;