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