TopoShapeSolidPyImp.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de) 2008     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
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 // inclusion of the generated files (generated out of TopoShapeSolidPy.xml)
00041 #include "TopoShapeShellPy.h"
00042 #include "TopoShapeSolidPy.h"
00043 #include "TopoShapeSolidPy.cpp"
00044 
00045 using namespace Part;
00046 
00047 // returns a string which represents the object e.g. when printed in python
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     // create a new instance of TopoShapeSolidPy and the Twin object 
00059     return new TopoShapeSolidPy(new TopoShape);
00060 }
00061 
00062 // constructor method
00063 int TopoShapeSolidPy::PyInit(PyObject* args, PyObject* /*kwd*/)
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* /*attr*/) const
00112 {
00113     return 0;
00114 }
00115 
00116 int TopoShapeSolidPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
00117 {
00118     return 0; 
00119 }

Generated on Wed Nov 23 19:00:48 2011 for FreeCAD by  doxygen 1.6.1