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