Differential D222 Diff 820 source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp
| Context not available. | |||||
| "\n" | "\n" | ||||
| "Class defining an iterator designed to iterate over the\n" | "Class defining an iterator designed to iterate over the\n" | ||||
| ":class:`StrokeVertex` of a :class:`Stroke`. An instance of a\n" | ":class:`StrokeVertex` of a :class:`Stroke`. An instance of a\n" | ||||
| "StrokeVertexIterator can only be obtained from a Stroke by calling\n" | "StrokeVertexIterator can be obtained from a Stroke by calling\n" | ||||
| "strokeVerticesBegin() or strokeVerticesEnd(). It is iterating over\n" | "iter(), stroke_vertices_begin() or stroke_vertices_begin(). It is iterating\n" | ||||
| "the same vertices as an :class:`Interface0DIterator`. The difference\n" | "over the same vertices as an :class:`Interface0DIterator`. The difference\n" | ||||
| "resides in the object access. Indeed, an Interface0DIterator allows\n" | "resides in the object access: an Interface0DIterator only allows\n" | ||||
| "only an access to an Interface0D whereas we could need to access the\n" | "access to an Interface0D while one might need to access the\n" | ||||
| "specialized StrokeVertex type. In this case, one should use a\n" | "specialized StrokeVertex type. In this case, one should use a\n" | ||||
| "StrokeVertexIterator. The castToInterface0DIterator() method is\n" | "StrokeVertexIterator. To call functions of the UnaryFuntion0D type,\n" | ||||
| "useful to get an Interface0DIterator from a StrokeVertexIterator in\n" | "a StrokeVertexIterator can be converted to an Interface0DIterator by\n" | ||||
| "order to call any functions of the UnaryFunction0D type.\n" | "by calling Interface0DIterator(it)." | ||||
| "\n" | "\n" | ||||
| ".. method:: __init__()\n" | ".. method:: __init__()\n" | ||||
| "\n" | "\n" | ||||
| Context not available. | |||||
| if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &StrokeVertexIterator_Type, &brother)) | if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &StrokeVertexIterator_Type, &brother)) | ||||
| return -1; | return -1; | ||||
| if (!brother) | if (!brother) { | ||||
| self->sv_it = new StrokeInternal::StrokeVertexIterator(); | 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->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->py_it.it = self->sv_it; | ||||
| self->reversed = 0; | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| static PyObject *StrokeVertexIterator_iternext(BPy_StrokeVertexIterator *self) | static PyObject *StrokeVertexIterator_iter(BPy_StrokeVertexIterator *self) | ||||
| { | { | ||||
| StrokeVertex *sv; | Py_INCREF(self); | ||||
| self->at_start = true; | |||||
| return (PyObject *) self; | |||||
| } | |||||
| static PyObject *StrokeVertexIterator_iternext(BPy_StrokeVertexIterator *self) | |||||
| { | |||||
| if (self->reversed) { | if (self->reversed) { | ||||
| if (self->sv_it->isBegin()) { | if (self->sv_it->isBegin()) { | ||||
| PyErr_SetNone(PyExc_StopIteration); | PyErr_SetNone(PyExc_StopIteration); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| self->sv_it->decrement(); | if (self->at_start) | ||||
| sv = self->sv_it->operator->(); | self->at_start = false; | ||||
| else { | |||||
| self->sv_it->increment(); | |||||
| if (self->sv_it->isBegin()){ | |||||
| PyErr_SetNone(PyExc_StopIteration); | |||||
| return NULL; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| else { | else { | ||||
| if (self->sv_it->isEnd()) { | if (self->sv_it->isEnd()) { | ||||
| PyErr_SetNone(PyExc_StopIteration); | PyErr_SetNone(PyExc_StopIteration); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| sv = self->sv_it->operator->(); | /* if at the start of the iterator, only return the object | ||||
| self->sv_it->increment(); | * 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; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| StrokeVertex *sv = self->sv_it->operator->(); | |||||
| return BPy_StrokeVertex_from_StrokeVertex(*sv); | return BPy_StrokeVertex_from_StrokeVertex(*sv); | ||||
| } | } | ||||
| /*----------------------StrokeVertexIterator get/setters ----------------------------*/ | /*----------------------StrokeVertexIterator get/setters ----------------------------*/ | ||||
| PyDoc_STRVAR(StrokeVertexIterator_object_doc, | PyDoc_STRVAR(StrokeVertexIterator_object_doc, | ||||
| "The StrokeVertex object currently pointed by this iterator.\n" | "The StrokeVertex object currently pointed to by this iterator.\n" | ||||
| "\n" | "\n" | ||||
| ":type: :class:`StrokeVertex`"); | ":type: :class:`StrokeVertex`"); | ||||
| Context not available. | |||||
| 0, /* tp_clear */ | 0, /* tp_clear */ | ||||
| 0, /* tp_richcompare */ | 0, /* tp_richcompare */ | ||||
| 0, /* tp_weaklistoffset */ | 0, /* tp_weaklistoffset */ | ||||
| PyObject_SelfIter, /* tp_iter */ | (getiterfunc)StrokeVertexIterator_iter, /* tp_iter */ | ||||
| (iternextfunc)StrokeVertexIterator_iternext, /* tp_iternext */ | (iternextfunc)StrokeVertexIterator_iternext, /* tp_iternext */ | ||||
| 0, /* tp_methods */ | 0, /* tp_methods */ | ||||
| 0, /* tp_members */ | 0, /* tp_members */ | ||||
| Context not available. | |||||