Blender  V2.93
BPy_UnaryFunction0DMaterial.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(&UnaryFunction0DMaterial_Type) < 0) {
45  return -1;
46  }
47  Py_INCREF(&UnaryFunction0DMaterial_Type);
48  PyModule_AddObject(module, "UnaryFunction0DMaterial", (PyObject *)&UnaryFunction0DMaterial_Type);
49 
50  if (PyType_Ready(&MaterialF0D_Type) < 0) {
51  return -1;
52  }
53  Py_INCREF(&MaterialF0D_Type);
54  PyModule_AddObject(module, "MaterialF0D", (PyObject *)&MaterialF0D_Type);
55 
56  return 0;
57 }
58 
59 //------------------------INSTANCE METHODS ----------------------------------
60 
62  "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DMaterial`\n"
63  "\n"
64  "Base class for unary functions (functors) that work on\n"
65  ":class:`Interface0DIterator` and return a :class:`Material` object.\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_material = new UnaryFunction0D<FrsMaterial>();
81  self->uf0D_material->py_uf0D = (PyObject *)self;
82  return 0;
83 }
84 
86 {
87  delete self->uf0D_material;
88  UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
89 }
90 
92 {
93  return PyUnicode_FromFormat(
94  "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_material);
95 }
96 
98  PyObject *args,
99  PyObject *kwds)
100 {
101  static const char *kwlist[] = {"it", nullptr};
102  PyObject *obj;
103 
104  if (!PyArg_ParseTupleAndKeywords(
105  args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
106  return nullptr;
107  }
108 
109  if (typeid(*(self->uf0D_material)) == typeid(UnaryFunction0D<FrsMaterial>)) {
110  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
111  return nullptr;
112  }
113  if (self->uf0D_material->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
114  if (!PyErr_Occurred()) {
115  string class_name(Py_TYPE(self)->tp_name);
116  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
117  }
118  return nullptr;
119  }
120  return BPy_FrsMaterial_from_FrsMaterial(self->uf0D_material->result);
121 }
122 
123 /*-----------------------BPy_UnaryFunction0DMaterial type definition ----------------------------*/
124 
126  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction0DMaterial", /* tp_name */
127  sizeof(BPy_UnaryFunction0DMaterial), /* tp_basicsize */
128  0, /* tp_itemsize */
129  (destructor)UnaryFunction0DMaterial___dealloc__, /* tp_dealloc */
130  0, /* tp_vectorcall_offset */
131  nullptr, /* tp_getattr */
132  nullptr, /* tp_setattr */
133  nullptr, /* tp_reserved */
134  (reprfunc)UnaryFunction0DMaterial___repr__, /* tp_repr */
135  nullptr, /* tp_as_number */
136  nullptr, /* tp_as_sequence */
137  nullptr, /* tp_as_mapping */
138  nullptr, /* tp_hash */
139  (ternaryfunc)UnaryFunction0DMaterial___call__, /* tp_call */
140  nullptr, /* tp_str */
141  nullptr, /* tp_getattro */
142  nullptr, /* tp_setattro */
143  nullptr, /* tp_as_buffer */
144  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
145  UnaryFunction0DMaterial___doc__, /* tp_doc */
146  nullptr, /* tp_traverse */
147  nullptr, /* tp_clear */
148  nullptr, /* tp_richcompare */
149  0, /* tp_weaklistoffset */
150  nullptr, /* tp_iter */
151  nullptr, /* tp_iternext */
152  nullptr, /* tp_methods */
153  nullptr, /* tp_members */
154  nullptr, /* tp_getset */
155  &UnaryFunction0D_Type, /* tp_base */
156  nullptr, /* tp_dict */
157  nullptr, /* tp_descr_get */
158  nullptr, /* tp_descr_set */
159  0, /* tp_dictoffset */
160  (initproc)UnaryFunction0DMaterial___init__, /* tp_init */
161  nullptr, /* tp_alloc */
162  nullptr, /* tp_new */
163 };
164 
166 
167 #ifdef __cplusplus
168 }
169 #endif
PyObject * BPy_FrsMaterial_from_FrsMaterial(const FrsMaterial &m)
PyTypeObject Interface0DIterator_Type
PyTypeObject MaterialF0D_Type
PyTypeObject UnaryFunction0DMaterial_Type
static char UnaryFunction0DMaterial___doc__[]
static int UnaryFunction0DMaterial___init__(BPy_UnaryFunction0DMaterial *self, PyObject *args, PyObject *kwds)
static PyObject * UnaryFunction0DMaterial___call__(BPy_UnaryFunction0DMaterial *self, PyObject *args, PyObject *kwds)
static PyObject * UnaryFunction0DMaterial___repr__(BPy_UnaryFunction0DMaterial *self)
static void UnaryFunction0DMaterial___dealloc__(BPy_UnaryFunction0DMaterial *self)
int UnaryFunction0DMaterial_Init(PyObject *module)
PyTypeObject UnaryFunction0D_Type
static struct PyModuleDef module
PyObject * self
Definition: bpy_driver.c:185
inherits from class Rep
Definition: AppCanvas.cpp:32