Blender V4.5
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.");
83
84static int Interface0D_init(BPy_Interface0D *self, PyObject *args, PyObject *kwds)
85{
86 static const char *kwlist[] = {nullptr};
87
88 if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
89 return -1;
90 }
91 self->if0D = new Interface0D();
92 self->borrowed = false;
93 return 0;
94}
95
97{
98 if (self->if0D && !self->borrowed) {
99 delete self->if0D;
100 }
101 Py_TYPE(self)->tp_free((PyObject *)self);
102}
103
105{
106 return PyUnicode_FromFormat(
107 "type: %s - address: %p", self->if0D->getExactTypeName().c_str(), self->if0D);
108}
109
111 /* Wrap. */
112 Interface0D_get_fedge_doc,
113 ".. method:: get_fedge(inter)\n"
114 "\n"
115 " Returns the FEdge that lies between this 0D element and the 0D\n"
116 " element given as the argument.\n"
117 "\n"
118 " :arg inter: A 0D element.\n"
119 " :type inter: :class:`Interface0D`\n"
120 " :return: The FEdge lying between the two 0D elements.\n"
121 " :rtype: :class:`FEdge`");
122
123static PyObject *Interface0D_get_fedge(BPy_Interface0D *self, PyObject *args, PyObject *kwds)
124{
125 static const char *kwlist[] = {"inter", nullptr};
126 PyObject *py_if0D;
127
128 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface0D_Type, &py_if0D))
129 {
130 return nullptr;
131 }
132 FEdge *fe = self->if0D->getFEdge(*(((BPy_Interface0D *)py_if0D)->if0D));
133 if (PyErr_Occurred()) {
134 return nullptr;
135 }
136 if (fe) {
137 return Any_BPy_FEdge_from_FEdge(*fe);
138 }
139 Py_RETURN_NONE;
140}
141
142#ifdef __GNUC__
143# ifdef __clang__
144# pragma clang diagnostic push
145# pragma clang diagnostic ignored "-Wcast-function-type"
146# else
147# pragma GCC diagnostic push
148# pragma GCC diagnostic ignored "-Wcast-function-type"
149# endif
150#endif
151
152static PyMethodDef BPy_Interface0D_methods[] = {
153 {"get_fedge",
154 (PyCFunction)Interface0D_get_fedge,
155 METH_VARARGS | METH_KEYWORDS,
156 Interface0D_get_fedge_doc},
157 {nullptr, nullptr, 0, nullptr},
158};
159
160#ifdef __GNUC__
161# ifdef __clang__
162# pragma clang diagnostic pop
163# else
164# pragma GCC diagnostic pop
165# endif
166#endif
167
168/*----------------------Interface1D get/setters ----------------------------*/
169
171 /* Wrap. */
172 Interface0D_name_doc,
173 "The string of the name of this 0D element.\n"
174 "\n"
175 ":type: str");
176
177static PyObject *Interface0D_name_get(BPy_Interface0D *self, void * /*closure*/)
178{
179 return PyUnicode_FromString(Py_TYPE(self)->tp_name);
180}
181
183 /* Wrap. */
184 Interface0D_point_3d_doc,
185 "The 3D point of this 0D element.\n"
186 "\n"
187 ":type: :class:`mathutils.Vector`");
188
189static PyObject *Interface0D_point_3d_get(BPy_Interface0D *self, void * /*closure*/)
190{
191 Vec3f p(self->if0D->getPoint3D());
192 if (PyErr_Occurred()) {
193 return nullptr;
194 }
195 return Vector_from_Vec3f(p);
196}
197
199 /* Wrap. */
200 Interface0D_projected_x_doc,
201 "The X coordinate of the projected 3D point of this 0D element.\n"
202 "\n"
203 ":type: float");
204
205static PyObject *Interface0D_projected_x_get(BPy_Interface0D *self, void * /*closure*/)
206{
207 real x = self->if0D->getProjectedX();
208 if (PyErr_Occurred()) {
209 return nullptr;
210 }
211 return PyFloat_FromDouble(x);
212}
213
215 /* Wrap. */
216 Interface0D_projected_y_doc,
217 "The Y coordinate of the projected 3D point of this 0D element.\n"
218 "\n"
219 ":type: float");
220
221static PyObject *Interface0D_projected_y_get(BPy_Interface0D *self, void * /*closure*/)
222{
223 real y = self->if0D->getProjectedY();
224 if (PyErr_Occurred()) {
225 return nullptr;
226 }
227 return PyFloat_FromDouble(y);
228}
229
231 /* Wrap. */
232 Interface0D_projected_z_doc,
233 "The Z coordinate of the projected 3D point of this 0D element.\n"
234 "\n"
235 ":type: float");
236
237static PyObject *Interface0D_projected_z_get(BPy_Interface0D *self, void * /*closure*/)
238{
239 real z = self->if0D->getProjectedZ();
240 if (PyErr_Occurred()) {
241 return nullptr;
242 }
243 return PyFloat_FromDouble(z);
244}
245
247 /* Wrap. */
248 Interface0D_point_2d_doc,
249 "The 2D point of this 0D element.\n"
250 "\n"
251 ":type: :class:`mathutils.Vector`");
252
253static PyObject *Interface0D_point_2d_get(BPy_Interface0D *self, void * /*closure*/)
254{
255 Vec2f p(self->if0D->getPoint2D());
256 if (PyErr_Occurred()) {
257 return nullptr;
258 }
259 return Vector_from_Vec2f(p);
260}
261
263 /* Wrap. */
264 Interface0D_id_doc,
265 "The Id of this 0D element.\n"
266 "\n"
267 ":type: :class:`Id`");
268
269static PyObject *Interface0D_id_get(BPy_Interface0D *self, void * /*closure*/)
270{
271 Id id(self->if0D->getId());
272 if (PyErr_Occurred()) {
273 return nullptr;
274 }
275 return BPy_Id_from_Id(id); // return a copy
276}
277
279 /* Wrap. */
280 Interface0D_nature_doc,
281 "The nature of this 0D element.\n"
282 "\n"
283 ":type: :class:`Nature`");
284
285static PyObject *Interface0D_nature_get(BPy_Interface0D *self, void * /*closure*/)
286{
287 Nature::VertexNature nature = self->if0D->getNature();
288 if (PyErr_Occurred()) {
289 return nullptr;
290 }
291 return BPy_Nature_from_Nature(nature);
292}
293
294static PyGetSetDef BPy_Interface0D_getseters[] = {
295 {"name", (getter)Interface0D_name_get, (setter) nullptr, Interface0D_name_doc, nullptr},
296 {"point_3d",
298 (setter) nullptr,
299 Interface0D_point_3d_doc,
300 nullptr},
301 {"projected_x",
303 (setter) nullptr,
304 Interface0D_projected_x_doc,
305 nullptr},
306 {"projected_y",
308 (setter) nullptr,
309 Interface0D_projected_y_doc,
310 nullptr},
311 {"projected_z",
313 (setter) nullptr,
314 Interface0D_projected_z_doc,
315 nullptr},
316 {"point_2d",
318 (setter) nullptr,
319 Interface0D_point_2d_doc,
320 nullptr},
321 {"id", (getter)Interface0D_id_get, (setter) nullptr, Interface0D_id_doc, nullptr},
322 {"nature", (getter)Interface0D_nature_get, (setter) nullptr, Interface0D_nature_doc, nullptr},
323 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
324};
325
326/*-----------------------BPy_Interface0D type definition ------------------------------*/
327
328PyTypeObject Interface0D_Type = {
329 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
330 /*tp_name*/ "Interface0D",
331 /*tp_basicsize*/ sizeof(BPy_Interface0D),
332 /*tp_itemsize*/ 0,
333 /*tp_dealloc*/ (destructor)Interface0D_dealloc,
334 /*tp_vectorcall_offset*/ 0,
335 /*tp_getattr*/ nullptr,
336 /*tp_setattr*/ nullptr,
337 /*tp_as_async*/ nullptr,
338 /*tp_repr*/ (reprfunc)Interface0D_repr,
339 /*tp_as_number*/ nullptr,
340 /*tp_as_sequence*/ nullptr,
341 /*tp_as_mapping*/ nullptr,
342 /*tp_hash*/ nullptr,
343 /*tp_call*/ nullptr,
344 /*tp_str*/ nullptr,
345 /*tp_getattro*/ nullptr,
346 /*tp_setattro*/ nullptr,
347 /*tp_as_buffer*/ nullptr,
348 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
349 /*tp_doc*/ Interface0D_doc,
350 /*tp_traverse*/ nullptr,
351 /*tp_clear*/ nullptr,
352 /*tp_richcompare*/ nullptr,
353 /*tp_weaklistoffset*/ 0,
354 /*tp_iter*/ nullptr,
355 /*tp_iternext*/ nullptr,
356 /*tp_methods*/ BPy_Interface0D_methods,
357 /*tp_members*/ nullptr,
358 /*tp_getset*/ BPy_Interface0D_getseters,
359 /*tp_base*/ nullptr,
360 /*tp_dict*/ nullptr,
361 /*tp_descr_get*/ nullptr,
362 /*tp_descr_set*/ nullptr,
363 /*tp_dictoffset*/ 0,
364 /*tp_init*/ (initproc)Interface0D_init,
365 /*tp_alloc*/ nullptr,
366 /*tp_new*/ PyType_GenericNew,
367};
368
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)
static PyGetSetDef BPy_Interface0D_getseters[]
static PyObject * Interface0D_repr(BPy_Interface0D *self)
static PyObject * Interface0D_name_get(BPy_Interface0D *self, void *)
PyDoc_STRVAR(Interface0D_doc, "Base class for any 0D element.\n" "\n" ".. method:: __init__()\n" "\n" " Default constructor.")
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