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