Skip to content

Commit

Permalink
methods to analyze shape tolerances
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Nov 12, 2016
1 parent 1537ecf commit ad49a96
Show file tree
Hide file tree
Showing 2 changed files with 225 additions and 11 deletions.
47 changes: 47 additions & 0 deletions src/Mod/Part/App/TopoShapePy.xml
Expand Up @@ -539,6 +539,53 @@ infos contains additional info on the solutions. It is a list of tuples:
<UserDocu>Returns a SubElement</UserDocu>
</Documentation>
</Methode>
<Methode Name="getTolerance" Const="true">
<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,
mode &lt; 0 : returns the minimal found.
ShapeType defines what kinds of sub-shapes to consider:
Shape (default) : all : Vertex, Edge, Face,
Vertex : only vertices,
Edge : only edges,
Face : only faces,
Shell : combined Shell + Face, for each face (and containing
shell), also checks edge and Vertex
</UserDocu>
</Documentation>
</Methode>
<Methode Name="overTolerance" Const="true">
<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>
</Documentation>
</Methode>
<Methode Name="inTolerance" Const="true">
<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>
</Documentation>
</Methode>
<Methode Name="globalTolerance" Const="true">
<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>
<!--
<Attribute Name="Location" ReadOnly="false">
<Documentation>
Expand Down
189 changes: 178 additions & 11 deletions src/Mod/Part/App/TopoShapePyImp.cpp
Expand Up @@ -59,6 +59,7 @@
#include <BRepGProp.hxx>
#include <GProp_GProps.hxx>
#include <BRepAlgo_NormalProjection.hxx>
#include <ShapeAnalysis_ShapeTolerance.hxx>


#include <Base/GeometryPyCXX.h>
Expand All @@ -70,19 +71,19 @@
#include <CXX/Extensions.hxx>

#include "TopoShape.h"
#include "TopoShapePy.h"
#include "TopoShapePy.cpp"
#include <Mod/Part/App/TopoShapePy.h>
#include <Mod/Part/App/TopoShapePy.cpp>

#include "OCCError.h"
#include "GeometryPy.h"
#include "TopoShapeFacePy.h"
#include "TopoShapeEdgePy.h"
#include "TopoShapeWirePy.h"
#include "TopoShapeVertexPy.h"
#include "TopoShapeSolidPy.h"
#include "TopoShapeShellPy.h"
#include "TopoShapeCompSolidPy.h"
#include "TopoShapeCompoundPy.h"
#include <Mod/Part/App/GeometryPy.h>
#include <Mod/Part/App/TopoShapeFacePy.h>
#include <Mod/Part/App/TopoShapeEdgePy.h>
#include <Mod/Part/App/TopoShapeWirePy.h>
#include <Mod/Part/App/TopoShapeVertexPy.h>
#include <Mod/Part/App/TopoShapeSolidPy.h>
#include <Mod/Part/App/TopoShapeShellPy.h>
#include <Mod/Part/App/TopoShapeCompSolidPy.h>
#include <Mod/Part/App/TopoShapeCompoundPy.h>

using namespace Part;

Expand Down Expand Up @@ -1851,6 +1852,172 @@ PyObject* TopoShapePy::getElement(PyObject *args)
return 0;
}

PyObject* TopoShapePy::getTolerance(PyObject *args)
{
int mode;
PyObject* type=0;
if (!PyArg_ParseTuple(args, "i|O!", &mode, &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, &TopoShapeShellPy::Type))
shapetype = TopAbs_SHELL;
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 != &TopoShapePy::Type) {
if (PyType_IsSubtype(pyType, &TopoShapePy::Type)) {
PyErr_SetString(PyExc_TypeError, "shape type must be Vertex, Edge, Face or Shell");
return 0;
}
else {
PyErr_SetString(PyExc_TypeError, "type must be a shape type");
return 0;
}
}

ShapeAnalysis_ShapeTolerance analysis;
double tolerance = analysis.Tolerance(shape, mode, shapetype);
return PyFloat_FromDouble(tolerance);
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
return NULL;
}
}

PyObject* TopoShapePy::overTolerance(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, &TopoShapeShellPy::Type))
shapetype = TopAbs_SHELL;
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 != &TopoShapePy::Type) {
if (PyType_IsSubtype(pyType, &TopoShapePy::Type)) {
PyErr_SetString(PyExc_TypeError, "shape type must be Vertex, Edge, Face or Shell");
return 0;
}
else {
PyErr_SetString(PyExc_TypeError, "type must be a shape type");
return 0;
}
}

ShapeAnalysis_ShapeTolerance analysis;
Handle(TopTools_HSequenceOfShape) seq = analysis.OverTolerance(shape, value, shapetype);
Py::Tuple tuple(seq->Length());
std::size_t index=0;
for (int i=seq->Lower(); i<= seq->Upper(); i++) {
TopoDS_Shape item = seq->Value(i);
tuple.setItem(index++, shape2pyshape(item));
}
return Py::new_reference_to(tuple);
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
return NULL;
}
}

PyObject* TopoShapePy::inTolerance(PyObject *args)
{
double valmin;
double valmax;
PyObject* type=0;
if (!PyArg_ParseTuple(args, "dd|O!", &valmin, &valmax, &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, &TopoShapeShellPy::Type))
shapetype = TopAbs_SHELL;
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 != &TopoShapePy::Type) {
if (PyType_IsSubtype(pyType, &TopoShapePy::Type)) {
PyErr_SetString(PyExc_TypeError, "shape type must be Vertex, Edge, Face or Shell");
return 0;
}
else {
PyErr_SetString(PyExc_TypeError, "type must be a shape type");
return 0;
}
}

ShapeAnalysis_ShapeTolerance analysis;
Handle(TopTools_HSequenceOfShape) seq = analysis.InTolerance(shape, valmin, valmax, shapetype);
Py::Tuple tuple(seq->Length());
std::size_t index=0;
for (int i=seq->Lower(); i<= seq->Upper(); i++) {
TopoDS_Shape item = seq->Value(i);
tuple.setItem(index++, shape2pyshape(item));
}
return Py::new_reference_to(tuple);
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
return NULL;
}
}

PyObject* TopoShapePy::globalTolerance(PyObject *args)
{
int mode;
if (!PyArg_ParseTuple(args, "i", &mode))
return NULL;

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

ShapeAnalysis_ShapeTolerance analysis;
analysis.Tolerance(shape, mode);
double tolerance = analysis.GlobalTolerance(mode);
return PyFloat_FromDouble(tolerance);
}
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 ad49a96

Please sign in to comment.