Blender V5.0
BPy_Interface0D.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_Interface0D.h"
10
11#include "BPy_Convert.h"
12#include "BPy_Nature.h"
20
21using namespace Freestyle;
22
24
25//-------------------MODULE INITIALIZATION--------------------------------
27{
28 if (module == nullptr) {
29 return -1;
30 }
31
32 if (PyType_Ready(&Interface0D_Type) < 0) {
33 return -1;
34 }
35 PyModule_AddObjectRef(module, "Interface0D", (PyObject *)&Interface0D_Type);
36
37 if (PyType_Ready(&CurvePoint_Type) < 0) {
38 return -1;
39 }
40 PyModule_AddObjectRef(module, "CurvePoint", (PyObject *)&CurvePoint_Type);
41
42 if (PyType_Ready(&SVertex_Type) < 0) {
43 return -1;
44 }
45 PyModule_AddObjectRef(module, "SVertex", (PyObject *)&SVertex_Type);
46
47 if (PyType_Ready(&ViewVertex_Type) < 0) {
48 return -1;
49 }
50 PyModule_AddObjectRef(module, "ViewVertex", (PyObject *)&ViewVertex_Type);
51
52 if (PyType_Ready(&StrokeVertex_Type) < 0) {
53 return -1;
54 }
55 PyModule_AddObjectRef(module, "StrokeVertex", (PyObject *)&StrokeVertex_Type);
56
57 if (PyType_Ready(&NonTVertex_Type) < 0) {
58 return -1;
59 }
60 PyModule_AddObjectRef(module, "NonTVertex", (PyObject *)&NonTVertex_Type);
61
62 if (PyType_Ready(&TVertex_Type) < 0) {
63 return -1;
64 }
65 PyModule_AddObjectRef(module, "TVertex", (PyObject *)&TVertex_Type);
66
69
70 return 0;
71}
72
73/*----------------------Interface1D methods ----------------------------*/
74
76 /* Wrap. */
77 Interface0D_doc,
78 "Base class for any 0D element.\n"
79 "\n"
80 ".. method:: __init__()\n"
81 "\n"
82 " Default constructor.\n");
83static int Interface0D_init(BPy_Interface0D *self, PyObject *args, PyObject *kwds)
84{
85 static const char *kwlist[] = {nullptr};
86
87 if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
88 return -1;
89 }
90 self->if0D = new Interface0D();
91 self->borrowed = false;
92 return 0;
93}
94
96{
97 if (self->if0D && !self->borrowed) {
98 delete self->if0D;
99 }
100 Py_TYPE(self)->tp_free((PyObject *)self);
101}
102
104{
105 return PyUnicode_FromFormat(
106 "type: %s - address: %p", self->if0D->getExactTypeName().c_str(), self->if0D);
107}
108
110 /* Wrap. */
111 Interface0D_get_fedge_doc,
112 ".. method:: get_fedge(inter)\n"
113 "\n"
114 " Returns the FEdge that lies between this 0D element and the 0D\n"
115 " element given as the argument.\n"
116 "\n"
117 " :arg inter: A 0D element.\n"
118 " :type inter: :class:`Interface0D`\n"
119 " :return: The FEdge lying between the two 0D elements.\n"
120 " :rtype: :class:`FEdge`\n");
121static PyObject *Interface0D_get_fedge(BPy_Interface0D *self, PyObject *args, PyObject *kwds)
122{
123 static const char *kwlist[] = {"inter", nullptr};
124 PyObject *py_if0D;
125
126 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0D_Type, &py_if0D))
127 {
128 return nullptr;
129 }
130 FEdge *fe = self->if0D->getFEdge(*(((BPy_Interface0D *)py_if0D)->if0D));
131 if (PyErr_Occurred()) {
132 return nullptr;
133 }
134 if (fe) {
135 return Any_BPy_FEdge_from_FEdge(*fe);
136 }
137 Py_RETURN_NONE;
138}
139
140#ifdef __GNUC__
141# ifdef __clang__
142# pragma clang diagnostic push
143# pragma clang diagnostic ignored "-Wcast-function-type"
144# else
145# pragma GCC diagnostic push
146# pragma GCC diagnostic ignored "-Wcast-function-type"
147# endif
148#endif
149
150static PyMethodDef BPy_Interface0D_methods[] = {
151 {"get_fedge",
152 (PyCFunction)Interface0D_get_fedge,
153 METH_VARARGS | METH_KEYWORDS,
154 Interface0D_get_fedge_doc},
155 {nullptr, nullptr, 0, nullptr},
156};
157
158#ifdef __GNUC__
159# ifdef __clang__
160# pragma clang diagnostic pop
161# else
162# pragma GCC diagnostic pop
163# endif
164#endif
165
166/*----------------------Interface1D get/setters ----------------------------*/
167
169 /* Wrap. */
170 Interface0D_name_doc,
171 "The string of the name of this 0D element.\n"
172 "\n"
173 ":type: str\n");
174static PyObject *Interface0D_name_get(BPy_Interface0D *self, void * /*closure*/)
175{
176 return PyUnicode_FromString(Py_TYPE(self)->tp_name);
177}
178
180 /* Wrap. */
181 Interface0D_point_3d_doc,
182 "The 3D point of this 0D element.\n"
183 "\n"
184 ":type: :class:`mathutils.Vector`\n");
185static PyObject *Interface0D_point_3d_get(BPy_Interface0D *self, void * /*closure*/)
186{
187 Vec3f p(self->if0D->getPoint3D());
188 if (PyErr_Occurred()) {
189 return nullptr;
190 }
191 return Vector_from_Vec3f(p);
192}
193
195 /* Wrap. */
196 Interface0D_projected_x_doc,
197 "The X coordinate of the projected 3D point of this 0D element.\n"
198 "\n"
199 ":type: float\n");
200static PyObject *Interface0D_projected_x_get(BPy_Interface0D *self, void * /*closure*/)
201{
202 real x = self->if0D->getProjectedX();
203 if (PyErr_Occurred()) {
204 return nullptr;
205 }
206 return PyFloat_FromDouble(x);
207}
208
210 /* Wrap. */
211 Interface0D_projected_y_doc,
212 "The Y coordinate of the projected 3D point of this 0D element.\n"
213 "\n"
214 ":type: float\n");
215static PyObject *Interface0D_projected_y_get(BPy_Interface0D *self, void * /*closure*/)
216{
217 real y = self->if0D->getProjectedY();
218 if (PyErr_Occurred()) {
219 return nullptr;
220 }
221 return PyFloat_FromDouble(y);
222}
223
225 /* Wrap. */
226 Interface0D_projected_z_doc,
227 "The Z coordinate of the projected 3D point of this 0D element.\n"
228 "\n"
229 ":type: float\n");
230static PyObject *Interface0D_projected_z_get(BPy_Interface0D *self, void * /*closure*/)
231{
232 real z = self->if0D->getProjectedZ();
233 if (PyErr_Occurred()) {
234 return nullptr;
235 }
236 return PyFloat_FromDouble(z);
237}
238
240 /* Wrap. */
241 Interface0D_point_2d_doc,
242 "The 2D point of this 0D element.\n"
243 "\n"
244 ":type: :class:`mathutils.Vector`\n");
245static PyObject *Interface0D_point_2d_get(BPy_Interface0D *self, void * /*closure*/)
246{
247 Vec2f p(self->if0D->getPoint2D());
248 if (PyErr_Occurred()) {
249 return nullptr;
250 }
251 return Vector_from_Vec2f(p);
252}
253
255 /* Wrap. */
256 Interface0D_id_doc,
257 "The Id of this 0D element.\n"
258 "\n"
259 ":type: :class:`Id`\n");
260static PyObject *Interface0D_id_get(BPy_Interface0D *self, void * /*closure*/)
261{
262 Id id(self->if0D->getId());
263 if (PyErr_Occurred()) {
264 return nullptr;
265 }
266 return BPy_Id_from_Id(id); // return a copy
267}
268
270 /* Wrap. */
271 Interface0D_nature_doc,
272 "The nature of this 0D element.\n"
273 "\n"
274 ":type: :class:`Nature`\n");
275static PyObject *Interface0D_nature_get(BPy_Interface0D *self, void * /*closure*/)
276{
277 Nature::VertexNature nature = self->if0D->getNature();
278 if (PyErr_Occurred()) {
279 return nullptr;
280 }
281 return BPy_Nature_from_Nature(nature);
282}
283
284static PyGetSetDef BPy_Interface0D_getseters[] = {
285 {"name", (getter)Interface0D_name_get, (setter) nullptr, Interface0D_name_doc, nullptr},
286 {"point_3d",
288 (setter) nullptr,
289 Interface0D_point_3d_doc,
290 nullptr},
291 {"projected_x",
293 (setter) nullptr,
294 Interface0D_projected_x_doc,
295 nullptr},
296 {"projected_y",
298 (setter) nullptr,
299 Interface0D_projected_y_doc,
300 nullptr},
301 {"projected_z",
303 (setter) nullptr,
304 Interface0D_projected_z_doc,
305 nullptr},
306 {"point_2d",
308 (setter) nullptr,
309 Interface0D_point_2d_doc,
310 nullptr},
311 {"id", (getter)Interface0D_id_get, (setter) nullptr, Interface0D_id_doc, nullptr},
312 {"nature", (getter)Interface0D_nature_get, (setter) nullptr, Interface0D_nature_doc, nullptr},
313 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
314};
315
316/*-----------------------BPy_Interface0D type definition ------------------------------*/
317
318PyTypeObject Interface0D_Type = {
319 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
320 /*tp_name*/ "Interface0D",
321 /*tp_basicsize*/ sizeof(BPy_Interface0D),
322 /*tp_itemsize*/ 0,
323 /*tp_dealloc*/ (destructor)Interface0D_dealloc,
324 /*tp_vectorcall_offset*/ 0,
325 /*tp_getattr*/ nullptr,
326 /*tp_setattr*/ nullptr,
327 /*tp_as_async*/ nullptr,
328 /*tp_repr*/ (reprfunc)Interface0D_repr,
329 /*tp_as_number*/ nullptr,
330 /*tp_as_sequence*/ nullptr,
331 /*tp_as_mapping*/ nullptr,
332 /*tp_hash*/ nullptr,
333 /*tp_call*/ nullptr,
334 /*tp_str*/ nullptr,
335 /*tp_getattro*/ nullptr,
336 /*tp_setattro*/ nullptr,
337 /*tp_as_buffer*/ nullptr,
338 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
339 /*tp_doc*/ Interface0D_doc,
340 /*tp_traverse*/ nullptr,
341 /*tp_clear*/ nullptr,
342 /*tp_richcompare*/ nullptr,
343 /*tp_weaklistoffset*/ 0,
344 /*tp_iter*/ nullptr,
345 /*tp_iternext*/ nullptr,
346 /*tp_methods*/ BPy_Interface0D_methods,
347 /*tp_members*/ nullptr,
348 /*tp_getset*/ BPy_Interface0D_getseters,
349 /*tp_base*/ nullptr,
350 /*tp_dict*/ nullptr,
351 /*tp_descr_get*/ nullptr,
352 /*tp_descr_set*/ nullptr,
353 /*tp_dictoffset*/ 0,
354 /*tp_init*/ (initproc)Interface0D_init,
355 /*tp_alloc*/ nullptr,
356 /*tp_new*/ PyType_GenericNew,
357};
358
PyObject * BPy_Id_from_Id(Id &id)
PyObject * Any_BPy_FEdge_from_FEdge(FEdge &fe)
PyObject * BPy_Nature_from_Nature(ushort n)
PyObject * Vector_from_Vec3f(Vec3f &vec)
PyObject * Vector_from_Vec2f(Vec2f &vec)
PyTypeObject CurvePoint_Type
static PyObject * Interface0D_id_get(BPy_Interface0D *self, void *)
static void Interface0D_dealloc(BPy_Interface0D *self)
static PyObject * Interface0D_get_fedge(BPy_Interface0D *self, PyObject *args, PyObject *kwds)
PyTypeObject Interface0D_Type
static int Interface0D_init(BPy_Interface0D *self, PyObject *args, PyObject *kwds)
PyDoc_STRVAR(Interface0D_doc, "Base class for any 0D element.\n" "\n" ".. method:: __init__()\n" "\n" " Default constructor.\n")
static PyGetSetDef BPy_Interface0D_getseters[]
static PyObject * Interface0D_repr(BPy_Interface0D *self)
static PyObject * Interface0D_name_get(BPy_Interface0D *self, void *)
static PyObject * Interface0D_projected_y_get(BPy_Interface0D *self, void *)
static PyMethodDef BPy_Interface0D_methods[]
int Interface0D_Init(PyObject *module)
static PyObject * Interface0D_projected_z_get(BPy_Interface0D *self, void *)
static PyObject * Interface0D_point_2d_get(BPy_Interface0D *self, void *)
static PyObject * Interface0D_nature_get(BPy_Interface0D *self, void *)
static PyObject * Interface0D_projected_x_get(BPy_Interface0D *self, void *)
static PyObject * Interface0D_point_3d_get(BPy_Interface0D *self, void *)
PyTypeObject NonTVertex_Type
void SVertex_mathutils_register_callback()
PyTypeObject SVertex_Type
void StrokeVertex_mathutils_register_callback()
PyTypeObject StrokeVertex_Type
PyTypeObject TVertex_Type
PyTypeObject ViewVertex_Type
PyObject * self
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
VecMat::Vec2< float > Vec2f
Definition Geom.h:22
ushort VertexNature
Definition Nature.h:22
inherits from class Rep
Definition AppCanvas.cpp:20
double real
Definition Precision.h:14
static struct PyModuleDef module
Definition python.cpp:796