From f3ac51d9b7ca0ccca68879d31d69812fdebb7a9c Mon Sep 17 00:00:00 2001 From: tomate44 Date: Sun, 10 Jun 2018 17:51:12 +0200 Subject: [PATCH] add Approximation option to TopoShape section --- src/Mod/Part/App/TopoShape.cpp | 13 ++++++++++--- src/Mod/Part/App/TopoShape.h | 4 ++-- src/Mod/Part/App/TopoShapePy.xml | 6 ++++-- src/Mod/Part/App/TopoShapePyImp.cpp | 13 +++++++------ 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index dcc4224768..7be315d84c 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -1637,17 +1637,23 @@ TopoDS_Shape TopoShape::oldFuse(TopoDS_Shape shape) const #endif } -TopoDS_Shape TopoShape::section(TopoDS_Shape shape) const +TopoDS_Shape TopoShape::section(TopoDS_Shape shape, const Standard_Boolean approximate) const { if (this->_Shape.IsNull()) Standard_Failure::Raise("Base shape is null"); if (shape.IsNull()) Standard_Failure::Raise("Tool shape is null"); - BRepAlgoAPI_Section mkSection(this->_Shape, shape); + BRepAlgoAPI_Section mkSection; + mkSection.Init1(this->_Shape); + mkSection.Init2(shape); + mkSection.Approximation(approximate); + mkSection.Build(); + if (!mkSection.IsDone()) + throw Base::RuntimeError("Section failed"); return mkSection.Shape(); } -TopoDS_Shape TopoShape::section(const std::vector& shapes, Standard_Real tolerance) const +TopoDS_Shape TopoShape::section(const std::vector& shapes, Standard_Real tolerance, const Standard_Boolean approximate) const { if (this->_Shape.IsNull()) Standard_Failure::Raise("Base shape is null"); @@ -1658,6 +1664,7 @@ TopoDS_Shape TopoShape::section(const std::vector& shapes, Standar #else BRepAlgoAPI_Section mkSection; mkSection.SetRunParallel(true); + mkSection.Approximation(approximate); TopTools_ListOfShape shapeArguments,shapeTools; shapeArguments.Append(this->_Shape); for (std::vector::const_iterator it = shapes.begin(); it != shapes.end(); ++it) { diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index e4d1a44fc6..c4916a5226 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -165,8 +165,8 @@ public: TopoDS_Shape fuse(TopoDS_Shape) const; TopoDS_Shape fuse(const std::vector&, Standard_Real tolerance = 0.0) const; TopoDS_Shape oldFuse(TopoDS_Shape) const; - TopoDS_Shape section(TopoDS_Shape) const; - TopoDS_Shape section(const std::vector&, Standard_Real tolerance = 0.0) const; + TopoDS_Shape section(TopoDS_Shape, const Standard_Boolean approximate=Standard_False) const; + TopoDS_Shape section(const std::vector&, Standard_Real tolerance = 0.0, const Standard_Boolean approximate=Standard_False) const; std::list slice(const Base::Vector3d&, double) const; TopoDS_Compound slices(const Base::Vector3d&, const std::vector&) const; /** diff --git a/src/Mod/Part/App/TopoShapePy.xml b/src/Mod/Part/App/TopoShapePy.xml index f19b27e773..91966033ed 100644 --- a/src/Mod/Part/App/TopoShapePy.xml +++ b/src/Mod/Part/App/TopoShapePy.xml @@ -197,9 +197,11 @@ OCC 6.9.0 or later is required. Section of this with a given (list of) topo shape. -section(tool) -> Shape +section(tool,[approximation=False]) -> Shape or -section((tool1,tool2,...),[tolerance=0.0]) -> Shape +section((tool1,tool2,...),[tolerance=0.0, approximation=False]) -> Shape + +If approximation is True, section edges are approximated to a C1-continuous BSpline curve. Section of this and a given list of topo shapes. diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index 6fd1b6619f..98a38f9052 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -911,11 +911,12 @@ PyObject* TopoShapePy::common(PyObject *args) PyObject* TopoShapePy::section(PyObject *args) { PyObject *pcObj; - if (PyArg_ParseTuple(args, "O!", &(TopoShapePy::Type), &pcObj)) { + PyObject *approx = Py_False; + if (PyArg_ParseTuple(args, "O!|O!", &(TopoShapePy::Type), &pcObj, &(PyBool_Type), &approx)) { TopoDS_Shape shape = static_cast(pcObj)->getTopoShapePtr()->getShape(); try { // Let's call algorithm computing a section operation: - TopoDS_Shape secShape = this->getTopoShapePtr()->section(shape); + TopoDS_Shape secShape = this->getTopoShapePtr()->section(shape,PyObject_IsTrue(approx) ? true : false); return new TopoShapePy(new TopoShape(secShape)); } catch (Standard_Failure& e) { @@ -931,11 +932,11 @@ PyObject* TopoShapePy::section(PyObject *args) PyErr_Clear(); double tolerance = 0.0; - if (PyArg_ParseTuple(args, "O!d", &(TopoShapePy::Type), &pcObj, &tolerance)) { + if (PyArg_ParseTuple(args, "O!d|O!", &(TopoShapePy::Type), &pcObj, &tolerance, &(PyBool_Type), &approx)) { std::vector shapeVec; shapeVec.push_back(static_cast(pcObj)->getTopoShapePtr()->getShape()); try { - TopoDS_Shape sectionShape = this->getTopoShapePtr()->section(shapeVec,tolerance); + TopoDS_Shape sectionShape = this->getTopoShapePtr()->section(shapeVec,tolerance,PyObject_IsTrue(approx) ? true : false); return new TopoShapePy(new TopoShape(sectionShape)); } catch (Standard_Failure& e) { @@ -949,7 +950,7 @@ PyObject* TopoShapePy::section(PyObject *args) } PyErr_Clear(); - if (PyArg_ParseTuple(args, "O|d", &pcObj, &tolerance)) { + if (PyArg_ParseTuple(args, "O|dO!", &pcObj, &tolerance, &(PyBool_Type), &approx)) { std::vector shapeVec; Py::Sequence shapeSeq(pcObj); for (Py::Sequence::iterator it = shapeSeq.begin(); it != shapeSeq.end(); ++it) { @@ -963,7 +964,7 @@ PyObject* TopoShapePy::section(PyObject *args) } } try { - TopoDS_Shape multiSectionShape = this->getTopoShapePtr()->section(shapeVec,tolerance); + TopoDS_Shape multiSectionShape = this->getTopoShapePtr()->section(shapeVec,tolerance,PyObject_IsTrue(approx) ? true : false); return new TopoShapePy(new TopoShape(multiSectionShape)); } catch (Standard_Failure& e) {