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