Blender V5.0
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`\n");
47static int FEdgeSharp_init(BPy_FEdgeSharp *self, PyObject *args, PyObject *kwds)
48{
49 static const char *kwlist_1[] = {"brother", nullptr};
50 static const char *kwlist_2[] = {"first_vertex", "second_vertex", nullptr};
51 PyObject *obj1 = nullptr, *obj2 = nullptr;
52
53 if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdgeSharp_Type, &obj1)) {
54 if (!obj1) {
55 self->fes = new FEdgeSharp();
56 }
57 else {
58 self->fes = new FEdgeSharp(*(((BPy_FEdgeSharp *)obj1)->fes));
59 }
60 }
61 else if ((void)PyErr_Clear(),
62 PyArg_ParseTupleAndKeywords(
63 args, kwds, "O!O!", (char **)kwlist_2, &SVertex_Type, &obj1, &SVertex_Type, &obj2))
64 {
65 self->fes = new FEdgeSharp(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv);
66 }
67 else {
68 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
69 return -1;
70 }
71 self->py_fe.fe = self->fes;
72 self->py_fe.py_if1D.if1D = self->fes;
73 self->py_fe.py_if1D.borrowed = false;
74 return 0;
75}
76
77/*----------------------mathutils callbacks ----------------------------*/
78
79/* subtype */
80#define MATHUTILS_SUBTYPE_NORMAL_A 1
81#define MATHUTILS_SUBTYPE_NORMAL_B 2
82
84{
85 if (!BPy_FEdgeSharp_Check(bmo->cb_user)) {
86 return -1;
87 }
88 return 0;
89}
90
91static int FEdgeSharp_mathutils_get(BaseMathObject *bmo, int subtype)
92{
93 BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user;
94 switch (subtype) {
96 Vec3r p(self->fes->normalA());
97 bmo->data[0] = p[0];
98 bmo->data[1] = p[1];
99 bmo->data[2] = p[2];
100 break;
101 }
103 Vec3r p(self->fes->normalB());
104 bmo->data[0] = p[0];
105 bmo->data[1] = p[1];
106 bmo->data[2] = p[2];
107 break;
108 }
109 default:
110 return -1;
111 }
112 return 0;
113}
114
115static int FEdgeSharp_mathutils_set(BaseMathObject *bmo, int subtype)
116{
117 BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user;
118 switch (subtype) {
120 Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]);
121 self->fes->setNormalA(p);
122 break;
123 }
125 Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]);
126 self->fes->setNormalB(p);
127 break;
128 }
129 default:
130 return -1;
131 }
132 return 0;
133}
134
135static int FEdgeSharp_mathutils_get_index(BaseMathObject *bmo, int subtype, int index)
136{
137 BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user;
138 switch (subtype) {
140 Vec3r p(self->fes->normalA());
141 bmo->data[index] = p[index];
142 break;
143 }
145 Vec3r p(self->fes->normalB());
146 bmo->data[index] = p[index];
147 break;
148 }
149 default:
150 return -1;
151 }
152 return 0;
153}
154
155static int FEdgeSharp_mathutils_set_index(BaseMathObject *bmo, int subtype, int index)
156{
157 BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user;
158 switch (subtype) {
160 Vec3r p(self->fes->normalA());
161 p[index] = bmo->data[index];
162 self->fes->setNormalA(p);
163 break;
164 }
166 Vec3r p(self->fes->normalB());
167 p[index] = bmo->data[index];
168 self->fes->setNormalB(p);
169 break;
170 }
171 default:
172 return -1;
173 }
174 return 0;
175}
176
184
186
191
192/*----------------------FEdgeSharp get/setters ----------------------------*/
193
195 /* Wrap. */
196 FEdgeSharp_normal_right_doc,
197 "The normal to the face lying on the right of the FEdge. If this FEdge\n"
198 "is a border, it has no Face on its right and therefore no normal.\n"
199 "\n"
200 ":type: :class:`mathutils.Vector`\n");
201static PyObject *FEdgeSharp_normal_right_get(BPy_FEdgeSharp *self, void * /*closure*/)
202{
205}
206
207static int FEdgeSharp_normal_right_set(BPy_FEdgeSharp *self, PyObject *value, void * /*closure*/)
208{
209 float v[3];
210 if (mathutils_array_parse(v, 3, 3, value, "value must be a 3-dimensional vector") == -1) {
211 return -1;
212 }
213 Vec3r p(v[0], v[1], v[2]);
214 self->fes->setNormalA(p);
215 return 0;
216}
217
219 /* Wrap. */
220 FEdgeSharp_normal_left_doc,
221 "The normal to the face lying on the left of the FEdge.\n"
222 "\n"
223 ":type: :class:`mathutils.Vector`\n");
224static PyObject *FEdgeSharp_normal_left_get(BPy_FEdgeSharp *self, void * /*closure*/)
225{
228}
229
230static int FEdgeSharp_normal_left_set(BPy_FEdgeSharp *self, PyObject *value, void * /*closure*/)
231{
232 float v[3];
233 if (mathutils_array_parse(v, 3, 3, value, "value must be a 3-dimensional vector") == -1) {
234 return -1;
235 }
236 Vec3r p(v[0], v[1], v[2]);
237 self->fes->setNormalB(p);
238 return 0;
239}
240
242 /* Wrap. */
243 FEdgeSharp_material_index_right_doc,
244 "The index of the material of the face lying on the right of the FEdge.\n"
245 "If this FEdge is a border, it has no Face on its right and therefore\n"
246 "no material.\n"
247 "\n"
248 ":type: int\n");
249static PyObject *FEdgeSharp_material_index_right_get(BPy_FEdgeSharp *self, void * /*closure*/)
250{
251 return PyLong_FromLong(self->fes->aFrsMaterialIndex());
252}
253
255 PyObject *value,
256 void * /*closure*/)
257{
258 uint i = PyLong_AsUnsignedLong(value);
259 if (PyErr_Occurred()) {
260 return -1;
261 }
262 self->fes->setaFrsMaterialIndex(i);
263 return 0;
264}
265
267 /* Wrap. */
268 FEdgeSharp_material_index_left_doc,
269 "The index of the material of the face lying on the left of the FEdge.\n"
270 "\n"
271 ":type: int\n");
272static PyObject *FEdgeSharp_material_index_left_get(BPy_FEdgeSharp *self, void * /*closure*/)
273{
274 return PyLong_FromLong(self->fes->bFrsMaterialIndex());
275}
276
278 PyObject *value,
279 void * /*closure*/)
280{
281 uint i = PyLong_AsUnsignedLong(value);
282 if (PyErr_Occurred()) {
283 return -1;
284 }
285 self->fes->setbFrsMaterialIndex(i);
286 return 0;
287}
288
290 /* Wrap. */
291 FEdgeSharp_material_right_doc,
292 "The material of the face lying on the right of the FEdge. If this FEdge\n"
293 "is a border, it has no Face on its right and therefore no material.\n"
294 "\n"
295 ":type: :class:`Material`\n");
296static PyObject *FEdgeSharp_material_right_get(BPy_FEdgeSharp *self, void * /*closure*/)
297{
298 return BPy_FrsMaterial_from_FrsMaterial(self->fes->aFrsMaterial());
299}
300
302 /* Wrap. */
303 FEdgeSharp_material_left_doc,
304 "The material of the face lying on the left of the FEdge.\n"
305 "\n"
306 ":type: :class:`Material`\n");
307static PyObject *FEdgeSharp_material_left_get(BPy_FEdgeSharp *self, void * /*closure*/)
308{
309 return BPy_FrsMaterial_from_FrsMaterial(self->fes->bFrsMaterial());
310}
311
313 /* Wrap. */
314 FEdgeSharp_face_mark_right_doc,
315 "The face mark of the face lying on the right of the FEdge. If this FEdge\n"
316 "is a border, it has no face on the right and thus this property is set to\n"
317 "false.\n"
318 "\n"
319 ":type: bool\n");
320static PyObject *FEdgeSharp_face_mark_right_get(BPy_FEdgeSharp *self, void * /*closure*/)
321{
322 return PyBool_from_bool(self->fes->aFaceMark());
323}
324
326 PyObject *value,
327 void * /*closure*/)
328{
329 if (!PyBool_Check(value)) {
330 return -1;
331 }
332 self->fes->setaFaceMark(bool_from_PyBool(value));
333 return 0;
334}
335
337 /* Wrap. */
338 FEdgeSharp_face_mark_left_doc,
339 "The face mark of the face lying on the left of the FEdge.\n"
340 "\n"
341 ":type: bool\n");
342static PyObject *FEdgeSharp_face_mark_left_get(BPy_FEdgeSharp *self, void * /*closure*/)
343{
344 return PyBool_from_bool(self->fes->bFaceMark());
345}
346
347static int FEdgeSharp_face_mark_left_set(BPy_FEdgeSharp *self, PyObject *value, void * /*closure*/)
348{
349 if (!PyBool_Check(value)) {
350 return -1;
351 }
352 self->fes->setbFaceMark(bool_from_PyBool(value));
353 return 0;
354}
355
356static PyGetSetDef BPy_FEdgeSharp_getseters[] = {
357 {"normal_right",
360 FEdgeSharp_normal_right_doc,
361 nullptr},
362 {"normal_left",
365 FEdgeSharp_normal_left_doc,
366 nullptr},
367 {"material_index_right",
370 FEdgeSharp_material_index_right_doc,
371 nullptr},
372 {"material_index_left",
375 FEdgeSharp_material_index_left_doc,
376 nullptr},
377 {"material_right",
379 (setter) nullptr,
380 FEdgeSharp_material_right_doc,
381 nullptr},
382 {"material_left",
384 (setter) nullptr,
385 FEdgeSharp_material_left_doc,
386 nullptr},
387 {"face_mark_right",
390 FEdgeSharp_face_mark_right_doc,
391 nullptr},
392 {"face_mark_left",
395 FEdgeSharp_face_mark_left_doc,
396 nullptr},
397 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
398};
399
400/*-----------------------BPy_FEdgeSharp type definition ------------------------------*/
401
402PyTypeObject FEdgeSharp_Type = {
403 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
404 /*tp_name*/ "FEdgeSharp",
405 /*tp_basicsize*/ sizeof(BPy_FEdgeSharp),
406 /*tp_itemsize*/ 0,
407 /*tp_dealloc*/ nullptr,
408 /*tp_vectorcall_offset*/ 0,
409 /*tp_getattr*/ nullptr,
410 /*tp_setattr*/ nullptr,
411 /*tp_as_async*/ nullptr,
412 /*tp_repr*/ nullptr,
413 /*tp_as_number*/ nullptr,
414 /*tp_as_sequence*/ nullptr,
415 /*tp_as_mapping*/ nullptr,
416 /*tp_hash*/ nullptr,
417 /*tp_call*/ nullptr,
418 /*tp_str*/ nullptr,
419 /*tp_getattro*/ nullptr,
420 /*tp_setattro*/ nullptr,
421 /*tp_as_buffer*/ nullptr,
422 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
423 /*tp_doc*/ FEdgeSharp_doc,
424 /*tp_traverse*/ nullptr,
425 /*tp_clear*/ nullptr,
426 /*tp_richcompare*/ nullptr,
427 /*tp_weaklistoffset*/ 0,
428 /*tp_iter*/ nullptr,
429 /*tp_iternext*/ nullptr,
430 /*tp_methods*/ nullptr,
431 /*tp_members*/ nullptr,
432 /*tp_getset*/ BPy_FEdgeSharp_getseters,
433 /*tp_base*/ &FEdge_Type,
434 /*tp_dict*/ nullptr,
435 /*tp_descr_get*/ nullptr,
436 /*tp_descr_set*/ nullptr,
437 /*tp_dictoffset*/ 0,
438 /*tp_init*/ (initproc)FEdgeSharp_init,
439 /*tp_alloc*/ nullptr,
440 /*tp_new*/ nullptr,
441};
442
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)
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[]
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`\n")
#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