Blender  V2.93
BPy_UnaryFunction1DVoid.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 "../BPy_IntegrationType.h"
25 #include "../BPy_Interface1D.h"
26 
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 using namespace Freestyle;
36 
38 
39 //-------------------MODULE INITIALIZATION--------------------------------
40 
42 {
43  if (module == nullptr) {
44  return -1;
45  }
46 
47  if (PyType_Ready(&UnaryFunction1DVoid_Type) < 0) {
48  return -1;
49  }
50  Py_INCREF(&UnaryFunction1DVoid_Type);
51  PyModule_AddObject(module, "UnaryFunction1DVoid", (PyObject *)&UnaryFunction1DVoid_Type);
52 
53  if (PyType_Ready(&ChainingTimeStampF1D_Type) < 0) {
54  return -1;
55  }
56  Py_INCREF(&ChainingTimeStampF1D_Type);
57  PyModule_AddObject(module, "ChainingTimeStampF1D", (PyObject *)&ChainingTimeStampF1D_Type);
58 
59  if (PyType_Ready(&IncrementChainingTimeStampF1D_Type) < 0) {
60  return -1;
61  }
63  PyModule_AddObject(
64  module, "IncrementChainingTimeStampF1D", (PyObject *)&IncrementChainingTimeStampF1D_Type);
65 
66  if (PyType_Ready(&TimeStampF1D_Type) < 0) {
67  return -1;
68  }
69  Py_INCREF(&TimeStampF1D_Type);
70  PyModule_AddObject(module, "TimeStampF1D", (PyObject *)&TimeStampF1D_Type);
71 
72  return 0;
73 }
74 
75 //------------------------INSTANCE METHODS ----------------------------------
76 
78  "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DVoid`\n"
79  "\n"
80  "Base class for unary functions (functors) working on\n"
81  ":class:`Interface1D`.\n"
82  "\n"
83  ".. method:: __init__()\n"
84  " __init__(integration_type)\n"
85  "\n"
86  " Builds a unary 1D function using either a default constructor\n"
87  " or the integration method given as an argument.\n"
88  "\n"
89  " :arg integration_type: An integration method.\n"
90  " :type integration_type: :class:`IntegrationType`\n";
91 
93  PyObject *args,
94  PyObject *kwds)
95 {
96  static const char *kwlist[] = {"integration", nullptr};
97  PyObject *obj = nullptr;
98 
99  if (!PyArg_ParseTupleAndKeywords(
100  args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) {
101  return -1;
102  }
103 
104  if (!obj) {
105  self->uf1D_void = new UnaryFunction1D_void();
106  }
107  else {
109  }
110 
111  self->uf1D_void->py_uf1D = (PyObject *)self;
112 
113  return 0;
114 }
115 
117 {
118  delete self->uf1D_void;
119  UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
120 }
121 
123 {
124  return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_void);
125 }
126 
128  PyObject *args,
129  PyObject *kwds)
130 {
131  static const char *kwlist[] = {"inter", nullptr};
132  PyObject *obj = nullptr;
133 
134  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
135  return nullptr;
136  }
137 
138  if (typeid(*(self->uf1D_void)) == typeid(UnaryFunction1D_void)) {
139  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
140  return nullptr;
141  }
142  if (self->uf1D_void->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
143  if (!PyErr_Occurred()) {
144  string class_name(Py_TYPE(self)->tp_name);
145  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
146  }
147  return nullptr;
148  }
149  Py_RETURN_NONE;
150 }
151 
152 /*----------------------UnaryFunction1DVoid get/setters ----------------------------*/
153 
154 PyDoc_STRVAR(integration_type_doc,
155  "The integration method.\n"
156  "\n"
157  ":type: :class:`IntegrationType`");
158 
159 static PyObject *integration_type_get(BPy_UnaryFunction1DVoid *self, void *UNUSED(closure))
160 {
161  return BPy_IntegrationType_from_IntegrationType(self->uf1D_void->getIntegrationType());
162 }
163 
165  PyObject *value,
166  void *UNUSED(closure))
167 {
168  if (!BPy_IntegrationType_Check(value)) {
169  PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
170  return -1;
171  }
172  self->uf1D_void->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
173  return 0;
174 }
175 
176 static PyGetSetDef BPy_UnaryFunction1DVoid_getseters[] = {
177  {"integration_type",
178  (getter)integration_type_get,
179  (setter)integration_type_set,
180  integration_type_doc,
181  nullptr},
182  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
183 };
184 
185 /*-----------------------BPy_UnaryFunction1DVoid type definition ------------------------------*/
186 
187 PyTypeObject UnaryFunction1DVoid_Type = {
188  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction1DVoid", /* tp_name */
189  sizeof(BPy_UnaryFunction1DVoid), /* tp_basicsize */
190  0, /* tp_itemsize */
191  (destructor)UnaryFunction1DVoid___dealloc__, /* tp_dealloc */
192  0, /* tp_vectorcall_offset */
193  nullptr, /* tp_getattr */
194  nullptr, /* tp_setattr */
195  nullptr, /* tp_reserved */
196  (reprfunc)UnaryFunction1DVoid___repr__, /* tp_repr */
197  nullptr, /* tp_as_number */
198  nullptr, /* tp_as_sequence */
199  nullptr, /* tp_as_mapping */
200  nullptr, /* tp_hash */
201  (ternaryfunc)UnaryFunction1DVoid___call__, /* tp_call */
202  nullptr, /* tp_str */
203  nullptr, /* tp_getattro */
204  nullptr, /* tp_setattro */
205  nullptr, /* tp_as_buffer */
206  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
207  UnaryFunction1DVoid___doc__, /* tp_doc */
208  nullptr, /* tp_traverse */
209  nullptr, /* tp_clear */
210  nullptr, /* tp_richcompare */
211  0, /* tp_weaklistoffset */
212  nullptr, /* tp_iter */
213  nullptr, /* tp_iternext */
214  nullptr, /* tp_methods */
215  nullptr, /* tp_members */
216  BPy_UnaryFunction1DVoid_getseters, /* tp_getset */
217  &UnaryFunction1D_Type, /* tp_base */
218  nullptr, /* tp_dict */
219  nullptr, /* tp_descr_get */
220  nullptr, /* tp_descr_set */
221  0, /* tp_dictoffset */
222  (initproc)UnaryFunction1DVoid___init__, /* tp_init */
223  nullptr, /* tp_alloc */
224  nullptr, /* tp_new */
225 };
226 
228 
229 #ifdef __cplusplus
230 }
231 #endif
#define UNUSED(x)
PyTypeObject ChainingTimeStampF1D_Type
PyObject * BPy_IntegrationType_from_IntegrationType(IntegrationType i)
IntegrationType IntegrationType_from_BPy_IntegrationType(PyObject *obj)
PyTypeObject IncrementChainingTimeStampF1D_Type
PyTypeObject IntegrationType_Type
#define BPy_IntegrationType_Check(v)
PyTypeObject Interface1D_Type
PyTypeObject TimeStampF1D_Type
static char UnaryFunction1DVoid___doc__[]
static PyObject * UnaryFunction1DVoid___call__(BPy_UnaryFunction1DVoid *self, PyObject *args, PyObject *kwds)
PyDoc_STRVAR(integration_type_doc, "The integration method.\n" "\n" ":type: :class:`IntegrationType`")
static PyObject * integration_type_get(BPy_UnaryFunction1DVoid *self, void *UNUSED(closure))
int UnaryFunction1DVoid_Init(PyObject *module)
static int integration_type_set(BPy_UnaryFunction1DVoid *self, PyObject *value, void *UNUSED(closure))
PyTypeObject UnaryFunction1DVoid_Type
static int UnaryFunction1DVoid___init__(BPy_UnaryFunction1DVoid *self, PyObject *args, PyObject *kwds)
static void UnaryFunction1DVoid___dealloc__(BPy_UnaryFunction1DVoid *self)
static PyObject * UnaryFunction1DVoid___repr__(BPy_UnaryFunction1DVoid *self)
static PyGetSetDef BPy_UnaryFunction1DVoid_getseters[]
PyTypeObject UnaryFunction1D_Type
static struct PyModuleDef module
PyObject * self
Definition: bpy_driver.c:185
inherits from class Rep
Definition: AppCanvas.cpp:32