Blender V5.0
BPy_Interface1D.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BPy_Interface1D.h"
10
11#include "BPy_Convert.h"
19
20#include "BPy_MediumType.h"
21
22using namespace Freestyle;
23
25
26//-------------------MODULE INITIALIZATION--------------------------------
28{
29 if (module == nullptr) {
30 return -1;
31 }
32
33 if (PyType_Ready(&Interface1D_Type) < 0) {
34 return -1;
35 }
36 PyModule_AddObjectRef(module, "Interface1D", (PyObject *)&Interface1D_Type);
37
38 if (PyType_Ready(&FrsCurve_Type) < 0) {
39 return -1;
40 }
41 PyModule_AddObjectRef(module, "Curve", (PyObject *)&FrsCurve_Type);
42
43 if (PyType_Ready(&Chain_Type) < 0) {
44 return -1;
45 }
46 PyModule_AddObjectRef(module, "Chain", (PyObject *)&Chain_Type);
47
48 if (PyType_Ready(&FEdge_Type) < 0) {
49 return -1;
50 }
51 PyModule_AddObjectRef(module, "FEdge", (PyObject *)&FEdge_Type);
52
53 if (PyType_Ready(&FEdgeSharp_Type) < 0) {
54 return -1;
55 }
56 PyModule_AddObjectRef(module, "FEdgeSharp", (PyObject *)&FEdgeSharp_Type);
57
58 if (PyType_Ready(&FEdgeSmooth_Type) < 0) {
59 return -1;
60 }
61 PyModule_AddObjectRef(module, "FEdgeSmooth", (PyObject *)&FEdgeSmooth_Type);
62
63 if (PyType_Ready(&Stroke_Type) < 0) {
64 return -1;
65 }
66 PyModule_AddObjectRef(module, "Stroke", (PyObject *)&Stroke_Type);
67
68#define ADD_TYPE_CONST(id) \
69 PyLong_subtype_add_to_dict(Stroke_Type.tp_dict, &MediumType_Type, STRINGIFY(id), Stroke::id)
70 ADD_TYPE_CONST(DRY_MEDIUM);
71 ADD_TYPE_CONST(HUMID_MEDIUM);
72 ADD_TYPE_CONST(OPAQUE_MEDIUM);
73#undef ADD_TYPE_CONST
74
75 if (PyType_Ready(&ViewEdge_Type) < 0) {
76 return -1;
77 }
78 PyModule_AddObjectRef(module, "ViewEdge", (PyObject *)&ViewEdge_Type);
79
82
83 return 0;
84}
85
86/*----------------------Interface1D methods ----------------------------*/
87
89 /* Wrap. */
90 Interface1D_doc,
91 "Base class for any 1D element.\n"
92 "\n"
93 ".. method:: __init__()\n"
94 "\n"
95 " Default constructor.\n");
96static int Interface1D_init(BPy_Interface1D *self, PyObject *args, PyObject *kwds)
97{
98 static const char *kwlist[] = {nullptr};
99
100 if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
101 return -1;
102 }
103 self->if1D = new Interface1D();
104 self->borrowed = false;
105 return 0;
106}
107
109{
110 if (self->if1D && !self->borrowed) {
111 delete self->if1D;
112 }
113 Py_TYPE(self)->tp_free((PyObject *)self);
114}
115
117{
118 return PyUnicode_FromFormat(
119 "type: %s - address: %p", self->if1D->getExactTypeName().c_str(), self->if1D);
120}
121
123 /* Wrap. */
124 Interface1D_vertices_begin_doc,
125 ".. method:: vertices_begin()\n"
126 "\n"
127 " Returns an iterator over the Interface1D vertices, pointing to the\n"
128 " first vertex.\n"
129 "\n"
130 " :return: An Interface0DIterator pointing to the first vertex.\n"
131 " :rtype: :class:`Interface0DIterator`\n");
133{
134 Interface0DIterator if0D_it(self->if1D->verticesBegin());
136}
137
139 /* Wrap. */
140 Interface1D_vertices_end_doc,
141 ".. method:: vertices_end()\n"
142 "\n"
143 " Returns an iterator over the Interface1D vertices, pointing after\n"
144 " the last vertex.\n"
145 "\n"
146 " :return: An Interface0DIterator pointing after the last vertex.\n"
147 " :rtype: :class:`Interface0DIterator`\n");
149{
150 Interface0DIterator if0D_it(self->if1D->verticesEnd());
152}
153
155 /* Wrap. */
156 Interface1D_points_begin_doc,
157 ".. method:: points_begin(t=0.0)\n"
158 "\n"
159 " Returns an iterator over the Interface1D points, pointing to the\n"
160 " first point. The difference with vertices_begin() is that here we can\n"
161 " iterate over points of the 1D element at a any given sampling.\n"
162 " Indeed, for each iteration, a virtual point is created.\n"
163 "\n"
164 " :arg t: A sampling with which we want to iterate over points of\n"
165 " this 1D element.\n"
166 " :type t: float\n"
167 " :return: An Interface0DIterator pointing to the first point.\n"
168 " :rtype: :class:`Interface0DIterator`\n");
169static PyObject *Interface1D_points_begin(BPy_Interface1D *self, PyObject *args, PyObject *kwds)
170{
171 static const char *kwlist[] = {"t", nullptr};
172 float f = 0.0f;
173
174 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|f", (char **)kwlist, &f)) {
175 return nullptr;
176 }
177 Interface0DIterator if0D_it(self->if1D->pointsBegin(f));
179}
180
182 /* Wrap. */
183 Interface1D_points_end_doc,
184 ".. method:: points_end(t=0.0)\n"
185 "\n"
186 " Returns an iterator over the Interface1D points, pointing after the\n"
187 " last point. The difference with vertices_end() is that here we can\n"
188 " iterate over points of the 1D element at a given sampling. Indeed,\n"
189 " for each iteration, a virtual point is created.\n"
190 "\n"
191 " :arg t: A sampling with which we want to iterate over points of\n"
192 " this 1D element.\n"
193 " :type t: float\n"
194 " :return: An Interface0DIterator pointing after the last point.\n"
195 " :rtype: :class:`Interface0DIterator`\n");
196static PyObject *Interface1D_points_end(BPy_Interface1D *self, PyObject *args, PyObject *kwds)
197{
198 static const char *kwlist[] = {"t", nullptr};
199 float f = 0.0f;
200
201 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|f", (char **)kwlist, &f)) {
202 return nullptr;
203 }
204 Interface0DIterator if0D_it(self->if1D->pointsEnd(f));
206}
207
208#ifdef __GNUC__
209# ifdef __clang__
210# pragma clang diagnostic push
211# pragma clang diagnostic ignored "-Wcast-function-type"
212# else
213# pragma GCC diagnostic push
214# pragma GCC diagnostic ignored "-Wcast-function-type"
215# endif
216#endif
217
218static PyMethodDef BPy_Interface1D_methods[] = {
219 {"vertices_begin",
220 (PyCFunction)Interface1D_vertices_begin,
221 METH_NOARGS,
222 Interface1D_vertices_begin_doc},
223 {"vertices_end",
224 (PyCFunction)Interface1D_vertices_end,
225 METH_NOARGS,
226 Interface1D_vertices_end_doc},
227 {"points_begin",
228 (PyCFunction)Interface1D_points_begin,
229 METH_VARARGS | METH_KEYWORDS,
230 Interface1D_points_begin_doc},
231 {"points_end",
232 (PyCFunction)Interface1D_points_end,
233 METH_VARARGS | METH_KEYWORDS,
234 Interface1D_points_end_doc},
235 {nullptr, nullptr, 0, nullptr},
236};
237
238#ifdef __GNUC__
239# ifdef __clang__
240# pragma clang diagnostic pop
241# else
242# pragma GCC diagnostic pop
243# endif
244#endif
245
246/*----------------------Interface1D get/setters ----------------------------*/
247
249 /* Wrap. */
250 Interface1D_name_doc,
251 "The string of the name of the 1D element.\n"
252 "\n"
253 ":type: str\n");
254static PyObject *Interface1D_name_get(BPy_Interface1D *self, void * /*closure*/)
255{
256 return PyUnicode_FromString(Py_TYPE(self)->tp_name);
257}
258
260 /* Wrap. */
261 Interface1D_id_doc,
262 "The Id of this Interface1D.\n"
263 "\n"
264 ":type: :class:`Id`\n");
265static PyObject *Interface1D_id_get(BPy_Interface1D *self, void * /*closure*/)
266{
267 Id id(self->if1D->getId());
268 if (PyErr_Occurred()) {
269 return nullptr;
270 }
271 return BPy_Id_from_Id(id); // return a copy
272}
273
275 /* Wrap. */
276 Interface1D_nature_doc,
277 "The nature of this Interface1D.\n"
278 "\n"
279 ":type: :class:`Nature`\n");
280static PyObject *Interface1D_nature_get(BPy_Interface1D *self, void * /*closure*/)
281{
282 Nature::VertexNature nature = self->if1D->getNature();
283 if (PyErr_Occurred()) {
284 return nullptr;
285 }
286 return BPy_Nature_from_Nature(nature);
287}
288
290 /* Wrap. */
291 Interface1D_length_2d_doc,
292 "The 2D length of this Interface1D.\n"
293 "\n"
294 ":type: float\n");
295static PyObject *Interface1D_length_2d_get(BPy_Interface1D *self, void * /*closure*/)
296{
297 real length = self->if1D->getLength2D();
298 if (PyErr_Occurred()) {
299 return nullptr;
300 }
301 return PyFloat_FromDouble(double(length));
302}
303
305 /* Wrap. */
306 Interface1D_time_stamp_doc,
307 "The time stamp of the 1D element, mainly used for selection.\n"
308 "\n"
309 ":type: int\n");
310static PyObject *Interface1D_time_stamp_get(BPy_Interface1D *self, void * /*closure*/)
311{
312 return PyLong_FromLong(self->if1D->getTimeStamp());
313}
314
315static int Interface1D_time_stamp_set(BPy_Interface1D *self, PyObject *value, void * /*closure*/)
316{
317 int timestamp;
318
319 if ((timestamp = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) {
320 PyErr_SetString(PyExc_TypeError, "value must be a number");
321 return -1;
322 }
323 self->if1D->setTimeStamp(timestamp);
324 return 0;
325}
326
327static PyGetSetDef BPy_Interface1D_getseters[] = {
328 {"name", (getter)Interface1D_name_get, (setter) nullptr, Interface1D_name_doc, nullptr},
329 {"id", (getter)Interface1D_id_get, (setter) nullptr, Interface1D_id_doc, nullptr},
330 {"nature", (getter)Interface1D_nature_get, (setter) nullptr, Interface1D_nature_doc, nullptr},
331 {"length_2d",
333 (setter) nullptr,
334 Interface1D_length_2d_doc,
335 nullptr},
336 {"time_stamp",
339 Interface1D_time_stamp_doc,
340 nullptr},
341 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
342};
343
344/*-----------------------BPy_Interface1D type definition ------------------------------*/
345
346PyTypeObject Interface1D_Type = {
347 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
348 /*tp_name*/ "Interface1D",
349 /*tp_basicsize*/ sizeof(BPy_Interface1D),
350 /*tp_itemsize*/ 0,
351 /*tp_dealloc*/ (destructor)Interface1D_dealloc,
352 /*tp_vectorcall_offset*/ 0,
353 /*tp_getattr*/ nullptr,
354 /*tp_setattr*/ nullptr,
355 /*tp_as_async*/ nullptr,
356 /*tp_repr*/ (reprfunc)Interface1D_repr,
357 /*tp_as_number*/ nullptr,
358 /*tp_as_sequence*/ nullptr,
359 /*tp_as_mapping*/ nullptr,
360 /*tp_hash*/ nullptr,
361 /*tp_call*/ nullptr,
362 /*tp_str*/ nullptr,
363 /*tp_getattro*/ nullptr,
364 /*tp_setattro*/ nullptr,
365 /*tp_as_buffer*/ nullptr,
366 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
367 /*tp_doc*/ Interface1D_doc,
368 /*tp_traverse*/ nullptr,
369 /*tp_clear*/ nullptr,
370 /*tp_richcompare*/ nullptr,
371 /*tp_weaklistoffset*/ 0,
372 /*tp_iter*/ nullptr,
373 /*tp_iternext*/ nullptr,
374 /*tp_methods*/ BPy_Interface1D_methods,
375 /*tp_members*/ nullptr,
376 /*tp_getset*/ BPy_Interface1D_getseters,
377 /*tp_base*/ nullptr,
378 /*tp_dict*/ nullptr,
379 /*tp_descr_get*/ nullptr,
380 /*tp_descr_set*/ nullptr,
381 /*tp_dictoffset*/ 0,
382 /*tp_init*/ (initproc)Interface1D_init,
383 /*tp_alloc*/ nullptr,
384 /*tp_new*/ PyType_GenericNew,
385};
386
PyTypeObject Chain_Type
PyObject * BPy_Interface0DIterator_from_Interface0DIterator(Interface0DIterator &if0D_it, bool reversed)
PyObject * BPy_Id_from_Id(Id &id)
PyObject * BPy_Nature_from_Nature(ushort n)
PyTypeObject FEdgeSharp_Type
void FEdgeSharp_mathutils_register_callback()
void FEdgeSmooth_mathutils_register_callback()
PyTypeObject FEdgeSmooth_Type
PyTypeObject FEdge_Type
PyTypeObject FrsCurve_Type
static void Interface1D_dealloc(BPy_Interface1D *self)
static PyObject * Interface1D_time_stamp_get(BPy_Interface1D *self, void *)
static PyObject * Interface1D_length_2d_get(BPy_Interface1D *self, void *)
static PyObject * Interface1D_id_get(BPy_Interface1D *self, void *)
static PyObject * Interface1D_vertices_begin(BPy_Interface1D *self)
static PyObject * Interface1D_points_end(BPy_Interface1D *self, PyObject *args, PyObject *kwds)
static PyObject * Interface1D_repr(BPy_Interface1D *self)
#define ADD_TYPE_CONST(id)
PyTypeObject Interface1D_Type
static int Interface1D_time_stamp_set(BPy_Interface1D *self, PyObject *value, void *)
static PyObject * Interface1D_name_get(BPy_Interface1D *self, void *)
static int Interface1D_init(BPy_Interface1D *self, PyObject *args, PyObject *kwds)
int Interface1D_Init(PyObject *module)
static PyObject * Interface1D_points_begin(BPy_Interface1D *self, PyObject *args, PyObject *kwds)
PyDoc_STRVAR(Interface1D_doc, "Base class for any 1D element.\n" "\n" ".. method:: __init__()\n" "\n" " Default constructor.\n")
static PyObject * Interface1D_nature_get(BPy_Interface1D *self, void *)
static PyGetSetDef BPy_Interface1D_getseters[]
static PyMethodDef BPy_Interface1D_methods[]
static PyObject * Interface1D_vertices_end(BPy_Interface1D *self)
PyTypeObject Stroke_Type
PyTypeObject ViewEdge_Type
PyObject * self
float length(VecOp< float, D >) RET
ushort VertexNature
Definition Nature.h:22
inherits from class Rep
Definition AppCanvas.cpp:20
double real
Definition Precision.h:14
static struct PyModuleDef module
Definition python.cpp:796