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