Part: expose ShapeFix_WireVertex to Python

This commit is contained in:
wmayer
2022-05-05 01:30:59 +02:00
parent 1ee1aee10e
commit 8c6ffc99e3
4 changed files with 151 additions and 0 deletions

View File

@@ -112,6 +112,7 @@
#include <Mod/Part/App/ShapeFix/ShapeFix_SolidPy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_SplitCommonVertexPy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_WirePy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_WireVertexPy.h>
#include <Mod/Part/App/ShapeUpgrade/UnifySameDomainPy.h>
#include "Mod/Part/App/SpherePy.h"
#include "Mod/Part/App/SurfaceOfExtrusionPy.h"
@@ -358,6 +359,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_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_FreeBoundsPy::Type, shapeFix, "FreeBounds");

View File

@@ -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_WireVertexPy)
generate_from_xml(ShapeFix/ShapeFix_EdgeConnectPy)
generate_from_xml(ShapeFix/ShapeFix_FaceConnectPy)
generate_from_xml(ShapeFix/ShapeFix_FreeBoundsPy)
@@ -447,6 +448,8 @@ SET(ShapeFixPy_SRCS
ShapeFix/ShapeFix_SolidPyImp.cpp
ShapeFix/ShapeFix_WirePy.xml
ShapeFix/ShapeFix_WirePyImp.cpp
ShapeFix/ShapeFix_WireVertexPy.xml
ShapeFix/ShapeFix_WireVertexPyImp.cpp
ShapeFix/ShapeFix_EdgeConnectPy.xml
ShapeFix/ShapeFix_EdgeConnectPyImp.cpp
ShapeFix/ShapeFix_FaceConnectPy.xml

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="PyObjectBase"
Name="ShapeFix_WireVertexPy"
PythonName="Part.ShapeFix.WireVertex"
Twin="ShapeFix_WireVertex"
TwinPointer="ShapeFix_WireVertex"
Include="ShapeFix_WireVertex.hxx"
Namespace="Part"
FatherInclude="Base/PyObjectBase.h"
FatherNamespace="Base"
Constructor="true"
Delete="true">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />
<UserDocu>Fixing disconnected edges in the wire</UserDocu>
</Documentation>
<Methode Name="init">
<Documentation>
<UserDocu>Loads the wire, ininializes internal analyzer with the given precision</UserDocu>
</Documentation>
</Methode>
<Methode Name="wire">
<Documentation>
<UserDocu>Returns resulting wire</UserDocu>
</Documentation>
</Methode>
<Methode Name="fixSame">
<Documentation>
<UserDocu>Returns the count of fixed vertices, 0 if none</UserDocu>
</Documentation>
</Methode>
<Methode Name="fix">
<Documentation>
<UserDocu>Fixes all statuses except Disjoined, i.e. the cases in which a
common value has been set, with or without changing parameters
Returns the count of fixed vertices, 0 if none</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,104 @@
/***************************************************************************
* 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 <Standard_Failure.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Wire.hxx>
#endif
#include "ShapeFix/ShapeFix_WireVertexPy.h"
#include "ShapeFix/ShapeFix_WireVertexPy.cpp"
#include "TopoShapeWirePy.h"
using namespace Part;
// returns a string which represents the object e.g. when printed in python
std::string ShapeFix_WireVertexPy::representation() const
{
return "<ShapeFix_WireVertex object>";
}
PyObject *ShapeFix_WireVertexPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
{
return new ShapeFix_WireVertexPy(new ShapeFix_WireVertex);
}
// constructor method
int ShapeFix_WireVertexPy::PyInit(PyObject* args, PyObject* /*kwds*/)
{
if (!PyArg_ParseTuple(args, ""))
return -1;
return 0;
}
PyObject* ShapeFix_WireVertexPy::init(PyObject *args)
{
PyObject* shape;
double prec;
if (!PyArg_ParseTuple(args, "O!d", &TopoShapeWirePy::Type, &shape, &prec))
return nullptr;
TopoDS_Shape sh = static_cast<TopoShapePy*>(shape)->getTopoShapePtr()->getShape();
getShapeFix_WireVertexPtr()->Init(TopoDS::Wire(sh), prec);
Py_Return;
}
PyObject* ShapeFix_WireVertexPy::wire(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
TopoShape w = getShapeFix_WireVertexPtr()->Wire();
return w.getPyObject();
}
PyObject* ShapeFix_WireVertexPy::fixSame(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
int num = getShapeFix_WireVertexPtr()->FixSame();
return Py::new_reference_to(Py::Long(num));
}
PyObject* ShapeFix_WireVertexPy::fix(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
int num = getShapeFix_WireVertexPtr()->Fix();
return Py::new_reference_to(Py::Long(num));
}
PyObject *ShapeFix_WireVertexPy::getCustomAttributes(const char* /*attr*/) const
{
return nullptr;
}
int ShapeFix_WireVertexPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}