Blender  V3.3
BPy_UnaryFunction0DVec2f.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 "../Iterator/BPy_Interface0DIterator.h"
11 
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(&UnaryFunction0DVec2f_Type) < 0) {
32  return -1;
33  }
34  Py_INCREF(&UnaryFunction0DVec2f_Type);
35  PyModule_AddObject(module, "UnaryFunction0DVec2f", (PyObject *)&UnaryFunction0DVec2f_Type);
36 
37  if (PyType_Ready(&Normal2DF0D_Type) < 0) {
38  return -1;
39  }
40  Py_INCREF(&Normal2DF0D_Type);
41  PyModule_AddObject(module, "Normal2DF0D", (PyObject *)&Normal2DF0D_Type);
42 
43  if (PyType_Ready(&VertexOrientation2DF0D_Type) < 0) {
44  return -1;
45  }
46  Py_INCREF(&VertexOrientation2DF0D_Type);
47  PyModule_AddObject(module, "VertexOrientation2DF0D", (PyObject *)&VertexOrientation2DF0D_Type);
48 
49  return 0;
50 }
51 
52 //------------------------INSTANCE METHODS ----------------------------------
53 
55  "Class hierarchy: :class:`UnaryFunction0D` > :class:`UnaryFunction0DVec2f`\n"
56  "\n"
57  "Base class for unary functions (functors) that work on\n"
58  ":class:`Interface0DIterator` and return a 2D vector.\n"
59  "\n"
60  ".. method:: __init__()\n"
61  "\n"
62  " Default constructor.\n";
63 
65  PyObject *args,
66  PyObject *kwds)
67 {
68  static const char *kwlist[] = {nullptr};
69 
70  if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
71  return -1;
72  }
73  self->uf0D_vec2f = new UnaryFunction0D<Vec2f>();
74  self->uf0D_vec2f->py_uf0D = (PyObject *)self;
75  return 0;
76 }
77 
79 {
80  delete self->uf0D_vec2f;
81  UnaryFunction0D_Type.tp_dealloc((PyObject *)self);
82 }
83 
85 {
86  return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf0D_vec2f);
87 }
88 
90  PyObject *args,
91  PyObject *kwds)
92 {
93  static const char *kwlist[] = {"it", nullptr};
94  PyObject *obj;
95 
96  if (!PyArg_ParseTupleAndKeywords(
97  args, kwds, "O!", (char **)kwlist, &Interface0DIterator_Type, &obj)) {
98  return nullptr;
99  }
100 
101  if (typeid(*(self->uf0D_vec2f)) == typeid(UnaryFunction0D<Vec2f>)) {
102  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
103  return nullptr;
104  }
105  if (self->uf0D_vec2f->operator()(*(((BPy_Interface0DIterator *)obj)->if0D_it)) < 0) {
106  if (!PyErr_Occurred()) {
107  string class_name(Py_TYPE(self)->tp_name);
108  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
109  }
110  return nullptr;
111  }
112  return Vector_from_Vec2f(self->uf0D_vec2f->result);
113 }
114 
115 /*-----------------------BPy_UnaryFunction0DVec2f type definition ------------------------------*/
116 
118  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction0DVec2f", /* tp_name */
119  sizeof(BPy_UnaryFunction0DVec2f), /* tp_basicsize */
120  0, /* tp_itemsize */
121  (destructor)UnaryFunction0DVec2f___dealloc__, /* tp_dealloc */
122  0, /* tp_vectorcall_offset */
123  nullptr, /* tp_getattr */
124  nullptr, /* tp_setattr */
125  nullptr, /* tp_reserved */
126  (reprfunc)UnaryFunction0DVec2f___repr__, /* tp_repr */
127  nullptr, /* tp_as_number */
128  nullptr, /* tp_as_sequence */
129  nullptr, /* tp_as_mapping */
130  nullptr, /* tp_hash */
131  (ternaryfunc)UnaryFunction0DVec2f___call__, /* tp_call */
132  nullptr, /* tp_str */
133  nullptr, /* tp_getattro */
134  nullptr, /* tp_setattro */
135  nullptr, /* tp_as_buffer */
136  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
137  UnaryFunction0DVec2f___doc__, /* tp_doc */
138  nullptr, /* tp_traverse */
139  nullptr, /* tp_clear */
140  nullptr, /* tp_richcompare */
141  0, /* tp_weaklistoffset */
142  nullptr, /* tp_iter */
143  nullptr, /* tp_iternext */
144  nullptr, /* tp_methods */
145  nullptr, /* tp_members */
146  nullptr, /* tp_getset */
147  &UnaryFunction0D_Type, /* tp_base */
148  nullptr, /* tp_dict */
149  nullptr, /* tp_descr_get */
150  nullptr, /* tp_descr_set */
151  0, /* tp_dictoffset */
152  (initproc)UnaryFunction0DVec2f___init__, /* tp_init */
153  nullptr, /* tp_alloc */
154  nullptr, /* tp_new */
155 };
156 
158 
159 #ifdef __cplusplus
160 }
161 #endif
PyObject * Vector_from_Vec2f(Vec2f &vec)
Definition: BPy_Convert.cpp:64
PyTypeObject Interface0DIterator_Type
PyTypeObject Normal2DF0D_Type
static PyObject * UnaryFunction0DVec2f___call__(BPy_UnaryFunction0DVec2f *self, PyObject *args, PyObject *kwds)
static PyObject * UnaryFunction0DVec2f___repr__(BPy_UnaryFunction0DVec2f *self)
static int UnaryFunction0DVec2f___init__(BPy_UnaryFunction0DVec2f *self, PyObject *args, PyObject *kwds)
PyTypeObject UnaryFunction0DVec2f_Type
static char UnaryFunction0DVec2f___doc__[]
static void UnaryFunction0DVec2f___dealloc__(BPy_UnaryFunction0DVec2f *self)
int UnaryFunction0DVec2f_Init(PyObject *module)
PyTypeObject UnaryFunction0D_Type
PyTypeObject VertexOrientation2DF0D_Type
PyObject * self
Definition: bpy_driver.c:165
inherits from class Rep
Definition: AppCanvas.cpp:18
static struct PyModuleDef module
Definition: python.cpp:972