Blender  V2.93
BPy_Chain.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BPy_Chain.h"
22 
23 #include "../../BPy_Convert.h"
24 #include "../../BPy_Id.h"
25 #include "../BPy_ViewEdge.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 using namespace Freestyle;
32 
34 
35 /*----------------------Chain methods ----------------------------*/
36 
37 PyDoc_STRVAR(Chain_doc,
38  "Class hierarchy: :class:`Interface1D` > :class:`Curve` > :class:`Chain`\n"
39  "\n"
40  "Class to represent a 1D elements issued from the chaining process. A\n"
41  "Chain is the last step before the :class:`Stroke` and is used in the\n"
42  "Splitting and Creation processes.\n"
43  "\n"
44  ".. method:: __init__()\n"
45  " __init__(brother)\n"
46  " __init__(id)\n"
47  "\n"
48  " Builds a :class:`Chain` using the default constructor,\n"
49  " copy constructor or from an :class:`Id`.\n"
50  "\n"
51  " :arg brother: A Chain object.\n"
52  " :type brother: :class:`Chain`\n"
53  " :arg id: An Id object.\n"
54  " :type id: :class:`Id`");
55 
56 static int Chain_init(BPy_Chain *self, PyObject *args, PyObject *kwds)
57 {
58  static const char *kwlist_1[] = {"brother", nullptr};
59  static const char *kwlist_2[] = {"id", nullptr};
60  PyObject *obj = nullptr;
61 
62  if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &Chain_Type, &obj)) {
63  if (!obj) {
64  self->c = new Chain();
65  }
66  else {
67  self->c = new Chain(*(((BPy_Chain *)obj)->c));
68  }
69  }
70  else if ((void)PyErr_Clear(),
71  PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Id_Type, &obj)) {
72  self->c = new Chain(*(((BPy_Id *)obj)->id));
73  }
74  else {
75  PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
76  return -1;
77  }
78  self->py_c.c = self->c;
79  self->py_c.py_if1D.if1D = self->c;
80  self->py_c.py_if1D.borrowed = false;
81  return 0;
82 }
83 
84 PyDoc_STRVAR(Chain_push_viewedge_back_doc,
85  ".. method:: push_viewedge_back(viewedge, orientation)\n"
86  "\n"
87  " Adds a ViewEdge at the end of the Chain.\n"
88  "\n"
89  " :arg viewedge: The ViewEdge that must be added.\n"
90  " :type viewedge: :class:`ViewEdge`\n"
91  " :arg orientation: The orientation with which the ViewEdge must be\n"
92  " processed.\n"
93  " :type orientation: bool");
94 
95 static PyObject *Chain_push_viewedge_back(BPy_Chain *self, PyObject *args, PyObject *kwds)
96 {
97  static const char *kwlist[] = {"viewedge", "orientation", nullptr};
98  PyObject *obj1 = nullptr, *obj2 = nullptr;
99 
100  if (!PyArg_ParseTupleAndKeywords(
101  args, kwds, "O!O!", (char **)kwlist, &ViewEdge_Type, &obj1, &PyBool_Type, &obj2)) {
102  return nullptr;
103  }
104  ViewEdge *ve = ((BPy_ViewEdge *)obj1)->ve;
105  bool orientation = bool_from_PyBool(obj2);
106  self->c->push_viewedge_back(ve, orientation);
107  Py_RETURN_NONE;
108 }
109 
110 PyDoc_STRVAR(Chain_push_viewedge_front_doc,
111  ".. method:: push_viewedge_front(viewedge, orientation)\n"
112  "\n"
113  " Adds a ViewEdge at the beginning of the Chain.\n"
114  "\n"
115  " :arg viewedge: The ViewEdge that must be added.\n"
116  " :type viewedge: :class:`ViewEdge`\n"
117  " :arg orientation: The orientation with which the ViewEdge must be\n"
118  " processed.\n"
119  " :type orientation: bool");
120 
121 static PyObject *Chain_push_viewedge_front(BPy_Chain *self, PyObject *args, PyObject *kwds)
122 {
123  static const char *kwlist[] = {"viewedge", "orientation", nullptr};
124  PyObject *obj1 = nullptr, *obj2 = nullptr;
125 
126  if (!PyArg_ParseTupleAndKeywords(
127  args, kwds, "O!O!", (char **)kwlist, &ViewEdge_Type, &obj1, &PyBool_Type, &obj2)) {
128  return nullptr;
129  }
130  ViewEdge *ve = ((BPy_ViewEdge *)obj1)->ve;
131  bool orientation = bool_from_PyBool(obj2);
132  self->c->push_viewedge_front(ve, orientation);
133  Py_RETURN_NONE;
134 }
135 
136 static PyMethodDef BPy_Chain_methods[] = {
137  {"push_viewedge_back",
138  (PyCFunction)Chain_push_viewedge_back,
139  METH_VARARGS | METH_KEYWORDS,
140  Chain_push_viewedge_back_doc},
141  {"push_viewedge_front",
142  (PyCFunction)Chain_push_viewedge_front,
143  METH_VARARGS | METH_KEYWORDS,
144  Chain_push_viewedge_front_doc},
145  {nullptr, nullptr, 0, nullptr},
146 };
147 
148 /*-----------------------BPy_Chain type definition ------------------------------*/
149 
150 PyTypeObject Chain_Type = {
151  PyVarObject_HEAD_INIT(nullptr, 0) "Chain", /* tp_name */
152  sizeof(BPy_Chain), /* tp_basicsize */
153  0, /* tp_itemsize */
154  nullptr, /* tp_dealloc */
155  0, /* tp_vectorcall_offset */
156  nullptr, /* tp_getattr */
157  nullptr, /* tp_setattr */
158  nullptr, /* tp_reserved */
159  nullptr, /* tp_repr */
160  nullptr, /* tp_as_number */
161  nullptr, /* tp_as_sequence */
162  nullptr, /* tp_as_mapping */
163  nullptr, /* tp_hash */
164  nullptr, /* tp_call */
165  nullptr, /* tp_str */
166  nullptr, /* tp_getattro */
167  nullptr, /* tp_setattro */
168  nullptr, /* tp_as_buffer */
169  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
170  Chain_doc, /* tp_doc */
171  nullptr, /* tp_traverse */
172  nullptr, /* tp_clear */
173  nullptr, /* tp_richcompare */
174  0, /* tp_weaklistoffset */
175  nullptr, /* tp_iter */
176  nullptr, /* tp_iternext */
177  BPy_Chain_methods, /* tp_methods */
178  nullptr, /* tp_members */
179  nullptr, /* tp_getset */
180  &FrsCurve_Type, /* tp_base */
181  nullptr, /* tp_dict */
182  nullptr, /* tp_descr_get */
183  nullptr, /* tp_descr_set */
184  0, /* tp_dictoffset */
185  (initproc)Chain_init, /* tp_init */
186  nullptr, /* tp_alloc */
187  nullptr, /* tp_new */
188 };
189 
191 
192 #ifdef __cplusplus
193 }
194 #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:95
PyTypeObject Chain_Type
Definition: BPy_Chain.cpp:150
static PyMethodDef BPy_Chain_methods[]
Definition: BPy_Chain.cpp:136
static PyObject * Chain_push_viewedge_front(BPy_Chain *self, PyObject *args, PyObject *kwds)
Definition: BPy_Chain.cpp:121
static int Chain_init(BPy_Chain *self, PyObject *args, PyObject *kwds)
Definition: BPy_Chain.cpp:56
bool bool_from_PyBool(PyObject *b)
PyTypeObject FrsCurve_Type
PyTypeObject Id_Type
Definition: BPy_Id.cpp:171
PyTypeObject ViewEdge_Type
inherits from class Rep
Definition: AppCanvas.cpp:32
static unsigned c
Definition: RandGen.cpp:97
Definition: BPy_Id.h:42