Blender V4.3
BPy_FEdgeSharp.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_FEdgeSharp.h"
10
11#include "../../BPy_Convert.h"
13
14#include "BLI_sys_types.h"
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20using namespace Freestyle;
21
23
24/*----------------------FEdgeSharp methods ----------------------------*/
25
27 /* Wrap. */
28 FEdgeSharp_doc,
29 "Class hierarchy: :class:`Interface1D` > :class:`FEdge` > :class:`FEdgeSharp`\n"
30 "\n"
31 "Class defining a sharp FEdge. A Sharp FEdge corresponds to an initial\n"
32 "edge of the input mesh. It can be a silhouette, a crease or a border.\n"
33 "If it is a crease edge, then it is bordered by two faces of the mesh.\n"
34 "Face a lies on its right whereas Face b lies on its left. If it is a\n"
35 "border edge, then it doesn't have any face on its right, and thus Face\n"
36 "a is None.\n"
37 "\n"
38 ".. method:: __init__()\n"
39 " __init__(brother)\n"
40 " __init__(first_vertex, second_vertex)\n"
41 "\n"
42 " Builds an :class:`FEdgeSharp` using the default constructor,\n"
43 " copy constructor, or between two :class:`SVertex` objects.\n"
44 "\n"
45 " :arg brother: An FEdgeSharp object.\n"
46 " :type brother: :class:`FEdgeSharp`\n"
47 " :arg first_vertex: The first SVertex object.\n"
48 " :type first_vertex: :class:`SVertex`\n"
49 " :arg second_vertex: The second SVertex object.\n"
50 " :type second_vertex: :class:`SVertex`");
51
52static int FEdgeSharp_init(BPy_FEdgeSharp *self, PyObject *args, PyObject *kwds)
53{
54 static const char *kwlist_1[] = {"brother", nullptr};
55 static const char *kwlist_2[] = {"first_vertex", "second_vertex", nullptr};
56 PyObject *obj1 = nullptr, *obj2 = nullptr;
57
58 if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdgeSharp_Type, &obj1)) {
59 if (!obj1) {
60 self->fes = new FEdgeSharp();
61 }
62 else {
63 self->fes = new FEdgeSharp(*(((BPy_FEdgeSharp *)obj1)->fes));
64 }
65 }
66 else if ((void)PyErr_Clear(),
67 PyArg_ParseTupleAndKeywords(
68 args, kwds, "O!O!", (char **)kwlist_2, &SVertex_Type, &obj1, &SVertex_Type, &obj2))
69 {
70 self->fes = new FEdgeSharp(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv);
71 }
72 else {
73 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
74 return -1;
75 }
76 self->py_fe.fe = self->fes;
77 self->py_fe.py_if1D.if1D = self->fes;
78 self->py_fe.py_if1D.borrowed = false;
79 return 0;
80}
81
82/*----------------------mathutils callbacks ----------------------------*/
83
84/* subtype */
85#define MATHUTILS_SUBTYPE_NORMAL_A 1
86#define MATHUTILS_SUBTYPE_NORMAL_B 2
87
89{
90 if (!BPy_FEdgeSharp_Check(bmo->cb_user)) {
91 return -1;
92 }
93 return 0;
94}
95
96static int FEdgeSharp_mathutils_get(BaseMathObject *bmo, int subtype)
97{
98 BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user;
99 switch (subtype) {
101 Vec3r p(self->fes->normalA());
102 bmo->data[0] = p[0];
103 bmo->data[1] = p[1];
104 bmo->data[2] = p[2];
105 break;
106 }
108 Vec3r p(self->fes->normalB());
109 bmo->data[0] = p[0];
110 bmo->data[1] = p[1];
111 bmo->data[2] = p[2];
112 break;
113 }
114 default:
115 return -1;
116 }
117 return 0;
118}
119
120static int FEdgeSharp_mathutils_set(BaseMathObject *bmo, int subtype)
121{
122 BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user;
123 switch (subtype) {
125 Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]);
126 self->fes->setNormalA(p);
127 break;
128 }
130 Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]);
131 self->fes->setNormalB(p);
132 break;
133 }
134 default:
135 return -1;
136 }
137 return 0;
138}
139
140static int FEdgeSharp_mathutils_get_index(BaseMathObject *bmo, int subtype, int index)
141{
142 BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user;
143 switch (subtype) {
145 Vec3r p(self->fes->normalA());
146 bmo->data[index] = p[index];
147 break;
148 }
150 Vec3r p(self->fes->normalB());
151 bmo->data[index] = p[index];
152 break;
153 }
154 default:
155 return -1;
156 }
157 return 0;
158}
159
160static int FEdgeSharp_mathutils_set_index(BaseMathObject *bmo, int subtype, int index)
161{
162 BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user;
163 switch (subtype) {
165 Vec3r p(self->fes->normalA());
166 p[index] = bmo->data[index];
167 self->fes->setNormalA(p);
168 break;
169 }
171 Vec3r p(self->fes->normalB());
172 p[index] = bmo->data[index];
173 self->fes->setNormalB(p);
174 break;
175 }
176 default:
177 return -1;
178 }
179 return 0;
180}
181
189
191
196
197/*----------------------FEdgeSharp get/setters ----------------------------*/
198
200 /* Wrap. */
201 FEdgeSharp_normal_right_doc,
202 "The normal to the face lying on the right of the FEdge. If this FEdge\n"
203 "is a border, it has no Face on its right and therefore no normal.\n"
204 "\n"
205 ":type: :class:`mathutils.Vector`");
206
207static PyObject *FEdgeSharp_normal_right_get(BPy_FEdgeSharp *self, void * /*closure*/)
208{
211}
212
213static int FEdgeSharp_normal_right_set(BPy_FEdgeSharp *self, PyObject *value, void * /*closure*/)
214{
215 float v[3];
216 if (mathutils_array_parse(v, 3, 3, value, "value must be a 3-dimensional vector") == -1) {
217 return -1;
218 }
219 Vec3r p(v[0], v[1], v[2]);
220 self->fes->setNormalA(p);
221 return 0;
222}
223
225 /* Wrap. */
226 FEdgeSharp_normal_left_doc,
227 "The normal to the face lying on the left of the FEdge.\n"
228 "\n"
229 ":type: :class:`mathutils.Vector`");
230
231static PyObject *FEdgeSharp_normal_left_get(BPy_FEdgeSharp *self, void * /*closure*/)
232{
235}
236
237static int FEdgeSharp_normal_left_set(BPy_FEdgeSharp *self, PyObject *value, void * /*closure*/)
238{
239 float v[3];
240 if (mathutils_array_parse(v, 3, 3, value, "value must be a 3-dimensional vector") == -1) {
241 return -1;
242 }
243 Vec3r p(v[0], v[1], v[2]);
244 self->fes->setNormalB(p);
245 return 0;
246}
247
249 /* Wrap. */
250 FEdgeSharp_material_index_right_doc,
251 "The index of the material of the face lying on the right of the FEdge.\n"
252 "If this FEdge is a border, it has no Face on its right and therefore\n"
253 "no material.\n"
254 "\n"
255 ":type: int");
256
257static PyObject *FEdgeSharp_material_index_right_get(BPy_FEdgeSharp *self, void * /*closure*/)
258{
259 return PyLong_FromLong(self->fes->aFrsMaterialIndex());
260}
261
263 PyObject *value,
264 void * /*closure*/)
265{
266 uint i = PyLong_AsUnsignedLong(value);
267 if (PyErr_Occurred()) {
268 return -1;
269 }
270 self->fes->setaFrsMaterialIndex(i);
271 return 0;
272}
273
275 /* Wrap. */
276 FEdgeSharp_material_index_left_doc,
277 "The index of the material of the face lying on the left of the FEdge.\n"
278 "\n"
279 ":type: int");
280
281static PyObject *FEdgeSharp_material_index_left_get(BPy_FEdgeSharp *self, void * /*closure*/)
282{
283 return PyLong_FromLong(self->fes->bFrsMaterialIndex());
284}
285
287 PyObject *value,
288 void * /*closure*/)
289{
290 uint i = PyLong_AsUnsignedLong(value);
291 if (PyErr_Occurred()) {
292 return -1;
293 }
294 self->fes->setbFrsMaterialIndex(i);
295 return 0;
296}
297
299 /* Wrap. */
300 FEdgeSharp_material_right_doc,
301 "The material of the face lying on the right of the FEdge. If this FEdge\n"
302 "is a border, it has no Face on its right and therefore no material.\n"
303 "\n"
304 ":type: :class:`Material`");
305
306static PyObject *FEdgeSharp_material_right_get(BPy_FEdgeSharp *self, void * /*closure*/)
307{
308 return BPy_FrsMaterial_from_FrsMaterial(self->fes->aFrsMaterial());
309}
310
312 /* Wrap. */
313 FEdgeSharp_material_left_doc,
314 "The material of the face lying on the left of the FEdge.\n"
315 "\n"
316 ":type: :class:`Material`");
317
318static PyObject *FEdgeSharp_material_left_get(BPy_FEdgeSharp *self, void * /*closure*/)
319{
320 return BPy_FrsMaterial_from_FrsMaterial(self->fes->bFrsMaterial());
321}
322
324 /* Wrap. */
325 FEdgeSharp_face_mark_right_doc,
326 "The face mark of the face lying on the right of the FEdge. If this FEdge\n"
327 "is a border, it has no face on the right and thus this property is set to\n"
328 "false.\n"
329 "\n"
330 ":type: bool");
331
332static PyObject *FEdgeSharp_face_mark_right_get(BPy_FEdgeSharp *self, void * /*closure*/)
333{
334 return PyBool_from_bool(self->fes->aFaceMark());
335}
336
338 PyObject *value,
339 void * /*closure*/)
340{
341 if (!PyBool_Check(value)) {
342 return -1;
343 }
344 self->fes->setaFaceMark(bool_from_PyBool(value));
345 return 0;
346}
347
349 /* Wrap. */
350 FEdgeSharp_face_mark_left_doc,
351 "The face mark of the face lying on the left of the FEdge.\n"
352 "\n"
353 ":type: bool");
354
355static PyObject *FEdgeSharp_face_mark_left_get(BPy_FEdgeSharp *self, void * /*closure*/)
356{
357 return PyBool_from_bool(self->fes->bFaceMark());
358}
359
360static int FEdgeSharp_face_mark_left_set(BPy_FEdgeSharp *self, PyObject *value, void * /*closure*/)
361{
362 if (!PyBool_Check(value)) {
363 return -1;
364 }
365 self->fes->setbFaceMark(bool_from_PyBool(value));
366 return 0;
367}
368
369static PyGetSetDef BPy_FEdgeSharp_getseters[] = {
370 {"normal_right",
373 FEdgeSharp_normal_right_doc,
374 nullptr},
375 {"normal_left",
378 FEdgeSharp_normal_left_doc,
379 nullptr},
380 {"material_index_right",
383 FEdgeSharp_material_index_right_doc,
384 nullptr},
385 {"material_index_left",
388 FEdgeSharp_material_index_left_doc,
389 nullptr},
390 {"material_right",
392 (setter) nullptr,
393 FEdgeSharp_material_right_doc,
394 nullptr},
395 {"material_left",
397 (setter) nullptr,
398 FEdgeSharp_material_left_doc,
399 nullptr},
400 {"face_mark_right",
403 FEdgeSharp_face_mark_right_doc,
404 nullptr},
405 {"face_mark_left",
408 FEdgeSharp_face_mark_left_doc,
409 nullptr},
410 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
411};
412
413/*-----------------------BPy_FEdgeSharp type definition ------------------------------*/
414
415PyTypeObject FEdgeSharp_Type = {
416 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
417 /*tp_name*/ "FEdgeSharp",
418 /*tp_basicsize*/ sizeof(BPy_FEdgeSharp),
419 /*tp_itemsize*/ 0,
420 /*tp_dealloc*/ nullptr,
421 /*tp_vectorcall_offset*/ 0,
422 /*tp_getattr*/ nullptr,
423 /*tp_setattr*/ nullptr,
424 /*tp_as_async*/ nullptr,
425 /*tp_repr*/ nullptr,
426 /*tp_as_number*/ nullptr,
427 /*tp_as_sequence*/ nullptr,
428 /*tp_as_mapping*/ nullptr,
429 /*tp_hash*/ nullptr,
430 /*tp_call*/ nullptr,
431 /*tp_str*/ nullptr,
432 /*tp_getattro*/ nullptr,
433 /*tp_setattro*/ nullptr,
434 /*tp_as_buffer*/ nullptr,
435 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
436 /*tp_doc*/ FEdgeSharp_doc,
437 /*tp_traverse*/ nullptr,
438 /*tp_clear*/ nullptr,
439 /*tp_richcompare*/ nullptr,
440 /*tp_weaklistoffset*/ 0,
441 /*tp_iter*/ nullptr,
442 /*tp_iternext*/ nullptr,
443 /*tp_methods*/ nullptr,
444 /*tp_members*/ nullptr,
445 /*tp_getset*/ BPy_FEdgeSharp_getseters,
446 /*tp_base*/ &FEdge_Type,
447 /*tp_dict*/ nullptr,
448 /*tp_descr_get*/ nullptr,
449 /*tp_descr_set*/ nullptr,
450 /*tp_dictoffset*/ 0,
451 /*tp_init*/ (initproc)FEdgeSharp_init,
452 /*tp_alloc*/ nullptr,
453 /*tp_new*/ nullptr,
454};
455
457
458#ifdef __cplusplus
459}
460#endif
unsigned char uchar
unsigned int uint
bool bool_from_PyBool(PyObject *b)
PyObject * PyBool_from_bool(bool b)
PyObject * BPy_FrsMaterial_from_FrsMaterial(const FrsMaterial &m)
static PyObject * FEdgeSharp_normal_left_get(BPy_FEdgeSharp *self, void *)
#define MATHUTILS_SUBTYPE_NORMAL_B
static int FEdgeSharp_mathutils_set(BaseMathObject *bmo, int subtype)
PyDoc_STRVAR(FEdgeSharp_doc, "Class hierarchy: :class:`Interface1D` > :class:`FEdge` > :class:`FEdgeSharp`\n" "\n" "Class defining a sharp FEdge. A Sharp FEdge corresponds to an initial\n" "edge of the input mesh. It can be a silhouette, a crease or a border.\n" "If it is a crease edge, then it is bordered by two faces of the mesh.\n" "Face a lies on its right whereas Face b lies on its left. If it is a\n" "border edge, then it doesn't have any face on its right, and thus Face\n" "a is None.\n" "\n" ".. method:: __init__()\n" " __init__(brother)\n" " __init__(first_vertex, second_vertex)\n" "\n" " Builds an :class:`FEdgeSharp` using the default constructor,\n" " copy constructor, or between two :class:`SVertex` objects.\n" "\n" " :arg brother: An FEdgeSharp object.\n" " :type brother: :class:`FEdgeSharp`\n" " :arg first_vertex: The first SVertex object.\n" " :type first_vertex: :class:`SVertex`\n" " :arg second_vertex: The second SVertex object.\n" " :type second_vertex: :class:`SVertex`")
static int FEdgeSharp_normal_left_set(BPy_FEdgeSharp *self, PyObject *value, void *)
static uchar FEdgeSharp_mathutils_cb_index
static int FEdgeSharp_face_mark_left_set(BPy_FEdgeSharp *self, PyObject *value, void *)
static PyObject * FEdgeSharp_material_left_get(BPy_FEdgeSharp *self, void *)
static PyObject * FEdgeSharp_face_mark_left_get(BPy_FEdgeSharp *self, void *)
static int FEdgeSharp_face_mark_right_set(BPy_FEdgeSharp *self, PyObject *value, void *)
static int FEdgeSharp_mathutils_get(BaseMathObject *bmo, int subtype)
static int FEdgeSharp_normal_right_set(BPy_FEdgeSharp *self, PyObject *value, void *)
static int FEdgeSharp_init(BPy_FEdgeSharp *self, PyObject *args, PyObject *kwds)
static PyObject * FEdgeSharp_normal_right_get(BPy_FEdgeSharp *self, void *)
static PyObject * FEdgeSharp_face_mark_right_get(BPy_FEdgeSharp *self, void *)
#define MATHUTILS_SUBTYPE_NORMAL_A
static int FEdgeSharp_material_index_right_set(BPy_FEdgeSharp *self, PyObject *value, void *)
static PyObject * FEdgeSharp_material_index_right_get(BPy_FEdgeSharp *self, void *)
static int FEdgeSharp_material_index_left_set(BPy_FEdgeSharp *self, PyObject *value, void *)
PyTypeObject FEdgeSharp_Type
static Mathutils_Callback FEdgeSharp_mathutils_cb
static PyObject * FEdgeSharp_material_right_get(BPy_FEdgeSharp *self, void *)
static int FEdgeSharp_mathutils_set_index(BaseMathObject *bmo, int subtype, int index)
static int FEdgeSharp_mathutils_get_index(BaseMathObject *bmo, int subtype, int index)
void FEdgeSharp_mathutils_register_callback()
static PyObject * FEdgeSharp_material_index_left_get(BPy_FEdgeSharp *self, void *)
static int FEdgeSharp_mathutils_check(BaseMathObject *bmo)
static PyGetSetDef BPy_FEdgeSharp_getseters[]
#define BPy_FEdgeSharp_Check(v)
PyTypeObject FEdge_Type
PyTypeObject SVertex_Type
ATTR_WARN_UNUSED_RESULT const BMVert * v
PyObject * self
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