Fix T77206: G + MMB Doesn't work in Graph Editor if the transform orientation is...
[blender.git] / source / blender / freestyle / intern / python / UnaryFunction0D / BPy_UnaryFunction0DMaterial.cpp
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
17 /** \file
18  * \ingroup freestyle
19  */
20
21 #include "BPy_UnaryFunction0DMaterial.h"
22
23 #include "../BPy_Convert.h"
24 #include "../Iterator/BPy_Interface0DIterator.h"
25
26 #include "UnaryFunction0D_Material/BPy_MaterialF0D.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 ///////////////////////////////////////////////////////////////////////////////////////////
33
34 //-------------------MODULE INITIALIZATION--------------------------------
35
36 int UnaryFunction0DMaterial_Init(PyObject *module)
37 {
38   if (module == NULL) {
39     return -1;
40   }
41
42   if (PyType_Ready(&UnaryFunction0DMaterial_Type) < 0) {
43     return -1;
44   }
45   Py_INCREF(&UnaryFunction0DMaterial_Type);
46   PyModule_AddObject(module, "UnaryFunction0DMaterial", (PyObject *)&UnaryFunction0DMaterial_Type);
47
48   if (PyType_Ready(&MaterialF0D_Type) < 0) {
49     return -1;
50   }
51   Py_INCREF(&MaterialF0D_Type);
52   PyModule_AddObject(module, "MaterialF0D", (PyObject *)&MaterialF0D_Type);
53
54   return 0;
55 }
56
57 //------------------------INSTANCE METHODS ----------------------------------
58
59 static char UnaryFunction0DMaterial___doc__[] =
60     "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DMaterial`\n"
61     "\n"
62     "Base class for unary functions (functors) that work on\n"
63     ":class:`Interface0DIterator` and return a :class:`Material` object.\n"
64     "\n"
65     ".. method:: __init__()\n"
66     "\n"
67     "   Default constructor.\n";
68
69 static int UnaryFunction0DMaterial___init__(BPy_UnaryFunction0DMaterial *self,
70                                             PyObject *args,
71                                             PyObject *kwds)
72 {
73   static const char *kwlist[] = {NULL};
74
75   if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
76     return -1;
77   }
78   self->uf0D_material = new UnaryFunction0D<FrsMaterial>();
79   self->uf0D_material->py_uf0D = (PyObject *)self;
80   return 0;
81 }
82
83 static void UnaryFunction0DMaterial___dealloc__(BPy_UnaryFunction0DMaterial *self)
84 {
85   if (self->uf0D_material) {
86     delete self->uf0D_material;
87   }
88   UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
89 }
90
91 static PyObject *UnaryFunction0DMaterial___repr__(BPy_UnaryFunction0DMaterial *self)
92 {
93   return PyUnicode_FromFormat(
94       "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_material);
95 }
96
97 static PyObject *UnaryFunction0DMaterial___call__(BPy_UnaryFunction0DMaterial *self,
98                                                   PyObject *args,
99                                                   PyObject *kwds)
100 {
101   static const char *kwlist[] = {"it", NULL};
102   PyObject *obj;
103
104   if (!PyArg_ParseTupleAndKeywords(
105           args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
106     return NULL;
107   }
108
109   if (typeid(*(self->uf0D_material)) == typeid(UnaryFunction0D<FrsMaterial>)) {
110     PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
111     return NULL;
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 NULL;
119   }
120   return BPy_FrsMaterial_from_FrsMaterial(self->uf0D_material->result);
121 }
122
123 /*-----------------------BPy_UnaryFunction0DMaterial type definition ----------------------------*/
124
125 PyTypeObject UnaryFunction0DMaterial_Type = {
126     PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DMaterial", /* tp_name */
127     sizeof(BPy_UnaryFunction0DMaterial),                      /* tp_basicsize */
128     0,                                                        /* tp_itemsize */
129     (destructor)UnaryFunction0DMaterial___dealloc__,          /* tp_dealloc */
130     0,                                                        /* tp_print */
131     0,                                                        /* tp_getattr */
132     0,                                                        /* tp_setattr */
133     0,                                                        /* tp_reserved */
134     (reprfunc)UnaryFunction0DMaterial___repr__,               /* tp_repr */
135     0,                                                        /* tp_as_number */
136     0,                                                        /* tp_as_sequence */
137     0,                                                        /* tp_as_mapping */
138     0,                                                        /* tp_hash  */
139     (ternaryfunc)UnaryFunction0DMaterial___call__,            /* tp_call */
140     0,                                                        /* tp_str */
141     0,                                                        /* tp_getattro */
142     0,                                                        /* tp_setattro */
143     0,                                                        /* tp_as_buffer */
144     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,                 /* tp_flags */
145     UnaryFunction0DMaterial___doc__,                          /* tp_doc */
146     0,                                                        /* tp_traverse */
147     0,                                                        /* tp_clear */
148     0,                                                        /* tp_richcompare */
149     0,                                                        /* tp_weaklistoffset */
150     0,                                                        /* tp_iter */
151     0,                                                        /* tp_iternext */
152     0,                                                        /* tp_methods */
153     0,                                                        /* tp_members */
154     0,                                                        /* tp_getset */
155     &UnaryFunction0D_Type,                                    /* tp_base */
156     0,                                                        /* tp_dict */
157     0,                                                        /* tp_descr_get */
158     0,                                                        /* tp_descr_set */
159     0,                                                        /* tp_dictoffset */
160     (initproc)UnaryFunction0DMaterial___init__,               /* tp_init */
161     0,                                                        /* tp_alloc */
162     0,                                                        /* tp_new */
163 };
164
165 ///////////////////////////////////////////////////////////////////////////////////////////
166
167 #ifdef __cplusplus
168 }
169 #endif