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