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