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