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