Blender  V3.3
Director.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "Director.h"
8 
9 #include "BPy_Convert.h"
10 
11 #include "BPy_BinaryPredicate0D.h"
12 #include "BPy_BinaryPredicate1D.h"
13 #include "BPy_FrsMaterial.h"
14 #include "BPy_Id.h"
15 #include "BPy_StrokeShader.h"
16 #include "BPy_UnaryFunction0D.h"
17 #include "BPy_UnaryFunction1D.h"
18 #include "BPy_UnaryPredicate0D.h"
19 #include "BPy_UnaryPredicate1D.h"
20 #include "BPy_ViewShape.h"
21 #include "Interface1D/BPy_Stroke.h"
25 
36 
44 
45 using namespace Freestyle;
46 
47 // BinaryPredicate0D: __call__
49  Interface0D &i1,
50  Interface0D &i2)
51 {
52  if (!bp0D->py_bp0D) { // internal error
53  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_bp0D) not initialized");
54  return -1;
55  }
56  PyObject *arg1 = Any_BPy_Interface0D_from_Interface0D(i1);
57  PyObject *arg2 = Any_BPy_Interface0D_from_Interface0D(i2);
58  if (!arg1 || !arg2) {
59  Py_XDECREF(arg1);
60  Py_XDECREF(arg2);
61  return -1;
62  }
63  PyObject *result = PyObject_CallMethod((PyObject *)bp0D->py_bp0D, "__call__", "OO", arg1, arg2);
64  Py_DECREF(arg1);
65  Py_DECREF(arg2);
66  if (!result) {
67  return -1;
68  }
69  int ret = PyObject_IsTrue(result);
70  Py_DECREF(result);
71  if (ret < 0) {
72  return -1;
73  }
74  bp0D->result = ret;
75  return 0;
76 }
77 
78 // BinaryPredicate1D: __call__
80  Interface1D &i1,
81  Interface1D &i2)
82 {
83  if (!bp1D->py_bp1D) { // internal error
84  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_bp1D) not initialized");
85  return -1;
86  }
87  PyObject *arg1 = Any_BPy_Interface1D_from_Interface1D(i1);
88  PyObject *arg2 = Any_BPy_Interface1D_from_Interface1D(i2);
89  if (!arg1 || !arg2) {
90  Py_XDECREF(arg1);
91  Py_XDECREF(arg2);
92  return -1;
93  }
94  PyObject *result = PyObject_CallMethod((PyObject *)bp1D->py_bp1D, "__call__", "OO", arg1, arg2);
95  Py_DECREF(arg1);
96  Py_DECREF(arg2);
97  if (!result) {
98  return -1;
99  }
100  int ret = PyObject_IsTrue(result);
101  Py_DECREF(result);
102  if (ret < 0) {
103  return -1;
104  }
105  bp1D->result = ret;
106  return 0;
107 }
108 
109 // UnaryPredicate0D: __call__
111 {
112  if (!up0D->py_up0D) { // internal error
113  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_up0D) not initialized");
114  return -1;
115  }
116  PyObject *arg = BPy_Interface0DIterator_from_Interface0DIterator(if0D_it, false);
117  if (!arg) {
118  return -1;
119  }
120  PyObject *result = PyObject_CallMethod((PyObject *)up0D->py_up0D, "__call__", "O", arg);
121  Py_DECREF(arg);
122  if (!result) {
123  return -1;
124  }
125  int ret = PyObject_IsTrue(result);
126  Py_DECREF(result);
127  if (ret < 0) {
128  return -1;
129  }
130  up0D->result = ret;
131  return 0;
132 }
133 
134 // UnaryPredicate1D: __call__
136 {
137  if (!up1D->py_up1D) { // internal error
138  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_up1D) not initialized");
139  return -1;
140  }
141  PyObject *arg = Any_BPy_Interface1D_from_Interface1D(if1D);
142  if (!arg) {
143  return -1;
144  }
145  PyObject *result = PyObject_CallMethod((PyObject *)up1D->py_up1D, "__call__", "O", arg);
146  Py_DECREF(arg);
147  if (!result) {
148  return -1;
149  }
150  int ret = PyObject_IsTrue(result);
151  Py_DECREF(result);
152  if (ret < 0) {
153  return -1;
154  }
155  up1D->result = ret;
156  return 0;
157 }
158 
159 // StrokeShader: shade
161 {
162  if (!ss->py_ss) { // internal error
163  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_ss) not initialized");
164  return -1;
165  }
166  PyObject *arg = BPy_Stroke_from_Stroke(s);
167  if (!arg) {
168  return -1;
169  }
170  PyObject *result = PyObject_CallMethod((PyObject *)ss->py_ss, "shade", "O", arg);
171  Py_DECREF(arg);
172  if (!result) {
173  return -1;
174  }
175  Py_DECREF(result);
176  return 0;
177 }
178 
179 // ChainingIterator: init, traverse
181 {
182  if (!c_it->py_c_it) { // internal error
183  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_c_it) not initialized");
184  return -1;
185  }
186  PyObject *result = PyObject_CallMethod((PyObject *)c_it->py_c_it, "init", nullptr);
187  if (!result) {
188  return -1;
189  }
190  Py_DECREF(result);
191  return 0;
192 }
193 
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 *arg = BPy_AdjacencyIterator_from_AdjacencyIterator(a_it);
201  if (!arg) {
202  return -1;
203  }
204  PyObject *result = PyObject_CallMethod((PyObject *)c_it->py_c_it, "traverse", "O", arg);
205  Py_DECREF(arg);
206  if (!result) {
207  return -1;
208  }
209  if (BPy_ViewEdge_Check(result)) {
210  c_it->result = ((BPy_ViewEdge *)result)->ve;
211  }
212  else if (result == Py_None) {
213  c_it->result = nullptr;
214  }
215  else {
216  PyErr_SetString(PyExc_RuntimeError, "traverse method returned a wrong value");
217  Py_DECREF(result);
218  return -1;
219  }
220  Py_DECREF(result);
221  return 0;
222 }
223 
224 // BPy_UnaryFunction{0D,1D}: __call__
225 int Director_BPy_UnaryFunction0D___call__(void *uf0D, void *py_uf0D, Interface0DIterator &if0D_it)
226 {
227  if (!py_uf0D) { // internal error
228  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_uf0D) not initialized");
229  return -1;
230  }
231  PyObject *obj = (PyObject *)py_uf0D;
232  PyObject *arg = BPy_Interface0DIterator_from_Interface0DIterator(if0D_it, false);
233  if (!arg) {
234  return -1;
235  }
236  PyObject *result = PyObject_CallMethod(obj, "__call__", "O", arg);
237  Py_DECREF(arg);
238  if (!result) {
239  return -1;
240  }
242  ((UnaryFunction0D<double> *)uf0D)->result = PyFloat_AsDouble(result);
243  }
244  else if (BPy_UnaryFunction0DEdgeNature_Check(obj)) {
246  }
247  else if (BPy_UnaryFunction0DFloat_Check(obj)) {
248  ((UnaryFunction0D<float> *)uf0D)->result = PyFloat_AsDouble(result);
249  }
250  else if (BPy_UnaryFunction0DId_Check(obj)) {
251  ((UnaryFunction0D<Id> *)uf0D)->result = *(((BPy_Id *)result)->id);
252  }
253  else if (BPy_UnaryFunction0DMaterial_Check(obj)) {
254  ((UnaryFunction0D<FrsMaterial> *)uf0D)->result = *(((BPy_FrsMaterial *)result)->m);
255  }
256  else if (BPy_UnaryFunction0DUnsigned_Check(obj)) {
257  ((UnaryFunction0D<unsigned> *)uf0D)->result = PyLong_AsLong(result);
258  }
259  else if (BPy_UnaryFunction0DVec2f_Check(obj)) {
260  Vec2f vec;
261  if (!Vec2f_ptr_from_Vector(result, vec)) {
262  return -1;
263  }
264  ((UnaryFunction0D<Vec2f> *)uf0D)->result = vec;
265  }
266  else if (BPy_UnaryFunction0DVec3f_Check(obj)) {
267  Vec3f vec;
268  if (!Vec3f_ptr_from_Vector(result, vec)) {
269  return -1;
270  }
271  ((UnaryFunction0D<Vec3f> *)uf0D)->result = vec;
272  }
274  vector<ViewShape *> vec;
275  vec.reserve(PyList_Size(result));
276  for (int i = 0; i < PyList_Size(result); i++) {
277  ViewShape *b = ((BPy_ViewShape *)PyList_GET_ITEM(result, i))->vs;
278  vec.push_back(b);
279  }
280  ((UnaryFunction0D<vector<ViewShape *>> *)uf0D)->result = vec;
281  }
282  else if (BPy_UnaryFunction0DViewShape_Check(obj)) {
283  ((UnaryFunction0D<ViewShape *> *)uf0D)->result = ((BPy_ViewShape *)result)->vs;
284  }
285  Py_DECREF(result);
286  return 0;
287 }
288 
289 int Director_BPy_UnaryFunction1D___call__(void *uf1D, void *py_uf1D, Interface1D &if1D)
290 {
291  if (!py_uf1D) { // internal error
292  PyErr_SetString(PyExc_RuntimeError, "Reference to Python object (py_uf1D) not initialized");
293  return -1;
294  }
295  PyObject *obj = (PyObject *)py_uf1D;
296  PyObject *arg = Any_BPy_Interface1D_from_Interface1D(if1D);
297  if (!arg) {
298  return -1;
299  }
300  PyObject *result = PyObject_CallMethod(obj, "__call__", "O", arg);
301  Py_DECREF(arg);
302  if (!result) {
303  return -1;
304  }
306  ((UnaryFunction1D<double> *)uf1D)->result = PyFloat_AsDouble(result);
307  }
308  else if (BPy_UnaryFunction1DEdgeNature_Check(obj)) {
310  }
311  else if (BPy_UnaryFunction1DFloat_Check(obj)) {
312  ((UnaryFunction1D<float> *)uf1D)->result = PyFloat_AsDouble(result);
313  }
314  else if (BPy_UnaryFunction1DUnsigned_Check(obj)) {
315  ((UnaryFunction1D<unsigned> *)uf1D)->result = PyLong_AsLong(result);
316  }
317  else if (BPy_UnaryFunction1DVec2f_Check(obj)) {
318  Vec2f vec;
319  if (!Vec2f_ptr_from_Vector(result, vec)) {
320  return -1;
321  }
322  ((UnaryFunction1D<Vec2f> *)uf1D)->result = vec;
323  }
324  else if (BPy_UnaryFunction1DVec3f_Check(obj)) {
325  Vec3f vec;
326  if (!Vec3f_ptr_from_Vector(result, vec)) {
327  return -1;
328  }
329  ((UnaryFunction1D<Vec3f> *)uf1D)->result = vec;
330  }
332  vector<ViewShape *> vec;
333  vec.reserve(PyList_Size(result));
334  for (int i = 1; i < PyList_Size(result); i++) {
335  ViewShape *b = ((BPy_ViewShape *)PyList_GET_ITEM(result, i))->vs;
336  vec.push_back(b);
337  }
338  ((UnaryFunction1D<vector<ViewShape *>> *)uf1D)->result = vec;
339  }
340  Py_DECREF(result);
341  return 0;
342 }
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)
Definition: BPy_Convert.cpp:97
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:21
int Director_BPy_BinaryPredicate0D___call__(BinaryPredicate0D *bp0D, Interface0D &i1, Interface0D &i2)
Definition: Director.cpp:48
int Director_BPy_UnaryFunction0D___call__(void *uf0D, void *py_uf0D, Interface0DIterator &if0D_it)
Definition: Director.cpp:225
int Director_BPy_UnaryFunction1D___call__(void *uf1D, void *py_uf1D, Interface1D &if1D)
Definition: Director.cpp:289
int Director_BPy_UnaryPredicate0D___call__(UnaryPredicate0D *up0D, Interface0DIterator &if0D_it)
Definition: Director.cpp:110
int Director_BPy_ChainingIterator_init(ChainingIterator *c_it)
Definition: Director.cpp:180
int Director_BPy_StrokeShader_shade(StrokeShader *ss, Stroke &s)
Definition: Director.cpp:160
int Director_BPy_ChainingIterator_traverse(ChainingIterator *c_it, AdjacencyIterator &a_it)
Definition: Director.cpp:194
int Director_BPy_BinaryPredicate1D___call__(BinaryPredicate1D *bp1D, Interface1D &i1, Interface1D &i2)
Definition: Director.cpp:79
int Director_BPy_UnaryPredicate1D___call__(UnaryPredicate1D *up1D, Interface1D &if1D)
Definition: Director.cpp:135
_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:18
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
return ret
Definition: BPy_Id.h:28