From 7ac12b111b9781d951fa2202f5b069cc5802f349 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 30 Jul 2014 12:21:22 +0200 Subject: [PATCH] + Allow to get clean copy of a shape from Python --- src/Mod/Part/App/TopoShapePy.xml | 9 +++++++++ src/Mod/Part/App/TopoShapePyImp.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/Mod/Part/App/TopoShapePy.xml b/src/Mod/Part/App/TopoShapePy.xml index 797f66b0ca..ab07ed0c3f 100644 --- a/src/Mod/Part/App/TopoShapePy.xml +++ b/src/Mod/Part/App/TopoShapePy.xml @@ -361,6 +361,15 @@ into BSpline surfaces. Create a copy of this shape + + + This creates a cleaned copy of the shape with the triangulation removed. +This can be useful to reduce file size when exporting as a BRep file. +Warning: Use the cleaned shape with care because certain algorithms may work incorrectly +if the shape has no internal triangulation any more. + + + Replace a sub-shape with a new shape and return a new shape. diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index 4e01da16a4..3e66232941 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -172,6 +172,31 @@ PyObject* TopoShapePy::copy(PyObject *args) return cpy; } +PyObject* TopoShapePy::cleaned(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + + const TopoDS_Shape& shape = this->getTopoShapePtr()->_Shape; + PyTypeObject* type = this->GetType(); + PyObject* cpy = 0; + // let the type object decide + if (type->tp_new) + cpy = type->tp_new(type, this, 0); + if (!cpy) { + PyErr_SetString(PyExc_TypeError, "failed to create copy of shape"); + return 0; + } + + if (!shape.IsNull()) { + BRepBuilderAPI_Copy c(shape); + const TopoDS_Shape& copiedShape = c.Shape(); + BRepTools::Clean(copiedShape); // remove triangulation + static_cast(cpy)->getTopoShapePtr()->_Shape = c.Shape(); + } + return cpy; +} + PyObject* TopoShapePy::replaceShape(PyObject *args) { PyObject *l;