Blender  V2.93
Director.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 
21 #include "Director.h"
22 
23 #include "BPy_Convert.h"
24 
25 #include "BPy_BinaryPredicate0D.h"
26 #include "BPy_BinaryPredicate1D.h"
27 #include "BPy_FrsMaterial.h"
28 #include "BPy_Id.h"
29 #include "BPy_StrokeShader.h"
30 #include "BPy_UnaryFunction0D.h"
31 #include "BPy_UnaryFunction1D.h"
32 #include "BPy_UnaryPredicate0D.h"
33 #include "BPy_UnaryPredicate1D.h"
34 #include "BPy_ViewShape.h"
35 #include "Interface1D/BPy_Stroke.h"
39 
50 
58 
59 using namespace Freestyle;
60 
61 // BinaryPredicate0D: __call__
63  Interface0D &i1,
64  Interface0D &i2)
65 {
66  if (!bp0D->py_bp0D) { // internal error
67  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_bp0D) not initialized");
68  return -1;
69  }
70  PyObject *arg1 = Any_BPy_Interface0D_from_Interface0D(i1);
71  PyObject *arg2 = Any_BPy_Interface0D_from_Interface0D(i2);
72  if (!arg1 || !arg2) {
73  Py_XDECREF(arg1);
74  Py_XDECREF(arg2);
75  return -1;
76  }
77  PyObject *result = PyObject_CallMethod((PyObject *)bp0D->py_bp0D, "__call__", "OO", arg1, arg2);
78  Py_DECREF(arg1);
79  Py_DECREF(arg2);
80  if (!result) {
81  return -1;
82  }
83  int ret = PyObject_IsTrue(result);
84  Py_DECREF(result);
85  if (ret < 0) {
86  return -1;
87  }
88  bp0D->result = ret;
89  return 0;
90 }
91 
92 // BinaryPredicate1D: __call__
94  Interface1D &i1,
95  Interface1D &i2)
96 {
97  if (!bp1D->py_bp1D) { // internal error
98  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_bp1D) not initialized");
99  return -1;
100  }
101  PyObject *arg1 = Any_BPy_Interface1D_from_Interface1D(i1);
102  PyObject *arg2 = Any_BPy_Interface1D_from_Interface1D(i2);
103  if (!arg1 || !arg2) {
104  Py_XDECREF(arg1);
105  Py_XDECREF(arg2);
106  return -1;
107  }
108  PyObject *result = PyObject_CallMethod((PyObject *)bp1D->py_bp1D, "__call__", "OO", arg1, arg2);
109  Py_DECREF(arg1);
110  Py_DECREF(arg2);
111  if (!result) {
112  return -1;
113  }
114  int ret = PyObject_IsTrue(result);
115  Py_DECREF(result);
116  if (ret < 0) {
117  return -1;
118  }
119  bp1D->result = ret;
120  return 0;
121 }
122 
123 // UnaryPredicate0D: __call__
125 {
126  if (!up0D->py_up0D) { // internal error
127  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_up0D) not initialized");
128  return -1;
129  }
130  PyObject *arg = BPy_Interface0DIterator_from_Interface0DIterator(if0D_it, false);
131  if (!arg) {
132  return -1;
133  }
134  PyObject *result = PyObject_CallMethod((PyObject *)up0D->py_up0D, "__call__", "O", arg);
135  Py_DECREF(arg);
136  if (!result) {
137  return -1;
138  }
139  int ret = PyObject_IsTrue(result);
140  Py_DECREF(result);
141  if (ret < 0) {
142  return -1;
143  }
144  up0D->result = ret;
145  return 0;
146 }
147 
148 // UnaryPredicate1D: __call__
150 {
151  if (!up1D->py_up1D) { // internal error
152  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_up1D) not initialized");
153  return -1;
154  }
155  PyObject *arg = Any_BPy_Interface1D_from_Interface1D(if1D);
156  if (!arg) {
157  return -1;
158  }
159  PyObject *result = PyObject_CallMethod((PyObject *)up1D->py_up1D, "__call__", "O", arg);
160  Py_DECREF(arg);
161  if (!result) {
162  return -1;
163  }
164  int ret = PyObject_IsTrue(result);
165  Py_DECREF(result);
166  if (ret < 0) {
167  return -1;
168  }
169  up1D->result = ret;
170  return 0;
171 }
172 
173 // StrokeShader: shade
175 {
176  if (!ss->py_ss) { // internal error
177  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_ss) not initialized");
178  return -1;
179  }
180  PyObject *arg = BPy_Stroke_from_Stroke(s);
181  if (!arg) {
182  return -1;
183  }
184  PyObject *result = PyObject_CallMethod((PyObject *)ss->py_ss, "shade", "O", arg);
185  Py_DECREF(arg);
186  if (!result) {
187  return -1;
188  }
189  Py_DECREF(result);
190  return 0;
191 }
192 
193 // ChainingIterator: init, traverse
195 {
196  if (!c_it->py_c_it) { // internal error
197  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_c_it) not initialized");
198  return -1;
199  }
200  PyObject *result = PyObject_CallMethod((PyObject *)c_it->py_c_it, "init", nullptr);
201  if (!result) {
202  return -1;
203  }
204  Py_DECREF(result);
205  return 0;
206 }
207 
209 {
210  if (!c_it->py_c_it) { // internal error
211  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_c_it) not initialized");
212  return -1;
213  }
214  PyObject *arg = BPy_AdjacencyIterator_from_AdjacencyIterator(a_it);
215  if (!arg) {
216  return -1;
217  }
218  PyObject *result = PyObject_CallMethod((PyObject *)c_it->py_c_it, "traverse", "O", arg);
219  Py_DECREF(arg);
220  if (!result) {
221  return -1;
222  }
223  if (BPy_ViewEdge_Check(result)) {
224  c_it->result = ((BPy_ViewEdge *)result)->ve;
225  }
226  else if (result == Py_None) {
227  c_it->result = nullptr;
228  }
229  else {
230  PyErr_SetString(PyExc_RuntimeError, "traverse method returned a wrong value");
231  Py_DECREF(result);
232  return -1;
233  }
234  Py_DECREF(result);
235  return 0;
236 }
237 
238 // BPy_UnaryFunction{0D,1D}: __call__
239 int Director_BPy_UnaryFunction0D___call__(void *uf0D, void *py_uf0D, Interface0DIterator &if0D_it)
240 {
241  if (!py_uf0D) { // internal error
242  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_uf0D) not initialized");
243  return -1;
244  }
245  PyObject *obj = (PyObject *)py_uf0D;
246  PyObject *arg = BPy_Interface0DIterator_from_Interface0DIterator(if0D_it, false);
247  if (!arg) {
248  return -1;
249  }
250  PyObject *result = PyObject_CallMethod(obj, "__call__", "O", arg);
251  Py_DECREF(arg);
252  if (!result) {
253  return -1;
254  }
256  ((UnaryFunction0D<double> *)uf0D)->result = PyFloat_AsDouble(result);
257  }
258  else if (BPy_UnaryFunction0DEdgeNature_Check(obj)) {
260  }
261  else if (BPy_UnaryFunction0DFloat_Check(obj)) {
262  ((UnaryFunction0D<float> *)uf0D)->result = PyFloat_AsDouble(result);
263  }
264  else if (BPy_UnaryFunction0DId_Check(obj)) {
265  ((UnaryFunction0D<Id> *)uf0D)->result = *(((BPy_Id *)result)->id);
266  }
267  else if (BPy_UnaryFunction0DMaterial_Check(obj)) {
268  ((UnaryFunction0D<FrsMaterial> *)uf0D)->result = *(((BPy_FrsMaterial *)result)->m);
269  }
270  else if (BPy_UnaryFunction0DUnsigned_Check(obj)) {
271  ((UnaryFunction0D<unsigned> *)uf0D)->result = PyLong_AsLong(result);
272  }
273  else if (BPy_UnaryFunction0DVec2f_Check(obj)) {
274  Vec2f vec;
275  if (!Vec2f_ptr_from_Vector(result, vec)) {
276  return -1;
277  }
278  ((UnaryFunction0D<Vec2f> *)uf0D)->result = vec;
279  }
280  else if (BPy_UnaryFunction0DVec3f_Check(obj)) {
281  Vec3f vec;
282  if (!Vec3f_ptr_from_Vector(result, vec)) {
283  return -1;
284  }
285  ((UnaryFunction0D<Vec3f> *)uf0D)->result = vec;
286  }
288  vector<ViewShape *> vec;
289  vec.reserve(PyList_Size(result));
290  for (int i = 0; i < PyList_Size(result); i++) {
291  ViewShape *b = ((BPy_ViewShape *)PyList_GET_ITEM(result, i))->vs;
292  vec.push_back(b);
293  }
294  ((UnaryFunction0D<vector<ViewShape *>> *)uf0D)->result = vec;
295  }
296  else if (BPy_UnaryFunction0DViewShape_Check(obj)) {
297  ((UnaryFunction0D<ViewShape *> *)uf0D)->result = ((BPy_ViewShape *)result)->vs;
298  }
299  Py_DECREF(result);
300  return 0;
301 }
302 
303 int Director_BPy_UnaryFunction1D___call__(void *uf1D, void *py_uf1D, Interface1D &if1D)
304 {
305  if (!py_uf1D) { // internal error
306  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_uf1D) not initialized");
307  return -1;
308  }
309  PyObject *obj = (PyObject *)py_uf1D;
310  PyObject *arg = Any_BPy_Interface1D_from_Interface1D(if1D);
311  if (!arg) {
312  return -1;
313  }
314  PyObject *result = PyObject_CallMethod(obj, "__call__", "O", arg);
315  Py_DECREF(arg);
316  if (!result) {
317  return -1;
318  }
320  ((UnaryFunction1D<double> *)uf1D)->result = PyFloat_AsDouble(result);
321  }
322  else if (BPy_UnaryFunction1DEdgeNature_Check(obj)) {
324  }
325  else if (BPy_UnaryFunction1DFloat_Check(obj)) {
326  ((UnaryFunction1D<float> *)uf1D)->result = PyFloat_AsDouble(result);
327  }
328  else if (BPy_UnaryFunction1DUnsigned_Check(obj)) {
329  ((UnaryFunction1D<unsigned> *)uf1D)->result = PyLong_AsLong(result);
330  }
331  else if (BPy_UnaryFunction1DVec2f_Check(obj)) {
332  Vec2f vec;
333  if (!Vec2f_ptr_from_Vector(result, vec)) {
334  return -1;
335  }
336  ((UnaryFunction1D<Vec2f> *)uf1D)->result = vec;
337  }
338  else if (BPy_UnaryFunction1DVec3f_Check(obj)) {
339  Vec3f vec;
340  if (!Vec3f_ptr_from_Vector(result, vec)) {
341  return -1;
342  }
343  ((UnaryFunction1D<Vec3f> *)uf1D)->result = vec;
344  }
346  vector<ViewShape *> vec;
347  vec.reserve(PyList_Size(result));
348  for (int i = 1; i < PyList_Size(result); i++) {
349  ViewShape *b = ((BPy_ViewShape *)PyList_GET_ITEM(result, i))->vs;
350  vec.push_back(b);
351  }
352  ((UnaryFunction1D<vector<ViewShape *>> *)uf1D)->result = vec;
353  }
354  Py_DECREF(result);
355  return 0;
356 }
bool Vec2f_ptr_from_Vector(PyObject *obj, Vec2f &vec)
PyObject * BPy_Interface0DIterator_from_Interface0DIterator(Interface0DIterator &if0D_it, bool reversed)
PyObject * BPy_Stroke_from_Stroke(Stroke &s)
PyObject * Any_BPy_Interface1D_from_Interface1D(Interface1D &if1D)
Nature::EdgeNature EdgeNature_from_BPy_Nature(PyObject *obj)
PyObject * Any_BPy_Interface0D_from_Interface0D(Interface0D &if0D)
PyObject * BPy_AdjacencyIterator_from_AdjacencyIterator(AdjacencyIterator &a_it)
bool Vec3f_ptr_from_Vector(PyObject *obj, Vec3f &vec)
#define BPy_UnaryFunction0DDouble_Check(v)
#define BPy_UnaryFunction0DEdgeNature_Check(v)
#define BPy_UnaryFunction0DFloat_Check(v)
#define BPy_UnaryFunction0DId_Check(v)
#define BPy_UnaryFunction0DMaterial_Check(v)
#define BPy_UnaryFunction0DUnsigned_Check(v)
#define BPy_UnaryFunction0DVec2f_Check(v)
#define BPy_UnaryFunction0DVec3f_Check(v)
#define BPy_UnaryFunction0DVectorViewShape_Check(v)
#define BPy_UnaryFunction0DViewShape_Check(v)
#define BPy_UnaryFunction1DDouble_Check(v)
#define BPy_UnaryFunction1DEdgeNature_Check(v)
#define BPy_UnaryFunction1DFloat_Check(v)
#define BPy_UnaryFunction1DUnsigned_Check(v)
#define BPy_UnaryFunction1DVec2f_Check(v)
#define BPy_UnaryFunction1DVec3f_Check(v)
#define BPy_UnaryFunction1DVectorViewShape_Check(v)
#define BPy_ViewEdge_Check(v)
Definition: BPy_ViewEdge.h:35
int Director_BPy_BinaryPredicate0D___call__(BinaryPredicate0D *bp0D, Interface0D &i1, Interface0D &i2)
Definition: Director.cpp:62
int Director_BPy_UnaryFunction0D___call__(void *uf0D, void *py_uf0D, Interface0DIterator &if0D_it)
Definition: Director.cpp:239
int Director_BPy_UnaryFunction1D___call__(void *uf1D, void *py_uf1D, Interface1D &if1D)
Definition: Director.cpp:303
int Director_BPy_UnaryPredicate0D___call__(UnaryPredicate0D *up0D, Interface0DIterator &if0D_it)
Definition: Director.cpp:124
int Director_BPy_ChainingIterator_init(ChainingIterator *c_it)
Definition: Director.cpp:194
int Director_BPy_StrokeShader_shade(StrokeShader *ss, Stroke &s)
Definition: Director.cpp:174
int Director_BPy_ChainingIterator_traverse(ChainingIterator *c_it, AdjacencyIterator &a_it)
Definition: Director.cpp:208
int Director_BPy_BinaryPredicate1D___call__(BinaryPredicate1D *bp1D, Interface1D &i1, Interface1D &i2)
Definition: Director.cpp:93
int Director_BPy_UnaryPredicate1D___call__(UnaryPredicate1D *up1D, Interface1D &if1D)
Definition: Director.cpp:149
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint i1
inherits from class Rep
Definition: AppCanvas.cpp:32
return ret
Definition: BPy_Id.h:42