diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/freestyle/intern/python/Iterator | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/freestyle/intern/python/Iterator')
20 files changed, 1641 insertions, 1453 deletions
diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp index f8bae0e5aca..6b23ffadffb 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.cpp @@ -31,179 +31,198 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- -PyDoc_STRVAR(AdjacencyIterator_doc, -"Class hierarchy: :class:`Iterator` > :class:`AdjacencyIterator`\n" -"\n" -"Class for representing adjacency iterators used in the chaining\n" -"process. An AdjacencyIterator is created in the increment() and\n" -"decrement() methods of a :class:`ChainingIterator` and passed to the\n" -"traverse() method of the ChainingIterator.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: An AdjacencyIterator object.\n" -" :type brother: :class:`AdjacencyIterator`\n" -"\n" -".. method:: __init__(vertex, restrict_to_selection=True, restrict_to_unvisited=True)\n" -"\n" -" Builds a AdjacencyIterator object.\n" -"\n" -" :arg vertex: The vertex which is the next crossing.\n" -" :type vertex: :class:`ViewVertex`\n" -" :arg restrict_to_selection: Indicates whether to force the chaining\n" -" to stay within the set of selected ViewEdges or not.\n" -" :type restrict_to_selection: bool\n" -" :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" -" already been chained must be ignored ot not.\n" -" :type restrict_to_unvisited: bool"); +PyDoc_STRVAR( + AdjacencyIterator_doc, + "Class hierarchy: :class:`Iterator` > :class:`AdjacencyIterator`\n" + "\n" + "Class for representing adjacency iterators used in the chaining\n" + "process. An AdjacencyIterator is created in the increment() and\n" + "decrement() methods of a :class:`ChainingIterator` and passed to the\n" + "traverse() method of the ChainingIterator.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: An AdjacencyIterator object.\n" + " :type brother: :class:`AdjacencyIterator`\n" + "\n" + ".. method:: __init__(vertex, restrict_to_selection=True, restrict_to_unvisited=True)\n" + "\n" + " Builds a AdjacencyIterator object.\n" + "\n" + " :arg vertex: The vertex which is the next crossing.\n" + " :type vertex: :class:`ViewVertex`\n" + " :arg restrict_to_selection: Indicates whether to force the chaining\n" + " to stay within the set of selected ViewEdges or not.\n" + " :type restrict_to_selection: bool\n" + " :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" + " already been chained must be ignored ot not.\n" + " :type restrict_to_unvisited: bool"); static int AdjacencyIterator_init(BPy_AdjacencyIterator *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"vertex", "restrict_to_selection", "restrict_to_unvisited", NULL}; - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &AdjacencyIterator_Type, &obj1)) { - if (!obj1) { - self->a_it = new AdjacencyIterator(); - 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, - &ViewVertex_Type, &obj1, &PyBool_Type, &obj2, &PyBool_Type, &obj3)) - { - 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)"); - return -1; - } - self->py_it.it = self->a_it; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = { + "vertex", "restrict_to_selection", "restrict_to_unvisited", NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist_1, &AdjacencyIterator_Type, &obj1)) { + if (!obj1) { + self->a_it = new AdjacencyIterator(); + 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, + &ViewVertex_Type, + &obj1, + &PyBool_Type, + &obj2, + &PyBool_Type, + &obj3)) { + 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)"); + return -1; + } + self->py_it.it = self->a_it; + return 0; } static PyObject *AdjacencyIterator_iter(BPy_AdjacencyIterator *self) { - Py_INCREF(self); - self->at_start = true; - return (PyObject *) 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; - } - 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); + if (self->a_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + 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 ----------------------------*/ PyDoc_STRVAR(AdjacencyIterator_object_doc, -"The ViewEdge object currently pointed to by this iterator.\n" -"\n" -":type: :class:`ViewEdge`"); + "The ViewEdge object currently pointed to by this iterator.\n" + "\n" + ":type: :class:`ViewEdge`"); static PyObject *AdjacencyIterator_object_get(BPy_AdjacencyIterator *self, void *UNUSED(closure)) { - if (self->a_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - ViewEdge *ve = self->a_it->operator*(); - if (ve) - return BPy_ViewEdge_from_ViewEdge(*ve); - Py_RETURN_NONE; + if (self->a_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + ViewEdge *ve = self->a_it->operator*(); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); + Py_RETURN_NONE; } PyDoc_STRVAR(AdjacencyIterator_is_incoming_doc, -"True if the current ViewEdge is coming towards the iteration vertex, and\n" -"False otherwise.\n" -"\n" -":type: bool"); + "True if the current ViewEdge is coming towards the iteration vertex, and\n" + "False otherwise.\n" + "\n" + ":type: bool"); -static PyObject *AdjacencyIterator_is_incoming_get(BPy_AdjacencyIterator *self, void *UNUSED(closure)) +static PyObject *AdjacencyIterator_is_incoming_get(BPy_AdjacencyIterator *self, + void *UNUSED(closure)) { - if (self->a_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - return PyBool_from_bool(self->a_it->isIncoming()); + if (self->a_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + return PyBool_from_bool(self->a_it->isIncoming()); } static PyGetSetDef BPy_AdjacencyIterator_getseters[] = { - {(char *)"is_incoming", (getter)AdjacencyIterator_is_incoming_get, (setter)NULL, - (char *)AdjacencyIterator_is_incoming_doc, NULL}, - {(char *)"object", (getter)AdjacencyIterator_object_get, (setter)NULL, (char *)AdjacencyIterator_object_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"is_incoming", + (getter)AdjacencyIterator_is_incoming_get, + (setter)NULL, + (char *)AdjacencyIterator_is_incoming_doc, + NULL}, + {(char *)"object", + (getter)AdjacencyIterator_object_get, + (setter)NULL, + (char *)AdjacencyIterator_object_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_AdjacencyIterator type definition ------------------------------*/ PyTypeObject AdjacencyIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "AdjacencyIterator", /* tp_name */ - sizeof(BPy_AdjacencyIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - AdjacencyIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)AdjacencyIterator_iter, /* tp_iter */ - (iternextfunc)AdjacencyIterator_iternext, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_AdjacencyIterator_getseters, /* tp_getset */ - &Iterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)AdjacencyIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "AdjacencyIterator", /* tp_name */ + sizeof(BPy_AdjacencyIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + AdjacencyIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc)AdjacencyIterator_iter, /* tp_iter */ + (iternextfunc)AdjacencyIterator_iternext, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_AdjacencyIterator_getseters, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)AdjacencyIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.h index 775f8a2628d..9a360f23f0a 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.h @@ -33,13 +33,14 @@ extern "C" { extern PyTypeObject AdjacencyIterator_Type; -#define BPy_AdjacencyIterator_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&AdjacencyIterator_Type)) +#define BPy_AdjacencyIterator_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&AdjacencyIterator_Type)) /*---------------------------Python BPy_AdjacencyIterator structure definition----------*/ typedef struct { - BPy_Iterator py_it; - AdjacencyIterator *a_it; - bool at_start; + BPy_Iterator py_it; + AdjacencyIterator *a_it; + bool at_start; } BPy_AdjacencyIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp index 994eb715fe3..f25435b421c 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.cpp @@ -35,152 +35,172 @@ extern "C" { PyDoc_STRVAR(ChainPredicateIterator_doc, -"Class hierarchy: :class:`freestyle.types.Iterator` >\n" -":class:`freestyle.types.ViewEdgeIterator` >\n" -":class:`freestyle.types.ChainingIterator` >\n" -":class:`ChainPredicateIterator`\n" -"\n" -"A \"generic\" user-controlled ViewEdge iterator. This iterator is in\n" -"particular built from a unary predicate and a binary predicate.\n" -"First, the unary predicate is evaluated for all potential next\n" -"ViewEdges in order to only keep the ones respecting a certain\n" -"constraint. Then, the binary predicate is evaluated on the current\n" -"ViewEdge together with each ViewEdge of the previous selection. The\n" -"first ViewEdge respecting both the unary predicate and the binary\n" -"predicate is kept as the next one. If none of the potential next\n" -"ViewEdge respects these two predicates, None is returned.\n" -"\n" -".. method:: __init__(upred, bpred, restrict_to_selection=True, restrict_to_unvisited=True, begin=None, " -"orientation=True)\n" -"\n" -" Builds a ChainPredicateIterator from a unary predicate, a binary\n" -" predicate, a starting ViewEdge and its orientation.\n" -"\n" -" :arg upred: The unary predicate that the next ViewEdge must satisfy.\n" -" :type upred: :class:`freestyle.types.UnaryPredicate1D`\n" -" :arg bpred: The binary predicate that the next ViewEdge must\n" -" satisfy together with the actual pointed ViewEdge.\n" -" :type bpred: :class:`freestyle.types.BinaryPredicate1D`\n" -" :arg restrict_to_selection: Indicates whether to force the chaining\n" -" to stay within the set of selected ViewEdges or not.\n" -" :type restrict_to_selection: bool\n" -" :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" -" already been chained must be ignored ot not.\n" -" :type restrict_to_unvisited: bool\n" -" :arg begin: The ViewEdge from where to start the iteration.\n" -" :type begin: :class:`freestyle.types.ViewEdge` or None\n" -" :arg orientation: If true, we'll look for the next ViewEdge among\n" -" the ViewEdges that surround the ending ViewVertex of begin. If\n" -" false, we'll search over the ViewEdges surrounding the ending\n" -" ViewVertex of begin.\n" -" :type orientation: bool\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A ChainPredicateIterator object.\n" -" :type brother: :class:`ChainPredicateIterator`"); + "Class hierarchy: :class:`freestyle.types.Iterator` >\n" + ":class:`freestyle.types.ViewEdgeIterator` >\n" + ":class:`freestyle.types.ChainingIterator` >\n" + ":class:`ChainPredicateIterator`\n" + "\n" + "A \"generic\" user-controlled ViewEdge iterator. This iterator is in\n" + "particular built from a unary predicate and a binary predicate.\n" + "First, the unary predicate is evaluated for all potential next\n" + "ViewEdges in order to only keep the ones respecting a certain\n" + "constraint. Then, the binary predicate is evaluated on the current\n" + "ViewEdge together with each ViewEdge of the previous selection. The\n" + "first ViewEdge respecting both the unary predicate and the binary\n" + "predicate is kept as the next one. If none of the potential next\n" + "ViewEdge respects these two predicates, None is returned.\n" + "\n" + ".. method:: __init__(upred, bpred, restrict_to_selection=True, " + "restrict_to_unvisited=True, begin=None, " + "orientation=True)\n" + "\n" + " Builds a ChainPredicateIterator from a unary predicate, a binary\n" + " predicate, a starting ViewEdge and its orientation.\n" + "\n" + " :arg upred: The unary predicate that the next ViewEdge must satisfy.\n" + " :type upred: :class:`freestyle.types.UnaryPredicate1D`\n" + " :arg bpred: The binary predicate that the next ViewEdge must\n" + " satisfy together with the actual pointed ViewEdge.\n" + " :type bpred: :class:`freestyle.types.BinaryPredicate1D`\n" + " :arg restrict_to_selection: Indicates whether to force the chaining\n" + " to stay within the set of selected ViewEdges or not.\n" + " :type restrict_to_selection: bool\n" + " :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" + " already been chained must be ignored ot not.\n" + " :type restrict_to_unvisited: bool\n" + " :arg begin: The ViewEdge from where to start the iteration.\n" + " :type begin: :class:`freestyle.types.ViewEdge` or None\n" + " :arg orientation: If true, we'll look for the next ViewEdge among\n" + " the ViewEdges that surround the ending ViewVertex of begin. If\n" + " false, we'll search over the ViewEdges surrounding the ending\n" + " ViewVertex of begin.\n" + " :type orientation: bool\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A ChainPredicateIterator object.\n" + " :type brother: :class:`ChainPredicateIterator`"); static int check_begin(PyObject *obj, void *v) { - if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) - return 0; - *((PyObject **)v) = obj; - return 1; + if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) + return 0; + *((PyObject **)v) = obj; + return 1; } -static int ChainPredicateIterator_init(BPy_ChainPredicateIterator *self, PyObject *args, PyObject *kwds) +static int ChainPredicateIterator_init(BPy_ChainPredicateIterator *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"upred", "bpred", "restrict_to_selection", "restrict_to_unvisited", "begin", - "orientation", NULL}; - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0, *obj5 = 0, *obj6 = 0; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &ChainPredicateIterator_Type, &obj1)) { - self->cp_it = new ChainPredicateIterator(*(((BPy_ChainPredicateIterator *)obj1)->cp_it)); - self->upred = ((BPy_ChainPredicateIterator *)obj1)->upred; - self->bpred = ((BPy_ChainPredicateIterator *)obj1)->bpred; - Py_INCREF(self->upred); - Py_INCREF(self->bpred); - } - else if (PyErr_Clear(), (obj3 = obj4 = obj5 = obj6 = 0), - PyArg_ParseTupleAndKeywords(args, kwds, "O!O!|O!O!O&O!", (char **)kwlist_2, - &UnaryPredicate1D_Type, &obj1, &BinaryPredicate1D_Type, &obj2, - &PyBool_Type, &obj3, &PyBool_Type, &obj4, check_begin, &obj5, - &PyBool_Type, &obj6)) - { - UnaryPredicate1D *up1D = ((BPy_UnaryPredicate1D *)obj1)->up1D; - BinaryPredicate1D *bp1D = ((BPy_BinaryPredicate1D *)obj2)->bp1D; - bool restrict_to_selection = (!obj3) ? true : bool_from_PyBool(obj3); - bool restrict_to_unvisited = (!obj4) ? true : bool_from_PyBool(obj4); - ViewEdge *begin = (!obj5 || obj5 == Py_None) ? NULL : ((BPy_ViewEdge *)obj5)->ve; - bool orientation = (!obj6) ? true : bool_from_PyBool(obj6); - self->cp_it = new ChainPredicateIterator(*up1D, *bp1D, restrict_to_selection, restrict_to_unvisited, begin, - orientation); - self->upred = obj1; - self->bpred = obj2; - Py_INCREF(self->upred); - Py_INCREF(self->bpred); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_c_it.c_it = self->cp_it; - self->py_c_it.py_ve_it.ve_it = self->cp_it; - self->py_c_it.py_ve_it.py_it.it = self->cp_it; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"upred", + "bpred", + "restrict_to_selection", + "restrict_to_unvisited", + "begin", + "orientation", + NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0, *obj5 = 0, *obj6 = 0; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist_1, &ChainPredicateIterator_Type, &obj1)) { + self->cp_it = new ChainPredicateIterator(*(((BPy_ChainPredicateIterator *)obj1)->cp_it)); + self->upred = ((BPy_ChainPredicateIterator *)obj1)->upred; + self->bpred = ((BPy_ChainPredicateIterator *)obj1)->bpred; + Py_INCREF(self->upred); + Py_INCREF(self->bpred); + } + else if (PyErr_Clear(), + (obj3 = obj4 = obj5 = obj6 = 0), + PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!|O!O!O&O!", + (char **)kwlist_2, + &UnaryPredicate1D_Type, + &obj1, + &BinaryPredicate1D_Type, + &obj2, + &PyBool_Type, + &obj3, + &PyBool_Type, + &obj4, + check_begin, + &obj5, + &PyBool_Type, + &obj6)) { + UnaryPredicate1D *up1D = ((BPy_UnaryPredicate1D *)obj1)->up1D; + BinaryPredicate1D *bp1D = ((BPy_BinaryPredicate1D *)obj2)->bp1D; + bool restrict_to_selection = (!obj3) ? true : bool_from_PyBool(obj3); + bool restrict_to_unvisited = (!obj4) ? true : bool_from_PyBool(obj4); + ViewEdge *begin = (!obj5 || obj5 == Py_None) ? NULL : ((BPy_ViewEdge *)obj5)->ve; + bool orientation = (!obj6) ? true : bool_from_PyBool(obj6); + self->cp_it = new ChainPredicateIterator( + *up1D, *bp1D, restrict_to_selection, restrict_to_unvisited, begin, orientation); + self->upred = obj1; + self->bpred = obj2; + Py_INCREF(self->upred); + Py_INCREF(self->bpred); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_c_it.c_it = self->cp_it; + self->py_c_it.py_ve_it.ve_it = self->cp_it; + self->py_c_it.py_ve_it.py_it.it = self->cp_it; + return 0; } static void ChainPredicateIterator_dealloc(BPy_ChainPredicateIterator *self) { - Py_XDECREF(self->upred); - Py_XDECREF(self->bpred); - ChainingIterator_Type.tp_dealloc((PyObject *)self); + Py_XDECREF(self->upred); + Py_XDECREF(self->bpred); + ChainingIterator_Type.tp_dealloc((PyObject *)self); } /*-----------------------BPy_ChainPredicateIterator type definition ------------------------------*/ PyTypeObject ChainPredicateIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ChainPredicateIterator", /* tp_name */ - sizeof(BPy_ChainPredicateIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)ChainPredicateIterator_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ChainPredicateIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &ChainingIterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ChainPredicateIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ChainPredicateIterator", /* tp_name */ + sizeof(BPy_ChainPredicateIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)ChainPredicateIterator_dealloc, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ChainPredicateIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &ChainingIterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ChainPredicateIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.h index 2fab8671239..645e6573257 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainPredicateIterator.h @@ -34,14 +34,14 @@ extern "C" { extern PyTypeObject ChainPredicateIterator_Type; #define BPy_ChainPredicateIterator_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&ChainPredicateIterator_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ChainPredicateIterator_Type)) /*---------------------------Python BPy_ChainPredicateIterator structure definition----------*/ typedef struct { - BPy_ChainingIterator py_c_it; - ChainPredicateIterator *cp_it; - PyObject *upred; - PyObject *bpred; + BPy_ChainingIterator py_c_it; + ChainPredicateIterator *cp_it; + PyObject *upred; + PyObject *bpred; } BPy_ChainPredicateIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp index 73e178a6706..6a4af0f8053 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp @@ -35,118 +35,128 @@ extern "C" { // ChainSilhouetteIterator (const ChainSilhouetteIterator &brother) PyDoc_STRVAR(ChainSilhouetteIterator_doc, -"Class hierarchy: :class:`freestyle.types.Iterator` >\n" -":class:`freestyle.types.ViewEdgeIterator` >\n" -":class:`freestyle.types.ChainingIterator` >\n" -":class:`ChainSilhouetteIterator`\n" -"\n" -"A ViewEdge Iterator used to follow ViewEdges the most naturally. For\n" -"example, it will follow visible ViewEdges of same nature. As soon, as\n" -"the nature or the visibility changes, the iteration stops (by setting\n" -"the pointed ViewEdge to 0). In the case of an iteration over a set of\n" -"ViewEdge that are both Silhouette and Crease, there will be a\n" -"precedence of the silhouette over the crease criterion.\n" -"\n" -".. method:: __init__(restrict_to_selection=True, begin=None, orientation=True)\n" -"\n" -" Builds a ChainSilhouetteIterator from the first ViewEdge used for\n" -" iteration and its orientation.\n" -"\n" -" :arg restrict_to_selection: Indicates whether to force the chaining\n" -" to stay within the set of selected ViewEdges or not.\n" -" :type restrict_to_selection: bool\n" -" :arg begin: The ViewEdge from where to start the iteration.\n" -" :type begin: :class:`freestyle.types.ViewEdge` or None\n" -" :arg orientation: If true, we'll look for the next ViewEdge among\n" -" the ViewEdges that surround the ending ViewVertex of begin. If\n" -" false, we'll search over the ViewEdges surrounding the ending\n" -" ViewVertex of begin.\n" -" :type orientation: bool\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A ChainSilhouetteIterator object.\n" -" :type brother: :class:`ChainSilhouetteIterator`"); + "Class hierarchy: :class:`freestyle.types.Iterator` >\n" + ":class:`freestyle.types.ViewEdgeIterator` >\n" + ":class:`freestyle.types.ChainingIterator` >\n" + ":class:`ChainSilhouetteIterator`\n" + "\n" + "A ViewEdge Iterator used to follow ViewEdges the most naturally. For\n" + "example, it will follow visible ViewEdges of same nature. As soon, as\n" + "the nature or the visibility changes, the iteration stops (by setting\n" + "the pointed ViewEdge to 0). In the case of an iteration over a set of\n" + "ViewEdge that are both Silhouette and Crease, there will be a\n" + "precedence of the silhouette over the crease criterion.\n" + "\n" + ".. method:: __init__(restrict_to_selection=True, begin=None, orientation=True)\n" + "\n" + " Builds a ChainSilhouetteIterator from the first ViewEdge used for\n" + " iteration and its orientation.\n" + "\n" + " :arg restrict_to_selection: Indicates whether to force the chaining\n" + " to stay within the set of selected ViewEdges or not.\n" + " :type restrict_to_selection: bool\n" + " :arg begin: The ViewEdge from where to start the iteration.\n" + " :type begin: :class:`freestyle.types.ViewEdge` or None\n" + " :arg orientation: If true, we'll look for the next ViewEdge among\n" + " the ViewEdges that surround the ending ViewVertex of begin. If\n" + " false, we'll search over the ViewEdges surrounding the ending\n" + " ViewVertex of begin.\n" + " :type orientation: bool\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A ChainSilhouetteIterator object.\n" + " :type brother: :class:`ChainSilhouetteIterator`"); static int check_begin(PyObject *obj, void *v) { - if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) - return 0; - *((PyObject **)v) = obj; - return 1; + if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) + return 0; + *((PyObject **)v) = obj; + return 1; } -static int ChainSilhouetteIterator_init(BPy_ChainSilhouetteIterator *self, PyObject *args, PyObject *kwds) +static int ChainSilhouetteIterator_init(BPy_ChainSilhouetteIterator *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"restrict_to_selection", "begin", "orientation", NULL}; - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"restrict_to_selection", "begin", "orientation", NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &ChainSilhouetteIterator_Type, &obj1)) { - self->cs_it = new ChainSilhouetteIterator(*(((BPy_ChainSilhouetteIterator *)obj1)->cs_it)); - } - else if (PyErr_Clear(), (obj1 = obj2 = obj3 = 0), - PyArg_ParseTupleAndKeywords(args, kwds, "|O!O&O!", (char **)kwlist_2, - &PyBool_Type, &obj1, check_begin, &obj2, &PyBool_Type, &obj3)) - { - bool restrict_to_selection = (!obj1) ? true : bool_from_PyBool(obj1); - ViewEdge *begin = (!obj2 || obj2 == Py_None) ? NULL : ((BPy_ViewEdge *)obj2)->ve; - bool orientation = (!obj3) ? true : bool_from_PyBool(obj3); - self->cs_it = new ChainSilhouetteIterator(restrict_to_selection, begin, orientation); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_c_it.c_it = self->cs_it; - self->py_c_it.py_ve_it.ve_it = self->cs_it; - self->py_c_it.py_ve_it.py_it.it = self->cs_it; - return 0; + if (PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist_1, &ChainSilhouetteIterator_Type, &obj1)) { + self->cs_it = new ChainSilhouetteIterator(*(((BPy_ChainSilhouetteIterator *)obj1)->cs_it)); + } + else if (PyErr_Clear(), + (obj1 = obj2 = obj3 = 0), + PyArg_ParseTupleAndKeywords(args, + kwds, + "|O!O&O!", + (char **)kwlist_2, + &PyBool_Type, + &obj1, + check_begin, + &obj2, + &PyBool_Type, + &obj3)) { + bool restrict_to_selection = (!obj1) ? true : bool_from_PyBool(obj1); + ViewEdge *begin = (!obj2 || obj2 == Py_None) ? NULL : ((BPy_ViewEdge *)obj2)->ve; + bool orientation = (!obj3) ? true : bool_from_PyBool(obj3); + self->cs_it = new ChainSilhouetteIterator(restrict_to_selection, begin, orientation); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_c_it.c_it = self->cs_it; + self->py_c_it.py_ve_it.ve_it = self->cs_it; + self->py_c_it.py_ve_it.py_it.it = self->cs_it; + return 0; } /*-----------------------BPy_ChainSilhouetteIterator type definition ------------------------------*/ PyTypeObject ChainSilhouetteIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ChainSilhouetteIterator", /* tp_name */ - sizeof(BPy_ChainSilhouetteIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ChainSilhouetteIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - &ChainingIterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ChainSilhouetteIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ChainSilhouetteIterator", /* tp_name */ + sizeof(BPy_ChainSilhouetteIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ChainSilhouetteIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + &ChainingIterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ChainSilhouetteIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.h index 7c5974ec218..72823832441 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.h @@ -34,12 +34,12 @@ extern "C" { extern PyTypeObject ChainSilhouetteIterator_Type; #define BPy_ChainSilhouetteIterator_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&ChainSilhouetteIterator_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ChainSilhouetteIterator_Type)) /*---------------------------Python BPy_ChainSilhouetteIterator structure definition----------*/ typedef struct { - BPy_ChainingIterator py_c_it; - ChainSilhouetteIterator *cs_it; + BPy_ChainingIterator py_c_it; + ChainSilhouetteIterator *cs_it; } BPy_ChainSilhouetteIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp index afd7f6f69c6..370ef23d8ef 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp @@ -33,229 +33,260 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- -PyDoc_STRVAR(ChainingIterator_doc, -"Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator` > :class:`ChainingIterator`\n" -"\n" -"Base class for chaining iterators. This class is designed to be\n" -"overloaded in order to describe chaining rules. It makes the\n" -"description of chaining rules easier. The two main methods that need\n" -"to overloaded are traverse() and init(). traverse() tells which\n" -":class:`ViewEdge` to follow, among the adjacent ones. If you specify\n" -"restriction rules (such as \"Chain only ViewEdges of the selection\"),\n" -"they will be included in the adjacency iterator (i.e, the adjacent\n" -"iterator will only stop on \"valid\" edges).\n" -"\n" -".. method:: __init__(restrict_to_selection=True, restrict_to_unvisited=True, begin=None, orientation=True)\n" -"\n" -" Builds a Chaining Iterator from the first ViewEdge used for\n" -" iteration and its orientation.\n" -"\n" -" :arg restrict_to_selection: Indicates whether to force the chaining\n" -" to stay within the set of selected ViewEdges or not.\n" -" :type restrict_to_selection: bool\n" -" :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" -" already been chained must be ignored ot not.\n" -" :type restrict_to_unvisited: bool\n" -" :arg begin: The ViewEdge from which to start the chain.\n" -" :type begin: :class:`ViewEdge` or None\n" -" :arg orientation: The direction to follow to explore the graph. If\n" -" true, the direction indicated by the first ViewEdge is used.\n" -" :type orientation: bool\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: \n" -" :type brother: ChainingIterator"); +PyDoc_STRVAR( + ChainingIterator_doc, + "Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator` > :class:`ChainingIterator`\n" + "\n" + "Base class for chaining iterators. This class is designed to be\n" + "overloaded in order to describe chaining rules. It makes the\n" + "description of chaining rules easier. The two main methods that need\n" + "to overloaded are traverse() and init(). traverse() tells which\n" + ":class:`ViewEdge` to follow, among the adjacent ones. If you specify\n" + "restriction rules (such as \"Chain only ViewEdges of the selection\"),\n" + "they will be included in the adjacency iterator (i.e, the adjacent\n" + "iterator will only stop on \"valid\" edges).\n" + "\n" + ".. method:: __init__(restrict_to_selection=True, restrict_to_unvisited=True, begin=None, " + "orientation=True)\n" + "\n" + " Builds a Chaining Iterator from the first ViewEdge used for\n" + " iteration and its orientation.\n" + "\n" + " :arg restrict_to_selection: Indicates whether to force the chaining\n" + " to stay within the set of selected ViewEdges or not.\n" + " :type restrict_to_selection: bool\n" + " :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" + " already been chained must be ignored ot not.\n" + " :type restrict_to_unvisited: bool\n" + " :arg begin: The ViewEdge from which to start the chain.\n" + " :type begin: :class:`ViewEdge` or None\n" + " :arg orientation: The direction to follow to explore the graph. If\n" + " true, the direction indicated by the first ViewEdge is used.\n" + " :type orientation: bool\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: \n" + " :type brother: ChainingIterator"); static int check_begin(PyObject *obj, void *v) { - if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) - return 0; - *((PyObject **)v) = obj; - return 1; + if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) + return 0; + *((PyObject **)v) = obj; + return 1; } static int ChainingIterator___init__(BPy_ChainingIterator *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"restrict_to_selection", "restrict_to_unvisited", "begin", "orientation", NULL}; - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &ChainingIterator_Type, &obj1)) { - self->c_it = new ChainingIterator(*(((BPy_ChainingIterator *)obj1)->c_it)); - } - else if (PyErr_Clear(), (obj1 = obj2 = obj3 = obj4 = 0), - PyArg_ParseTupleAndKeywords(args, kwds, "|O!O!O&O!", (char **)kwlist_2, - &PyBool_Type, &obj1, &PyBool_Type, &obj2, check_begin, &obj3, - &PyBool_Type, &obj4)) - { - bool restrict_to_selection = (!obj1) ? true : bool_from_PyBool(obj1); - bool restrict_to_unvisited = (!obj2) ? true : bool_from_PyBool(obj2); - ViewEdge *begin = (!obj3 || obj3 == Py_None) ? NULL : ((BPy_ViewEdge *)obj3)->ve; - bool orientation = (!obj4) ? true : bool_from_PyBool(obj4); - self->c_it = new ChainingIterator(restrict_to_selection, restrict_to_unvisited, begin, orientation); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_ve_it.ve_it = self->c_it; - self->py_ve_it.py_it.it = self->c_it; - - self->c_it->py_c_it = (PyObject *)self; - - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = { + "restrict_to_selection", "restrict_to_unvisited", "begin", "orientation", NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist_1, &ChainingIterator_Type, &obj1)) { + self->c_it = new ChainingIterator(*(((BPy_ChainingIterator *)obj1)->c_it)); + } + else if (PyErr_Clear(), + (obj1 = obj2 = obj3 = obj4 = 0), + PyArg_ParseTupleAndKeywords(args, + kwds, + "|O!O!O&O!", + (char **)kwlist_2, + &PyBool_Type, + &obj1, + &PyBool_Type, + &obj2, + check_begin, + &obj3, + &PyBool_Type, + &obj4)) { + bool restrict_to_selection = (!obj1) ? true : bool_from_PyBool(obj1); + bool restrict_to_unvisited = (!obj2) ? true : bool_from_PyBool(obj2); + ViewEdge *begin = (!obj3 || obj3 == Py_None) ? NULL : ((BPy_ViewEdge *)obj3)->ve; + bool orientation = (!obj4) ? true : bool_from_PyBool(obj4); + self->c_it = new ChainingIterator( + restrict_to_selection, restrict_to_unvisited, begin, orientation); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_ve_it.ve_it = self->c_it; + self->py_ve_it.py_it.it = self->c_it; + + self->c_it->py_c_it = (PyObject *)self; + + return 0; } PyDoc_STRVAR(ChainingIterator_init_doc, -".. method:: init()\n" -"\n" -" Initializes the iterator context. This method is called each\n" -" time a new chain is started. It can be used to reset some\n" -" history information that you might want to keep."); + ".. method:: init()\n" + "\n" + " Initializes the iterator context. This method is called each\n" + " time a new chain is started. It can be used to reset some\n" + " history information that you might want to keep."); static PyObject *ChainingIterator_init(BPy_ChainingIterator *self) { - if (typeid(*(self->c_it)) == typeid(ChainingIterator)) { - PyErr_SetString(PyExc_TypeError, "init() method not properly overridden"); - return NULL; - } - self->c_it->init(); - Py_RETURN_NONE; + if (typeid(*(self->c_it)) == typeid(ChainingIterator)) { + PyErr_SetString(PyExc_TypeError, "init() method not properly overridden"); + return NULL; + } + self->c_it->init(); + Py_RETURN_NONE; } PyDoc_STRVAR(ChainingIterator_traverse_doc, -".. method:: traverse(it)\n" -"\n" -" This method iterates over the potential next ViewEdges and returns\n" -" the one that will be followed next. Returns the next ViewEdge to\n" -" follow or None when the end of the chain is reached.\n" -"\n" -" :arg it: The iterator over the ViewEdges adjacent to the end vertex\n" -" of the current ViewEdge. The adjacency iterator reflects the\n" -" restriction rules by only iterating over the valid ViewEdges.\n" -" :type it: :class:`AdjacencyIterator`\n" -" :return: Returns the next ViewEdge to follow, or None if chaining ends.\n" -" :rtype: :class:`ViewEdge` or None"); - -static PyObject *ChainingIterator_traverse(BPy_ChainingIterator *self, PyObject *args, PyObject *kwds) + ".. method:: traverse(it)\n" + "\n" + " This method iterates over the potential next ViewEdges and returns\n" + " the one that will be followed next. Returns the next ViewEdge to\n" + " follow or None when the end of the chain is reached.\n" + "\n" + " :arg it: The iterator over the ViewEdges adjacent to the end vertex\n" + " of the current ViewEdge. The adjacency iterator reflects the\n" + " restriction rules by only iterating over the valid ViewEdges.\n" + " :type it: :class:`AdjacencyIterator`\n" + " :return: Returns the next ViewEdge to follow, or None if chaining ends.\n" + " :rtype: :class:`ViewEdge` or None"); + +static PyObject *ChainingIterator_traverse(BPy_ChainingIterator *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"it", NULL}; - PyObject *py_a_it; - - if (typeid(*(self->c_it)) == typeid(ChainingIterator)) { - PyErr_SetString(PyExc_TypeError, "traverse() method not properly overridden"); - return NULL; - } - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &AdjacencyIterator_Type, &py_a_it)) - return NULL; - if (((BPy_AdjacencyIterator *)py_a_it)->a_it) - self->c_it->traverse(*(((BPy_AdjacencyIterator *)py_a_it)->a_it)); - Py_RETURN_NONE; + static const char *kwlist[] = {"it", NULL}; + PyObject *py_a_it; + + if (typeid(*(self->c_it)) == typeid(ChainingIterator)) { + PyErr_SetString(PyExc_TypeError, "traverse() method not properly overridden"); + return NULL; + } + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist, &AdjacencyIterator_Type, &py_a_it)) + return NULL; + if (((BPy_AdjacencyIterator *)py_a_it)->a_it) + self->c_it->traverse(*(((BPy_AdjacencyIterator *)py_a_it)->a_it)); + Py_RETURN_NONE; } static PyMethodDef BPy_ChainingIterator_methods[] = { - {"init", (PyCFunction) ChainingIterator_init, METH_NOARGS, ChainingIterator_init_doc}, - {"traverse", (PyCFunction) ChainingIterator_traverse, METH_VARARGS | METH_KEYWORDS, ChainingIterator_traverse_doc}, - {NULL, NULL, 0, NULL}, + {"init", (PyCFunction)ChainingIterator_init, METH_NOARGS, ChainingIterator_init_doc}, + {"traverse", + (PyCFunction)ChainingIterator_traverse, + METH_VARARGS | METH_KEYWORDS, + ChainingIterator_traverse_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------ChainingIterator get/setters ----------------------------*/ PyDoc_STRVAR(ChainingIterator_object_doc, -"The ViewEdge object currently pointed by this iterator.\n" -"\n" -":type: :class:`ViewEdge`"); + "The ViewEdge object currently pointed by this iterator.\n" + "\n" + ":type: :class:`ViewEdge`"); static PyObject *ChainingIterator_object_get(BPy_ChainingIterator *self, void *UNUSED(closure)) { - if (self->c_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - ViewEdge *ve = self->c_it->operator*(); - if (ve) - return BPy_ViewEdge_from_ViewEdge(*ve); - - Py_RETURN_NONE; + if (self->c_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + ViewEdge *ve = self->c_it->operator*(); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); + + Py_RETURN_NONE; } PyDoc_STRVAR(ChainingIterator_next_vertex_doc, -"The ViewVertex that is the next crossing.\n" -"\n" -":type: :class:`ViewVertex`"); + "The ViewVertex that is the next crossing.\n" + "\n" + ":type: :class:`ViewVertex`"); -static PyObject *ChainingIterator_next_vertex_get(BPy_ChainingIterator *self, void *UNUSED(closure)) +static PyObject *ChainingIterator_next_vertex_get(BPy_ChainingIterator *self, + void *UNUSED(closure)) { - ViewVertex *v = self->c_it->getVertex(); - if (v) - return Any_BPy_ViewVertex_from_ViewVertex(*v); + ViewVertex *v = self->c_it->getVertex(); + if (v) + return Any_BPy_ViewVertex_from_ViewVertex(*v); - Py_RETURN_NONE; + Py_RETURN_NONE; } PyDoc_STRVAR(ChainingIterator_is_incrementing_doc, -"True if the current iteration is an incrementation.\n" -"\n" -":type: bool"); + "True if the current iteration is an incrementation.\n" + "\n" + ":type: bool"); -static PyObject *ChainingIterator_is_incrementing_get(BPy_ChainingIterator *self, void *UNUSED(closure)) +static PyObject *ChainingIterator_is_incrementing_get(BPy_ChainingIterator *self, + void *UNUSED(closure)) { - return PyBool_from_bool(self->c_it->isIncrementing()); + return PyBool_from_bool(self->c_it->isIncrementing()); } static PyGetSetDef BPy_ChainingIterator_getseters[] = { - {(char *)"object", (getter)ChainingIterator_object_get, (setter)NULL, (char *)ChainingIterator_object_doc, NULL}, - {(char *)"next_vertex", (getter)ChainingIterator_next_vertex_get, (setter)NULL, - (char *)ChainingIterator_next_vertex_doc, NULL}, - {(char *)"is_incrementing", (getter)ChainingIterator_is_incrementing_get, (setter)NULL, - (char *)ChainingIterator_is_incrementing_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"object", + (getter)ChainingIterator_object_get, + (setter)NULL, + (char *)ChainingIterator_object_doc, + NULL}, + {(char *)"next_vertex", + (getter)ChainingIterator_next_vertex_get, + (setter)NULL, + (char *)ChainingIterator_next_vertex_doc, + NULL}, + {(char *)"is_incrementing", + (getter)ChainingIterator_is_incrementing_get, + (setter)NULL, + (char *)ChainingIterator_is_incrementing_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_ChainingIterator type definition ------------------------------*/ PyTypeObject ChainingIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ChainingIterator", /* tp_name */ - sizeof(BPy_ChainingIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ChainingIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_ChainingIterator_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_ChainingIterator_getseters, /* tp_getset */ - &ViewEdgeIterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ChainingIterator___init__, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ChainingIterator", /* tp_name */ + sizeof(BPy_ChainingIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ChainingIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_ChainingIterator_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_ChainingIterator_getseters, /* tp_getset */ + &ViewEdgeIterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ChainingIterator___init__, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.h index 898662c4f09..7e3be0bc6cd 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.h @@ -33,12 +33,13 @@ extern "C" { extern PyTypeObject ChainingIterator_Type; -#define BPy_ChainingIterator_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&ChainingIterator_Type)) +#define BPy_ChainingIterator_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ChainingIterator_Type)) /*---------------------------Python BPy_ChainingIterator structure definition----------*/ typedef struct { - BPy_ViewEdgeIterator py_ve_it; - ChainingIterator *c_it; + BPy_ViewEdgeIterator py_ve_it; + ChainingIterator *c_it; } BPy_ChainingIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp index 1caf0e9eb58..5b287433c13 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp @@ -32,143 +32,153 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(CurvePointIterator_doc, -"Class hierarchy: :class:`Iterator` > :class:`CurvePointIterator`\n" -"\n" -"Class representing an iterator on a curve. Allows an iterating\n" -"outside initial vertices. A CurvePoint is instanciated and returned\n" -"through the .object attribute.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A CurvePointIterator object.\n" -" :type brother: :class:`CurvePointIterator`\n" -"\n" -".. method:: __init__(step=0.0)\n" -"\n" -" Builds a CurvePointIterator object.\n" -"\n" -" :arg step: A resampling resolution with which the curve is resampled.\n" -" If zero, no resampling is done (i.e., the iterator iterates over\n" -" initial vertices).\n" -" :type step: float"); + "Class hierarchy: :class:`Iterator` > :class:`CurvePointIterator`\n" + "\n" + "Class representing an iterator on a curve. Allows an iterating\n" + "outside initial vertices. A CurvePoint is instanciated and returned\n" + "through the .object attribute.\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A CurvePointIterator object.\n" + " :type brother: :class:`CurvePointIterator`\n" + "\n" + ".. method:: __init__(step=0.0)\n" + "\n" + " Builds a CurvePointIterator object.\n" + "\n" + " :arg step: A resampling resolution with which the curve is resampled.\n" + " If zero, no resampling is done (i.e., the iterator iterates over\n" + " initial vertices).\n" + " :type step: float"); static int CurvePointIterator_init(BPy_CurvePointIterator *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"step", NULL}; - PyObject *brother = 0; - float step; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &CurvePointIterator_Type, &brother)) { - if (!brother) - self->cp_it = new CurveInternal::CurvePointIterator(); - else - self->cp_it = new CurveInternal::CurvePointIterator(*(((BPy_CurvePointIterator *)brother)->cp_it)); - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist_2, &step)) - { - self->cp_it = new CurveInternal::CurvePointIterator(step); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_it.it = self->cp_it; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"step", NULL}; + PyObject *brother = 0; + float step; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist_1, &CurvePointIterator_Type, &brother)) { + if (!brother) + self->cp_it = new CurveInternal::CurvePointIterator(); + else + self->cp_it = new CurveInternal::CurvePointIterator( + *(((BPy_CurvePointIterator *)brother)->cp_it)); + } + else if (PyErr_Clear(), PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist_2, &step)) { + self->cp_it = new CurveInternal::CurvePointIterator(step); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_it.it = self->cp_it; + return 0; } /*----------------------CurvePointIterator get/setters ----------------------------*/ PyDoc_STRVAR(CurvePointIterator_object_doc, -"The CurvePoint object currently pointed by this iterator.\n" -"\n" -":type: :class:`CurvePoint`"); + "The CurvePoint object currently pointed by this iterator.\n" + "\n" + ":type: :class:`CurvePoint`"); static PyObject *CurvePointIterator_object_get(BPy_CurvePointIterator *self, void *UNUSED(closure)) { - if (self->cp_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - return BPy_CurvePoint_from_CurvePoint(self->cp_it->operator*()); + if (self->cp_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + return BPy_CurvePoint_from_CurvePoint(self->cp_it->operator*()); } PyDoc_STRVAR(CurvePointIterator_t_doc, -"The curvilinear abscissa of the current point.\n" -"\n" -":type: float"); + "The curvilinear abscissa of the current point.\n" + "\n" + ":type: float"); static PyObject *CurvePointIterator_t_get(BPy_CurvePointIterator *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->cp_it->t()); + return PyFloat_FromDouble(self->cp_it->t()); } PyDoc_STRVAR(CurvePointIterator_u_doc, -"The point parameter at the current point in the stroke (0 <= u <= 1).\n" -"\n" -":type: float"); + "The point parameter at the current point in the stroke (0 <= u <= 1).\n" + "\n" + ":type: float"); static PyObject *CurvePointIterator_u_get(BPy_CurvePointIterator *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->cp_it->u()); + return PyFloat_FromDouble(self->cp_it->u()); } static PyGetSetDef BPy_CurvePointIterator_getseters[] = { - {(char *)"object", (getter)CurvePointIterator_object_get, (setter)NULL, - (char *)CurvePointIterator_object_doc, NULL}, - {(char *)"t", (getter)CurvePointIterator_t_get, (setter)NULL, (char *)CurvePointIterator_t_doc, NULL}, - {(char *)"u", (getter)CurvePointIterator_u_get, (setter)NULL, (char *)CurvePointIterator_u_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"object", + (getter)CurvePointIterator_object_get, + (setter)NULL, + (char *)CurvePointIterator_object_doc, + NULL}, + {(char *)"t", + (getter)CurvePointIterator_t_get, + (setter)NULL, + (char *)CurvePointIterator_t_doc, + NULL}, + {(char *)"u", + (getter)CurvePointIterator_u_get, + (setter)NULL, + (char *)CurvePointIterator_u_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_CurvePointIterator type definition ------------------------------*/ PyTypeObject CurvePointIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "CurvePointIterator", /* tp_name */ - sizeof(BPy_CurvePointIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - CurvePointIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_CurvePointIterator_getseters, /* tp_getset */ - &Iterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)CurvePointIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "CurvePointIterator", /* tp_name */ + sizeof(BPy_CurvePointIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + CurvePointIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_CurvePointIterator_getseters, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)CurvePointIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.h index 41a3007d12c..aa84b1020ce 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.h @@ -33,12 +33,13 @@ extern "C" { extern PyTypeObject CurvePointIterator_Type; -#define BPy_CurvePointIterator_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&CurvePointIterator_Type)) +#define BPy_CurvePointIterator_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&CurvePointIterator_Type)) /*---------------------------Python BPy_CurvePointIterator structure definition----------*/ typedef struct { - BPy_Iterator py_it; - CurveInternal::CurvePointIterator *cp_it; + BPy_Iterator py_it; + CurveInternal::CurvePointIterator *cp_it; } BPy_CurvePointIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp index 6e3606c0041..6218541df9b 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp @@ -32,210 +32,227 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(Interface0DIterator_doc, -"Class hierarchy: :class:`Iterator` > :class:`Interface0DIterator`\n" -"\n" -"Class defining an iterator over Interface0D elements. An instance of\n" -"this iterator is always obtained from a 1D element.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: An Interface0DIterator object.\n" -" :type brother: :class:`Interface0DIterator`\n" -"\n" -".. method:: __init__(it)\n" -"\n" -" Construct a nested Interface0DIterator that can be the argument of\n" -" a Function0D.\n" -"\n" -" :arg it: An iterator object to be nested.\n" -" :type it: :class:`SVertexIterator`, :class:`CurvePointIterator`, or\n" -" :class:`StrokeVertexIterator`"); + "Class hierarchy: :class:`Iterator` > :class:`Interface0DIterator`\n" + "\n" + "Class defining an iterator over Interface0D elements. An instance of\n" + "this iterator is always obtained from a 1D element.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: An Interface0DIterator object.\n" + " :type brother: :class:`Interface0DIterator`\n" + "\n" + ".. method:: __init__(it)\n" + "\n" + " Construct a nested Interface0DIterator that can be the argument of\n" + " a Function0D.\n" + "\n" + " :arg it: An iterator object to be nested.\n" + " :type it: :class:`SVertexIterator`, :class:`CurvePointIterator`, or\n" + " :class:`StrokeVertexIterator`"); static int convert_nested_it(PyObject *obj, void *v) { - if (!obj || !BPy_Iterator_Check(obj)) - return 0; - Interface0DIteratorNested *nested_it = dynamic_cast<Interface0DIteratorNested *>(((BPy_Iterator *)obj)->it); - if (!nested_it) - return 0; - *((Interface0DIteratorNested **)v) = nested_it; - return 1; + if (!obj || !BPy_Iterator_Check(obj)) + return 0; + Interface0DIteratorNested *nested_it = dynamic_cast<Interface0DIteratorNested *>( + ((BPy_Iterator *)obj)->it); + if (!nested_it) + return 0; + *((Interface0DIteratorNested **)v) = nested_it; + return 1; } static int Interface0DIterator_init(BPy_Interface0DIterator *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"it", NULL}; - static const char *kwlist_2[] = {"inter", NULL}; - static const char *kwlist_3[] = {"brother", NULL}; - Interface0DIteratorNested *nested_it; - PyObject *brother, *inter; - - 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, &Interface1D_Type, &inter)) - { - self->if0D_it = new Interface0DIterator(((BPy_Interface1D *)inter)->if1D->verticesBegin()); - self->at_start = true; - self->reversed = false; - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_3, &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; - return 0; + static const char *kwlist_1[] = {"it", NULL}; + static const char *kwlist_2[] = {"inter", NULL}; + static const char *kwlist_3[] = {"brother", NULL}; + Interface0DIteratorNested *nested_it; + PyObject *brother, *inter; + + 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, &Interface1D_Type, &inter)) { + self->if0D_it = new Interface0DIterator(((BPy_Interface1D *)inter)->if1D->verticesBegin()); + self->at_start = true; + self->reversed = false; + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist_3, &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; + return 0; } static PyObject *Interface0DIterator_iter(BPy_Interface0DIterator *self) { - Py_INCREF(self); - self->at_start = true; - return (PyObject *) self; + 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(); - } - else { - if (self->if0D_it->isEnd()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - else if (self->at_start) { - self->at_start = false; - } - else if (self->if0D_it->atLast()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - else { - self->if0D_it->increment(); - } - } - Interface0D *if0D = self->if0D_it->operator->(); - return Any_BPy_Interface0D_from_Interface0D(*if0D); + if (self->reversed) { + if (self->if0D_it->isBegin()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + self->if0D_it->decrement(); + } + else { + if (self->if0D_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + else if (self->at_start) { + self->at_start = false; + } + else if (self->if0D_it->atLast()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + else { + self->if0D_it->increment(); + } + } + Interface0D *if0D = self->if0D_it->operator->(); + return Any_BPy_Interface0D_from_Interface0D(*if0D); } /*----------------------Interface0DIterator get/setters ----------------------------*/ PyDoc_STRVAR(Interface0DIterator_object_doc, -"The 0D object currently pointed to by this iterator. Note that the object\n" -"may be an instance of an Interface0D subclass. For example if the iterator\n" -"has been created from the `vertices_begin()` method of the :class:`Stroke`\n" -"class, the .object property refers to a :class:`StrokeVertex` object.\n" -"\n" -":type: :class:`Interface0D` or one of its subclasses."); - -static PyObject *Interface0DIterator_object_get(BPy_Interface0DIterator *self, void *UNUSED(closure)) + "The 0D object currently pointed to by this iterator. Note that the object\n" + "may be an instance of an Interface0D subclass. For example if the iterator\n" + "has been created from the `vertices_begin()` method of the :class:`Stroke`\n" + "class, the .object property refers to a :class:`StrokeVertex` object.\n" + "\n" + ":type: :class:`Interface0D` or one of its subclasses."); + +static PyObject *Interface0DIterator_object_get(BPy_Interface0DIterator *self, + void *UNUSED(closure)) { - if (self->if0D_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - return Any_BPy_Interface0D_from_Interface0D(self->if0D_it->operator*()); + if (self->if0D_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + return Any_BPy_Interface0D_from_Interface0D(self->if0D_it->operator*()); } PyDoc_STRVAR(Interface0DIterator_t_doc, -"The curvilinear abscissa of the current point.\n" -"\n" -":type: float"); + "The curvilinear abscissa of the current point.\n" + "\n" + ":type: float"); static PyObject *Interface0DIterator_t_get(BPy_Interface0DIterator *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->if0D_it->t()); + return PyFloat_FromDouble(self->if0D_it->t()); } PyDoc_STRVAR(Interface0DIterator_u_doc, -"The point parameter at the current point in the 1D element (0 <= u <= 1).\n" -"\n" -":type: float"); + "The point parameter at the current point in the 1D element (0 <= u <= 1).\n" + "\n" + ":type: float"); static PyObject *Interface0DIterator_u_get(BPy_Interface0DIterator *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->if0D_it->u()); + return PyFloat_FromDouble(self->if0D_it->u()); } PyDoc_STRVAR(Interface0DIterator_at_last_doc, -"True if the interator points to the last valid element.\n" -"For its counterpart (pointing to the first valid element), use it.is_begin.\n" -"\n" -":type: bool"); + "True if the interator points to the last valid element.\n" + "For its counterpart (pointing to the first valid element), use it.is_begin.\n" + "\n" + ":type: bool"); -static PyObject *Interface0DIterator_at_last_get(BPy_Interface0DIterator *self, void *UNUSED(closure)) +static PyObject *Interface0DIterator_at_last_get(BPy_Interface0DIterator *self, + void *UNUSED(closure)) { - return PyBool_from_bool(self->if0D_it->atLast()); + return PyBool_from_bool(self->if0D_it->atLast()); } static PyGetSetDef BPy_Interface0DIterator_getseters[] = { - {(char *)"object", (getter)Interface0DIterator_object_get, (setter)NULL, - (char *)Interface0DIterator_object_doc, NULL}, - {(char *)"t", (getter)Interface0DIterator_t_get, (setter)NULL, (char *)Interface0DIterator_t_doc, NULL}, - {(char *)"u", (getter)Interface0DIterator_u_get, (setter)NULL, (char *)Interface0DIterator_u_doc, NULL}, - {(char *)"at_last", (getter)Interface0DIterator_at_last_get, (setter)NULL, - (char *)Interface0DIterator_at_last_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"object", + (getter)Interface0DIterator_object_get, + (setter)NULL, + (char *)Interface0DIterator_object_doc, + NULL}, + {(char *)"t", + (getter)Interface0DIterator_t_get, + (setter)NULL, + (char *)Interface0DIterator_t_doc, + NULL}, + {(char *)"u", + (getter)Interface0DIterator_u_get, + (setter)NULL, + (char *)Interface0DIterator_u_doc, + NULL}, + {(char *)"at_last", + (getter)Interface0DIterator_at_last_get, + (setter)NULL, + (char *)Interface0DIterator_at_last_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_Interface0DIterator type definition ------------------------------*/ PyTypeObject Interface0DIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "Interface0DIterator", /* tp_name */ - sizeof(BPy_Interface0DIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Interface0DIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)Interface0DIterator_iter, /* tp_iter */ - (iternextfunc)Interface0DIterator_iternext, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_Interface0DIterator_getseters, /* tp_getset */ - &Iterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)Interface0DIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "Interface0DIterator", /* tp_name */ + sizeof(BPy_Interface0DIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + Interface0DIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc)Interface0DIterator_iter, /* tp_iter */ + (iternextfunc)Interface0DIterator_iternext, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_Interface0DIterator_getseters, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)Interface0DIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.h index 7379ec5112d..3695cda6c76 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.h @@ -33,14 +33,15 @@ extern "C" { extern PyTypeObject Interface0DIterator_Type; -#define BPy_Interface0DIterator_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&Interface0DIterator_Type)) +#define BPy_Interface0DIterator_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&Interface0DIterator_Type)) /*---------------------------Python BPy_Interface0DIterator structure definition----------*/ typedef struct { - BPy_Iterator py_it; - Interface0DIterator *if0D_it; - bool reversed; - bool at_start; + BPy_Iterator py_it; + Interface0DIterator *if0D_it; + bool reversed; + bool at_start; } BPy_Interface0DIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp index ef8e1135139..2a860976d7f 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.cpp @@ -33,162 +33,179 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(SVertexIterator_doc, -"Class hierarchy: :class:`Iterator` > :class:`SVertexIterator`\n" -"\n" -"Class representing an iterator over :class:`SVertex` of a\n" -":class:`ViewEdge`. An instance of an SVertexIterator can be obtained\n" -"from a ViewEdge by calling verticesBegin() or verticesEnd().\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: An SVertexIterator object.\n" -" :type brother: :class:`SVertexIterator`\n" -"\n" -".. method:: __init__(vertex, begin, previous_edge, next_edge, t)\n" -"\n" -" Build an SVertexIterator that starts iteration from an SVertex\n" -" object v.\n" -"\n" -" :arg vertex: The SVertex from which the iterator starts iteration.\n" -" :type vertex: :class:`SVertex`\n" -" :arg begin: The first SVertex of a ViewEdge.\n" -" :type begin: :class:`SVertex`\n" -" :arg previous_edge: The previous FEdge coming to vertex.\n" -" :type previous_edge: :class:`FEdge`\n" -" :arg next_edge: The next FEdge going out from vertex.\n" -" :type next_edge: :class:`FEdge`\n" -" :arg t: The curvilinear abscissa at vertex.\n" -" :type t: float"); + "Class hierarchy: :class:`Iterator` > :class:`SVertexIterator`\n" + "\n" + "Class representing an iterator over :class:`SVertex` of a\n" + ":class:`ViewEdge`. An instance of an SVertexIterator can be obtained\n" + "from a ViewEdge by calling verticesBegin() or verticesEnd().\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: An SVertexIterator object.\n" + " :type brother: :class:`SVertexIterator`\n" + "\n" + ".. method:: __init__(vertex, begin, previous_edge, next_edge, t)\n" + "\n" + " Build an SVertexIterator that starts iteration from an SVertex\n" + " object v.\n" + "\n" + " :arg vertex: The SVertex from which the iterator starts iteration.\n" + " :type vertex: :class:`SVertex`\n" + " :arg begin: The first SVertex of a ViewEdge.\n" + " :type begin: :class:`SVertex`\n" + " :arg previous_edge: The previous FEdge coming to vertex.\n" + " :type previous_edge: :class:`FEdge`\n" + " :arg next_edge: The next FEdge going out from vertex.\n" + " :type next_edge: :class:`FEdge`\n" + " :arg t: The curvilinear abscissa at vertex.\n" + " :type t: float"); static int SVertexIterator_init(BPy_SVertexIterator *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"vertex", "begin", "previous_edge", "next_edge", "t", NULL}; - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; - float t; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &SVertexIterator_Type, &obj1)) { - if (!obj1) - self->sv_it = new ViewEdgeInternal::SVertexIterator(); - else - self->sv_it = new ViewEdgeInternal::SVertexIterator(*(((BPy_SVertexIterator *)obj1)->sv_it)); - } - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!O!f", (char **)kwlist_2, - &SVertex_Type, &obj1, - &SVertex_Type, &obj2, - &FEdge_Type, &obj3, - &FEdge_Type, &obj4, - &t)) - { - self->sv_it = new ViewEdgeInternal::SVertexIterator( - ((BPy_SVertex *)obj1)->sv, - ((BPy_SVertex *)obj2)->sv, - ((BPy_FEdge *)obj3)->fe, - ((BPy_FEdge *)obj4)->fe, - t); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_it.it = self->sv_it; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"vertex", "begin", "previous_edge", "next_edge", "t", NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; + float t; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist_1, &SVertexIterator_Type, &obj1)) { + if (!obj1) + self->sv_it = new ViewEdgeInternal::SVertexIterator(); + else + self->sv_it = new ViewEdgeInternal::SVertexIterator(*(((BPy_SVertexIterator *)obj1)->sv_it)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, + kwds, + "O!O!O!O!f", + (char **)kwlist_2, + &SVertex_Type, + &obj1, + &SVertex_Type, + &obj2, + &FEdge_Type, + &obj3, + &FEdge_Type, + &obj4, + &t)) { + self->sv_it = new ViewEdgeInternal::SVertexIterator(((BPy_SVertex *)obj1)->sv, + ((BPy_SVertex *)obj2)->sv, + ((BPy_FEdge *)obj3)->fe, + ((BPy_FEdge *)obj4)->fe, + t); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_it.it = self->sv_it; + return 0; } /*----------------------SVertexIterator get/setters ----------------------------*/ PyDoc_STRVAR(SVertexIterator_object_doc, -"The SVertex object currently pointed by this iterator.\n" -"\n" -":type: :class:`SVertex`"); + "The SVertex object currently pointed by this iterator.\n" + "\n" + ":type: :class:`SVertex`"); static PyObject *SVertexIterator_object_get(BPy_SVertexIterator *self, void *UNUSED(closure)) { - if (self->sv_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - SVertex *sv = self->sv_it->operator->(); - if (sv) - return BPy_SVertex_from_SVertex(*sv); - Py_RETURN_NONE; + if (self->sv_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + SVertex *sv = self->sv_it->operator->(); + if (sv) + return BPy_SVertex_from_SVertex(*sv); + Py_RETURN_NONE; } PyDoc_STRVAR(SVertexIterator_t_doc, -"The curvilinear abscissa of the current point.\n" -"\n" -":type: float"); + "The curvilinear abscissa of the current point.\n" + "\n" + ":type: float"); static PyObject *SVertexIterator_t_get(BPy_SVertexIterator *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->sv_it->t()); + return PyFloat_FromDouble(self->sv_it->t()); } PyDoc_STRVAR(SVertexIterator_u_doc, -"The point parameter at the current point in the 1D element (0 <= u <= 1).\n" -"\n" -":type: float"); + "The point parameter at the current point in the 1D element (0 <= u <= 1).\n" + "\n" + ":type: float"); static PyObject *SVertexIterator_u_get(BPy_SVertexIterator *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->sv_it->u()); + return PyFloat_FromDouble(self->sv_it->u()); } static PyGetSetDef BPy_SVertexIterator_getseters[] = { - {(char *)"object", (getter)SVertexIterator_object_get, (setter)NULL, (char *)SVertexIterator_object_doc, NULL}, - {(char *)"t", (getter)SVertexIterator_t_get, (setter)NULL, (char *)SVertexIterator_t_doc, NULL}, - {(char *)"u", (getter)SVertexIterator_u_get, (setter)NULL, (char *)SVertexIterator_u_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"object", + (getter)SVertexIterator_object_get, + (setter)NULL, + (char *)SVertexIterator_object_doc, + NULL}, + {(char *)"t", + (getter)SVertexIterator_t_get, + (setter)NULL, + (char *)SVertexIterator_t_doc, + NULL}, + {(char *)"u", + (getter)SVertexIterator_u_get, + (setter)NULL, + (char *)SVertexIterator_u_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_SVertexIterator type definition ------------------------------*/ PyTypeObject SVertexIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "SVertexIterator", /* tp_name */ - sizeof(BPy_SVertexIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - SVertexIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_SVertexIterator_getseters, /* tp_getset */ - &Iterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)SVertexIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "SVertexIterator", /* tp_name */ + sizeof(BPy_SVertexIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + SVertexIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_SVertexIterator_getseters, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)SVertexIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.h index 43e67af1183..2a3bfa6baf9 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_SVertexIterator.h @@ -33,12 +33,13 @@ extern "C" { extern PyTypeObject SVertexIterator_Type; -#define BPy_SVertexIterator_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&SVertexIterator_Type)) +#define BPy_SVertexIterator_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&SVertexIterator_Type)) /*---------------------------Python BPy_SVertexIterator structure definition----------*/ typedef struct { - BPy_Iterator py_it; - ViewEdgeInternal::SVertexIterator *sv_it; + BPy_Iterator py_it; + ViewEdgeInternal::SVertexIterator *sv_it; } BPy_SVertexIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp index f39f95fda2d..5727ac2e461 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp @@ -33,271 +33,298 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(StrokeVertexIterator_doc, -"Class hierarchy: :class:`Iterator` > :class:`StrokeVertexIterator`\n" -"\n" -"Class defining an iterator designed to iterate over the\n" -":class:`StrokeVertex` of a :class:`Stroke`. An instance of a\n" -"StrokeVertexIterator can be obtained from a Stroke by calling\n" -"iter(), stroke_vertices_begin() or stroke_vertices_begin(). It is iterating\n" -"over the same vertices as an :class:`Interface0DIterator`. The difference\n" -"resides in the object access: an Interface0DIterator only allows\n" -"access to an Interface0D while one might need to access the\n" -"specialized StrokeVertex type. In this case, one should use a\n" -"StrokeVertexIterator. To call functions of the UnaryFuntion0D type,\n" -"a StrokeVertexIterator can be converted to an Interface0DIterator by\n" -"by calling Interface0DIterator(it).\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A StrokeVertexIterator object.\n" -" :type brother: :class:`StrokeVertexIterator`"); - -static int StrokeVertexIterator_init(BPy_StrokeVertexIterator *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`Iterator` > :class:`StrokeVertexIterator`\n" + "\n" + "Class defining an iterator designed to iterate over the\n" + ":class:`StrokeVertex` of a :class:`Stroke`. An instance of a\n" + "StrokeVertexIterator can be obtained from a Stroke by calling\n" + "iter(), stroke_vertices_begin() or stroke_vertices_begin(). It is iterating\n" + "over the same vertices as an :class:`Interface0DIterator`. The difference\n" + "resides in the object access: an Interface0DIterator only allows\n" + "access to an Interface0D while one might need to access the\n" + "specialized StrokeVertex type. In this case, one should use a\n" + "StrokeVertexIterator. To call functions of the UnaryFuntion0D type,\n" + "a StrokeVertexIterator can be converted to an Interface0DIterator by\n" + "by calling Interface0DIterator(it).\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A StrokeVertexIterator object.\n" + " :type brother: :class:`StrokeVertexIterator`"); + +static int StrokeVertexIterator_init(BPy_StrokeVertexIterator *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"stroke", NULL}; - PyObject *brother = 0, *stroke = 0; - - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &StrokeVertexIterator_Type, &brother)) { - 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; - } - - else if (PyErr_Clear(), - PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_2, &Stroke_Type, &stroke)) - { - if (!stroke) - self->sv_it = new StrokeInternal::StrokeVertexIterator(); - else - self->sv_it = new StrokeInternal::StrokeVertexIterator(((BPy_Stroke *)stroke)->s->strokeVerticesBegin()); - self->reversed = false; - self->at_start = true; - } - else { - PyErr_SetString(PyExc_TypeError, "argument 1 must be StrokeVertexIterator or Stroke"); - return -1; - } - self->py_it.it = self->sv_it; - return 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"stroke", NULL}; + PyObject *brother = 0, *stroke = 0; + + if (PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist_1, &StrokeVertexIterator_Type, &brother)) { + 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; + } + + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist_2, &Stroke_Type, &stroke)) { + if (!stroke) + self->sv_it = new StrokeInternal::StrokeVertexIterator(); + else + self->sv_it = new StrokeInternal::StrokeVertexIterator( + ((BPy_Stroke *)stroke)->s->strokeVerticesBegin()); + self->reversed = false; + self->at_start = true; + } + else { + PyErr_SetString(PyExc_TypeError, "argument 1 must be StrokeVertexIterator or Stroke"); + return -1; + } + self->py_it.it = self->sv_it; + return 0; } static PyObject *StrokeVertexIterator_iter(BPy_StrokeVertexIterator *self) { - Py_INCREF(self); - self->at_start = true; - return (PyObject *) self; + Py_INCREF(self); + self->at_start = true; + return (PyObject *)self; } static PyObject *StrokeVertexIterator_iternext(BPy_StrokeVertexIterator *self) { - /* Because Freestyle iterators for which it.isEnd() holds true have no valid object - * (they point to the past-the-end element and can't be dereferenced), we have to check - * iterators for validity. - * Additionally, the at_start attribute is used to keep Freestyle iterator objects - * and Python for loops in sync. */ - - if (self->reversed) { - if (self->sv_it->isBegin()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - self->sv_it->decrement(); - } - else { - /* If sv_it.isEnd() is true, the iterator can't be incremented. */ - 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 */ - else if (self->at_start) { - self->at_start = false; - } - /* If sv_it.atLast() is true, the iterator is currently pointing to the final valid element. - * Incrementing it further would lead to a state that the iterator can't be dereferenced. */ - else if (self->sv_it->atLast()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - else { - self->sv_it->increment(); - } - } - StrokeVertex *sv = self->sv_it->operator->(); - return BPy_StrokeVertex_from_StrokeVertex(*sv); + /* Because Freestyle iterators for which it.isEnd() holds true have no valid object + * (they point to the past-the-end element and can't be dereferenced), we have to check + * iterators for validity. + * Additionally, the at_start attribute is used to keep Freestyle iterator objects + * and Python for loops in sync. */ + + if (self->reversed) { + if (self->sv_it->isBegin()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + self->sv_it->decrement(); + } + else { + /* If sv_it.isEnd() is true, the iterator can't be incremented. */ + 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 */ + else if (self->at_start) { + self->at_start = false; + } + /* If sv_it.atLast() is true, the iterator is currently pointing to the final valid element. + * Incrementing it further would lead to a state that the iterator can't be dereferenced. */ + else if (self->sv_it->atLast()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + else { + self->sv_it->increment(); + } + } + StrokeVertex *sv = self->sv_it->operator->(); + return BPy_StrokeVertex_from_StrokeVertex(*sv); } /*----------------------StrokeVertexIterator methods ----------------------------*/ PyDoc_STRVAR(StrokeVertexIterator_incremented_doc, -".. method:: incremented()\n" -"\n" -" Returns a copy of an incremented StrokeVertexIterator.\n" -"\n" -" :return: A StrokeVertexIterator pointing the next StrokeVertex.\n" -" :rtype: :class:`StrokeVertexIterator`"); + ".. method:: incremented()\n" + "\n" + " Returns a copy of an incremented StrokeVertexIterator.\n" + "\n" + " :return: A StrokeVertexIterator pointing the next StrokeVertex.\n" + " :rtype: :class:`StrokeVertexIterator`"); 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(*self->sv_it); - copy.increment(); - return BPy_StrokeVertexIterator_from_StrokeVertexIterator(copy, self->reversed); + if (self->sv_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "cannot increment any more"); + return NULL; + } + StrokeInternal::StrokeVertexIterator copy(*self->sv_it); + copy.increment(); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(copy, self->reversed); } PyDoc_STRVAR(StrokeVertexIterator_decremented_doc, -".. method:: decremented()\n" -"\n" -" Returns a copy of a decremented StrokeVertexIterator.\n" -"\n" -" :return: A StrokeVertexIterator pointing the previous StrokeVertex.\n" -" :rtype: :class:`StrokeVertexIterator`"); + ".. method:: decremented()\n" + "\n" + " Returns a copy of a decremented StrokeVertexIterator.\n" + "\n" + " :return: A StrokeVertexIterator pointing the previous StrokeVertex.\n" + " :rtype: :class:`StrokeVertexIterator`"); 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(*self->sv_it); - copy.decrement(); - return BPy_StrokeVertexIterator_from_StrokeVertexIterator(copy, self->reversed); + if (self->sv_it->isBegin()) { + PyErr_SetString(PyExc_RuntimeError, "cannot decrement any more"); + return NULL; + } + StrokeInternal::StrokeVertexIterator copy(*self->sv_it); + copy.decrement(); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(copy, self->reversed); } PyDoc_STRVAR(StrokeVertexIterator_reversed_doc, -".. method:: reversed()\n" -"\n" -" Returns a StrokeVertexIterator that traverses stroke vertices in the\n" -" reversed order.\n" -"\n" -" :return: A StrokeVertexIterator traversing stroke vertices backward.\n" -" :rtype: :class:`StrokeVertexIterator`"); + ".. method:: reversed()\n" + "\n" + " Returns a StrokeVertexIterator that traverses stroke vertices in the\n" + " reversed order.\n" + "\n" + " :return: A StrokeVertexIterator traversing stroke vertices backward.\n" + " :rtype: :class:`StrokeVertexIterator`"); static PyObject *StrokeVertexIterator_reversed(BPy_StrokeVertexIterator *self) { - return BPy_StrokeVertexIterator_from_StrokeVertexIterator(*self->sv_it, !self->reversed); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(*self->sv_it, !self->reversed); } static PyMethodDef BPy_StrokeVertexIterator_methods[] = { - {"incremented", (PyCFunction)StrokeVertexIterator_incremented, METH_NOARGS, StrokeVertexIterator_incremented_doc}, - {"decremented", (PyCFunction)StrokeVertexIterator_decremented, METH_NOARGS, StrokeVertexIterator_decremented_doc}, - {"reversed", (PyCFunction)StrokeVertexIterator_reversed, METH_NOARGS, StrokeVertexIterator_reversed_doc}, - {NULL, NULL, 0, NULL}, + {"incremented", + (PyCFunction)StrokeVertexIterator_incremented, + METH_NOARGS, + StrokeVertexIterator_incremented_doc}, + {"decremented", + (PyCFunction)StrokeVertexIterator_decremented, + METH_NOARGS, + StrokeVertexIterator_decremented_doc}, + {"reversed", + (PyCFunction)StrokeVertexIterator_reversed, + METH_NOARGS, + StrokeVertexIterator_reversed_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------StrokeVertexIterator get/setters ----------------------------*/ PyDoc_STRVAR(StrokeVertexIterator_object_doc, -"The StrokeVertex object currently pointed to by this iterator.\n" -"\n" -":type: :class:`StrokeVertex`"); + "The StrokeVertex object currently pointed to by this iterator.\n" + "\n" + ":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->sv_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - StrokeVertex *sv = self->sv_it->operator->(); - if (sv) - return BPy_StrokeVertex_from_StrokeVertex(*sv); - Py_RETURN_NONE; + if (self->sv_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + StrokeVertex *sv = self->sv_it->operator->(); + if (sv) + return BPy_StrokeVertex_from_StrokeVertex(*sv); + Py_RETURN_NONE; } PyDoc_STRVAR(StrokeVertexIterator_t_doc, -"The curvilinear abscissa of the current point.\n" -"\n" -":type: float"); + "The curvilinear abscissa of the current point.\n" + "\n" + ":type: float"); static PyObject *StrokeVertexIterator_t_get(BPy_StrokeVertexIterator *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->sv_it->t()); + return PyFloat_FromDouble(self->sv_it->t()); } PyDoc_STRVAR(StrokeVertexIterator_u_doc, -"The point parameter at the current point in the stroke (0 <= u <= 1).\n" -"\n" -":type: float"); + "The point parameter at the current point in the stroke (0 <= u <= 1).\n" + "\n" + ":type: float"); static PyObject *StrokeVertexIterator_u_get(BPy_StrokeVertexIterator *self, void *UNUSED(closure)) { - return PyFloat_FromDouble(self->sv_it->u()); + return PyFloat_FromDouble(self->sv_it->u()); } PyDoc_STRVAR(StrokeVertexIterator_at_last_doc, -"True if the interator points to the last valid element.\n" -"For its counterpart (pointing to the first valid element), use it.is_begin.\n" -"\n" -":type: bool"); + "True if the interator points to the last valid element.\n" + "For its counterpart (pointing to the first valid element), use it.is_begin.\n" + "\n" + ":type: bool"); static PyObject *StrokeVertexIterator_at_last_get(BPy_StrokeVertexIterator *self) { - return PyBool_from_bool(self->sv_it->atLast()); - + return PyBool_from_bool(self->sv_it->atLast()); } static PyGetSetDef BPy_StrokeVertexIterator_getseters[] = { - {(char *)"object", (getter)StrokeVertexIterator_object_get, (setter)NULL, - (char *)StrokeVertexIterator_object_doc, NULL}, - {(char *)"t", (getter)StrokeVertexIterator_t_get, (setter)NULL, (char *)StrokeVertexIterator_t_doc, NULL}, - {(char *)"u", (getter)StrokeVertexIterator_u_get, (setter)NULL, (char *)StrokeVertexIterator_u_doc, NULL}, - {(char *)"at_last", (getter)StrokeVertexIterator_at_last_get, (setter)NULL, - (char *)StrokeVertexIterator_at_last_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"object", + (getter)StrokeVertexIterator_object_get, + (setter)NULL, + (char *)StrokeVertexIterator_object_doc, + NULL}, + {(char *)"t", + (getter)StrokeVertexIterator_t_get, + (setter)NULL, + (char *)StrokeVertexIterator_t_doc, + NULL}, + {(char *)"u", + (getter)StrokeVertexIterator_u_get, + (setter)NULL, + (char *)StrokeVertexIterator_u_doc, + NULL}, + {(char *)"at_last", + (getter)StrokeVertexIterator_at_last_get, + (setter)NULL, + (char *)StrokeVertexIterator_at_last_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_StrokeVertexIterator type definition ------------------------------*/ PyTypeObject StrokeVertexIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "StrokeVertexIterator", /* tp_name */ - sizeof(BPy_StrokeVertexIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - StrokeVertexIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)StrokeVertexIterator_iter, /* tp_iter */ - (iternextfunc)StrokeVertexIterator_iternext, /* tp_iternext */ - BPy_StrokeVertexIterator_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_StrokeVertexIterator_getseters, /* tp_getset */ - &Iterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)StrokeVertexIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "StrokeVertexIterator", /* tp_name */ + sizeof(BPy_StrokeVertexIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + StrokeVertexIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc)StrokeVertexIterator_iter, /* tp_iter */ + (iternextfunc)StrokeVertexIterator_iternext, /* tp_iternext */ + BPy_StrokeVertexIterator_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_StrokeVertexIterator_getseters, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)StrokeVertexIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.h index 22bdf3341c4..04bca16337d 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.h @@ -33,15 +33,16 @@ extern "C" { extern PyTypeObject StrokeVertexIterator_Type; -#define BPy_StrokeVertexIterator_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&StrokeVertexIterator_Type)) +#define BPy_StrokeVertexIterator_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&StrokeVertexIterator_Type)) /*---------------------------Python BPy_StrokeVertexIterator structure definition----------*/ typedef struct { - BPy_Iterator py_it; - StrokeInternal::StrokeVertexIterator *sv_it; - bool reversed; - /* attribute to make next() work correctly */ - bool at_start; + BPy_Iterator py_it; + StrokeInternal::StrokeVertexIterator *sv_it; + bool reversed; + /* attribute to make next() work correctly */ + bool at_start; } BPy_StrokeVertexIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp index efd0aafbc17..525df5dd89b 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp @@ -32,224 +32,247 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(ViewEdgeIterator_doc, -"Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator`\n" -"\n" -"Base class for iterators over ViewEdges of the :class:`ViewMap` Graph.\n" -"Basically the increment() operator of this class should be able to\n" -"take the decision of \"where\" (on which ViewEdge) to go when pointing\n" -"on a given ViewEdge.\n" -"\n" -".. method:: __init__(begin=None, orientation=True)\n" -"\n" -" Builds a ViewEdgeIterator from a starting ViewEdge and its\n" -" orientation.\n" -"\n" -" :arg begin: The ViewEdge from where to start the iteration.\n" -" :type begin: :class:`ViewEdge` or None\n" -" :arg orientation: If true, we'll look for the next ViewEdge among\n" -" the ViewEdges that surround the ending ViewVertex of begin. If\n" -" false, we'll search over the ViewEdges surrounding the ending\n" -" ViewVertex of begin.\n" -" :type orientation: bool\n" -"\n" -".. method:: __init__(brother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg brother: A ViewEdgeIterator object.\n" -" :type brother: :class:`ViewEdgeIterator`"); + "Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator`\n" + "\n" + "Base class for iterators over ViewEdges of the :class:`ViewMap` Graph.\n" + "Basically the increment() operator of this class should be able to\n" + "take the decision of \"where\" (on which ViewEdge) to go when pointing\n" + "on a given ViewEdge.\n" + "\n" + ".. method:: __init__(begin=None, orientation=True)\n" + "\n" + " Builds a ViewEdgeIterator from a starting ViewEdge and its\n" + " orientation.\n" + "\n" + " :arg begin: The ViewEdge from where to start the iteration.\n" + " :type begin: :class:`ViewEdge` or None\n" + " :arg orientation: If true, we'll look for the next ViewEdge among\n" + " the ViewEdges that surround the ending ViewVertex of begin. If\n" + " false, we'll search over the ViewEdges surrounding the ending\n" + " ViewVertex of begin.\n" + " :type orientation: bool\n" + "\n" + ".. method:: __init__(brother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg brother: A ViewEdgeIterator object.\n" + " :type brother: :class:`ViewEdgeIterator`"); static int check_begin(PyObject *obj, void *v) { - if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) - return 0; - *((PyObject **)v) = obj; - return 1; + if (obj != NULL && obj != Py_None && !BPy_ViewEdge_Check(obj)) + return 0; + *((PyObject **)v) = obj; + return 1; } static int ViewEdgeIterator_init(BPy_ViewEdgeIterator *self, PyObject *args, PyObject *kwds) { - static const char *kwlist_1[] = {"brother", NULL}; - static const char *kwlist_2[] = {"begin", "orientation", NULL}; - PyObject *obj1 = 0, *obj2 = 0; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"begin", "orientation", NULL}; + PyObject *obj1 = 0, *obj2 = 0; - if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &ViewEdgeIterator_Type, &obj1)) { - self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(*(((BPy_ViewEdgeIterator *)obj1)->ve_it)); - } - else if (PyErr_Clear(), (obj1 = obj2 = 0), - PyArg_ParseTupleAndKeywords(args, kwds, "|O&O!", (char **)kwlist_2, - check_begin, &obj1, &PyBool_Type, &obj2)) - { - ViewEdge *begin = (!obj1 || obj1 == Py_None) ? NULL : ((BPy_ViewEdge *)obj1)->ve; - bool orientation = (!obj2) ? true : bool_from_PyBool(obj2); - self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(begin, orientation); - } - else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - self->py_it.it = self->ve_it; - return 0; + if (PyArg_ParseTupleAndKeywords( + args, kwds, "O!", (char **)kwlist_1, &ViewEdgeIterator_Type, &obj1)) { + self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(*(((BPy_ViewEdgeIterator *)obj1)->ve_it)); + } + else if (PyErr_Clear(), + (obj1 = obj2 = 0), + PyArg_ParseTupleAndKeywords( + args, kwds, "|O&O!", (char **)kwlist_2, check_begin, &obj1, &PyBool_Type, &obj2)) { + ViewEdge *begin = (!obj1 || obj1 == Py_None) ? NULL : ((BPy_ViewEdge *)obj1)->ve; + bool orientation = (!obj2) ? true : bool_from_PyBool(obj2); + self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(begin, orientation); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } + self->py_it.it = self->ve_it; + return 0; } PyDoc_STRVAR(ViewEdgeIterator_change_orientation_doc, -".. method:: change_orientation()\n" -"\n" -" Changes the current orientation."); + ".. method:: change_orientation()\n" + "\n" + " Changes the current orientation."); static PyObject *ViewEdgeIterator_change_orientation(BPy_ViewEdgeIterator *self) { - self->ve_it->changeOrientation(); - Py_RETURN_NONE; + self->ve_it->changeOrientation(); + Py_RETURN_NONE; } static PyMethodDef BPy_ViewEdgeIterator_methods[] = { - {"change_orientation", (PyCFunction) ViewEdgeIterator_change_orientation, METH_NOARGS, - ViewEdgeIterator_change_orientation_doc}, - {NULL, NULL, 0, NULL}, + {"change_orientation", + (PyCFunction)ViewEdgeIterator_change_orientation, + METH_NOARGS, + ViewEdgeIterator_change_orientation_doc}, + {NULL, NULL, 0, NULL}, }; /*----------------------ViewEdgeIterator get/setters ----------------------------*/ PyDoc_STRVAR(ViewEdgeIterator_object_doc, -"The ViewEdge object currently pointed by this iterator.\n" -"\n" -":type: :class:`ViewEdge`"); + "The ViewEdge object currently pointed by this iterator.\n" + "\n" + ":type: :class:`ViewEdge`"); static PyObject *ViewEdgeIterator_object_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure)) { - if (!self->ve_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - ViewEdge *ve = self->ve_it->operator*(); - if (ve) - return BPy_ViewEdge_from_ViewEdge(*ve); - Py_RETURN_NONE; + if (!self->ve_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + ViewEdge *ve = self->ve_it->operator*(); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); + Py_RETURN_NONE; } PyDoc_STRVAR(ViewEdgeIterator_current_edge_doc, -"The ViewEdge object currently pointed by this iterator.\n" -"\n" -":type: :class:`ViewEdge`"); + "The ViewEdge object currently pointed by this iterator.\n" + "\n" + ":type: :class:`ViewEdge`"); -static PyObject *ViewEdgeIterator_current_edge_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure)) +static PyObject *ViewEdgeIterator_current_edge_get(BPy_ViewEdgeIterator *self, + void *UNUSED(closure)) { - ViewEdge *ve = self->ve_it->getCurrentEdge(); - if (ve) - return BPy_ViewEdge_from_ViewEdge(*ve); - Py_RETURN_NONE; + ViewEdge *ve = self->ve_it->getCurrentEdge(); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); + Py_RETURN_NONE; } -static int ViewEdgeIterator_current_edge_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure)) +static int ViewEdgeIterator_current_edge_set(BPy_ViewEdgeIterator *self, + PyObject *value, + void *UNUSED(closure)) { - if (!BPy_ViewEdge_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge"); - return -1; - } - self->ve_it->setCurrentEdge(((BPy_ViewEdge *)value)->ve); - return 0; + if (!BPy_ViewEdge_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge"); + return -1; + } + self->ve_it->setCurrentEdge(((BPy_ViewEdge *)value)->ve); + return 0; } PyDoc_STRVAR(ViewEdgeIterator_orientation_doc, -"The orientation of the pointed ViewEdge in the iteration.\n" -"If true, the iterator looks for the next ViewEdge among those ViewEdges\n" -"that surround the ending ViewVertex of the \"begin\" ViewEdge. If false,\n" -"the iterator searches over the ViewEdges surrounding the ending ViewVertex\n" -"of the \"begin\" ViewEdge.\n" -"\n" -":type: bool"); + "The orientation of the pointed ViewEdge in the iteration.\n" + "If true, the iterator looks for the next ViewEdge among those ViewEdges\n" + "that surround the ending ViewVertex of the \"begin\" ViewEdge. If false,\n" + "the iterator searches over the ViewEdges surrounding the ending ViewVertex\n" + "of the \"begin\" ViewEdge.\n" + "\n" + ":type: bool"); -static PyObject *ViewEdgeIterator_orientation_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure)) +static PyObject *ViewEdgeIterator_orientation_get(BPy_ViewEdgeIterator *self, + void *UNUSED(closure)) { - return PyBool_from_bool(self->ve_it->getOrientation()); + return PyBool_from_bool(self->ve_it->getOrientation()); } -static int ViewEdgeIterator_orientation_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure)) +static int ViewEdgeIterator_orientation_set(BPy_ViewEdgeIterator *self, + PyObject *value, + void *UNUSED(closure)) { - if (!PyBool_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be a boolean"); - return -1; - } - self->ve_it->setOrientation(bool_from_PyBool(value)); - return 0; + if (!PyBool_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a boolean"); + return -1; + } + self->ve_it->setOrientation(bool_from_PyBool(value)); + return 0; } PyDoc_STRVAR(ViewEdgeIterator_begin_doc, -"The first ViewEdge used for the iteration.\n" -"\n" -":type: :class:`ViewEdge`"); + "The first ViewEdge used for the iteration.\n" + "\n" + ":type: :class:`ViewEdge`"); static PyObject *ViewEdgeIterator_begin_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure)) { - ViewEdge *ve = self->ve_it->getBegin(); - if (ve) - return BPy_ViewEdge_from_ViewEdge(*ve); - Py_RETURN_NONE; + ViewEdge *ve = self->ve_it->getBegin(); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); + Py_RETURN_NONE; } -static int ViewEdgeIterator_begin_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure)) +static int ViewEdgeIterator_begin_set(BPy_ViewEdgeIterator *self, + PyObject *value, + void *UNUSED(closure)) { - if (!BPy_ViewEdge_Check(value)) { - PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge"); - return -1; - } - self->ve_it->setBegin(((BPy_ViewEdge *)value)->ve); - return 0; + if (!BPy_ViewEdge_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge"); + return -1; + } + self->ve_it->setBegin(((BPy_ViewEdge *)value)->ve); + return 0; } static PyGetSetDef BPy_ViewEdgeIterator_getseters[] = { - {(char *)"object", (getter)ViewEdgeIterator_object_get, (setter)NULL, (char *)ViewEdgeIterator_object_doc, NULL}, - {(char *)"current_edge", (getter)ViewEdgeIterator_current_edge_get, (setter)ViewEdgeIterator_current_edge_set, - (char *)ViewEdgeIterator_current_edge_doc, NULL}, - {(char *)"orientation", (getter)ViewEdgeIterator_orientation_get, (setter)ViewEdgeIterator_orientation_set, - (char *)ViewEdgeIterator_orientation_doc, NULL}, - {(char *)"begin", (getter)ViewEdgeIterator_begin_get, (setter)ViewEdgeIterator_begin_set, - (char *)ViewEdgeIterator_begin_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"object", + (getter)ViewEdgeIterator_object_get, + (setter)NULL, + (char *)ViewEdgeIterator_object_doc, + NULL}, + {(char *)"current_edge", + (getter)ViewEdgeIterator_current_edge_get, + (setter)ViewEdgeIterator_current_edge_set, + (char *)ViewEdgeIterator_current_edge_doc, + NULL}, + {(char *)"orientation", + (getter)ViewEdgeIterator_orientation_get, + (setter)ViewEdgeIterator_orientation_set, + (char *)ViewEdgeIterator_orientation_doc, + NULL}, + {(char *)"begin", + (getter)ViewEdgeIterator_begin_get, + (setter)ViewEdgeIterator_begin_set, + (char *)ViewEdgeIterator_begin_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_ViewEdgeIterator type definition ------------------------------*/ PyTypeObject ViewEdgeIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "ViewEdgeIterator", /* tp_name */ - sizeof(BPy_ViewEdgeIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ViewEdgeIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - BPy_ViewEdgeIterator_methods, /* tp_methods */ - 0, /* tp_members */ - BPy_ViewEdgeIterator_getseters, /* tp_getset */ - &Iterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)ViewEdgeIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "ViewEdgeIterator", /* tp_name */ + sizeof(BPy_ViewEdgeIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + ViewEdgeIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + BPy_ViewEdgeIterator_methods, /* tp_methods */ + 0, /* tp_members */ + BPy_ViewEdgeIterator_getseters, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)ViewEdgeIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.h index 83c1512e239..c9061d30e07 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.h @@ -33,12 +33,13 @@ extern "C" { extern PyTypeObject ViewEdgeIterator_Type; -#define BPy_ViewEdgeIterator_Check(v) (PyObject_IsInstance((PyObject *)v, (PyObject *)&ViewEdgeIterator_Type)) +#define BPy_ViewEdgeIterator_Check(v) \ + (PyObject_IsInstance((PyObject *)v, (PyObject *)&ViewEdgeIterator_Type)) /*---------------------------Python BPy_ViewEdgeIterator structure definition----------*/ typedef struct { - BPy_Iterator py_it; - ViewEdgeInternal::ViewEdgeIterator *ve_it; + BPy_Iterator py_it; + ViewEdgeInternal::ViewEdgeIterator *ve_it; } BPy_ViewEdgeIterator; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp index 4ef1eca4e0a..3cb114a0037 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.cpp @@ -31,145 +31,152 @@ extern "C" { //------------------------INSTANCE METHODS ---------------------------------- PyDoc_STRVAR(orientedViewEdgeIterator_doc, -"Class hierarchy: :class:`Iterator` > :class:`orientedViewEdgeIterator`\n" -"\n" -"Class representing an iterator over oriented ViewEdges around a\n" -":class:`ViewVertex`. This iterator allows a CCW iteration (in the image\n" -"plane). An instance of an orientedViewEdgeIterator can only be\n" -"obtained from a ViewVertex by calling edges_begin() or edges_end().\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(iBrother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg iBrother: An orientedViewEdgeIterator object.\n" -" :type iBrother: :class:`orientedViewEdgeIterator`"); - -static int orientedViewEdgeIterator_init(BPy_orientedViewEdgeIterator *self, PyObject *args, PyObject *kwds) + "Class hierarchy: :class:`Iterator` > :class:`orientedViewEdgeIterator`\n" + "\n" + "Class representing an iterator over oriented ViewEdges around a\n" + ":class:`ViewVertex`. This iterator allows a CCW iteration (in the image\n" + "plane). An instance of an orientedViewEdgeIterator can only be\n" + "obtained from a ViewVertex by calling edges_begin() or edges_end().\n" + "\n" + ".. method:: __init__()\n" + "\n" + " Default constructor.\n" + "\n" + ".. method:: __init__(iBrother)\n" + "\n" + " Copy constructor.\n" + "\n" + " :arg iBrother: An orientedViewEdgeIterator object.\n" + " :type iBrother: :class:`orientedViewEdgeIterator`"); + +static int orientedViewEdgeIterator_init(BPy_orientedViewEdgeIterator *self, + PyObject *args, + PyObject *kwds) { - static const char *kwlist[] = {"brother", NULL}; - PyObject *brother = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &orientedViewEdgeIterator_Type, &brother)) - return -1; - if (!brother) { - self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(); - self->at_start = true; - self->reversed = false; - } - else { - self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(*(((BPy_orientedViewEdgeIterator *)brother)->ove_it)); - self->at_start = ((BPy_orientedViewEdgeIterator *)brother)->at_start; - self->reversed = ((BPy_orientedViewEdgeIterator *)brother)->reversed; - } - self->py_it.it = self->ove_it; - return 0; + static const char *kwlist[] = {"brother", NULL}; + PyObject *brother = 0; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "|O!", (char **)kwlist, &orientedViewEdgeIterator_Type, &brother)) + return -1; + if (!brother) { + self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator(); + self->at_start = true; + self->reversed = false; + } + else { + self->ove_it = new ViewVertexInternal::orientedViewEdgeIterator( + *(((BPy_orientedViewEdgeIterator *)brother)->ove_it)); + 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_iter(BPy_orientedViewEdgeIterator *self) { - Py_INCREF(self); - self->at_start = true; - return (PyObject *) self; + 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(); - } - else { - if (self->ove_it->isEnd()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - if (self->at_start) - self->at_start = false; - else { - self->ove_it->increment(); - if (self->ove_it->isEnd()) { - PyErr_SetNone(PyExc_StopIteration); - return NULL; - } - } - } - ViewVertex::directedViewEdge *dve = self->ove_it->operator->(); - return BPy_directedViewEdge_from_directedViewEdge(*dve); + if (self->reversed) { + if (self->ove_it->isBegin()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + self->ove_it->decrement(); + } + else { + if (self->ove_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + if (self->at_start) + self->at_start = false; + else { + self->ove_it->increment(); + if (self->ove_it->isEnd()) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + } + } + ViewVertex::directedViewEdge *dve = self->ove_it->operator->(); + return BPy_directedViewEdge_from_directedViewEdge(*dve); } /*----------------------orientedViewEdgeIterator get/setters ----------------------------*/ PyDoc_STRVAR(orientedViewEdgeIterator_object_doc, -"The oriented ViewEdge (i.e., a tuple of the pointed ViewEdge and a boolean\n" -"value) currently pointed to by this iterator. If the boolean value is true,\n" -"the ViewEdge is incoming.\n" -"\n" -":type: (:class:`ViewEdge`, bool)"); - -static PyObject *orientedViewEdgeIterator_object_get(BPy_orientedViewEdgeIterator *self, void *UNUSED(closure)) + "The oriented ViewEdge (i.e., a tuple of the pointed ViewEdge and a boolean\n" + "value) currently pointed to by this iterator. If the boolean value is true,\n" + "the ViewEdge is incoming.\n" + "\n" + ":type: (:class:`ViewEdge`, bool)"); + +static PyObject *orientedViewEdgeIterator_object_get(BPy_orientedViewEdgeIterator *self, + void *UNUSED(closure)) { - if (self->ove_it->isEnd()) { - PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); - return NULL; - } - return BPy_directedViewEdge_from_directedViewEdge(self->ove_it->operator*()); + if (self->ove_it->isEnd()) { + PyErr_SetString(PyExc_RuntimeError, "iteration has stopped"); + return NULL; + } + return BPy_directedViewEdge_from_directedViewEdge(self->ove_it->operator*()); } static PyGetSetDef BPy_orientedViewEdgeIterator_getseters[] = { - {(char *)"object", (getter)orientedViewEdgeIterator_object_get, (setter)NULL, - (char *)orientedViewEdgeIterator_object_doc, NULL}, - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ + {(char *)"object", + (getter)orientedViewEdgeIterator_object_get, + (setter)NULL, + (char *)orientedViewEdgeIterator_object_doc, + NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_orientedViewEdgeIterator type definition ------------------------------*/ PyTypeObject orientedViewEdgeIterator_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "orientedViewEdgeIterator", /* tp_name */ - sizeof(BPy_orientedViewEdgeIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_reserved */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - orientedViewEdgeIterator_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - (getiterfunc)orientedViewEdgeIterator_iter, /* tp_iter */ - (iternextfunc)orientedViewEdgeIterator_iternext, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - BPy_orientedViewEdgeIterator_getseters, /* tp_getset */ - &Iterator_Type, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)orientedViewEdgeIterator_init, /* tp_init */ - 0, /* tp_alloc */ - 0, /* tp_new */ + PyVarObject_HEAD_INIT(NULL, 0) "orientedViewEdgeIterator", /* tp_name */ + sizeof(BPy_orientedViewEdgeIterator), /* tp_basicsize */ + 0, /* tp_itemsize */ + 0, /* tp_dealloc */ + 0, /* tp_print */ + 0, /* tp_getattr */ + 0, /* tp_setattr */ + 0, /* tp_reserved */ + 0, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + 0, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ + orientedViewEdgeIterator_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + (getiterfunc)orientedViewEdgeIterator_iter, /* tp_iter */ + (iternextfunc)orientedViewEdgeIterator_iternext, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + BPy_orientedViewEdgeIterator_getseters, /* tp_getset */ + &Iterator_Type, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)orientedViewEdgeIterator_init, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ }; /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.h b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.h index 226535e3882..179e315b1be 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.h +++ b/source/blender/freestyle/intern/python/Iterator/BPy_orientedViewEdgeIterator.h @@ -34,14 +34,14 @@ extern "C" { extern PyTypeObject orientedViewEdgeIterator_Type; #define BPy_orientedViewEdgeIterator_Check(v) \ - (PyObject_IsInstance((PyObject *)v, (PyObject *)&orientedViewEdgeIterator_Type)) + (PyObject_IsInstance((PyObject *)v, (PyObject *)&orientedViewEdgeIterator_Type)) /*---------------------------Python BPy_orientedViewEdgeIterator structure definition----------*/ typedef struct { - BPy_Iterator py_it; - ViewVertexInternal::orientedViewEdgeIterator *ove_it; - bool reversed; - bool at_start; + BPy_Iterator py_it; + ViewVertexInternal::orientedViewEdgeIterator *ove_it; + bool reversed; + bool at_start; } BPy_orientedViewEdgeIterator; /////////////////////////////////////////////////////////////////////////////////////////// |