From 4b44c54cfabe93c425e69f4d8af8bf2be7e5880a Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 4 May 2022 19:44:12 +0200 Subject: [PATCH] Part: expose ShapeFix_SplitCommonVertex to Python --- src/Mod/Part/App/AppPart.cpp | 2 + src/Mod/Part/App/CMakeLists.txt | 3 + .../ShapeFix/ShapeFix_SplitCommonVertexPy.xml | 34 ++++++ .../ShapeFix_SplitCommonVertexPyImp.cpp | 103 ++++++++++++++++++ 4 files changed, 142 insertions(+) create mode 100644 src/Mod/Part/App/ShapeFix/ShapeFix_SplitCommonVertexPy.xml create mode 100644 src/Mod/Part/App/ShapeFix/ShapeFix_SplitCommonVertexPyImp.cpp diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 4eef0d50a2..2a4e7fd1d7 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -107,6 +107,7 @@ #include #include #include +#include #include #include #include "Mod/Part/App/SpherePy.h" @@ -355,6 +356,7 @@ PyMOD_INIT_FUNC(Part) Base::Interpreter().addType(&Part::ShapeFix_SolidPy::Type, shapeFix, "Solid"); Base::Interpreter().addType(&Part::ShapeFix_WirePy::Type, shapeFix, "Wire"); Base::Interpreter().addType(&Part::ShapeFix_EdgeConnectPy::Type, shapeFix, "EdgeConnect"); + Base::Interpreter().addType(&Part::ShapeFix_SplitCommonVertexPy::Type, shapeFix, "SplitCommonVertex"); // ShapeUpgrade sub-module PyObject* shapeUpgrade(module.getAttr("ShapeUpgrade").ptr()); diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index 6261b4a621..ef5adf5600 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -144,6 +144,7 @@ generate_from_xml(ShapeFix/ShapeFix_ShellPy) generate_from_xml(ShapeFix/ShapeFix_SolidPy) generate_from_xml(ShapeFix/ShapeFix_WirePy) generate_from_xml(ShapeFix/ShapeFix_EdgeConnectPy) +generate_from_xml(ShapeFix/ShapeFix_SplitCommonVertexPy) generate_from_xml(ShapeUpgrade/UnifySameDomainPy) @@ -445,6 +446,8 @@ SET(ShapeFixPy_SRCS ShapeFix/ShapeFix_WirePyImp.cpp ShapeFix/ShapeFix_EdgeConnectPy.xml ShapeFix/ShapeFix_EdgeConnectPyImp.cpp + ShapeFix/ShapeFix_SplitCommonVertexPy.xml + ShapeFix/ShapeFix_SplitCommonVertexPyImp.cpp ) SOURCE_GROUP("ShapeFix" FILES ${ShapeFixPy_SRCS}) diff --git a/src/Mod/Part/App/ShapeFix/ShapeFix_SplitCommonVertexPy.xml b/src/Mod/Part/App/ShapeFix/ShapeFix_SplitCommonVertexPy.xml new file mode 100644 index 0000000000..3470f55e25 --- /dev/null +++ b/src/Mod/Part/App/ShapeFix/ShapeFix_SplitCommonVertexPy.xml @@ -0,0 +1,34 @@ + + + + + + Class for fixing operations on shapes + + + + Initializes by shape + + + + + Iterates on sub- shape and performs fixes + + + + + Returns resulting shape + + + + diff --git a/src/Mod/Part/App/ShapeFix/ShapeFix_SplitCommonVertexPyImp.cpp b/src/Mod/Part/App/ShapeFix/ShapeFix_SplitCommonVertexPyImp.cpp new file mode 100644 index 0000000000..283cf08483 --- /dev/null +++ b/src/Mod/Part/App/ShapeFix/ShapeFix_SplitCommonVertexPyImp.cpp @@ -0,0 +1,103 @@ +/*************************************************************************** + * 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 +#endif + +#include "ShapeFix/ShapeFix_SplitCommonVertexPy.h" +#include "ShapeFix/ShapeFix_SplitCommonVertexPy.cpp" +#include "ShapeFix/ShapeFix_EdgePy.h" +#include "ShapeFix/ShapeFix_WirePy.h" +#include "ShapeFix/ShapeFix_FacePy.h" +#include "ShapeFix/ShapeFix_ShellPy.h" +#include "ShapeFix/ShapeFix_SolidPy.h" +#include + +using namespace Part; + +// returns a string which represents the object e.g. when printed in python +std::string ShapeFix_SplitCommonVertexPy::representation() const +{ + return ""; +} + +PyObject *ShapeFix_SplitCommonVertexPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of ShapeFix_ShapePy + return new ShapeFix_SplitCommonVertexPy(nullptr); +} + +// constructor method +int ShapeFix_SplitCommonVertexPy::PyInit(PyObject* args, PyObject* /*kwds*/) +{ + PyObject* shape = nullptr; + if (!PyArg_ParseTuple(args, "|O!", &TopoShapePy::Type, &shape)) + return -1; + + setHandle(new ShapeFix_SplitCommonVertex); + if (shape) { + getShapeFix_SplitCommonVertexPtr()->Init(static_cast(shape)->getTopoShapePtr()->getShape()); + } + + return 0; +} + +PyObject* ShapeFix_SplitCommonVertexPy::init(PyObject *args) +{ + PyObject* shape; + if (!PyArg_ParseTuple(args, "O!", &TopoShapePy::Type, &shape)) + return nullptr; + + getShapeFix_SplitCommonVertexPtr()->Init(static_cast(shape)->getTopoShapePtr()->getShape()); + Py_Return; +} + +PyObject* ShapeFix_SplitCommonVertexPy::perform(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + getShapeFix_SplitCommonVertexPtr()->Perform(); + Py_Return; +} + +PyObject* ShapeFix_SplitCommonVertexPy::shape(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + TopoShape shape = getShapeFix_SplitCommonVertexPtr()->Shape(); + return shape.getPyObject(); +} + +PyObject *ShapeFix_SplitCommonVertexPy::getCustomAttributes(const char* /*attr*/) const +{ + return nullptr; +} + +int ShapeFix_SplitCommonVertexPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +}