Freestyle: Code cleanup, prepare for strict C++ flags
[blender.git] / source / blender / freestyle / intern / python / Interface1D / FEdge / BPy_FEdgeSmooth.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
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.
8  *
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.
13  *
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.
17  *
18  * ***** END GPL LICENSE BLOCK *****
19  */
20
21 /** \file source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp
22  *  \ingroup freestyle
23  */
24
25 #include "BPy_FEdgeSmooth.h"
26
27 #include "../../BPy_Convert.h"
28 #include "../../Interface0D/BPy_SVertex.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 ///////////////////////////////////////////////////////////////////////////////////////////
35
36 /*----------------------FEdgeSmooth methods ----------------------------*/
37
38 PyDoc_STRVAR(FEdgeSmooth_doc,
39 "Class hierarchy: :class:`Interface1D` > :class:`FEdge` > :class:`FEdgeSmooth`\n"
40 "\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"
44 "\n"
45 ".. method:: __init__()\n"
46 "\n"
47 "   Default constructor.\n"
48 "\n"
49 ".. method:: __init__(brother)\n"
50 "\n"
51 "   Copy constructor.\n"
52 "\n"
53 "   :arg brother: An FEdgeSmooth object.\n"
54 "   :type brother: :class:`FEdgeSmooth`\n"
55 "\n"
56 ".. method:: __init__(first_vertex, second_vertex)\n"
57 "\n"
58 "   Builds an FEdgeSmooth going from the first to the second.\n"
59 "\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`");
64
65 static int FEdgeSmooth_init(BPy_FEdgeSmooth *self, PyObject *args, PyObject *kwds)
66 {
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;
70
71         if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdgeSmooth_Type, &obj1)) {
72                 if (!obj1)
73                         self->fes = new FEdgeSmooth();
74                 else
75                         self->fes = new FEdgeSmooth(*(((BPy_FEdgeSmooth *)obj1)->fes));
76         }
77         else if (PyErr_Clear(),
78                  PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist_2,
79                                              &SVertex_Type, &obj1, &SVertex_Type, &obj2))
80         {
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
95 static int FEdgeSmooth_mathutils_check(BaseMathObject *bmo)
96 {
97         if (!BPy_FEdgeSmooth_Check(bmo->cb_user))
98                 return -1;
99         return 0;
100 }
101
102 static int FEdgeSmooth_mathutils_get(BaseMathObject *bmo, int /*subtype*/)
103 {
104         BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user;
105         Vec3r p(self->fes->normal());
106         bmo->data[0] = p[0];
107         bmo->data[1] = p[1];
108         bmo->data[2] = p[2];
109         return 0;
110 }
111
112 static int FEdgeSmooth_mathutils_set(BaseMathObject *bmo, int /*subtype*/)
113 {
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);
117         return 0;
118 }
119
120 static int FEdgeSmooth_mathutils_get_index(BaseMathObject *bmo, int /*subtype*/, int index)
121 {
122         BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user;
123         Vec3r p(self->fes->normal());
124         bmo->data[index] = p[index];
125         return 0;
126 }
127
128 static int FEdgeSmooth_mathutils_set_index(BaseMathObject *bmo, int /*subtype*/, int index)
129 {
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);
134         return 0;
135 }
136
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
143 };
144
145 static unsigned char FEdgeSmooth_mathutils_cb_index = -1;
146
147 void FEdgeSmooth_mathutils_register_callback()
148 {
149         FEdgeSmooth_mathutils_cb_index = Mathutils_RegisterCallback(&FEdgeSmooth_mathutils_cb);
150 }
151
152 /*----------------------FEdgeSmooth get/setters ----------------------------*/
153
154 PyDoc_STRVAR(FEdgeSmooth_normal_doc,
155 "The normal of the face that this FEdge is running across.\n"
156 "\n"
157 ":type: :class:`mathutils.Vector`");
158
159 static PyObject *FEdgeSmooth_normal_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
160 {
161         return Vector_CreatePyObject_cb((PyObject *)self, 3, FEdgeSmooth_mathutils_cb_index, 0);
162 }
163
164 static int FEdgeSmooth_normal_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure))
165 {
166         float v[3];
167         if (mathutils_array_parse(v, 3, 3, value,
168                                   "value must be a 3-dimensional vector") == -1)
169         {
170                 return -1;
171         }
172         Vec3r p(v[0], v[1], v[2]);
173         self->fes->setNormal(p);
174         return 0;
175 }
176
177 PyDoc_STRVAR(FEdgeSmooth_material_index_doc,
178 "The index of the material of the face that this FEdge is running across.\n"
179 "\n"
180 ":type: int");
181
182 static PyObject *FEdgeSmooth_material_index_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
183 {
184         return PyLong_FromLong(self->fes->frs_materialIndex());
185 }
186
187 static int FEdgeSmooth_material_index_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure))
188 {
189         unsigned int i = PyLong_AsUnsignedLong(value);
190         if (PyErr_Occurred())
191                 return -1;
192         self->fes->setFrsMaterialIndex(i);
193         return 0;
194 }
195
196 PyDoc_STRVAR(FEdgeSmooth_material_doc,
197 "The material of the face that this FEdge is running across.\n"
198 "\n"
199 ":type: :class:`Material`");
200
201 static PyObject *FEdgeSmooth_material_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
202 {
203         return BPy_FrsMaterial_from_FrsMaterial(self->fes->frs_material());
204 }
205
206 PyDoc_STRVAR(FEdgeSmooth_face_mark_doc,
207 "The face mark of the face that this FEdge is running across.\n"
208 "\n"
209 ":type: bool");
210
211 static PyObject *FEdgeSmooth_face_mark_get(BPy_FEdgeSmooth *self, void *UNUSED(closure))
212 {
213         return PyBool_from_bool(self->fes->faceMark());
214 }
215
216 static int FEdgeSmooth_face_mark_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure))
217 {
218         if (!PyBool_Check(value))
219                 return -1;
220         self->fes->setFaceMark(bool_from_PyBool(value));
221         return 0;
222 }
223
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 */
233 };
234
235 /*-----------------------BPy_FEdgeSmooth type definition ------------------------------*/
236
237 PyTypeObject FEdgeSmooth_Type = {
238         PyVarObject_HEAD_INIT(NULL, 0)
239         "FEdgeSmooth",                  /* tp_name */
240         sizeof(BPy_FEdgeSmooth),        /* tp_basicsize */
241         0,                              /* tp_itemsize */
242         0,                              /* tp_dealloc */
243         0,                              /* tp_print */
244         0,                              /* tp_getattr */
245         0,                              /* tp_setattr */
246         0,                              /* tp_reserved */
247         0,                              /* tp_repr */
248         0,                              /* tp_as_number */
249         0,                              /* tp_as_sequence */
250         0,                              /* tp_as_mapping */
251         0,                              /* tp_hash  */
252         0,                              /* tp_call */
253         0,                              /* tp_str */
254         0,                              /* tp_getattro */
255         0,                              /* tp_setattro */
256         0,                              /* tp_as_buffer */
257         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
258         FEdgeSmooth_doc,                /* tp_doc */
259         0,                              /* tp_traverse */
260         0,                              /* tp_clear */
261         0,                              /* tp_richcompare */
262         0,                              /* tp_weaklistoffset */
263         0,                              /* tp_iter */
264         0,                              /* tp_iternext */
265         0,                              /* tp_methods */
266         0,                              /* tp_members */
267         BPy_FEdgeSmooth_getseters,      /* tp_getset */
268         &FEdge_Type,                    /* tp_base */
269         0,                              /* tp_dict */
270         0,                              /* tp_descr_get */
271         0,                              /* tp_descr_set */
272         0,                              /* tp_dictoffset */
273         (initproc)FEdgeSmooth_init,     /* tp_init */
274         0,                              /* tp_alloc */
275         0,                              /* tp_new */
276 };
277
278 ///////////////////////////////////////////////////////////////////////////////////////////
279
280 #ifdef __cplusplus
281 }
282 #endif