Part: expose ShapeFix_FixSmallFace to Python

This commit is contained in:
wmayer
2022-05-05 16:45:58 +02:00
parent 6843a461e6
commit 4c2946c8a4
4 changed files with 273 additions and 0 deletions

View File

@@ -105,6 +105,7 @@
#include <Mod/Part/App/ShapeFix/ShapeFix_EdgeConnectPy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_FacePy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_FaceConnectPy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_FixSmallFacePy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_FreeBoundsPy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_ShapePy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_ShapeTolerancePy.h>
@@ -365,6 +366,7 @@ PyMOD_INIT_FUNC(Part)
Base::Interpreter().addType(&Part::ShapeFix_WireVertexPy::Type, shapeFix, "WireVertex");
Base::Interpreter().addType(&Part::ShapeFix_EdgeConnectPy::Type, shapeFix, "EdgeConnect");
Base::Interpreter().addType(&Part::ShapeFix_FaceConnectPy::Type, shapeFix, "FaceConnect");
Base::Interpreter().addType(&Part::ShapeFix_FixSmallFacePy::Type, shapeFix, "FixSmallFace");
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");

View File

@@ -147,6 +147,7 @@ generate_from_xml(ShapeFix/ShapeFix_WireframePy)
generate_from_xml(ShapeFix/ShapeFix_WireVertexPy)
generate_from_xml(ShapeFix/ShapeFix_EdgeConnectPy)
generate_from_xml(ShapeFix/ShapeFix_FaceConnectPy)
generate_from_xml(ShapeFix/ShapeFix_FixSmallFacePy)
generate_from_xml(ShapeFix/ShapeFix_FreeBoundsPy)
generate_from_xml(ShapeFix/ShapeFix_ShapeTolerancePy)
generate_from_xml(ShapeFix/ShapeFix_SplitCommonVertexPy)
@@ -458,6 +459,8 @@ SET(ShapeFixPy_SRCS
ShapeFix/ShapeFix_EdgeConnectPyImp.cpp
ShapeFix/ShapeFix_FaceConnectPy.xml
ShapeFix/ShapeFix_FaceConnectPyImp.cpp
ShapeFix/ShapeFix_FixSmallFacePy.xml
ShapeFix/ShapeFix_FixSmallFacePyImp.cpp
ShapeFix/ShapeFix_FreeBoundsPy.xml
ShapeFix/ShapeFix_FreeBoundsPyImp.cpp
ShapeFix/ShapeFix_ShapeTolerancePy.xml

View File

@@ -0,0 +1,94 @@
<?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_FixSmallFacePy"
PythonName="Part.ShapeFix.FixSmallFace"
Twin="ShapeFix_FixSmallFace"
TwinPointer="ShapeFix_FixSmallFace"
Include="ShapeFix_FixSmallFace.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>Class for fixing operations on faces</UserDocu>
</Documentation>
<Methode Name="init">
<Documentation>
<UserDocu>Initializes by shape</UserDocu>
</Documentation>
</Methode>
<Methode Name="perform">
<Documentation>
<UserDocu>Fixing case of spot face</UserDocu>
</Documentation>
</Methode>
<Methode Name="fixSpotFace">
<Documentation>
<UserDocu>Fixing case of spot face, if tol = -1 used local tolerance</UserDocu>
</Documentation>
</Methode>
<Methode Name="replaceVerticesInCaseOfSpot">
<Documentation>
<UserDocu>Compute average vertex and replacing vertices by new one</UserDocu>
</Documentation>
</Methode>
<Methode Name="removeFacesInCaseOfSpot">
<Documentation>
<UserDocu>Remove spot face from compound</UserDocu>
</Documentation>
</Methode>
<Methode Name="fixStripFace">
<Documentation>
<UserDocu>Fixing case of strip face, if tol = -1 used local tolerance</UserDocu>
</Documentation>
</Methode>
<!--<Methode Name="replaceInCaseOfStrip">
<Documentation>
<UserDocu>Replace vertices and edges</UserDocu>
</Documentation>
</Methode>-->
<Methode Name="removeFacesInCaseOfStrip">
<Documentation>
<UserDocu>Remove strip face from compound</UserDocu>
</Documentation>
</Methode>
<!--<Methode Name="computeSharedEdgeForStripFace">
<Documentation>
<UserDocu>Compute average edge for strip face</UserDocu>
</Documentation>
</Methode>-->
<Methode Name="fixSplitFace">
<Documentation>
<UserDocu></UserDocu>
</Documentation>
</Methode>
<!--<Methode Name="splitOneFace">
<Documentation>
<UserDocu>Compute data for face splitting</UserDocu>
</Documentation>
</Methode>-->
<Methode Name="fixFace">
<Documentation>
<UserDocu></UserDocu>
</Documentation>
</Methode>
<Methode Name="fixShape">
<Documentation>
<UserDocu></UserDocu>
</Documentation>
</Methode>
<Methode Name="shape">
<Documentation>
<UserDocu></UserDocu>
</Documentation>
</Methode>
<!--<Methode Name="fixPinFace">
<Documentation>
<UserDocu></UserDocu>
</Documentation>
</Methode>-->
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,174 @@
/***************************************************************************
* 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 <TopoDS.hxx>
# include <TopoDS_Face.hxx>
#endif
#include "ShapeFix/ShapeFix_FixSmallFacePy.h"
#include "ShapeFix/ShapeFix_FixSmallFacePy.cpp"
#include "TopoShapeFacePy.h"
using namespace Part;
std::string ShapeFix_FixSmallFacePy::representation() const
{
return "<ShapeFix_FixSmallFace object>";
}
PyObject *ShapeFix_FixSmallFacePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
{
// create a new instance of ShapeFix_FacePy
return new ShapeFix_FixSmallFacePy(new ShapeFix_FixSmallFace);
}
// constructor method
int ShapeFix_FixSmallFacePy::PyInit(PyObject* args, PyObject* /*kwds*/)
{
if (!PyArg_ParseTuple(args, ""))
return -1;
return 0;
}
PyObject* ShapeFix_FixSmallFacePy::init(PyObject *args)
{
PyObject* shape;
if (!PyArg_ParseTuple(args, "O!", &TopoShapePy::Type, &shape))
return nullptr;
getShapeFix_FixSmallFacePtr()->Init(static_cast<TopoShapePy*>(shape)->getTopoShapePtr()->getShape());
Py_Return;
}
PyObject* ShapeFix_FixSmallFacePy::perform(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
getShapeFix_FixSmallFacePtr()->Perform();
Py_Return;
}
PyObject* ShapeFix_FixSmallFacePy::fixSpotFace(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
TopoShape sh = getShapeFix_FixSmallFacePtr()->FixSpotFace();
return sh.getPyObject();
}
PyObject* ShapeFix_FixSmallFacePy::replaceVerticesInCaseOfSpot(PyObject *args)
{
PyObject* face;
if (!PyArg_ParseTuple(args, "O!", &TopoShapeFacePy::Type, &face))
return nullptr;
TopoDS_Face shape = TopoDS::Face(static_cast<TopoShapeFacePy*>(face)->getTopoShapePtr()->getShape());
getShapeFix_FixSmallFacePtr()->ReplaceVerticesInCaseOfSpot(shape, 0.0);
return TopoShape(shape).getPyObject();
}
PyObject* ShapeFix_FixSmallFacePy::removeFacesInCaseOfSpot(PyObject *args)
{
PyObject* face;
if (!PyArg_ParseTuple(args, "O!", &TopoShapeFacePy::Type, &face))
return nullptr;
TopoDS_Face shape = TopoDS::Face(static_cast<TopoShapeFacePy*>(face)->getTopoShapePtr()->getShape());
bool ok = getShapeFix_FixSmallFacePtr()->RemoveFacesInCaseOfSpot(shape);
return Py::new_reference_to(Py::Boolean(ok));
}
PyObject* ShapeFix_FixSmallFacePy::fixStripFace(PyObject *args)
{
PyObject* wasdone = Py_False;
if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &wasdone))
return nullptr;
TopoShape sh = getShapeFix_FixSmallFacePtr()->FixStripFace(PyObject_IsTrue(wasdone) ? Standard_True : Standard_False);
return sh.getPyObject();
}
PyObject* ShapeFix_FixSmallFacePy::removeFacesInCaseOfStrip(PyObject *args)
{
PyObject* face;
if (!PyArg_ParseTuple(args, "O!", &TopoShapeFacePy::Type, &face))
return nullptr;
TopoDS_Face shape = TopoDS::Face(static_cast<TopoShapeFacePy*>(face)->getTopoShapePtr()->getShape());
bool ok = getShapeFix_FixSmallFacePtr()->RemoveFacesInCaseOfStrip(shape);
return Py::new_reference_to(Py::Boolean(ok));
}
PyObject* ShapeFix_FixSmallFacePy::fixSplitFace(PyObject *args)
{
PyObject* shape;
if (!PyArg_ParseTuple(args, "O!", &TopoShapePy::Type, &shape))
return nullptr;
TopoShape sh = getShapeFix_FixSmallFacePtr()->FixSplitFace(static_cast<TopoShapeFacePy*>(shape)->getTopoShapePtr()->getShape());
return sh.getPyObject();
}
PyObject* ShapeFix_FixSmallFacePy::fixFace(PyObject *args)
{
PyObject* face;
if (!PyArg_ParseTuple(args, "O!", &TopoShapeFacePy::Type, &face))
return nullptr;
TopoDS_Face shape = TopoDS::Face(static_cast<TopoShapeFacePy*>(face)->getTopoShapePtr()->getShape());
TopoShape sh = getShapeFix_FixSmallFacePtr()->FixFace(shape);
return sh.getPyObject();
}
PyObject* ShapeFix_FixSmallFacePy::fixShape(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
TopoShape shape = getShapeFix_FixSmallFacePtr()->FixShape();
return shape.getPyObject();
}
PyObject* ShapeFix_FixSmallFacePy::shape(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
TopoShape sh = getShapeFix_FixSmallFacePtr()->Shape();
return sh.getPyObject();
}
PyObject *ShapeFix_FixSmallFacePy::getCustomAttributes(const char* /*attr*/) const
{
return nullptr;
}
int ShapeFix_FixSmallFacePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}