Blender V5.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
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--------------------------------
26int Interface0D_Init(PyObject *module)
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
103static PyObject *Interface0D_repr(BPy_Interface0D *self)
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 " :param 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,
127 kwds,
128 "O!" /* `inter` */
129 ":get_fedge",
130 (char **)kwlist,
132 &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
146#ifdef __GNUC__
147# ifdef __clang__
148# pragma clang diagnostic push
149# pragma clang diagnostic ignored "-Wcast-function-type"
150# else
151# pragma GCC diagnostic push
152# pragma GCC diagnostic ignored "-Wcast-function-type"
153# endif
154#endif
155
156static PyMethodDef BPy_Interface0D_methods[] = {
157 {"get_fedge",
158 (PyCFunction)Interface0D_get_fedge,
159 METH_VARARGS | METH_KEYWORDS,
160 Interface0D_get_fedge_doc},
161 {nullptr, nullptr, 0, nullptr},
162};
163
164#ifdef __GNUC__
165# ifdef __clang__
166# pragma clang diagnostic pop
167# else
168# pragma GCC diagnostic pop
169# endif
170#endif
171
172/*----------------------Interface1D get/setters ----------------------------*/
173
175 /* Wrap. */
176 Interface0D_name_doc,
177 "The string of the name of this 0D element.\n"
178 "\n"
179 ":type: str\n");
180static PyObject *Interface0D_name_get(BPy_Interface0D *self, void * /*closure*/)
181{
182 return PyUnicode_FromString(Py_TYPE(self)->tp_name);
183}
184
186 /* Wrap. */
187 Interface0D_point_3d_doc,
188 "The 3D point of this 0D element.\n"
189 "\n"
190 ":type: :class:`mathutils.Vector`\n");
191static PyObject *Interface0D_point_3d_get(BPy_Interface0D *self, void * /*closure*/)
192{
193 Vec3f p(self->if0D->getPoint3D());
194 if (PyErr_Occurred()) {
195 return nullptr;
196 }
197 return Vector_from_Vec3f(p);
198}
199
201 /* Wrap. */
202 Interface0D_projected_x_doc,
203 "The X coordinate of the projected 3D point of this 0D element.\n"
204 "\n"
205 ":type: float\n");
206static PyObject *Interface0D_projected_x_get(BPy_Interface0D *self, void * /*closure*/)
207{
208 real x = self->if0D->getProjectedX();
209 if (PyErr_Occurred()) {
210 return nullptr;
211 }
212 return PyFloat_FromDouble(x);
213}
214
216 /* Wrap. */
217 Interface0D_projected_y_doc,
218 "The Y coordinate of the projected 3D point of this 0D element.\n"
219 "\n"
220 ":type: float\n");
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\n");
236static PyObject *Interface0D_projected_z_get(BPy_Interface0D *self, void * /*closure*/)
237{
238 real z = self->if0D->getProjectedZ();
239 if (PyErr_Occurred()) {
240 return nullptr;
241 }
242 return PyFloat_FromDouble(z);
243}
244
246 /* Wrap. */
247 Interface0D_point_2d_doc,
248 "The 2D point of this 0D element.\n"
249 "\n"
250 ":type: :class:`mathutils.Vector`\n");
251static PyObject *Interface0D_point_2d_get(BPy_Interface0D *self, void * /*closure*/)
252{
253 Vec2f p(self->if0D->getPoint2D());
254 if (PyErr_Occurred()) {
255 return nullptr;
256 }
257 return Vector_from_Vec2f(p);
258}
259
261 /* Wrap. */
262 Interface0D_id_doc,
263 "The Id of this 0D element.\n"
264 "\n"
265 ":type: :class:`Id`\n");
266static PyObject *Interface0D_id_get(BPy_Interface0D *self, void * /*closure*/)
267{
268 Id id(self->if0D->getId());
269 if (PyErr_Occurred()) {
270 return nullptr;
271 }
272 return BPy_Id_from_Id(id); // return a copy
273}
274
276 /* Wrap. */
277 Interface0D_nature_doc,
278 "The nature of this 0D element.\n"
279 "\n"
280 ":type: :class:`Nature`\n");
281static PyObject *Interface0D_nature_get(BPy_Interface0D *self, void * /*closure*/)
282{
283 Nature::VertexNature nature = self->if0D->getNature();
284 if (PyErr_Occurred()) {
285 return nullptr;
286 }
287 return BPy_Nature_from_Nature(nature);
288}
289
290static PyGetSetDef BPy_Interface0D_getseters[] = {
291 {"name", (getter)Interface0D_name_get, (setter) nullptr, Interface0D_name_doc, nullptr},
292 {"point_3d",
294 (setter) nullptr,
295 Interface0D_point_3d_doc,
296 nullptr},
297 {"projected_x",
299 (setter) nullptr,
300 Interface0D_projected_x_doc,
301 nullptr},
302 {"projected_y",
304 (setter) nullptr,
305 Interface0D_projected_y_doc,
306 nullptr},
307 {"projected_z",
309 (setter) nullptr,
310 Interface0D_projected_z_doc,
311 nullptr},
312 {"point_2d",
314 (setter) nullptr,
315 Interface0D_point_2d_doc,
316 nullptr},
317 {"id", (getter)Interface0D_id_get, (setter) nullptr, Interface0D_id_doc, nullptr},
318 {"nature", (getter)Interface0D_nature_get, (setter) nullptr, Interface0D_nature_doc, nullptr},
319 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
320};
321
322/*-----------------------BPy_Interface0D type definition ------------------------------*/
323
324PyTypeObject Interface0D_Type = {
325 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
326 /*tp_name*/ "Interface0D",
327 /*tp_basicsize*/ sizeof(BPy_Interface0D),
328 /*tp_itemsize*/ 0,
329 /*tp_dealloc*/ (destructor)Interface0D_dealloc,
330 /*tp_vectorcall_offset*/ 0,
331 /*tp_getattr*/ nullptr,
332 /*tp_setattr*/ nullptr,
333 /*tp_as_async*/ nullptr,
334 /*tp_repr*/ (reprfunc)Interface0D_repr,
335 /*tp_as_number*/ nullptr,
336 /*tp_as_sequence*/ nullptr,
337 /*tp_as_mapping*/ nullptr,
338 /*tp_hash*/ nullptr,
339 /*tp_call*/ nullptr,
340 /*tp_str*/ nullptr,
341 /*tp_getattro*/ nullptr,
342 /*tp_setattro*/ nullptr,
343 /*tp_as_buffer*/ nullptr,
344 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
345 /*tp_doc*/ Interface0D_doc,
346 /*tp_traverse*/ nullptr,
347 /*tp_clear*/ nullptr,
348 /*tp_richcompare*/ nullptr,
349 /*tp_weaklistoffset*/ 0,
350 /*tp_iter*/ nullptr,
351 /*tp_iternext*/ nullptr,
352 /*tp_methods*/ BPy_Interface0D_methods,
353 /*tp_members*/ nullptr,
354 /*tp_getset*/ BPy_Interface0D_getseters,
355 /*tp_base*/ nullptr,
356 /*tp_dict*/ nullptr,
357 /*tp_descr_get*/ nullptr,
358 /*tp_descr_set*/ nullptr,
359 /*tp_dictoffset*/ 0,
360 /*tp_init*/ (initproc)Interface0D_init,
361 /*tp_alloc*/ nullptr,
362 /*tp_new*/ PyType_GenericNew,
363};
364
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
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
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 *)
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
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
virtual real getProjectedX() const
virtual Geometry::Vec2r getPoint2D() const
virtual FEdge * getFEdge(Interface0D &)
virtual string getExactTypeName() const
Definition Interface0D.h:50
virtual Nature::VertexNature getNature() const
virtual Id getId() const
virtual Geometry::Vec3r getPoint3D() const
virtual real getProjectedZ() const
virtual real getProjectedY() const
VecMat::Vec3< float > Vec3f
Definition Geom.h:28
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
PyObject_HEAD Freestyle::Interface0D * if0D