Blender  V3.3
BPy_UnaryFunction1DVec3f.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 
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 using namespace Freestyle;
20 
22 
23 //-------------------MODULE INITIALIZATION--------------------------------
24 
26 {
27  if (module == nullptr) {
28  return -1;
29  }
30 
31  if (PyType_Ready(&UnaryFunction1DVec3f_Type) < 0) {
32  return -1;
33  }
34  Py_INCREF(&UnaryFunction1DVec3f_Type);
35  PyModule_AddObject(module, "UnaryFunction1DVec3f", (PyObject *)&UnaryFunction1DVec3f_Type);
36 
37  if (PyType_Ready(&Orientation3DF1D_Type) < 0) {
38  return -1;
39  }
40  Py_INCREF(&Orientation3DF1D_Type);
41  PyModule_AddObject(module, "Orientation3DF1D", (PyObject *)&Orientation3DF1D_Type);
42 
43  return 0;
44 }
45 
46 //------------------------INSTANCE METHODS ----------------------------------
47 
49  "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVec3f`\n"
50  "\n"
51  "Base class for unary functions (functors) that work on\n"
52  ":class:`Interface1D` and return a 3D vector.\n"
53  "\n"
54  ".. method:: __init__()\n"
55  " __init__(integration_type)\n"
56  "\n"
57  " Builds a unary 1D function using the default constructor\n"
58  " or the integration method given as an argument.\n"
59  "\n"
60  " :arg integration_type: An integration method.\n"
61  " :type integration_type: :class:`IntegrationType`\n";
62 
64  PyObject *args,
65  PyObject *kwds)
66 {
67  static const char *kwlist[] = {"integration", nullptr};
68  PyObject *obj = nullptr;
69 
70  if (!PyArg_ParseTupleAndKeywords(
71  args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) {
72  return -1;
73  }
74 
75  if (!obj) {
76  self->uf1D_vec3f = new UnaryFunction1D<Vec3f>();
77  }
78  else {
80  }
81 
82  self->uf1D_vec3f->py_uf1D = (PyObject *)self;
83 
84  return 0;
85 }
86 
88 {
89  delete self->uf1D_vec3f;
90  UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
91 }
92 
94 {
95  return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_vec3f);
96 }
97 
99  PyObject *args,
100  PyObject *kwds)
101 {
102  static const char *kwlist[] = {"inter", nullptr};
103  PyObject *obj = nullptr;
104 
105  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
106  return nullptr;
107  }
108 
109  if (typeid(*(self->uf1D_vec3f)) == typeid(UnaryFunction1D<Vec3f>)) {
110  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
111  return nullptr;
112  }
113  if (self->uf1D_vec3f->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
114  if (!PyErr_Occurred()) {
115  string class_name(Py_TYPE(self)->tp_name);
116  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
117  }
118  return nullptr;
119  }
120  return Vector_from_Vec3f(self->uf1D_vec3f->result);
121 }
122 
123 /*----------------------UnaryFunction1DVec3f get/setters ----------------------------*/
124 
125 PyDoc_STRVAR(integration_type_doc,
126  "The integration method.\n"
127  "\n"
128  ":type: :class:`IntegrationType`");
129 
130 static PyObject *integration_type_get(BPy_UnaryFunction1DVec3f *self, void *UNUSED(closure))
131 {
132  return BPy_IntegrationType_from_IntegrationType(self->uf1D_vec3f->getIntegrationType());
133 }
134 
136  PyObject *value,
137  void *UNUSED(closure))
138 {
139  if (!BPy_IntegrationType_Check(value)) {
140  PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
141  return -1;
142  }
143  self->uf1D_vec3f->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
144  return 0;
145 }
146 
147 static PyGetSetDef BPy_UnaryFunction1DVec3f_getseters[] = {
148  {"integration_type",
149  (getter)integration_type_get,
150  (setter)integration_type_set,
151  integration_type_doc,
152  nullptr},
153  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
154 };
155 
156 /*-----------------------BPy_UnaryFunction1DVec3f type definition ------------------------------*/
157 
159  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction1DVec3f", /* tp_name */
160  sizeof(BPy_UnaryFunction1DVec3f), /* tp_basicsize */
161  0, /* tp_itemsize */
162  (destructor)UnaryFunction1DVec3f___dealloc__, /* tp_dealloc */
163  0, /* tp_vectorcall_offset */
164  nullptr, /* tp_getattr */
165  nullptr, /* tp_setattr */
166  nullptr, /* tp_reserved */
167  (reprfunc)UnaryFunction1DVec3f___repr__, /* tp_repr */
168  nullptr, /* tp_as_number */
169  nullptr, /* tp_as_sequence */
170  nullptr, /* tp_as_mapping */
171  nullptr, /* tp_hash */
172  (ternaryfunc)UnaryFunction1DVec3f___call__, /* tp_call */
173  nullptr, /* tp_str */
174  nullptr, /* tp_getattro */
175  nullptr, /* tp_setattro */
176  nullptr, /* tp_as_buffer */
177  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
178  UnaryFunction1DVec3f___doc__, /* tp_doc */
179  nullptr, /* tp_traverse */
180  nullptr, /* tp_clear */
181  nullptr, /* tp_richcompare */
182  0, /* tp_weaklistoffset */
183  nullptr, /* tp_iter */
184  nullptr, /* tp_iternext */
185  nullptr, /* tp_methods */
186  nullptr, /* tp_members */
187  BPy_UnaryFunction1DVec3f_getseters, /* tp_getset */
188  &UnaryFunction1D_Type, /* tp_base */
189  nullptr, /* tp_dict */
190  nullptr, /* tp_descr_get */
191  nullptr, /* tp_descr_set */
192  0, /* tp_dictoffset */
193  (initproc)UnaryFunction1DVec3f___init__, /* tp_init */
194  nullptr, /* tp_alloc */
195  nullptr, /* tp_new */
196 };
197 
199 
200 #ifdef __cplusplus
201 }
202 #endif
#define UNUSED(x)
PyObject * Vector_from_Vec3f(Vec3f &vec)
Definition: BPy_Convert.cpp:72
PyObject * BPy_IntegrationType_from_IntegrationType(IntegrationType i)
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
PyTypeObject IntegrationType_Type
#define BPy_IntegrationType_Check(v)
PyTypeObject Interface1D_Type
PyTypeObject Orientation3DF1D_Type
static char UnaryFunction1DVec3f___doc__[]
PyDoc_STRVAR(integration_type_doc, "The integration method.\n" "\n" ":type: :class:`IntegrationType`")
static PyObject * integration_type_get(BPy_UnaryFunction1DVec3f *self, void *UNUSED(closure))
static int integration_type_set(BPy_UnaryFunction1DVec3f *self, PyObject *value, void *UNUSED(closure))
int UnaryFunction1DVec3f_Init(PyObject *module)
static int UnaryFunction1DVec3f___init__(BPy_UnaryFunction1DVec3f *self, PyObject *args, PyObject *kwds)
static PyGetSetDef BPy_UnaryFunction1DVec3f_getseters[]
static PyObject * UnaryFunction1DVec3f___repr__(BPy_UnaryFunction1DVec3f *self)
PyTypeObject UnaryFunction1DVec3f_Type
static PyObject * UnaryFunction1DVec3f___call__(BPy_UnaryFunction1DVec3f *self, PyObject *args, PyObject *kwds)
static void UnaryFunction1DVec3f___dealloc__(BPy_UnaryFunction1DVec3f *self)
PyTypeObject UnaryFunction1D_Type
PyObject * self
Definition: bpy_driver.c:165
inherits from class Rep
Definition: AppCanvas.cpp:18
static struct PyModuleDef module
Definition: python.cpp:972