Blender  V2.93
BPy_FEdgeSharp.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BPy_FEdgeSharp.h"
22 
23 #include "../../BPy_Convert.h"
24 #include "../../Interface0D/BPy_SVertex.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 using namespace Freestyle;
31 
33 
34 /*----------------------FEdgeSharp methods ----------------------------*/
35 
36 PyDoc_STRVAR(FEdgeSharp_doc,
37  "Class hierarchy: :class:`Interface1D` > :class:`FEdge` > :class:`FEdgeSharp`\n"
38  "\n"
39  "Class defining a sharp FEdge. A Sharp FEdge corresponds to an initial\n"
40  "edge of the input mesh. It can be a silhouette, a crease or a border.\n"
41  "If it is a crease edge, then it is bordered by two faces of the mesh.\n"
42  "Face a lies on its right whereas Face b lies on its left. If it is a\n"
43  "border edge, then it doesn't have any face on its right, and thus Face\n"
44  "a is None.\n"
45  "\n"
46  ".. method:: __init__()\n"
47  " __init__(brother)\n"
48  " __init__(first_vertex, second_vertex)\n"
49  "\n"
50  " Builds an :class:`FEdgeSharp` using the default constructor,\n"
51  " copy constructor, or between two :class:`SVertex` objects.\n"
52  "\n"
53  " :arg brother: An FEdgeSharp object.\n"
54  " :type brother: :class:`FEdgeSharp`\n"
55  " :arg first_vertex: The first SVertex object.\n"
56  " :type first_vertex: :class:`SVertex`\n"
57  " :arg second_vertex: The second SVertex object.\n"
58  " :type second_vertex: :class:`SVertex`");
59 
60 static int FEdgeSharp_init(BPy_FEdgeSharp *self, PyObject *args, PyObject *kwds)
61 {
62  static const char *kwlist_1[] = {"brother", nullptr};
63  static const char *kwlist_2[] = {"first_vertex", "second_vertex", nullptr};
64  PyObject *obj1 = nullptr, *obj2 = nullptr;
65 
66  if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdgeSharp_Type, &obj1)) {
67  if (!obj1) {
68  self->fes = new FEdgeSharp();
69  }
70  else {
71  self->fes = new FEdgeSharp(*(((BPy_FEdgeSharp *)obj1)->fes));
72  }
73  }
74  else if ((void)PyErr_Clear(),
75  PyArg_ParseTupleAndKeywords(args,
76  kwds,
77  "O!O!",
78  (char **)kwlist_2,
79  &SVertex_Type,
80  &obj1,
81  &SVertex_Type,
82  &obj2)) {
83  self->fes = new FEdgeSharp(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv);
84  }
85  else {
86  PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
87  return -1;
88  }
89  self->py_fe.fe = self->fes;
90  self->py_fe.py_if1D.if1D = self->fes;
91  self->py_fe.py_if1D.borrowed = false;
92  return 0;
93 }
94 
95 /*----------------------mathutils callbacks ----------------------------*/
96 
97 /* subtype */
98 #define MATHUTILS_SUBTYPE_NORMAL_A 1
99 #define MATHUTILS_SUBTYPE_NORMAL_B 2
100 
102 {
103  if (!BPy_FEdgeSharp_Check(bmo->cb_user)) {
104  return -1;
105  }
106  return 0;
107 }
108 
109 static int FEdgeSharp_mathutils_get(BaseMathObject *bmo, int subtype)
110 {
111  BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user;
112  switch (subtype) {
114  Vec3r p(self->fes->normalA());
115  bmo->data[0] = p[0];
116  bmo->data[1] = p[1];
117  bmo->data[2] = p[2];
118  } break;
120  Vec3r p(self->fes->normalB());
121  bmo->data[0] = p[0];
122  bmo->data[1] = p[1];
123  bmo->data[2] = p[2];
124  } break;
125  default:
126  return -1;
127  }
128  return 0;
129 }
130 
131 static int FEdgeSharp_mathutils_set(BaseMathObject *bmo, int subtype)
132 {
133  BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user;
134  switch (subtype) {
136  Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]);
137  self->fes->setNormalA(p);
138  } break;
140  Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]);
141  self->fes->setNormalB(p);
142  } break;
143  default:
144  return -1;
145  }
146  return 0;
147 }
148 
149 static int FEdgeSharp_mathutils_get_index(BaseMathObject *bmo, int subtype, int index)
150 {
151  BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user;
152  switch (subtype) {
154  Vec3r p(self->fes->normalA());
155  bmo->data[index] = p[index];
156  } break;
158  Vec3r p(self->fes->normalB());
159  bmo->data[index] = p[index];
160  } break;
161  default:
162  return -1;
163  }
164  return 0;
165 }
166 
167 static int FEdgeSharp_mathutils_set_index(BaseMathObject *bmo, int subtype, int index)
168 {
169  BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user;
170  switch (subtype) {
172  Vec3r p(self->fes->normalA());
173  p[index] = bmo->data[index];
174  self->fes->setNormalA(p);
175  } break;
177  Vec3r p(self->fes->normalB());
178  p[index] = bmo->data[index];
179  self->fes->setNormalB(p);
180  } break;
181  default:
182  return -1;
183  }
184  return 0;
185 }
186 
193 };
194 
195 static unsigned char FEdgeSharp_mathutils_cb_index = -1;
196 
198 {
200 }
201 
202 /*----------------------FEdgeSharp get/setters ----------------------------*/
203 
204 PyDoc_STRVAR(FEdgeSharp_normal_right_doc,
205  "The normal to the face lying on the right of the FEdge. If this FEdge\n"
206  "is a border, it has no Face on its right and therefore no normal.\n"
207  "\n"
208  ":type: :class:`mathutils.Vector`");
209 
210 static PyObject *FEdgeSharp_normal_right_get(BPy_FEdgeSharp *self, void *UNUSED(closure))
211 {
214 }
215 
217  PyObject *value,
218  void *UNUSED(closure))
219 {
220  float v[3];
221  if (mathutils_array_parse(v, 3, 3, value, "value must be a 3-dimensional vector") == -1) {
222  return -1;
223  }
224  Vec3r p(v[0], v[1], v[2]);
225  self->fes->setNormalA(p);
226  return 0;
227 }
228 
229 PyDoc_STRVAR(FEdgeSharp_normal_left_doc,
230  "The normal to the face lying on the left of the FEdge.\n"
231  "\n"
232  ":type: :class:`mathutils.Vector`");
233 
234 static PyObject *FEdgeSharp_normal_left_get(BPy_FEdgeSharp *self, void *UNUSED(closure))
235 {
238 }
239 
240 static int FEdgeSharp_normal_left_set(BPy_FEdgeSharp *self, PyObject *value, void *UNUSED(closure))
241 {
242  float v[3];
243  if (mathutils_array_parse(v, 3, 3, value, "value must be a 3-dimensional vector") == -1) {
244  return -1;
245  }
246  Vec3r p(v[0], v[1], v[2]);
247  self->fes->setNormalB(p);
248  return 0;
249 }
250 
251 PyDoc_STRVAR(FEdgeSharp_material_index_right_doc,
252  "The index of the material of the face lying on the right of the FEdge.\n"
253  "If this FEdge is a border, it has no Face on its right and therefore\n"
254  "no material.\n"
255  "\n"
256  ":type: int");
257 
258 static PyObject *FEdgeSharp_material_index_right_get(BPy_FEdgeSharp *self, void *UNUSED(closure))
259 {
260  return PyLong_FromLong(self->fes->aFrsMaterialIndex());
261 }
262 
264  PyObject *value,
265  void *UNUSED(closure))
266 {
267  unsigned int i = PyLong_AsUnsignedLong(value);
268  if (PyErr_Occurred()) {
269  return -1;
270  }
271  self->fes->setaFrsMaterialIndex(i);
272  return 0;
273 }
274 
275 PyDoc_STRVAR(FEdgeSharp_material_index_left_doc,
276  "The index of the material of the face lying on the left of the FEdge.\n"
277  "\n"
278  ":type: int");
279 
280 static PyObject *FEdgeSharp_material_index_left_get(BPy_FEdgeSharp *self, void *UNUSED(closure))
281 {
282  return PyLong_FromLong(self->fes->bFrsMaterialIndex());
283 }
284 
286  PyObject *value,
287  void *UNUSED(closure))
288 {
289  unsigned int i = PyLong_AsUnsignedLong(value);
290  if (PyErr_Occurred()) {
291  return -1;
292  }
293  self->fes->setbFrsMaterialIndex(i);
294  return 0;
295 }
296 
297 PyDoc_STRVAR(FEdgeSharp_material_right_doc,
298  "The material of the face lying on the right of the FEdge. If this FEdge\n"
299  "is a border, it has no Face on its right and therefore no material.\n"
300  "\n"
301  ":type: :class:`Material`");
302 
303 static PyObject *FEdgeSharp_material_right_get(BPy_FEdgeSharp *self, void *UNUSED(closure))
304 {
305  return BPy_FrsMaterial_from_FrsMaterial(self->fes->aFrsMaterial());
306 }
307 
308 PyDoc_STRVAR(FEdgeSharp_material_left_doc,
309  "The material of the face lying on the left of the FEdge.\n"
310  "\n"
311  ":type: :class:`Material`");
312 
313 static PyObject *FEdgeSharp_material_left_get(BPy_FEdgeSharp *self, void *UNUSED(closure))
314 {
315  return BPy_FrsMaterial_from_FrsMaterial(self->fes->bFrsMaterial());
316 }
317 
318 PyDoc_STRVAR(FEdgeSharp_face_mark_right_doc,
319  "The face mark of the face lying on the right of the FEdge. If this FEdge\n"
320  "is a border, it has no face on the right and thus this property is set to\n"
321  "false.\n"
322  "\n"
323  ":type: bool");
324 
325 static PyObject *FEdgeSharp_face_mark_right_get(BPy_FEdgeSharp *self, void *UNUSED(closure))
326 {
327  return PyBool_from_bool(self->fes->aFaceMark());
328 }
329 
331  PyObject *value,
332  void *UNUSED(closure))
333 {
334  if (!PyBool_Check(value)) {
335  return -1;
336  }
337  self->fes->setaFaceMark(bool_from_PyBool(value));
338  return 0;
339 }
340 
341 PyDoc_STRVAR(FEdgeSharp_face_mark_left_doc,
342  "The face mark of the face lying on the left of the FEdge.\n"
343  "\n"
344  ":type: bool");
345 
346 static PyObject *FEdgeSharp_face_mark_left_get(BPy_FEdgeSharp *self, void *UNUSED(closure))
347 {
348  return PyBool_from_bool(self->fes->bFaceMark());
349 }
350 
352  PyObject *value,
353  void *UNUSED(closure))
354 {
355  if (!PyBool_Check(value)) {
356  return -1;
357  }
358  self->fes->setbFaceMark(bool_from_PyBool(value));
359  return 0;
360 }
361 
362 static PyGetSetDef BPy_FEdgeSharp_getseters[] = {
363  {"normal_right",
366  FEdgeSharp_normal_right_doc,
367  nullptr},
368  {"normal_left",
371  FEdgeSharp_normal_left_doc,
372  nullptr},
373  {"material_index_right",
376  FEdgeSharp_material_index_right_doc,
377  nullptr},
378  {"material_index_left",
381  FEdgeSharp_material_index_left_doc,
382  nullptr},
383  {"material_right",
385  (setter) nullptr,
386  FEdgeSharp_material_right_doc,
387  nullptr},
388  {"material_left",
390  (setter) nullptr,
391  FEdgeSharp_material_left_doc,
392  nullptr},
393  {"face_mark_right",
396  FEdgeSharp_face_mark_right_doc,
397  nullptr},
398  {"face_mark_left",
401  FEdgeSharp_face_mark_left_doc,
402  nullptr},
403  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
404 };
405 
406 /*-----------------------BPy_FEdgeSharp type definition ------------------------------*/
407 
408 PyTypeObject FEdgeSharp_Type = {
409  PyVarObject_HEAD_INIT(nullptr, 0) "FEdgeSharp", /* tp_name */
410  sizeof(BPy_FEdgeSharp), /* tp_basicsize */
411  0, /* tp_itemsize */
412  nullptr, /* tp_dealloc */
413  0, /* tp_vectorcall_offset */
414  nullptr, /* tp_getattr */
415  nullptr, /* tp_setattr */
416  nullptr, /* tp_reserved */
417  nullptr, /* tp_repr */
418  nullptr, /* tp_as_number */
419  nullptr, /* tp_as_sequence */
420  nullptr, /* tp_as_mapping */
421  nullptr, /* tp_hash */
422  nullptr, /* tp_call */
423  nullptr, /* tp_str */
424  nullptr, /* tp_getattro */
425  nullptr, /* tp_setattro */
426  nullptr, /* tp_as_buffer */
427  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
428  FEdgeSharp_doc, /* tp_doc */
429  nullptr, /* tp_traverse */
430  nullptr, /* tp_clear */
431  nullptr, /* tp_richcompare */
432  0, /* tp_weaklistoffset */
433  nullptr, /* tp_iter */
434  nullptr, /* tp_iternext */
435  nullptr, /* tp_methods */
436  nullptr, /* tp_members */
437  BPy_FEdgeSharp_getseters, /* tp_getset */
438  &FEdge_Type, /* tp_base */
439  nullptr, /* tp_dict */
440  nullptr, /* tp_descr_get */
441  nullptr, /* tp_descr_set */
442  0, /* tp_dictoffset */
443  (initproc)FEdgeSharp_init, /* tp_init */
444  nullptr, /* tp_alloc */
445  nullptr, /* tp_new */
446 };
447 
449 
450 #ifdef __cplusplus
451 }
452 #endif
#define UNUSED(x)
PyObject * PyBool_from_bool(bool b)
Definition: BPy_Convert.cpp:73
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:358
PyTypeObject SVertex_Type
ATTR_WARN_UNUSED_RESULT const BMVert * v
PyObject * self
Definition: bpy_driver.c:185
uchar Mathutils_RegisterCallback(Mathutils_Callback *cb)
Definition: mathutils.c:584
int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix)
Definition: mathutils.c:118
PyObject * Vector_CreatePyObject_cb(PyObject *cb_user, int size, uchar cb_type, uchar cb_subtype)
inherits from class Rep
Definition: AppCanvas.cpp:32