Blender V5.0
BPy_Chain.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BPy_Chain.h"
10
11#include "../../BPy_Convert.h"
12#include "../../BPy_Id.h"
13#include "../BPy_ViewEdge.h"
14
15using namespace Freestyle;
16
18
19/*----------------------Chain methods ----------------------------*/
20
22 /* Wrap. */
23 Chain_doc,
24 "Class hierarchy: :class:`Interface1D` > :class:`Curve` > :class:`Chain`\n"
25 "\n"
26 "Class to represent a 1D elements issued from the chaining process. A\n"
27 "Chain is the last step before the :class:`Stroke` and is used in the\n"
28 "Splitting and Creation processes.\n"
29 "\n"
30 ".. method:: __init__()\n"
31 " __init__(brother)\n"
32 " __init__(id)\n"
33 "\n"
34 " Builds a :class:`Chain` using the default constructor,\n"
35 " copy constructor or from an :class:`Id`.\n"
36 "\n"
37 " :arg brother: A Chain object.\n"
38 " :type brother: :class:`Chain`\n"
39 " :arg id: An Id object.\n"
40 " :type id: :class:`Id`\n");
41static int Chain_init(BPy_Chain *self, PyObject *args, PyObject *kwds)
42{
43 static const char *kwlist_1[] = {"brother", nullptr};
44 static const char *kwlist_2[] = {"id", nullptr};
45 PyObject *obj = nullptr;
46
47 if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &Chain_Type, &obj)) {
48 if (!obj) {
49 self->c = new Chain();
50 }
51 else {
52 self->c = new Chain(*(((BPy_Chain *)obj)->c));
53 }
54 }
55 else if ((void)PyErr_Clear(),
56 PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Id_Type, &obj))
57 {
58 self->c = new Chain(*(((BPy_Id *)obj)->id));
59 }
60 else {
61 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
62 return -1;
63 }
64 self->py_c.c = self->c;
65 self->py_c.py_if1D.if1D = self->c;
66 self->py_c.py_if1D.borrowed = false;
67 return 0;
68}
69
71 /* Wrap. */
72 Chain_push_viewedge_back_doc,
73 ".. method:: push_viewedge_back(viewedge, orientation)\n"
74 "\n"
75 " Adds a ViewEdge at the end of the Chain.\n"
76 "\n"
77 " :arg viewedge: The ViewEdge that must be added.\n"
78 " :type viewedge: :class:`ViewEdge`\n"
79 " :arg orientation: The orientation with which the ViewEdge must be processed.\n"
80 " :type orientation: bool\n");
81static PyObject *Chain_push_viewedge_back(BPy_Chain *self, PyObject *args, PyObject *kwds)
82{
83 static const char *kwlist[] = {"viewedge", "orientation", nullptr};
84 PyObject *obj1 = nullptr, *obj2 = nullptr;
85
86 if (!PyArg_ParseTupleAndKeywords(
87 args, kwds, "O!O!", (char **)kwlist, &ViewEdge_Type, &obj1, &PyBool_Type, &obj2))
88 {
89 return nullptr;
90 }
91 ViewEdge *ve = ((BPy_ViewEdge *)obj1)->ve;
92 bool orientation = bool_from_PyBool(obj2);
93 self->c->push_viewedge_back(ve, orientation);
94 Py_RETURN_NONE;
95}
96
98 /* Wrap. */
99 Chain_push_viewedge_front_doc,
100 ".. method:: push_viewedge_front(viewedge, orientation)\n"
101 "\n"
102 " Adds a ViewEdge at the beginning of the Chain.\n"
103 "\n"
104 " :arg viewedge: The ViewEdge that must be added.\n"
105 " :type viewedge: :class:`ViewEdge`\n"
106 " :arg orientation: The orientation with which the ViewEdge must be\n"
107 " processed.\n"
108 " :type orientation: bool\n");
109static PyObject *Chain_push_viewedge_front(BPy_Chain *self, PyObject *args, PyObject *kwds)
110{
111 static const char *kwlist[] = {"viewedge", "orientation", nullptr};
112 PyObject *obj1 = nullptr, *obj2 = nullptr;
113
114 if (!PyArg_ParseTupleAndKeywords(
115 args, kwds, "O!O!", (char **)kwlist, &ViewEdge_Type, &obj1, &PyBool_Type, &obj2))
116 {
117 return nullptr;
118 }
119 ViewEdge *ve = ((BPy_ViewEdge *)obj1)->ve;
120 bool orientation = bool_from_PyBool(obj2);
121 self->c->push_viewedge_front(ve, orientation);
122 Py_RETURN_NONE;
123}
124
125#ifdef __GNUC__
126# ifdef __clang__
127# pragma clang diagnostic push
128# pragma clang diagnostic ignored "-Wcast-function-type"
129# else
130# pragma GCC diagnostic push
131# pragma GCC diagnostic ignored "-Wcast-function-type"
132# endif
133#endif
134
135static PyMethodDef BPy_Chain_methods[] = {
136 {"push_viewedge_back",
137 (PyCFunction)Chain_push_viewedge_back,
138 METH_VARARGS | METH_KEYWORDS,
139 Chain_push_viewedge_back_doc},
140 {"push_viewedge_front",
141 (PyCFunction)Chain_push_viewedge_front,
142 METH_VARARGS | METH_KEYWORDS,
143 Chain_push_viewedge_front_doc},
144 {nullptr, nullptr, 0, nullptr},
145};
146
147#ifdef __GNUC__
148# ifdef __clang__
149# pragma clang diagnostic pop
150# else
151# pragma GCC diagnostic pop
152# endif
153#endif
154
155/*-----------------------BPy_Chain type definition ------------------------------*/
156
157PyTypeObject Chain_Type = {
158 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
159 /*tp_name*/ "Chain",
160 /*tp_basicsize*/ sizeof(BPy_Chain),
161 /*tp_itemsize*/ 0,
162 /*tp_dealloc*/ nullptr,
163 /*tp_vectorcall_offset*/ 0,
164 /*tp_getattr*/ nullptr,
165 /*tp_setattr*/ nullptr,
166 /*tp_as_async*/ nullptr,
167 /*tp_repr*/ nullptr,
168 /*tp_as_number*/ nullptr,
169 /*tp_as_sequence*/ nullptr,
170 /*tp_as_mapping*/ nullptr,
171 /*tp_hash*/ nullptr,
172 /*tp_call*/ nullptr,
173 /*tp_str*/ nullptr,
174 /*tp_getattro*/ nullptr,
175 /*tp_setattro*/ nullptr,
176 /*tp_as_buffer*/ nullptr,
177 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
178 /*tp_doc*/ Chain_doc,
179 /*tp_traverse*/ nullptr,
180 /*tp_clear*/ nullptr,
181 /*tp_richcompare*/ nullptr,
182 /*tp_weaklistoffset*/ 0,
183 /*tp_iter*/ nullptr,
184 /*tp_iternext*/ nullptr,
185 /*tp_methods*/ BPy_Chain_methods,
186 /*tp_members*/ nullptr,
187 /*tp_getset*/ nullptr,
188 /*tp_base*/ &FrsCurve_Type,
189 /*tp_dict*/ nullptr,
190 /*tp_descr_get*/ nullptr,
191 /*tp_descr_set*/ nullptr,
192 /*tp_dictoffset*/ 0,
193 /*tp_init*/ (initproc)Chain_init,
194 /*tp_alloc*/ nullptr,
195 /*tp_new*/ nullptr,
196};
197
static PyObject * Chain_push_viewedge_front(BPy_Chain *self, PyObject *args, PyObject *kwds)
PyDoc_STRVAR(Chain_doc, "Class hierarchy: :class:`Interface1D` > :class:`Curve` > :class:`Chain`\n" "\n" "Class to represent a 1D elements issued from the chaining process. A\n" "Chain is the last step before the :class:`Stroke` and is used in the\n" "Splitting and Creation processes.\n" "\n" ".. method:: __init__()\n" " __init__(brother)\n" " __init__(id)\n" "\n" " Builds a :class:`Chain` using the default constructor,\n" " copy constructor or from an :class:`Id`.\n" "\n" " :arg brother: A Chain object.\n" " :type brother: :class:`Chain`\n" " :arg id: An Id object.\n" " :type id: :class:`Id`\n")
PyTypeObject Chain_Type
static PyMethodDef BPy_Chain_methods[]
static int Chain_init(BPy_Chain *self, PyObject *args, PyObject *kwds)
Definition BPy_Chain.cpp:41
static PyObject * Chain_push_viewedge_back(BPy_Chain *self, PyObject *args, PyObject *kwds)
Definition BPy_Chain.cpp:81
bool bool_from_PyBool(PyObject *b)
PyTypeObject FrsCurve_Type
PyTypeObject Id_Type
Definition BPy_Id.cpp:157
PyTypeObject ViewEdge_Type
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20
static uint c
Definition RandGen.cpp:87