methods to analyze shape tolerances
This commit is contained in:
parent
1537ecf9e4
commit
ad49a96b14
|
@ -539,6 +539,53 @@ infos contains additional info on the solutions. It is a list of tuples:
|
||||||
<UserDocu>Returns a SubElement</UserDocu>
|
<UserDocu>Returns a SubElement</UserDocu>
|
||||||
</Documentation>
|
</Documentation>
|
||||||
</Methode>
|
</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 > 0 : returns the maximal found,
|
||||||
|
mode < 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 > 0 : maximal
|
||||||
|
mode < 0 : minimal
|
||||||
|
</UserDocu>
|
||||||
|
</Documentation>
|
||||||
|
</Methode>
|
||||||
<!--
|
<!--
|
||||||
<Attribute Name="Location" ReadOnly="false">
|
<Attribute Name="Location" ReadOnly="false">
|
||||||
<Documentation>
|
<Documentation>
|
||||||
|
|
|
@ -59,6 +59,7 @@
|
||||||
#include <BRepGProp.hxx>
|
#include <BRepGProp.hxx>
|
||||||
#include <GProp_GProps.hxx>
|
#include <GProp_GProps.hxx>
|
||||||
#include <BRepAlgo_NormalProjection.hxx>
|
#include <BRepAlgo_NormalProjection.hxx>
|
||||||
|
#include <ShapeAnalysis_ShapeTolerance.hxx>
|
||||||
|
|
||||||
|
|
||||||
#include <Base/GeometryPyCXX.h>
|
#include <Base/GeometryPyCXX.h>
|
||||||
|
@ -70,19 +71,19 @@
|
||||||
#include <CXX/Extensions.hxx>
|
#include <CXX/Extensions.hxx>
|
||||||
|
|
||||||
#include "TopoShape.h"
|
#include "TopoShape.h"
|
||||||
#include "TopoShapePy.h"
|
#include <Mod/Part/App/TopoShapePy.h>
|
||||||
#include "TopoShapePy.cpp"
|
#include <Mod/Part/App/TopoShapePy.cpp>
|
||||||
|
|
||||||
#include "OCCError.h"
|
#include "OCCError.h"
|
||||||
#include "GeometryPy.h"
|
#include <Mod/Part/App/GeometryPy.h>
|
||||||
#include "TopoShapeFacePy.h"
|
#include <Mod/Part/App/TopoShapeFacePy.h>
|
||||||
#include "TopoShapeEdgePy.h"
|
#include <Mod/Part/App/TopoShapeEdgePy.h>
|
||||||
#include "TopoShapeWirePy.h"
|
#include <Mod/Part/App/TopoShapeWirePy.h>
|
||||||
#include "TopoShapeVertexPy.h"
|
#include <Mod/Part/App/TopoShapeVertexPy.h>
|
||||||
#include "TopoShapeSolidPy.h"
|
#include <Mod/Part/App/TopoShapeSolidPy.h>
|
||||||
#include "TopoShapeShellPy.h"
|
#include <Mod/Part/App/TopoShapeShellPy.h>
|
||||||
#include "TopoShapeCompSolidPy.h"
|
#include <Mod/Part/App/TopoShapeCompSolidPy.h>
|
||||||
#include "TopoShapeCompoundPy.h"
|
#include <Mod/Part/App/TopoShapeCompoundPy.h>
|
||||||
|
|
||||||
using namespace Part;
|
using namespace Part;
|
||||||
|
|
||||||
|
@ -1851,6 +1852,172 @@ PyObject* TopoShapePy::getElement(PyObject *args)
|
||||||
return 0;
|
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) {
|
PyObject* _getSupportIndex(char* suppStr, TopoShape* ts, TopoDS_Shape suppShape) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
TopoDS_Shape subShape;
|
TopoDS_Shape subShape;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user