Blender V5.0
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");
171static int StrokeShader___init__(BPy_StrokeShader *self, PyObject *args, PyObject *kwds)
172{
173 static const char *kwlist[] = {nullptr};
174
175 if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
176 return -1;
177 }
178 self->ss = new StrokeShader();
179 self->ss->py_ss = (PyObject *)self;
180 return 0;
181}
182
184{
185 delete self->ss;
186 Py_TYPE(self)->tp_free((PyObject *)self);
187}
188
190{
191 return PyUnicode_FromFormat("type: %s - address: %p", Py_TYPE(self)->tp_name, self->ss);
192}
193
195 /* Wrap. */
196 StrokeShader_shade___doc__,
197 ".. method:: shade(stroke)\n"
198 "\n"
199 " The shading method. Must be overloaded by inherited classes.\n"
200 "\n"
201 " :arg stroke: A Stroke object.\n"
202 " :type stroke: :class:`Stroke`\n");
203static PyObject *StrokeShader_shade(BPy_StrokeShader *self, PyObject *args, PyObject *kwds)
204{
205 static const char *kwlist[] = {"stroke", nullptr};
206 PyObject *py_s = nullptr;
207
208 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &Stroke_Type, &py_s)) {
209 return nullptr;
210 }
211
212 if (typeid(*(self->ss)) == typeid(StrokeShader)) {
213 PyErr_SetString(PyExc_TypeError, "shade method not properly overridden");
214 return nullptr;
215 }
216 if (self->ss->shade(*(((BPy_Stroke *)py_s)->s)) < 0) {
217 if (!PyErr_Occurred()) {
218 string class_name(Py_TYPE(self)->tp_name);
219 PyErr_SetString(PyExc_RuntimeError, (class_name + " shade method failed").c_str());
220 }
221 return nullptr;
222 }
223 Py_RETURN_NONE;
224}
225
226#ifdef __GNUC__
227# ifdef __clang__
228# pragma clang diagnostic push
229# pragma clang diagnostic ignored "-Wcast-function-type"
230# else
231# pragma GCC diagnostic push
232# pragma GCC diagnostic ignored "-Wcast-function-type"
233# endif
234#endif
235
236static PyMethodDef BPy_StrokeShader_methods[] = {
237 {"shade",
238 (PyCFunction)StrokeShader_shade,
239 METH_VARARGS | METH_KEYWORDS,
240 StrokeShader_shade___doc__},
241 {nullptr, nullptr, 0, nullptr},
242};
243
244#ifdef __GNUC__
245# ifdef __clang__
246# pragma clang diagnostic pop
247# else
248# pragma GCC diagnostic pop
249# endif
250#endif
251
252/*----------------------StrokeShader get/setters ----------------------------*/
253
255 /* Wrap. */
256 StrokeShader_name_doc,
257 "The name of the stroke shader.\n"
258 "\n"
259 ":type: str\n");
260static PyObject *StrokeShader_name_get(BPy_StrokeShader *self, void * /*closure*/)
261{
262 return PyUnicode_FromString(Py_TYPE(self)->tp_name);
263}
264
265static PyGetSetDef BPy_StrokeShader_getseters[] = {
266 {"name", (getter)StrokeShader_name_get, (setter) nullptr, StrokeShader_name_doc, nullptr},
267 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
268};
269
270/*-----------------------BPy_StrokeShader type definition ------------------------------*/
271
272PyTypeObject StrokeShader_Type = {
273 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
274 /*tp_name*/ "StrokeShader",
275 /*tp_basicsize*/ sizeof(BPy_StrokeShader),
276 /*tp_itemsize*/ 0,
277 /*tp_dealloc*/ (destructor)StrokeShader___dealloc__,
278 /*tp_vectorcall_offset*/ 0,
279 /*tp_getattr*/ nullptr,
280 /*tp_setattr*/ nullptr,
281 /*tp_as_async*/ nullptr,
282 /*tp_repr*/ (reprfunc)StrokeShader___repr__,
283 /*tp_as_number*/ nullptr,
284 /*tp_as_sequence*/ nullptr,
285 /*tp_as_mapping*/ nullptr,
286 /*tp_hash*/ nullptr,
287 /*tp_call*/ nullptr,
288 /*tp_str*/ nullptr,
289 /*tp_getattro*/ nullptr,
290 /*tp_setattro*/ nullptr,
291 /*tp_as_buffer*/ nullptr,
292 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
293 /*tp_doc*/ StrokeShader___doc__,
294 /*tp_traverse*/ nullptr,
295 /*tp_clear*/ nullptr,
296 /*tp_richcompare*/ nullptr,
297 /*tp_weaklistoffset*/ 0,
298 /*tp_iter*/ nullptr,
299 /*tp_iternext*/ nullptr,
300 /*tp_methods*/ BPy_StrokeShader_methods,
301 /*tp_members*/ nullptr,
302 /*tp_getset*/ BPy_StrokeShader_getseters,
303 /*tp_base*/ nullptr,
304 /*tp_dict*/ nullptr,
305 /*tp_descr_get*/ nullptr,
306 /*tp_descr_set*/ nullptr,
307 /*tp_dictoffset*/ 0,
308 /*tp_init*/ (initproc)StrokeShader___init__,
309 /*tp_alloc*/ nullptr,
310 /*tp_new*/ PyType_GenericNew,
311};
312
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