Blender V4.5
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`");
41
42static int Chain_init(BPy_Chain *self, PyObject *args, PyObject *kwds)
43{
44 static const char *kwlist_1[] = {"brother", nullptr};
45 static const char *kwlist_2[] = {"id", nullptr};
46 PyObject *obj = nullptr;
47
48 if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &Chain_Type, &obj)) {
49 if (!obj) {
50 self->c = new Chain();
51 }
52 else {
53 self->c = new Chain(*(((BPy_Chain *)obj)->c));
54 }
55 }
56 else if ((void)PyErr_Clear(),
57 PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Id_Type, &obj))
58 {
59 self->c = new Chain(*(((BPy_Id *)obj)->id));
60 }
61 else {
62 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
63 return -1;
64 }
65 self->py_c.c = self->c;
66 self->py_c.py_if1D.if1D = self->c;
67 self->py_c.py_if1D.borrowed = false;
68 return 0;
69}
70
72 /* Wrap. */
73 Chain_push_viewedge_back_doc,
74 ".. method:: push_viewedge_back(viewedge, orientation)\n"
75 "\n"
76 " Adds a ViewEdge at the end of the Chain.\n"
77 "\n"
78 " :arg viewedge: The ViewEdge that must be added.\n"
79 " :type viewedge: :class:`ViewEdge`\n"
80 " :arg orientation: The orientation with which the ViewEdge must be\n"
81 " processed.\n"
82 " :type orientation: bool");
83
84static PyObject *Chain_push_viewedge_back(BPy_Chain *self, PyObject *args, PyObject *kwds)
85{
86 static const char *kwlist[] = {"viewedge", "orientation", nullptr};
87 PyObject *obj1 = nullptr, *obj2 = nullptr;
88
89 if (!PyArg_ParseTupleAndKeywords(
90 args, kwds, "O!O!", (char **)kwlist, &ViewEdge_Type, &obj1, &PyBool_Type, &obj2))
91 {
92 return nullptr;
93 }
94 ViewEdge *ve = ((BPy_ViewEdge *)obj1)->ve;
95 bool orientation = bool_from_PyBool(obj2);
96 self->c->push_viewedge_back(ve, orientation);
97 Py_RETURN_NONE;
98}
99
101 /* Wrap. */
102 Chain_push_viewedge_front_doc,
103 ".. method:: push_viewedge_front(viewedge, orientation)\n"
104 "\n"
105 " Adds a ViewEdge at the beginning of the Chain.\n"
106 "\n"
107 " :arg viewedge: The ViewEdge that must be added.\n"
108 " :type viewedge: :class:`ViewEdge`\n"
109 " :arg orientation: The orientation with which the ViewEdge must be\n"
110 " processed.\n"
111 " :type orientation: bool");
112
113static PyObject *Chain_push_viewedge_front(BPy_Chain *self, PyObject *args, PyObject *kwds)
114{
115 static const char *kwlist[] = {"viewedge", "orientation", nullptr};
116 PyObject *obj1 = nullptr, *obj2 = nullptr;
117
118 if (!PyArg_ParseTupleAndKeywords(
119 args, kwds, "O!O!", (char **)kwlist, &ViewEdge_Type, &obj1, &PyBool_Type, &obj2))
120 {
121 return nullptr;
122 }
123 ViewEdge *ve = ((BPy_ViewEdge *)obj1)->ve;
124 bool orientation = bool_from_PyBool(obj2);
125 self->c->push_viewedge_front(ve, orientation);
126 Py_RETURN_NONE;
127}
128
129#ifdef __GNUC__
130# ifdef __clang__
131# pragma clang diagnostic push
132# pragma clang diagnostic ignored "-Wcast-function-type"
133# else
134# pragma GCC diagnostic push
135# pragma GCC diagnostic ignored "-Wcast-function-type"
136# endif
137#endif
138
139static PyMethodDef BPy_Chain_methods[] = {
140 {"push_viewedge_back",
141 (PyCFunction)Chain_push_viewedge_back,
142 METH_VARARGS | METH_KEYWORDS,
143 Chain_push_viewedge_back_doc},
144 {"push_viewedge_front",
145 (PyCFunction)Chain_push_viewedge_front,
146 METH_VARARGS | METH_KEYWORDS,
147 Chain_push_viewedge_front_doc},
148 {nullptr, nullptr, 0, nullptr},
149};
150
151#ifdef __GNUC__
152# ifdef __clang__
153# pragma clang diagnostic pop
154# else
155# pragma GCC diagnostic pop
156# endif
157#endif
158
159/*-----------------------BPy_Chain type definition ------------------------------*/
160
161PyTypeObject Chain_Type = {
162 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
163 /*tp_name*/ "Chain",
164 /*tp_basicsize*/ sizeof(BPy_Chain),
165 /*tp_itemsize*/ 0,
166 /*tp_dealloc*/ nullptr,
167 /*tp_vectorcall_offset*/ 0,
168 /*tp_getattr*/ nullptr,
169 /*tp_setattr*/ nullptr,
170 /*tp_as_async*/ nullptr,
171 /*tp_repr*/ nullptr,
172 /*tp_as_number*/ nullptr,
173 /*tp_as_sequence*/ nullptr,
174 /*tp_as_mapping*/ nullptr,
175 /*tp_hash*/ nullptr,
176 /*tp_call*/ nullptr,
177 /*tp_str*/ nullptr,
178 /*tp_getattro*/ nullptr,
179 /*tp_setattro*/ nullptr,
180 /*tp_as_buffer*/ nullptr,
181 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
182 /*tp_doc*/ Chain_doc,
183 /*tp_traverse*/ nullptr,
184 /*tp_clear*/ nullptr,
185 /*tp_richcompare*/ nullptr,
186 /*tp_weaklistoffset*/ 0,
187 /*tp_iter*/ nullptr,
188 /*tp_iternext*/ nullptr,
189 /*tp_methods*/ BPy_Chain_methods,
190 /*tp_members*/ nullptr,
191 /*tp_getset*/ nullptr,
192 /*tp_base*/ &FrsCurve_Type,
193 /*tp_dict*/ nullptr,
194 /*tp_descr_get*/ nullptr,
195 /*tp_descr_set*/ nullptr,
196 /*tp_dictoffset*/ 0,
197 /*tp_init*/ (initproc)Chain_init,
198 /*tp_alloc*/ nullptr,
199 /*tp_new*/ nullptr,
200};
201
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`")
PyTypeObject Chain_Type
static PyMethodDef BPy_Chain_methods[]
static int Chain_init(BPy_Chain *self, PyObject *args, PyObject *kwds)
Definition BPy_Chain.cpp:42
static PyObject * Chain_push_viewedge_back(BPy_Chain *self, PyObject *args, PyObject *kwds)
Definition BPy_Chain.cpp:84
bool bool_from_PyBool(PyObject *b)
PyTypeObject FrsCurve_Type
PyTypeObject Id_Type
Definition BPy_Id.cpp:160
PyTypeObject ViewEdge_Type
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20
static uint c
Definition RandGen.cpp:87