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