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