From 4d4adb932b832b3186c795a2578c664b0c0dae14 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 4 May 2022 19:19:46 +0200 Subject: [PATCH] Part: expose ShapeFix_EdgeConnect to Python --- src/Mod/Part/App/AppPart.cpp | 2 + src/Mod/Part/App/CMakeLists.txt | 3 + .../App/ShapeFix/ShapeFix_EdgeConnectPy.xml | 42 +++++++ .../ShapeFix/ShapeFix_EdgeConnectPyImp.cpp | 106 ++++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 src/Mod/Part/App/ShapeFix/ShapeFix_EdgeConnectPy.xml create mode 100644 src/Mod/Part/App/ShapeFix/ShapeFix_EdgeConnectPyImp.cpp diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index de985d0ee5..4eef0d50a2 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -102,6 +102,7 @@ #include #include #include +#include #include #include #include @@ -353,6 +354,7 @@ PyMOD_INIT_FUNC(Part) Base::Interpreter().addType(&Part::ShapeFix_ShellPy::Type, shapeFix, "Shell"); 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"); // 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 9290643e99..6261b4a621 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -143,6 +143,7 @@ generate_from_xml(ShapeFix/ShapeFix_ShapePy) 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(ShapeUpgrade/UnifySameDomainPy) @@ -442,6 +443,8 @@ SET(ShapeFixPy_SRCS ShapeFix/ShapeFix_SolidPyImp.cpp ShapeFix/ShapeFix_WirePy.xml ShapeFix/ShapeFix_WirePyImp.cpp + ShapeFix/ShapeFix_EdgeConnectPy.xml + ShapeFix/ShapeFix_EdgeConnectPyImp.cpp ) SOURCE_GROUP("ShapeFix" FILES ${ShapeFixPy_SRCS}) diff --git a/src/Mod/Part/App/ShapeFix/ShapeFix_EdgeConnectPy.xml b/src/Mod/Part/App/ShapeFix/ShapeFix_EdgeConnectPy.xml new file mode 100644 index 0000000000..fbcfc02903 --- /dev/null +++ b/src/Mod/Part/App/ShapeFix/ShapeFix_EdgeConnectPy.xml @@ -0,0 +1,42 @@ + + + + + + Root class for fixing operations + + + + add(edge, edge) +Adds information on connectivity between start vertex +of second edge and end vertex of first edge taking +edges orientation into account + +add(shape) +Adds connectivity information for the whole shape. + + + + + + Builds shared vertices, updates their positions and tolerances + + + + + Clears internal data structure + + + + diff --git a/src/Mod/Part/App/ShapeFix/ShapeFix_EdgeConnectPyImp.cpp b/src/Mod/Part/App/ShapeFix/ShapeFix_EdgeConnectPyImp.cpp new file mode 100644 index 0000000000..680aacce6a --- /dev/null +++ b/src/Mod/Part/App/ShapeFix/ShapeFix_EdgeConnectPyImp.cpp @@ -0,0 +1,106 @@ +/*************************************************************************** + * 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_EdgeConnectPy.h" +#include "ShapeFix/ShapeFix_EdgeConnectPy.cpp" +#include "TopoShapeEdgePy.h" + +using namespace Part; + +// returns a string which represents the object e.g. when printed in python +std::string ShapeFix_EdgeConnectPy::representation() const +{ + return ""; +} + +PyObject *ShapeFix_EdgeConnectPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of ShapeFix_RootPy + return new ShapeFix_EdgeConnectPy(new ShapeFix_EdgeConnect); +} + +// constructor method +int ShapeFix_EdgeConnectPy::PyInit(PyObject* args, PyObject* /*kwds*/) +{ + if (!PyArg_ParseTuple(args, "")) + return -1; + return 0; +} + +PyObject* ShapeFix_EdgeConnectPy::add(PyObject *args) +{ + PyObject* edge1; + PyObject* edge2; + if (PyArg_ParseTuple(args, "O!O!", &TopoShapeEdgePy::Type, &edge1, + &TopoShapeEdgePy::Type, &edge2)) { + TopoDS_Shape e1 = static_cast(edge1)->getTopoShapePtr()->getShape(); + TopoDS_Shape e2 = static_cast(edge2)->getTopoShapePtr()->getShape(); + getShapeFix_EdgeConnectPtr()->Add(TopoDS::Edge(e1), TopoDS::Edge(e2)); + Py_Return; + } + + PyErr_Clear(); + if (PyArg_ParseTuple(args, "O!", &TopoShapePy::Type, &edge1)) { + TopoDS_Shape shape = static_cast(edge1)->getTopoShapePtr()->getShape(); + getShapeFix_EdgeConnectPtr()->Add(shape); + Py_Return; + } + + PyErr_SetString(PyExc_TypeError, "add(edge, edge) or\n" + "add(shape)"); + return nullptr; +} + +PyObject* ShapeFix_EdgeConnectPy::build(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + getShapeFix_EdgeConnectPtr()->Build(); + Py_Return; +} + +PyObject* ShapeFix_EdgeConnectPy::clear(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + getShapeFix_EdgeConnectPtr()->Clear(); + Py_Return; +} + +PyObject *ShapeFix_EdgeConnectPy::getCustomAttributes(const char* /*attr*/) const +{ + return nullptr; +} + +int ShapeFix_EdgeConnectPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +}