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