Blender V5.0
BPy_TVertex.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BPy_TVertex.h"
10
11#include "../../BPy_Convert.h"
12#include "../../BPy_Id.h"
15#include "../BPy_SVertex.h"
16
17using namespace Freestyle;
18
20
21/*----------------------TVertex methods ----------------------------*/
22
24 /* Wrap. */
25 TVertex_doc,
26 "Class hierarchy: :class:`Interface0D` > :class:`ViewVertex` > :class:`TVertex`\n"
27 "\n"
28 "Class to define a T vertex, i.e. an intersection between two edges.\n"
29 "It points towards two SVertex and four ViewEdges. Among the\n"
30 "ViewEdges, two are front and the other two are back. Basically a\n"
31 "front edge hides part of a back edge. So, among the back edges, one\n"
32 "is of invisibility N and the other of invisibility N+1.\n"
33 "\n"
34 ".. method:: __init__()\n"
35 "\n"
36 " Default constructor.\n");
37
38/* NOTE: No copy constructor in Python because the C++ copy constructor is 'protected'. */
39
40static int TVertex_init(BPy_TVertex *self, PyObject *args, PyObject *kwds)
41{
42 static const char *kwlist[] = {nullptr};
43
44 if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) {
45 return -1;
46 }
47 self->tv = new TVertex();
48 self->py_vv.vv = self->tv;
49 self->py_vv.py_if0D.if0D = self->tv;
50 self->py_vv.py_if0D.borrowed = false;
51 return 0;
52}
53
55 /* Wrap. */
56 TVertex_get_svertex_doc,
57 ".. method:: get_svertex(fedge)\n"
58 "\n"
59 " Returns the SVertex (among the 2) belonging to the given FEdge.\n"
60 "\n"
61 " :arg fedge: An FEdge object.\n"
62 " :type fedge: :class:`FEdge`\n"
63 " :return: The SVertex belonging to the given FEdge.\n"
64 " :rtype: :class:`SVertex`\n");
65static PyObject *TVertex_get_svertex(BPy_TVertex *self, PyObject *args, PyObject *kwds)
66{
67 static const char *kwlist[] = {"fedge", nullptr};
68 PyObject *py_fe;
69
70 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &FEdge_Type, &py_fe)) {
71 return nullptr;
72 }
73 SVertex *sv = self->tv->getSVertex(((BPy_FEdge *)py_fe)->fe);
74 if (sv) {
75 return BPy_SVertex_from_SVertex(*sv);
76 }
77 Py_RETURN_NONE;
78}
79
81 /* Wrap. */
82 TVertex_get_mate_doc,
83 ".. method:: get_mate(viewedge)\n"
84 "\n"
85 " Returns the mate edge of the ViewEdge given as argument. If the\n"
86 " ViewEdge is frontEdgeA, frontEdgeB is returned. If the ViewEdge is\n"
87 " frontEdgeB, frontEdgeA is returned. Same for back edges.\n"
88 "\n"
89 " :arg viewedge: A ViewEdge object.\n"
90 " :type viewedge: :class:`ViewEdge`\n"
91 " :return: The mate edge of the given ViewEdge.\n"
92 " :rtype: :class:`ViewEdge`\n");
93static PyObject *TVertex_get_mate(BPy_TVertex *self, PyObject *args, PyObject *kwds)
94{
95 static const char *kwlist[] = {"viewedge", nullptr};
96 PyObject *py_ve;
97
98 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &ViewEdge_Type, &py_ve)) {
99 return nullptr;
100 }
101 ViewEdge *ve = self->tv->mate(((BPy_ViewEdge *)py_ve)->ve);
102 if (ve) {
103 return BPy_ViewEdge_from_ViewEdge(*ve);
104 }
105 Py_RETURN_NONE;
106}
107
108#ifdef __GNUC__
109# ifdef __clang__
110# pragma clang diagnostic push
111# pragma clang diagnostic ignored "-Wcast-function-type"
112# else
113# pragma GCC diagnostic push
114# pragma GCC diagnostic ignored "-Wcast-function-type"
115# endif
116#endif
117
118static PyMethodDef BPy_TVertex_methods[] = {
119 {"get_svertex",
120 (PyCFunction)TVertex_get_svertex,
121 METH_VARARGS | METH_KEYWORDS,
122 TVertex_get_svertex_doc},
123 {"get_mate",
124 (PyCFunction)TVertex_get_mate,
125 METH_VARARGS | METH_KEYWORDS,
126 TVertex_get_mate_doc},
127 {nullptr, nullptr, 0, nullptr},
128};
129
130#ifdef __GNUC__
131# ifdef __clang__
132# pragma clang diagnostic pop
133# else
134# pragma GCC diagnostic pop
135# endif
136#endif
137
138/*----------------------TVertex get/setters ----------------------------*/
139
141 /* Wrap. */
142 TVertex_front_svertex_doc,
143 "The SVertex that is closer to the viewpoint.\n"
144 "\n"
145 ":type: :class:`SVertex`\n");
146static PyObject *TVertex_front_svertex_get(BPy_TVertex *self, void * /*closure*/)
147{
148 SVertex *v = self->tv->frontSVertex();
149 if (v) {
151 }
152 Py_RETURN_NONE;
153}
154
155static int TVertex_front_svertex_set(BPy_TVertex *self, PyObject *value, void * /*closure*/)
156{
157 if (!BPy_SVertex_Check(value)) {
158 PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
159 return -1;
160 }
161 self->tv->setFrontSVertex(((BPy_SVertex *)value)->sv);
162 return 0;
163}
164
166 /* Wrap. */
167 TVertex_back_svertex_doc,
168 "The SVertex that is further away from the viewpoint.\n"
169 "\n"
170 ":type: :class:`SVertex`\n");
171static PyObject *TVertex_back_svertex_get(BPy_TVertex *self, void * /*closure*/)
172{
173 SVertex *v = self->tv->backSVertex();
174 if (v) {
176 }
177 Py_RETURN_NONE;
178}
179
180static int TVertex_back_svertex_set(BPy_TVertex *self, PyObject *value, void * /*closure*/)
181{
182 if (!BPy_SVertex_Check(value)) {
183 PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
184 return -1;
185 }
186 self->tv->setBackSVertex(((BPy_SVertex *)value)->sv);
187 return 0;
188}
189
191 /* Wrap. */
192 TVertex_id_doc,
193 "The Id of this TVertex.\n"
194 "\n"
195 ":type: :class:`Id`\n");
196static PyObject *TVertex_id_get(BPy_TVertex *self, void * /*closure*/)
197{
198 Id id(self->tv->getId());
199 return BPy_Id_from_Id(id); // return a copy
200}
201
202static int TVertex_id_set(BPy_TVertex *self, PyObject *value, void * /*closure*/)
203{
204 if (!BPy_Id_Check(value)) {
205 PyErr_SetString(PyExc_TypeError, "value must be an Id");
206 return -1;
207 }
208 self->tv->setId(*(((BPy_Id *)value)->id));
209 return 0;
210}
211
212static PyGetSetDef BPy_TVertex_getseters[] = {
213 {"front_svertex",
216 TVertex_front_svertex_doc,
217 nullptr},
218 {"back_svertex",
221 TVertex_back_svertex_doc,
222 nullptr},
223 {"id", (getter)TVertex_id_get, (setter)TVertex_id_set, TVertex_id_doc, nullptr},
224 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
225};
226
227/*-----------------------BPy_TVertex type definition ------------------------------*/
228
229PyTypeObject TVertex_Type = {
230 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
231 /*tp_name*/ "TVertex",
232 /*tp_basicsize*/ sizeof(BPy_TVertex),
233 /*tp_itemsize*/ 0,
234 /*tp_dealloc*/ nullptr,
235 /*tp_vectorcall_offset*/ 0,
236 /*tp_getattr*/ nullptr,
237 /*tp_setattr*/ nullptr,
238 /*tp_as_async*/ nullptr,
239 /*tp_repr*/ nullptr,
240 /*tp_as_number*/ nullptr,
241 /*tp_as_sequence*/ nullptr,
242 /*tp_as_mapping*/ nullptr,
243 /*tp_hash*/ nullptr,
244 /*tp_call*/ nullptr,
245 /*tp_str*/ nullptr,
246 /*tp_getattro*/ nullptr,
247 /*tp_setattro*/ nullptr,
248 /*tp_as_buffer*/ nullptr,
249 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
250 /*tp_doc*/ TVertex_doc,
251 /*tp_traverse*/ nullptr,
252 /*tp_clear*/ nullptr,
253 /*tp_richcompare*/ nullptr,
254 /*tp_weaklistoffset*/ 0,
255 /*tp_iter*/ nullptr,
256 /*tp_iternext*/ nullptr,
257 /*tp_methods*/ BPy_TVertex_methods,
258 /*tp_members*/ nullptr,
259 /*tp_getset*/ BPy_TVertex_getseters,
260 /*tp_base*/ &ViewVertex_Type,
261 /*tp_dict*/ nullptr,
262 /*tp_descr_get*/ nullptr,
263 /*tp_descr_set*/ nullptr,
264 /*tp_dictoffset*/ 0,
265 /*tp_init*/ (initproc)TVertex_init,
266 /*tp_alloc*/ nullptr,
267 /*tp_new*/ nullptr,
268};
269
PyObject * BPy_Id_from_Id(Id &id)
PyObject * BPy_SVertex_from_SVertex(SVertex &sv)
PyObject * BPy_ViewEdge_from_ViewEdge(ViewEdge &ve)
PyTypeObject FEdge_Type
#define BPy_Id_Check(v)
Definition BPy_Id.h:23
#define BPy_SVertex_Check(v)
Definition BPy_SVertex.h:19
static PyMethodDef BPy_TVertex_methods[]
PyTypeObject TVertex_Type
PyDoc_STRVAR(TVertex_doc, "Class hierarchy: :class:`Interface0D` > :class:`ViewVertex` > :class:`TVertex`\n" "\n" "Class to define a T vertex, i.e. an intersection between two edges.\n" "It points towards two SVertex and four ViewEdges. Among the\n" "ViewEdges, two are front and the other two are back. Basically a\n" "front edge hides part of a back edge. So, among the back edges, one\n" "is of invisibility N and the other of invisibility N+1.\n" "\n" ".. method:: __init__()\n" "\n" " Default constructor.\n")
static PyObject * TVertex_get_svertex(BPy_TVertex *self, PyObject *args, PyObject *kwds)
static PyObject * TVertex_get_mate(BPy_TVertex *self, PyObject *args, PyObject *kwds)
static PyObject * TVertex_front_svertex_get(BPy_TVertex *self, void *)
static int TVertex_back_svertex_set(BPy_TVertex *self, PyObject *value, void *)
static PyObject * TVertex_back_svertex_get(BPy_TVertex *self, void *)
static int TVertex_id_set(BPy_TVertex *self, PyObject *value, void *)
static PyObject * TVertex_id_get(BPy_TVertex *self, void *)
static PyGetSetDef BPy_TVertex_getseters[]
static int TVertex_front_svertex_set(BPy_TVertex *self, PyObject *value, void *)
static int TVertex_init(BPy_TVertex *self, PyObject *args, PyObject *kwds)
PyTypeObject ViewEdge_Type
PyTypeObject ViewVertex_Type
ATTR_WARN_UNUSED_RESULT const BMVert * v
PyObject * self
inherits from class Rep
Definition AppCanvas.cpp:20