Blender  V3.3
BPy_Chain.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BPy_Chain.h"
8 
9 #include "../../BPy_Convert.h"
10 #include "../../BPy_Id.h"
11 #include "../BPy_ViewEdge.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 using namespace Freestyle;
18 
20 
21 /*----------------------Chain methods ----------------------------*/
22 
23 PyDoc_STRVAR(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 
42 static 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  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 
70 PyDoc_STRVAR(Chain_push_viewedge_back_doc,
71  ".. method:: push_viewedge_back(viewedge, orientation)\n"
72  "\n"
73  " Adds a ViewEdge at the end of the Chain.\n"
74  "\n"
75  " :arg viewedge: The ViewEdge that must be added.\n"
76  " :type viewedge: :class:`ViewEdge`\n"
77  " :arg orientation: The orientation with which the ViewEdge must be\n"
78  " processed.\n"
79  " :type orientation: bool");
80 
81 static 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  return nullptr;
89  }
90  ViewEdge *ve = ((BPy_ViewEdge *)obj1)->ve;
91  bool orientation = bool_from_PyBool(obj2);
92  self->c->push_viewedge_back(ve, orientation);
93  Py_RETURN_NONE;
94 }
95 
96 PyDoc_STRVAR(Chain_push_viewedge_front_doc,
97  ".. method:: push_viewedge_front(viewedge, orientation)\n"
98  "\n"
99  " Adds a ViewEdge at the beginning of the Chain.\n"
100  "\n"
101  " :arg viewedge: The ViewEdge that must be added.\n"
102  " :type viewedge: :class:`ViewEdge`\n"
103  " :arg orientation: The orientation with which the ViewEdge must be\n"
104  " processed.\n"
105  " :type orientation: bool");
106 
107 static PyObject *Chain_push_viewedge_front(BPy_Chain *self, PyObject *args, PyObject *kwds)
108 {
109  static const char *kwlist[] = {"viewedge", "orientation", nullptr};
110  PyObject *obj1 = nullptr, *obj2 = nullptr;
111 
112  if (!PyArg_ParseTupleAndKeywords(
113  args, kwds, "O!O!", (char **)kwlist, &ViewEdge_Type, &obj1, &PyBool_Type, &obj2)) {
114  return nullptr;
115  }
116  ViewEdge *ve = ((BPy_ViewEdge *)obj1)->ve;
117  bool orientation = bool_from_PyBool(obj2);
118  self->c->push_viewedge_front(ve, orientation);
119  Py_RETURN_NONE;
120 }
121 
122 static PyMethodDef BPy_Chain_methods[] = {
123  {"push_viewedge_back",
124  (PyCFunction)Chain_push_viewedge_back,
125  METH_VARARGS | METH_KEYWORDS,
126  Chain_push_viewedge_back_doc},
127  {"push_viewedge_front",
128  (PyCFunction)Chain_push_viewedge_front,
129  METH_VARARGS | METH_KEYWORDS,
130  Chain_push_viewedge_front_doc},
131  {nullptr, nullptr, 0, nullptr},
132 };
133 
134 /*-----------------------BPy_Chain type definition ------------------------------*/
135 
136 PyTypeObject Chain_Type = {
137  PyVarObject_HEAD_INIT(nullptr, 0) "Chain", /* tp_name */
138  sizeof(BPy_Chain), /* tp_basicsize */
139  0, /* tp_itemsize */
140  nullptr, /* tp_dealloc */
141  0, /* tp_vectorcall_offset */
142  nullptr, /* tp_getattr */
143  nullptr, /* tp_setattr */
144  nullptr, /* tp_reserved */
145  nullptr, /* tp_repr */
146  nullptr, /* tp_as_number */
147  nullptr, /* tp_as_sequence */
148  nullptr, /* tp_as_mapping */
149  nullptr, /* tp_hash */
150  nullptr, /* tp_call */
151  nullptr, /* tp_str */
152  nullptr, /* tp_getattro */
153  nullptr, /* tp_setattro */
154  nullptr, /* tp_as_buffer */
155  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
156  Chain_doc, /* tp_doc */
157  nullptr, /* tp_traverse */
158  nullptr, /* tp_clear */
159  nullptr, /* tp_richcompare */
160  0, /* tp_weaklistoffset */
161  nullptr, /* tp_iter */
162  nullptr, /* tp_iternext */
163  BPy_Chain_methods, /* tp_methods */
164  nullptr, /* tp_members */
165  nullptr, /* tp_getset */
166  &FrsCurve_Type, /* tp_base */
167  nullptr, /* tp_dict */
168  nullptr, /* tp_descr_get */
169  nullptr, /* tp_descr_set */
170  0, /* tp_dictoffset */
171  (initproc)Chain_init, /* tp_init */
172  nullptr, /* tp_alloc */
173  nullptr, /* tp_new */
174 };
175 
177 
178 #ifdef __cplusplus
179 }
180 #endif
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`")
static PyObject * Chain_push_viewedge_back(BPy_Chain *self, PyObject *args, PyObject *kwds)
Definition: BPy_Chain.cpp:81
PyTypeObject Chain_Type
Definition: BPy_Chain.cpp:136
static PyMethodDef BPy_Chain_methods[]
Definition: BPy_Chain.cpp:122
static PyObject * Chain_push_viewedge_front(BPy_Chain *self, PyObject *args, PyObject *kwds)
Definition: BPy_Chain.cpp:107
static int Chain_init(BPy_Chain *self, PyObject *args, PyObject *kwds)
Definition: BPy_Chain.cpp:42
bool bool_from_PyBool(PyObject *b)
PyTypeObject FrsCurve_Type
PyTypeObject Id_Type
Definition: BPy_Id.cpp:157
PyTypeObject ViewEdge_Type
inherits from class Rep
Definition: AppCanvas.cpp:18
static unsigned c
Definition: RandGen.cpp:83
Definition: BPy_Id.h:28