From 565a875365c94127305a930a5c6652ae2e89e611 Mon Sep 17 00:00:00 2001 From: Sebastian Hoogen Date: Sun, 8 Mar 2015 15:41:27 +0100 Subject: [PATCH] add shape.proximity(shape) --- src/Mod/Part/App/TopoShapePy.xml | 5 +++ src/Mod/Part/App/TopoShapePyImp.cpp | 52 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/Mod/Part/App/TopoShapePy.xml b/src/Mod/Part/App/TopoShapePy.xml index 5a812748f989..88fdb257f4db 100644 --- a/src/Mod/Part/App/TopoShapePy.xml +++ b/src/Mod/Part/App/TopoShapePy.xml @@ -413,6 +413,11 @@ Boolean indicates if the point lying directly on a face is considered to be insi Removes redundant edges from the B-REP model + + + + proximity(Shape s): Returns two lists of Face indexes for the Faces involved in the intersection. + diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index c014d45e219f..e50efd1a789a 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -36,6 +36,9 @@ # include # include # include +#if OCC_VERSION_HEX >= 0x060801 +# include +#endif # include # include # include @@ -1653,6 +1656,55 @@ PyObject* _getSupportIndex(char* suppStr, TopoShape* ts, TopoDS_Shape suppShape) return PyInt_FromLong(supportIndex); } +PyObject* TopoShapePy::proximity(PyObject *args) +{ +#if OCC_VERSION_HEX >= 0x060801 + PyObject* ps2; + Standard_Real tol = Precision::Confusion(); + if (!PyArg_ParseTuple(args, "O!|d",&(TopoShapePy::Type), &ps2, &tol)) + return 0; + const TopoDS_Shape& s1 = getTopoShapePtr()->_Shape; + const TopoDS_Shape& s2 = static_cast(ps2)->getTopoShapePtr()->_Shape; + if (s1.IsNull()) { + PyErr_SetString(PyExc_ValueError, "proximity: Shape object is invalid"); + return 0; + } + if (s2.IsNull()) { + PyErr_SetString(PyExc_ValueError, "proximity: Shape parameter is invalid"); + return 0; + } + + BRepExtrema_ShapeProximity proximity;getTopoShapePtr()->_Shape; + proximity.LoadShape1 (s1); + proximity.LoadShape2 (s2); + if (tol > 0.0) + proximity.SetTolerance (tol); + proximity.Perform(); + if (!proximity.IsDone()) { + PyErr_SetString(PartExceptionOCCError, "BRepExtrema_ShapeProximity not done"); + return 0; + } + //PyObject* overlappss1 = PyList_New(0); + //PyObject* overlappss2 = PyList_New(0); + PyObject* overlappssindex1 = PyList_New(0); + PyObject* overlappssindex2 = PyList_New(0); + + for (BRepExtrema_OverlappedSubShapes::Iterator anIt1 (proximity.OverlapSubShapes1()); anIt1.More(); anIt1.Next()) { + //PyList_Append(overlappss1, new TopoShapeFacePy(new TopoShape(proximity.GetSubShape1 (anIt1.Key())))); + PyList_Append(overlappssindex1,PyInt_FromLong(anIt1.Key()+1)); + } + for (BRepExtrema_OverlappedSubShapes::Iterator anIt2 (proximity.OverlapSubShapes2()); anIt2.More(); anIt2.Next()) { + //PyList_Append(overlappss2, new TopoShapeFacePy(new TopoShape(proximity.GetSubShape2 (anIt2.Key())))); + PyList_Append(overlappssindex2,PyInt_FromLong(anIt2.Key()+1)); + } + //return Py_BuildValue("OO", overlappss1, overlappss2); //subshapes + return Py_BuildValue("OO", overlappssindex1, overlappssindex2); //face indexes +#else + PyErr_SetString(PyExc_NotImplementedError, "proximity requires OCCT >= 6.8.1"); + return 0; +#endif +} + PyObject* TopoShapePy::distToShape(PyObject *args) { PyObject* ps2;