Blender  V2.93
BPy_CurvePointIterator.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 
21 #include "BPy_CurvePointIterator.h"
22 
23 #include "../BPy_Convert.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 using namespace Freestyle;
31 
33 
34 //------------------------INSTANCE METHODS ----------------------------------
35 
36 PyDoc_STRVAR(CurvePointIterator_doc,
37  "Class hierarchy: :class:`Iterator` > :class:`CurvePointIterator`\n"
38  "\n"
39  "Class representing an iterator on a curve. Allows an iterating\n"
40  "outside initial vertices. A CurvePoint is instantiated and returned\n"
41  "through the .object attribute.\n"
42  "\n"
43  ".. method:: __init__()\n"
44  " __init__(brother)\n"
45  " __init__(step=0.0)\n"
46  "\n"
47  " Builds a CurvePointIterator object using either the default constructor,\n"
48  " copy constructor, or the overloaded constructor.\n"
49  "\n"
50  " :arg brother: A CurvePointIterator object.\n"
51  " :type brother: :class:`CurvePointIterator`\n"
52  " :arg step: A resampling resolution with which the curve is resampled.\n"
53  " If zero, no resampling is done (i.e., the iterator iterates over\n"
54  " initial vertices).\n"
55  " :type step: float");
56 
57 static int CurvePointIterator_init(BPy_CurvePointIterator *self, PyObject *args, PyObject *kwds)
58 {
59  static const char *kwlist_1[] = {"brother", nullptr};
60  static const char *kwlist_2[] = {"step", nullptr};
61  PyObject *brother = nullptr;
62  float step;
63 
64  if (PyArg_ParseTupleAndKeywords(
65  args, kwds, "|O!", (char **)kwlist_1, &CurvePointIterator_Type, &brother)) {
66  if (!brother) {
67  self->cp_it = new CurveInternal::CurvePointIterator();
68  }
69  else {
70  self->cp_it = new CurveInternal::CurvePointIterator(
71  *(((BPy_CurvePointIterator *)brother)->cp_it));
72  }
73  }
74  else if ((void)PyErr_Clear(),
75  PyArg_ParseTupleAndKeywords(args, kwds, "f", (char **)kwlist_2, &step)) {
76  self->cp_it = new CurveInternal::CurvePointIterator(step);
77  }
78  else {
79  PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
80  return -1;
81  }
82  self->py_it.it = self->cp_it;
83  return 0;
84 }
85 
86 /*----------------------CurvePointIterator get/setters ----------------------------*/
87 
88 PyDoc_STRVAR(CurvePointIterator_object_doc,
89  "The CurvePoint object currently pointed by this iterator.\n"
90  "\n"
91  ":type: :class:`CurvePoint`");
92 
93 static PyObject *CurvePointIterator_object_get(BPy_CurvePointIterator *self, void *UNUSED(closure))
94 {
95  if (self->cp_it->isEnd()) {
96  PyErr_SetString(PyExc_RuntimeError, "iteration has stopped");
97  return nullptr;
98  }
99  return BPy_CurvePoint_from_CurvePoint(self->cp_it->operator*());
100 }
101 
102 PyDoc_STRVAR(CurvePointIterator_t_doc,
103  "The curvilinear abscissa of the current point.\n"
104  "\n"
105  ":type: float");
106 
107 static PyObject *CurvePointIterator_t_get(BPy_CurvePointIterator *self, void *UNUSED(closure))
108 {
109  return PyFloat_FromDouble(self->cp_it->t());
110 }
111 
112 PyDoc_STRVAR(CurvePointIterator_u_doc,
113  "The point parameter at the current point in the stroke (0 <= u <= 1).\n"
114  "\n"
115  ":type: float");
116 
117 static PyObject *CurvePointIterator_u_get(BPy_CurvePointIterator *self, void *UNUSED(closure))
118 {
119  return PyFloat_FromDouble(self->cp_it->u());
120 }
121 
122 static PyGetSetDef BPy_CurvePointIterator_getseters[] = {
123  {"object",
125  (setter) nullptr,
126  CurvePointIterator_object_doc,
127  nullptr},
128  {"t", (getter)CurvePointIterator_t_get, (setter) nullptr, CurvePointIterator_t_doc, nullptr},
129  {"u", (getter)CurvePointIterator_u_get, (setter) nullptr, CurvePointIterator_u_doc, nullptr},
130  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
131 };
132 
133 /*-----------------------BPy_CurvePointIterator type definition ------------------------------*/
134 
135 PyTypeObject CurvePointIterator_Type = {
136  PyVarObject_HEAD_INIT(nullptr, 0) "CurvePointIterator", /* tp_name */
137  sizeof(BPy_CurvePointIterator), /* tp_basicsize */
138  0, /* tp_itemsize */
139  nullptr, /* tp_dealloc */
140  0, /* tp_vectorcall_offset */
141  nullptr, /* tp_getattr */
142  nullptr, /* tp_setattr */
143  nullptr, /* tp_reserved */
144  nullptr, /* tp_repr */
145  nullptr, /* tp_as_number */
146  nullptr, /* tp_as_sequence */
147  nullptr, /* tp_as_mapping */
148  nullptr, /* tp_hash */
149  nullptr, /* tp_call */
150  nullptr, /* tp_str */
151  nullptr, /* tp_getattro */
152  nullptr, /* tp_setattro */
153  nullptr, /* tp_as_buffer */
154  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
155  CurvePointIterator_doc, /* tp_doc */
156  nullptr, /* tp_traverse */
157  nullptr, /* tp_clear */
158  nullptr, /* tp_richcompare */
159  0, /* tp_weaklistoffset */
160  nullptr, /* tp_iter */
161  nullptr, /* tp_iternext */
162  nullptr, /* tp_methods */
163  nullptr, /* tp_members */
164  BPy_CurvePointIterator_getseters, /* tp_getset */
165  &Iterator_Type, /* tp_base */
166  nullptr, /* tp_dict */
167  nullptr, /* tp_descr_get */
168  nullptr, /* tp_descr_set */
169  0, /* tp_dictoffset */
170  (initproc)CurvePointIterator_init, /* tp_init */
171  nullptr, /* tp_alloc */
172  nullptr, /* tp_new */
173 };
174 
176 
177 #ifdef __cplusplus
178 }
179 #endif
#define UNUSED(x)
PyObject * BPy_CurvePoint_from_CurvePoint(CurvePoint &cp)
static PyObject * CurvePointIterator_u_get(BPy_CurvePointIterator *self, void *UNUSED(closure))
static int CurvePointIterator_init(BPy_CurvePointIterator *self, PyObject *args, PyObject *kwds)
static PyGetSetDef BPy_CurvePointIterator_getseters[]
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 instantiated and returned\n" "through the .object attribute.\n" "\n" ".. method:: __init__()\n" " __init__(brother)\n" " __init__(step=0.0)\n" "\n" " Builds a CurvePointIterator object using either the default constructor,\n" " copy constructor, or the overloaded constructor.\n" "\n" " :arg brother: A CurvePointIterator object.\n" " :type brother: :class:`CurvePointIterator`\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 PyObject * CurvePointIterator_object_get(BPy_CurvePointIterator *self, void *UNUSED(closure))
PyTypeObject CurvePointIterator_Type
static PyObject * CurvePointIterator_t_get(BPy_CurvePointIterator *self, void *UNUSED(closure))
PyTypeObject Iterator_Type
PyObject * self
Definition: bpy_driver.c:185
inherits from class Rep
Definition: AppCanvas.cpp:32