Differential D545 Diff 1919 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
| Show All 19 Lines | |||||
| /** \file source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp | /** \file source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp | ||||
| * \ingroup freestyle | * \ingroup freestyle | ||||
| */ | */ | ||||
| #include "BPy_StrokeVertexIterator.h" | #include "BPy_StrokeVertexIterator.h" | ||||
| #include "../BPy_Convert.h" | #include "../BPy_Convert.h" | ||||
| #include "../Interface1D/BPy_Stroke.h" | |||||
| #include "BPy_Interface0DIterator.h" | #include "BPy_Interface0DIterator.h" | ||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||
| extern "C" { | extern "C" { | ||||
| #endif | #endif | ||||
| /////////////////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////////////////// | ||||
| Show All 22 Lines | |||||
| "\n" | "\n" | ||||
| " Copy constructor.\n" | " Copy constructor.\n" | ||||
| "\n" | "\n" | ||||
| " :arg brother: A StrokeVertexIterator object.\n" | " :arg brother: A StrokeVertexIterator object.\n" | ||||
| " :type brother: :class:`StrokeVertexIterator`"); | " :type brother: :class:`StrokeVertexIterator`"); | ||||
| static int StrokeVertexIterator_init(BPy_StrokeVertexIterator *self, PyObject *args, PyObject *kwds) | static int StrokeVertexIterator_init(BPy_StrokeVertexIterator *self, PyObject *args, PyObject *kwds) | ||||
| { | { | ||||
| static const char *kwlist[] = {"brother", NULL}; | static const char *kwlist_1[] = {"brother", NULL}; | ||||
| PyObject *brother = 0; | static const char *kwlist_2[] = {"stroke", NULL}; | ||||
| PyObject *brother = 0, *stroke = 0; | |||||
kjym3: This first call of `PyErr_Clear()` is unnecessary. | |||||
| if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &StrokeVertexIterator_Type, &brother)) | if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &StrokeVertexIterator_Type, &brother)) { | ||||
| return -1; | self->sv_it = new StrokeInternal::StrokeVertexIterator(*(((BPy_StrokeVertexIterator *)brother)->sv_it)); | ||||
| if (!brother) { | self->reversed = ((BPy_StrokeVertexIterator *)brother)->reversed; | ||||
| self->sv_it = new StrokeInternal::StrokeVertexIterator(); | self->at_start = ((BPy_StrokeVertexIterator *)brother)->at_start; | ||||
| } | |||||
| else if (PyErr_Clear(), | |||||
| PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_2, &Stroke_Type, &stroke)) | |||||
| { | |||||
| self->sv_it = new StrokeInternal::StrokeVertexIterator(((BPy_Stroke *)stroke)->s->strokeVerticesBegin()); | |||||
| self->reversed = false; | self->reversed = false; | ||||
| self->at_start = true; | self->at_start = true; | ||||
| } | } | ||||
| else { | else { | ||||
| self->sv_it = new StrokeInternal::StrokeVertexIterator(*(((BPy_StrokeVertexIterator *)brother)->sv_it)); | self->sv_it = new StrokeInternal::StrokeVertexIterator(); | ||||
| self->reversed = ((BPy_StrokeVertexIterator *)brother)->reversed; | self->reversed = false; | ||||
| self->at_start = ((BPy_StrokeVertexIterator *)brother)->at_start; | self->at_start = true; | ||||
| } | } | ||||
| self->py_it.it = self->sv_it; | self->py_it.it = self->sv_it; | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| static PyObject *StrokeVertexIterator_iter(BPy_StrokeVertexIterator *self) | static PyObject *StrokeVertexIterator_iter(BPy_StrokeVertexIterator *self) | ||||
| { | { | ||||
| Py_INCREF(self); | Py_INCREF(self); | ||||
| self->at_start = true; | self->at_start = true; | ||||
| return (PyObject *) self; | return (PyObject *) self; | ||||
| } | } | ||||
| static PyObject *StrokeVertexIterator_iternext(BPy_StrokeVertexIterator *self) | static PyObject *StrokeVertexIterator_iternext(BPy_StrokeVertexIterator *self) | ||||
| { | { | ||||
| /* Because Freestyle iterators for which it.isEnd() holds true have no valid object | |||||
| * (referencing it.object in this case leads to a crash), we must check if it.object | |||||
| * is valid after incrementing, to prevent crashes in Python. | |||||
| * Additionally, the at_start attribute is used to keep Freestyle iterator objects | |||||
| * and Python for loops in sync. */ | |||||
| 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(); | self->sv_it->decrement(); | ||||
| } | } | ||||
| else { | else { | ||||
| Show All 14 Lines | else { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| StrokeVertex *sv = self->sv_it->operator->(); | StrokeVertex *sv = self->sv_it->operator->(); | ||||
| return BPy_StrokeVertex_from_StrokeVertex(*sv); | return BPy_StrokeVertex_from_StrokeVertex(*sv); | ||||
| } | } | ||||
| /*----------------------StrokeVertexIterator methods ----------------------------*/ | |||||
| static PyObject *StrokeVertexIterator_incremented(BPy_StrokeVertexIterator *self) | |||||
| { | |||||
| if (self->sv_it->isEnd()) { | |||||
| PyErr_SetString(PyExc_RuntimeError, "cannot increment any more"); | |||||
| return NULL; | |||||
| } | |||||
| StrokeInternal::StrokeVertexIterator *copy = new StrokeInternal::StrokeVertexIterator(*self->sv_it); | |||||
| copy->increment(); | |||||
| return BPy_StrokeVertexIterator_from_StrokeVertexIterator(*copy, self->reversed); | |||||
| } | |||||
| static PyObject *StrokeVertexIterator_decremented(BPy_StrokeVertexIterator *self) | |||||
| { | |||||
| if (self->sv_it->isBegin()) { | |||||
| PyErr_SetString(PyExc_RuntimeError, "cannot decrement any more"); | |||||
| return NULL; | |||||
| } | |||||
| StrokeInternal::StrokeVertexIterator *copy = new StrokeInternal::StrokeVertexIterator(*self->sv_it); | |||||
| copy->decrement(); | |||||
| return BPy_StrokeVertexIterator_from_StrokeVertexIterator(*copy, self->reversed); | |||||
| } | |||||
| static PyObject *StrokeVertexIterator_reversed(BPy_StrokeVertexIterator *self) | |||||
| { | |||||
| StrokeInternal::StrokeVertexIterator *copy = new StrokeInternal::StrokeVertexIterator(*self->sv_it); | |||||
| return BPy_StrokeVertexIterator_from_StrokeVertexIterator(*copy, !self->reversed); | |||||
| } | |||||
| static PyMethodDef BPy_StrokeVertexIterator_methods[] = { | |||||
| {"incremented", (PyCFunction) StrokeVertexIterator_incremented, METH_NOARGS, NULL}, | |||||
| {"decremented", (PyCFunction) StrokeVertexIterator_decremented, METH_NOARGS, NULL}, | |||||
| {"reversed", (PyCFunction) StrokeVertexIterator_reversed, METH_NOARGS, NULL}, | |||||
| {NULL, NULL, 0, NULL} | |||||
| }; | |||||
| /*----------------------StrokeVertexIterator get/setters ----------------------------*/ | /*----------------------StrokeVertexIterator get/setters ----------------------------*/ | ||||
| PyDoc_STRVAR(StrokeVertexIterator_object_doc, | PyDoc_STRVAR(StrokeVertexIterator_object_doc, | ||||
| "The StrokeVertex object currently pointed to by this iterator.\n" | "The StrokeVertex object currently pointed to by this iterator.\n" | ||||
| "\n" | "\n" | ||||
| ":type: :class:`StrokeVertex`"); | ":type: :class:`StrokeVertex`"); | ||||
| static PyObject *StrokeVertexIterator_object_get(BPy_StrokeVertexIterator *self, void *UNUSED(closure)) | static PyObject *StrokeVertexIterator_object_get(BPy_StrokeVertexIterator *self, void *UNUSED(closure)) | ||||
| { | { | ||||
| if (!self->reversed && self->sv_it->isEnd()) { | if (self->sv_it->isEnd()) { | ||||
| PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); | PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| StrokeVertex *sv = self->sv_it->operator->(); | StrokeVertex *sv = self->sv_it->operator->(); | ||||
| if (sv) | if (sv) | ||||
| return BPy_StrokeVertex_from_StrokeVertex(*sv); | return BPy_StrokeVertex_from_StrokeVertex(*sv); | ||||
| Py_RETURN_NONE; | Py_RETURN_NONE; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | PyTypeObject StrokeVertexIterator_Type = { | ||||
| Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ | ||||
| StrokeVertexIterator_doc, /* tp_doc */ | StrokeVertexIterator_doc, /* tp_doc */ | ||||
| 0, /* tp_traverse */ | 0, /* tp_traverse */ | ||||
| 0, /* tp_clear */ | 0, /* tp_clear */ | ||||
| 0, /* tp_richcompare */ | 0, /* tp_richcompare */ | ||||
| 0, /* tp_weaklistoffset */ | 0, /* tp_weaklistoffset */ | ||||
| (getiterfunc)StrokeVertexIterator_iter, /* tp_iter */ | (getiterfunc)StrokeVertexIterator_iter, /* tp_iter */ | ||||
| (iternextfunc)StrokeVertexIterator_iternext, /* tp_iternext */ | (iternextfunc)StrokeVertexIterator_iternext, /* tp_iternext */ | ||||
| 0, /* tp_methods */ | BPy_StrokeVertexIterator_methods, /* tp_methods */ | ||||
| 0, /* tp_members */ | 0, /* tp_members */ | ||||
| BPy_StrokeVertexIterator_getseters, /* tp_getset */ | BPy_StrokeVertexIterator_getseters, /* tp_getset */ | ||||
| &Iterator_Type, /* tp_base */ | &Iterator_Type, /* tp_base */ | ||||
| 0, /* tp_dict */ | 0, /* tp_dict */ | ||||
| 0, /* tp_descr_get */ | 0, /* tp_descr_get */ | ||||
| 0, /* tp_descr_set */ | 0, /* tp_descr_set */ | ||||
| 0, /* tp_dictoffset */ | 0, /* tp_dictoffset */ | ||||
| (initproc)StrokeVertexIterator_init, /* tp_init */ | (initproc)StrokeVertexIterator_init, /* tp_init */ | ||||
| Show All 9 Lines | |||||
This first call of PyErr_Clear() is unnecessary.