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