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