Part: expose BRepFeat_MakePrism to Python

This commit is contained in:
wmayer
2020-10-16 13:50:29 +02:00
parent b33a120935
commit e1b56f8551
5 changed files with 461 additions and 0 deletions

View File

@@ -108,6 +108,7 @@
#include "Mod/Part/App/BRepOffsetAPI_MakeFillingPy.h"
#include "Mod/Part/App/PartFeaturePy.h"
#include "Mod/Part/App/AttachEnginePy.h"
#include <Mod/Part/App/BRepFeat/MakePrismPy.h>
#include <Mod/Part/App/Geom2d/ArcOfCircle2dPy.h>
#include <Mod/Part/App/Geom2d/ArcOfConic2dPy.h>
#include <Mod/Part/App/Geom2d/ArcOfEllipse2dPy.h>
@@ -376,6 +377,10 @@ PyMOD_INIT_FUNC(Part)
Base::Interpreter().addType(&Part::GeometryBoolExtensionPy ::Type,partModule,"GeometryBoolExtension");
Base::Interpreter().addType(&Part::GeometryDoubleExtensionPy ::Type,partModule,"GeometryDoubleExtension");
// BRepFeat package
PyObject* brepfeatModule(module.getAttr("BRepFeat").ptr());
Base::Interpreter().addType(&Part::MakePrismPy::Type,brepfeatModule,"MakePrism");
// BRepOffsetAPI package
PyObject* brepOffsetApiModule(module.getAttr("BRepOffsetAPI").ptr());
Base::Interpreter().addType(&Part::BRepOffsetAPI_MakePipeShellPy::Type,brepOffsetApiModule,"MakePipeShell");

View File

@@ -271,6 +271,17 @@ PartExport std::list<TopoDS_Edge> sort_Edges(double tol3d, std::list<TopoDS_Edge
}
namespace Part {
class BRepFeatModule : public Py::ExtensionModule<BRepFeatModule>
{
public:
BRepFeatModule() : Py::ExtensionModule<BRepFeatModule>("BRepFeat")
{
initialize("This is a module working with the BRepFeat package."); // register with Python
}
virtual ~BRepFeatModule() {}
};
class BRepOffsetAPIModule : public Py::ExtensionModule<BRepOffsetAPIModule>
{
public:
@@ -317,6 +328,7 @@ public:
class Module : public Py::ExtensionModule<Module>
{
BRepFeatModule brepFeat;
BRepOffsetAPIModule brepOffsetApi;
Geom2dModule geom2d;
GeomPlateModule geomPlate;
@@ -537,6 +549,7 @@ public:
);
initialize("This is a module working with shapes."); // register with Python
PyModule_AddObject(m_module, "BRepFeat", brepFeat.module().ptr());
PyModule_AddObject(m_module, "BRepOffsetAPI", brepOffsetApi.module().ptr());
PyModule_AddObject(m_module, "Geom2d", geom2d.module().ptr());
PyModule_AddObject(m_module, "GeomPlate", geomPlate.module().ptr());

View File

@@ -0,0 +1,100 @@
<?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="MakePrismPy"
PythonName="Part.BRepFeat.MakePrism"
Twin="BRepFeat_MakePrism"
TwinPointer="BRepFeat_MakePrism"
Include="BRepFeat_MakePrism.hxx"
Namespace="Part"
FatherInclude="Base/PyObjectBase.h"
FatherNamespace="Base"
Constructor="true"
Delete="true">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer[at]users.sourceforge.net" />
<UserDocu>Describes functions to build prism features.</UserDocu>
</Documentation>
<Methode Name="init" Keyword="true">
<Documentation>
<UserDocu>
Initializes this algorithm for building prisms along surfaces.
A face Pbase is selected in the shape Sbase
to serve as the basis for the prism. The orientation
of the prism will be defined by the vector Direction.
Fuse offers a choice between:
- removing matter with a Boolean cut using the setting 0
- adding matter with Boolean fusion using the setting 1.
The sketch face Skface serves to determine
the type of operation. If it is inside the basis
shape, a local operation such as glueing can be performed.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="add" Keyword="true">
<Documentation>
<UserDocu>
Indicates that the edge will slide on the face.
Raises ConstructionError if the face does not belong to the
basis shape, or the edge to the prismed shape.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="perform" Keyword="true">
<Documentation>
<UserDocu></UserDocu>
</Documentation>
</Methode>
<Methode Name="performUntilEnd">
<Documentation>
<UserDocu>
Realizes a semi-infinite prism, limited by the
position of the prism base. All other faces extend infinitely.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="performFromEnd">
<Documentation>
<UserDocu>
Realizes a semi-infinite prism, limited by the face Funtil.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="performThruAll">
<Documentation>
<UserDocu>
Builds an infinite prism. The infinite descendants will not be kept in the result.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="performUntilHeight">
<Documentation>
<UserDocu>
Assigns both a limiting shape, Until from TopoDS_Shape
and a height, Length at which to stop generation of the prism feature.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="curves" Const="true">
<Documentation>
<UserDocu>
Returns the list of curves S parallel to the axis of the prism.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="barycCurve" Const="true">
<Documentation>
<UserDocu>
Generates a curve along the center of mass of the primitive.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="shape" Const="true">
<Documentation>
<UserDocu>Returns a shape built by the shape construction algorithm.</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>

View File

@@ -0,0 +1,331 @@
/***************************************************************************
* Copyright (c) 2020 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_Edge.hxx>
# include <TopoDS_Face.hxx>
#endif
#include "BRepFeat/MakePrismPy.h"
#include "BRepFeat/MakePrismPy.cpp"
#include "Geometry.h"
#include "TopoShapeEdgePy.h"
#include "TopoShapeFacePy.h"
#include <Base/VectorPy.h>
using namespace Part;
PyObject *MakePrismPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
{
// create a new instance of MakePrismPy
return new MakePrismPy(nullptr);
}
// constructor method
int MakePrismPy::PyInit(PyObject* args, PyObject* kwds)
{
PyObject* Sbase;
PyObject* Pbase;
PyObject* Skface;
PyObject* Direction;
int Fuse;
PyObject* Modify;
static char* keywords[] = {"Sbase", "Pbase", "Skface", "Direction", "Fuse", "Modifiy", nullptr};
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!O!iO!", keywords,
&(TopoShapePy::Type), &Sbase,
&(TopoShapePy::Type), &Pbase,
&(TopoShapeFacePy::Type), &Skface,
&(Base::VectorPy::Type), &Direction, &Fuse,
&(PyBool_Type), &Modify)) {
try {
TopoDS_Shape sbase = static_cast<TopoShapePy*>(Sbase)->getTopoShapePtr()->getShape();
TopoDS_Shape pbase = static_cast<TopoShapePy*>(Pbase)->getTopoShapePtr()->getShape();
TopoDS_Face skface = TopoDS::Face(static_cast<TopoShapePy*>(Skface)->getTopoShapePtr()->getShape());
Base::Vector3d dir = static_cast<Base::VectorPy*>(Direction)->value();
std::unique_ptr<BRepFeat_MakePrism> ptr(new BRepFeat_MakePrism(sbase, pbase, skface, gp_Dir(dir.x, dir.y, dir.z), Fuse,
PyObject_IsTrue(Modify) ? Standard_True : Standard_False));
setTwinPointer(ptr.release());
return 0;
}
catch (const Standard_Failure& e) {
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
return -1;
}
}
PyErr_Clear();
if (PyArg_ParseTuple(args, "")) {
try {
std::unique_ptr<BRepFeat_MakePrism> ptr(new BRepFeat_MakePrism());
setTwinPointer(ptr.release());
return 0;
}
catch (const Standard_Failure& e) {
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
return -1;
}
}
return -1;
}
// returns a string which represents the object e.g. when printed in python
std::string MakePrismPy::representation(void) const
{
return std::string("<BRepFeat_MakePrism object>");
}
PyObject* MakePrismPy::init(PyObject *args, PyObject* kwds)
{
PyObject* Sbase;
PyObject* Pbase;
PyObject* Skface;
PyObject* Direction;
int Fuse;
PyObject* Modify;
static char* keywords[] = {"Sbase", "Pbase", "Skface", "Direction", "Fuse", "Modifiy", nullptr};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!O!iO!", keywords,
&(TopoShapePy::Type), &Sbase,
&(TopoShapePy::Type), &Pbase,
&(TopoShapeFacePy::Type), &Skface,
&(Base::VectorPy::Type), &Direction, &Fuse,
&(PyBool_Type), &Modify))
return nullptr;
try {
TopoDS_Shape sbase = static_cast<TopoShapePy*>(Sbase)->getTopoShapePtr()->getShape();
TopoDS_Shape pbase = static_cast<TopoShapePy*>(Pbase)->getTopoShapePtr()->getShape();
TopoDS_Face skface = TopoDS::Face(static_cast<TopoShapePy*>(Skface)->getTopoShapePtr()->getShape());
Base::Vector3d dir = static_cast<Base::VectorPy*>(Direction)->value();
getBRepFeat_MakePrismPtr()->Init(sbase, pbase, skface, gp_Dir(dir.x, dir.y, dir.z), Fuse,
PyObject_IsTrue(Modify) ? Standard_True : Standard_False);
Py_Return;
}
catch (const Standard_Failure& e) {
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
return nullptr;
}
}
PyObject* MakePrismPy::add(PyObject *args, PyObject* kwds)
{
PyObject* Edge;
PyObject* Face;
static char* keywords[] = {"Edge", "Face", nullptr};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", keywords,
&(TopoShapeEdgePy::Type), &Edge,
&(TopoShapeFacePy::Type), &Face))
return nullptr;
try {
TopoDS_Edge edge = TopoDS::Edge(static_cast<TopoShapePy*>(Edge)->getTopoShapePtr()->getShape());
TopoDS_Face face = TopoDS::Face(static_cast<TopoShapePy*>(Face)->getTopoShapePtr()->getShape());
getBRepFeat_MakePrismPtr()->Add(edge, face);
Py_Return;
}
catch (const Standard_Failure& e) {
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
return nullptr;
}
}
PyObject* MakePrismPy::perform(PyObject *args, PyObject* kwds)
{
PyObject* From;
PyObject* Until;
static char* keywords_fu[] = {"From", "Until", nullptr};
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", keywords_fu,
&(TopoShapePy::Type), &From,
&(TopoShapePy::Type), &Until)) {
try {
TopoDS_Shape from = static_cast<TopoShapePy*>(From)->getTopoShapePtr()->getShape();
TopoDS_Shape until = static_cast<TopoShapePy*>(Until)->getTopoShapePtr()->getShape();
getBRepFeat_MakePrismPtr()->Perform(from, until);
Py_Return;
}
catch (const Standard_Failure& e) {
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
return nullptr;
}
}
PyErr_Clear();
static char* keywords_u[] = {"Until", nullptr};
if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", keywords_u,
&(TopoShapePy::Type), &Until)) {
try {
TopoDS_Shape until = static_cast<TopoShapePy*>(Until)->getTopoShapePtr()->getShape();
getBRepFeat_MakePrismPtr()->Perform(until);
Py_Return;
}
catch (const Standard_Failure& e) {
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
return nullptr;
}
}
PyErr_Clear();
double length;
static char* keywords_l[] = {"Length", nullptr};
if (PyArg_ParseTupleAndKeywords(args, kwds, "d", keywords_l, &length)) {
try {
getBRepFeat_MakePrismPtr()->Perform(length);
Py_Return;
}
catch (const Standard_Failure& e) {
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
return nullptr;
}
}
PyErr_SetString(PyExc_TypeError, "supported signatures:\n"
"perform(From [shape], Until [shape])\n"
"perform(Until [shape])\n"
"perform(Length [float])\n");
return nullptr;
}
PyObject* MakePrismPy::performUntilEnd(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
try {
getBRepFeat_MakePrismPtr()->PerformUntilEnd();
Py_Return;
}
catch (const Standard_Failure& e) {
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
return nullptr;
}
}
PyObject* MakePrismPy::performFromEnd(PyObject *args)
{
PyObject* Until;
if (!PyArg_ParseTuple(args, "O!", &(TopoShapePy::Type), &Until))
return nullptr;
try {
TopoDS_Shape until = static_cast<TopoShapePy*>(Until)->getTopoShapePtr()->getShape();
getBRepFeat_MakePrismPtr()->PerformFromEnd(until);
Py_Return;
}
catch (const Standard_Failure& e) {
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
return nullptr;
}
}
PyObject* MakePrismPy::performThruAll(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
try {
getBRepFeat_MakePrismPtr()->PerformThruAll();
Py_Return;
}
catch (const Standard_Failure& e) {
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
return nullptr;
}
}
PyObject* MakePrismPy::performUntilHeight(PyObject *args)
{
PyObject* Until;
double length;
if (!PyArg_ParseTuple(args, "O!d", &(TopoShapePy::Type), &Until, &length))
return nullptr;
try {
TopoDS_Shape until = static_cast<TopoShapePy*>(Until)->getTopoShapePtr()->getShape();
getBRepFeat_MakePrismPtr()->PerformUntilHeight(until, length);
Py_Return;
}
catch (const Standard_Failure& e) {
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
return nullptr;
}
}
PyObject* MakePrismPy::curves(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
TColGeom_SequenceOfCurve S;
getBRepFeat_MakePrismPtr()->Curves(S);
Py::Tuple tuple(S.Length());
for (int i = S.Lower(); i <= S.Upper(); ++i) {
Handle(Geom_Curve) hC = S.Value(i);
std::unique_ptr<GeomCurve> gc(Part::makeFromCurve(hC));
tuple.setItem(i, Py::asObject(gc->getPyObject()));
}
return Py::new_reference_to(tuple);
}
PyObject* MakePrismPy::barycCurve(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
Handle(Geom_Curve) hC = getBRepFeat_MakePrismPtr()->BarycCurve();
std::unique_ptr<GeomCurve> gc(Part::makeFromCurve(hC));
return gc->getPyObject();
}
PyObject* MakePrismPy::shape(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return nullptr;
try {
TopoShape shape(getBRepFeat_MakePrismPtr()->Shape());
return shape.getPyObject();
}
catch (const Standard_Failure& e) {
PyErr_SetString(PyExc_RuntimeError, e.GetMessageString());
return nullptr;
}
}
PyObject *MakePrismPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int MakePrismPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

View File

@@ -94,10 +94,13 @@ generate_from_xml(BRepOffsetAPI_MakePipeShellPy)
generate_from_xml(BRepOffsetAPI_MakeFillingPy)
# make sure to create the directory at configure time
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/BRepFeat)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Geom2d)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/GeomPlate)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ShapeUpgrade)
generate_from_xml(BRepFeat/MakePrismPy)
generate_from_xml(Geom2d/ArcOfCircle2dPy)
generate_from_xml(Geom2d/ArcOfConic2dPy)
generate_from_xml(Geom2d/ArcOfEllipse2dPy)
@@ -312,6 +315,14 @@ SET(Python_SRCS
)
SOURCE_GROUP("Python" FILES ${Python_SRCS})
# BRepFeat wrappers
SET(BRepFeatPy_SRCS
BRepFeat/MakePrismPy.xml
BRepFeat/MakePrismPyImp.cpp
)
SOURCE_GROUP("ShapeUpgrade" FILES ${ShapeUpgradePy_SRCS})
# Geom2d wrappers
SET(Geom2dPy_SRCS
Geom2d/ArcOfCircle2dPy.xml
@@ -376,6 +387,7 @@ SET(Part_SRCS
${Features_SRCS}
${Properties_SRCS}
${Python_SRCS}
${BRepFeatPy_SRCS}
${Geom2dPy_SRCS}
${GeomPlatePy_SRCS}
${ShapeUpgradePy_SRCS}