UI: more informative light energy description based on light type
[blender.git] / source / blender / freestyle / intern / python / UnaryFunction0D / BPy_UnaryFunction0DEdgeNature.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_UnaryFunction0DEdgeNature.h"
22
23 #include "../BPy_Convert.h"
24 #include "../Iterator/BPy_Interface0DIterator.h"
25
26 #include "UnaryFunction0D_Nature_EdgeNature/BPy_CurveNatureF0D.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 ///////////////////////////////////////////////////////////////////////////////////////////
33
34 //-------------------MODULE INITIALIZATION--------------------------------
35
36 int UnaryFunction0DEdgeNature_Init(PyObject *module)
37 {
38   if (module == NULL) {
39     return -1;
40   }
41
42   if (PyType_Ready(&UnaryFunction0DEdgeNature_Type) < 0) {
43     return -1;
44   }
45   Py_INCREF(&UnaryFunction0DEdgeNature_Type);
46   PyModule_AddObject(
47       module, "UnaryFunction0DEdgeNature", (PyObject *)&UnaryFunction0DEdgeNature_Type);
48
49   if (PyType_Ready(&CurveNatureF0D_Type) < 0) {
50     return -1;
51   }
52   Py_INCREF(&CurveNatureF0D_Type);
53   PyModule_AddObject(module, "CurveNatureF0D", (PyObject *)&CurveNatureF0D_Type);
54
55   return 0;
56 }
57
58 //------------------------INSTANCE METHODS ----------------------------------
59
60 static char UnaryFunction0DEdgeNature___doc__[] =
61     "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DEdgeNature`\n"
62     "\n"
63     "Base class for unary functions (functors) that work on\n"
64     ":class:`Interface0DIterator` and return a :class:`Nature` object.\n"
65     "\n"
66     ".. method:: __init__()\n"
67     "\n"
68     "   Default constructor.\n";
69
70 static int UnaryFunction0DEdgeNature___init__(BPy_UnaryFunction0DEdgeNature *self,
71                                               PyObject *args,
72                                               PyObject *kwds)
73 {
74   static const char *kwlist[] = {NULL};
75
76   if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
77     return -1;
78   }
79   self->uf0D_edgenature = new UnaryFunction0D<Nature::EdgeNature>();
80   self->uf0D_edgenature->py_uf0D = (PyObject *)self;
81   return 0;
82 }
83
84 static void UnaryFunction0DEdgeNature___dealloc__(BPy_UnaryFunction0DEdgeNature *self)
85 {
86   if (self->uf0D_edgenature) {
87     delete self->uf0D_edgenature;
88   }
89   UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
90 }
91
92 static PyObject *UnaryFunction0DEdgeNature___repr__(BPy_UnaryFunction0DEdgeNature *self)
93 {
94   return PyUnicode_FromFormat(
95       "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_edgenature);
96 }
97
98 static PyObject *UnaryFunction0DEdgeNature___call__(BPy_UnaryFunction0DEdgeNature *self,
99                                                     PyObject *args,
100                                                     PyObject *kwds)
101 {
102   static const char *kwlist[] = {"it", NULL};
103   PyObject *obj;
104
105   if (!PyArg_ParseTupleAndKeywords(
106           args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
107     return NULL;
108   }
109
110   if (typeid(*(self->uf0D_edgenature)) == typeid(UnaryFunction0D<Nature::EdgeNature>)) {
111     PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
112     return NULL;
113   }
114   if (self->uf0D_edgenature->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
115     if (!PyErr_Occurred()) {
116       string class_name(Py_TYPE(self)->tp_name);
117       PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
118     }
119     return NULL;
120   }
121   return BPy_Nature_from_Nature(self->uf0D_edgenature->result);
122 }
123
124 /*-----------------------BPy_UnaryFunction0DEdgeNature type definition --------------------------*/
125
126 PyTypeObject UnaryFunction0DEdgeNature_Type = {
127     PyVarObject_HEAD_INIT(NULL, 0) "UnaryFunction0DEdgeNature", /* tp_name */
128     sizeof(BPy_UnaryFunction0DEdgeNature),                      /* tp_basicsize */
129     0,                                                          /* tp_itemsize */
130     (destructor)UnaryFunction0DEdgeNature___dealloc__,          /* tp_dealloc */
131     0,                                                          /* tp_print */
132     0,                                                          /* tp_getattr */
133     0,                                                          /* tp_setattr */
134     0,                                                          /* tp_reserved */
135     (reprfunc)UnaryFunction0DEdgeNature___repr__,               /* tp_repr */
136     0,                                                          /* tp_as_number */
137     0,                                                          /* tp_as_sequence */
138     0,                                                          /* tp_as_mapping */
139     0,                                                          /* tp_hash  */
140     (ternaryfunc)UnaryFunction0DEdgeNature___call__,            /* tp_call */
141     0,                                                          /* tp_str */
142     0,                                                          /* tp_getattro */
143     0,                                                          /* tp_setattro */
144     0,                                                          /* tp_as_buffer */
145     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,                   /* tp_flags */
146     UnaryFunction0DEdgeNature___doc__,                          /* tp_doc */
147     0,                                                          /* tp_traverse */
148     0,                                                          /* tp_clear */
149     0,                                                          /* tp_richcompare */
150     0,                                                          /* tp_weaklistoffset */
151     0,                                                          /* tp_iter */
152     0,                                                          /* tp_iternext */
153     0,                                                          /* tp_methods */
154     0,                                                          /* tp_members */
155     0,                                                          /* tp_getset */
156     &UnaryFunction0D_Type,                                      /* tp_base */
157     0,                                                          /* tp_dict */
158     0,                                                          /* tp_descr_get */
159     0,                                                          /* tp_descr_set */
160     0,                                                          /* tp_dictoffset */
161     (initproc)UnaryFunction0DEdgeNature___init__,               /* tp_init */
162     0,                                                          /* tp_alloc */
163     0,                                                          /* tp_new */
164 };
165
166 ///////////////////////////////////////////////////////////////////////////////////////////
167
168 #ifdef __cplusplus
169 }
170 #endif