diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2008-12-01 14:14:33 +0300 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2008-12-01 14:14:33 +0300 |
commit | 17555efed7583c12459d4f3044dfdd457489ab39 (patch) | |
tree | 3cece3831c7cffc68cd40edf0ffb9afb6ea1773d /source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp | |
parent | a407b65c834486b1ebd534e696460456fa2f210c (diff) |
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.
Diffstat (limited to 'source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp')
-rw-r--r-- | source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
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() ); } |