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