Blender  V2.93
BPy_FrsCurve.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BPy_FrsCurve.h"
22 
23 #include "../BPy_Convert.h"
24 #include "../BPy_Id.h"
25 #include "../Interface0D/BPy_CurvePoint.h"
26 #include "../Interface0D/BPy_SVertex.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 using namespace Freestyle;
33 
35 
36 /*----------------------CurvePoint methods ----------------------------*/
37 
38 PyDoc_STRVAR(FrsCurve_doc,
39  "Class hierarchy: :class:`Interface1D` > :class:`Curve`\n"
40  "\n"
41  "Base class for curves made of CurvePoints. :class:`SVertex` is the\n"
42  "type of the initial curve vertices. A :class:`Chain` is a\n"
43  "specialization of a Curve.\n"
44  "\n"
45  ".. method:: __init__()\n"
46  " __init__(brother)\n"
47  " __init__(id)\n"
48  "\n"
49  " Builds a :class:`FrsCurve` using a default constructor,\n"
50  " copy constructor or from an :class:`Id`.\n"
51  "\n"
52  " :arg brother: A Curve object.\n"
53  " :type brother: :class:`Curve`\n"
54  " :arg id: An Id object.\n"
55  " :type id: :class:`Id`");
56 
57 static int FrsCurve_init(BPy_FrsCurve *self, PyObject *args, PyObject *kwds)
58 {
59  static const char *kwlist_1[] = {"brother", nullptr};
60  static const char *kwlist_2[] = {"id", nullptr};
61  PyObject *obj = nullptr;
62 
63  if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FrsCurve_Type, &obj)) {
64  if (!obj) {
65  self->c = new Curve();
66  }
67  else {
68  self->c = new Curve(*(((BPy_FrsCurve *)obj)->c));
69  }
70  }
71  else if ((void)PyErr_Clear(),
72  PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Id_Type, &obj)) {
73  self->c = new Curve(*(((BPy_Id *)obj)->id));
74  }
75  else {
76  PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
77  return -1;
78  }
79  self->py_if1D.if1D = self->c;
80  self->py_if1D.borrowed = false;
81  return 0;
82 }
83 
84 PyDoc_STRVAR(FrsCurve_push_vertex_back_doc,
85  ".. method:: push_vertex_back(vertex)\n"
86  "\n"
87  " Adds a single vertex at the end of the Curve.\n"
88  "\n"
89  " :arg vertex: A vertex object.\n"
90  " :type vertex: :class:`SVertex` or :class:`CurvePoint`");
91 
92 static PyObject *FrsCurve_push_vertex_back(BPy_FrsCurve *self, PyObject *args, PyObject *kwds)
93 {
94  static const char *kwlist[] = {"vertex", nullptr};
95  PyObject *obj = nullptr;
96 
97  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj)) {
98  return nullptr;
99  }
100 
101  if (BPy_CurvePoint_Check(obj)) {
102  self->c->push_vertex_back(((BPy_CurvePoint *)obj)->cp);
103  }
104  else if (BPy_SVertex_Check(obj)) {
105  self->c->push_vertex_back(((BPy_SVertex *)obj)->sv);
106  }
107  else {
108  PyErr_SetString(PyExc_TypeError, "invalid argument");
109  return nullptr;
110  }
111  Py_RETURN_NONE;
112 }
113 
114 PyDoc_STRVAR(FrsCurve_push_vertex_front_doc,
115  ".. method:: push_vertex_front(vertex)\n"
116  "\n"
117  " Adds a single vertex at the front of the Curve.\n"
118  "\n"
119  " :arg vertex: A vertex object.\n"
120  " :type vertex: :class:`SVertex` or :class:`CurvePoint`");
121 
122 static PyObject *FrsCurve_push_vertex_front(BPy_FrsCurve *self, PyObject *args, PyObject *kwds)
123 {
124  static const char *kwlist[] = {"vertex", nullptr};
125  PyObject *obj = nullptr;
126 
127  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj)) {
128  return nullptr;
129  }
130 
131  if (BPy_CurvePoint_Check(obj)) {
132  self->c->push_vertex_front(((BPy_CurvePoint *)obj)->cp);
133  }
134  else if (BPy_SVertex_Check(obj)) {
135  self->c->push_vertex_front(((BPy_SVertex *)obj)->sv);
136  }
137  else {
138  PyErr_SetString(PyExc_TypeError, "invalid argument");
139  return nullptr;
140  }
141  Py_RETURN_NONE;
142 }
143 
144 static PyMethodDef BPy_FrsCurve_methods[] = {
145  {"push_vertex_back",
146  (PyCFunction)FrsCurve_push_vertex_back,
147  METH_VARARGS | METH_KEYWORDS,
148  FrsCurve_push_vertex_back_doc},
149  {"push_vertex_front",
150  (PyCFunction)FrsCurve_push_vertex_front,
151  METH_VARARGS | METH_KEYWORDS,
152  FrsCurve_push_vertex_front_doc},
153  {nullptr, nullptr, 0, nullptr},
154 };
155 
156 /*----------------------CurvePoint get/setters ----------------------------*/
157 
158 PyDoc_STRVAR(FrsCurve_is_empty_doc,
159  "True if the Curve doesn't have any Vertex yet.\n"
160  "\n"
161  ":type: bool");
162 
163 static PyObject *FrsCurve_is_empty_get(BPy_FrsCurve *self, void *UNUSED(closure))
164 {
165  return PyBool_from_bool(self->c->empty());
166 }
167 
168 PyDoc_STRVAR(FrsCurve_segments_size_doc,
169  "The number of segments in the polyline constituting the Curve.\n"
170  "\n"
171  ":type: int");
172 
173 static PyObject *FrsCurve_segments_size_get(BPy_FrsCurve *self, void *UNUSED(closure))
174 {
175  return PyLong_FromLong(self->c->nSegments());
176 }
177 
178 static PyGetSetDef BPy_FrsCurve_getseters[] = {
179  {"is_empty", (getter)FrsCurve_is_empty_get, (setter) nullptr, FrsCurve_is_empty_doc, nullptr},
180  {"segments_size",
182  (setter) nullptr,
183  FrsCurve_segments_size_doc,
184  nullptr},
185  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
186 };
187 
188 /*-----------------------BPy_FrsCurve type definition ------------------------------*/
189 
190 PyTypeObject FrsCurve_Type = {
191  PyVarObject_HEAD_INIT(nullptr, 0) "Curve", /* tp_name */
192  sizeof(BPy_FrsCurve), /* tp_basicsize */
193  0, /* tp_itemsize */
194  nullptr, /* tp_dealloc */
195  0, /* tp_vectorcall_offset */
196  nullptr, /* tp_getattr */
197  nullptr, /* tp_setattr */
198  nullptr, /* tp_reserved */
199  nullptr, /* tp_repr */
200  nullptr, /* tp_as_number */
201  nullptr, /* tp_as_sequence */
202  nullptr, /* tp_as_mapping */
203  nullptr, /* tp_hash */
204  nullptr, /* tp_call */
205  nullptr, /* tp_str */
206  nullptr, /* tp_getattro */
207  nullptr, /* tp_setattro */
208  nullptr, /* tp_as_buffer */
209  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
210  FrsCurve_doc, /* tp_doc */
211  nullptr, /* tp_traverse */
212  nullptr, /* tp_clear */
213  nullptr, /* tp_richcompare */
214  0, /* tp_weaklistoffset */
215  nullptr, /* tp_iter */
216  nullptr, /* tp_iternext */
217  BPy_FrsCurve_methods, /* tp_methods */
218  nullptr, /* tp_members */
219  BPy_FrsCurve_getseters, /* tp_getset */
220  &Interface1D_Type, /* tp_base */
221  nullptr, /* tp_dict */
222  nullptr, /* tp_descr_get */
223  nullptr, /* tp_descr_set */
224  0, /* tp_dictoffset */
225  (initproc)FrsCurve_init, /* tp_init */
226  nullptr, /* tp_alloc */
227  nullptr, /* tp_new */
228 };
229 
231 
232 #ifdef __cplusplus
233 }
234 #endif
#define UNUSED(x)
PyObject * PyBool_from_bool(bool b)
Definition: BPy_Convert.cpp:73
#define BPy_CurvePoint_Check(v)
static PyObject * FrsCurve_segments_size_get(BPy_FrsCurve *self, void *UNUSED(closure))
static PyObject * FrsCurve_push_vertex_front(BPy_FrsCurve *self, PyObject *args, PyObject *kwds)
static int FrsCurve_init(BPy_FrsCurve *self, PyObject *args, PyObject *kwds)
static PyObject * FrsCurve_is_empty_get(BPy_FrsCurve *self, void *UNUSED(closure))
PyTypeObject FrsCurve_Type
static PyGetSetDef BPy_FrsCurve_getseters[]
static PyObject * FrsCurve_push_vertex_back(BPy_FrsCurve *self, PyObject *args, PyObject *kwds)
static PyMethodDef BPy_FrsCurve_methods[]
PyDoc_STRVAR(FrsCurve_doc, "Class hierarchy: :class:`Interface1D` > :class:`Curve`\n" "\n" "Base class for curves made of CurvePoints. :class:`SVertex` is the\n" "type of the initial curve vertices. A :class:`Chain` is a\n" "specialization of a Curve.\n" "\n" ".. method:: __init__()\n" " __init__(brother)\n" " __init__(id)\n" "\n" " Builds a :class:`FrsCurve` using a default constructor,\n" " copy constructor or from an :class:`Id`.\n" "\n" " :arg brother: A Curve object.\n" " :type brother: :class:`Curve`\n" " :arg id: An Id object.\n" " :type id: :class:`Id`")
PyTypeObject Id_Type
Definition: BPy_Id.cpp:171
PyTypeObject Interface1D_Type
#define BPy_SVertex_Check(v)
Definition: BPy_SVertex.h:35
struct Curve Curve
PyObject * self
Definition: bpy_driver.c:185
inherits from class Rep
Definition: AppCanvas.cpp:32
static unsigned c
Definition: RandGen.cpp:97
Definition: BPy_Id.h:42