From 1ee1aee10e55ba0e45ac20ac3fd22b5dbf55607c Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 5 May 2022 00:11:23 +0200 Subject: [PATCH] Part: expose ShapeFix_FreeBounds to Python --- src/Mod/Part/App/AppPart.cpp | 2 + src/Mod/Part/App/CMakeLists.txt | 3 + .../App/ShapeFix/ShapeFix_FreeBoundsPy.xml | 35 +++++ .../App/ShapeFix/ShapeFix_FreeBoundsPyImp.cpp | 123 ++++++++++++++++++ 4 files changed, 163 insertions(+) create mode 100644 src/Mod/Part/App/ShapeFix/ShapeFix_FreeBoundsPy.xml create mode 100644 src/Mod/Part/App/ShapeFix/ShapeFix_FreeBoundsPyImp.cpp diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 0cb14bebf7..fe4b65e49c 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 @@ -359,6 +360,7 @@ PyMOD_INIT_FUNC(Part) Base::Interpreter().addType(&Part::ShapeFix_WirePy::Type, shapeFix, "Wire"); Base::Interpreter().addType(&Part::ShapeFix_EdgeConnectPy::Type, shapeFix, "EdgeConnect"); Base::Interpreter().addType(&Part::ShapeFix_FaceConnectPy::Type, shapeFix, "FaceConnect"); + 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 ae67ccd17d..a254d2d04f 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -145,6 +145,7 @@ generate_from_xml(ShapeFix/ShapeFix_SolidPy) generate_from_xml(ShapeFix/ShapeFix_WirePy) generate_from_xml(ShapeFix/ShapeFix_EdgeConnectPy) generate_from_xml(ShapeFix/ShapeFix_FaceConnectPy) +generate_from_xml(ShapeFix/ShapeFix_FreeBoundsPy) generate_from_xml(ShapeFix/ShapeFix_ShapeTolerancePy) generate_from_xml(ShapeFix/ShapeFix_SplitCommonVertexPy) @@ -450,6 +451,8 @@ SET(ShapeFixPy_SRCS ShapeFix/ShapeFix_EdgeConnectPyImp.cpp ShapeFix/ShapeFix_FaceConnectPy.xml ShapeFix/ShapeFix_FaceConnectPyImp.cpp + ShapeFix/ShapeFix_FreeBoundsPy.xml + ShapeFix/ShapeFix_FreeBoundsPyImp.cpp ShapeFix/ShapeFix_ShapeTolerancePy.xml ShapeFix/ShapeFix_ShapeTolerancePyImp.cpp ShapeFix/ShapeFix_SplitCommonVertexPy.xml diff --git a/src/Mod/Part/App/ShapeFix/ShapeFix_FreeBoundsPy.xml b/src/Mod/Part/App/ShapeFix/ShapeFix_FreeBoundsPy.xml new file mode 100644 index 0000000000..c073d54ef3 --- /dev/null +++ b/src/Mod/Part/App/ShapeFix/ShapeFix_FreeBoundsPy.xml @@ -0,0 +1,35 @@ + + + + + + This class is intended to output free bounds of the shape + + + + Returns compound of closed wires out of free edges + + + + + Returns compound of open wires out of free edges + + + + + Returns modified source shape + + + + diff --git a/src/Mod/Part/App/ShapeFix/ShapeFix_FreeBoundsPyImp.cpp b/src/Mod/Part/App/ShapeFix/ShapeFix_FreeBoundsPyImp.cpp new file mode 100644 index 0000000000..6a2bd4251b --- /dev/null +++ b/src/Mod/Part/App/ShapeFix/ShapeFix_FreeBoundsPyImp.cpp @@ -0,0 +1,123 @@ +/*************************************************************************** + * 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 +# include +# include +#endif + +#include "ShapeFix/ShapeFix_FreeBoundsPy.h" +#include "ShapeFix/ShapeFix_FreeBoundsPy.cpp" +#include "TopoShapePy.h" + +using namespace Part; + +// returns a string which represents the object e.g. when printed in python +std::string ShapeFix_FreeBoundsPy::representation() const +{ + return ""; +} + +PyObject *ShapeFix_FreeBoundsPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + return new ShapeFix_FreeBoundsPy(nullptr); +} + +// constructor method +int ShapeFix_FreeBoundsPy::PyInit(PyObject* args, PyObject* /*kwds*/) +{ + if (PyArg_ParseTuple(args, "")) { + setTwinPointer(new ShapeFix_FreeBounds); + return 0; + } + + PyErr_Clear(); + PyObject* shape; + PyObject* splitclosed; + PyObject* splitopen; + double sewtoler; + double closetoler; + if (PyArg_ParseTuple(args, "O!ddO!O!", &TopoShapePy::Type, &shape, &sewtoler, &closetoler, + &PyBool_Type, &splitclosed, &PyBool_Type, &splitopen)) { + TopoDS_Shape sh = static_cast(shape)->getTopoShapePtr()->getShape(); + setTwinPointer(new ShapeFix_FreeBounds(sh, sewtoler, closetoler, + PyObject_IsTrue(splitclosed) ? Standard_True : Standard_False, + PyObject_IsTrue(splitopen) ? Standard_True : Standard_False)); + return 0; + } + + PyErr_Clear(); + if (PyArg_ParseTuple(args, "O!dO!O!", &TopoShapePy::Type, &shape, &closetoler, + &PyBool_Type, &splitclosed, &PyBool_Type, &splitopen)) { + TopoDS_Shape sh = static_cast(shape)->getTopoShapePtr()->getShape(); + setTwinPointer(new ShapeFix_FreeBounds(sh, closetoler, + PyObject_IsTrue(splitclosed) ? Standard_True : Standard_False, + PyObject_IsTrue(splitopen) ? Standard_True : Standard_False)); + return 0; + } + + PyErr_SetString(PyExc_TypeError, "ShapeFix_FreeBounds()\n" + "ShapeFix_FreeBounds(shape, sewtolerance, closetolerance, splitClosed, splitOpen)\n" + "ShapeFix_FreeBounds(shape, closetolerance, splitClosed, splitOpen)"); + return -1; +} + +PyObject* ShapeFix_FreeBoundsPy::closedWires(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + TopoShape comp = getShapeFix_FreeBoundsPtr()->GetClosedWires(); + return comp.getPyObject(); +} + +PyObject* ShapeFix_FreeBoundsPy::openWires(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + TopoShape comp = getShapeFix_FreeBoundsPtr()->GetOpenWires(); + return comp.getPyObject(); +} + +PyObject* ShapeFix_FreeBoundsPy::shape(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + TopoShape shape = getShapeFix_FreeBoundsPtr()->GetShape(); + return shape.getPyObject(); +} + +PyObject *ShapeFix_FreeBoundsPy::getCustomAttributes(const char* /*attr*/) const +{ + return nullptr; +} + +int ShapeFix_FreeBoundsPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +}