Blender  V3.3
BPy_FEdgeSmooth.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BPy_FEdgeSmooth.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 /*----------------------FEdgeSmooth methods ----------------------------*/
21 
22 PyDoc_STRVAR(FEdgeSmooth_doc,
23  "Class hierarchy: :class:`Interface1D` > :class:`FEdge` > :class:`FEdgeSmooth`\n"
24  "\n"
25  "Class defining a smooth edge. This kind of edge typically runs across\n"
26  "a face of the input mesh. It can be a silhouette, a ridge or valley,\n"
27  "a suggestive contour.\n"
28  "\n"
29  ".. method:: __init__()\n"
30  " __init__(brother)\n"
31  " __init__(first_vertex, second_vertex)\n"
32  "\n"
33  " Builds an :class:`FEdgeSmooth` using the default constructor,\n"
34  " copy constructor, or between two :class:`SVertex`.\n"
35  "\n"
36  " :arg brother: An FEdgeSmooth object.\n"
37  " :type brother: :class:`FEdgeSmooth`\n"
38  " :arg first_vertex: The first SVertex object.\n"
39  " :type first_vertex: :class:`SVertex`\n"
40  " :arg second_vertex: The second SVertex object.\n"
41  " :type second_vertex: :class:`SVertex`");
42 
43 static int FEdgeSmooth_init(BPy_FEdgeSmooth *self, PyObject *args, PyObject *kwds)
44 {
45  static const char *kwlist_1[] = {"brother", nullptr};
46  static const char *kwlist_2[] = {"first_vertex", "second_vertex", nullptr};
47  PyObject *obj1 = nullptr, *obj2 = nullptr;
48 
49  if (PyArg_ParseTupleAndKeywords(
50  args, kwds, "|O!", (char **)kwlist_1, &FEdgeSmooth_Type, &obj1)) {
51  if (!obj1) {
52  self->fes = new FEdgeSmooth();
53  }
54  else {
55  self->fes = new FEdgeSmooth(*(((BPy_FEdgeSmooth *)obj1)->fes));
56  }
57  }
58  else if ((void)PyErr_Clear(),
59  PyArg_ParseTupleAndKeywords(args,
60  kwds,
61  "O!O!",
62  (char **)kwlist_2,
63  &SVertex_Type,
64  &obj1,
65  &SVertex_Type,
66  &obj2)) {
67  self->fes = new FEdgeSmooth(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv);
68  }
69  else {
70  PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
71  return -1;
72  }
73  self->py_fe.fe = self->fes;
74  self->py_fe.py_if1D.if1D = self->fes;
75  self->py_fe.py_if1D.borrowed = false;
76  return 0;
77 }
78 
79 /*----------------------mathutils callbacks ----------------------------*/
80 
82 {
83  if (!BPy_FEdgeSmooth_Check(bmo->cb_user)) {
84  return -1;
85  }
86  return 0;
87 }
88 
89 static int FEdgeSmooth_mathutils_get(BaseMathObject *bmo, int /*subtype*/)
90 {
91  BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user;
92  Vec3r p(self->fes->normal());
93  bmo->data[0] = p[0];
94  bmo->data[1] = p[1];
95  bmo->data[2] = p[2];
96  return 0;
97 }
98 
99 static int FEdgeSmooth_mathutils_set(BaseMathObject *bmo, int /*subtype*/)
100 {
101  BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user;
102  Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]);
103  self->fes->setNormal(p);
104  return 0;
105 }
106 
107 static int FEdgeSmooth_mathutils_get_index(BaseMathObject *bmo, int /*subtype*/, int index)
108 {
109  BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user;
110  Vec3r p(self->fes->normal());
111  bmo->data[index] = p[index];
112  return 0;
113 }
114 
115 static int FEdgeSmooth_mathutils_set_index(BaseMathObject *bmo, int /*subtype*/, int index)
116 {
117  BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user;
118  Vec3r p(self->fes->normal());
119  p[index] = bmo->data[index];
120  self->fes->setNormal(p);
121  return 0;
122 }
123 
130 };
131 
132 static unsigned char FEdgeSmooth_mathutils_cb_index = -1;
133 
135 {
137 }
138 
139 /*----------------------FEdgeSmooth get/setters ----------------------------*/
140 
141 PyDoc_STRVAR(FEdgeSmooth_normal_doc,
142  "The normal of the face that this FEdge is running across.\n"
143  "\n"
144  ":type: :class:`mathutils.Vector`");
145 
146 static PyObject *FEdgeSmooth_normal_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
147 {
148  return Vector_CreatePyObject_cb((PyObject *)self, 3, FEdgeSmooth_mathutils_cb_index, 0);
149 }
150 
151 static int FEdgeSmooth_normal_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure))
152 {
153  float v[3];
154  if (mathutils_array_parse(v, 3, 3, value, "value must be a 3-dimensional vector") == -1) {
155  return -1;
156  }
157  Vec3r p(v[0], v[1], v[2]);
158  self->fes->setNormal(p);
159  return 0;
160 }
161 
162 PyDoc_STRVAR(FEdgeSmooth_material_index_doc,
163  "The index of the material of the face that this FEdge is running across.\n"
164  "\n"
165  ":type: int");
166 
167 static PyObject *FEdgeSmooth_material_index_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
168 {
169  return PyLong_FromLong(self->fes->frs_materialIndex());
170 }
171 
173  PyObject *value,
174  void *UNUSED(closure))
175 {
176  unsigned int i = PyLong_AsUnsignedLong(value);
177  if (PyErr_Occurred()) {
178  return -1;
179  }
180  self->fes->setFrsMaterialIndex(i);
181  return 0;
182 }
183 
184 PyDoc_STRVAR(FEdgeSmooth_material_doc,
185  "The material of the face that this FEdge is running across.\n"
186  "\n"
187  ":type: :class:`Material`");
188 
189 static PyObject *FEdgeSmooth_material_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
190 {
191  return BPy_FrsMaterial_from_FrsMaterial(self->fes->frs_material());
192 }
193 
194 PyDoc_STRVAR(FEdgeSmooth_face_mark_doc,
195  "The face mark of the face that this FEdge is running across.\n"
196  "\n"
197  ":type: bool");
198 
199 static PyObject *FEdgeSmooth_face_mark_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
200 {
201  return PyBool_from_bool(self->fes->faceMark());
202 }
203 
204 static int FEdgeSmooth_face_mark_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure))
205 {
206  if (!PyBool_Check(value)) {
207  return -1;
208  }
209  self->fes->setFaceMark(bool_from_PyBool(value));
210  return 0;
211 }
212 
213 static PyGetSetDef BPy_FEdgeSmooth_getseters[] = {
214  {"normal",
215  (getter)FEdgeSmooth_normal_get,
216  (setter)FEdgeSmooth_normal_set,
217  FEdgeSmooth_normal_doc,
218  nullptr},
219  {"material_index",
222  FEdgeSmooth_material_index_doc,
223  nullptr},
224  {"material",
225  (getter)FEdgeSmooth_material_get,
226  (setter) nullptr,
227  FEdgeSmooth_material_doc,
228  nullptr},
229  {"face_mark",
232  FEdgeSmooth_face_mark_doc,
233  nullptr},
234  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
235 };
236 
237 /*-----------------------BPy_FEdgeSmooth type definition ------------------------------*/
238 
239 PyTypeObject FEdgeSmooth_Type = {
240  PyVarObject_HEAD_INIT(nullptr, 0) "FEdgeSmooth", /* tp_name */
241  sizeof(BPy_FEdgeSmooth), /* tp_basicsize */
242  0, /* tp_itemsize */
243  nullptr, /* tp_dealloc */
244  0, /* tp_vectorcall_offset */
245  nullptr, /* tp_getattr */
246  nullptr, /* tp_setattr */
247  nullptr, /* tp_reserved */
248  nullptr, /* tp_repr */
249  nullptr, /* tp_as_number */
250  nullptr, /* tp_as_sequence */
251  nullptr, /* tp_as_mapping */
252  nullptr, /* tp_hash */
253  nullptr, /* tp_call */
254  nullptr, /* tp_str */
255  nullptr, /* tp_getattro */
256  nullptr, /* tp_setattro */
257  nullptr, /* tp_as_buffer */
258  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
259  FEdgeSmooth_doc, /* tp_doc */
260  nullptr, /* tp_traverse */
261  nullptr, /* tp_clear */
262  nullptr, /* tp_richcompare */
263  0, /* tp_weaklistoffset */
264  nullptr, /* tp_iter */
265  nullptr, /* tp_iternext */
266  nullptr, /* tp_methods */
267  nullptr, /* tp_members */
268  BPy_FEdgeSmooth_getseters, /* tp_getset */
269  &FEdge_Type, /* tp_base */
270  nullptr, /* tp_dict */
271  nullptr, /* tp_descr_get */
272  nullptr, /* tp_descr_set */
273  0, /* tp_dictoffset */
274  (initproc)FEdgeSmooth_init, /* tp_init */
275  nullptr, /* tp_alloc */
276  nullptr, /* tp_new */
277 };
278 
280 
281 #ifdef __cplusplus
282 }
283 #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 Mathutils_Callback FEdgeSmooth_mathutils_cb
static PyObject * FEdgeSmooth_normal_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
static PyObject * FEdgeSmooth_face_mark_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
static int FEdgeSmooth_material_index_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure))
static int FEdgeSmooth_mathutils_get(BaseMathObject *bmo, int)
static PyObject * FEdgeSmooth_material_index_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
void FEdgeSmooth_mathutils_register_callback()
static int FEdgeSmooth_mathutils_set_index(BaseMathObject *bmo, int, int index)
static int FEdgeSmooth_normal_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure))
static PyObject * FEdgeSmooth_material_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
static int FEdgeSmooth_mathutils_check(BaseMathObject *bmo)
PyTypeObject FEdgeSmooth_Type
static int FEdgeSmooth_mathutils_set(BaseMathObject *bmo, int)
static int FEdgeSmooth_init(BPy_FEdgeSmooth *self, PyObject *args, PyObject *kwds)
PyDoc_STRVAR(FEdgeSmooth_doc, "Class hierarchy: :class:`Interface1D` > :class:`FEdge` > :class:`FEdgeSmooth`\n" "\n" "Class defining a smooth edge. This kind of edge typically runs across\n" "a face of the input mesh. It can be a silhouette, a ridge or valley,\n" "a suggestive contour.\n" "\n" ".. method:: __init__()\n" " __init__(brother)\n" " __init__(first_vertex, second_vertex)\n" "\n" " Builds an :class:`FEdgeSmooth` using the default constructor,\n" " copy constructor, or between two :class:`SVertex`.\n" "\n" " :arg brother: An FEdgeSmooth object.\n" " :type brother: :class:`FEdgeSmooth`\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 unsigned char FEdgeSmooth_mathutils_cb_index
static int FEdgeSmooth_mathutils_get_index(BaseMathObject *bmo, int, int index)
static PyGetSetDef BPy_FEdgeSmooth_getseters[]
static int FEdgeSmooth_face_mark_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure))
#define BPy_FEdgeSmooth_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