diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 12b697add4..77651ccf1d 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -3277,9 +3277,9 @@ TopoDS_Shape TopoShape::removeShape(const std::vector& s) const return reshape.Apply(this->_Shape, TopAbs_SHAPE); } -void TopoShape::sewShape() +void TopoShape::sewShape(double tolerance) { - BRepBuilderAPI_Sewing sew; + BRepBuilderAPI_Sewing sew(tolerance); sew.Load(this->_Shape); sew.Perform(); @@ -3615,20 +3615,17 @@ void TopoShape::getFaces(std::vector &aPoints, } void TopoShape::setFaces(const std::vector &Points, - const std::vector &Topo, float Accuracy) + const std::vector &Topo, double tolerance) { gp_XYZ p1, p2, p3; std::vector Vertexes; std::map, TopoDS_Edge> Edges; TopoDS_Face newFace; TopoDS_Wire newWire; - BRepBuilderAPI_Sewing aSewingTool; Standard_Real x1, y1, z1; Standard_Real x2, y2, z2; Standard_Real x3, y3, z3; - aSewingTool.Init(Accuracy, Standard_True); - TopoDS_Compound aComp; BRep_Builder BuildTool; BuildTool.MakeCompound(aComp); @@ -3707,6 +3704,15 @@ void TopoShape::setFaces(const std::vector &Points, } } + // If performSewing is true BRepBuilderAPI_Sewing creates a compound of + // shells. Since the resulting shape isn't very usable in most use cases + // it's fine to set it to false so the algorithm only performs some control + // checks and creates a compound of faces. + // However, the computing time can be reduced by 90%. + // If a shell is needed then the sewShape() function should be called explicitly. + BRepBuilderAPI_Sewing aSewingTool; + Standard_Boolean performSewing = Standard_False; + aSewingTool.Init(tolerance, performSewing); aSewingTool.Load(aComp); #if OCC_VERSION_HEX < 0x070500 diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 07c43b6628..f720dae87d 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -285,7 +285,7 @@ public: TopoDS_Shape toNurbs() const; TopoDS_Shape replaceShape(const std::vector< std::pair >& s) const; TopoDS_Shape removeShape(const std::vector& s) const; - void sewShape(); + void sewShape(double tolerance = 1.0e-06); bool fix(double, double, double); bool removeInternalWires(double); TopoDS_Shape removeSplitter() const; @@ -302,7 +302,7 @@ public: virtual void getFaces(std::vector &Points,std::vector &faces, float Accuracy, uint16_t flags=0) const; void setFaces(const std::vector &Points, - const std::vector &faces, float Accuracy=1.0e-06); + const std::vector &faces, double tolerance=1.0e-06); void getDomains(std::vector&) const; //@} diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index 6d3edd729f..806d24d8ee 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -1185,8 +1185,9 @@ PyObject* TopoShapePy::generalFuse(PyObject *args) PyObject* TopoShapePy::sewShape(PyObject *args) { - if (!PyArg_ParseTuple(args, "")) - return NULL; + double tolerance = 1.0e-06; + if (!PyArg_ParseTuple(args, "|d", &tolerance)) + return nullptr; try { getTopoShapePtr()->sewShape(); @@ -2132,9 +2133,10 @@ PyObject* TopoShapePy::reflectLines(PyObject *args, PyObject *kwds) PyObject* TopoShapePy::makeShapeFromMesh(PyObject *args) { PyObject *tup; - float tolerance; - if (!PyArg_ParseTuple(args, "O!f",&PyTuple_Type, &tup, &tolerance)) - return 0; + double tolerance = 1.0e-06; + PyObject* sewShape = Py_True; + if (!PyArg_ParseTuple(args, "O!|dO!",&PyTuple_Type, &tup, &tolerance, &PyBool_Type, &sewShape)) + return nullptr; try { Py::Tuple tuple(tup); @@ -2156,7 +2158,9 @@ PyObject* TopoShapePy::makeShapeFromMesh(PyObject *args) Facets.push_back(face); } - getTopoShapePtr()->setFaces(Points, Facets,tolerance); + getTopoShapePtr()->setFaces(Points, Facets, tolerance); + if (PyObject_IsTrue(sewShape)) + getTopoShapePtr()->sewShape(tolerance); Py_Return; } PY_CATCH_OCC }