code cleanup: spelling
[blender.git] / source / blender / freestyle / intern / python / Interface1D / BPy_FrsCurve.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/BPy_FrsCurve.cpp
22  *  \ingroup freestyle
23  */
24
25 #include "BPy_FrsCurve.h"
26
27 #include "../BPy_Convert.h"
28 #include "../BPy_Id.h"
29 #include "../Interface0D/BPy_CurvePoint.h"
30 #include "../Interface0D/BPy_SVertex.h"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 ///////////////////////////////////////////////////////////////////////////////////////////
37
38 /*----------------------CurvePoint methods ----------------------------*/
39
40 PyDoc_STRVAR(FrsCurve_doc,
41 "Class hierarchy: :class:`Interface1D` > :class:`Curve`\n"
42 "\n"
43 "Base class for curves made of CurvePoints.  :class:`SVertex` is the\n"
44 "type of the initial curve vertices.  A :class:`Chain` is a\n"
45 "specialization of a Curve.\n"
46 "\n"
47 ".. method:: __init__()\n"
48 "\n"
49 "   Default Constructor.\n"
50 "\n"
51 ".. method:: __init__(brother)\n"
52 "\n"
53 "   Copy Constructor.\n"
54 "\n"
55 "   :arg brother: A Curve object.\n"
56 "   :type brother: :class:`Curve`\n"
57 "\n"
58 ".. method:: __init__(id)\n"
59 "\n"
60 "   Builds a Curve from its Id.\n"
61 "\n"
62 "   :arg id: An Id object.\n"
63 "   :type id: :class:`Id`");
64
65 static int FrsCurve_init(BPy_FrsCurve *self, PyObject *args, PyObject *kwds)
66 {
67         static const char *kwlist_1[] = {"brother", NULL};
68         static const char *kwlist_2[] = {"id", NULL};
69         PyObject *obj = 0;
70
71         if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FrsCurve_Type, &obj)) {
72                 if (!obj)
73                         self->c = new Curve();
74                 else
75                         self->c = new Curve(*(((BPy_FrsCurve *)obj)->c));
76         }
77         else if (PyErr_Clear(),
78                  PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Id_Type, &obj))
79         {
80                 self->c = new Curve(*(((BPy_Id *)obj)->id));
81         }
82         else {
83                 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
84                 return -1;
85         }
86         self->py_if1D.if1D = self->c;
87         self->py_if1D.borrowed = 0;
88         return 0;
89 }
90
91 PyDoc_STRVAR(FrsCurve_push_vertex_back_doc,
92 ".. method:: push_vertex_back(vertex)\n"
93 "\n"
94 "   Adds a single vertex at the end of the Curve.\n"
95 "\n"
96 "   :arg vertex: A vertex object.\n"
97 "   :type vertex: :class:`SVertex` or :class:`CurvePoint`");
98
99 static PyObject *FrsCurve_push_vertex_back(BPy_FrsCurve *self, PyObject *args, PyObject *kwds)
100 {
101         static const char *kwlist[] = {"vertex", NULL};
102         PyObject *obj = 0;
103
104         if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj))
105                 return NULL;
106
107         if (BPy_CurvePoint_Check(obj)) {
108                 self->c->push_vertex_back(((BPy_CurvePoint *)obj)->cp);
109         }
110         else if (BPy_SVertex_Check(obj)) {
111                 self->c->push_vertex_back(((BPy_SVertex *)obj)->sv);
112         }
113         else {
114                 PyErr_SetString(PyExc_TypeError, "invalid argument");
115                 return NULL;
116         }
117         Py_RETURN_NONE;
118 }
119
120 PyDoc_STRVAR(FrsCurve_push_vertex_front_doc,
121 ".. method:: push_vertex_front(vertex)\n"
122 "\n"
123 "   Adds a single vertex at the front of the Curve.\n"
124 "\n"
125 "   :arg vertex: A vertex object.\n"
126 "   :type vertex: :class:`SVertex` or :class:`CurvePoint`");
127
128 static PyObject *FrsCurve_push_vertex_front(BPy_FrsCurve *self, PyObject *args, PyObject *kwds)
129 {
130         static const char *kwlist[] = {"vertex", NULL};
131         PyObject *obj = 0;
132
133         if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj))
134                 return NULL;
135
136         if (BPy_CurvePoint_Check(obj)) {
137                 self->c->push_vertex_front(((BPy_CurvePoint *)obj)->cp);
138         }
139         else if (BPy_SVertex_Check(obj)) {
140                 self->c->push_vertex_front(((BPy_SVertex *)obj)->sv);
141         }
142         else {
143                 PyErr_SetString(PyExc_TypeError, "invalid argument");
144                 return NULL;
145         }
146         Py_RETURN_NONE;
147 }
148
149 static PyMethodDef BPy_FrsCurve_methods[] = {
150         {"push_vertex_back", (PyCFunction)FrsCurve_push_vertex_back, METH_VARARGS | METH_KEYWORDS,
151                              FrsCurve_push_vertex_back_doc},
152         {"push_vertex_front", (PyCFunction)FrsCurve_push_vertex_front, METH_VARARGS | METH_KEYWORDS,
153                               FrsCurve_push_vertex_front_doc},
154         {NULL, NULL, 0, NULL}
155 };
156
157 /*----------------------CurvePoint get/setters ----------------------------*/
158
159 PyDoc_STRVAR(FrsCurve_is_empty_doc,
160 "True if the Curve doesn't have any Vertex yet.\n"
161 "\n"
162 ":type: bool");
163
164 static PyObject *FrsCurve_is_empty_get(BPy_FrsCurve *self, void *UNUSED(closure))
165 {
166         return PyBool_from_bool(self->c->empty());
167 }
168
169 PyDoc_STRVAR(FrsCurve_segments_size_doc,
170 "The number of segments in the polyline constituting the Curve.\n"
171 "\n"
172 ":type: int");
173
174 static PyObject *FrsCurve_segments_size_get(BPy_FrsCurve *self, void *UNUSED(closure))
175 {
176         return PyLong_FromLong(self->c->nSegments());
177 }
178
179 static PyGetSetDef BPy_FrsCurve_getseters[] = {
180         {(char *)"is_empty", (getter)FrsCurve_is_empty_get, (setter)NULL, (char *)FrsCurve_is_empty_doc, NULL},
181         {(char *)"segments_size", (getter)FrsCurve_segments_size_get, (setter)NULL,
182                                   (char *)FrsCurve_segments_size_doc, NULL},
183         {NULL, NULL, NULL, NULL, NULL}  /* Sentinel */
184 };
185
186 /*-----------------------BPy_FrsCurve type definition ------------------------------*/
187
188 PyTypeObject FrsCurve_Type = {
189         PyVarObject_HEAD_INIT(NULL, 0)
190         "Curve",                        /* tp_name */
191         sizeof(BPy_FrsCurve),           /* tp_basicsize */
192         0,                              /* tp_itemsize */
193         0,                              /* tp_dealloc */
194         0,                              /* tp_print */
195         0,                              /* tp_getattr */
196         0,                              /* tp_setattr */
197         0,                              /* tp_reserved */
198         0,                              /* tp_repr */
199         0,                              /* tp_as_number */
200         0,                              /* tp_as_sequence */
201         0,                              /* tp_as_mapping */
202         0,                              /* tp_hash  */
203         0,                              /* tp_call */
204         0,                              /* tp_str */
205         0,                              /* tp_getattro */
206         0,                              /* tp_setattro */
207         0,                              /* tp_as_buffer */
208         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
209         FrsCurve_doc,                   /* tp_doc */
210         0,                              /* tp_traverse */
211         0,                              /* tp_clear */
212         0,                              /* tp_richcompare */
213         0,                              /* tp_weaklistoffset */
214         0,                              /* tp_iter */
215         0,                              /* tp_iternext */
216         BPy_FrsCurve_methods,           /* tp_methods */
217         0,                              /* tp_members */
218         BPy_FrsCurve_getseters,         /* tp_getset */
219         &Interface1D_Type,              /* tp_base */
220         0,                              /* tp_dict */
221         0,                              /* tp_descr_get */
222         0,                              /* tp_descr_set */
223         0,                              /* tp_dictoffset */
224         (initproc)FrsCurve_init,        /* tp_init */
225         0,                              /* tp_alloc */
226         0,                              /* tp_new */
227 };
228
229 ///////////////////////////////////////////////////////////////////////////////////////////
230
231 #ifdef __cplusplus
232 }
233 #endif