TopoShapeCompSolidPyImp.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 #include <BRep_Builder.hxx>
00026 #include <TopoDS_CompSolid.hxx>
00027 
00028 #include "Mod/Part/App/TopoShape.h"
00029 
00030 // inclusion of the generated files (generated out of TopoShapeCompSolidPy.xml)
00031 #include "TopoShapeSolidPy.h"
00032 #include "TopoShapeCompSolidPy.h"
00033 #include "TopoShapeCompSolidPy.cpp"
00034 
00035 using namespace Part;
00036 
00037 // returns a string which represents the object e.g. when printed in python
00038 std::string TopoShapeCompSolidPy::representation(void) const
00039 {
00040     std::stringstream str;
00041     str << "<CompSolid object at " << getTopoShapePtr() << ">";
00042 
00043     return str.str();
00044 }
00045 
00046 PyObject *TopoShapeCompSolidPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00047 {
00048     return new TopoShapeCompSolidPy(new TopoShape);
00049 }
00050 
00051 int TopoShapeCompSolidPy::PyInit(PyObject* args, PyObject* /*kwd*/)
00052 {
00053     PyObject *pcObj;
00054     if (!PyArg_ParseTuple(args, "O!", &(PyList_Type), &pcObj))
00055         return -1;
00056 
00057     BRep_Builder builder;
00058     TopoDS_CompSolid Comp;
00059     builder.MakeCompSolid(Comp);
00060 
00061     try {
00062         Py::List list(pcObj);
00063         for (Py::List::iterator it = list.begin(); it != list.end(); ++it) {
00064             if (PyObject_TypeCheck((*it).ptr(), &(Part::TopoShapeSolidPy::Type))) {
00065                 const TopoDS_Shape& sh = static_cast<TopoShapePy*>((*it).ptr())->
00066                     getTopoShapePtr()->_Shape;
00067                 if (!sh.IsNull())
00068                     builder.Add(Comp, sh);
00069             }
00070         }
00071     }
00072     catch (Standard_Failure) {
00073         Handle_Standard_Failure e = Standard_Failure::Caught();
00074         PyErr_SetString(PyExc_Exception, e->GetMessageString());
00075         return -1;
00076     }
00077 
00078     getTopoShapePtr()->_Shape = Comp;
00079     return 0;
00080 }
00081 
00082 PyObject*  TopoShapeCompSolidPy::add(PyObject *args)
00083 {
00084     PyObject *obj;
00085     if (!PyArg_ParseTuple(args, "O!", &(Part::TopoShapeSolidPy::Type), &obj))
00086         return NULL;
00087 
00088     BRep_Builder builder;
00089     TopoDS_Shape& comp = getTopoShapePtr()->_Shape;
00090     
00091     try {
00092         const TopoDS_Shape& sh = static_cast<TopoShapePy*>(obj)->
00093             getTopoShapePtr()->_Shape;
00094         if (!sh.IsNull())
00095             builder.Add(comp, sh);
00096         else
00097             Standard_Failure::Raise("Cannot empty shape to compound solid");
00098     }
00099     catch (Standard_Failure) {
00100         Handle_Standard_Failure e = Standard_Failure::Caught();
00101         PyErr_SetString(PyExc_Exception, e->GetMessageString());
00102         return 0;
00103     }
00104 
00105     Py_Return;
00106 }
00107 
00108 PyObject *TopoShapeCompSolidPy::getCustomAttributes(const char* /*attr*/) const
00109 {
00110     return 0;
00111 }
00112 
00113 int TopoShapeCompSolidPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
00114 {
00115     return 0; 
00116 }

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