TopoShapeCompSolidPyImp.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 #include <BRep_Builder.hxx>
00026 #include <TopoDS_CompSolid.hxx>
00027
00028 #include "Mod/Part/App/TopoShape.h"
00029
00030
00031 #include "TopoShapeSolidPy.h"
00032 #include "TopoShapeCompSolidPy.h"
00033 #include "TopoShapeCompSolidPy.cpp"
00034
00035 using namespace Part;
00036
00037
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* )
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* ) const
00109 {
00110 return 0;
00111 }
00112
00113 int TopoShapeCompSolidPy::setCustomAttributes(const char* , PyObject* )
00114 {
00115 return 0;
00116 }