Blender  V2.93
BPy_UnaryFunction1DVectorViewShape.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 "../BPy_IntegrationType.h"
25 #include "../BPy_Interface1D.h"
26 
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 using namespace Freestyle;
36 
38 
39 //-------------------MODULE INITIALIZATION--------------------------------
40 
42 {
43  if (module == nullptr) {
44  return -1;
45  }
46 
47  if (PyType_Ready(&UnaryFunction1DVectorViewShape_Type) < 0) {
48  return -1;
49  }
51  PyModule_AddObject(
52  module, "UnaryFunction1DVectorViewShape", (PyObject *)&UnaryFunction1DVectorViewShape_Type);
53 
54  if (PyType_Ready(&GetOccludeeF1D_Type) < 0) {
55  return -1;
56  }
57  Py_INCREF(&GetOccludeeF1D_Type);
58  PyModule_AddObject(module, "GetOccludeeF1D", (PyObject *)&GetOccludeeF1D_Type);
59 
60  if (PyType_Ready(&GetOccludersF1D_Type) < 0) {
61  return -1;
62  }
63  Py_INCREF(&GetOccludersF1D_Type);
64  PyModule_AddObject(module, "GetOccludersF1D", (PyObject *)&GetOccludersF1D_Type);
65 
66  if (PyType_Ready(&GetShapeF1D_Type) < 0) {
67  return -1;
68  }
69  Py_INCREF(&GetShapeF1D_Type);
70  PyModule_AddObject(module, "GetShapeF1D", (PyObject *)&GetShapeF1D_Type);
71 
72  return 0;
73 }
74 
75 //------------------------INSTANCE METHODS ----------------------------------
76 
78  "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVectorViewShape`\n"
79  "\n"
80  "Base class for unary functions (functors) that work on\n"
81  ":class:`Interface1D` and return a list of :class:`ViewShape`\n"
82  "objects.\n"
83  "\n"
84  ".. method:: __init__()\n"
85  " __init__(integration_type)\n"
86  "\n"
87  " Builds a unary 1D function using the default constructor\n"
88  " or the integration method given as an argument.\n"
89  "\n"
90  " :arg integration_type: An integration method.\n"
91  " :type integration_type: :class:`IntegrationType`\n";
92 
94  PyObject *args,
95  PyObject *kwds)
96 {
97  static const char *kwlist[] = {"integration", nullptr};
98  PyObject *obj = nullptr;
99 
100  if (!PyArg_ParseTupleAndKeywords(
101  args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) {
102  return -1;
103  }
104 
105  if (!obj) {
106  self->uf1D_vectorviewshape = new UnaryFunction1D<std::vector<ViewShape *>>();
107  }
108  else {
109  self->uf1D_vectorviewshape = new UnaryFunction1D<std::vector<ViewShape *>>(
111  }
112 
113  self->uf1D_vectorviewshape->py_uf1D = (PyObject *)self;
114 
115  return 0;
116 }
117 
119 {
120  delete self->uf1D_vectorviewshape;
121  UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
122 }
123 
125 {
126  return PyUnicode_FromFormat(
127  "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_vectorviewshape);
128 }
129 
131  PyObject *args,
132  PyObject *kwds)
133 {
134  static const char *kwlist[] = {"inter", nullptr};
135  PyObject *obj = nullptr;
136 
137  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
138  return nullptr;
139  }
140 
141  if (typeid(*(self->uf1D_vectorviewshape)) == typeid(UnaryFunction1D<std::vector<ViewShape *>>)) {
142  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
143  return nullptr;
144  }
145  if (self->uf1D_vectorviewshape->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
146  if (!PyErr_Occurred()) {
147  string class_name(Py_TYPE(self)->tp_name);
148  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
149  }
150  return nullptr;
151  }
152 
153  const unsigned int list_len = self->uf1D_vectorviewshape->result.size();
154  PyObject *list = PyList_New(list_len);
155  for (unsigned int i = 0; i < list_len; i++) {
156  ViewShape *v = self->uf1D_vectorviewshape->result[i];
157  PyList_SET_ITEM(list, i, v ? BPy_ViewShape_from_ViewShape(*v) : (Py_INCREF(Py_None), Py_None));
158  }
159 
160  return list;
161 }
162 
163 /*----------------------UnaryFunction1DVectorViewShape get/setters ----------------------------*/
164 
165 PyDoc_STRVAR(integration_type_doc,
166  "The integration method.\n"
167  "\n"
168  ":type: :class:`IntegrationType`");
169 
171  void *UNUSED(closure))
172 {
174  self->uf1D_vectorviewshape->getIntegrationType());
175 }
176 
178  PyObject *value,
179  void *UNUSED(closure))
180 {
181  if (!BPy_IntegrationType_Check(value)) {
182  PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
183  return -1;
184  }
185  self->uf1D_vectorviewshape->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
186  return 0;
187 }
188 
190  {"integration_type",
191  (getter)integration_type_get,
192  (setter)integration_type_set,
193  integration_type_doc,
194  nullptr},
195  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
196 };
197 
198 /*-----------------------BPy_UnaryFunction1DVectorViewShape type definition ---------------------*/
199 
201  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction1DVectorViewShape", /* tp_name */
202  sizeof(BPy_UnaryFunction1DVectorViewShape), /* tp_basicsize */
203  0, /* tp_itemsize */
204  (destructor)UnaryFunction1DVectorViewShape___dealloc__, /* tp_dealloc */
205  0, /* tp_vectorcall_offset */
206  nullptr, /* tp_getattr */
207  nullptr, /* tp_setattr */
208  nullptr, /* tp_reserved */
209  (reprfunc)UnaryFunction1DVectorViewShape___repr__, /* tp_repr */
210  nullptr, /* tp_as_number */
211  nullptr, /* tp_as_sequence */
212  nullptr, /* tp_as_mapping */
213  nullptr, /* tp_hash */
214  (ternaryfunc)UnaryFunction1DVectorViewShape___call__, /* tp_call */
215  nullptr, /* tp_str */
216  nullptr, /* tp_getattro */
217  nullptr, /* tp_setattro */
218  nullptr, /* tp_as_buffer */
219  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
221  nullptr, /* tp_traverse */
222  nullptr, /* tp_clear */
223  nullptr, /* tp_richcompare */
224  0, /* tp_weaklistoffset */
225  nullptr, /* tp_iter */
226  nullptr, /* tp_iternext */
227  nullptr, /* tp_methods */
228  nullptr, /* tp_members */
230  &UnaryFunction1D_Type, /* tp_base */
231  nullptr, /* tp_dict */
232  nullptr, /* tp_descr_get */
233  nullptr, /* tp_descr_set */
234  0, /* tp_dictoffset */
235  (initproc)UnaryFunction1DVectorViewShape___init__, /* tp_init */
236  nullptr, /* tp_alloc */
237  nullptr, /* tp_new */
238 };
239 
241 
242 #ifdef __cplusplus
243 }
244 #endif
#define UNUSED(x)
PyObject * BPy_ViewShape_from_ViewShape(ViewShape &vs)
PyObject * BPy_IntegrationType_from_IntegrationType(IntegrationType i)
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
PyTypeObject GetOccludeeF1D_Type
PyTypeObject GetOccludersF1D_Type
PyTypeObject GetShapeF1D_Type
PyTypeObject IntegrationType_Type
#define BPy_IntegrationType_Check(v)
PyTypeObject Interface1D_Type
PyDoc_STRVAR(integration_type_doc, "The integration method.\n" "\n" ":type: :class:`IntegrationType`")
static PyObject * integration_type_get(BPy_UnaryFunction1DVectorViewShape *self, void *UNUSED(closure))
static PyObject * UnaryFunction1DVectorViewShape___call__(BPy_UnaryFunction1DVectorViewShape *self, PyObject *args, PyObject *kwds)
static int UnaryFunction1DVectorViewShape___init__(BPy_UnaryFunction1DVectorViewShape *self, PyObject *args, PyObject *kwds)
static char UnaryFunction1DVectorViewShape___doc__[]
static PyGetSetDef BPy_UnaryFunction1DVectorViewShape_getseters[]
PyTypeObject UnaryFunction1DVectorViewShape_Type
static PyObject * UnaryFunction1DVectorViewShape___repr__(BPy_UnaryFunction1DVectorViewShape *self)
int UnaryFunction1DVectorViewShape_Init(PyObject *module)
static void UnaryFunction1DVectorViewShape___dealloc__(BPy_UnaryFunction1DVectorViewShape *self)
static int integration_type_set(BPy_UnaryFunction1DVectorViewShape *self, PyObject *value, void *UNUSED(closure))
PyTypeObject UnaryFunction1D_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