diff --git a/src/Mod/Part/App/TopoShapeSolidPy.xml b/src/Mod/Part/App/TopoShapeSolidPy.xml index c8e4048cf742..77e6608539c2 100644 --- a/src/Mod/Part/App/TopoShapeSolidPy.xml +++ b/src/Mod/Part/App/TopoShapeSolidPy.xml @@ -90,5 +90,15 @@ shape if the solid has no shells Returns the radius of gyration of the current system about the axis A. + + + 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) + + + diff --git a/src/Mod/Part/App/TopoShapeSolidPyImp.cpp b/src/Mod/Part/App/TopoShapeSolidPyImp.cpp index 76ff4e73c044..7720219a943d 100644 --- a/src/Mod/Part/App/TopoShapeSolidPyImp.cpp +++ b/src/Mod/Part/App/TopoShapeSolidPyImp.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #if OCC_VERSION_HEX >= 0x060600 #include #endif @@ -33,6 +34,7 @@ #include #include #include +# include #include #include #include @@ -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((*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((*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;