Blender V4.5
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.");
96
97static int Interface1D_init(BPy_Interface1D *self, PyObject *args, PyObject *kwds)
98{
99 static const char *kwlist[] = {nullptr};
100
101 if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
102 return -1;
103 }
104 self->if1D = new Interface1D();
105 self->borrowed = false;
106 return 0;
107}
108
110{
111 if (self->if1D && !self->borrowed) {
112 delete self->if1D;
113 }
114 Py_TYPE(self)->tp_free((PyObject *)self);
115}
116
118{
119 return PyUnicode_FromFormat(
120 "type: %s - address: %p", self->if1D->getExactTypeName().c_str(), self->if1D);
121}
122
124 /* Wrap. */
125 Interface1D_vertices_begin_doc,
126 ".. method:: vertices_begin()\n"
127 "\n"
128 " Returns an iterator over the Interface1D vertices, pointing to the\n"
129 " first vertex.\n"
130 "\n"
131 " :return: An Interface0DIterator pointing to the first vertex.\n"
132 " :rtype: :class:`Interface0DIterator`");
133
135{
136 Interface0DIterator if0D_it(self->if1D->verticesBegin());
138}
139
141 /* Wrap. */
142 Interface1D_vertices_end_doc,
143 ".. method:: vertices_end()\n"
144 "\n"
145 " Returns an iterator over the Interface1D vertices, pointing after\n"
146 " the last vertex.\n"
147 "\n"
148 " :return: An Interface0DIterator pointing after the last vertex.\n"
149 " :rtype: :class:`Interface0DIterator`");
150
152{
153 Interface0DIterator if0D_it(self->if1D->verticesEnd());
155}
156
158 /* Wrap. */
159 Interface1D_points_begin_doc,
160 ".. method:: points_begin(t=0.0)\n"
161 "\n"
162 " Returns an iterator over the Interface1D points, pointing to the\n"
163 " first point. The difference with vertices_begin() is that here we can\n"
164 " iterate over points of the 1D element at a any given sampling.\n"
165 " Indeed, for each iteration, a virtual point is created.\n"
166 "\n"
167 " :arg t: A sampling with which we want to iterate over points of\n"
168 " this 1D element.\n"
169 " :type t: float\n"
170 " :return: An Interface0DIterator pointing to the first point.\n"
171 " :rtype: :class:`Interface0DIterator`");
172
173static PyObject *Interface1D_points_begin(BPy_Interface1D *self, PyObject *args, PyObject *kwds)
174{
175 static const char *kwlist[] = {"t", nullptr};
176 float f = 0.0f;
177
178 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|f", (char **)kwlist, &f)) {
179 return nullptr;
180 }
181 Interface0DIterator if0D_it(self->if1D->pointsBegin(f));
183}
184
186 /* Wrap. */
187 Interface1D_points_end_doc,
188 ".. method:: points_end(t=0.0)\n"
189 "\n"
190 " Returns an iterator over the Interface1D points, pointing after the\n"
191 " last point. The difference with vertices_end() is that here we can\n"
192 " iterate over points of the 1D element at a given sampling. Indeed,\n"
193 " for each iteration, a virtual point is created.\n"
194 "\n"
195 " :arg t: A sampling with which we want to iterate over points of\n"
196 " this 1D element.\n"
197 " :type t: float\n"
198 " :return: An Interface0DIterator pointing after the last point.\n"
199 " :rtype: :class:`Interface0DIterator`");
200
201static PyObject *Interface1D_points_end(BPy_Interface1D *self, PyObject *args, PyObject *kwds)
202{
203 static const char *kwlist[] = {"t", nullptr};
204 float f = 0.0f;
205
206 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|f", (char **)kwlist, &f)) {
207 return nullptr;
208 }
209 Interface0DIterator if0D_it(self->if1D->pointsEnd(f));
211}
212
213#ifdef __GNUC__
214# ifdef __clang__
215# pragma clang diagnostic push
216# pragma clang diagnostic ignored "-Wcast-function-type"
217# else
218# pragma GCC diagnostic push
219# pragma GCC diagnostic ignored "-Wcast-function-type"
220# endif
221#endif
222
223static PyMethodDef BPy_Interface1D_methods[] = {
224 {"vertices_begin",
225 (PyCFunction)Interface1D_vertices_begin,
226 METH_NOARGS,
227 Interface1D_vertices_begin_doc},
228 {"vertices_end",
229 (PyCFunction)Interface1D_vertices_end,
230 METH_NOARGS,
231 Interface1D_vertices_end_doc},
232 {"points_begin",
233 (PyCFunction)Interface1D_points_begin,
234 METH_VARARGS | METH_KEYWORDS,
235 Interface1D_points_begin_doc},
236 {"points_end",
237 (PyCFunction)Interface1D_points_end,
238 METH_VARARGS | METH_KEYWORDS,
239 Interface1D_points_end_doc},
240 {nullptr, nullptr, 0, nullptr},
241};
242
243#ifdef __GNUC__
244# ifdef __clang__
245# pragma clang diagnostic pop
246# else
247# pragma GCC diagnostic pop
248# endif
249#endif
250
251/*----------------------Interface1D get/setters ----------------------------*/
252
254 /* Wrap. */
255 Interface1D_name_doc,
256 "The string of the name of the 1D element.\n"
257 "\n"
258 ":type: str");
259
260static PyObject *Interface1D_name_get(BPy_Interface1D *self, void * /*closure*/)
261{
262 return PyUnicode_FromString(Py_TYPE(self)->tp_name);
263}
264
266 /* Wrap. */
267 Interface1D_id_doc,
268 "The Id of this Interface1D.\n"
269 "\n"
270 ":type: :class:`Id`");
271
272static PyObject *Interface1D_id_get(BPy_Interface1D *self, void * /*closure*/)
273{
274 Id id(self->if1D->getId());
275 if (PyErr_Occurred()) {
276 return nullptr;
277 }
278 return BPy_Id_from_Id(id); // return a copy
279}
280
282 /* Wrap. */
283 Interface1D_nature_doc,
284 "The nature of this Interface1D.\n"
285 "\n"
286 ":type: :class:`Nature`");
287
288static PyObject *Interface1D_nature_get(BPy_Interface1D *self, void * /*closure*/)
289{
290 Nature::VertexNature nature = self->if1D->getNature();
291 if (PyErr_Occurred()) {
292 return nullptr;
293 }
294 return BPy_Nature_from_Nature(nature);
295}
296
298 /* Wrap. */
299 Interface1D_length_2d_doc,
300 "The 2D length of this Interface1D.\n"
301 "\n"
302 ":type: float");
303
304static PyObject *Interface1D_length_2d_get(BPy_Interface1D *self, void * /*closure*/)
305{
306 real length = self->if1D->getLength2D();
307 if (PyErr_Occurred()) {
308 return nullptr;
309 }
310 return PyFloat_FromDouble(double(length));
311}
312
314 /* Wrap. */
315 Interface1D_time_stamp_doc,
316 "The time stamp of the 1D element, mainly used for selection.\n"
317 "\n"
318 ":type: int");
319
320static PyObject *Interface1D_time_stamp_get(BPy_Interface1D *self, void * /*closure*/)
321{
322 return PyLong_FromLong(self->if1D->getTimeStamp());
323}
324
325static int Interface1D_time_stamp_set(BPy_Interface1D *self, PyObject *value, void * /*closure*/)
326{
327 int timestamp;
328
329 if ((timestamp = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) {
330 PyErr_SetString(PyExc_TypeError, "value must be a number");
331 return -1;
332 }
333 self->if1D->setTimeStamp(timestamp);
334 return 0;
335}
336
337static PyGetSetDef BPy_Interface1D_getseters[] = {
338 {"name", (getter)Interface1D_name_get, (setter) nullptr, Interface1D_name_doc, nullptr},
339 {"id", (getter)Interface1D_id_get, (setter) nullptr, Interface1D_id_doc, nullptr},
340 {"nature", (getter)Interface1D_nature_get, (setter) nullptr, Interface1D_nature_doc, nullptr},
341 {"length_2d",
343 (setter) nullptr,
344 Interface1D_length_2d_doc,
345 nullptr},
346 {"time_stamp",
349 Interface1D_time_stamp_doc,
350 nullptr},
351 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
352};
353
354/*-----------------------BPy_Interface1D type definition ------------------------------*/
355
356PyTypeObject Interface1D_Type = {
357 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
358 /*tp_name*/ "Interface1D",
359 /*tp_basicsize*/ sizeof(BPy_Interface1D),
360 /*tp_itemsize*/ 0,
361 /*tp_dealloc*/ (destructor)Interface1D_dealloc,
362 /*tp_vectorcall_offset*/ 0,
363 /*tp_getattr*/ nullptr,
364 /*tp_setattr*/ nullptr,
365 /*tp_as_async*/ nullptr,
366 /*tp_repr*/ (reprfunc)Interface1D_repr,
367 /*tp_as_number*/ nullptr,
368 /*tp_as_sequence*/ nullptr,
369 /*tp_as_mapping*/ nullptr,
370 /*tp_hash*/ nullptr,
371 /*tp_call*/ nullptr,
372 /*tp_str*/ nullptr,
373 /*tp_getattro*/ nullptr,
374 /*tp_setattro*/ nullptr,
375 /*tp_as_buffer*/ nullptr,
376 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
377 /*tp_doc*/ Interface1D_doc,
378 /*tp_traverse*/ nullptr,
379 /*tp_clear*/ nullptr,
380 /*tp_richcompare*/ nullptr,
381 /*tp_weaklistoffset*/ 0,
382 /*tp_iter*/ nullptr,
383 /*tp_iternext*/ nullptr,
384 /*tp_methods*/ BPy_Interface1D_methods,
385 /*tp_members*/ nullptr,
386 /*tp_getset*/ BPy_Interface1D_getseters,
387 /*tp_base*/ nullptr,
388 /*tp_dict*/ nullptr,
389 /*tp_descr_get*/ nullptr,
390 /*tp_descr_set*/ nullptr,
391 /*tp_dictoffset*/ 0,
392 /*tp_init*/ (initproc)Interface1D_init,
393 /*tp_alloc*/ nullptr,
394 /*tp_new*/ PyType_GenericNew,
395};
396
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)
PyDoc_STRVAR(Interface1D_doc, "Base class for any 1D element.\n" "\n" ".. method:: __init__()\n" "\n" " Default constructor.")
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)
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