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