Blender  V3.3
BPy_FrsCurve.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BPy_FrsCurve.h"
8 
9 #include "../BPy_Convert.h"
10 #include "../BPy_Id.h"
11 #include "../Interface0D/BPy_CurvePoint.h"
12 #include "../Interface0D/BPy_SVertex.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 using namespace Freestyle;
19 
21 
22 /*----------------------CurvePoint methods ----------------------------*/
23 
24 PyDoc_STRVAR(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 
43 static 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  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 
70 PyDoc_STRVAR(FrsCurve_push_vertex_back_doc,
71  ".. method:: push_vertex_back(vertex)\n"
72  "\n"
73  " Adds a single vertex at the end of the Curve.\n"
74  "\n"
75  " :arg vertex: A vertex object.\n"
76  " :type vertex: :class:`SVertex` or :class:`CurvePoint`");
77 
78 static PyObject *FrsCurve_push_vertex_back(BPy_FrsCurve *self, PyObject *args, PyObject *kwds)
79 {
80  static const char *kwlist[] = {"vertex", nullptr};
81  PyObject *obj = nullptr;
82 
83  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj)) {
84  return nullptr;
85  }
86 
87  if (BPy_CurvePoint_Check(obj)) {
88  self->c->push_vertex_back(((BPy_CurvePoint *)obj)->cp);
89  }
90  else if (BPy_SVertex_Check(obj)) {
91  self->c->push_vertex_back(((BPy_SVertex *)obj)->sv);
92  }
93  else {
94  PyErr_SetString(PyExc_TypeError, "invalid argument");
95  return nullptr;
96  }
97  Py_RETURN_NONE;
98 }
99 
100 PyDoc_STRVAR(FrsCurve_push_vertex_front_doc,
101  ".. method:: push_vertex_front(vertex)\n"
102  "\n"
103  " Adds a single vertex at the front of the Curve.\n"
104  "\n"
105  " :arg vertex: A vertex object.\n"
106  " :type vertex: :class:`SVertex` or :class:`CurvePoint`");
107 
108 static PyObject *FrsCurve_push_vertex_front(BPy_FrsCurve *self, PyObject *args, PyObject *kwds)
109 {
110  static const char *kwlist[] = {"vertex", nullptr};
111  PyObject *obj = nullptr;
112 
113  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", (char **)kwlist, &obj)) {
114  return nullptr;
115  }
116 
117  if (BPy_CurvePoint_Check(obj)) {
118  self->c->push_vertex_front(((BPy_CurvePoint *)obj)->cp);
119  }
120  else if (BPy_SVertex_Check(obj)) {
121  self->c->push_vertex_front(((BPy_SVertex *)obj)->sv);
122  }
123  else {
124  PyErr_SetString(PyExc_TypeError, "invalid argument");
125  return nullptr;
126  }
127  Py_RETURN_NONE;
128 }
129 
130 static PyMethodDef BPy_FrsCurve_methods[] = {
131  {"push_vertex_back",
132  (PyCFunction)FrsCurve_push_vertex_back,
133  METH_VARARGS | METH_KEYWORDS,
134  FrsCurve_push_vertex_back_doc},
135  {"push_vertex_front",
136  (PyCFunction)FrsCurve_push_vertex_front,
137  METH_VARARGS | METH_KEYWORDS,
138  FrsCurve_push_vertex_front_doc},
139  {nullptr, nullptr, 0, nullptr},
140 };
141 
142 /*----------------------CurvePoint get/setters ----------------------------*/
143 
144 PyDoc_STRVAR(FrsCurve_is_empty_doc,
145  "True if the Curve doesn't have any Vertex yet.\n"
146  "\n"
147  ":type: bool");
148 
149 static PyObject *FrsCurve_is_empty_get(BPy_FrsCurve *self, void *UNUSED(closure))
150 {
151  return PyBool_from_bool(self->c->empty());
152 }
153 
154 PyDoc_STRVAR(FrsCurve_segments_size_doc,
155  "The number of segments in the polyline constituting the Curve.\n"
156  "\n"
157  ":type: int");
158 
159 static PyObject *FrsCurve_segments_size_get(BPy_FrsCurve *self, void *UNUSED(closure))
160 {
161  return PyLong_FromLong(self->c->nSegments());
162 }
163 
164 static PyGetSetDef BPy_FrsCurve_getseters[] = {
165  {"is_empty", (getter)FrsCurve_is_empty_get, (setter) nullptr, FrsCurve_is_empty_doc, nullptr},
166  {"segments_size",
168  (setter) nullptr,
169  FrsCurve_segments_size_doc,
170  nullptr},
171  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
172 };
173 
174 /*-----------------------BPy_FrsCurve type definition ------------------------------*/
175 
176 PyTypeObject FrsCurve_Type = {
177  PyVarObject_HEAD_INIT(nullptr, 0) "Curve", /* tp_name */
178  sizeof(BPy_FrsCurve), /* tp_basicsize */
179  0, /* tp_itemsize */
180  nullptr, /* tp_dealloc */
181  0, /* tp_vectorcall_offset */
182  nullptr, /* tp_getattr */
183  nullptr, /* tp_setattr */
184  nullptr, /* tp_reserved */
185  nullptr, /* tp_repr */
186  nullptr, /* tp_as_number */
187  nullptr, /* tp_as_sequence */
188  nullptr, /* tp_as_mapping */
189  nullptr, /* tp_hash */
190  nullptr, /* tp_call */
191  nullptr, /* tp_str */
192  nullptr, /* tp_getattro */
193  nullptr, /* tp_setattro */
194  nullptr, /* tp_as_buffer */
195  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
196  FrsCurve_doc, /* tp_doc */
197  nullptr, /* tp_traverse */
198  nullptr, /* tp_clear */
199  nullptr, /* tp_richcompare */
200  0, /* tp_weaklistoffset */
201  nullptr, /* tp_iter */
202  nullptr, /* tp_iternext */
203  BPy_FrsCurve_methods, /* tp_methods */
204  nullptr, /* tp_members */
205  BPy_FrsCurve_getseters, /* tp_getset */
206  &Interface1D_Type, /* tp_base */
207  nullptr, /* tp_dict */
208  nullptr, /* tp_descr_get */
209  nullptr, /* tp_descr_set */
210  0, /* tp_dictoffset */
211  (initproc)FrsCurve_init, /* tp_init */
212  nullptr, /* tp_alloc */
213  nullptr, /* tp_new */
214 };
215 
217 
218 #ifdef __cplusplus
219 }
220 #endif
#define UNUSED(x)
PyObject * PyBool_from_bool(bool b)
Definition: BPy_Convert.cpp:59
#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:157
PyTypeObject Interface1D_Type
#define BPy_SVertex_Check(v)
Definition: BPy_SVertex.h:21
struct Curve Curve
PyObject * self
Definition: bpy_driver.c:165
inherits from class Rep
Definition: AppCanvas.cpp:18
static unsigned c
Definition: RandGen.cpp:83
Definition: BPy_Id.h:28