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