Blender  V2.93
BPy_Interface0DIterator.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
22 
23 #include "../BPy_Convert.h"
24 #include "../BPy_Interface1D.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 using namespace Freestyle;
31 
33 
34 //------------------------INSTANCE METHODS ----------------------------------
35 
36 PyDoc_STRVAR(Interface0DIterator_doc,
37  "Class hierarchy: :class:`Iterator` > :class:`Interface0DIterator`\n"
38  "\n"
39  "Class defining an iterator over Interface0D elements. An instance of\n"
40  "this iterator is always obtained from a 1D element.\n"
41  "\n"
42  ".. method:: __init__(brother)\n"
43  " __init__(it)\n"
44  "\n"
45  " Construct a nested Interface0DIterator using either the copy constructor\n"
46  " or the constructor that takes an he argument of a Function0D.\n"
47  "\n"
48  " :arg brother: An Interface0DIterator object.\n"
49  " :type brother: :class:`Interface0DIterator`\n"
50  " :arg it: An iterator object to be nested.\n"
51  " :type it: :class:`SVertexIterator`, :class:`CurvePointIterator`, or\n"
52  " :class:`StrokeVertexIterator`");
53 
54 static int convert_nested_it(PyObject *obj, void *v)
55 {
56  if (!obj || !BPy_Iterator_Check(obj)) {
57  return 0;
58  }
59  Interface0DIteratorNested *nested_it = dynamic_cast<Interface0DIteratorNested *>(
60  ((BPy_Iterator *)obj)->it);
61  if (!nested_it) {
62  return 0;
63  }
64  *((Interface0DIteratorNested **)v) = nested_it;
65  return 1;
66 }
67 
68 static int Interface0DIterator_init(BPy_Interface0DIterator *self, PyObject *args, PyObject *kwds)
69 {
70  static const char *kwlist_1[] = {"it", nullptr};
71  static const char *kwlist_2[] = {"inter", nullptr};
72  static const char *kwlist_3[] = {"brother", nullptr};
73  Interface0DIteratorNested *nested_it;
74  PyObject *brother, *inter;
75 
76  if (PyArg_ParseTupleAndKeywords(
77  args, kwds, "O&", (char **)kwlist_1, convert_nested_it, &nested_it)) {
78  self->if0D_it = new Interface0DIterator(nested_it->copy());
79  self->at_start = true;
80  self->reversed = false;
81  }
82  else if ((void)PyErr_Clear(),
83  PyArg_ParseTupleAndKeywords(
84  args, kwds, "O!", (char **)kwlist_2, &Interface1D_Type, &inter)) {
85  self->if0D_it = new Interface0DIterator(((BPy_Interface1D *)inter)->if1D->verticesBegin());
86  self->at_start = true;
87  self->reversed = false;
88  }
89  else if ((void)PyErr_Clear(),
90  PyArg_ParseTupleAndKeywords(
91  args, kwds, "O!", (char **)kwlist_3, &Interface0DIterator_Type, &brother)) {
92  self->if0D_it = new Interface0DIterator(*(((BPy_Interface0DIterator *)brother)->if0D_it));
93  self->at_start = ((BPy_Interface0DIterator *)brother)->at_start;
94  self->reversed = ((BPy_Interface0DIterator *)brother)->reversed;
95  }
96  else {
97  PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
98  return -1;
99  }
100  self->py_it.it = self->if0D_it;
101  return 0;
102 }
103 
105 {
106  Py_INCREF(self);
107  self->at_start = true;
108  return (PyObject *)self;
109 }
110 
112 {
113  if (self->reversed) {
114  if (self->if0D_it->isBegin()) {
115  PyErr_SetNone(PyExc_StopIteration);
116  return nullptr;
117  }
118  self->if0D_it->decrement();
119  }
120  else {
121  if (self->if0D_it->isEnd()) {
122  PyErr_SetNone(PyExc_StopIteration);
123  return nullptr;
124  }
125  if (self->at_start) {
126  self->at_start = false;
127  }
128  else if (self->if0D_it->atLast()) {
129  PyErr_SetNone(PyExc_StopIteration);
130  return nullptr;
131  }
132  else {
133  self->if0D_it->increment();
134  }
135  }
136  Interface0D *if0D = self->if0D_it->operator->();
138 }
139 
140 /*----------------------Interface0DIterator get/setters ----------------------------*/
141 
142 PyDoc_STRVAR(Interface0DIterator_object_doc,
143  "The 0D object currently pointed to by this iterator. Note that the object\n"
144  "may be an instance of an Interface0D subclass. For example if the iterator\n"
145  "has been created from the `vertices_begin()` method of the :class:`Stroke`\n"
146  "class, the .object property refers to a :class:`StrokeVertex` object.\n"
147  "\n"
148  ":type: :class:`Interface0D` or one of its subclasses.");
149 
151  void *UNUSED(closure))
152 {
153  if (self->if0D_it->isEnd()) {
154  PyErr_SetString(PyExc_RuntimeError, "iteration has stopped");
155  return nullptr;
156  }
157  return Any_BPy_Interface0D_from_Interface0D(self->if0D_it->operator*());
158 }
159 
160 PyDoc_STRVAR(Interface0DIterator_t_doc,
161  "The curvilinear abscissa of the current point.\n"
162  "\n"
163  ":type: float");
164 
165 static PyObject *Interface0DIterator_t_get(BPy_Interface0DIterator *self, void *UNUSED(closure))
166 {
167  return PyFloat_FromDouble(self->if0D_it->t());
168 }
169 
170 PyDoc_STRVAR(Interface0DIterator_u_doc,
171  "The point parameter at the current point in the 1D element (0 <= u <= 1).\n"
172  "\n"
173  ":type: float");
174 
175 static PyObject *Interface0DIterator_u_get(BPy_Interface0DIterator *self, void *UNUSED(closure))
176 {
177  return PyFloat_FromDouble(self->if0D_it->u());
178 }
179 
180 PyDoc_STRVAR(Interface0DIterator_at_last_doc,
181  "True if the iterator points to the last valid element.\n"
182  "For its counterpart (pointing to the first valid element), use it.is_begin.\n"
183  "\n"
184  ":type: bool");
185 
187  void *UNUSED(closure))
188 {
189  return PyBool_from_bool(self->if0D_it->atLast());
190 }
191 
192 static PyGetSetDef BPy_Interface0DIterator_getseters[] = {
193  {"object",
195  (setter) nullptr,
196  Interface0DIterator_object_doc,
197  nullptr},
198  {"t", (getter)Interface0DIterator_t_get, (setter) nullptr, Interface0DIterator_t_doc, nullptr},
199  {"u", (getter)Interface0DIterator_u_get, (setter) nullptr, Interface0DIterator_u_doc, nullptr},
200  {"at_last",
202  (setter) nullptr,
203  Interface0DIterator_at_last_doc,
204  nullptr},
205  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
206 };
207 
208 /*-----------------------BPy_Interface0DIterator type definition ------------------------------*/
209 
210 PyTypeObject Interface0DIterator_Type = {
211  PyVarObject_HEAD_INIT(nullptr, 0) "Interface0DIterator", /* tp_name */
212  sizeof(BPy_Interface0DIterator), /* tp_basicsize */
213  0, /* tp_itemsize */
214  nullptr, /* tp_dealloc */
215  0, /* tp_vectorcall_offset */
216  nullptr, /* tp_getattr */
217  nullptr, /* tp_setattr */
218  nullptr, /* tp_reserved */
219  nullptr, /* tp_repr */
220  nullptr, /* tp_as_number */
221  nullptr, /* tp_as_sequence */
222  nullptr, /* tp_as_mapping */
223  nullptr, /* tp_hash */
224  nullptr, /* tp_call */
225  nullptr, /* tp_str */
226  nullptr, /* tp_getattro */
227  nullptr, /* tp_setattro */
228  nullptr, /* tp_as_buffer */
229  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
230  Interface0DIterator_doc, /* tp_doc */
231  nullptr, /* tp_traverse */
232  nullptr, /* tp_clear */
233  nullptr, /* tp_richcompare */
234  0, /* tp_weaklistoffset */
235  (getiterfunc)Interface0DIterator_iter, /* tp_iter */
236  (iternextfunc)Interface0DIterator_iternext, /* tp_iternext */
237  nullptr, /* tp_methods */
238  nullptr, /* tp_members */
239  BPy_Interface0DIterator_getseters, /* tp_getset */
240  &Iterator_Type, /* tp_base */
241  nullptr, /* tp_dict */
242  nullptr, /* tp_descr_get */
243  nullptr, /* tp_descr_set */
244  0, /* tp_dictoffset */
245  (initproc)Interface0DIterator_init, /* tp_init */
246  nullptr, /* tp_alloc */
247  nullptr, /* tp_new */
248 };
249 
251 
252 #ifdef __cplusplus
253 }
254 #endif
#define UNUSED(x)
PyObject * PyBool_from_bool(bool b)
Definition: BPy_Convert.cpp:73
PyObject * Any_BPy_Interface0D_from_Interface0D(Interface0D &if0D)
static PyObject * Interface0DIterator_iternext(BPy_Interface0DIterator *self)
static int Interface0DIterator_init(BPy_Interface0DIterator *self, PyObject *args, PyObject *kwds)
static PyObject * Interface0DIterator_u_get(BPy_Interface0DIterator *self, void *UNUSED(closure))
static PyObject * Interface0DIterator_object_get(BPy_Interface0DIterator *self, void *UNUSED(closure))
static int convert_nested_it(PyObject *obj, void *v)
static PyObject * Interface0DIterator_iter(BPy_Interface0DIterator *self)
static PyObject * Interface0DIterator_t_get(BPy_Interface0DIterator *self, void *UNUSED(closure))
static PyObject * Interface0DIterator_at_last_get(BPy_Interface0DIterator *self, void *UNUSED(closure))
static PyGetSetDef BPy_Interface0DIterator_getseters[]
PyTypeObject Interface0DIterator_Type
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" " __init__(it)\n" "\n" " Construct a nested Interface0DIterator using either the copy constructor\n" " or the constructor that takes an he argument of a Function0D.\n" "\n" " :arg brother: An Interface0DIterator object.\n" " :type brother: :class:`Interface0DIterator`\n" " :arg it: An iterator object to be nested.\n" " :type it: :class:`SVertexIterator`, :class:`CurvePointIterator`, or\n" " :class:`StrokeVertexIterator`")
PyTypeObject Interface1D_Type
PyTypeObject Iterator_Type
#define BPy_Iterator_Check(v)
Definition: BPy_Iterator.h:37
ATTR_WARN_UNUSED_RESULT const BMVert * v
PyObject * self
Definition: bpy_driver.c:185
inherits from class Rep
Definition: AppCanvas.cpp:32