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