Part: expose ShapeFix_SplitTool to Python

This commit is contained in:
wmayer
2022-05-05 02:20:19 +02:00
parent 8c6ffc99e3
commit bbecc3f296
4 changed files with 175 additions and 0 deletions

View File

@@ -111,6 +111,7 @@
#include <Mod/Part/App/ShapeFix/ShapeFix_ShellPy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_SolidPy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_SplitCommonVertexPy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_SplitToolPy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_WirePy.h>
#include <Mod/Part/App/ShapeFix/ShapeFix_WireVertexPy.h>
#include <Mod/Part/App/ShapeUpgrade/UnifySameDomainPy.h>
@@ -365,6 +366,7 @@ PyMOD_INIT_FUNC(Part)
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");
Base::Interpreter().addType(&Part::ShapeFix_SplitToolPy::Type, shapeFix, "SplitTool");
// ShapeUpgrade sub-module
PyObject* shapeUpgrade(module.getAttr("ShapeUpgrade").ptr());

View File

@@ -149,6 +149,7 @@ generate_from_xml(ShapeFix/ShapeFix_FaceConnectPy)
generate_from_xml(ShapeFix/ShapeFix_FreeBoundsPy)
generate_from_xml(ShapeFix/ShapeFix_ShapeTolerancePy)
generate_from_xml(ShapeFix/ShapeFix_SplitCommonVertexPy)
generate_from_xml(ShapeFix/ShapeFix_SplitToolPy)
generate_from_xml(ShapeUpgrade/UnifySameDomainPy)
@@ -460,6 +461,8 @@ SET(ShapeFixPy_SRCS
ShapeFix/ShapeFix_ShapeTolerancePyImp.cpp
ShapeFix/ShapeFix_SplitCommonVertexPy.xml
ShapeFix/ShapeFix_SplitCommonVertexPyImp.cpp
ShapeFix/ShapeFix_SplitToolPy.xml
ShapeFix/ShapeFix_SplitToolPyImp.cpp
)
SOURCE_GROUP("ShapeFix" FILES ${ShapeFixPy_SRCS})

View File

@@ -0,0 +1,30 @@
<?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_SplitToolPy"
PythonName="Part.ShapeFix.SplitTool"
Twin="ShapeFix_SplitTool"
TwinPointer="ShapeFix_SplitTool"
Include="ShapeFix_SplitTool.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>Tool for splitting and cutting edges</UserDocu>
</Documentation>
<Methode Name="splitEdge">
<Documentation>
<UserDocu>Split edge on two new edges using new vertex</UserDocu>
</Documentation>
</Methode>
<Methode Name="cutEdge">
<Documentation>
<UserDocu>Cut edge by parameters pend and cut</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,140 @@
/***************************************************************************
* 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 <ShapeFix_Wire.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Edge.hxx>
# include <TopoDS_Face.hxx>
# include <TopoDS_Vertex.hxx>
#endif
#include "ShapeFix/ShapeFix_SplitToolPy.h"
#include "ShapeFix/ShapeFix_SplitToolPy.cpp"
#include "TopoShapeEdgePy.h"
#include "TopoShapeFacePy.h"
#include "TopoShapeVertexPy.h"
using namespace Part;
std::string ShapeFix_SplitToolPy::representation() const
{
return "<ShapeFix_SplitTool object>";
}
PyObject *ShapeFix_SplitToolPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
{
return new ShapeFix_SplitToolPy(new ShapeFix_SplitTool);
}
// constructor method
int ShapeFix_SplitToolPy::PyInit(PyObject* args, PyObject* /*kwds*/)
{
if (PyArg_ParseTuple(args, ""))
return -1;
return 0;
}
PyObject* ShapeFix_SplitToolPy::splitEdge(PyObject *args)
{
TopoDS_Edge e1, e2;
bool ok = false;
do {
PyObject* edge;
PyObject* vert;
PyObject* face;
double param1, param2;
double tol3d;
double tol2d;
if (PyArg_ParseTuple(args, "O!dO!O!dd", &TopoShapeEdgePy::Type, &edge, &param1,
&TopoShapeVertexPy::Type, &vert,
&TopoShapeFacePy::Type, &face,
&tol3d, &tol2d)) {
TopoDS_Shape e = static_cast<TopoShapePy*>(edge)->getTopoShapePtr()->getShape();
TopoDS_Shape v = static_cast<TopoShapePy*>(vert)->getTopoShapePtr()->getShape();
TopoDS_Shape f = static_cast<TopoShapePy*>(face)->getTopoShapePtr()->getShape();
ok = getShapeFix_SplitToolPtr()->SplitEdge(TopoDS::Edge(e), param1, TopoDS::Vertex(v), TopoDS::Face(f), e1, e2, tol3d, tol2d);
break;
}
PyErr_Clear();
if (PyArg_ParseTuple(args, "O!ddO!O!dd", &TopoShapeEdgePy::Type, &edge,
&param1, &param2,
&TopoShapeVertexPy::Type, &vert,
&TopoShapeFacePy::Type, &face,
&tol3d, &tol2d)) {
TopoDS_Shape e = static_cast<TopoShapePy*>(edge)->getTopoShapePtr()->getShape();
TopoDS_Shape v = static_cast<TopoShapePy*>(vert)->getTopoShapePtr()->getShape();
TopoDS_Shape f = static_cast<TopoShapePy*>(face)->getTopoShapePtr()->getShape();
ok = getShapeFix_SplitToolPtr()->SplitEdge(TopoDS::Edge(e), param1, param2, TopoDS::Vertex(v), TopoDS::Face(f), e1, e2, tol3d, tol2d);
break;
}
PyErr_SetString(PyExc_TypeError, "splitEdge(edge, param, vertex, face, tol3d, tol2d)\n"
"splitEdge(edge, param1, param2, vertex, face, tol3d, tol2d)");
return nullptr;
}
while(false);
Py::Tuple tuple(2);
if (ok && !e1.IsNull() && !e2.IsNull()) {
tuple.setItem(0, Py::asObject(TopoShape(e1).getPyObject()));
tuple.setItem(1, Py::asObject(TopoShape(e2).getPyObject()));
}
return Py::new_reference_to(tuple);
}
PyObject* ShapeFix_SplitToolPy::cutEdge(PyObject *args)
{
PyObject* edge;
PyObject* face;
double pend;
double cut;
if (!PyArg_ParseTuple(args, "O!ddO!", &TopoShapeEdgePy::Type, &edge, &pend, &cut,
&TopoShapeFacePy::Type, &face))
return nullptr;
TopoDS_Shape e = static_cast<TopoShapePy*>(edge)->getTopoShapePtr()->getShape();
TopoDS_Shape f = static_cast<TopoShapePy*>(face)->getTopoShapePtr()->getShape();
Standard_Boolean iscutline;
bool ok = getShapeFix_SplitToolPtr()->CutEdge(TopoDS::Edge(e), pend, cut, TopoDS::Face(f), iscutline);
return Py::new_reference_to(Py::Boolean(ok));
}
PyObject *ShapeFix_SplitToolPy::getCustomAttributes(const char* /*attr*/) const
{
return nullptr;
}
int ShapeFix_SplitToolPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}