diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index 56f5886933..de985d0ee5 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 "Mod/Part/App/SpherePy.h" @@ -350,6 +351,7 @@ PyMOD_INIT_FUNC(Part) Base::Interpreter().addType(&Part::ShapeFix_FacePy::Type, shapeFix, "Face"); Base::Interpreter().addType(&Part::ShapeFix_ShapePy::Type, shapeFix, "Shape"); 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"); // ShapeUpgrade sub-module diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index 60bef7cbfc..9290643e99 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -141,6 +141,7 @@ generate_from_xml(ShapeFix/ShapeFix_EdgePy) generate_from_xml(ShapeFix/ShapeFix_FacePy) 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(ShapeUpgrade/UnifySameDomainPy) @@ -437,6 +438,8 @@ SET(ShapeFixPy_SRCS ShapeFix/ShapeFix_ShapePyImp.cpp ShapeFix/ShapeFix_ShellPy.xml ShapeFix/ShapeFix_ShellPyImp.cpp + ShapeFix/ShapeFix_SolidPy.xml + ShapeFix/ShapeFix_SolidPyImp.cpp ShapeFix/ShapeFix_WirePy.xml ShapeFix/ShapeFix_WirePyImp.cpp ) diff --git a/src/Mod/Part/App/ShapeFix/ShapeFix_ShapePyImp.cpp b/src/Mod/Part/App/ShapeFix/ShapeFix_ShapePyImp.cpp index b15e513c5f..bf7c15af68 100644 --- a/src/Mod/Part/App/ShapeFix/ShapeFix_ShapePyImp.cpp +++ b/src/Mod/Part/App/ShapeFix/ShapeFix_ShapePyImp.cpp @@ -32,7 +32,7 @@ #include "ShapeFix/ShapeFix_WirePy.h" #include "ShapeFix/ShapeFix_FacePy.h" #include "ShapeFix/ShapeFix_ShellPy.h" -//#include "ShapeFix/ShapeFix_SolidPy.h" +#include "ShapeFix/ShapeFix_SolidPy.h" #include using namespace Part; @@ -98,7 +98,9 @@ PyObject* ShapeFix_ShapePy::fixSolidTool(PyObject *args) return nullptr; Handle(ShapeFix_Solid) tool = getShapeFix_ShapePtr()->FixSolidTool(); - Py_Return; + ShapeFix_SolidPy* solid = new ShapeFix_SolidPy(nullptr); + solid->setHandle(tool); + return solid; } PyObject* ShapeFix_ShapePy::fixShellTool(PyObject *args) diff --git a/src/Mod/Part/App/ShapeFix/ShapeFix_SolidPy.xml b/src/Mod/Part/App/ShapeFix/ShapeFix_SolidPy.xml new file mode 100644 index 0000000000..18cafdb36f --- /dev/null +++ b/src/Mod/Part/App/ShapeFix/ShapeFix_SolidPy.xml @@ -0,0 +1,69 @@ + + + + + + Root class for fixing operations + + + + Initializes by solid + + + + + Iterates on subshapes and performs fixes + + + + + Calls MakeSolid and orients the solid to be not infinite + + + + + Returns resulting solid + + + + + In case of multiconnexity returns compound of fixed solids +else returns one solid + + + + + Returns tool for fixing shells + + + + + Mode for applying fixes of ShapeFix_Shell + + + + + + Mode for applying analysis and fixes of +orientation of shells in the solid + + + + + + Mode for creation of solids + + + + + diff --git a/src/Mod/Part/App/ShapeFix/ShapeFix_SolidPyImp.cpp b/src/Mod/Part/App/ShapeFix/ShapeFix_SolidPyImp.cpp new file mode 100644 index 0000000000..b02a5e9030 --- /dev/null +++ b/src/Mod/Part/App/ShapeFix/ShapeFix_SolidPyImp.cpp @@ -0,0 +1,165 @@ +/*************************************************************************** + * 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_SolidPy.h" +#include "ShapeFix/ShapeFix_SolidPy.cpp" +#include "ShapeFix/ShapeFix_ShellPy.h" +#include "ShapeFix/ShapeFix_FacePy.h" +#include +#include + +using namespace Part; + +// returns a string which represents the object e.g. when printed in python +std::string ShapeFix_SolidPy::representation() const +{ + return ""; +} + +PyObject *ShapeFix_SolidPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // create a new instance of ShapeFix_SolidPy + return new ShapeFix_SolidPy(nullptr); +} + +// constructor method +int ShapeFix_SolidPy::PyInit(PyObject* args, PyObject* /*kwds*/) +{ + PyObject* solid = nullptr; + if (!PyArg_ParseTuple(args, "|O!", &TopoShapeSolidPy::Type, &solid)) + return -1; + + setHandle(new ShapeFix_Solid); + if (solid) { + getShapeFix_SolidPtr()->Init(TopoDS::Solid(static_cast(solid)->getTopoShapePtr()->getShape())); + } + + return 0; +} + +PyObject* ShapeFix_SolidPy::init(PyObject *args) +{ + PyObject* solid; + if (!PyArg_ParseTuple(args, "O!", &TopoShapeSolidPy::Type, &solid)) + return nullptr; + + getShapeFix_SolidPtr()->Init(TopoDS::Solid(static_cast(solid)->getTopoShapePtr()->getShape())); + Py_Return; +} + +PyObject* ShapeFix_SolidPy::perform(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + Standard_Boolean ok = getShapeFix_SolidPtr()->Perform(); + return Py::new_reference_to(Py::Boolean(ok ? true : false)); +} + +PyObject* ShapeFix_SolidPy::solidFromShell(PyObject *args) +{ + PyObject* shell; + if (!PyArg_ParseTuple(args, "O!", &TopoShapeShellPy::Type, &shell)) + return nullptr; + + TopoDS_Shape shape = static_cast(shell)->getTopoShapePtr()->getShape(); + TopoShape solid = getShapeFix_SolidPtr()->SolidFromShell(TopoDS::Shell(shape)); + return solid.getPyObject(); +} + +PyObject* ShapeFix_SolidPy::solid(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + TopoShape shape = getShapeFix_SolidPtr()->Solid(); + return shape.getPyObject(); +} + +PyObject* ShapeFix_SolidPy::shape(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + TopoShape shape = getShapeFix_SolidPtr()->Shape(); + return shape.getPyObject(); +} + +PyObject* ShapeFix_SolidPy::fixShellTool(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + Handle(ShapeFix_Shell) tool = getShapeFix_SolidPtr()->FixShellTool(); + ShapeFix_ShellPy* shell = new ShapeFix_ShellPy(nullptr); + shell->setHandle(tool); + return shell; +} + +Py::Boolean ShapeFix_SolidPy::getFixShellMode() const +{ + return Py::Boolean(getShapeFix_SolidPtr()->FixShellMode()); +} + +void ShapeFix_SolidPy::setFixShellMode(Py::Boolean arg) +{ + getShapeFix_SolidPtr()->FixShellMode() = arg; +} + +Py::Boolean ShapeFix_SolidPy::getFixShellOrientationMode() const +{ + return Py::Boolean(getShapeFix_SolidPtr()->FixShellOrientationMode()); +} + +void ShapeFix_SolidPy::setFixShellOrientationMode(Py::Boolean arg) +{ + getShapeFix_SolidPtr()->FixShellOrientationMode() = arg; +} + +Py::Boolean ShapeFix_SolidPy::getCreateOpenSolidMode() const +{ + return Py::Boolean(getShapeFix_SolidPtr()->CreateOpenSolidMode()); +} + +void ShapeFix_SolidPy::setCreateOpenSolidMode(Py::Boolean arg) +{ + getShapeFix_SolidPtr()->CreateOpenSolidMode() = arg; +} + +PyObject *ShapeFix_SolidPy::getCustomAttributes(const char* /*attr*/) const +{ + return nullptr; +} + +int ShapeFix_SolidPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/Part/TestPartApp.py b/src/Mod/Part/TestPartApp.py index da7fe3b430..5b83b82a89 100644 --- a/src/Mod/Part/TestPartApp.py +++ b/src/Mod/Part/TestPartApp.py @@ -583,6 +583,30 @@ class PartTestShapeFix(unittest.TestCase): fix.FixOrientationMode = True self.assertEqual(fix.FixOrientationMode, True) + def testShapeFix_Solid(self): + box = Part.makeBox(1, 1, 1) + with self.assertRaises(TypeError): + Part.ShapeFix.Solid([]) + + fix = Part.ShapeFix.Solid() + fix.init(box) + print (fix) + + fix.perform() + fix.solid() + fix.shape() + fix.fixShellTool() + fix.solidFromShell(box.Shells[0]) + + fix.FixShellMode = True + self.assertEqual(fix.FixShellMode, True) + + fix.FixShellOrientationMode = True + self.assertEqual(fix.FixShellOrientationMode, True) + + fix.CreateOpenSolidMode = True + self.assertEqual(fix.CreateOpenSolidMode, True) + def testShapeFix_Wire(self): with self.assertRaises(TypeError): Part.ShapeFix.Wire([])