diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 1cf20a7759..534e9a07f3 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -106,6 +106,7 @@ #include #include #include +#include #include #include #include @@ -367,6 +368,7 @@ PyMOD_INIT_FUNC(Part) Base::Interpreter().addType(&Part::ShapeFix_EdgeConnectPy::Type, shapeFix, "EdgeConnect"); Base::Interpreter().addType(&Part::ShapeFix_FaceConnectPy::Type, shapeFix, "FaceConnect"); Base::Interpreter().addType(&Part::ShapeFix_FixSmallFacePy::Type, shapeFix, "FixSmallFace"); + Base::Interpreter().addType(&Part::ShapeFix_FixSmallSolidPy::Type, shapeFix, "FixSmallSolid"); Base::Interpreter().addType(&Part::ShapeFix_FreeBoundsPy::Type, shapeFix, "FreeBounds"); Base::Interpreter().addType(&Part::ShapeFix_ShapeTolerancePy::Type, shapeFix, "ShapeTolerance"); Base::Interpreter().addType(&Part::ShapeFix_SplitCommonVertexPy::Type, shapeFix, "SplitCommonVertex"); diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index a44643a79f..0b7c7c327d 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -148,6 +148,7 @@ generate_from_xml(ShapeFix/ShapeFix_WireVertexPy) generate_from_xml(ShapeFix/ShapeFix_EdgeConnectPy) generate_from_xml(ShapeFix/ShapeFix_FaceConnectPy) generate_from_xml(ShapeFix/ShapeFix_FixSmallFacePy) +generate_from_xml(ShapeFix/ShapeFix_FixSmallSolidPy) generate_from_xml(ShapeFix/ShapeFix_FreeBoundsPy) generate_from_xml(ShapeFix/ShapeFix_ShapeTolerancePy) generate_from_xml(ShapeFix/ShapeFix_SplitCommonVertexPy) @@ -461,6 +462,8 @@ SET(ShapeFixPy_SRCS ShapeFix/ShapeFix_FaceConnectPyImp.cpp ShapeFix/ShapeFix_FixSmallFacePy.xml ShapeFix/ShapeFix_FixSmallFacePyImp.cpp + ShapeFix/ShapeFix_FixSmallSolidPy.xml + ShapeFix/ShapeFix_FixSmallSolidPyImp.cpp ShapeFix/ShapeFix_FreeBoundsPy.xml ShapeFix/ShapeFix_FreeBoundsPyImp.cpp ShapeFix/ShapeFix_ShapeTolerancePy.xml diff --git a/src/Mod/Part/App/ShapeFix/ShapeFix_FixSmallSolidPy.xml b/src/Mod/Part/App/ShapeFix/ShapeFix_FixSmallSolidPy.xml new file mode 100644 index 0000000000..7c71b2ac58 --- /dev/null +++ b/src/Mod/Part/App/ShapeFix/ShapeFix_FixSmallSolidPy.xml @@ -0,0 +1,49 @@ + + + + + + Fixing solids with small size + + + + +Set working mode for operator: +- theMode = 0 use both WidthFactorThreshold and VolumeThreshold parameters +- theMode = 1 use only WidthFactorThreshold parameter +- theMode = 2 use only VolumeThreshold parameter + + + + + + Set or clear volume threshold for small solids + + + + + Set or clear width factor threshold for small solids + + + + + Remove small solids from the given shape + + + + + Merge small solids in the given shape to adjacent non-small ones + + + + diff --git a/src/Mod/Part/App/ShapeFix/ShapeFix_FixSmallSolidPyImp.cpp b/src/Mod/Part/App/ShapeFix/ShapeFix_FixSmallSolidPyImp.cpp new file mode 100644 index 0000000000..ae24b8b5ec --- /dev/null +++ b/src/Mod/Part/App/ShapeFix/ShapeFix_FixSmallSolidPyImp.cpp @@ -0,0 +1,115 @@ +/*************************************************************************** + * Copyright (c) 2022 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +#endif + +#include "ShapeFix/ShapeFix_FixSmallSolidPy.h" +#include "ShapeFix/ShapeFix_FixSmallSolidPy.cpp" +#include "TopoShapePy.h" + +using namespace Part; + + +std::string ShapeFix_FixSmallSolidPy::representation() const +{ + return ""; +} + +PyObject *ShapeFix_FixSmallSolidPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + return new ShapeFix_FixSmallSolidPy(new ShapeFix_FixSmallSolid); +} + +// constructor method +int ShapeFix_FixSmallSolidPy::PyInit(PyObject* args, PyObject* /*kwds*/) +{ + if (!PyArg_ParseTuple(args, "")) + return -1; + return 0; +} + +PyObject* ShapeFix_FixSmallSolidPy::setFixMode(PyObject *args) +{ + int mode; + if (!PyArg_ParseTuple(args, "i", &mode)) + return nullptr; + + getShapeFix_FixSmallSolidPtr()->SetFixMode(mode); + Py_Return; +} + +PyObject* ShapeFix_FixSmallSolidPy::setVolumeThreshold(PyObject *args) +{ + double value = -1.0; + if (!PyArg_ParseTuple(args, "|d", &value)) + return nullptr; + + getShapeFix_FixSmallSolidPtr()->SetVolumeThreshold(value); + Py_Return; +} + +PyObject* ShapeFix_FixSmallSolidPy::setWidthFactorThreshold(PyObject *args) +{ + double value = -1.0; + if (!PyArg_ParseTuple(args, "|d", &value)) + return nullptr; + + getShapeFix_FixSmallSolidPtr()->SetWidthFactorThreshold(value); + Py_Return; +} + +PyObject* ShapeFix_FixSmallSolidPy::remove(PyObject *args) +{ + PyObject* shape; + if (!PyArg_ParseTuple(args, "O!", &TopoShapePy::Type, &shape)) + return nullptr; + + Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape(); + TopoShape sh = getShapeFix_FixSmallSolidPtr()->Remove(static_cast(shape)->getTopoShapePtr()->getShape(), context); + return sh.getPyObject(); +} + +PyObject* ShapeFix_FixSmallSolidPy::merge(PyObject *args) +{ + PyObject* shape; + if (!PyArg_ParseTuple(args, "O!", &TopoShapePy::Type, &shape)) + return nullptr; + + Handle(ShapeBuild_ReShape) context = new ShapeBuild_ReShape(); + TopoShape sh = getShapeFix_FixSmallSolidPtr()->Merge(static_cast(shape)->getTopoShapePtr()->getShape(), context); + return sh.getPyObject(); +} + +PyObject *ShapeFix_FixSmallSolidPy::getCustomAttributes(const char* /*attr*/) const +{ + return nullptr; +} + +int ShapeFix_FixSmallSolidPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +}