Skip to content

Commit

Permalink
Part: add function Geometry.toShell
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Oct 6, 2021
1 parent 7b45d63 commit 5593b84
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Mod/Part/App/GeometrySurfacePy.xml
Expand Up @@ -22,6 +22,11 @@
<UserDocu>Return the shape for the geometry.</UserDocu>
</Documentation>
</Methode>
<Methode Name="toShell" Const="true" Keyword="true">
<Documentation>
<UserDocu>Make a shell of the surface.</UserDocu>
</Documentation>
</Methode>
<Methode Name="getD0" Const="true">
<Documentation>
<UserDocu>Returns the point of given parameter</UserDocu>
Expand Down
48 changes: 48 additions & 0 deletions src/Mod/Part/App/GeometrySurfacePyImp.cpp
Expand Up @@ -25,6 +25,7 @@

#ifndef _PreComp_
# include <BRepBuilderAPI_MakeFace.hxx>
# include <BRepBuilderAPI_MakeShell.hxx>
# include <gp_Circ.hxx>
# include <gp_Dir.hxx>
# include <gp_Elips.hxx>
Expand Down Expand Up @@ -74,6 +75,7 @@
#include <Mod/Part/App/TopoShape.h>
#include <Mod/Part/App/TopoShapePy.h>
#include <Mod/Part/App/TopoShapeFacePy.h>
#include <Mod/Part/App/TopoShapeShellPy.h>

namespace Part {
const Py::Object makeTrimmedCurvePy(const Handle(Geom_Curve)& c, double f, double l)
Expand Down Expand Up @@ -153,6 +155,52 @@ PyObject* GeometrySurfacePy::toShape(PyObject *args)
return 0;
}

PyObject* GeometrySurfacePy::toShell(PyObject *args, PyObject* kwds)
{
PyObject* bound = nullptr;
PyObject* segm = nullptr;
static char *kwlist[] = {"Bounds", "Segment", nullptr};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!O!", kwlist,
&PyTuple_Type, &bound, &PyBool_Type, &segm))
return nullptr;

Handle(Geom_Geometry) g = getGeometryPtr()->handle();
Handle(Geom_Surface) s = Handle(Geom_Surface)::DownCast(g);
try {
if (!s.IsNull()) {
if (segm) {
Standard_Boolean segment = PyObject_IsTrue(segm) ? Standard_True : Standard_False;
BRepBuilderAPI_MakeShell mkBuilder(s, segment);
TopoDS_Shape sh = mkBuilder.Shape();
return new TopoShapeShellPy(new TopoShape(sh));
}
else {
double u1,u2,v1,v2;
s->Bounds(u1,u2,v1,v2);

if (bound) {
Py::Tuple tuple(bound);
u1 = double(Py::Float(tuple[0]));
u2 = double(Py::Float(tuple[1]));
v1 = double(Py::Float(tuple[2]));
v2 = double(Py::Float(tuple[3]));
}

BRepBuilderAPI_MakeShell mkBuilder(s, u1, u2, v1, v2);
TopoDS_Shape sh = mkBuilder.Shape();
return new TopoShapeShellPy(new TopoShape(sh));
}
}
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return nullptr;
}

PyErr_SetString(PartExceptionOCCError, "Geometry is not a surface");
return nullptr;
}

PyObject* GeometrySurfacePy::getD0(PyObject *args)
{
Handle(Geom_Geometry) g = getGeometryPtr()->handle();
Expand Down

0 comments on commit 5593b84

Please sign in to comment.