Blender V5.3
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 " :param 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,
71 kwds,
72 "O!" /* `fedge` */
73 ":get_svertex",
74 (char **)kwlist,
76 &py_fe))
77 {
78 return nullptr;
79 }
80 SVertex *sv = self->tv->getSVertex(((BPy_FEdge *)py_fe)->fe);
81 if (sv) {
82 return BPy_SVertex_from_SVertex(*sv);
83 }
84 Py_RETURN_NONE;
85}
86
88 /* Wrap. */
89 TVertex_get_mate_doc,
90 ".. method:: get_mate(viewedge)\n"
91 "\n"
92 " Returns the mate edge of the ViewEdge given as argument. If the\n"
93 " ViewEdge is frontEdgeA, frontEdgeB is returned. If the ViewEdge is\n"
94 " frontEdgeB, frontEdgeA is returned. Same for back edges.\n"
95 "\n"
96 " :param viewedge: A ViewEdge object.\n"
97 " :type viewedge: :class:`ViewEdge`\n"
98 " :return: The mate edge of the given ViewEdge.\n"
99 " :rtype: :class:`ViewEdge`\n");
100static PyObject *TVertex_get_mate(BPy_TVertex *self, PyObject *args, PyObject *kwds)
101{
102 static const char *kwlist[] = {"viewedge", nullptr};
103 PyObject *py_ve;
104
105 if (!PyArg_ParseTupleAndKeywords(args,
106 kwds,
107 "O!" /* `viewedge` */
108 ":get_mate",
109 (char **)kwlist,
111 &py_ve))
112 {
113 return nullptr;
114 }
115 ViewEdge *ve = self->tv->mate(((BPy_ViewEdge *)py_ve)->ve);
116 if (ve) {
117 return BPy_ViewEdge_from_ViewEdge(*ve);
118 }
119 Py_RETURN_NONE;
120}
121
122#ifdef __GNUC__
123# ifdef __clang__
124# pragma clang diagnostic push
125# pragma clang diagnostic ignored "-Wcast-function-type"
126# else
127# pragma GCC diagnostic push
128# pragma GCC diagnostic ignored "-Wcast-function-type"
129# endif
130#endif
131
132static PyMethodDef BPy_TVertex_methods[] = {
133 {"get_svertex",
134 (PyCFunction)TVertex_get_svertex,
135 METH_VARARGS | METH_KEYWORDS,
136 TVertex_get_svertex_doc},
137 {"get_mate",
138 (PyCFunction)TVertex_get_mate,
139 METH_VARARGS | METH_KEYWORDS,
140 TVertex_get_mate_doc},
141 {nullptr, nullptr, 0, nullptr},
142};
143
144#ifdef __GNUC__
145# ifdef __clang__
146# pragma clang diagnostic pop
147# else
148# pragma GCC diagnostic pop
149# endif
150#endif
151
152/*----------------------TVertex get/setters ----------------------------*/
153
155 /* Wrap. */
156 TVertex_front_svertex_doc,
157 "The SVertex that is closer to the viewpoint.\n"
158 "\n"
159 ":type: :class:`SVertex`\n");
160static PyObject *TVertex_front_svertex_get(BPy_TVertex *self, void * /*closure*/)
161{
162 SVertex *v = self->tv->frontSVertex();
163 if (v) {
164 return BPy_SVertex_from_SVertex(*v);
165 }
166 Py_RETURN_NONE;
167}
168
169static int TVertex_front_svertex_set(BPy_TVertex *self, PyObject *value, void * /*closure*/)
170{
171 if (!BPy_SVertex_Check(value)) {
172 PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
173 return -1;
174 }
175 self->tv->setFrontSVertex(((BPy_SVertex *)value)->sv);
176 return 0;
177}
178
180 /* Wrap. */
181 TVertex_back_svertex_doc,
182 "The SVertex that is further away from the viewpoint.\n"
183 "\n"
184 ":type: :class:`SVertex`\n");
185static PyObject *TVertex_back_svertex_get(BPy_TVertex *self, void * /*closure*/)
186{
187 SVertex *v = self->tv->backSVertex();
188 if (v) {
189 return BPy_SVertex_from_SVertex(*v);
190 }
191 Py_RETURN_NONE;
192}
193
194static int TVertex_back_svertex_set(BPy_TVertex *self, PyObject *value, void * /*closure*/)
195{
196 if (!BPy_SVertex_Check(value)) {
197 PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
198 return -1;
199 }
200 self->tv->setBackSVertex(((BPy_SVertex *)value)->sv);
201 return 0;
202}
203
205 /* Wrap. */
206 TVertex_id_doc,
207 "The Id of this TVertex.\n"
208 "\n"
209 ":type: :class:`Id`\n");
210static PyObject *TVertex_id_get(BPy_TVertex *self, void * /*closure*/)
211{
212 Id id(self->tv->getId());
213 return BPy_Id_from_Id(id); // return a copy
214}
215
216static int TVertex_id_set(BPy_TVertex *self, PyObject *value, void * /*closure*/)
217{
218 if (!BPy_Id_Check(value)) {
219 PyErr_SetString(PyExc_TypeError, "value must be an Id");
220 return -1;
221 }
222 self->tv->setId(*(((BPy_Id *)value)->id));
223 return 0;
224}
225
226static PyGetSetDef BPy_TVertex_getseters[] = {
227 {"front_svertex",
230 TVertex_front_svertex_doc,
231 nullptr},
232 {"back_svertex",
235 TVertex_back_svertex_doc,
236 nullptr},
237 {"id", (getter)TVertex_id_get, (setter)TVertex_id_set, TVertex_id_doc, nullptr},
238 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
239};
240
241/*-----------------------BPy_TVertex type definition ------------------------------*/
242
243PyTypeObject TVertex_Type = {
244 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
245 /*tp_name*/ "TVertex",
246 /*tp_basicsize*/ sizeof(BPy_TVertex),
247 /*tp_itemsize*/ 0,
248 /*tp_dealloc*/ nullptr,
249 /*tp_vectorcall_offset*/ 0,
250 /*tp_getattr*/ nullptr,
251 /*tp_setattr*/ nullptr,
252 /*tp_as_async*/ nullptr,
253 /*tp_repr*/ nullptr,
254 /*tp_as_number*/ nullptr,
255 /*tp_as_sequence*/ nullptr,
256 /*tp_as_mapping*/ nullptr,
257 /*tp_hash*/ nullptr,
258 /*tp_call*/ nullptr,
259 /*tp_str*/ nullptr,
260 /*tp_getattro*/ nullptr,
261 /*tp_setattro*/ nullptr,
262 /*tp_as_buffer*/ nullptr,
263 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
264 /*tp_doc*/ TVertex_doc,
265 /*tp_traverse*/ nullptr,
266 /*tp_clear*/ nullptr,
267 /*tp_richcompare*/ nullptr,
268 /*tp_weaklistoffset*/ 0,
269 /*tp_iter*/ nullptr,
270 /*tp_iternext*/ nullptr,
271 /*tp_methods*/ BPy_TVertex_methods,
272 /*tp_members*/ nullptr,
273 /*tp_getset*/ BPy_TVertex_getseters,
274 /*tp_base*/ &ViewVertex_Type,
275 /*tp_dict*/ nullptr,
276 /*tp_descr_get*/ nullptr,
277 /*tp_descr_set*/ nullptr,
278 /*tp_dictoffset*/ 0,
279 /*tp_init*/ (initproc)TVertex_init,
280 /*tp_alloc*/ nullptr,
281 /*tp_new*/ nullptr,
282};
283
PyObject * BPy_Id_from_Id(Id &id)
PyObject * BPy_SVertex_from_SVertex(SVertex &sv)
PyObject * BPy_ViewEdge_from_ViewEdge(ViewEdge &ve)
PyTypeObject FEdge_Type
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")
#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
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
void setId(const Id &iId)
Definition ViewMap.h:565
SVertex * backSVertex()
Definition ViewMap.h:519
SVertex * getSVertex(FEdge *iFEdge)
Definition ViewMap.h:571
SVertex * frontSVertex()
Definition ViewMap.h:513
void setBackSVertex(SVertex *iBackSVertex)
Definition ViewMap.h:553
virtual ViewEdge * mate(ViewEdge *iEdgeA)
Definition ViewMap.h:596
void setFrontSVertex(SVertex *iFrontSVertex)
Definition ViewMap.h:546
virtual Id getId() const
Definition ViewMap.h:432
inherits from class Rep
Definition AppCanvas.cpp:20
PyObject_HEAD Freestyle::Interface0D * if0D
BPy_ViewVertex py_vv
Definition BPy_TVertex.h:23
Freestyle::TVertex * tv
Definition BPy_TVertex.h:24
BPy_Interface0D py_if0D
Freestyle::ViewVertex * vv