From 6ed14ed76a03d5040f3192a5f529a37d48dd0ce8 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 18 Sep 2017 22:16:15 +0200 Subject: [PATCH] for boolean ops also support to pass single shape and tolerance --- src/Mod/Part/App/TopoShapePyImp.cpp | 74 ++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index c01f9b5880..71816338d7 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -782,6 +782,25 @@ PyObject* TopoShapePy::fuse(PyObject *args) PyErr_Clear(); double tolerance = 0.0; + if (PyArg_ParseTuple(args, "O!d", &(TopoShapePy::Type), &pcObj, &tolerance)) { + std::vector shapeVec; + shapeVec.push_back(static_cast(pcObj)->getTopoShapePtr()->getShape()); + try { + // Let's call algorithm computing a fuse operation: + TopoDS_Shape fuseShape = this->getTopoShapePtr()->fuse(shapeVec,tolerance); + return new TopoShapePy(new TopoShape(fuseShape)); + } + catch (Standard_Failure& e) { + PyErr_SetString(PartExceptionOCCError, e.GetMessageString()); + return NULL; + } + catch (const std::exception& e) { + PyErr_SetString(PartExceptionOCCError, e.what()); + return NULL; + } + } + + PyErr_Clear(); if (PyArg_ParseTuple(args, "O|d", &pcObj, &tolerance)) { std::vector shapeVec; Py::Sequence shapeSeq(pcObj); @@ -800,7 +819,6 @@ PyObject* TopoShapePy::fuse(PyObject *args) return new TopoShapePy(new TopoShape(multiFusedShape)); } catch (Standard_Failure& e) { - PyErr_SetString(PartExceptionOCCError, e.GetMessageString()); return NULL; } @@ -893,6 +911,24 @@ PyObject* TopoShapePy::common(PyObject *args) PyErr_Clear(); double tolerance = 0.0; + if (PyArg_ParseTuple(args, "O!d", &(TopoShapePy::Type), &pcObj, &tolerance)) { + std::vector shapeVec; + shapeVec.push_back(static_cast(pcObj)->getTopoShapePtr()->getShape()); + try { + TopoDS_Shape commonShape = this->getTopoShapePtr()->common(shapeVec,tolerance); + return new TopoShapePy(new TopoShape(commonShape)); + } + catch (Standard_Failure& e) { + PyErr_SetString(PartExceptionOCCError, e.GetMessageString()); + return NULL; + } + catch (const std::exception& e) { + PyErr_SetString(PartExceptionOCCError, e.what()); + return NULL; + } + } + + PyErr_Clear(); if (PyArg_ParseTuple(args, "O|d", &pcObj, &tolerance)) { std::vector shapeVec; Py::Sequence shapeSeq(pcObj); @@ -948,6 +984,24 @@ PyObject* TopoShapePy::section(PyObject *args) PyErr_Clear(); double tolerance = 0.0; + if (PyArg_ParseTuple(args, "O!d", &(TopoShapePy::Type), &pcObj, &tolerance)) { + std::vector shapeVec; + shapeVec.push_back(static_cast(pcObj)->getTopoShapePtr()->getShape()); + try { + TopoDS_Shape sectionShape = this->getTopoShapePtr()->section(shapeVec,tolerance); + return new TopoShapePy(new TopoShape(sectionShape)); + } + catch (Standard_Failure& e) { + PyErr_SetString(PartExceptionOCCError, e.GetMessageString()); + return NULL; + } + catch (const std::exception& e) { + PyErr_SetString(PartExceptionOCCError, e.what()); + return NULL; + } + } + + PyErr_Clear(); if (PyArg_ParseTuple(args, "O|d", &pcObj, &tolerance)) { std::vector shapeVec; Py::Sequence shapeSeq(pcObj); @@ -1058,6 +1112,24 @@ PyObject* TopoShapePy::cut(PyObject *args) PyErr_Clear(); double tolerance = 0.0; + if (PyArg_ParseTuple(args, "O!d", &(TopoShapePy::Type), &pcObj, &tolerance)) { + std::vector shapeVec; + shapeVec.push_back(static_cast(pcObj)->getTopoShapePtr()->getShape()); + try { + TopoDS_Shape cutShape = this->getTopoShapePtr()->cut(shapeVec,tolerance); + return new TopoShapePy(new TopoShape(cutShape)); + } + catch (Standard_Failure& e) { + PyErr_SetString(PartExceptionOCCError, e.GetMessageString()); + return NULL; + } + catch (const std::exception& e) { + PyErr_SetString(PartExceptionOCCError, e.what()); + return NULL; + } + } + + PyErr_Clear(); if (PyArg_ParseTuple(args, "O|d", &pcObj, &tolerance)) { std::vector shapeVec; Py::Sequence shapeSeq(pcObj);