Blender  V3.3
BPy_TVertex.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BPy_TVertex.h"
8 
9 #include "../../BPy_Convert.h"
10 #include "../../BPy_Id.h"
11 #include "../../Interface1D/BPy_FEdge.h"
12 #include "../../Interface1D/BPy_ViewEdge.h"
13 #include "../BPy_SVertex.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 using namespace Freestyle;
20 
22 
23 /*----------------------TVertex methods ----------------------------*/
24 
25 PyDoc_STRVAR(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.");
37 
38 /* NOTE: No copy constructor in Python because the C++ copy constructor is 'protected'. */
39 
40 static 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 
54 PyDoc_STRVAR(TVertex_get_svertex_doc,
55  ".. method:: get_svertex(fedge)\n"
56  "\n"
57  " Returns the SVertex (among the 2) belonging to the given FEdge.\n"
58  "\n"
59  " :arg fedge: An FEdge object.\n"
60  " :type fedge: :class:`FEdge`\n"
61  " :return: The SVertex belonging to the given FEdge.\n"
62  " :rtype: :class:`SVertex`");
63 
64 static PyObject *TVertex_get_svertex(BPy_TVertex *self, PyObject *args, PyObject *kwds)
65 {
66  static const char *kwlist[] = {"fedge", nullptr};
67  PyObject *py_fe;
68 
69  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &FEdge_Type, &py_fe)) {
70  return nullptr;
71  }
72  SVertex *sv = self->tv->getSVertex(((BPy_FEdge *)py_fe)->fe);
73  if (sv) {
74  return BPy_SVertex_from_SVertex(*sv);
75  }
76  Py_RETURN_NONE;
77 }
78 
79 PyDoc_STRVAR(TVertex_get_mate_doc,
80  ".. method:: get_mate(viewedge)\n"
81  "\n"
82  " Returns the mate edge of the ViewEdge given as argument. If the\n"
83  " ViewEdge is frontEdgeA, frontEdgeB is returned. If the ViewEdge is\n"
84  " frontEdgeB, frontEdgeA is returned. Same for back edges.\n"
85  "\n"
86  " :arg viewedge: A ViewEdge object.\n"
87  " :type viewedge: :class:`ViewEdge`\n"
88  " :return: The mate edge of the given ViewEdge.\n"
89  " :rtype: :class:`ViewEdge`");
90 
91 static PyObject *TVertex_get_mate(BPy_TVertex *self, PyObject *args, PyObject *kwds)
92 {
93  static const char *kwlist[] = {"viewedge", nullptr};
94  PyObject *py_ve;
95 
96  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist, &ViewEdge_Type, &py_ve)) {
97  return nullptr;
98  }
99  ViewEdge *ve = self->tv->mate(((BPy_ViewEdge *)py_ve)->ve);
100  if (ve) {
101  return BPy_ViewEdge_from_ViewEdge(*ve);
102  }
103  Py_RETURN_NONE;
104 }
105 
106 static PyMethodDef BPy_TVertex_methods[] = {
107  {"get_svertex",
108  (PyCFunction)TVertex_get_svertex,
109  METH_VARARGS | METH_KEYWORDS,
110  TVertex_get_svertex_doc},
111  {"get_mate",
112  (PyCFunction)TVertex_get_mate,
113  METH_VARARGS | METH_KEYWORDS,
114  TVertex_get_mate_doc},
115  {nullptr, nullptr, 0, nullptr},
116 };
117 
118 /*----------------------TVertex get/setters ----------------------------*/
119 
120 PyDoc_STRVAR(TVertex_front_svertex_doc,
121  "The SVertex that is closer to the viewpoint.\n"
122  "\n"
123  ":type: :class:`SVertex`");
124 
125 static PyObject *TVertex_front_svertex_get(BPy_TVertex *self, void *UNUSED(closure))
126 {
127  SVertex *v = self->tv->frontSVertex();
128  if (v) {
129  return BPy_SVertex_from_SVertex(*v);
130  }
131  Py_RETURN_NONE;
132 }
133 
134 static int TVertex_front_svertex_set(BPy_TVertex *self, PyObject *value, void *UNUSED(closure))
135 {
136  if (!BPy_SVertex_Check(value)) {
137  PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
138  return -1;
139  }
140  self->tv->setFrontSVertex(((BPy_SVertex *)value)->sv);
141  return 0;
142 }
143 
144 PyDoc_STRVAR(TVertex_back_svertex_doc,
145  "The SVertex that is further away from the viewpoint.\n"
146  "\n"
147  ":type: :class:`SVertex`");
148 
149 static PyObject *TVertex_back_svertex_get(BPy_TVertex *self, void *UNUSED(closure))
150 {
151  SVertex *v = self->tv->backSVertex();
152  if (v) {
153  return BPy_SVertex_from_SVertex(*v);
154  }
155  Py_RETURN_NONE;
156 }
157 
158 static int TVertex_back_svertex_set(BPy_TVertex *self, PyObject *value, void *UNUSED(closure))
159 {
160  if (!BPy_SVertex_Check(value)) {
161  PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
162  return -1;
163  }
164  self->tv->setBackSVertex(((BPy_SVertex *)value)->sv);
165  return 0;
166 }
167 
168 PyDoc_STRVAR(TVertex_id_doc,
169  "The Id of this TVertex.\n"
170  "\n"
171  ":type: :class:`Id`");
172 
173 static PyObject *TVertex_id_get(BPy_TVertex *self, void *UNUSED(closure))
174 {
175  Id id(self->tv->getId());
176  return BPy_Id_from_Id(id); // return a copy
177 }
178 
179 static int TVertex_id_set(BPy_TVertex *self, PyObject *value, void *UNUSED(closure))
180 {
181  if (!BPy_Id_Check(value)) {
182  PyErr_SetString(PyExc_TypeError, "value must be an Id");
183  return -1;
184  }
185  self->tv->setId(*(((BPy_Id *)value)->id));
186  return 0;
187 }
188 
189 static PyGetSetDef BPy_TVertex_getseters[] = {
190  {"front_svertex",
193  TVertex_front_svertex_doc,
194  nullptr},
195  {"back_svertex",
196  (getter)TVertex_back_svertex_get,
197  (setter)TVertex_back_svertex_set,
198  TVertex_back_svertex_doc,
199  nullptr},
200  {"id", (getter)TVertex_id_get, (setter)TVertex_id_set, TVertex_id_doc, nullptr},
201  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
202 };
203 
204 /*-----------------------BPy_TVertex type definition ------------------------------*/
205 PyTypeObject TVertex_Type = {
206  PyVarObject_HEAD_INIT(nullptr, 0) "TVertex", /* tp_name */
207  sizeof(BPy_TVertex), /* tp_basicsize */
208  0, /* tp_itemsize */
209  nullptr, /* tp_dealloc */
210  0, /* tp_vectorcall_offset */
211  nullptr, /* tp_getattr */
212  nullptr, /* tp_setattr */
213  nullptr, /* tp_reserved */
214  nullptr, /* tp_repr */
215  nullptr, /* tp_as_number */
216  nullptr, /* tp_as_sequence */
217  nullptr, /* tp_as_mapping */
218  nullptr, /* tp_hash */
219  nullptr, /* tp_call */
220  nullptr, /* tp_str */
221  nullptr, /* tp_getattro */
222  nullptr, /* tp_setattro */
223  nullptr, /* tp_as_buffer */
224  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
225  TVertex_doc, /* tp_doc */
226  nullptr, /* tp_traverse */
227  nullptr, /* tp_clear */
228  nullptr, /* tp_richcompare */
229  0, /* tp_weaklistoffset */
230  nullptr, /* tp_iter */
231  nullptr, /* tp_iternext */
232  BPy_TVertex_methods, /* tp_methods */
233  nullptr, /* tp_members */
234  BPy_TVertex_getseters, /* tp_getset */
235  &ViewVertex_Type, /* tp_base */
236  nullptr, /* tp_dict */
237  nullptr, /* tp_descr_get */
238  nullptr, /* tp_descr_set */
239  0, /* tp_dictoffset */
240  (initproc)TVertex_init, /* tp_init */
241  nullptr, /* tp_alloc */
242  nullptr, /* tp_new */
243 };
244 
246 
247 #ifdef __cplusplus
248 }
249 #endif
#define UNUSED(x)
PyObject * BPy_SVertex_from_SVertex(SVertex &sv)
PyObject * BPy_ViewEdge_from_ViewEdge(ViewEdge &ve)
PyObject * BPy_Id_from_Id(Id &id)
Definition: BPy_Convert.cpp:90
PyTypeObject FEdge_Type
Definition: BPy_FEdge.cpp:344
#define BPy_Id_Check(v)
Definition: BPy_Id.h:25
#define BPy_SVertex_Check(v)
Definition: BPy_SVertex.h:21
static PyMethodDef BPy_TVertex_methods[]
static int TVertex_id_set(BPy_TVertex *self, PyObject *value, void *UNUSED(closure))
PyTypeObject TVertex_Type
static PyObject * TVertex_front_svertex_get(BPy_TVertex *self, void *UNUSED(closure))
static int TVertex_front_svertex_set(BPy_TVertex *self, PyObject *value, void *UNUSED(closure))
static PyObject * TVertex_get_mate(BPy_TVertex *self, PyObject *args, PyObject *kwds)
Definition: BPy_TVertex.cpp:91
static PyObject * TVertex_id_get(BPy_TVertex *self, void *UNUSED(closure))
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.")
static PyObject * TVertex_back_svertex_get(BPy_TVertex *self, void *UNUSED(closure))
static PyGetSetDef BPy_TVertex_getseters[]
static PyObject * TVertex_get_svertex(BPy_TVertex *self, PyObject *args, PyObject *kwds)
Definition: BPy_TVertex.cpp:64
static int TVertex_init(BPy_TVertex *self, PyObject *args, PyObject *kwds)
Definition: BPy_TVertex.cpp:40
static int TVertex_back_svertex_set(BPy_TVertex *self, PyObject *value, void *UNUSED(closure))
PyTypeObject ViewEdge_Type
PyTypeObject ViewVertex_Type
ATTR_WARN_UNUSED_RESULT const BMVert * v
PyObject * self
Definition: bpy_driver.c:165
inherits from class Rep
Definition: AppCanvas.cpp:18
Definition: BPy_Id.h:28