Blender  V2.93
BPy_UnaryFunction0DVectorViewShape.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(&UnaryFunction0DVectorViewShape_Type) < 0) {
45  return -1;
46  }
48  PyModule_AddObject(
49  module, "UnaryFunction0DVectorViewShape", (PyObject *)&UnaryFunction0DVectorViewShape_Type);
50 
51  if (PyType_Ready(&GetOccludersF0D_Type) < 0) {
52  return -1;
53  }
54  Py_INCREF(&GetOccludersF0D_Type);
55  PyModule_AddObject(module, "GetOccludersF0D", (PyObject *)&GetOccludersF0D_Type);
56 
57  return 0;
58 }
59 
60 //------------------------INSTANCE METHODS ----------------------------------
61 
63  "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DVectorViewShape`\n"
64  "\n"
65  "Base class for unary functions (functors) that work on\n"
66  ":class:`Interface0DIterator` and return a list of :class:`ViewShape`\n"
67  "objects.\n"
68  "\n"
69  ".. method:: __init__()\n"
70  "\n"
71  " Default constructor.\n";
72 
74  PyObject *args,
75  PyObject *kwds)
76 {
77  static const char *kwlist[] = {nullptr};
78 
79  if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
80  return -1;
81  }
82  self->uf0D_vectorviewshape = new UnaryFunction0D<std::vector<ViewShape *>>();
83  self->uf0D_vectorviewshape->py_uf0D = (PyObject *)self;
84  return 0;
85 }
86 
88 {
89  delete self->uf0D_vectorviewshape;
90  UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
91 }
92 
94 {
95  return PyUnicode_FromFormat(
96  "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_vectorviewshape);
97 }
98 
100  PyObject *args,
101  PyObject *kwds)
102 {
103  static const char *kwlist[] = {"it", nullptr};
104  PyObject *obj;
105 
106  if (!PyArg_ParseTupleAndKeywords(
107  args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
108  return nullptr;
109  }
110 
111  if (typeid(*(self->uf0D_vectorviewshape)) == typeid(UnaryFunction0D<std::vector<ViewShape *>>)) {
112  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
113  return nullptr;
114  }
115  if (self->uf0D_vectorviewshape->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
116  if (!PyErr_Occurred()) {
117  string class_name(Py_TYPE(self)->tp_name);
118  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
119  }
120  return nullptr;
121  }
122 
123  const unsigned int list_len = self->uf0D_vectorviewshape->result.size();
124  PyObject *list = PyList_New(list_len);
125  for (unsigned int i = 0; i < list_len; i++) {
126  ViewShape *v = self->uf0D_vectorviewshape->result[i];
127  PyList_SET_ITEM(list, i, v ? BPy_ViewShape_from_ViewShape(*v) : (Py_INCREF(Py_None), Py_None));
128  }
129 
130  return list;
131 }
132 
133 /*-----------------------BPy_UnaryFunction0DVectorViewShape type definition ---------------------*/
134 
136  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction0DVectorViewShape", /* tp_name */
137  sizeof(BPy_UnaryFunction0DVectorViewShape), /* tp_basicsize */
138  0, /* tp_itemsize */
139  (destructor)UnaryFunction0DVectorViewShape___dealloc__, /* tp_dealloc */
140  0, /* tp_vectorcall_offset */
141  nullptr, /* tp_getattr */
142  nullptr, /* tp_setattr */
143  nullptr, /* tp_reserved */
144  (reprfunc)UnaryFunction0DVectorViewShape___repr__, /* tp_repr */
145  nullptr, /* tp_as_number */
146  nullptr, /* tp_as_sequence */
147  nullptr, /* tp_as_mapping */
148  nullptr, /* tp_hash */
149  (ternaryfunc)UnaryFunction0DVectorViewShape___call__, /* tp_call */
150  nullptr, /* tp_str */
151  nullptr, /* tp_getattro */
152  nullptr, /* tp_setattro */
153  nullptr, /* tp_as_buffer */
154  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
156  nullptr, /* tp_traverse */
157  nullptr, /* tp_clear */
158  nullptr, /* tp_richcompare */
159  0, /* tp_weaklistoffset */
160  nullptr, /* tp_iter */
161  nullptr, /* tp_iternext */
162  nullptr, /* tp_methods */
163  nullptr, /* tp_members */
164  nullptr, /* tp_getset */
165  &UnaryFunction0D_Type, /* tp_base */
166  nullptr, /* tp_dict */
167  nullptr, /* tp_descr_get */
168  nullptr, /* tp_descr_set */
169  0, /* tp_dictoffset */
170  (initproc)UnaryFunction0DVectorViewShape___init__, /* tp_init */
171  nullptr, /* tp_alloc */
172  nullptr, /* tp_new */
173 };
174 
176 
177 #ifdef __cplusplus
178 }
179 #endif
PyObject * BPy_ViewShape_from_ViewShape(ViewShape &vs)
PyTypeObject GetOccludersF0D_Type
PyTypeObject Interface0DIterator_Type
PyTypeObject UnaryFunction0DVectorViewShape_Type
static PyObject * UnaryFunction0DVectorViewShape___call__(BPy_UnaryFunction0DVectorViewShape *self, PyObject *args, PyObject *kwds)
int UnaryFunction0DVectorViewShape_Init(PyObject *module)
static PyObject * UnaryFunction0DVectorViewShape___repr__(BPy_UnaryFunction0DVectorViewShape *self)
static char UnaryFunction0DVectorViewShape___doc__[]
static void UnaryFunction0DVectorViewShape___dealloc__(BPy_UnaryFunction0DVectorViewShape *self)
static int UnaryFunction0DVectorViewShape___init__(BPy_UnaryFunction0DVectorViewShape *self, PyObject *args, PyObject *kwds)
PyTypeObject UnaryFunction0D_Type
static struct PyModuleDef module
ATTR_WARN_UNUSED_RESULT const BMVert * v
PyObject * self
Definition: bpy_driver.c:185
inherits from class Rep
Definition: AppCanvas.cpp:32