Skip to content

Commit

Permalink
methods to fix shape tolerances
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Nov 12, 2016
1 parent ad49a96 commit a557836
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Mod/Part/App/TopoShapePy.xml
Expand Up @@ -543,6 +543,7 @@ infos contains additional info on the solutions. It is a list of tuples:
<Documentation>
<UserDocu>
getTolerance(mode, ShapeType=Shape) -> float

Determines a tolerance from the ones stored in a shape
mode = 0 : returns the average value between sub-shapes,
mode &gt; 0 : returns the maximal found,
Expand All @@ -561,6 +562,7 @@ infos contains additional info on the solutions. It is a list of tuples:
<Documentation>
<UserDocu>
overTolerance(value, ShapeType=Shape) -> float

Determines which shapes have a tolerance over the given value
ShapeType is interpreted as in the method getTolerance
</UserDocu>
Expand All @@ -570,6 +572,7 @@ infos contains additional info on the solutions. It is a list of tuples:
<Documentation>
<UserDocu>
inTolerance(value, ShapeType=Shape) -> float

Determines which shapes have a tolerance within a given interval
ShapeType is interpreted as in the method getTolerance
</UserDocu>
Expand All @@ -579,13 +582,49 @@ infos contains additional info on the solutions. It is a list of tuples:
<Documentation>
<UserDocu>
globalTolerance(mode) -> float

Returns the computed tolerance according to the mode
mode = 0 : average
mode &gt; 0 : maximal
mode &lt; 0 : minimal
</UserDocu>
</Documentation>
</Methode>
<Methode Name="fixTolerance" Const="true">
<Documentation>
<UserDocu>
fixTolerance(value, ShapeType=Shape)

Sets (enforces) tolerances in a shape to the given value
ShapeType = Vertex : only vertices are set
ShapeType = Edge : only edges are set
ShapeType = Face : only faces are set
ShapeType = Wire : to have edges and their vertices set
ShapeType = other value : all (vertices,edges,faces) are set
</UserDocu>
</Documentation>
</Methode>
<Methode Name="limitTolerance" Const="true">
<Documentation>
<UserDocu>
limitTolerance(tmin, tmax=0, ShapeType=Shape)

Limits tolerances in a shape as follows :
tmin = tmax -> as fixTolerance (forces)
tmin = 0 -> maximum tolerance will be tmax
tmax = 0 or not given (more generally, tmax &lt; tmin) ->
tmax ignored, minimum will be tmin
else, maximum will be max and minimum will be min
ShapeType = Vertex : only vertices are set
ShapeType = Edge : only edges are set
ShapeType = Face : only faces are set
ShapeType = Wire : to have edges and their vertices set
ShapeType = other value : all (vertices,edges,faces) are set
Returns True if at least one tolerance of the sub-shape has
been modified
</UserDocu>
</Documentation>
</Methode>
<!--
<Attribute Name="Location" ReadOnly="false">
<Documentation>
Expand Down
82 changes: 82 additions & 0 deletions src/Mod/Part/App/TopoShapePyImp.cpp
Expand Up @@ -60,6 +60,7 @@
#include <GProp_GProps.hxx>
#include <BRepAlgo_NormalProjection.hxx>
#include <ShapeAnalysis_ShapeTolerance.hxx>
#include <ShapeFix_ShapeTolerance.hxx>


#include <Base/GeometryPyCXX.h>
Expand Down Expand Up @@ -2018,6 +2019,87 @@ PyObject* TopoShapePy::globalTolerance(PyObject *args)
}
}

PyObject* TopoShapePy::fixTolerance(PyObject *args)
{
double value;
PyObject* type=0;
if (!PyArg_ParseTuple(args, "d|O!", &value, &PyType_Type, &type))
return NULL;

try {
TopoDS_Shape shape = this->getTopoShapePtr()->getShape();
TopAbs_ShapeEnum shapetype = TopAbs_SHAPE;

PyTypeObject* pyType = reinterpret_cast<PyTypeObject*>(type);
if (pyType == 0)
shapetype = TopAbs_SHAPE;
else if (PyType_IsSubtype(pyType, &TopoShapeWirePy::Type))
shapetype = TopAbs_WIRE;
else if (PyType_IsSubtype(pyType, &TopoShapeFacePy::Type))
shapetype = TopAbs_FACE;
else if (PyType_IsSubtype(pyType, &TopoShapeEdgePy::Type))
shapetype = TopAbs_EDGE;
else if (PyType_IsSubtype(pyType, &TopoShapeVertexPy::Type))
shapetype = TopAbs_VERTEX;
else if (PyType_IsSubtype(pyType, &TopoShapePy::Type))
shapetype = TopAbs_SHAPE;
else if (pyType != &TopoShapePy::Type) {
PyErr_SetString(PyExc_TypeError, "type must be a shape type");
return 0;
}

ShapeFix_ShapeTolerance fix;
fix.SetTolerance(shape, value, shapetype);
Py_Return;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
return NULL;
}
}

PyObject* TopoShapePy::limitTolerance(PyObject *args)
{
double tmin;
double tmax=0;
PyObject* type=0;
if (!PyArg_ParseTuple(args, "d|dO!", &tmin, &tmax, &PyType_Type, &type))
return NULL;

try {
TopoDS_Shape shape = this->getTopoShapePtr()->getShape();
TopAbs_ShapeEnum shapetype = TopAbs_SHAPE;

PyTypeObject* pyType = reinterpret_cast<PyTypeObject*>(type);
if (pyType == 0)
shapetype = TopAbs_SHAPE;
else if (PyType_IsSubtype(pyType, &TopoShapeWirePy::Type))
shapetype = TopAbs_WIRE;
else if (PyType_IsSubtype(pyType, &TopoShapeFacePy::Type))
shapetype = TopAbs_FACE;
else if (PyType_IsSubtype(pyType, &TopoShapeEdgePy::Type))
shapetype = TopAbs_EDGE;
else if (PyType_IsSubtype(pyType, &TopoShapeVertexPy::Type))
shapetype = TopAbs_VERTEX;
else if (PyType_IsSubtype(pyType, &TopoShapePy::Type))
shapetype = TopAbs_SHAPE;
else if (pyType != &TopoShapePy::Type) {
PyErr_SetString(PyExc_TypeError, "type must be a shape type");
return 0;
}

ShapeFix_ShapeTolerance fix;
Standard_Boolean ok = fix.LimitTolerance(shape, tmin, tmax, shapetype);
return PyBool_FromLong(ok ? 1 : 0);
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
return NULL;
}
}

PyObject* _getSupportIndex(char* suppStr, TopoShape* ts, TopoDS_Shape suppShape) {
std::stringstream ss;
TopoDS_Shape subShape;
Expand Down

0 comments on commit a557836

Please sign in to comment.