2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * ***** END GPL LICENSE BLOCK *****
21 /** \file source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp
25 #include "BPy_FEdgeSmooth.h"
27 #include "../../BPy_Convert.h"
28 #include "../../Interface0D/BPy_SVertex.h"
34 ///////////////////////////////////////////////////////////////////////////////////////////
36 /*----------------------FEdgeSmooth methods ----------------------------*/
38 PyDoc_STRVAR(FEdgeSmooth_doc,
39 "Class hierarchy: :class:`Interface1D` > :class:`FEdge` > :class:`FEdgeSmooth`\n"
41 "Class defining a smooth edge. This kind of edge typically runs across\n"
42 "a face of the input mesh. It can be a silhouette, a ridge or valley,\n"
43 "a suggestive contour.\n"
45 ".. method:: __init__()\n"
47 " Default constructor.\n"
49 ".. method:: __init__(brother)\n"
51 " Copy constructor.\n"
53 " :arg brother: An FEdgeSmooth object.\n"
54 " :type brother: :class:`FEdgeSmooth`\n"
56 ".. method:: __init__(first_vertex, second_vertex)\n"
58 " Builds an FEdgeSmooth going from the first to the second.\n"
60 " :arg first_vertex: The first SVertex object.\n"
61 " :type first_vertex: :class:`SVertex`\n"
62 " :arg second_vertex: The second SVertex object.\n"
63 " :type second_vertex: :class:`SVertex`");
65 static int FEdgeSmooth_init(BPy_FEdgeSmooth *self, PyObject *args, PyObject *kwds)
67 static const char *kwlist_1[] = {"brother", NULL};
68 static const char *kwlist_2[] = {"first_vertex", "second_vertex", NULL};
69 PyObject *obj1 = 0, *obj2 = 0;
71 if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdgeSmooth_Type, &obj1)) {
73 self->fes = new FEdgeSmooth();
75 self->fes = new FEdgeSmooth(*(((BPy_FEdgeSmooth *)obj1)->fes));
77 else if (PyErr_Clear(),
78 PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist_2,
79 &SVertex_Type, &obj1, &SVertex_Type, &obj2))
81 self->fes = new FEdgeSmooth(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv);
84 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
87 self->py_fe.fe = self->fes;
88 self->py_fe.py_if1D.if1D = self->fes;
89 self->py_fe.py_if1D.borrowed = false;
93 /*----------------------mathutils callbacks ----------------------------*/
95 static int FEdgeSmooth_mathutils_check(BaseMathObject *bmo)
97 if (!BPy_FEdgeSmooth_Check(bmo->cb_user))
102 static int FEdgeSmooth_mathutils_get(BaseMathObject *bmo, int subtype)
104 BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user;
105 Vec3r p(self->fes->normal());
112 static int FEdgeSmooth_mathutils_set(BaseMathObject *bmo, int subtype)
114 BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user;
115 Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]);
116 self->fes->setNormal(p);
120 static int FEdgeSmooth_mathutils_get_index(BaseMathObject *bmo, int subtype, int index)
122 BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user;
123 Vec3r p(self->fes->normal());
124 bmo->data[index] = p[index];
128 static int FEdgeSmooth_mathutils_set_index(BaseMathObject *bmo, int subtype, int index)
130 BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user;
131 Vec3r p(self->fes->normal());
132 p[index] = bmo->data[index];
133 self->fes->setNormal(p);
137 static Mathutils_Callback FEdgeSmooth_mathutils_cb = {
138 FEdgeSmooth_mathutils_check,
139 FEdgeSmooth_mathutils_get,
140 FEdgeSmooth_mathutils_set,
141 FEdgeSmooth_mathutils_get_index,
142 FEdgeSmooth_mathutils_set_index
145 static unsigned char FEdgeSmooth_mathutils_cb_index = -1;
147 void FEdgeSmooth_mathutils_register_callback()
149 FEdgeSmooth_mathutils_cb_index = Mathutils_RegisterCallback(&FEdgeSmooth_mathutils_cb);
152 /*----------------------FEdgeSmooth get/setters ----------------------------*/
154 PyDoc_STRVAR(FEdgeSmooth_normal_doc,
155 "The normal of the face that this FEdge is running across.\n"
157 ":type: :class:`mathutils.Vector`");
159 static PyObject *FEdgeSmooth_normal_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
161 return Vector_CreatePyObject_cb((PyObject *)self, 3, FEdgeSmooth_mathutils_cb_index, 0);
164 static int FEdgeSmooth_normal_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure))
167 if (mathutils_array_parse(v, 3, 3, value,
168 "value must be a 3-dimensional vector") == -1)
172 Vec3r p(v[0], v[1], v[2]);
173 self->fes->setNormal(p);
177 PyDoc_STRVAR(FEdgeSmooth_material_index_doc,
178 "The index of the material of the face that this FEdge is running across.\n"
182 static PyObject *FEdgeSmooth_material_index_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
184 return PyLong_FromLong(self->fes->frs_materialIndex());
187 static int FEdgeSmooth_material_index_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure))
189 unsigned int i = PyLong_AsUnsignedLong(value);
190 if (PyErr_Occurred())
192 self->fes->setFrsMaterialIndex(i);
196 PyDoc_STRVAR(FEdgeSmooth_material_doc,
197 "The material of the face that this FEdge is running across.\n"
199 ":type: :class:`Material`");
201 static PyObject *FEdgeSmooth_material_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
203 return BPy_FrsMaterial_from_FrsMaterial(self->fes->frs_material());
206 PyDoc_STRVAR(FEdgeSmooth_face_mark_doc,
207 "The face mark of the face that this FEdge is running across.\n"
211 static PyObject *FEdgeSmooth_face_mark_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
213 return PyBool_from_bool(self->fes->faceMark());
216 static int FEdgeSmooth_face_mark_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure))
218 if (!PyBool_Check(value))
220 self->fes->setFaceMark(bool_from_PyBool(value));
224 static PyGetSetDef BPy_FEdgeSmooth_getseters[] = {
225 {(char *)"normal", (getter)FEdgeSmooth_normal_get, (setter)FEdgeSmooth_normal_set,
226 (char *)FEdgeSmooth_normal_doc, NULL},
227 {(char *)"material_index", (getter)FEdgeSmooth_material_index_get, (setter)FEdgeSmooth_material_index_set,
228 (char *)FEdgeSmooth_material_index_doc, NULL},
229 {(char *)"material", (getter)FEdgeSmooth_material_get, (setter)NULL, (char *)FEdgeSmooth_material_doc, NULL},
230 {(char *)"face_mark", (getter)FEdgeSmooth_face_mark_get, (setter)FEdgeSmooth_face_mark_set,
231 (char *)FEdgeSmooth_face_mark_doc, NULL},
232 {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
235 /*-----------------------BPy_FEdgeSmooth type definition ------------------------------*/
237 PyTypeObject FEdgeSmooth_Type = {
238 PyVarObject_HEAD_INIT(NULL, 0)
239 "FEdgeSmooth", /* tp_name */
240 sizeof(BPy_FEdgeSmooth), /* tp_basicsize */
248 0, /* tp_as_number */
249 0, /* tp_as_sequence */
250 0, /* tp_as_mapping */
256 0, /* tp_as_buffer */
257 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
258 FEdgeSmooth_doc, /* tp_doc */
261 0, /* tp_richcompare */
262 0, /* tp_weaklistoffset */
267 BPy_FEdgeSmooth_getseters, /* tp_getset */
268 &FEdge_Type, /* tp_base */
270 0, /* tp_descr_get */
271 0, /* tp_descr_set */
272 0, /* tp_dictoffset */
273 (initproc)FEdgeSmooth_init, /* tp_init */
278 ///////////////////////////////////////////////////////////////////////////////////////////