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