Blender  V3.3
BPy_UnaryFunction0DVec3f.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
8 
9 #include "../BPy_Convert.h"
10 #include "../Iterator/BPy_Interface0DIterator.h"
11 
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 using namespace Freestyle;
19 
21 
22 //-------------------MODULE INITIALIZATION--------------------------------
23 
25 {
26  if (module == nullptr) {
27  return -1;
28  }
29 
30  if (PyType_Ready(&UnaryFunction0DVec3f_Type) < 0) {
31  return -1;
32  }
33  Py_INCREF(&UnaryFunction0DVec3f_Type);
34  PyModule_AddObject(module, "UnaryFunction0DVec3f", (PyObject *)&UnaryFunction0DVec3f_Type);
35 
36  if (PyType_Ready(&VertexOrientation3DF0D_Type) < 0) {
37  return -1;
38  }
39  Py_INCREF(&VertexOrientation3DF0D_Type);
40  PyModule_AddObject(module, "VertexOrientation3DF0D", (PyObject *)&VertexOrientation3DF0D_Type);
41 
42  return 0;
43 }
44 
45 //------------------------INSTANCE METHODS ----------------------------------
46 
48  "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DVec3f`\n"
49  "\n"
50  "Base class for unary functions (functors) that work on\n"
51  ":class:`Interface0DIterator` and return a 3D vector.\n"
52  "\n"
53  ".. method:: __init__()\n"
54  "\n"
55  " Default constructor.\n";
56 
58  PyObject *args,
59  PyObject *kwds)
60 {
61  static const char *kwlist[] = {nullptr};
62 
63  if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
64  return -1;
65  }
66  self->uf0D_vec3f = new UnaryFunction0D<Vec3f>();
67  self->uf0D_vec3f->py_uf0D = (PyObject *)self;
68  return 0;
69 }
70 
72 {
73  delete self->uf0D_vec3f;
74  UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
75 }
76 
78 {
79  return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_vec3f);
80 }
81 
83  PyObject *args,
84  PyObject *kwds)
85 {
86  static const char *kwlist[] = {"it", nullptr};
87  PyObject *obj;
88 
89  if (!PyArg_ParseTupleAndKeywords(
90  args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
91  return nullptr;
92  }
93 
94  if (typeid(*(self->uf0D_vec3f)) == typeid(UnaryFunction0D<Vec3f>)) {
95  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
96  return nullptr;
97  }
98  if (self->uf0D_vec3f->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
99  if (!PyErr_Occurred()) {
100  string class_name(Py_TYPE(self)->tp_name);
101  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
102  }
103  return nullptr;
104  }
105  return Vector_from_Vec3f(self->uf0D_vec3f->result);
106 }
107 
108 /*-----------------------BPy_UnaryFunction0DVec3f type definition ------------------------------*/
109 
111  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction0DVec3f", /* tp_name */
112  sizeof(BPy_UnaryFunction0DVec3f), /* tp_basicsize */
113  0, /* tp_itemsize */
114  (destructor)UnaryFunction0DVec3f___dealloc__, /* tp_dealloc */
115  0, /* tp_vectorcall_offset */
116  nullptr, /* tp_getattr */
117  nullptr, /* tp_setattr */
118  nullptr, /* tp_reserved */
119  (reprfunc)UnaryFunction0DVec3f___repr__, /* tp_repr */
120  nullptr, /* tp_as_number */
121  nullptr, /* tp_as_sequence */
122  nullptr, /* tp_as_mapping */
123  nullptr, /* tp_hash */
124  (ternaryfunc)UnaryFunction0DVec3f___call__, /* tp_call */
125  nullptr, /* tp_str */
126  nullptr, /* tp_getattro */
127  nullptr, /* tp_setattro */
128  nullptr, /* tp_as_buffer */
129  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
130  UnaryFunction0DVec3f___doc__, /* tp_doc */
131  nullptr, /* tp_traverse */
132  nullptr, /* tp_clear */
133  nullptr, /* tp_richcompare */
134  0, /* tp_weaklistoffset */
135  nullptr, /* tp_iter */
136  nullptr, /* tp_iternext */
137  nullptr, /* tp_methods */
138  nullptr, /* tp_members */
139  nullptr, /* tp_getset */
140  &UnaryFunction0D_Type, /* tp_base */
141  nullptr, /* tp_dict */
142  nullptr, /* tp_descr_get */
143  nullptr, /* tp_descr_set */
144  0, /* tp_dictoffset */
145  (initproc)UnaryFunction0DVec3f___init__, /* tp_init */
146  nullptr, /* tp_alloc */
147  nullptr, /* tp_new */
148 };
149 
151 
152 #ifdef __cplusplus
153 }
154 #endif
PyObject * Vector_from_Vec3f(Vec3f &vec)
Definition: BPy_Convert.cpp:72
PyTypeObject Interface0DIterator_Type
static void UnaryFunction0DVec3f___dealloc__(BPy_UnaryFunction0DVec3f *self)
static char UnaryFunction0DVec3f___doc__[]
static PyObject * UnaryFunction0DVec3f___call__(BPy_UnaryFunction0DVec3f *self, PyObject *args, PyObject *kwds)
int UnaryFunction0DVec3f_Init(PyObject *module)
static PyObject * UnaryFunction0DVec3f___repr__(BPy_UnaryFunction0DVec3f *self)
PyTypeObject UnaryFunction0DVec3f_Type
static int UnaryFunction0DVec3f___init__(BPy_UnaryFunction0DVec3f *self, PyObject *args, PyObject *kwds)
PyTypeObject UnaryFunction0D_Type
PyTypeObject VertexOrientation3DF0D_Type
PyObject * self
Definition: bpy_driver.c:165
inherits from class Rep
Definition: AppCanvas.cpp:18
static struct PyModuleDef module
Definition: python.cpp:972