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