Blender V4.5
BPy_StrokeShader.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BPy_StrokeShader.h"
10
11#include "BPy_Convert.h"
13
32
33using namespace Freestyle;
34
36
37//-------------------MODULE INITIALIZATION--------------------------------
39{
40 if (module == nullptr) {
41 return -1;
42 }
43
44 if (PyType_Ready(&StrokeShader_Type) < 0) {
45 return -1;
46 }
47 PyModule_AddObjectRef(module, "StrokeShader", (PyObject *)&StrokeShader_Type);
48
49 if (PyType_Ready(&BackboneStretcherShader_Type) < 0) {
50 return -1;
51 }
52 PyModule_AddObjectRef(
53 module, "BackboneStretcherShader", (PyObject *)&BackboneStretcherShader_Type);
54
55 if (PyType_Ready(&BezierCurveShader_Type) < 0) {
56 return -1;
57 }
58 PyModule_AddObjectRef(module, "BezierCurveShader", (PyObject *)&BezierCurveShader_Type);
59
60 if (PyType_Ready(&BlenderTextureShader_Type) < 0) {
61 return -1;
62 }
63 PyModule_AddObjectRef(module, "BlenderTextureShader", (PyObject *)&BlenderTextureShader_Type);
64
65 if (PyType_Ready(&CalligraphicShader_Type) < 0) {
66 return -1;
67 }
68 PyModule_AddObjectRef(module, "CalligraphicShader", (PyObject *)&CalligraphicShader_Type);
69
70 if (PyType_Ready(&ColorNoiseShader_Type) < 0) {
71 return -1;
72 }
73 PyModule_AddObjectRef(module, "ColorNoiseShader", (PyObject *)&ColorNoiseShader_Type);
74
75 if (PyType_Ready(&ConstantColorShader_Type) < 0) {
76 return -1;
77 }
78 PyModule_AddObjectRef(module, "ConstantColorShader", (PyObject *)&ConstantColorShader_Type);
79
80 if (PyType_Ready(&ConstantThicknessShader_Type) < 0) {
81 return -1;
82 }
83 PyModule_AddObjectRef(
84 module, "ConstantThicknessShader", (PyObject *)&ConstantThicknessShader_Type);
85
86 if (PyType_Ready(&ConstrainedIncreasingThicknessShader_Type) < 0) {
87 return -1;
88 }
89 PyModule_AddObjectRef(module,
90 "ConstrainedIncreasingThicknessShader",
92
93 if (PyType_Ready(&GuidingLinesShader_Type) < 0) {
94 return -1;
95 }
96 PyModule_AddObjectRef(module, "GuidingLinesShader", (PyObject *)&GuidingLinesShader_Type);
97
98 if (PyType_Ready(&IncreasingColorShader_Type) < 0) {
99 return -1;
100 }
101 PyModule_AddObjectRef(module, "IncreasingColorShader", (PyObject *)&IncreasingColorShader_Type);
102
103 if (PyType_Ready(&IncreasingThicknessShader_Type) < 0) {
104 return -1;
105 }
106 PyModule_AddObjectRef(
107 module, "IncreasingThicknessShader", (PyObject *)&IncreasingThicknessShader_Type);
108
109 if (PyType_Ready(&PolygonalizationShader_Type) < 0) {
110 return -1;
111 }
112 PyModule_AddObjectRef(
113 module, "PolygonalizationShader", (PyObject *)&PolygonalizationShader_Type);
114
115 if (PyType_Ready(&SamplingShader_Type) < 0) {
116 return -1;
117 }
118 PyModule_AddObjectRef(module, "SamplingShader", (PyObject *)&SamplingShader_Type);
119
120 if (PyType_Ready(&SmoothingShader_Type) < 0) {
121 return -1;
122 }
123 PyModule_AddObjectRef(module, "SmoothingShader", (PyObject *)&SmoothingShader_Type);
124
125 if (PyType_Ready(&SpatialNoiseShader_Type) < 0) {
126 return -1;
127 }
128 PyModule_AddObjectRef(module, "SpatialNoiseShader", (PyObject *)&SpatialNoiseShader_Type);
129
130 if (PyType_Ready(&StrokeTextureStepShader_Type) < 0) {
131 return -1;
132 }
133 PyModule_AddObjectRef(
134 module, "StrokeTextureStepShader", (PyObject *)&StrokeTextureStepShader_Type);
135
136 if (PyType_Ready(&ThicknessNoiseShader_Type) < 0) {
137 return -1;
138 }
139 PyModule_AddObjectRef(module, "ThicknessNoiseShader", (PyObject *)&ThicknessNoiseShader_Type);
140
141 if (PyType_Ready(&TipRemoverShader_Type) < 0) {
142 return -1;
143 }
144 PyModule_AddObjectRef(module, "TipRemoverShader", (PyObject *)&TipRemoverShader_Type);
145
146 return 0;
147}
148
149//------------------------INSTANCE METHODS ----------------------------------
150
152 /* Wrap. */
153 StrokeShader___doc__,
154 "Base class for stroke shaders. Any stroke shader must inherit from\n"
155 "this class and overload the shade() method. A StrokeShader is\n"
156 "designed to modify stroke attributes such as thickness, color,\n"
157 "geometry, texture, blending mode, and so on. The basic way for this\n"
158 "operation is to iterate over the stroke vertices of the :class:`Stroke`\n"
159 "and to modify the :class:`StrokeAttribute` of each vertex. Here is a\n"
160 "code example of such an iteration::\n"
161 "\n"
162 " it = ioStroke.strokeVerticesBegin()\n"
163 " while not it.is_end:\n"
164 " att = it.object.attribute\n"
165 " ## perform here any attribute modification\n"
166 " it.increment()\n"
167 "\n"
168 ".. method:: __init__()\n"
169 "\n"
170 " Default constructor.\n");
171
172static int StrokeShader___init__(BPy_StrokeShader *self, PyObject *args, PyObject *kwds)
173{
174 static const char *kwlist[] = {nullptr};
175
176 if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
177 return -1;
178 }
179 self->ss = new StrokeShader();
180 self->ss->py_ss = (PyObject *)self;
181 return 0;
182}
183
185{
186 delete self->ss;
187 Py_TYPE(self)->tp_free((PyObject *)self);
188}
189
191{
192 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->ss);
193}
194
196 /* Wrap. */
197 StrokeShader_shade___doc__,
198 ".. method:: shade(stroke)\n"
199 "\n"
200 " The shading method. Must be overloaded by inherited classes.\n"
201 "\n"
202 " :arg stroke: A Stroke object.\n"
203 " :type stroke: :class:`Stroke`\n");
204
205static PyObject *StrokeShader_shade(BPy_StrokeShader *self, PyObject *args, PyObject *kwds)
206{
207 static const char *kwlist[] = {"stroke", nullptr};
208 PyObject *py_s = nullptr;
209
210 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Stroke_Type, &py_s)) {
211 return nullptr;
212 }
213
214 if (typeid(*(self->ss)) == typeid(StrokeShader)) {
215 PyErr_SetString(PyExc_TypeError, "shade method not properly overridden");
216 return nullptr;
217 }
218 if (self->ss->shade(*(((BPy_Stroke *)py_s)->s)) < 0) {
219 if (!PyErr_Occurred()) {
220 string class_name(Py_TYPE(self)->tp_name);
221 PyErr_SetString(PyExc_RuntimeError, (class_name + " shade method failed").c_str());
222 }
223 return nullptr;
224 }
225 Py_RETURN_NONE;
226}
227
228#ifdef __GNUC__
229# ifdef __clang__
230# pragma clang diagnostic push
231# pragma clang diagnostic ignored "-Wcast-function-type"
232# else
233# pragma GCC diagnostic push
234# pragma GCC diagnostic ignored "-Wcast-function-type"
235# endif
236#endif
237
238static PyMethodDef BPy_StrokeShader_methods[] = {
239 {"shade",
240 (PyCFunction)StrokeShader_shade,
241 METH_VARARGS | METH_KEYWORDS,
242 StrokeShader_shade___doc__},
243 {nullptr, nullptr, 0, nullptr},
244};
245
246#ifdef __GNUC__
247# ifdef __clang__
248# pragma clang diagnostic pop
249# else
250# pragma GCC diagnostic pop
251# endif
252#endif
253
254/*----------------------StrokeShader get/setters ----------------------------*/
255
257 /* Wrap. */
258 StrokeShader_name_doc,
259 "The name of the stroke shader.\n"
260 "\n"
261 ":type: str");
262
263static PyObject *StrokeShader_name_get(BPy_StrokeShader *self, void * /*closure*/)
264{
265 return PyUnicode_FromString(Py_TYPE(self)->tp_name);
266}
267
268static PyGetSetDef BPy_StrokeShader_getseters[] = {
269 {"name", (getter)StrokeShader_name_get, (setter) nullptr, StrokeShader_name_doc, nullptr},
270 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
271};
272
273/*-----------------------BPy_StrokeShader type definition ------------------------------*/
274
275PyTypeObject StrokeShader_Type = {
276 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
277 /*tp_name*/ "StrokeShader",
278 /*tp_basicsize*/ sizeof(BPy_StrokeShader),
279 /*tp_itemsize*/ 0,
280 /*tp_dealloc*/ (destructor)StrokeShader___dealloc__,
281 /*tp_vectorcall_offset*/ 0,
282 /*tp_getattr*/ nullptr,
283 /*tp_setattr*/ nullptr,
284 /*tp_as_async*/ nullptr,
285 /*tp_repr*/ (reprfunc)StrokeShader___repr__,
286 /*tp_as_number*/ nullptr,
287 /*tp_as_sequence*/ nullptr,
288 /*tp_as_mapping*/ nullptr,
289 /*tp_hash*/ nullptr,
290 /*tp_call*/ nullptr,
291 /*tp_str*/ nullptr,
292 /*tp_getattro*/ nullptr,
293 /*tp_setattro*/ nullptr,
294 /*tp_as_buffer*/ nullptr,
295 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
296 /*tp_doc*/ StrokeShader___doc__,
297 /*tp_traverse*/ nullptr,
298 /*tp_clear*/ nullptr,
299 /*tp_richcompare*/ nullptr,
300 /*tp_weaklistoffset*/ 0,
301 /*tp_iter*/ nullptr,
302 /*tp_iternext*/ nullptr,
303 /*tp_methods*/ BPy_StrokeShader_methods,
304 /*tp_members*/ nullptr,
305 /*tp_getset*/ BPy_StrokeShader_getseters,
306 /*tp_base*/ nullptr,
307 /*tp_dict*/ nullptr,
308 /*tp_descr_get*/ nullptr,
309 /*tp_descr_set*/ nullptr,
310 /*tp_dictoffset*/ 0,
311 /*tp_init*/ (initproc)StrokeShader___init__,
312 /*tp_alloc*/ nullptr,
313 /*tp_new*/ PyType_GenericNew,
314};
315
PyTypeObject BackboneStretcherShader_Type
PyTypeObject BezierCurveShader_Type
PyTypeObject BlenderTextureShader_Type
PyTypeObject CalligraphicShader_Type
PyTypeObject ColorNoiseShader_Type
PyTypeObject ConstantColorShader_Type
PyTypeObject ConstantThicknessShader_Type
PyTypeObject ConstrainedIncreasingThicknessShader_Type
PyTypeObject GuidingLinesShader_Type
PyTypeObject IncreasingColorShader_Type
PyTypeObject IncreasingThicknessShader_Type
PyTypeObject PolygonalizationShader_Type
PyTypeObject SamplingShader_Type
PyTypeObject SmoothingShader_Type
PyTypeObject SpatialNoiseShader_Type
PyTypeObject StrokeShader_Type
static PyGetSetDef BPy_StrokeShader_getseters[]
static PyObject * StrokeShader___repr__(BPy_StrokeShader *self)
static int StrokeShader___init__(BPy_StrokeShader *self, PyObject *args, PyObject *kwds)
static PyObject * StrokeShader_name_get(BPy_StrokeShader *self, void *)
static PyObject * StrokeShader_shade(BPy_StrokeShader *self, PyObject *args, PyObject *kwds)
static void StrokeShader___dealloc__(BPy_StrokeShader *self)
int StrokeShader_Init(PyObject *module)
PyDoc_STRVAR(StrokeShader___doc__, "Base class for stroke shaders. Any stroke shader must inherit from\n" "this class and overload the shade() method. A StrokeShader is\n" "designed to modify stroke attributes such as thickness, color,\n" "geometry, texture, blending mode, and so on. The basic way for this\n" "operation is to iterate over the stroke vertices of the :class:`Stroke`\n" "and to modify the :class:`StrokeAttribute` of each vertex. Here is a\n" "code example of such an iteration::\n" "\n" " it = ioStroke.strokeVerticesBegin()\n" " while not it.is_end:\n" " att = it.object.attribute\n" " ## perform here any attribute modification\n" " it.increment()\n" "\n" ".. method:: __init__()\n" "\n" " Default constructor.\n")
static PyMethodDef BPy_StrokeShader_methods[]
PyTypeObject StrokeTextureStepShader_Type
PyTypeObject Stroke_Type
PyTypeObject ThicknessNoiseShader_Type
PyTypeObject TipRemoverShader_Type
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20
static struct PyModuleDef module
Definition python.cpp:796