Skip to content

Commit

Permalink
+ Extrude subset of faces of a solid
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jan 6, 2014
1 parent 1820a56 commit 5d1960d
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Mod/Part/App/TopoShapeSolidPy.xml
Expand Up @@ -90,5 +90,15 @@ shape if the solid has no shells</UserDocu>
<UserDocu>Returns the radius of gyration of the current system about the axis A.</UserDocu>
</Documentation>
</Methode>
<Methode Name="extrudeFaces" ReadOnly="true">
<Documentation>
<UserDocu>Extrude single faces of the solid.
Example:
solid.extrudeFaces({solid.Faces[0]:1.0,solid.Faces[1]:2.0})
Example:
solid.extrudeFaces((solid.Faces[0],solid.Faces[1]), 1.5)
</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>
62 changes: 62 additions & 0 deletions src/Mod/Part/App/TopoShapeSolidPyImp.cpp
Expand Up @@ -26,13 +26,15 @@
#include <Standard_Version.hxx>
#include <BRepGProp.hxx>
#include <BRepTools.hxx>
#include <BRepOffset_MakeOffset.hxx>
#if OCC_VERSION_HEX >= 0x060600
#include <BRepClass3d.hxx>
#endif
#include <GProp_GProps.hxx>
#include <GProp_PrincipalProps.hxx>
#include <BRepBuilderAPI_MakeSolid.hxx>
#include <BRepLib.hxx>
# include <Precision.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Solid.hxx>
Expand Down Expand Up @@ -238,6 +240,66 @@ PyObject* TopoShapeSolidPy::getRadiusOfGyration(PyObject *args)
}
}

PyObject* TopoShapeSolidPy::extrudeFaces(PyObject *args)
{
PyObject *obj;
Standard_Real offset;

const TopoDS_Shape& shape = getTopoShapePtr()->_Shape;
BRepOffset_MakeOffset builder;
// Set here an offset value higher than the tolerance
builder.Initialize(shape,1.0,Precision::Confusion(),BRepOffset_Skin,Standard_False,Standard_False,GeomAbs_Intersection);
TopExp_Explorer xp(shape,TopAbs_FACE);
while (xp.More()) {
// go through all faces and set offset to zero
builder.SetOffsetOnFace(TopoDS::Face(xp.Current()), 0.0);
xp.Next();
}

bool paramOK = false;
if (!paramOK && PyArg_ParseTuple(args, "Od", &obj,&offset)) {
paramOK = true;
Py::Sequence list(obj);
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
if (PyObject_TypeCheck((*it).ptr(), &(Part::TopoShapePy::Type))) {
// set offset of the requested faces
const TopoDS_Shape& face = static_cast<TopoShapePy*>((*it).ptr())->getTopoShapePtr()->_Shape;
builder.SetOffsetOnFace(TopoDS::Face(face), offset);
}
}
}

PyErr_Clear();
if (!paramOK && PyArg_ParseTuple(args, "O!", &PyDict_Type, &obj)) {
paramOK = true;
Py::Dict dict(obj);
for (Py::Dict::iterator it = dict.begin(); it != dict.end(); ++it) {
if (PyObject_TypeCheck((*it).first.ptr(), &(Part::TopoShapePy::Type))) {
// set offset of the requested faces
const TopoDS_Shape& face = static_cast<TopoShapePy*>((*it).first.ptr())->getTopoShapePtr()->_Shape;
Standard_Real value = (double)Py::Float((*it).second.ptr());
builder.SetOffsetOnFace(TopoDS::Face(face), value);
}
}
}

if (!paramOK) {
PyErr_SetString(PyExc_TypeError, "Wrong parameter");
return 0;
}

try {
builder.MakeOffsetShape();
const TopoDS_Shape& offsetshape = builder.Shape();
return new TopoShapeSolidPy(new TopoShape(offsetshape));
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PyExc_Exception, e->GetMessageString());
return 0;
}
}

PyObject *TopoShapeSolidPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
Expand Down

0 comments on commit 5d1960d

Please sign in to comment.