Blender V5.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
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--------------------------------
27int Interface1D_Init(PyObject *module)
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
116static PyObject *Interface1D_repr(BPy_Interface1D *self)
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 " :param 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,
175 kwds,
176 "|" /* Optional arguments. */
177 "f" /* `t` */
178 ":points_begin",
179 (char **)kwlist,
180 &f))
181 {
182 return nullptr;
183 }
184 Interface0DIterator if0D_it(self->if1D->pointsBegin(f));
186}
187
189 /* Wrap. */
190 Interface1D_points_end_doc,
191 ".. method:: points_end(t=0.0)\n"
192 "\n"
193 " Returns an iterator over the Interface1D points, pointing after the\n"
194 " last point. The difference with vertices_end() is that here we can\n"
195 " iterate over points of the 1D element at a given sampling. Indeed,\n"
196 " for each iteration, a virtual point is created.\n"
197 "\n"
198 " :param t: A sampling with which we want to iterate over points of\n"
199 " this 1D element.\n"
200 " :type t: float\n"
201 " :return: An Interface0DIterator pointing after the last point.\n"
202 " :rtype: :class:`Interface0DIterator`\n");
203static PyObject *Interface1D_points_end(BPy_Interface1D *self, PyObject *args, PyObject *kwds)
204{
205 static const char *kwlist[] = {"t", nullptr};
206 float f = 0.0f;
207
208 if (!PyArg_ParseTupleAndKeywords(args,
209 kwds,
210 "|" /* Optional arguments. */
211 "f" /* `t` */
212 ":points_end",
213 (char **)kwlist,
214 &f))
215 {
216 return nullptr;
217 }
218 Interface0DIterator if0D_it(self->if1D->pointsEnd(f));
220}
221
222#ifdef __GNUC__
223# ifdef __clang__
224# pragma clang diagnostic push
225# pragma clang diagnostic ignored "-Wcast-function-type"
226# else
227# pragma GCC diagnostic push
228# pragma GCC diagnostic ignored "-Wcast-function-type"
229# endif
230#endif
231
232static PyMethodDef BPy_Interface1D_methods[] = {
233 {"vertices_begin",
234 (PyCFunction)Interface1D_vertices_begin,
235 METH_NOARGS,
236 Interface1D_vertices_begin_doc},
237 {"vertices_end",
238 (PyCFunction)Interface1D_vertices_end,
239 METH_NOARGS,
240 Interface1D_vertices_end_doc},
241 {"points_begin",
242 (PyCFunction)Interface1D_points_begin,
243 METH_VARARGS | METH_KEYWORDS,
244 Interface1D_points_begin_doc},
245 {"points_end",
246 (PyCFunction)Interface1D_points_end,
247 METH_VARARGS | METH_KEYWORDS,
248 Interface1D_points_end_doc},
249 {nullptr, nullptr, 0, nullptr},
250};
251
252#ifdef __GNUC__
253# ifdef __clang__
254# pragma clang diagnostic pop
255# else
256# pragma GCC diagnostic pop
257# endif
258#endif
259
260/*----------------------Interface1D get/setters ----------------------------*/
261
263 /* Wrap. */
264 Interface1D_name_doc,
265 "The string of the name of the 1D element.\n"
266 "\n"
267 ":type: str\n");
268static PyObject *Interface1D_name_get(BPy_Interface1D *self, void * /*closure*/)
269{
270 return PyUnicode_FromString(Py_TYPE(self)->tp_name);
271}
272
274 /* Wrap. */
275 Interface1D_id_doc,
276 "The Id of this Interface1D.\n"
277 "\n"
278 ":type: :class:`Id`\n");
279static PyObject *Interface1D_id_get(BPy_Interface1D *self, void * /*closure*/)
280{
281 Id id(self->if1D->getId());
282 if (PyErr_Occurred()) {
283 return nullptr;
284 }
285 return BPy_Id_from_Id(id); // return a copy
286}
287
289 /* Wrap. */
290 Interface1D_nature_doc,
291 "The nature of this Interface1D.\n"
292 "\n"
293 ":type: :class:`Nature`\n");
294static PyObject *Interface1D_nature_get(BPy_Interface1D *self, void * /*closure*/)
295{
296 Nature::VertexNature nature = self->if1D->getNature();
297 if (PyErr_Occurred()) {
298 return nullptr;
299 }
300 return BPy_Nature_from_Nature(nature);
301}
302
304 /* Wrap. */
305 Interface1D_length_2d_doc,
306 "The 2D length of this Interface1D.\n"
307 "\n"
308 ":type: float\n");
309static PyObject *Interface1D_length_2d_get(BPy_Interface1D *self, void * /*closure*/)
310{
311 real length = self->if1D->getLength2D();
312 if (PyErr_Occurred()) {
313 return nullptr;
314 }
315 return PyFloat_FromDouble(double(length));
316}
317
319 /* Wrap. */
320 Interface1D_time_stamp_doc,
321 "The time stamp of the 1D element, mainly used for selection.\n"
322 "\n"
323 ":type: int\n");
324static PyObject *Interface1D_time_stamp_get(BPy_Interface1D *self, void * /*closure*/)
325{
326 return PyLong_FromLong(self->if1D->getTimeStamp());
327}
328
329static int Interface1D_time_stamp_set(BPy_Interface1D *self, PyObject *value, void * /*closure*/)
330{
331 int timestamp;
332
333 if ((timestamp = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) {
334 PyErr_SetString(PyExc_TypeError, "value must be a number");
335 return -1;
336 }
337 self->if1D->setTimeStamp(timestamp);
338 return 0;
339}
340
341static PyGetSetDef BPy_Interface1D_getseters[] = {
342 {"name", (getter)Interface1D_name_get, (setter) nullptr, Interface1D_name_doc, nullptr},
343 {"id", (getter)Interface1D_id_get, (setter) nullptr, Interface1D_id_doc, nullptr},
344 {"nature", (getter)Interface1D_nature_get, (setter) nullptr, Interface1D_nature_doc, nullptr},
345 {"length_2d",
347 (setter) nullptr,
348 Interface1D_length_2d_doc,
349 nullptr},
350 {"time_stamp",
353 Interface1D_time_stamp_doc,
354 nullptr},
355 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
356};
357
358/*-----------------------BPy_Interface1D type definition ------------------------------*/
359
360PyTypeObject Interface1D_Type = {
361 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
362 /*tp_name*/ "Interface1D",
363 /*tp_basicsize*/ sizeof(BPy_Interface1D),
364 /*tp_itemsize*/ 0,
365 /*tp_dealloc*/ (destructor)Interface1D_dealloc,
366 /*tp_vectorcall_offset*/ 0,
367 /*tp_getattr*/ nullptr,
368 /*tp_setattr*/ nullptr,
369 /*tp_as_async*/ nullptr,
370 /*tp_repr*/ (reprfunc)Interface1D_repr,
371 /*tp_as_number*/ nullptr,
372 /*tp_as_sequence*/ nullptr,
373 /*tp_as_mapping*/ nullptr,
374 /*tp_hash*/ nullptr,
375 /*tp_call*/ nullptr,
376 /*tp_str*/ nullptr,
377 /*tp_getattro*/ nullptr,
378 /*tp_setattro*/ nullptr,
379 /*tp_as_buffer*/ nullptr,
380 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
381 /*tp_doc*/ Interface1D_doc,
382 /*tp_traverse*/ nullptr,
383 /*tp_clear*/ nullptr,
384 /*tp_richcompare*/ nullptr,
385 /*tp_weaklistoffset*/ 0,
386 /*tp_iter*/ nullptr,
387 /*tp_iternext*/ nullptr,
388 /*tp_methods*/ BPy_Interface1D_methods,
389 /*tp_members*/ nullptr,
390 /*tp_getset*/ BPy_Interface1D_getseters,
391 /*tp_base*/ nullptr,
392 /*tp_dict*/ nullptr,
393 /*tp_descr_get*/ nullptr,
394 /*tp_descr_set*/ nullptr,
395 /*tp_dictoffset*/ 0,
396 /*tp_init*/ (initproc)Interface1D_init,
397 /*tp_alloc*/ nullptr,
398 /*tp_new*/ PyType_GenericNew,
399};
400
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
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
PyTypeObject FrsCurve_Type
#define ADD_TYPE_CONST(id)
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)
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
virtual Interface0DIterator verticesEnd()
virtual Interface0DIterator pointsEnd(float t=0.0f)
virtual Nature::EdgeNature getNature() const
virtual Interface0DIterator verticesBegin()
virtual string getExactTypeName() const
virtual uint getTimeStamp() const
virtual real getLength2D() const
void setTimeStamp(uint iTimeStamp)
virtual Interface0DIterator pointsBegin(float t=0.0f)
virtual Id getId() const
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
PyObject_HEAD Freestyle::Interface1D * if1D