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