diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2014-01-31 08:40:24 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2014-02-02 17:05:28 +0400 |
commit | b58beed604f69ff8136d55f91ad75003cc5f575f (patch) | |
tree | f7bff176aecedc317851337bf3488d6a0b019d65 /source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp | |
parent | 41cc86a666d22501f25c58d81b1b94020b8c997f (diff) |
Imported D222 Diff 2 (ID 781) by flokkievids (Folkert de Vries).
Diffstat (limited to 'source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp')
-rw-r--r-- | source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp index 292729782ec..8ff744c4681 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp @@ -74,10 +74,14 @@ static int AdjacencyIterator_init(BPy_AdjacencyIterator *self, PyObject *args, P PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &AdjacencyIterator_Type, &obj1)) { - if (!obj1) + if (!obj1) { self->a_it = new AdjacencyIterator(); - else + self->at_start = true; + } + else { self->a_it = new AdjacencyIterator(*(((BPy_AdjacencyIterator *)obj1)->a_it)); + self->at_start = ((BPy_AdjacencyIterator *)obj1)->at_start; + } } else if (PyErr_Clear(), (obj2 = obj3 = 0), PyArg_ParseTupleAndKeywords(args, kwds, "O!|O!O!", (char **)kwlist_2, @@ -86,6 +90,7 @@ static int AdjacencyIterator_init(BPy_AdjacencyIterator *self, PyObject *args, P bool restrictToSelection = (!obj2) ? true : bool_from_PyBool(obj2); bool restrictToUnvisited = (!obj3) ? true : bool_from_PyBool(obj3); self->a_it = new AdjacencyIterator(((BPy_ViewVertex *)obj1)->vv, restrictToSelection, restrictToUnvisited); + self->at_start = ((BPy_AdjacencyIterator *)obj1)->at_start; } else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); @@ -95,15 +100,31 @@ static int AdjacencyIterator_init(BPy_AdjacencyIterator *self, PyObject *args, P return 0; } +static PyObject *AdjacencyIterator_iter(BPy_AdjacencyIterator *self) +{ + Py_INCREF(self); + self->at_start = true; + return (PyObject *) self; +} + static PyObject *AdjacencyIterator_iternext(BPy_AdjacencyIterator *self) { if (self->a_it->isEnd()) { PyErr_SetNone(PyExc_StopIteration); return NULL; } - ViewEdge *ve = self->a_it->operator*(); - self->a_it->increment(); - return BPy_ViewEdge_from_ViewEdge(*ve); + + if (self->at_start) + self->at_start = false; + else { + self->a_it->increment(); + if (self->a_it->isEnd()){ + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + } + ViewEdge *ve = self->a_it->operator->(); + return BPy_ViewEdge_from_ViewEdge(*ve); } /*----------------------AdjacencyIterator get/setters ----------------------------*/ @@ -175,7 +196,7 @@ PyTypeObject AdjacencyIterator_Type = { 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ - PyObject_SelfIter, /* tp_iter */ + (getiterfunc)AdjacencyIterator_iter, /* tp_iter */ (iternextfunc)AdjacencyIterator_iternext, /* tp_iternext */ 0, /* tp_methods */ 0, /* tp_members */ |