Part: expose ShapeFix_Solid to Python

This commit is contained in:
wmayer
2022-05-04 16:20:13 +02:00
parent 75dee7b35c
commit 6f521063db
6 changed files with 267 additions and 2 deletions

View File

@@ -105,6 +105,7 @@
#include <Mod/Part/App/ShapeFix/ShapeFix_FacePy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_ShapePy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_ShellPy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_SolidPy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_WirePy.h>
#include <Mod/Part/App/ShapeUpgrade/UnifySameDomainPy.h>
#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

View File

@@ -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
)

View File

@@ -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 <Mod/Part/App/TopoShapePy.h>
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)

View File

@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="ShapeFix_RootPy"
Name="ShapeFix_SolidPy"
PythonName="Part.ShapeFix.Solid"
Twin="ShapeFix_Solid"
TwinPointer="ShapeFix_Solid"
Include="ShapeFix_Solid.hxx"
Namespace="Part"
FatherInclude="Mod/Part/App/ShapeFix/ShapeFix_RootPy.h"
FatherNamespace="Part"
Constructor="true">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>Root class for fixing operations</UserDocu>
</Documentation>
<Methode Name="init">
<Documentation>
<UserDocu>Initializes by solid</UserDocu>
</Documentation>
</Methode>
<Methode Name="perform">
<Documentation>
<UserDocu>Iterates on subshapes and performs fixes</UserDocu>
</Documentation>
</Methode>
<Methode Name="solidFromShell">
<Documentation>
<UserDocu>Calls MakeSolid and orients the solid to be not infinite</UserDocu>
</Documentation>
</Methode>
<Methode Name="solid">
<Documentation>
<UserDocu>Returns resulting solid</UserDocu>
</Documentation>
</Methode>
<Methode Name="shape">
<Documentation>
<UserDocu>In case of multiconnexity returns compound of fixed solids
else returns one solid</UserDocu>
</Documentation>
</Methode>
<Methode Name="fixShellTool">
<Documentation>
<UserDocu>Returns tool for fixing shells</UserDocu>
</Documentation>
</Methode>
<Attribute Name="FixShellMode" ReadOnly="false">
<Documentation>
<UserDocu>Mode for applying fixes of ShapeFix_Shell</UserDocu>
</Documentation>
<Parameter Name="FixShellMode" Type="Boolean"/>
</Attribute>
<Attribute Name="FixShellOrientationMode" ReadOnly="false">
<Documentation>
<UserDocu>Mode for applying analysis and fixes of
orientation of shells in the solid</UserDocu>
</Documentation>
<Parameter Name="FixShellOrientationMode" Type="Boolean"/>
</Attribute>
<Attribute Name="CreateOpenSolidMode" ReadOnly="false">
<Documentation>
<UserDocu>Mode for creation of solids</UserDocu>
</Documentation>
<Parameter Name="CreateOpenSolidMode" Type="Boolean"/>
</Attribute>
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,165 @@
/***************************************************************************
* Copyright (c) 2022 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <Precision.hxx>
# include <Standard_Failure.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Solid.hxx>
#endif
#include "ShapeFix/ShapeFix_SolidPy.h"
#include "ShapeFix/ShapeFix_SolidPy.cpp"
#include "ShapeFix/ShapeFix_ShellPy.h"
#include "ShapeFix/ShapeFix_FacePy.h"
#include <Mod/Part/App/TopoShapeShellPy.h>
#include <Mod/Part/App/TopoShapeSolidPy.h>
using namespace Part;
// returns a string which represents the object e.g. when printed in python
std::string ShapeFix_SolidPy::representation() const
{
return "<ShapeFix_Solid object>";
}
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<TopoShapePy*>(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<TopoShapePy*>(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<TopoShapePy*>(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;
}

View File

@@ -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([])