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