From 17555efed7583c12459d4f3044dfdd457489ab39 Mon Sep 17 00:00:00 2001 From: Tamito Kajiyama Date: Mon, 1 Dec 2008 11:14:33 +0000 Subject: Added changes to support Python's native iterator protocol in Stroke and StrokeVertexIterator. freestyle_init.py * Added a generic getName() method that allows subclasses to omit the method to return their class names. BPy_Convert.cpp BPy_Convert.h * Added to BPy_StrokeVertexIterator_from_StrokeVertexIterator() a second argument to specify the direction (reversed or not) of the iterator to be created. BPy_Stroke.cpp * Added support for Python's native iterator protocol. * Added code to parse the optional argument of strokeVerticesBegin(). BPy_StrokeVertexIterator.cpp BPy_StrokeVertexIterator.h * Added support for Python's native iterator protocol. Stroke.cpp * Fixed a null pointer reference. Stroke.h * Added new method Stroke::strokeVerticeAt(i) that returns the i-th StrokeVertex of the Stroke. --- .../python/Iterator/BPy_StrokeVertexIterator.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp') diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp index 1994cb9ce6d..14356970c93 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp @@ -11,6 +11,7 @@ extern "C" { /*--------------- Python API function prototypes for StrokeVertexIterator instance -----------*/ static int StrokeVertexIterator___init__(BPy_StrokeVertexIterator *self, PyObject *args); +static PyObject * StrokeVertexIterator_iternext( PyObject *obj ); static PyObject * StrokeVertexIterator_t( BPy_StrokeVertexIterator *self ); static PyObject * StrokeVertexIterator_u( BPy_StrokeVertexIterator *self ); static PyObject * StrokeVertexIterator_castToInterface0DIterator( BPy_StrokeVertexIterator *self ); @@ -81,8 +82,8 @@ PyTypeObject StrokeVertexIterator_Type = { /*** Added in release 2.2 ***/ /* Iterators */ - NULL, /* getiterfunc tp_iter; */ - NULL, /* iternextfunc tp_iternext; */ + PyObject_SelfIter, /* getiterfunc tp_iter; */ + (iternextfunc)StrokeVertexIterator_iternext, /* iternextfunc tp_iternext; */ /*** Attribute descriptor and subclassing stuff ***/ BPy_StrokeVertexIterator_methods, /* struct PyMethodDef *tp_methods; */ @@ -139,6 +140,23 @@ int StrokeVertexIterator___init__(BPy_StrokeVertexIterator *self, PyObject *args return 0; } +PyObject * StrokeVertexIterator_iternext( PyObject *obj ) { + BPy_StrokeVertexIterator *self = (BPy_StrokeVertexIterator *)obj; + StrokeVertex *sv; + if (self->reversed) { + if (self->sv_it->isBegin()) + return NULL; + self->sv_it->decrement(); + sv = self->sv_it->operator->(); + } else { + if (self->sv_it->isEnd()) + return NULL; + sv = self->sv_it->operator->(); + self->sv_it->increment(); + } + return BPy_StrokeVertex_from_StrokeVertex_ptr( sv ); +} + PyObject * StrokeVertexIterator_t( BPy_StrokeVertexIterator *self ) { return PyFloat_FromDouble( self->sv_it->t() ); } -- cgit v1.2.3