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