Blender  V2.93
BPy_Interface0D.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BPy_Interface0D.h"
22 
23 #include "BPy_Convert.h"
24 #include "BPy_Nature.h"
31 #include "Interface1D/BPy_FEdge.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 using namespace Freestyle;
38 
40 
41 //-------------------MODULE INITIALIZATION--------------------------------
42 int Interface0D_Init(PyObject *module)
43 {
44  if (module == nullptr) {
45  return -1;
46  }
47 
48  if (PyType_Ready(&Interface0D_Type) < 0) {
49  return -1;
50  }
51  Py_INCREF(&Interface0D_Type);
52  PyModule_AddObject(module, "Interface0D", (PyObject *)&Interface0D_Type);
53 
54  if (PyType_Ready(&CurvePoint_Type) < 0) {
55  return -1;
56  }
57  Py_INCREF(&CurvePoint_Type);
58  PyModule_AddObject(module, "CurvePoint", (PyObject *)&CurvePoint_Type);
59 
60  if (PyType_Ready(&SVertex_Type) < 0) {
61  return -1;
62  }
63  Py_INCREF(&SVertex_Type);
64  PyModule_AddObject(module, "SVertex", (PyObject *)&SVertex_Type);
65 
66  if (PyType_Ready(&ViewVertex_Type) < 0) {
67  return -1;
68  }
69  Py_INCREF(&ViewVertex_Type);
70  PyModule_AddObject(module, "ViewVertex", (PyObject *)&ViewVertex_Type);
71 
72  if (PyType_Ready(&StrokeVertex_Type) < 0) {
73  return -1;
74  }
75  Py_INCREF(&StrokeVertex_Type);
76  PyModule_AddObject(module, "StrokeVertex", (PyObject *)&StrokeVertex_Type);
77 
78  if (PyType_Ready(&NonTVertex_Type) < 0) {
79  return -1;
80  }
81  Py_INCREF(&NonTVertex_Type);
82  PyModule_AddObject(module, "NonTVertex", (PyObject *)&NonTVertex_Type);
83 
84  if (PyType_Ready(&TVertex_Type) < 0) {
85  return -1;
86  }
87  Py_INCREF(&TVertex_Type);
88  PyModule_AddObject(module, "TVertex", (PyObject *)&TVertex_Type);
89 
92 
93  return 0;
94 }
95 
96 /*----------------------Interface1D methods ----------------------------*/
97 
98 PyDoc_STRVAR(Interface0D_doc,
99  "Base class for any 0D element.\n"
100  "\n"
101  ".. method:: __init__()\n"
102  "\n"
103  " Default constructor.");
104 
105 static int Interface0D_init(BPy_Interface0D *self, PyObject *args, PyObject *kwds)
106 {
107  static const char *kwlist[] = {nullptr};
108 
109  if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
110  return -1;
111  }
112  self->if0D = new Interface0D();
113  self->borrowed = false;
114  return 0;
115 }
116 
118 {
119  if (self->if0D && !self->borrowed) {
120  delete self->if0D;
121  }
122  Py_TYPE(self)->tp_free((PyObject *)self);
123 }
124 
125 static PyObject *Interface0D_repr(BPy_Interface0D *self)
126 {
127  return PyUnicode_FromFormat(
128  "type: %s - address: %p", self->if0D->getExactTypeName().c_str(), self->if0D);
129 }
130 
131 PyDoc_STRVAR(Interface0D_get_fedge_doc,
132  ".. method:: get_fedge(inter)\n"
133  "\n"
134  " Returns the FEdge that lies between this 0D element and the 0D\n"
135  " element given as the argument.\n"
136  "\n"
137  " :arg inter: A 0D element.\n"
138  " :type inter: :class:`Interface0D`\n"
139  " :return: The FEdge lying between the two 0D elements.\n"
140  " :rtype: :class:`FEdge`");
141 
142 static PyObject *Interface0D_get_fedge(BPy_Interface0D *self, PyObject *args, PyObject *kwds)
143 {
144  static const char *kwlist[] = {"inter", nullptr};
145  PyObject *py_if0D;
146 
147  if (!PyArg_ParseTupleAndKeywords(
148  args, kwds, "O!", (char **)kwlist, &Interface0D_Type, &py_if0D)) {
149  return nullptr;
150  }
151  FEdge *fe = self->if0D->getFEdge(*(((BPy_Interface0D *)py_if0D)->if0D));
152  if (PyErr_Occurred()) {
153  return nullptr;
154  }
155  if (fe) {
156  return Any_BPy_FEdge_from_FEdge(*fe);
157  }
158  Py_RETURN_NONE;
159 }
160 
161 static PyMethodDef BPy_Interface0D_methods[] = {
162  {"get_fedge",
163  (PyCFunction)Interface0D_get_fedge,
164  METH_VARARGS | METH_KEYWORDS,
165  Interface0D_get_fedge_doc},
166  {nullptr, nullptr, 0, nullptr},
167 };
168 
169 /*----------------------Interface1D get/setters ----------------------------*/
170 
171 PyDoc_STRVAR(Interface0D_name_doc,
172  "The string of the name of this 0D element.\n"
173  "\n"
174  ":type: str");
175 
176 static PyObject *Interface0D_name_get(BPy_Interface0D *self, void *UNUSED(closure))
177 {
178  return PyUnicode_FromString(Py_TYPE(self)->tp_name);
179 }
180 
181 PyDoc_STRVAR(Interface0D_point_3d_doc,
182  "The 3D point of this 0D element.\n"
183  "\n"
184  ":type: :class:`mathutils.Vector`");
185 
186 static PyObject *Interface0D_point_3d_get(BPy_Interface0D *self, void *UNUSED(closure))
187 {
188  Vec3f p(self->if0D->getPoint3D());
189  if (PyErr_Occurred()) {
190  return nullptr;
191  }
192  return Vector_from_Vec3f(p);
193 }
194 
195 PyDoc_STRVAR(Interface0D_projected_x_doc,
196  "The X coordinate of the projected 3D point of this 0D element.\n"
197  "\n"
198  ":type: float");
199 
200 static PyObject *Interface0D_projected_x_get(BPy_Interface0D *self, void *UNUSED(closure))
201 {
202  real x = self->if0D->getProjectedX();
203  if (PyErr_Occurred()) {
204  return nullptr;
205  }
206  return PyFloat_FromDouble(x);
207 }
208 
209 PyDoc_STRVAR(Interface0D_projected_y_doc,
210  "The Y coordinate of the projected 3D point of this 0D element.\n"
211  "\n"
212  ":type: float");
213 
214 static PyObject *Interface0D_projected_y_get(BPy_Interface0D *self, void *UNUSED(closure))
215 {
216  real y = self->if0D->getProjectedY();
217  if (PyErr_Occurred()) {
218  return nullptr;
219  }
220  return PyFloat_FromDouble(y);
221 }
222 
223 PyDoc_STRVAR(Interface0D_projected_z_doc,
224  "The Z coordinate of the projected 3D point of this 0D element.\n"
225  "\n"
226  ":type: float");
227 
228 static PyObject *Interface0D_projected_z_get(BPy_Interface0D *self, void *UNUSED(closure))
229 {
230  real z = self->if0D->getProjectedZ();
231  if (PyErr_Occurred()) {
232  return nullptr;
233  }
234  return PyFloat_FromDouble(z);
235 }
236 
237 PyDoc_STRVAR(Interface0D_point_2d_doc,
238  "The 2D point of this 0D element.\n"
239  "\n"
240  ":type: :class:`mathutils.Vector`");
241 
242 static PyObject *Interface0D_point_2d_get(BPy_Interface0D *self, void *UNUSED(closure))
243 {
244  Vec2f p(self->if0D->getPoint2D());
245  if (PyErr_Occurred()) {
246  return nullptr;
247  }
248  return Vector_from_Vec2f(p);
249 }
250 
251 PyDoc_STRVAR(Interface0D_id_doc,
252  "The Id of this 0D element.\n"
253  "\n"
254  ":type: :class:`Id`");
255 
256 static PyObject *Interface0D_id_get(BPy_Interface0D *self, void *UNUSED(closure))
257 {
258  Id id(self->if0D->getId());
259  if (PyErr_Occurred()) {
260  return nullptr;
261  }
262  return BPy_Id_from_Id(id); // return a copy
263 }
264 
265 PyDoc_STRVAR(Interface0D_nature_doc,
266  "The nature of this 0D element.\n"
267  "\n"
268  ":type: :class:`Nature`");
269 
270 static PyObject *Interface0D_nature_get(BPy_Interface0D *self, void *UNUSED(closure))
271 {
272  Nature::VertexNature nature = self->if0D->getNature();
273  if (PyErr_Occurred()) {
274  return nullptr;
275  }
276  return BPy_Nature_from_Nature(nature);
277 }
278 
279 static PyGetSetDef BPy_Interface0D_getseters[] = {
280  {"name", (getter)Interface0D_name_get, (setter) nullptr, Interface0D_name_doc, nullptr},
281  {"point_3d",
282  (getter)Interface0D_point_3d_get,
283  (setter) nullptr,
284  Interface0D_point_3d_doc,
285  nullptr},
286  {"projected_x",
288  (setter) nullptr,
289  Interface0D_projected_x_doc,
290  nullptr},
291  {"projected_y",
293  (setter) nullptr,
294  Interface0D_projected_y_doc,
295  nullptr},
296  {"projected_z",
298  (setter) nullptr,
299  Interface0D_projected_z_doc,
300  nullptr},
301  {"point_2d",
302  (getter)Interface0D_point_2d_get,
303  (setter) nullptr,
304  Interface0D_point_2d_doc,
305  nullptr},
306  {"id", (getter)Interface0D_id_get, (setter) nullptr, Interface0D_id_doc, nullptr},
307  {"nature", (getter)Interface0D_nature_get, (setter) nullptr, Interface0D_nature_doc, nullptr},
308  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
309 };
310 
311 /*-----------------------BPy_Interface0D type definition ------------------------------*/
312 
313 PyTypeObject Interface0D_Type = {
314  PyVarObject_HEAD_INIT(nullptr, 0) "Interface0D", /* tp_name */
315  sizeof(BPy_Interface0D), /* tp_basicsize */
316  0, /* tp_itemsize */
317  (destructor)Interface0D_dealloc, /* tp_dealloc */
318  0, /* tp_vectorcall_offset */
319  nullptr, /* tp_getattr */
320  nullptr, /* tp_setattr */
321  nullptr, /* tp_reserved */
322  (reprfunc)Interface0D_repr, /* tp_repr */
323  nullptr, /* tp_as_number */
324  nullptr, /* tp_as_sequence */
325  nullptr, /* tp_as_mapping */
326  nullptr, /* tp_hash */
327  nullptr, /* tp_call */
328  nullptr, /* tp_str */
329  nullptr, /* tp_getattro */
330  nullptr, /* tp_setattro */
331  nullptr, /* tp_as_buffer */
332  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
333  Interface0D_doc, /* tp_doc */
334  nullptr, /* tp_traverse */
335  nullptr, /* tp_clear */
336  nullptr, /* tp_richcompare */
337  0, /* tp_weaklistoffset */
338  nullptr, /* tp_iter */
339  nullptr, /* tp_iternext */
340  BPy_Interface0D_methods, /* tp_methods */
341  nullptr, /* tp_members */
342  BPy_Interface0D_getseters, /* tp_getset */
343  nullptr, /* tp_base */
344  nullptr, /* tp_dict */
345  nullptr, /* tp_descr_get */
346  nullptr, /* tp_descr_set */
347  0, /* tp_dictoffset */
348  (initproc)Interface0D_init, /* tp_init */
349  nullptr, /* tp_alloc */
350  PyType_GenericNew, /* tp_new */
351 };
352 
354 
355 #ifdef __cplusplus
356 }
357 #endif
#define UNUSED(x)
PyObject * Vector_from_Vec3f(Vec3f &vec)
Definition: BPy_Convert.cpp:86
PyObject * Vector_from_Vec2f(Vec2f &vec)
Definition: BPy_Convert.cpp:78
PyObject * Any_BPy_FEdge_from_FEdge(FEdge &fe)
PyObject * BPy_Id_from_Id(Id &id)
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
static struct PyModuleDef module
PyObject * self
Definition: bpy_driver.c:185
unsigned short VertexNature
Definition: Nature.h:32
inherits from class Rep
Definition: AppCanvas.cpp:32
static unsigned x[3]
Definition: RandGen.cpp:87
double real
Definition: Precision.h:26