9 #include "../BPy_Convert.h"
10 #include "../BPy_Id.h"
11 #include "../BPy_MediumType.h"
12 #include "../Interface0D/BPy_SVertex.h"
13 #include "../Interface0D/CurvePoint/BPy_StrokeVertex.h"
14 #include "../Iterator/BPy_StrokeVertexIterator.h"
33 "Class hierarchy: :class:`Interface1D` > :class:`Stroke`\n"
35 "Class to define a stroke. A stroke is made of a set of 2D vertices\n"
36 "(:class:`StrokeVertex`), regularly spaced out. This set of vertices\n"
37 "defines the stroke's backbone geometry. Each of these stroke vertices\n"
38 "defines the stroke's shape and appearance at this vertex position.\n"
40 ".. method:: Stroke()\n"
43 " Creates a :class:`Stroke` using the default constructor or copy constructor\n");
47 static const char *kwlist[] = {
"brother",
nullptr};
48 PyObject *brother =
nullptr;
50 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|O!", (
char **)kwlist, &
Stroke_Type, &brother)) {
59 self->py_if1D.if1D =
self->s;
60 self->py_if1D.borrowed =
false;
72 return self->s->strokeVerticesSize();
81 PyErr_Format(PyExc_IndexError,
"Stroke[index]: index %d out of range", keynum);
88 ".. method:: compute_sampling(n)\n"
90 " Compute the sampling needed to get N vertices. If the\n"
91 " specified number of vertices is less than the actual number of\n"
92 " vertices, the actual sampling value is returned. (To remove Vertices,\n"
93 " use the RemoveVertex() method of this class.)\n"
95 " :arg n: The number of stroke vertices we eventually want\n"
98 " :return: The sampling that must be used in the Resample(float)\n"
104 static const char *kwlist[] = {
"n",
nullptr};
107 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"i", (
char **)kwlist, &i)) {
110 return PyFloat_FromDouble(
self->s->ComputeSampling(i));
114 ".. method:: resample(n)\n"
115 " resample(sampling)\n"
117 " Resamples the stroke so using one of two methods with the goal\n"
118 " of creating a stroke with fewer points and the same shape.\n"
120 " :arg n: Resamples the stroke so that it eventually has N points. That means\n"
121 " it is going to add N-vertices_size, where vertices_size is the\n"
122 " number of points we already have. If vertices_size >= N, no\n"
123 " resampling is done.\n"
125 " :arg sampling: Resamples the stroke with a given sampling value. If the\n"
126 " sampling is smaller than the actual sampling value, no resampling is done.\n"
127 " :type sampling: float");
131 static const char *kwlist_1[] = {
"n",
nullptr};
132 static const char *kwlist_2[] = {
"sampling",
nullptr};
136 if (PyArg_ParseTupleAndKeywords(args, kwds,
"i", (
char **)kwlist_1, &i)) {
137 if (
self->s->Resample(i) < 0) {
138 PyErr_SetString(PyExc_RuntimeError,
"Stroke resampling (by vertex count) failed");
142 else if ((
void)PyErr_Clear(),
143 PyArg_ParseTupleAndKeywords(args, kwds,
"f", (
char **)kwlist_2, &f)) {
144 if (
self->s->Resample(f) < 0) {
145 PyErr_SetString(PyExc_RuntimeError,
"Stroke resampling (by vertex interval) failed");
150 PyErr_SetString(PyExc_TypeError,
"invalid argument");
157 ".. method:: insert_vertex(vertex, next)\n"
159 " Inserts the StrokeVertex given as argument into the Stroke before the\n"
160 " point specified by next. The length and curvilinear abscissa are\n"
161 " updated consequently.\n"
163 " :arg vertex: The StrokeVertex to insert in the Stroke.\n"
164 " :type vertex: :class:`StrokeVertex`\n"
165 " :arg next: A StrokeVertexIterator pointing to the StrokeVertex\n"
166 " before which vertex must be inserted.\n"
167 " :type next: :class:`StrokeVertexIterator`");
171 static const char *kwlist[] = {
"vertex",
"next",
nullptr};
172 PyObject *py_sv =
nullptr, *py_sv_it =
nullptr;
174 if (!PyArg_ParseTupleAndKeywords(args,
190 self->s->InsertVertex(sv, sv_it);
195 ".. method:: remove_vertex(vertex)\n"
197 " Removes the StrokeVertex given as argument from the Stroke. The length\n"
198 " and curvilinear abscissa are updated consequently.\n"
200 " :arg vertex: the StrokeVertex to remove from the Stroke.\n"
201 " :type vertex: :class:`StrokeVertex`");
205 static const char *kwlist[] = {
"vertex",
nullptr};
206 PyObject *py_sv =
nullptr;
208 if (!PyArg_ParseTupleAndKeywords(
216 PyErr_SetString(PyExc_TypeError,
"invalid argument");
223 ".. method:: remove_all_vertices()\n"
225 " Removes all vertices from the Stroke.");
229 self->s->RemoveAllVertices();
234 ".. method:: update_length()\n"
236 " Updates the 2D length of the Stroke.");
240 self->s->UpdateLength();
245 ".. method:: stroke_vertices_begin(t=0.0)\n"
247 " Returns a StrokeVertexIterator pointing on the first StrokeVertex of\n"
248 " the Stroke. One can specify a sampling value to re-sample the Stroke\n"
249 " on the fly if needed.\n"
251 " :arg t: The resampling value with which we want our Stroke to be\n"
252 " resampled. If 0 is specified, no resampling is done.\n"
254 " :return: A StrokeVertexIterator pointing on the first StrokeVertex.\n"
255 " :rtype: :class:`StrokeVertexIterator`");
259 static const char *kwlist[] = {
"t",
nullptr};
262 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|f", (
char **)kwlist, &f)) {
270 ".. method:: stroke_vertices_end()\n"
272 " Returns a StrokeVertexIterator pointing after the last StrokeVertex\n"
275 " :return: A StrokeVertexIterator pointing after the last StrokeVertex.\n"
276 " :rtype: :class:`StrokeVertexIterator`");
285 ".. method:: __reversed__()\n"
287 " Returns a StrokeVertexIterator iterating over the vertices of the Stroke\n"
288 " in the reversed order (from the last to the first).\n"
290 " :return: A StrokeVertexIterator pointing after the last StrokeVertex.\n"
291 " :rtype: :class:`StrokeVertexIterator`");
300 ".. method:: stroke_vertices_size()\n"
302 " Returns the number of StrokeVertex constituting the Stroke.\n"
304 " :return: The number of stroke vertices.\n"
309 return PyLong_FromLong(
self->s->strokeVerticesSize());
315 METH_VARARGS | METH_KEYWORDS,
316 Stroke_compute_sampling_doc},
317 {
"resample", (PyCFunction)
Stroke_resample, METH_VARARGS | METH_KEYWORDS, Stroke_resample_doc},
318 {
"remove_all_vertices",
321 Stroke_remove_all_vertices_doc},
324 METH_VARARGS | METH_KEYWORDS,
325 Stroke_remove_vertex_doc},
328 METH_VARARGS | METH_KEYWORDS,
329 Stroke_insert_vertex_doc},
331 {
"stroke_vertices_begin",
333 METH_VARARGS | METH_KEYWORDS,
334 Stroke_stroke_vertices_begin_doc},
335 {
"stroke_vertices_end",
338 Stroke_stroke_vertices_end_doc},
339 {
"__reversed__", (PyCFunction)
Stroke_reversed, METH_NOARGS, Stroke_reversed_doc},
340 {
"stroke_vertices_size",
343 Stroke_stroke_vertices_size_doc},
344 {
nullptr,
nullptr, 0,
nullptr},
350 "The MediumType used for this Stroke.\n"
352 ":type: :class:`MediumType`");
362 PyErr_SetString(PyExc_TypeError,
"value must be a MediumType");
370 "The ID of the texture used to simulate th marks system for this Stroke.\n"
376 return PyLong_FromLong(
self->s->getTextureId());
381 unsigned int i = PyLong_AsUnsignedLong(value);
382 if (PyErr_Occurred()) {
385 self->s->setTextureId(i);
390 "True if this Stroke uses a texture with tips, and false otherwise.\n"
401 if (!PyBool_Check(value)) {
409 "The 2D length of the Stroke.\n"
415 return PyFloat_FromDouble(
self->s->getLength2D());
421 if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) {
423 PyErr_SetString(PyExc_TypeError,
"value must be a number");
426 self->s->setLength(scalar);
431 "The Id of this Stroke.\n"
433 ":type: :class:`Id`");
444 PyErr_SetString(PyExc_TypeError,
"value must be an Id");
447 self->s->setId(*(((
BPy_Id *)value)->
id));
455 Stroke_medium_type_doc,
460 Stroke_texture_id_doc,
466 Stroke_length_2d_doc,
469 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}
488 PyVarObject_HEAD_INIT(
nullptr, 0)
"Stroke",
506 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
PyObject * BPy_MediumType_from_MediumType(Stroke::MediumType n)
PyObject * PyBool_from_bool(bool b)
bool bool_from_PyBool(PyObject *b)
PyObject * BPy_StrokeVertex_from_StrokeVertex(StrokeVertex &sv)
PyObject * BPy_Id_from_Id(Id &id)
Stroke::MediumType MediumType_from_BPy_MediumType(PyObject *obj)
PyObject * BPy_StrokeVertexIterator_from_StrokeVertexIterator(StrokeInternal::StrokeVertexIterator &sv_it, bool reversed)
PyTypeObject Interface1D_Type
#define BPy_MediumType_Check(v)
PyTypeObject StrokeVertexIterator_Type
PyTypeObject StrokeVertex_Type
static PyObject * Stroke_medium_type_get(BPy_Stroke *self, void *UNUSED(closure))
PyDoc_STRVAR(Stroke_doc, "Class hierarchy: :class:`Interface1D` > :class:`Stroke`\n" "\n" "Class to define a stroke. A stroke is made of a set of 2D vertices\n" "(:class:`StrokeVertex`), regularly spaced out. This set of vertices\n" "defines the stroke's backbone geometry. Each of these stroke vertices\n" "defines the stroke's shape and appearance at this vertex position.\n" "\n" ".. method:: Stroke()\n" " Stroke(brother)\n" "\n" " Creates a :class:`Stroke` using the default constructor or copy constructor\n")
static Py_ssize_t Stroke_sq_length(BPy_Stroke *self)
static PyObject * Stroke_remove_vertex(BPy_Stroke *self, PyObject *args, PyObject *kwds)
static int Stroke_id_set(BPy_Stroke *self, PyObject *value, void *UNUSED(closure))
static PyObject * Stroke_sq_item(BPy_Stroke *self, int keynum)
static int Stroke_medium_type_set(BPy_Stroke *self, PyObject *value, void *UNUSED(closure))
static PyObject * Stroke_reversed(BPy_Stroke *self)
static PySequenceMethods BPy_Stroke_as_sequence
static PyObject * Stroke_stroke_vertices_begin(BPy_Stroke *self, PyObject *args, PyObject *kwds)
static PyMethodDef BPy_Stroke_methods[]
static PyObject * Stroke_iter(PyObject *self)
static PyObject * Stroke_stroke_vertices_size(BPy_Stroke *self)
static PyObject * Stroke_stroke_vertices_end(BPy_Stroke *self)
static PyObject * Stroke_length_2d_get(BPy_Stroke *self, void *UNUSED(closure))
static PyObject * Stroke_remove_all_vertices(BPy_Stroke *self)
static PyObject * Stroke_resample(BPy_Stroke *self, PyObject *args, PyObject *kwds)
static PyObject * Stroke_texture_id_get(BPy_Stroke *self, void *UNUSED(closure))
static int Stroke_tips_set(BPy_Stroke *self, PyObject *value, void *UNUSED(closure))
static PyObject * Stroke_update_length(BPy_Stroke *self)
static int Stroke_length_2d_set(BPy_Stroke *self, PyObject *value, void *UNUSED(closure))
static int Stroke_init(BPy_Stroke *self, PyObject *args, PyObject *kwds)
static PyObject * Stroke_compute_sampling(BPy_Stroke *self, PyObject *args, PyObject *kwds)
static PyGetSetDef BPy_Stroke_getseters[]
static PyObject * Stroke_tips_get(BPy_Stroke *self, void *UNUSED(closure))
static PyObject * Stroke_insert_vertex(BPy_Stroke *self, PyObject *args, PyObject *kwds)
static PyObject * Stroke_id_get(BPy_Stroke *self, void *UNUSED(closure))
static int Stroke_texture_id_set(BPy_Stroke *self, PyObject *value, void *UNUSED(closure))