TopoShapeSolidPyImp.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #include <BRepGProp.hxx>
00027 #include <BRepTools.hxx>
00028 #include <GProp_GProps.hxx>
00029 #include <BRepBuilderAPI_MakeSolid.hxx>
00030 #include <TopExp_Explorer.hxx>
00031 #include <TopoDS.hxx>
00032 #include <TopoDS_Solid.hxx>
00033 #include <TopoDS_Shell.hxx>
00034
00035 #include <Base/VectorPy.h>
00036 #include <Base/GeometryPyCXX.h>
00037
00038 #include "Mod/Part/App/TopoShape.h"
00039
00040
00041 #include "TopoShapeShellPy.h"
00042 #include "TopoShapeSolidPy.h"
00043 #include "TopoShapeSolidPy.cpp"
00044
00045 using namespace Part;
00046
00047
00048 std::string TopoShapeSolidPy::representation(void) const
00049 {
00050 std::stringstream str;
00051 str << "<Solid object at " << getTopoShapePtr() << ">";
00052
00053 return str.str();
00054 }
00055
00056 PyObject *TopoShapeSolidPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00057 {
00058
00059 return new TopoShapeSolidPy(new TopoShape);
00060 }
00061
00062
00063 int TopoShapeSolidPy::PyInit(PyObject* args, PyObject* )
00064 {
00065 PyObject *obj;
00066 if (!PyArg_ParseTuple(args, "O!", &(TopoShapePy::Type), &obj))
00067 return -1;
00068
00069 try {
00070 BRepBuilderAPI_MakeSolid mkSolid;
00071 const TopoDS_Shape& shape = static_cast<TopoShapePy*>(obj)
00072 ->getTopoShapePtr()->_Shape;
00073 TopExp_Explorer anExp (shape, TopAbs_SHELL);
00074 int count=0;
00075 for (; anExp.More(); anExp.Next()) {
00076 ++count;
00077 mkSolid.Add(TopoDS::Shell(anExp.Current()));
00078 }
00079
00080 if (count == 0)
00081 Standard_Failure::Raise("No shells found in shape");
00082
00083 const TopoDS_Solid& solid = mkSolid.Solid();
00084 getTopoShapePtr()->_Shape = solid;
00085 }
00086 catch (Standard_Failure) {
00087 PyErr_SetString(PyExc_Exception, "creation of solid failed");
00088 return -1;
00089 }
00090
00091 return 0;
00092 }
00093
00094 Py::Object TopoShapeSolidPy::getCenterOfMass(void) const
00095 {
00096 GProp_GProps props;
00097 BRepGProp::VolumeProperties(getTopoShapePtr()->_Shape, props);
00098 gp_Pnt c = props.CentreOfMass();
00099 return Py::Vector(Base::Vector3d(c.X(),c.Y(),c.Z()));
00100 }
00101
00102 Py::Object TopoShapeSolidPy::getOuterShell(void) const
00103 {
00104 TopoDS_Shell shell;
00105 const TopoDS_Shape& shape = getTopoShapePtr()->_Shape;
00106 if (!shape.IsNull() && shape.ShapeType() == TopAbs_SOLID)
00107 shell = BRepTools::OuterShell(TopoDS::Solid(shape));
00108 return Py::Object(new TopoShapeShellPy(new TopoShape(shell)),true);
00109 }
00110
00111 PyObject *TopoShapeSolidPy::getCustomAttributes(const char* ) const
00112 {
00113 return 0;
00114 }
00115
00116 int TopoShapeSolidPy::setCustomAttributes(const char* , PyObject* )
00117 {
00118 return 0;
00119 }