Part: start to expose ShapeFix framework to Python
This commit is contained in:
@@ -99,7 +99,9 @@
|
||||
#include "Mod/Part/App/PlanePy.h"
|
||||
#include "Mod/Part/App/PointPy.h"
|
||||
#include <Mod/Part/App/PrecisionPy.h>
|
||||
#include "Mod/Part/App/RectangularTrimmedSurfacePy.h"
|
||||
#include <Mod/Part/App/RectangularTrimmedSurfacePy.h>
|
||||
#include <Mod/Part/App/ShapeFix/ShapeFix_RootPy.h>
|
||||
#include <Mod/Part/App/ShapeFix/ShapeFix_ShellPy.h>
|
||||
#include <Mod/Part/App/ShapeUpgrade/UnifySameDomainPy.h>
|
||||
#include "Mod/Part/App/SpherePy.h"
|
||||
#include "Mod/Part/App/SurfaceOfExtrusionPy.h"
|
||||
@@ -337,6 +339,11 @@ PyMOD_INIT_FUNC(Part)
|
||||
Base::Interpreter().addType(&Part::CurveConstraintPy::Type, geomPlate, "CurveConstraint");
|
||||
Base::Interpreter().addType(&Part::PointConstraintPy::Type, geomPlate, "PointConstraint");
|
||||
|
||||
// ShapeFix sub-module
|
||||
PyObject* shapeFix(module.getAttr("ShapeFix").ptr());
|
||||
Base::Interpreter().addType(&Part::ShapeFix_RootPy::Type, shapeFix, "Root");
|
||||
Base::Interpreter().addType(&Part::ShapeFix_ShellPy::Type, shapeFix, "Shell");
|
||||
|
||||
// ShapeUpgrade sub-module
|
||||
PyObject* shapeUpgrade(module.getAttr("ShapeUpgrade").ptr());
|
||||
Base::Interpreter().addType(&Part::UnifySameDomainPy::Type, shapeUpgrade, "UnifySameDomain");
|
||||
|
||||
@@ -303,6 +303,17 @@ public:
|
||||
virtual ~HLRBRepModule() {}
|
||||
};
|
||||
|
||||
class ShapeFixModule : public Py::ExtensionModule<ShapeFixModule>
|
||||
{
|
||||
public:
|
||||
ShapeFixModule() : Py::ExtensionModule<ShapeFixModule>("ShapeFix")
|
||||
{
|
||||
initialize("This is a module working with the ShapeFix framework."); // register with Python
|
||||
}
|
||||
|
||||
virtual ~ShapeFixModule() {}
|
||||
};
|
||||
|
||||
class ShapeUpgradeModule : public Py::ExtensionModule<ShapeUpgradeModule>
|
||||
{
|
||||
public:
|
||||
@@ -332,6 +343,7 @@ class Module : public Py::ExtensionModule<Module>
|
||||
Geom2dModule geom2d;
|
||||
GeomPlateModule geomPlate;
|
||||
HLRBRepModule HLRBRep;
|
||||
ShapeFixModule shapeFix;
|
||||
ShapeUpgradeModule shapeUpgrade;
|
||||
ChFi2dModule chFi2d;
|
||||
public:
|
||||
@@ -559,6 +571,7 @@ public:
|
||||
PyModule_AddObject(m_module, "Geom2d", geom2d.module().ptr());
|
||||
PyModule_AddObject(m_module, "GeomPlate", geomPlate.module().ptr());
|
||||
PyModule_AddObject(m_module, "HLRBRep", HLRBRep.module().ptr());
|
||||
PyModule_AddObject(m_module, "ShapeFix", shapeFix.module().ptr());
|
||||
PyModule_AddObject(m_module, "ShapeUpgrade", shapeUpgrade.module().ptr());
|
||||
PyModule_AddObject(m_module, "ChFi2d", chFi2d.module().ptr());
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ChFi2d)
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Geom2d)
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/GeomPlate)
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/HLRBRep)
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ShapeFix)
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ShapeUpgrade)
|
||||
|
||||
generate_from_xml(BRepFeat/MakePrismPy)
|
||||
@@ -135,6 +136,9 @@ generate_from_xml(HLRBRep/HLRToShapePy)
|
||||
generate_from_xml(HLRBRep/HLRBRep_PolyAlgoPy)
|
||||
generate_from_xml(HLRBRep/PolyHLRToShapePy)
|
||||
|
||||
generate_from_xml(ShapeFix/ShapeFix_RootPy)
|
||||
generate_from_xml(ShapeFix/ShapeFix_ShellPy)
|
||||
|
||||
generate_from_xml(ShapeUpgrade/UnifySameDomainPy)
|
||||
|
||||
SET(Features_SRCS
|
||||
@@ -417,6 +421,16 @@ SET(HLRBRepPy_SRCS
|
||||
)
|
||||
SOURCE_GROUP("HLRBRep" FILES ${HLRBRepPy_SRCS})
|
||||
|
||||
# ShapeFix wrappers
|
||||
SET(ShapeFixPy_SRCS
|
||||
ShapeFix/ShapeFix_RootPy.xml
|
||||
ShapeFix/ShapeFix_RootPyImp.cpp
|
||||
ShapeFix/ShapeFix_ShellPy.xml
|
||||
ShapeFix/ShapeFix_ShellPyImp.cpp
|
||||
)
|
||||
|
||||
SOURCE_GROUP("ShapeFix" FILES ${ShapeFixPy_SRCS})
|
||||
|
||||
# ShapeUpgrade wrappers
|
||||
SET(ShapeUpgradePy_SRCS
|
||||
ShapeUpgrade/UnifySameDomainPy.xml
|
||||
@@ -434,6 +448,7 @@ SET(Part_SRCS
|
||||
${Geom2dPy_SRCS}
|
||||
${GeomPlatePy_SRCS}
|
||||
${HLRBRepPy_SRCS}
|
||||
${ShapeFixPy_SRCS}
|
||||
${ShapeUpgradePy_SRCS}
|
||||
Attacher.cpp
|
||||
Attacher.h
|
||||
|
||||
43
src/Mod/Part/App/ShapeFix/ShapeFix_RootPy.xml
Normal file
43
src/Mod/Part/App/ShapeFix/ShapeFix_RootPy.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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_RootPy"
|
||||
PythonName="Part.ShapeFix.Root"
|
||||
Twin="ShapeFix_Root"
|
||||
TwinPointer="ShapeFix_Root"
|
||||
Include="ShapeFix_Root.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>Root class for fixing operations</UserDocu>
|
||||
</Documentation>
|
||||
<Methode Name="limitTolerance" Const="true">
|
||||
<Documentation>
|
||||
<UserDocu>Returns tolerance limited by [MinTolerance,MaxTolerance]</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Attribute Name="Precision" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Basic precision value</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Precision" Type="Float"/>
|
||||
</Attribute>
|
||||
<Attribute Name="MinTolerance" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Minimal allowed tolerance</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="MinTolerance" Type="Float"/>
|
||||
</Attribute>
|
||||
<Attribute Name="MaxTolerance" ReadOnly="false">
|
||||
<Documentation>
|
||||
<UserDocu>Maximal allowed tolerance</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="MaxTolerance" Type="Float"/>
|
||||
</Attribute>
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
101
src/Mod/Part/App/ShapeFix/ShapeFix_RootPyImp.cpp
Normal file
101
src/Mod/Part/App/ShapeFix/ShapeFix_RootPyImp.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/***************************************************************************
|
||||
* 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>
|
||||
#endif
|
||||
|
||||
#include "ShapeFix/ShapeFix_RootPy.h"
|
||||
#include "ShapeFix/ShapeFix_RootPy.cpp"
|
||||
|
||||
using namespace Part;
|
||||
|
||||
// returns a string which represents the object e.g. when printed in python
|
||||
std::string ShapeFix_RootPy::representation() const
|
||||
{
|
||||
return "<ShapeFix_Root object>";
|
||||
}
|
||||
|
||||
PyObject *ShapeFix_RootPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
{
|
||||
// create a new instance of ShapeFix_RootPy
|
||||
return new ShapeFix_RootPy(new ShapeFix_Root);
|
||||
}
|
||||
|
||||
// constructor method
|
||||
int ShapeFix_RootPy::PyInit(PyObject* /*args*/, PyObject* /*kwds*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject* ShapeFix_RootPy::limitTolerance(PyObject *args)
|
||||
{
|
||||
double tol;
|
||||
if (!PyArg_ParseTuple(args, "d", &tol))
|
||||
return nullptr;
|
||||
|
||||
tol = getShapeFix_RootPtr()->LimitTolerance(tol);
|
||||
return Py::new_reference_to(Py::Float(tol));
|
||||
}
|
||||
|
||||
Py::Float ShapeFix_RootPy::getPrecision() const
|
||||
{
|
||||
return Py::Float(getShapeFix_RootPtr()->Precision());
|
||||
}
|
||||
|
||||
void ShapeFix_RootPy::setPrecision(Py::Float arg)
|
||||
{
|
||||
getShapeFix_RootPtr()->SetPrecision(arg);
|
||||
}
|
||||
|
||||
Py::Float ShapeFix_RootPy::getMinTolerance() const
|
||||
{
|
||||
return Py::Float(getShapeFix_RootPtr()->MinTolerance());
|
||||
}
|
||||
|
||||
void ShapeFix_RootPy::setMinTolerance(Py::Float arg)
|
||||
{
|
||||
getShapeFix_RootPtr()->SetMinTolerance(arg);
|
||||
}
|
||||
|
||||
Py::Float ShapeFix_RootPy::getMaxTolerance() const
|
||||
{
|
||||
return Py::Float(getShapeFix_RootPtr()->MaxTolerance());
|
||||
}
|
||||
|
||||
void ShapeFix_RootPy::setMaxTolerance(Py::Float arg)
|
||||
{
|
||||
getShapeFix_RootPtr()->SetMaxTolerance(arg);
|
||||
}
|
||||
|
||||
PyObject *ShapeFix_RootPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int ShapeFix_RootPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
39
src/Mod/Part/App/ShapeFix/ShapeFix_ShellPy.xml
Normal file
39
src/Mod/Part/App/ShapeFix/ShapeFix_ShellPy.xml
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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_ShellPy"
|
||||
PythonName="Part.ShapeFix.Shell"
|
||||
Twin="ShapeFix_Shell"
|
||||
TwinPointer="ShapeFix_Shell"
|
||||
Include="ShapeFix_Shell.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 shell</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="perform">
|
||||
<Documentation>
|
||||
<UserDocu>Iterates on subshapes and performs fixes</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="shell">
|
||||
<Documentation>
|
||||
<UserDocu>Returns fixed shell (or subset of oriented faces)</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="shape">
|
||||
<Documentation>
|
||||
<UserDocu>In case of multiconnexity returns compound of fixed shells and one shell otherwise</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
</PythonExport>
|
||||
</GenerateModel>
|
||||
108
src/Mod/Part/App/ShapeFix/ShapeFix_ShellPyImp.cpp
Normal file
108
src/Mod/Part/App/ShapeFix/ShapeFix_ShellPyImp.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
/***************************************************************************
|
||||
* 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>
|
||||
#endif
|
||||
|
||||
#include "ShapeFix/ShapeFix_ShellPy.h"
|
||||
#include "ShapeFix/ShapeFix_ShellPy.cpp"
|
||||
#include <Mod/Part/App/TopoShapeShellPy.h>
|
||||
|
||||
using namespace Part;
|
||||
|
||||
// returns a string which represents the object e.g. when printed in python
|
||||
std::string ShapeFix_ShellPy::representation() const
|
||||
{
|
||||
return "<ShapeFix_Shell object>";
|
||||
}
|
||||
|
||||
PyObject *ShapeFix_ShellPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
{
|
||||
// create a new instance of ShapeFix_RootPy
|
||||
return new ShapeFix_ShellPy(new ShapeFix_Shell);
|
||||
}
|
||||
|
||||
// constructor method
|
||||
int ShapeFix_ShellPy::PyInit(PyObject* args, PyObject* /*kwds*/)
|
||||
{
|
||||
PyObject* shell = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "|O!", &TopoShapeShellPy::Type, &shell))
|
||||
return -1;
|
||||
|
||||
if (shell) {
|
||||
getShapeFix_ShellPtr()->Init(TopoDS::Shell(static_cast<TopoShapePy*>(shell)->getTopoShapePtr()->getShape()));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyObject* ShapeFix_ShellPy::init(PyObject *args)
|
||||
{
|
||||
PyObject* shell;
|
||||
if (!PyArg_ParseTuple(args, "O!", &TopoShapeShellPy::Type, &shell))
|
||||
return nullptr;
|
||||
|
||||
getShapeFix_ShellPtr()->Init(TopoDS::Shell(static_cast<TopoShapePy*>(shell)->getTopoShapePtr()->getShape()));
|
||||
Py_Return;
|
||||
}
|
||||
|
||||
PyObject* ShapeFix_ShellPy::perform(PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
|
||||
Standard_Boolean ok = getShapeFix_ShellPtr()->Perform();
|
||||
return Py::new_reference_to(Py::Boolean(ok ? true : false));
|
||||
}
|
||||
|
||||
PyObject* ShapeFix_ShellPy::shell(PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
|
||||
TopoShape shape = getShapeFix_ShellPtr()->Shell();
|
||||
return shape.getPyObject();
|
||||
}
|
||||
|
||||
PyObject* ShapeFix_ShellPy::shape(PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
|
||||
TopoShape shape = getShapeFix_ShellPtr()->Shape();
|
||||
return shape.getPyObject();
|
||||
}
|
||||
|
||||
PyObject *ShapeFix_ShellPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int ShapeFix_ShellPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user