Blender  V3.3
BPy_UnaryFunction1DEdgeNature.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
8 
9 #include "../BPy_Convert.h"
10 #include "../BPy_IntegrationType.h"
11 #include "../BPy_Interface1D.h"
12 
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 using namespace Freestyle;
20 
22 
23 //-------------------MODULE INITIALIZATION--------------------------------
24 
26 {
27  if (module == nullptr) {
28  return -1;
29  }
30 
31  if (PyType_Ready(&UnaryFunction1DEdgeNature_Type) < 0) {
32  return -1;
33  }
35  PyModule_AddObject(
36  module, "UnaryFunction1DEdgeNature", (PyObject *)&UnaryFunction1DEdgeNature_Type);
37 
38  if (PyType_Ready(&CurveNatureF1D_Type) < 0) {
39  return -1;
40  }
41  Py_INCREF(&CurveNatureF1D_Type);
42  PyModule_AddObject(module, "CurveNatureF1D", (PyObject *)&CurveNatureF1D_Type);
43 
44  return 0;
45 }
46 
47 //------------------------INSTANCE METHODS ----------------------------------
48 
50  "Class hierarchy: :class:`UnaryFunction1D` > :class:`UnaryFunction1DEdgeNature`\n"
51  "\n"
52  "Base class for unary functions (functors) that work on\n"
53  ":class:`Interface1D` and return a :class:`Nature` object.\n"
54  "\n"
55  ".. method:: __init__()\n"
56  " __init__(integration_type)\n"
57  "\n"
58  " Builds a unary 1D function using the default constructor\n"
59  " or the integration method given as an argument.\n"
60  "\n"
61  " :arg integration_type: An integration method.\n"
62  " :type integration_type: :class:`IntegrationType`\n";
63 
65  PyObject *args,
66  PyObject *kwds)
67 {
68  static const char *kwlist[] = {"integration", nullptr};
69  PyObject *obj = nullptr;
70 
71  if (!PyArg_ParseTupleAndKeywords(
72  args, kwds, "|O!", (char **)kwlist, &IntegrationType_Type, &obj)) {
73  return -1;
74  }
75 
76  if (!obj) {
77  self->uf1D_edgenature = new UnaryFunction1D<Nature::EdgeNature>();
78  }
79  else {
80  self->uf1D_edgenature = new UnaryFunction1D<Nature::EdgeNature>(
82  }
83 
84  self->uf1D_edgenature->py_uf1D = (PyObject *)self;
85 
86  return 0;
87 }
88 
90 {
91  delete self->uf1D_edgenature;
92  UnaryFunction1D_Type.tp_dealloc((PyObject *)self);
93 }
94 
96 {
97  return PyUnicode_FromFormat(
98  "type: %s - address: %p", Py_TYPE(self)->tp_name, self->uf1D_edgenature);
99 }
100 
102  PyObject *args,
103  PyObject *kwds)
104 {
105  static const char *kwlist[] = {"inter", nullptr};
106  PyObject *obj = nullptr;
107 
108  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Interface1D_Type, &obj)) {
109  return nullptr;
110  }
111 
112  if (typeid(*(self->uf1D_edgenature)) == typeid(UnaryFunction1D<Nature::EdgeNature>)) {
113  PyErr_SetString(PyExc_TypeError, "__call__ method not properly overridden");
114  return nullptr;
115  }
116  if (self->uf1D_edgenature->operator()(*(((BPy_Interface1D *)obj)->if1D)) < 0) {
117  if (!PyErr_Occurred()) {
118  string class_name(Py_TYPE(self)->tp_name);
119  PyErr_SetString(PyExc_RuntimeError, (class_name + " __call__ method failed").c_str());
120  }
121  return nullptr;
122  }
123  return BPy_Nature_from_Nature(self->uf1D_edgenature->result);
124 }
125 
126 /*----------------------UnaryFunction1DEdgeNature get/setters ----------------------------*/
127 
128 PyDoc_STRVAR(integration_type_doc,
129  "The integration method.\n"
130  "\n"
131  ":type: :class:`IntegrationType`");
132 
133 static PyObject *integration_type_get(BPy_UnaryFunction1DEdgeNature *self, void *UNUSED(closure))
134 {
135  return BPy_IntegrationType_from_IntegrationType(self->uf1D_edgenature->getIntegrationType());
136 }
137 
139  PyObject *value,
140  void *UNUSED(closure))
141 {
142  if (!BPy_IntegrationType_Check(value)) {
143  PyErr_SetString(PyExc_TypeError, "value must be an IntegrationType");
144  return -1;
145  }
146  self->uf1D_edgenature->setIntegrationType(IntegrationType_from_BPy_IntegrationType(value));
147  return 0;
148 }
149 
151  {"integration_type",
152  (getter)integration_type_get,
153  (setter)integration_type_set,
154  integration_type_doc,
155  nullptr},
156  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
157 };
158 
159 /*-----------------------BPy_UnaryFunction1DEdgeNature type definition --------------------------*/
160 
162  PyVarObject_HEAD_INIT(nullptr, 0) "UnaryFunction1DEdgeNature", /* tp_name */
163  sizeof(BPy_UnaryFunction1DEdgeNature), /* tp_basicsize */
164  0, /* tp_itemsize */
165  (destructor)UnaryFunction1DEdgeNature___dealloc__, /* tp_dealloc */
166  0, /* tp_vectorcall_offset */
167  nullptr, /* tp_getattr */
168  nullptr, /* tp_setattr */
169  nullptr, /* tp_reserved */
170  (reprfunc)UnaryFunction1DEdgeNature___repr__, /* tp_repr */
171  nullptr, /* tp_as_number */
172  nullptr, /* tp_as_sequence */
173  nullptr, /* tp_as_mapping */
174  nullptr, /* tp_hash */
175  (ternaryfunc)UnaryFunction1DEdgeNature___call__, /* tp_call */
176  nullptr, /* tp_str */
177  nullptr, /* tp_getattro */
178  nullptr, /* tp_setattro */
179  nullptr, /* tp_as_buffer */
180  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
182  nullptr, /* tp_traverse */
183  nullptr, /* tp_clear */
184  nullptr, /* tp_richcompare */
185  0, /* tp_weaklistoffset */
186  nullptr, /* tp_iter */
187  nullptr, /* tp_iternext */
188  nullptr, /* tp_methods */
189  nullptr, /* tp_members */
191  &UnaryFunction1D_Type, /* tp_base */
192  nullptr, /* tp_dict */
193  nullptr, /* tp_descr_get */
194  nullptr, /* tp_descr_set */
195  0, /* tp_dictoffset */
196  (initproc)UnaryFunction1DEdgeNature___init__, /* tp_init */
197  nullptr, /* tp_alloc */
198  nullptr, /* tp_new */
199 };
200 
202 
203 #ifdef __cplusplus
204 }
205 #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
PyObject * self
Definition: bpy_driver.c:165
inherits from class Rep
Definition: AppCanvas.cpp:18
static struct PyModuleDef module
Definition: python.cpp:972