Blender V5.3
BPy_ViewShape.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_ViewShape.h"
10
11#include "BPy_Convert.h"
12#include "BPy_SShape.h"
15
16#include "BLI_sys_types.hh"
17
18#include "../generic/py_capi_utils.hh"
19
20using namespace Freestyle;
21
23
24//-------------------MODULE INITIALIZATION--------------------------------
25
26int ViewShape_Init(PyObject *module)
27{
28 if (module == nullptr) {
29 return -1;
30 }
31
32 if (PyType_Ready(&ViewShape_Type) < 0) {
33 return -1;
34 }
35 PyModule_AddObjectRef(module, "ViewShape", (PyObject *)&ViewShape_Type);
36
37 return 0;
38}
39
40/*----------------------ViewShape methods ----------------------------*/
41
43 /* Wrap. */
44 ViewShape_doc,
45 "Class gathering the elements of the ViewMap (i.e., :class:`ViewVertex`\n"
46 "and :class:`ViewEdge`) that are issued from the same input shape.\n"
47 "\n"
48 ".. method:: __init__(*args)\n"
49 "\n"
50 " Accepted call signatures:\n"
51 "\n"
52 " - ``__init__()``\n"
53 " - ``__init__(brother)``\n"
54 " - ``__init__(sshape)``\n"
55 "\n"
56 " Builds a :class:`ViewShape` using the default constructor,\n"
57 " copy constructor, or from a :class:`SShape`.\n"
58 "\n"
59 " :param brother: A ViewShape object.\n"
60 " :type brother: :class:`ViewShape`\n"
61 " :param sshape: An SShape object.\n"
62 " :type sshape: :class:`SShape`\n");
63static int ViewShape_init(BPy_ViewShape *self, PyObject *args, PyObject *kwds)
64{
65 static const char *kwlist_1[] = {"brother", nullptr};
66 static const char *kwlist_2[] = {"sshape", nullptr};
67 PyObject *obj = nullptr;
68
69 if (PyArg_ParseTupleAndKeywords(args,
70 kwds,
71 "|" /* Optional arguments. */
72 "O!" /* `brother` */
73 ":__init__",
74 (char **)kwlist_1,
76 &obj))
77 {
78 if (!obj) {
79 self->vs = new ViewShape();
80 self->py_ss = nullptr;
81 }
82 else {
83 self->vs = new ViewShape(*(((BPy_ViewShape *)obj)->vs));
84 self->py_ss = ((BPy_ViewShape *)obj)->py_ss;
85 }
86 }
87 else if ((void)PyErr_Clear(),
88 PyArg_ParseTupleAndKeywords(args,
89 kwds,
90 "O!" /* `sshape` */
91 ":__init__",
92 (char **)kwlist_2,
94 &obj))
95 {
96 BPy_SShape *py_ss = (BPy_SShape *)obj;
97 self->vs = new ViewShape(py_ss->ss);
98 self->py_ss = (!py_ss->borrowed) ? py_ss : nullptr;
99 }
100 else {
101 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
102 return -1;
103 }
104 self->borrowed = false;
105 Py_XINCREF(self->py_ss);
106 return 0;
107}
108
110{
111 if (self->py_ss) {
112 self->vs->setSShape((SShape *)nullptr);
113 Py_DECREF(self->py_ss);
114 }
115 if (self->vs && !self->borrowed) {
116 delete self->vs;
117 }
118 Py_TYPE(self)->tp_free((PyObject *)self);
119}
120
121static PyObject *ViewShape_repr(BPy_ViewShape *self)
122{
123 return PyUnicode_FromFormat("ViewShape - address: %p", self->vs);
124}
125
127 /* Wrap. */
128 ViewShape_add_edge_doc,
129 ".. method:: add_edge(edge)\n"
130 "\n"
131 " Adds a ViewEdge to the list of ViewEdge objects.\n"
132 "\n"
133 " :param edge: A ViewEdge object.\n"
134 " :type edge: :class:`ViewEdge`\n");
135static PyObject *ViewShape_add_edge(BPy_ViewShape *self, PyObject *args, PyObject *kwds)
136{
137 static const char *kwlist[] = {"edge", nullptr};
138 PyObject *py_ve = nullptr;
139
140 if (PyArg_ParseTupleAndKeywords(args,
141 kwds,
142 "O!" /* `edge` */
143 ":add_edge",
144 (char **)kwlist,
146 &py_ve))
147 {
148 return nullptr;
149 }
150 self->vs->AddEdge(((BPy_ViewEdge *)py_ve)->ve);
151 Py_RETURN_NONE;
152}
153
155 /* Wrap. */
156 ViewShape_add_vertex_doc,
157 ".. method:: add_vertex(vertex)\n"
158 "\n"
159 " Adds a ViewVertex to the list of the ViewVertex objects.\n"
160 "\n"
161 " :param vertex: A ViewVertex object.\n"
162 " :type vertex: :class:`ViewVertex`\n");
163static PyObject *ViewShape_add_vertex(BPy_ViewShape *self, PyObject *args, PyObject *kwds)
164{
165 static const char *kwlist[] = {"vertex", nullptr};
166 PyObject *py_vv = nullptr;
167
168 if (PyArg_ParseTupleAndKeywords(args,
169 kwds,
170 "O!" /* `vertex` */
171 ":add_vertex",
172 (char **)kwlist,
174 &py_vv))
175 {
176 return nullptr;
177 }
178 self->vs->AddVertex(((BPy_ViewVertex *)py_vv)->vv);
179 Py_RETURN_NONE;
180}
181
182// virtual ViewShape *duplicate()
183
184#ifdef __GNUC__
185# ifdef __clang__
186# pragma clang diagnostic push
187# pragma clang diagnostic ignored "-Wcast-function-type"
188# else
189# pragma GCC diagnostic push
190# pragma GCC diagnostic ignored "-Wcast-function-type"
191# endif
192#endif
193
194static PyMethodDef BPy_ViewShape_methods[] = {
195 {"add_edge",
196 (PyCFunction)ViewShape_add_edge,
197 METH_VARARGS | METH_KEYWORDS,
198 ViewShape_add_edge_doc},
199 {"add_vertex",
200 (PyCFunction)ViewShape_add_vertex,
201 METH_VARARGS | METH_KEYWORDS,
202 ViewShape_add_vertex_doc},
203 {nullptr, nullptr, 0, nullptr},
204};
205
206#ifdef __GNUC__
207# ifdef __clang__
208# pragma clang diagnostic pop
209# else
210# pragma GCC diagnostic pop
211# endif
212#endif
213
214/*----------------------ViewShape get/setters ----------------------------*/
215
217 /* Wrap. */
218 ViewShape_sshape_doc,
219 "The SShape on top of which this ViewShape is built.\n"
220 "\n"
221 ":type: :class:`SShape`\n");
222static PyObject *ViewShape_sshape_get(BPy_ViewShape *self, void * /*closure*/)
223{
224 SShape *ss = self->vs->sshape();
225 if (!ss) {
226 Py_RETURN_NONE;
227 }
228 return BPy_SShape_from_SShape(*ss);
229}
230
231static int ViewShape_sshape_set(BPy_ViewShape *self, PyObject *value, void * /*closure*/)
232{
233 if (!BPy_SShape_Check(value)) {
234 PyErr_SetString(PyExc_TypeError, "value must be an SShape");
235 return -1;
236 }
237 BPy_SShape *py_ss = (BPy_SShape *)value;
238 self->vs->setSShape(py_ss->ss);
239 if (self->py_ss) {
240 Py_DECREF(self->py_ss);
241 }
242 if (!py_ss->borrowed) {
243 self->py_ss = py_ss;
244 Py_INCREF(self->py_ss);
245 }
246 return 0;
247}
248
250 /* Wrap. */
251 ViewShape_vertices_doc,
252 "The list of ViewVertex objects contained in this ViewShape.\n"
253 "\n"
254 ":type: list[:class:`ViewVertex`]\n");
255static PyObject *ViewShape_vertices_get(BPy_ViewShape *self, void * /*closure*/)
256{
257 vector<ViewVertex *> vertices = self->vs->vertices();
259 PyObject *py_vertices = PyList_New(vertices.size());
260 uint i = 0;
261
262 for (it = vertices.begin(); it != vertices.end(); it++) {
263 PyList_SET_ITEM(py_vertices, i++, Any_BPy_ViewVertex_from_ViewVertex(*(*it)));
264 }
265 return py_vertices;
266}
267
268static int ViewShape_vertices_set(BPy_ViewShape *self, PyObject *value, void * /*closure*/)
269{
270 PyObject *item;
272
273 if (!PyList_Check(value)) {
274 PyErr_SetString(PyExc_TypeError, "value must be a list of ViewVertex objects");
275 return -1;
276 }
277
278 v.reserve(PyList_GET_SIZE(value));
279 for (uint i = 0; i < PyList_GET_SIZE(value); i++) {
280 item = PyList_GET_ITEM(value, i);
281 if (BPy_ViewVertex_Check(item)) {
282 v.push_back(((BPy_ViewVertex *)item)->vv);
283 }
284 else {
285 PyErr_SetString(PyExc_TypeError, "value must be a list of ViewVertex objects");
286 return -1;
287 }
288 }
289 self->vs->setVertices(v);
290 return 0;
291}
292
294 /* Wrap. */
295 ViewShape_edges_doc,
296 "The list of ViewEdge objects contained in this ViewShape.\n"
297 "\n"
298 ":type: list[:class:`ViewEdge`]\n");
299static PyObject *ViewShape_edges_get(BPy_ViewShape *self, void * /*closure*/)
300{
301 vector<ViewEdge *> edges = self->vs->edges();
303 PyObject *py_edges = PyList_New(edges.size());
304 uint i = 0;
305
306 for (it = edges.begin(); it != edges.end(); it++) {
307 PyList_SET_ITEM(py_edges, i++, BPy_ViewEdge_from_ViewEdge(*(*it)));
308 }
309 return py_edges;
310}
311
312static int ViewShape_edges_set(BPy_ViewShape *self, PyObject *value, void * /*closure*/)
313{
314 PyObject *item;
316
317 if (!PyList_Check(value)) {
318 PyErr_SetString(PyExc_TypeError, "value must be a list of ViewEdge objects");
319 return -1;
320 }
321
322 v.reserve(PyList_GET_SIZE(value));
323 for (int i = 0; i < PyList_GET_SIZE(value); i++) {
324 item = PyList_GET_ITEM(value, i);
325 if (BPy_ViewEdge_Check(item)) {
326 v.push_back(((BPy_ViewEdge *)item)->ve);
327 }
328 else {
329 PyErr_SetString(PyExc_TypeError, "argument must be list of ViewEdge objects");
330 return -1;
331 }
332 }
333 self->vs->setEdges(v);
334 return 0;
335}
336
338 /* Wrap. */
339 ViewShape_name_doc,
340 "The name of the ViewShape.\n"
341 "\n"
342 ":type: str\n");
343static PyObject *ViewShape_name_get(BPy_ViewShape *self, void * /*closure*/)
344{
346}
347
349 /* Wrap. */
350 ViewShape_library_path_doc,
351 "The library path of the ViewShape, or None if the ViewShape is not part of\n"
352 "a library.\n"
353 "\n"
354 ":type: str | None\n");
355static PyObject *ViewShape_library_path_get(BPy_ViewShape *self, void * /*closure*/)
356{
358}
359
361 /* Wrap. */
362 ViewShape_id_doc,
363 "The Id of this ViewShape.\n"
364 "\n"
365 ":type: :class:`Id`\n");
366static PyObject *ViewShape_id_get(BPy_ViewShape *self, void * /*closure*/)
367{
368 Id id(self->vs->getId());
369 return BPy_Id_from_Id(id); // return a copy
370}
371
372static PyGetSetDef BPy_ViewShape_getseters[] = {
373 {"sshape",
374 (getter)ViewShape_sshape_get,
375 (setter)ViewShape_sshape_set,
376 ViewShape_sshape_doc,
377 nullptr},
378 {"vertices",
381 ViewShape_vertices_doc,
382 nullptr},
383 {"edges",
384 (getter)ViewShape_edges_get,
385 (setter)ViewShape_edges_set,
386 ViewShape_edges_doc,
387 nullptr},
388 {"name", (getter)ViewShape_name_get, (setter) nullptr, ViewShape_name_doc, nullptr},
389 {"library_path",
391 (setter) nullptr,
392 ViewShape_library_path_doc,
393 nullptr},
394 {"id", (getter)ViewShape_id_get, (setter) nullptr, ViewShape_id_doc, nullptr},
395 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
396};
397
398/*-----------------------BPy_ViewShape type definition ------------------------------*/
399
400PyTypeObject ViewShape_Type = {
401 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
402 /*tp_name*/ "ViewShape",
403 /*tp_basicsize*/ sizeof(BPy_ViewShape),
404 /*tp_itemsize*/ 0,
405 /*tp_dealloc*/ (destructor)ViewShape_dealloc,
406 /*tp_vectorcall_offset*/ 0,
407 /*tp_getattr*/ nullptr,
408 /*tp_setattr*/ nullptr,
409 /*tp_as_async*/ nullptr,
410 /*tp_repr*/ (reprfunc)ViewShape_repr,
411 /*tp_as_number*/ nullptr,
412 /*tp_as_sequence*/ nullptr,
413 /*tp_as_mapping*/ nullptr,
414 /*tp_hash*/ nullptr,
415 /*tp_call*/ nullptr,
416 /*tp_str*/ nullptr,
417 /*tp_getattro*/ nullptr,
418 /*tp_setattro*/ nullptr,
419 /*tp_as_buffer*/ nullptr,
420 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
421 /*tp_doc*/ ViewShape_doc,
422 /*tp_traverse*/ nullptr,
423 /*tp_clear*/ nullptr,
424 /*tp_richcompare*/ nullptr,
425 /*tp_weaklistoffset*/ 0,
426 /*tp_iter*/ nullptr,
427 /*tp_iternext*/ nullptr,
428 /*tp_methods*/ BPy_ViewShape_methods,
429 /*tp_members*/ nullptr,
430 /*tp_getset*/ BPy_ViewShape_getseters,
431 /*tp_base*/ nullptr,
432 /*tp_dict*/ nullptr,
433 /*tp_descr_get*/ nullptr,
434 /*tp_descr_set*/ nullptr,
435 /*tp_dictoffset*/ 0,
436 /*tp_init*/ (initproc)ViewShape_init,
437 /*tp_alloc*/ nullptr,
438 /*tp_new*/ PyType_GenericNew,
439};
440
PyObject * BPy_Id_from_Id(Id &id)
PyObject * BPy_SShape_from_SShape(SShape &ss)
PyObject * Any_BPy_ViewVertex_from_ViewVertex(ViewVertex &vv)
PyObject * BPy_ViewEdge_from_ViewEdge(ViewEdge &ve)
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
PyTypeObject SShape_Type
#define BPy_SShape_Check(v)
Definition BPy_SShape.h:21
PyTypeObject ViewEdge_Type
#define BPy_ViewEdge_Check(v)
static PyObject * ViewShape_add_edge(BPy_ViewShape *self, PyObject *args, PyObject *kwds)
PyTypeObject ViewShape_Type
static PyObject * ViewShape_add_vertex(BPy_ViewShape *self, PyObject *args, PyObject *kwds)
static PyObject * ViewShape_repr(BPy_ViewShape *self)
static PyObject * ViewShape_sshape_get(BPy_ViewShape *self, void *)
static PyObject * ViewShape_edges_get(BPy_ViewShape *self, void *)
static int ViewShape_init(BPy_ViewShape *self, PyObject *args, PyObject *kwds)
static PyObject * ViewShape_id_get(BPy_ViewShape *self, void *)
static PyObject * ViewShape_library_path_get(BPy_ViewShape *self, void *)
static int ViewShape_vertices_set(BPy_ViewShape *self, PyObject *value, void *)
static void ViewShape_dealloc(BPy_ViewShape *self)
static PyMethodDef BPy_ViewShape_methods[]
int ViewShape_Init(PyObject *module)
static PyObject * ViewShape_vertices_get(BPy_ViewShape *self, void *)
static int ViewShape_edges_set(BPy_ViewShape *self, PyObject *value, void *)
static PyObject * ViewShape_name_get(BPy_ViewShape *self, void *)
static PyGetSetDef BPy_ViewShape_getseters[]
static int ViewShape_sshape_set(BPy_ViewShape *self, PyObject *value, void *)
PyTypeObject ViewVertex_Type
#define BPy_ViewVertex_Check(v)
const string & getName() const
Definition ViewMap.h:1559
void setVertices(const vector< ViewVertex * > &iVertices)
Definition ViewMap.h:1578
void AddVertex(ViewVertex *iVertex)
Definition ViewMap.h:1590
vector< ViewEdge * > & edges()
Definition ViewMap.h:1547
void setSShape(SShape *iSShape)
Definition ViewMap.h:1572
vector< ViewVertex * > & vertices()
Definition ViewMap.h:1541
void setEdges(const vector< ViewEdge * > &iEdges)
Definition ViewMap.h:1584
void AddEdge(ViewEdge *iEdge)
Definition ViewMap.h:1597
SShape * sshape()
Definition ViewMap.h:1529
const string & getLibraryPath() const
Definition ViewMap.h:1565
inherits from class Rep
Definition AppCanvas.cpp:20
PyObject * PyC_UnicodeFromStdStr(const std::string &str)
PyObject_HEAD Freestyle::SShape * ss
Definition BPy_SShape.h:26
bool borrowed
Definition BPy_SShape.h:27
PyObject_HEAD Freestyle::ViewShape * vs
BPy_SShape * py_ss