TopoShapeCompoundPyImp.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 "Mod/Part/App/TopoShape.h"
00027 #include <BRep_Builder.hxx>
00028 #include <TopoDS_Compound.hxx>
00029
00030
00031 #include "TopoShapeCompoundPy.h"
00032 #include "TopoShapeCompoundPy.cpp"
00033
00034 using namespace Part;
00035
00036
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
00050 int TopoShapeCompoundPy::PyInit(PyObject* args, PyObject* )
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* ) const
00106 {
00107 return 0;
00108 }
00109
00110 int TopoShapeCompoundPy::setCustomAttributes(const char* , PyObject* )
00111 {
00112 return 0;
00113 }