OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * ***** BEGIN GPL LICENSE BLOCK ***** |
| 3 * |
| 4 * This program is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU General Public License |
| 6 * as published by the Free Software Foundation; either version 2 |
| 7 * of the License, or (at your option) any later version. |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with this program; if not, write to the Free Software Foundation, |
| 16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 * |
| 18 * The Original Code is Copyright (C) 2010 Blender Foundation. |
| 19 * All rights reserved. |
| 20 * |
| 21 * The Original Code is: all of this file. |
| 22 * |
| 23 * Contributor(s): none yet. |
| 24 * |
| 25 * ***** END GPL LICENSE BLOCK ***** |
| 26 */ |
| 27 |
| 28 /** \file source/blender/freestyle/intern/python/Iterator/BPy_AdjacencyIterator.
cpp |
| 29 * \ingroup freestyle |
| 30 */ |
| 31 |
| 32 #include "BPy_AdjacencyIterator.h" |
| 33 |
| 34 #include "../BPy_Convert.h" |
| 35 #include "../Interface0D/BPy_ViewVertex.h" |
| 36 |
| 37 #ifdef __cplusplus |
| 38 extern "C" { |
| 39 #endif |
| 40 |
| 41 ////////////////////////////////////////////////////////////////////////////////
/////////// |
| 42 |
| 43 //------------------------INSTANCE METHODS ---------------------------------- |
| 44 |
| 45 PyDoc_STRVAR(AdjacencyIterator_doc, |
| 46 "Class hierarchy: :class:`Iterator` > :class:`AdjacencyIterator`\n" |
| 47 "\n" |
| 48 "Class for representing adjacency iterators used in the chaining\n" |
| 49 "process. An AdjacencyIterator is created in the increment() and\n" |
| 50 "decrement() methods of a :class:`ChainingIterator` and passed to the\n" |
| 51 "traverse() method of the ChainingIterator.\n" |
| 52 "\n" |
| 53 ".. method:: __init__()\n" |
| 54 "\n" |
| 55 " Default constructor.\n" |
| 56 "\n" |
| 57 ".. method:: __init__(brother)\n" |
| 58 "\n" |
| 59 " Copy constructor.\n" |
| 60 "\n" |
| 61 " :arg brother: An AdjacencyIterator object.\n" |
| 62 " :type brother: :class:`AdjacencyIterator`\n" |
| 63 "\n" |
| 64 ".. method:: __init__(vertex, restrict_to_selection=True, restrict_to_unvisited=
True)\n" |
| 65 "\n" |
| 66 " Builds a AdjacencyIterator object.\n" |
| 67 "\n" |
| 68 " :arg vertex: The vertex which is the next crossing.\n" |
| 69 " :type vertex: :class:`ViewVertex`\n" |
| 70 " :arg restrict_to_selection: Indicates whether to force the chaining\n" |
| 71 " to stay within the set of selected ViewEdges or not.\n" |
| 72 " :type restrict_to_selection: bool\n" |
| 73 " :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" |
| 74 " already been chained must be ignored ot not.\n" |
| 75 " :type restrict_to_unvisited: bool"); |
| 76 |
| 77 static int AdjacencyIterator_init(BPy_AdjacencyIterator *self, PyObject *args, P
yObject *kwds) |
| 78 { |
| 79 static const char *kwlist_1[] = {"brother", NULL}; |
| 80 static const char *kwlist_2[] = {"vertex", "restrict_to_selection", "res
trict_to_unvisited", NULL}; |
| 81 PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0; |
| 82 |
| 83 if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &A
djacencyIterator_Type, &obj1)) { |
| 84 if (!obj1) |
| 85 self->a_it = new AdjacencyIterator(); |
| 86 else· |
| 87 self->a_it = new AdjacencyIterator(*(((BPy_AdjacencyIter
ator *)obj1)->a_it)); |
| 88 } |
| 89 else if (PyErr_Clear(), (obj2 = obj3 = 0), |
| 90 PyArg_ParseTupleAndKeywords(args, kwds, "O!|O!O!", (char **)kwl
ist_2, |
| 91 &ViewVertex_Type, &obj1, &PyBool_Ty
pe, &obj2, &PyBool_Type, &obj3)) |
| 92 { |
| 93 bool restrictToSelection = (!obj2) ? true : bool_from_PyBool(obj
2); |
| 94 bool restrictToUnvisited = (!obj3) ? true : bool_from_PyBool(obj
3); |
| 95 self->a_it = new AdjacencyIterator(((BPy_ViewVertex *)obj1)->vv,
restrictToSelection, restrictToUnvisited); |
| 96 } |
| 97 else { |
| 98 PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); |
| 99 return -1; |
| 100 } |
| 101 self->py_it.it = self->a_it; |
| 102 return 0; |
| 103 } |
| 104 |
| 105 static PyObject * AdjacencyIterator_iternext(BPy_AdjacencyIterator *self) |
| 106 { |
| 107 if (self->a_it->isEnd()) { |
| 108 PyErr_SetNone(PyExc_StopIteration); |
| 109 return NULL; |
| 110 } |
| 111 ViewEdge *ve = self->a_it->operator*(); |
| 112 self->a_it->increment(); |
| 113 return BPy_ViewEdge_from_ViewEdge(*ve); |
| 114 } |
| 115 |
| 116 /*----------------------AdjacencyIterator get/setters --------------------------
--*/ |
| 117 |
| 118 PyDoc_STRVAR(AdjacencyIterator_object_doc, |
| 119 "The ViewEdge object currently pointed by this iterator.\n" |
| 120 "\n" |
| 121 ":type: :class:`ViewEdge`"); |
| 122 |
| 123 static PyObject *AdjacencyIterator_object_get(BPy_AdjacencyIterator *self, void
*UNUSED(closure)) |
| 124 { |
| 125 ViewEdge *ve = self->a_it->operator*(); |
| 126 if (ve) |
| 127 return BPy_ViewEdge_from_ViewEdge(*ve); |
| 128 Py_RETURN_NONE; |
| 129 } |
| 130 |
| 131 PyDoc_STRVAR(AdjacencyIterator_is_incoming_doc, |
| 132 "True if the current ViewEdge is coming towards the iteration vertex, and\n" |
| 133 "False otherwise.\n" |
| 134 "\n" |
| 135 ":type: bool"); |
| 136 |
| 137 static PyObject *AdjacencyIterator_is_incoming_get(BPy_AdjacencyIterator *self,
void *UNUSED(closure)) |
| 138 { |
| 139 return PyBool_from_bool(self->a_it->isIncoming()); |
| 140 } |
| 141 |
| 142 static PyGetSetDef BPy_AdjacencyIterator_getseters[] = { |
| 143 {(char *)"is_incoming", (getter)AdjacencyIterator_is_incoming_get, (sett
er)NULL, (char *)AdjacencyIterator_is_incoming_doc, NULL}, |
| 144 {(char *)"object", (getter)AdjacencyIterator_object_get, (setter)NULL, (
char *)AdjacencyIterator_object_doc, NULL}, |
| 145 {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ |
| 146 }; |
| 147 |
| 148 /*-----------------------BPy_AdjacencyIterator type definition -----------------
-------------*/ |
| 149 |
| 150 PyTypeObject AdjacencyIterator_Type = { |
| 151 PyVarObject_HEAD_INIT(NULL, 0) |
| 152 "AdjacencyIterator", /* tp_name */ |
| 153 sizeof(BPy_AdjacencyIterator), /* tp_basicsize */ |
| 154 0, /* tp_itemsize */ |
| 155 0, /* tp_dealloc */ |
| 156 0, /* tp_print */ |
| 157 0, /* tp_getattr */ |
| 158 0, /* tp_setattr */ |
| 159 0, /* tp_reserved */ |
| 160 0, /* tp_repr */ |
| 161 0, /* tp_as_number */ |
| 162 0, /* tp_as_sequence */ |
| 163 0, /* tp_as_mapping */ |
| 164 0, /* tp_hash */ |
| 165 0, /* tp_call */ |
| 166 0, /* tp_str */ |
| 167 0, /* tp_getattro */ |
| 168 0, /* tp_setattro */ |
| 169 0, /* tp_as_buffer */ |
| 170 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ |
| 171 AdjacencyIterator_doc, /* tp_doc */ |
| 172 0, /* tp_traverse */ |
| 173 0, /* tp_clear */ |
| 174 0, /* tp_richcompare */ |
| 175 0, /* tp_weaklistoffset */ |
| 176 PyObject_SelfIter, /* tp_iter */ |
| 177 (iternextfunc)AdjacencyIterator_iternext, /* tp_iternext */ |
| 178 0, /* tp_methods */ |
| 179 0, /* tp_members */ |
| 180 BPy_AdjacencyIterator_getseters, /* tp_getset */ |
| 181 &Iterator_Type, /* tp_base */ |
| 182 0, /* tp_dict */ |
| 183 0, /* tp_descr_get */ |
| 184 0, /* tp_descr_set */ |
| 185 0, /* tp_dictoffset */ |
| 186 (initproc)AdjacencyIterator_init, /* tp_init */ |
| 187 0, /* tp_alloc */ |
| 188 0, /* tp_new */ |
| 189 }; |
| 190 |
| 191 ////////////////////////////////////////////////////////////////////////////////
/////////// |
| 192 |
| 193 #ifdef __cplusplus |
| 194 } |
| 195 #endif |
OLD | NEW |