diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 04c5593cba..1cf20a7759 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -105,6 +105,7 @@ #include #include #include +#include #include #include #include @@ -365,6 +366,7 @@ PyMOD_INIT_FUNC(Part) Base::Interpreter().addType(&Part::ShapeFix_WireVertexPy::Type, shapeFix, "WireVertex"); 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_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 21accb67cd..a44643a79f 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -147,6 +147,7 @@ generate_from_xml(ShapeFix/ShapeFix_WireframePy) 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_FreeBoundsPy) generate_from_xml(ShapeFix/ShapeFix_ShapeTolerancePy) generate_from_xml(ShapeFix/ShapeFix_SplitCommonVertexPy) @@ -458,6 +459,8 @@ SET(ShapeFixPy_SRCS ShapeFix/ShapeFix_EdgeConnectPyImp.cpp ShapeFix/ShapeFix_FaceConnectPy.xml ShapeFix/ShapeFix_FaceConnectPyImp.cpp + ShapeFix/ShapeFix_FixSmallFacePy.xml + ShapeFix/ShapeFix_FixSmallFacePyImp.cpp ShapeFix/ShapeFix_FreeBoundsPy.xml ShapeFix/ShapeFix_FreeBoundsPyImp.cpp ShapeFix/ShapeFix_ShapeTolerancePy.xml diff --git a/src/Mod/Part/App/ShapeFix/ShapeFix_FixSmallFacePy.xml b/src/Mod/Part/App/ShapeFix/ShapeFix_FixSmallFacePy.xml new file mode 100644 index 0000000000..dbbd8b3469 --- /dev/null +++ b/src/Mod/Part/App/ShapeFix/ShapeFix_FixSmallFacePy.xml @@ -0,0 +1,94 @@ + + + + + + Class for fixing operations on faces + + + + Initializes by shape + + + + + Fixing case of spot face + + + + + Fixing case of spot face, if tol = -1 used local tolerance + + + + + Compute average vertex and replacing vertices by new one + + + + + Remove spot face from compound + + + + + Fixing case of strip face, if tol = -1 used local tolerance + + + + + + Remove strip face from compound + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/Part/App/ShapeFix/ShapeFix_FixSmallFacePyImp.cpp b/src/Mod/Part/App/ShapeFix/ShapeFix_FixSmallFacePyImp.cpp new file mode 100644 index 0000000000..4a23fdff6b --- /dev/null +++ b/src/Mod/Part/App/ShapeFix/ShapeFix_FixSmallFacePyImp.cpp @@ -0,0 +1,174 @@ +/*************************************************************************** + * 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_FixSmallFacePy.h" +#include "ShapeFix/ShapeFix_FixSmallFacePy.cpp" +#include "TopoShapeFacePy.h" + +using namespace Part; + + +std::string ShapeFix_FixSmallFacePy::representation() const +{ + return ""; +} + +PyObject *ShapeFix_FixSmallFacePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of ShapeFix_FacePy + return new ShapeFix_FixSmallFacePy(new ShapeFix_FixSmallFace); +} + +// constructor method +int ShapeFix_FixSmallFacePy::PyInit(PyObject* args, PyObject* /*kwds*/) +{ + if (!PyArg_ParseTuple(args, "")) + return -1; + return 0; +} + +PyObject* ShapeFix_FixSmallFacePy::init(PyObject *args) +{ + PyObject* shape; + if (!PyArg_ParseTuple(args, "O!", &TopoShapePy::Type, &shape)) + return nullptr; + + getShapeFix_FixSmallFacePtr()->Init(static_cast(shape)->getTopoShapePtr()->getShape()); + Py_Return; +} + +PyObject* ShapeFix_FixSmallFacePy::perform(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + getShapeFix_FixSmallFacePtr()->Perform(); + Py_Return; +} + +PyObject* ShapeFix_FixSmallFacePy::fixSpotFace(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + TopoShape sh = getShapeFix_FixSmallFacePtr()->FixSpotFace(); + return sh.getPyObject(); +} + +PyObject* ShapeFix_FixSmallFacePy::replaceVerticesInCaseOfSpot(PyObject *args) +{ + PyObject* face; + if (!PyArg_ParseTuple(args, "O!", &TopoShapeFacePy::Type, &face)) + return nullptr; + + TopoDS_Face shape = TopoDS::Face(static_cast(face)->getTopoShapePtr()->getShape()); + getShapeFix_FixSmallFacePtr()->ReplaceVerticesInCaseOfSpot(shape, 0.0); + return TopoShape(shape).getPyObject(); +} + +PyObject* ShapeFix_FixSmallFacePy::removeFacesInCaseOfSpot(PyObject *args) +{ + PyObject* face; + if (!PyArg_ParseTuple(args, "O!", &TopoShapeFacePy::Type, &face)) + return nullptr; + + TopoDS_Face shape = TopoDS::Face(static_cast(face)->getTopoShapePtr()->getShape()); + bool ok = getShapeFix_FixSmallFacePtr()->RemoveFacesInCaseOfSpot(shape); + return Py::new_reference_to(Py::Boolean(ok)); +} + +PyObject* ShapeFix_FixSmallFacePy::fixStripFace(PyObject *args) +{ + PyObject* wasdone = Py_False; + if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &wasdone)) + return nullptr; + + TopoShape sh = getShapeFix_FixSmallFacePtr()->FixStripFace(PyObject_IsTrue(wasdone) ? Standard_True : Standard_False); + return sh.getPyObject(); +} + +PyObject* ShapeFix_FixSmallFacePy::removeFacesInCaseOfStrip(PyObject *args) +{ + PyObject* face; + if (!PyArg_ParseTuple(args, "O!", &TopoShapeFacePy::Type, &face)) + return nullptr; + + TopoDS_Face shape = TopoDS::Face(static_cast(face)->getTopoShapePtr()->getShape()); + bool ok = getShapeFix_FixSmallFacePtr()->RemoveFacesInCaseOfStrip(shape); + return Py::new_reference_to(Py::Boolean(ok)); +} + +PyObject* ShapeFix_FixSmallFacePy::fixSplitFace(PyObject *args) +{ + PyObject* shape; + if (!PyArg_ParseTuple(args, "O!", &TopoShapePy::Type, &shape)) + return nullptr; + + TopoShape sh = getShapeFix_FixSmallFacePtr()->FixSplitFace(static_cast(shape)->getTopoShapePtr()->getShape()); + return sh.getPyObject(); +} + +PyObject* ShapeFix_FixSmallFacePy::fixFace(PyObject *args) +{ + PyObject* face; + if (!PyArg_ParseTuple(args, "O!", &TopoShapeFacePy::Type, &face)) + return nullptr; + + TopoDS_Face shape = TopoDS::Face(static_cast(face)->getTopoShapePtr()->getShape()); + TopoShape sh = getShapeFix_FixSmallFacePtr()->FixFace(shape); + return sh.getPyObject(); +} + +PyObject* ShapeFix_FixSmallFacePy::fixShape(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + TopoShape shape = getShapeFix_FixSmallFacePtr()->FixShape(); + return shape.getPyObject(); +} + +PyObject* ShapeFix_FixSmallFacePy::shape(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + TopoShape sh = getShapeFix_FixSmallFacePtr()->Shape(); + return sh.getPyObject(); +} + +PyObject *ShapeFix_FixSmallFacePy::getCustomAttributes(const char* /*attr*/) const +{ + return nullptr; +} + +int ShapeFix_FixSmallFacePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +}