diff options
author | Maxime Curioni <maxime.curioni@gmail.com> | 2008-07-24 12:29:48 +0400 |
---|---|---|
committer | Maxime Curioni <maxime.curioni@gmail.com> | 2008-07-24 12:29:48 +0400 |
commit | a0359c37506d05589bae86e4818fa653c8f281ab (patch) | |
tree | 35927f22801fa65585ac6f076abb29406189dd2a /source/blender/freestyle/intern/python/BPy_SShape.cpp | |
parent | dd899939dabae68564f7a1d1994b50ee2f2cf8be (diff) |
soc-2008-mxcurioni: added (without testing) the following classes: BBox, SShape, ViewShape. Also corrected a few typos (Get#->get#).
Diffstat (limited to 'source/blender/freestyle/intern/python/BPy_SShape.cpp')
-rw-r--r-- | source/blender/freestyle/intern/python/BPy_SShape.cpp | 301 |
1 files changed, 229 insertions, 72 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_SShape.cpp b/source/blender/freestyle/intern/python/BPy_SShape.cpp index a5b1cf3f27a..62c554aab51 100644 --- a/source/blender/freestyle/intern/python/BPy_SShape.cpp +++ b/source/blender/freestyle/intern/python/BPy_SShape.cpp @@ -1,120 +1,277 @@ - PyObject *_wrap_SShape_userdata_set(PyObject *self , PyObject *args) { +#include "BPy_SShape.h" + +#include "BPy_Convert.h" +#include "Interface0D/BPy_SVertex.h" +#include "Interface1D/BPy_FEdge.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/////////////////////////////////////////////////////////////////////////////////////////// + +/*--------------- Python API function prototypes for SShape instance -----------*/ +static int SShape___init__(BPy_SShape *self, PyObject *args, PyObject *kwds); +static void SShape___dealloc__(BPy_SShape *self); +static PyObject * SShape___repr__(BPy_SShape* self); + +static PyObject * SShape_AddEdge( BPy_SShape *self , PyObject *args); +static PyObject * SShape_AddNewVertex( BPy_SShape *self , PyObject *args); +static PyObject * SShape_setBBox( BPy_SShape *self , PyObject *args); +static PyObject * SShape_ComputeBBox( BPy_SShape *self ); +static PyObject * SShape_bbox( BPy_SShape *self ); +static PyObject * SShape_getVertexList( BPy_SShape *self ); +static PyObject * SShape_getEdgeList( BPy_SShape *self ); +static PyObject * SShape_getId( BPy_SShape *self ); +static PyObject * SShape_setId( BPy_SShape *self , PyObject *args); + +/*----------------------SShape instance definitions ----------------------------*/ +static PyMethodDef BPy_SShape_methods[] = { + {"AddEdge", ( PyCFunction ) SShape_AddEdge, METH_VARARGS, "(FEdge fe )Adds a FEdge to the list of FEdges. "}, + {"AddNewVertex", ( PyCFunction ) SShape_AddNewVertex, METH_VARARGS, "(SVertex sv )Adds a SVertex to the list of SVertex of this Shape. The SShape attribute of the SVertex is also set to 'this'."}, + {"setBBox", ( PyCFunction ) SShape_setBBox, METH_VARARGS, "(BBox bb )Sets the Bounding Box of the Shape"}, + {"ComputeBBox", ( PyCFunction ) SShape_ComputeBBox, METH_NOARGS, "( )Compute the bbox of the SShape"}, + {"bbox", ( PyCFunction ) SShape_bbox, METH_NOARGS, "( )Returns the bounding box of the shape."}, + {"getVertexList", ( PyCFunction ) SShape_getVertexList, METH_NOARGS, "( )Returns the list of SVertex of the Shape"}, + {"getEdgeList", ( PyCFunction ) SShape_getEdgeList, METH_NOARGS, "( )Returns the list of FEdges of the Shape."}, + {"getId", ( PyCFunction ) SShape_getId, METH_NOARGS, "( )Returns the Id of the Shape. "}, + {"setId", ( PyCFunction ) SShape_setId, METH_VARARGS, "(Id id )Sets the Id of the shape. "}, + + {NULL, NULL, 0, NULL} +}; + +/*-----------------------BPy_SShape type definition ------------------------------*/ + +PyTypeObject SShape_Type = { + PyObject_HEAD_INIT( NULL ) + 0, /* ob_size */ + "SShape", /* tp_name */ + sizeof( BPy_SShape ), /* tp_basicsize */ + 0, /* tp_itemsize */ + + /* methods */ + (destructor)SShape___dealloc__, /* tp_dealloc */ + NULL, /* printfunc tp_print; */ + NULL, /* getattrfunc tp_getattr; */ + NULL, /* setattrfunc tp_setattr; */ + NULL, /* tp_compare */ + (reprfunc)SShape___repr__, /* tp_repr */ + + /* Method suites for standard classes */ + + NULL, /* PyNumberMethods *tp_as_number; */ + NULL, /* PySequenceMethods *tp_as_sequence; */ + NULL, /* PyMappingMethods *tp_as_mapping; */ + + /* More standard operations (here for binary compatibility) */ + + NULL, /* hashfunc tp_hash; */ + NULL, /* ternaryfunc tp_call; */ + NULL, /* reprfunc tp_str; */ + NULL, /* getattrofunc tp_getattro; */ + NULL, /* setattrofunc tp_setattro; */ + + /* Functions to access object as input/output buffer */ + NULL, /* PyBufferProcs *tp_as_buffer; */ + + /*** Flags to define presence of optional/expanded features ***/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* long tp_flags; */ + + NULL, /* char *tp_doc; Documentation string */ + /*** Assigned meaning in release 2.0 ***/ + /* call function for all accessible objects */ + NULL, /* traverseproc tp_traverse; */ + + /* delete references to contained objects */ + NULL, /* inquiry tp_clear; */ + + /*** Assigned meaning in release 2.1 ***/ + /*** rich comparisons ***/ + NULL, /* richcmpfunc tp_richcompare; */ + + /*** weak reference enabler ***/ + 0, /* long tp_weaklistoffset; */ + + /*** Added in release 2.2 ***/ + /* Iterators */ + NULL, /* getiterfunc tp_iter; */ + NULL, /* iternextfunc tp_iternext; */ + + /*** Attribute descriptor and subclassing stuff ***/ + BPy_SShape_methods, /* struct PyMethodDef *tp_methods; */ + NULL, /* struct PyMemberDef *tp_members; */ + NULL, /* struct PyGetSetDef *tp_getset; */ + NULL, /* struct _typeobject *tp_base; */ + NULL, /* PyObject *tp_dict; */ + NULL, /* descrgetfunc tp_descr_get; */ + NULL, /* descrsetfunc tp_descr_set; */ + 0, /* long tp_dictoffset; */ + (initproc)SShape___init__, /* initproc tp_init; */ + NULL, /* allocfunc tp_alloc; */ + PyType_GenericNew, /* newfunc tp_new; */ + + /* Low-level free-memory routine */ + NULL, /* freefunc tp_free; */ + + /* For PyObject_IS_GC */ + NULL, /* inquiry tp_is_gc; */ + NULL, /* PyObject *tp_bases; */ + + /* method resolution order */ + NULL, /* PyObject *tp_mro; */ + NULL, /* PyObject *tp_cache; */ + NULL, /* PyObject *tp_subclasses; */ + NULL, /* PyObject *tp_weaklist; */ + NULL +}; + +//-------------------MODULE INITIALIZATION-------------------------------- +PyMODINIT_FUNC SShape_Init( PyObject *module ) +{ + if( module == NULL ) + return; + + if( PyType_Ready( &SShape_Type ) < 0 ) + return; + + Py_INCREF( &SShape_Type ); + PyModule_AddObject(module, "SShape", (PyObject *)&SShape_Type); } +//------------------------INSTANCE METHODS ---------------------------------- - PyObject *_wrap_SShape_userdata_get(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_new_SShape__SWIG_0(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_new_SShape__SWIG_1(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_new_SShape(PyObject *self, PyObject *args) { -} - - - PyObject *_wrap_SShape_dupplicate(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_delete_SShape(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_SShape_AddEdge(PyObject *self , PyObject *args) { -} - - - PyObject *_wrap_SShape_AddNewVertex(PyObject *self , PyObject *args) { -} +int SShape___init__(BPy_SShape *self, PyObject *args, PyObject *kwds) +{ + PyObject *obj; + if (! PyArg_ParseTuple(args, "|O", &obj) ) + return -1; - PyObject *_wrap_SShape_AddChain(PyObject *self , PyObject *args) { + if( !obj ) { + self->ss = new SShape(); + + } else if( BPy_SShape_Check(obj) ) { + self->ss = new SShape(*( ((BPy_SShape *) obj)->ss )); + } + + return 0; } - - PyObject *_wrap_SShape_CreateSVertex(PyObject *self , PyObject *args) { +void SShape___dealloc__(BPy_SShape *self) +{ + delete self->ss; + self->ob_type->tp_free((PyObject*)self); } - - PyObject *_wrap_SShape_SplitEdge(PyObject *self , PyObject *args) { +PyObject * SShape___repr__(BPy_SShape *self) +{ + return PyString_FromFormat("SShape - address: %p", self->ss ); } +PyObject * SShape_AddEdge( BPy_SShape *self , PyObject *args) { + PyObject *py_fe = 0; - PyObject *_wrap_SShape_SplitEdgeIn2(PyObject *self , PyObject *args) { -} - + if(!( PyArg_ParseTuple(args, "O", &py_fe) && BPy_FEdge_Check(py_fe) )) { + cout << "ERROR: SShape_AddEdge" << endl; + Py_RETURN_NONE; + } + + self->ss->AddEdge( ((BPy_FEdge *) py_fe)->fe ); - PyObject *_wrap_SShape_SetBBox(PyObject *self , PyObject *args) { + Py_RETURN_NONE; } +PyObject * SShape_AddNewVertex( BPy_SShape *self , PyObject *args) { + PyObject *py_sv = 0; - PyObject *_wrap_SShape_ComputeBBox(PyObject *self , PyObject *args) { -} + if(!( PyArg_ParseTuple(args, "O", &py_sv) && BPy_SVertex_Check(py_sv) )) { + cout << "ERROR: SShape_AddNewVertex" << endl; + Py_RETURN_NONE; + } + + self->ss->AddNewVertex( ((BPy_SVertex *) py_sv)->sv ); - - PyObject *_wrap_SShape_RemoveEdgeFromChain(PyObject *self , PyObject *args) { + Py_RETURN_NONE; } +PyObject * SShape_setBBox( BPy_SShape *self , PyObject *args) { + PyObject *py_bb = 0; - PyObject *_wrap_SShape_RemoveEdge(PyObject *self , PyObject *args) { -} - + if(!( PyArg_ParseTuple(args, "O", &py_bb) && BPy_BBox_Check(py_bb) )) { + cout << "ERROR: SShape_SetBBox" << endl; + Py_RETURN_NONE; + } + + self->ss->setBBox(*( ((BPy_BBox*) py_bb)->bb )); - PyObject *_wrap_SShape_GetVertexList(PyObject *self , PyObject *args) { + Py_RETURN_NONE; } +PyObject * SShape_ComputeBBox( BPy_SShape *self ) { + self->ss->ComputeBBox(); - PyObject *_wrap_SShape_GetEdgeList(PyObject *self , PyObject *args) { + Py_RETURN_NONE; } - - PyObject *_wrap_SShape_GetChains(PyObject *self , PyObject *args) { +PyObject * SShape_bbox( BPy_SShape *self ) { + BBox<Vec3r> bb( self->ss->bbox() ); + return BPy_BBox_from_BBox( bb ); } - PyObject *_wrap_SShape_bbox(PyObject *self , PyObject *args) { -} +PyObject * SShape_getVertexList( BPy_SShape *self ) { + PyObject *py_vertices = PyList_New(NULL); - - PyObject *_wrap_SShape_material(PyObject *self , PyObject *args) { + vector< SVertex * > vertices = self->ss->getVertexList(); + vector< SVertex * >::iterator it; + + for( it = vertices.begin(); it != vertices.end(); it++ ) { + PyList_Append( py_vertices, BPy_SVertex_from_SVertex(*( *it )) ); + } + + return py_vertices; } - PyObject *_wrap_SShape_materials(PyObject *self , PyObject *args) { -} - +PyObject * SShape_getEdgeList( BPy_SShape *self ) { + PyObject *py_edges = PyList_New(NULL); - PyObject *_wrap_SShape_viewShape(PyObject *self , PyObject *args) { + vector< FEdge * > edges = self->ss->getEdgeList(); + vector< FEdge * >::iterator it; + + for( it = edges.begin(); it != edges.end(); it++ ) { + PyList_Append( py_edges, BPy_FEdge_from_FEdge(*( *it )) ); + } + + return py_edges; } - - PyObject *_wrap_SShape_importance(PyObject *self , PyObject *args) { +PyObject * SShape_getId( BPy_SShape *self ) { + Id id( self->ss->getId() ); + return BPy_Id_from_Id( id ); } +PyObject * SShape_setId( BPy_SShape *self , PyObject *args) { + PyObject *py_id; - PyObject *_wrap_SShape_getId(PyObject *self , PyObject *args) { -} + if(!( PyArg_ParseTuple(args, "O", &py_id) && BPy_Id_Check(py_id) )) { + cout << "ERROR: SShape_setId" << endl; + Py_RETURN_NONE; + } + self->ss->setId(*( ((BPy_Id *) py_id)->id )); - PyObject *_wrap_SShape_SetId(PyObject *self , PyObject *args) { + Py_RETURN_NONE; } - PyObject *_wrap_SShape_SetMaterials(PyObject *self , PyObject *args) { -} - +// const Material & material (unsigned i) const +// const vector< Material > & materials () const +// void SetMaterials (const vector< Material > &iMaterials) - PyObject *_wrap_SShape_SetViewShape(PyObject *self , PyObject *args) { -} +/////////////////////////////////////////////////////////////////////////////////////////// - PyObject *_wrap_SShape_SetImportance(PyObject *self , PyObject *args) { +#ifdef __cplusplus } - - +#endif
\ No newline at end of file |