Skip to content

Commit

Permalink
add shape.proximity(shape)
Browse files Browse the repository at this point in the history
  • Loading branch information
5263 authored and wwmayer committed Mar 21, 2015
1 parent 89117e2 commit 565a875
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Mod/Part/App/TopoShapePy.xml
Expand Up @@ -413,6 +413,11 @@ Boolean indicates if the point lying directly on a face is considered to be insi
<Documentation>
<UserDocu>Removes redundant edges from the B-REP model</UserDocu>
</Documentation>
</Methode>
<Methode Name="proximity" Const="true">
<Documentation>
<UserDocu>proximity(Shape s): Returns two lists of Face indexes for the Faces involved in the intersection.</UserDocu>
</Documentation>
</Methode>
<Methode Name="distToShape" Const="true">
<Documentation>
Expand Down
52 changes: 52 additions & 0 deletions src/Mod/Part/App/TopoShapePyImp.cpp
Expand Up @@ -36,6 +36,9 @@
# include <BRepProj_Projection.hxx>
# include <BRepTools.hxx>
# include <BRepExtrema_DistShapeShape.hxx>
#if OCC_VERSION_HEX >= 0x060801
# include <BRepExtrema_ShapeProximity.hxx>
#endif
# include <BRepExtrema_SupportType.hxx>
# include <gp_Ax1.hxx>
# include <gp_Ax2.hxx>
Expand Down Expand Up @@ -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<Part::TopoShapePy*>(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;
Expand Down

0 comments on commit 565a875

Please sign in to comment.