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

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