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 | |
parent | 41cc86a666d22501f25c58d81b1b94020b8c997f (diff) |
Imported D222 Diff 2 (ID 781) by flokkievids (Folkert de Vries).
Diffstat (limited to 'source/blender/freestyle/intern/python')
8 files changed, 157 insertions, 48 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 */ diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.h index 3fd1441ba5b..d675cdb7a3e 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.h @@ -45,6 +45,7 @@ extern PyTypeObject AdjacencyIterator_Type; typedef struct { BPy_Iterator py_it; AdjacencyIterator *a_it; + bool at_start; } BPy_AdjacencyIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp index 3a246263efa..e6a01808305 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp @@ -76,41 +76,66 @@ static int Interface0DIterator_init(BPy_Interface0DIterator *self, PyObject *arg if (PyArg_ParseTupleAndKeywords(args, kwds, "O&", (char **)kwlist_1, convert_nested_it, &nested_it)) { self->if0D_it = new Interface0DIterator(nested_it->copy()); + self->at_start = true; + self->reversed = false; } else if (PyErr_Clear(), PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Interface0DIterator_Type, &brother)) { self->if0D_it = new Interface0DIterator(*(((BPy_Interface0DIterator *)brother)->if0D_it)); + self->at_start = ((BPy_Interface0DIterator *)brother)->at_start; + self->reversed = ((BPy_Interface0DIterator *)brother)->reversed; } else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } self->py_it.it = self->if0D_it; - self->reversed = 0; return 0; } -static PyObject *Interface0DIterator_iternext(BPy_Interface0DIterator *self) +static PyObject *Interface0DIterator_iter(BPy_Interface0DIterator *self) { - Interface0D *if0D; + Py_INCREF(self); + self->at_start = true; + return (PyObject *) self; +} +static PyObject *Interface0DIterator_iternext(BPy_Interface0DIterator *self) +{ if (self->reversed) { if (self->if0D_it->isBegin()) { PyErr_SetNone(PyExc_StopIteration); return NULL; } - self->if0D_it->decrement(); - if0D = self->if0D_it->operator->(); + + if (self->at_start) + self->at_start = false; + else { + self->if0D_it->decrement(); + if (self->if0D_it->isBegin()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + } + } else { if (self->if0D_it->isEnd()) { PyErr_SetNone(PyExc_StopIteration); return NULL; } - if0D = self->if0D_it->operator->(); - self->if0D_it->increment(); - } + if (self->at_start) + self->at_start = false; + else { + self->if0D_it->increment(); + if (self->if0D_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + } + } + Interface0D *if0D = self->if0D_it->operator->(); return Any_BPy_Interface0D_from_Interface0D(*if0D); } @@ -186,7 +211,7 @@ PyTypeObject Interface0DIterator_Type = { 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ - PyObject_SelfIter, /* tp_iter */ + (getiterfunc)Interface0DIterator_iter, /* tp_iter */ (iternextfunc)Interface0DIterator_iternext, /* tp_iternext */ 0, /* tp_methods */ 0, /* tp_members */ diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.h index 359e009b5fd..afc21c65ec0 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.h @@ -45,7 +45,8 @@ extern PyTypeObject Interface0DIterator_Type; typedef struct { BPy_Iterator py_it; Interface0DIterator *if0D_it; - int reversed; + bool reversed; + bool at_start; } BPy_Interface0DIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp index 8287e280186..a284ea2a0b5 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp @@ -68,35 +68,68 @@ static int StrokeVertexIterator_init(BPy_StrokeVertexIterator *self, PyObject *a if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &StrokeVertexIterator_Type, &brother)) return -1; - if (!brother) + if (!brother) { self->sv_it = new StrokeInternal::StrokeVertexIterator(); - else + self->reversed = false; + self->at_start = true; + } + else { self->sv_it = new StrokeInternal::StrokeVertexIterator(*(((BPy_StrokeVertexIterator *)brother)->sv_it)); + self->reversed = ((BPy_StrokeVertexIterator *)brother)->reversed; + self->at_start = ((BPy_StrokeVertexIterator *)brother)->at_start; + } self->py_it.it = self->sv_it; - self->reversed = 0; return 0; } +static PyObject *StrokeVertexIterator_iter(BPy_StrokeVertexIterator *self) +{ + Py_INCREF(self); + self->at_start = true; + return (PyObject *) self; +} + static PyObject *StrokeVertexIterator_iternext(BPy_StrokeVertexIterator *self) { StrokeVertex *sv; if (self->reversed) { - if (self->sv_it->isBegin()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - self->sv_it->decrement(); - sv = self->sv_it->operator->(); + if (self->sv_it->isBegin()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + + if (self->at_start) + self->at_start = false; + else { + self->sv_it->increment(); + if (self->sv_it->isBegin()){ + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + } } + else { - if (self->sv_it->isEnd()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - sv = self->sv_it->operator->(); - self->sv_it->increment(); - } + if (self->sv_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + /* if at the start of the iterator, only return the object + * and don't increment, to keep for-loops in sync */ + if (self->at_start) + self->at_start = false; + /* after incrementing, check if the iterator is at its end + * exit the loop if it is. not doing so will result in a crash */ + else { + self->sv_it->increment(); + if (self->sv_it->isEnd()){ + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + } + } + sv = self->sv_it->operator->(); return BPy_StrokeVertex_from_StrokeVertex(*sv); } @@ -174,8 +207,8 @@ PyTypeObject StrokeVertexIterator_Type = { 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - PyObject_SelfIter, /* tp_iter */ + 0, /* tp_weaklistoffset */ + (getiterfunc)StrokeVertexIterator_iter, /* tp_iter */ (iternextfunc)StrokeVertexIterator_iternext, /* tp_iternext */ 0, /* tp_methods */ 0, /* tp_members */ diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.h index f38adb80095..ec1b7d76ae8 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.h @@ -45,7 +45,9 @@ extern PyTypeObject StrokeVertexIterator_Type; typedef struct { BPy_Iterator py_it; StrokeInternal::StrokeVertexIterator *sv_it; - int reversed; + bool reversed; + /* attribute to make next() work correctly */ + bool at_start; } BPy_StrokeVertexIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp index 12ca3d6cc4a..b7cb53b9dd0 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp @@ -60,36 +60,61 @@ static int orientedViewEdgeIterator_init(BPy_orientedViewEdgeIterator *self, PyO if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &orientedViewEdgeIterator_Type, &brother)) return -1; - if (!brother) + if (!brother) { self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(); - else + self->at_start = true; + self->reversed = false; + } + else { self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(*(((BPy_orientedViewEdgeIterator *)brother)->ove_it)); - self->py_it.it = self->ove_it; - self->reversed = 0; + self->at_start = ((BPy_orientedViewEdgeIterator *)brother)->at_start; + self->reversed = ((BPy_orientedViewEdgeIterator *)brother)->reversed; + } + self->py_it.it = self->ove_it; return 0; } -static PyObject *orientedViewEdgeIterator_iternext(BPy_orientedViewEdgeIterator *self) +static PyObject *orientedViewEdgeIterator_iter(BPy_orientedViewEdgeIterator *self) { - ViewVertex::directedViewEdge *dve; + Py_INCREF(self); + self->at_start = true; + return (PyObject *) self; +} +static PyObject *orientedViewEdgeIterator_iternext(BPy_orientedViewEdgeIterator *self) +{ if (self->reversed) { if (self->ove_it->isBegin()) { PyErr_SetNone(PyExc_StopIteration); return NULL; } - self->ove_it->decrement(); - dve = self->ove_it->operator->(); + if (self->at_start) + self->at_start = false; + else { + self->ove_it->decrement(); + if (self->ove_it->isBegin()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + } } else { if (self->ove_it->isEnd()) { PyErr_SetNone(PyExc_StopIteration); return NULL; } - dve = self->ove_it->operator->(); - self->ove_it->increment(); + if (self->at_start) + self->at_start = false; + else { + self->ove_it->increment(); + if (self->ove_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + } } - return BPy_directedViewEdge_from_directedViewEdge(*dve); + ViewVertex::directedViewEdge *dve = self->ove_it->operator->(); + return BPy_directedViewEdge_from_directedViewEdge(*dve); } /*----------------------orientedViewEdgeIterator get/setters ----------------------------*/ @@ -144,7 +169,7 @@ PyTypeObject orientedViewEdgeIterator_Type = { 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ - PyObject_SelfIter, /* tp_iter */ + (getiterfunc)orientedViewEdgeIterator_iter, /* tp_iter */ (iternextfunc)orientedViewEdgeIterator_iternext, /* tp_iternext */ 0, /* tp_methods */ 0, /* tp_members */ diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.h index 57dabfc0308..d95811fc6b6 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.h @@ -47,7 +47,8 @@ extern PyTypeObject orientedViewEdgeIterator_Type; typedef struct { BPy_Iterator py_it; ViewVertexInternal::orientedViewEdgeIterator *ove_it; - int reversed; + bool reversed; + bool at_start; } BPy_orientedViewEdgeIterator; /////////////////////////////////////////////////////////////////////////////////////////// |