Blender V5.3
BPy_StrokeVertex.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BPy_StrokeVertex.h"
10
11#include "../../BPy_Convert.h"
12#include "../../BPy_Freestyle.h"
15
16using namespace Freestyle;
17
19
20//------------------------INSTANCE METHODS ----------------------------------
21
23 /* Wrap. */
24 StrokeVertex_doc,
25 "Class hierarchy: :class:`Interface0D` > :class:`CurvePoint` > :class:`StrokeVertex`\n"
26 "\n"
27 "Class to define a stroke vertex.\n"
28 "\n"
29 ".. method:: __init__(*args)\n"
30 "\n"
31 " Accepted call signatures:\n"
32 "\n"
33 " - ``__init__()``\n"
34 " - ``__init__(brother)``\n"
35 " - ``__init__(first_vertex, second_vertex, t3d)``\n"
36 " - ``__init__(point)``\n"
37 " - ``__init__(svertex)``\n"
38 " - ``__init__(svertex, attribute)``\n"
39 "\n"
40 " Builds a :class:`StrokeVertex` using the default constructor,\n"
41 " copy constructor, from 2 :class:`StrokeVertex` and an interpolation parameter,\n"
42 " from a CurvePoint, from a SVertex, or a :class:`SVertex`"
43 " and a :class:`StrokeAttribute` object.\n"
44 "\n"
45 " :param brother: A StrokeVertex object.\n"
46 " :type brother: :class:`StrokeVertex`\n"
47 " :param first_vertex: The first StrokeVertex.\n"
48 " :type first_vertex: :class:`StrokeVertex`\n"
49 " :param second_vertex: The second StrokeVertex.\n"
50 " :type second_vertex: :class:`StrokeVertex`\n"
51 " :param t3d: An interpolation parameter.\n"
52 " :type t3d: float\n"
53 " :param point: A CurvePoint object.\n"
54 " :type point: :class:`CurvePoint`\n"
55 " :param svertex: An SVertex object.\n"
56 " :type svertex: :class:`SVertex`\n"
57 " :param svertex: An SVertex object.\n"
58 " :type svertex: :class:`SVertex`\n"
59 " :param attribute: A StrokeAttribute object.\n"
60 " :type attribute: :class:`StrokeAttribute`\n");
61static int StrokeVertex_init(BPy_StrokeVertex *self, PyObject *args, PyObject *kwds)
62{
63 static const char *kwlist_1[] = {"brother", nullptr};
64 static const char *kwlist_2[] = {"first_vertex", "second_vertex", "t3d", nullptr};
65 static const char *kwlist_3[] = {"point", nullptr};
66 static const char *kwlist_4[] = {"svertex", "attribute", nullptr};
67 PyObject *obj1 = nullptr, *obj2 = nullptr;
68 float t3d;
69
70 if (PyArg_ParseTupleAndKeywords(args,
71 kwds,
72 "|" /* Optional arguments. */
73 "O!" /* `brother` */
74 ":__init__",
75 (char **)kwlist_1,
77 &obj1))
78 {
79 if (!obj1) {
80 self->sv = new StrokeVertex();
81 }
82 else {
83 if (!((BPy_StrokeVertex *)obj1)->sv) {
84 PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid StrokeVertex object");
85 return -1;
86 }
87 self->sv = new StrokeVertex(*(((BPy_StrokeVertex *)obj1)->sv));
88 }
89 }
90 else if ((void)PyErr_Clear(),
91 PyArg_ParseTupleAndKeywords(args,
92 kwds,
93 "O!" /* `first_vertex` */
94 "O!" /* `second_vertex` */
95 "f" /* `t3d` */
96 ":__init__",
97 (char **)kwlist_2,
99 &obj1,
101 &obj2,
102 &t3d))
103 {
104 StrokeVertex *sv1 = ((BPy_StrokeVertex *)obj1)->sv;
105 StrokeVertex *sv2 = ((BPy_StrokeVertex *)obj2)->sv;
106 if (!sv1 || (sv1->A() == nullptr && sv1->B() == nullptr)) {
107 PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid StrokeVertex object");
108 return -1;
109 }
110 if (!sv2 || (sv2->A() == nullptr && sv2->B() == nullptr)) {
111 PyErr_SetString(PyExc_TypeError, "argument 2 is an invalid StrokeVertex object");
112 return -1;
113 }
114 self->sv = new StrokeVertex(sv1, sv2, t3d);
115 }
116 else if ((void)PyErr_Clear(),
117 PyArg_ParseTupleAndKeywords(args,
118 kwds,
119 "O!" /* `point` */
120 ":__init__",
121 (char **)kwlist_3,
123 &obj1))
124 {
125 CurvePoint *cp = ((BPy_CurvePoint *)obj1)->cp;
126 if (!cp || cp->A() == nullptr || cp->B() == nullptr) {
127 PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid CurvePoint object");
128 return -1;
129 }
130 self->sv = new StrokeVertex(cp);
131 }
132 else if ((void)PyErr_Clear(),
133 (void)(obj2 = nullptr),
134 PyArg_ParseTupleAndKeywords(args,
135 kwds,
136 "O!" /* `svertex` */
137 "|" /* Optional arguments. */
138 "O!" /* `attribute` */
139 ":__init__",
140 (char **)kwlist_4,
142 &obj1,
144 &obj2))
145 {
146 if (!obj2) {
147 self->sv = new StrokeVertex(((BPy_SVertex *)obj1)->sv);
148 }
149 else {
150 self->sv = new StrokeVertex(((BPy_SVertex *)obj1)->sv, *(((BPy_StrokeAttribute *)obj2)->sa));
151 }
152 }
153 else {
154 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
155 return -1;
156 }
157 self->py_cp.cp = self->sv;
158 self->py_cp.py_if0D.if0D = self->sv;
159 self->py_cp.py_if0D.borrowed = false;
160 return 0;
161}
162
163// real operator[] (const int i) const
164// real & operator[] (const int i)
165
166/*----------------------mathutils callbacks ----------------------------*/
167
169{
170 if (!BPy_StrokeVertex_Check(bmo->cb_user)) {
171 return -1;
172 }
173 return 0;
174}
175
177{
178 BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user;
179 bmo->data[0] = float(self->sv->x());
180 bmo->data[1] = float(self->sv->y());
181 return 0;
182}
183
185{
186 BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user;
187 self->sv->setX((real)bmo->data[0]);
188 self->sv->setY((real)bmo->data[1]);
189 return 0;
190}
191
193 int /*subtype*/,
194 int index)
195{
196 BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user;
197 switch (index) {
198 case 0:
199 bmo->data[0] = float(self->sv->x());
200 break;
201 case 1:
202 bmo->data[1] = float(self->sv->y());
203 break;
204 default:
205 return -1;
206 }
207 return 0;
208}
209
211 int /*subtype*/,
212 int index)
213{
214 BPy_StrokeVertex *self = (BPy_StrokeVertex *)bmo->cb_user;
215 switch (index) {
216 case 0:
217 self->sv->setX((real)bmo->data[0]);
218 break;
219 case 1:
220 self->sv->setY((real)bmo->data[1]);
221 break;
222 default:
223 return -1;
224 }
225 return 0;
226}
227
235
237
242
243/*----------------------StrokeVertex get/setters ----------------------------*/
244
246 /* Wrap. */
247 StrokeVertex_attribute_doc,
248 "StrokeAttribute for this StrokeVertex.\n"
249 "\n"
250 ":type: :class:`StrokeAttribute`\n");
251static PyObject *StrokeVertex_attribute_get(BPy_StrokeVertex *self, void * /*closure*/)
252{
254}
255
256static int StrokeVertex_attribute_set(BPy_StrokeVertex *self, PyObject *value, void * /*closure*/)
257{
258 if (!BPy_StrokeAttribute_Check(value)) {
259 PyErr_SetString(PyExc_TypeError, "value must be a StrokeAttribute object");
260 return -1;
261 }
262 self->sv->setAttribute(*(((BPy_StrokeAttribute *)value)->sa));
263 return 0;
264}
265
267 /* Wrap. */
268 StrokeVertex_curvilinear_abscissa_doc,
269 "Curvilinear abscissa of this StrokeVertex in the Stroke.\n"
270 "\n"
271 ":type: float\n");
272static PyObject *StrokeVertex_curvilinear_abscissa_get(BPy_StrokeVertex *self, void * /*closure*/)
273{
274 return PyFloat_FromDouble(self->sv->curvilinearAbscissa());
275}
276
278 PyObject *value,
279 void * /*closure*/)
280{
281 float scalar;
282 if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) {
283 /* parsed item not a number */
284 PyErr_SetString(PyExc_TypeError, "value must be a number");
285 return -1;
286 }
287 self->sv->setCurvilinearAbscissa(scalar);
288 return 0;
289}
290
292 /* Wrap. */
293 StrokeVertex_point_doc,
294 "2D point coordinates.\n"
295 "\n"
296 ":type: :class:`mathutils.Vector`\n");
297static PyObject *StrokeVertex_point_get(BPy_StrokeVertex *self, void * /*closure*/)
298{
300 (PyObject *)self, 2, StrokeVertex_mathutils_cb_index, 0);
301}
302
303static int StrokeVertex_point_set(BPy_StrokeVertex *self, PyObject *value, void * /*closure*/)
304{
305 float v[2];
306 if (blender::mathutils_array_parse(v, 2, 2, value, "value must be a 2-dimensional vector") == -1)
307 {
308 return -1;
309 }
310 self->sv->setX(v[0]);
311 self->sv->setY(v[1]);
312 return 0;
313}
314
316 /* Wrap. */
317 StrokeVertex_stroke_length_doc,
318 "Stroke length (it is only a value retained by the StrokeVertex,\n"
319 "and it won't change the real stroke length).\n"
320 "\n"
321 ":type: float\n");
322static PyObject *StrokeVertex_stroke_length_get(BPy_StrokeVertex *self, void * /*closure*/)
323{
324 return PyFloat_FromDouble(self->sv->strokeLength());
325}
326
328 PyObject *value,
329 void * /*closure*/)
330{
331 float scalar;
332 if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) {
333 /* parsed item not a number */
334 PyErr_SetString(PyExc_TypeError, "value must be a number");
335 return -1;
336 }
337 self->sv->setStrokeLength(scalar);
338 return 0;
339}
340
342 /* Wrap. */
343 StrokeVertex_u_doc,
344 "Curvilinear abscissa of this StrokeVertex in the Stroke.\n"
345 "\n"
346 ":type: float\n");
347static PyObject *StrokeVertex_u_get(BPy_StrokeVertex *self, void * /*closure*/)
348{
349 return PyFloat_FromDouble(self->sv->u());
350}
351
352static PyGetSetDef BPy_StrokeVertex_getseters[] = {
353 {"attribute",
356 StrokeVertex_attribute_doc,
357 nullptr},
358 {"curvilinear_abscissa",
361 StrokeVertex_curvilinear_abscissa_doc,
362 nullptr},
363 {"point",
366 StrokeVertex_point_doc,
367 nullptr},
368 {"stroke_length",
371 StrokeVertex_stroke_length_doc,
372 nullptr},
373 {"u", (getter)StrokeVertex_u_get, (setter) nullptr, StrokeVertex_u_doc, nullptr},
374 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
375};
376
377/*-----------------------BPy_StrokeVertex type definition ------------------------------*/
378
379PyTypeObject StrokeVertex_Type = {
380 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
381 /*tp_name*/ "StrokeVertex",
382 /*tp_basicsize*/ sizeof(BPy_StrokeVertex),
383 /*tp_itemsize*/ 0,
384 /*tp_dealloc*/ nullptr,
385 /*tp_vectorcall_offset*/ 0,
386 /*tp_getattr*/ nullptr,
387 /*tp_setattr*/ nullptr,
388 /*tp_as_async*/ nullptr,
389 /*tp_repr*/ nullptr,
390 /*tp_as_number*/ nullptr,
391 /*tp_as_sequence*/ nullptr,
392 /*tp_as_mapping*/ nullptr,
393 /*tp_hash*/ nullptr,
394 /*tp_call*/ nullptr,
395 /*tp_str*/ nullptr,
396 /*tp_getattro*/ nullptr,
397 /*tp_setattro*/ nullptr,
398 /*tp_as_buffer*/ nullptr,
399 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
400 /*tp_doc*/ StrokeVertex_doc,
401 /*tp_traverse*/ nullptr,
402 /*tp_clear*/ nullptr,
403 /*tp_richcompare*/ nullptr,
404 /*tp_weaklistoffset*/ 0,
405 /*tp_iter*/ nullptr,
406 /*tp_iternext*/ nullptr,
407 /*tp_methods*/ nullptr,
408 /*tp_members*/ nullptr,
409 /*tp_getset*/ BPy_StrokeVertex_getseters,
410 /*tp_base*/ &CurvePoint_Type,
411 /*tp_dict*/ nullptr,
412 /*tp_descr_get*/ nullptr,
413 /*tp_descr_set*/ nullptr,
414 /*tp_dictoffset*/ 0,
415 /*tp_init*/ (initproc)StrokeVertex_init,
416 /*tp_alloc*/ nullptr,
417 /*tp_new*/ nullptr,
418};
419
PyObject * BPy_StrokeAttribute_from_StrokeAttribute(StrokeAttribute &sa)
PyTypeObject CurvePoint_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 SVertex_Type
PyTypeObject StrokeAttribute_Type
#define BPy_StrokeAttribute_Check(v)
static int StrokeVertex_mathutils_get_index(blender::BaseMathObject *bmo, int, int index)
static PyGetSetDef BPy_StrokeVertex_getseters[]
static int StrokeVertex_mathutils_set_index(blender::BaseMathObject *bmo, int, int index)
static blender::Mathutils_Callback StrokeVertex_mathutils_cb
static int StrokeVertex_point_set(BPy_StrokeVertex *self, PyObject *value, void *)
static int StrokeVertex_curvilinear_abscissa_set(BPy_StrokeVertex *self, PyObject *value, void *)
static PyObject * StrokeVertex_point_get(BPy_StrokeVertex *self, void *)
static PyObject * StrokeVertex_attribute_get(BPy_StrokeVertex *self, void *)
static int StrokeVertex_stroke_length_set(BPy_StrokeVertex *self, PyObject *value, void *)
static int StrokeVertex_mathutils_get(blender::BaseMathObject *bmo, int)
static int StrokeVertex_init(BPy_StrokeVertex *self, PyObject *args, PyObject *kwds)
static PyObject * StrokeVertex_curvilinear_abscissa_get(BPy_StrokeVertex *self, void *)
static PyObject * StrokeVertex_u_get(BPy_StrokeVertex *self, void *)
static uchar StrokeVertex_mathutils_cb_index
void StrokeVertex_mathutils_register_callback()
static PyObject * StrokeVertex_stroke_length_get(BPy_StrokeVertex *self, void *)
static int StrokeVertex_mathutils_check(blender::BaseMathObject *bmo)
static int StrokeVertex_attribute_set(BPy_StrokeVertex *self, PyObject *value, void *)
PyTypeObject StrokeVertex_Type
static int StrokeVertex_mathutils_set(blender::BaseMathObject *bmo, int)
#define BPy_StrokeVertex_Check(v)
SVertex * A()
Definition Curve.h:235
SVertex * B()
Definition Curve.h:241
float curvilinearAbscissa() const
Definition Stroke.h:384
void setCurvilinearAbscissa(float iAbscissa)
Definition Stroke.h:441
void setY(real y)
Definition Stroke.h:409
void setAttribute(const StrokeAttribute &iAttribute)
Definition Stroke.h:435
float u() const
Definition Stroke.h:396
float strokeLength() const
Definition Stroke.h:390
void setX(real x)
Definition Stroke.h:403
const StrokeAttribute & attribute() const
Definition Stroke.h:372
void setStrokeLength(float iLength)
Definition Stroke.h:449
#define index(i)
unsigned int uchar
inherits from class Rep
Definition AppCanvas.cpp:20
double real
Definition Precision.h:14
PyObject * Vector_CreatePyObject_cb(PyObject *cb_user, int vec_num, uchar cb_type, uchar cb_subtype)
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
Definition mathutils.cc:97
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
BPy_Interface0D py_if0D
Freestyle::CurvePoint * cp
PyObject_HEAD Freestyle::Interface0D * if0D
BPy_CurvePoint py_cp
Freestyle::StrokeVertex * sv