Blender V5.3
BPy_FEdge.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_FEdge.h"
10
11#include "../BPy_Convert.h"
12#include "../BPy_Id.h"
13#include "../BPy_Nature.h"
16
17using namespace Freestyle;
18
20
21/*----------------------FEdge methods ----------------------------*/
22
24 /* Wrap. */
25 FEdge_doc,
26 "Class hierarchy: :class:`Interface1D` > :class:`FEdge`\n"
27 "\n"
28 "Base Class for feature edges. This FEdge can represent a silhouette,\n"
29 "a crease, a ridge/valley, a border or a suggestive contour. For\n"
30 "silhouettes, the FEdge is oriented so that the visible face lies on\n"
31 "the left of the edge. For borders, the FEdge is oriented so that the\n"
32 "face lies on the left of the edge. An FEdge can represent an initial\n"
33 "edge of the mesh or runs across a face of the initial mesh depending\n"
34 "on the smoothness or sharpness of the mesh. This class is specialized\n"
35 "into a smooth and a sharp version since their properties slightly vary\n"
36 "from one to the other.\n"
37 "\n"
38 ".. method:: FEdge(*args)\n"
39 "\n"
40 " Accepted call signatures:\n"
41 "\n"
42 " - ``FEdge()``\n"
43 " - ``FEdge(brother)``\n"
44 "\n"
45 " Builds an :class:`FEdge` using the default constructor,\n"
46 " copy constructor, or between two :class:`SVertex` objects.\n"
47 "\n"
48 " :param brother: An FEdge object.\n"
49 " :type brother: :class:`FEdge`\n"
50 " :param first_vertex: The first SVertex.\n"
51 " :type first_vertex: :class:`SVertex`\n"
52 " :param second_vertex: The second SVertex.\n"
53 " :type second_vertex: :class:`SVertex`\n");
54static int FEdge_init(BPy_FEdge *self, PyObject *args, PyObject *kwds)
55{
56 static const char *kwlist_1[] = {"brother", nullptr};
57 static const char *kwlist_2[] = {"first_vertex", "second_vertex", nullptr};
58 PyObject *obj1 = nullptr, *obj2 = nullptr;
59
60 if (PyArg_ParseTupleAndKeywords(args,
61 kwds,
62 "|" /* Optional arguments. */
63 "O!" /* `brother` */
64 ":__init__",
65 (char **)kwlist_1,
67 &obj1))
68 {
69 if (!obj1) {
70 self->fe = new FEdge();
71 }
72 else {
73 self->fe = new FEdge(*(((BPy_FEdge *)obj1)->fe));
74 }
75 }
76 else if ((void)PyErr_Clear(),
77 PyArg_ParseTupleAndKeywords(args,
78 kwds,
79 "O!" /* `first_vertex` */
80 "O!" /* `second_vertex` */
81 ":__init__",
82 (char **)kwlist_2,
84 &obj1,
86 &obj2))
87 {
88 self->fe = new FEdge(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv);
89 }
90 else {
91 PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
92 return -1;
93 }
94 self->py_if1D.if1D = self->fe;
95 self->py_if1D.borrowed = false;
96 return 0;
97}
98
99/*----------------------FEdge sequence protocol ----------------------------*/
100
101static Py_ssize_t FEdge_sq_length(BPy_FEdge * /*self*/)
102{
103 return 2;
104}
105
106static PyObject *FEdge_sq_item(BPy_FEdge *self, Py_ssize_t keynum)
107{
108 if (keynum < 0) {
109 keynum += FEdge_sq_length(self);
110 }
111 if (ELEM(keynum, 0, 1)) {
112 SVertex *v = self->fe->operator[](keynum);
113 if (v) {
114 return BPy_SVertex_from_SVertex(*v);
115 }
116 Py_RETURN_NONE;
117 }
118 PyErr_Format(PyExc_IndexError, "FEdge[index]: index %d out of range", keynum);
119 return nullptr;
120}
121
122static PySequenceMethods BPy_FEdge_as_sequence = {
123 /*sq_length*/ (lenfunc)FEdge_sq_length,
124 /*sq_concat*/ nullptr,
125 /*sq_repeat*/ nullptr,
126 /*sq_item*/ (ssizeargfunc)FEdge_sq_item,
127 /*was_sq_slice*/ nullptr, /* DEPRECATED. */
128 /*sq_ass_item*/ nullptr,
129 /*was_sq_ass_slice*/ nullptr, /* DEPRECATED. */
130 /*sq_contains*/ nullptr,
131 /*sq_inplace_concat*/ nullptr,
132 /*sq_inplace_repeat*/ nullptr,
133};
134
135/*----------------------FEdge get/setters ----------------------------*/
136
138 /* Wrap. */
139 FEdge_first_svertex_doc,
140 "The first SVertex constituting this FEdge.\n"
141 "\n"
142 ":type: :class:`SVertex`\n");
143static PyObject *FEdge_first_svertex_get(BPy_FEdge *self, void * /*closure*/)
144{
145 SVertex *A = self->fe->vertexA();
146 if (A) {
148 }
149 Py_RETURN_NONE;
150}
151
152static int FEdge_first_svertex_set(BPy_FEdge *self, PyObject *value, void * /*closure*/)
153{
154 if (!BPy_SVertex_Check(value)) {
155 PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
156 return -1;
157 }
158 self->fe->setVertexA(((BPy_SVertex *)value)->sv);
159 return 0;
160}
161
163 /* Wrap. */
164 FEdge_second_svertex_doc,
165 "The second SVertex constituting this FEdge.\n"
166 "\n"
167 ":type: :class:`SVertex`\n");
168static PyObject *FEdge_second_svertex_get(BPy_FEdge *self, void * /*closure*/)
169{
170 SVertex *B = self->fe->vertexB();
171 if (B) {
173 }
174 Py_RETURN_NONE;
175}
176
177static int FEdge_second_svertex_set(BPy_FEdge *self, PyObject *value, void * /*closure*/)
178{
179 if (!BPy_SVertex_Check(value)) {
180 PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
181 return -1;
182 }
183 self->fe->setVertexB(((BPy_SVertex *)value)->sv);
184 return 0;
185}
186
188 /* Wrap. */
189 FEdge_next_fedge_doc,
190 "The FEdge following this one in the ViewEdge. The value is None if\n"
191 "this FEdge is the last of the ViewEdge.\n"
192 "\n"
193 ":type: :class:`FEdge`\n");
194static PyObject *FEdge_next_fedge_get(BPy_FEdge *self, void * /*closure*/)
195{
196 FEdge *fe = self->fe->nextEdge();
197 if (fe) {
198 return Any_BPy_FEdge_from_FEdge(*fe);
199 }
200 Py_RETURN_NONE;
201}
202
203static int FEdge_next_fedge_set(BPy_FEdge *self, PyObject *value, void * /*closure*/)
204{
205 if (!BPy_FEdge_Check(value)) {
206 PyErr_SetString(PyExc_TypeError, "value must be an FEdge");
207 return -1;
208 }
209 self->fe->setNextEdge(((BPy_FEdge *)value)->fe);
210 return 0;
211}
212
214 /* Wrap. */
215 FEdge_previous_fedge_doc,
216 "The FEdge preceding this one in the ViewEdge. The value is None if\n"
217 "this FEdge is the first one of the ViewEdge.\n"
218 "\n"
219 ":type: :class:`FEdge`\n");
220static PyObject *FEdge_previous_fedge_get(BPy_FEdge *self, void * /*closure*/)
221{
222 FEdge *fe = self->fe->previousEdge();
223 if (fe) {
224 return Any_BPy_FEdge_from_FEdge(*fe);
225 }
226 Py_RETURN_NONE;
227}
228
229static int FEdge_previous_fedge_set(BPy_FEdge *self, PyObject *value, void * /*closure*/)
230{
231 if (!BPy_FEdge_Check(value)) {
232 PyErr_SetString(PyExc_TypeError, "value must be an FEdge");
233 return -1;
234 }
235 self->fe->setPreviousEdge(((BPy_FEdge *)value)->fe);
236 return 0;
237}
238
240 /* Wrap. */
241 FEdge_viewedge_doc,
242 "The ViewEdge to which this FEdge belongs to.\n"
243 "\n"
244 ":type: :class:`ViewEdge`\n");
245static PyObject *FEdge_viewedge_get(BPy_FEdge *self, void * /*closure*/)
246{
247 ViewEdge *ve = self->fe->viewedge();
248 if (ve) {
249 return BPy_ViewEdge_from_ViewEdge(*ve);
250 }
251 Py_RETURN_NONE;
252}
253
254static int FEdge_viewedge_set(BPy_FEdge *self, PyObject *value, void * /*closure*/)
255{
256 if (!BPy_ViewEdge_Check(value)) {
257 PyErr_SetString(PyExc_TypeError, "value must be an ViewEdge");
258 return -1;
259 }
260 self->fe->setViewEdge(((BPy_ViewEdge *)value)->ve);
261 return 0;
262}
263
265 /* Wrap. */
266 FEdge_is_smooth_doc,
267 "True if this FEdge is a smooth FEdge.\n"
268 "\n"
269 ":type: bool\n");
270static PyObject *FEdge_is_smooth_get(BPy_FEdge *self, void * /*closure*/)
271{
272 return PyBool_from_bool(self->fe->isSmooth());
273}
274
275static int FEdge_is_smooth_set(BPy_FEdge *self, PyObject *value, void * /*closure*/)
276{
277 if (!PyBool_Check(value)) {
278 PyErr_SetString(PyExc_TypeError, "value must be boolean");
279 return -1;
280 }
281 self->fe->setSmooth(bool_from_PyBool(value));
282 return 0;
283}
284
286 /* Wrap. */
287 FEdge_id_doc,
288 "The Id of this FEdge.\n"
289 "\n"
290 ":type: :class:`Id`\n");
291static PyObject *FEdge_id_get(BPy_FEdge *self, void * /*closure*/)
292{
293 Id id(self->fe->getId());
294 return BPy_Id_from_Id(id); // return a copy
295}
296
297static int FEdge_id_set(BPy_FEdge *self, PyObject *value, void * /*closure*/)
298{
299 if (!BPy_Id_Check(value)) {
300 PyErr_SetString(PyExc_TypeError, "value must be an Id");
301 return -1;
302 }
303 self->fe->setId(*(((BPy_Id *)value)->id));
304 return 0;
305}
306
308 /* Wrap. */
309 FEdge_nature_doc,
310 "The nature of this FEdge.\n"
311 "\n"
312 ":type: :class:`Nature`\n");
313static PyObject *FEdge_nature_get(BPy_FEdge *self, void * /*closure*/)
314{
315 return BPy_Nature_from_Nature(self->fe->getNature());
316}
317
318static int FEdge_nature_set(BPy_FEdge *self, PyObject *value, void * /*closure*/)
319{
320 if (!BPy_Nature_Check(value)) {
321 PyErr_SetString(PyExc_TypeError, "value must be a Nature");
322 return -1;
323 }
324 self->fe->setNature(PyLong_AsLong((PyObject *)&((BPy_Nature *)value)->i));
325 return 0;
326}
327
328static PyGetSetDef BPy_FEdge_getseters[] = {
329 {"first_svertex",
332 FEdge_first_svertex_doc,
333 nullptr},
334 {"second_svertex",
337 FEdge_second_svertex_doc,
338 nullptr},
339 {"next_fedge",
340 (getter)FEdge_next_fedge_get,
341 (setter)FEdge_next_fedge_set,
342 FEdge_next_fedge_doc,
343 nullptr},
344 {"previous_fedge",
347 FEdge_previous_fedge_doc,
348 nullptr},
349 {"viewedge",
350 (getter)FEdge_viewedge_get,
351 (setter)FEdge_viewedge_set,
352 FEdge_viewedge_doc,
353 nullptr},
354 {"is_smooth",
355 (getter)FEdge_is_smooth_get,
356 (setter)FEdge_is_smooth_set,
357 FEdge_is_smooth_doc,
358 nullptr},
359 {"id", (getter)FEdge_id_get, (setter)FEdge_id_set, FEdge_id_doc, nullptr},
360 {"nature", (getter)FEdge_nature_get, (setter)FEdge_nature_set, FEdge_nature_doc, nullptr},
361 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
362};
363
364/*-----------------------BPy_FEdge type definition ------------------------------*/
365
366PyTypeObject FEdge_Type = {
367 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
368 /*tp_name*/ "FEdge",
369 /*tp_basicsize*/ sizeof(BPy_FEdge),
370 /*tp_itemsize*/ 0,
371 /*tp_dealloc*/ nullptr,
372 /*tp_vectorcall_offset*/ 0,
373 /*tp_getattr*/ nullptr,
374 /*tp_setattr*/ nullptr,
375 /*tp_as_async*/ nullptr,
376 /*tp_repr*/ nullptr,
377 /*tp_as_number*/ nullptr,
378 /*tp_as_sequence*/ &BPy_FEdge_as_sequence,
379 /*tp_as_mapping*/ nullptr,
380 /*tp_hash*/ nullptr,
381 /*tp_call*/ nullptr,
382 /*tp_str*/ nullptr,
383 /*tp_getattro*/ nullptr,
384 /*tp_setattro*/ nullptr,
385 /*tp_as_buffer*/ nullptr,
386 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
387 /*tp_doc*/ FEdge_doc,
388 /*tp_traverse*/ nullptr,
389 /*tp_clear*/ nullptr,
390 /*tp_richcompare*/ nullptr,
391 /*tp_weaklistoffset*/ 0,
392 /*tp_iter*/ nullptr,
393 /*tp_iternext*/ nullptr,
394 /*tp_methods*/ nullptr,
395 /*tp_members*/ nullptr,
396 /*tp_getset*/ BPy_FEdge_getseters,
397 /*tp_base*/ &Interface1D_Type,
398 /*tp_dict*/ nullptr,
399 /*tp_descr_get*/ nullptr,
400 /*tp_descr_set*/ nullptr,
401 /*tp_dictoffset*/ 0,
402 /*tp_init*/ (initproc)FEdge_init,
403 /*tp_alloc*/ nullptr,
404 /*tp_new*/ nullptr,
405};
406
PyObject * BPy_Id_from_Id(Id &id)
bool bool_from_PyBool(PyObject *b)
PyObject * Any_BPy_FEdge_from_FEdge(FEdge &fe)
PyObject * BPy_Nature_from_Nature(ushort n)
PyObject * BPy_SVertex_from_SVertex(SVertex &sv)
PyObject * BPy_ViewEdge_from_ViewEdge(ViewEdge &ve)
PyObject * PyBool_from_bool(bool b)
static int FEdge_viewedge_set(BPy_FEdge *self, PyObject *value, void *)
static int FEdge_previous_fedge_set(BPy_FEdge *self, PyObject *value, void *)
static PyObject * FEdge_id_get(BPy_FEdge *self, void *)
static PyObject * FEdge_viewedge_get(BPy_FEdge *self, void *)
static PyObject * FEdge_first_svertex_get(BPy_FEdge *self, void *)
static PyObject * FEdge_is_smooth_get(BPy_FEdge *self, void *)
static int FEdge_is_smooth_set(BPy_FEdge *self, PyObject *value, void *)
static int FEdge_first_svertex_set(BPy_FEdge *self, PyObject *value, void *)
static PySequenceMethods BPy_FEdge_as_sequence
static PyObject * FEdge_previous_fedge_get(BPy_FEdge *self, void *)
PyTypeObject FEdge_Type
static PyObject * FEdge_second_svertex_get(BPy_FEdge *self, void *)
static PyObject * FEdge_nature_get(BPy_FEdge *self, void *)
static PyObject * FEdge_sq_item(BPy_FEdge *self, Py_ssize_t keynum)
static int FEdge_nature_set(BPy_FEdge *self, PyObject *value, void *)
static Py_ssize_t FEdge_sq_length(BPy_FEdge *)
static int FEdge_id_set(BPy_FEdge *self, PyObject *value, void *)
static int FEdge_init(BPy_FEdge *self, PyObject *args, PyObject *kwds)
Definition BPy_FEdge.cpp:54
static PyObject * FEdge_next_fedge_get(BPy_FEdge *self, void *)
static int FEdge_next_fedge_set(BPy_FEdge *self, PyObject *value, void *)
static int FEdge_second_svertex_set(BPy_FEdge *self, PyObject *value, void *)
static PyGetSetDef BPy_FEdge_getseters[]
#define BPy_FEdge_Check(v)
Definition BPy_FEdge.h:19
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
PyTypeObject Interface1D_Type
#define BPy_Nature_Check(v)
Definition BPy_Nature.h:21
PyTypeObject SVertex_Type
#define BPy_SVertex_Check(v)
Definition BPy_SVertex.h:19
#define BPy_ViewEdge_Check(v)
#define ELEM(...)
#define A
virtual Id getId() const
Definition Silhouette.h:481
ViewEdge * viewedge() const
Definition Silhouette.h:654
void setVertexB(SVertex *vB)
Definition Silhouette.h:725
void setId(const Id &id)
Definition Silhouette.h:731
FEdge * nextEdge()
Definition Silhouette.h:619
SVertex * vertexA()
Definition Silhouette.h:593
void setViewEdge(ViewEdge *iViewEdge)
Definition Silhouette.h:762
SVertex * vertexB()
Definition Silhouette.h:599
void setNextEdge(FEdge *iEdge)
Definition Silhouette.h:737
void setNature(Nature::EdgeNature iNature)
Definition Silhouette.h:749
void setSmooth(bool iFlag)
Definition Silhouette.h:802
void setPreviousEdge(FEdge *iEdge)
Definition Silhouette.h:743
FEdge * previousEdge()
Definition Silhouette.h:627
bool isSmooth() const
Definition Silhouette.h:702
void setVertexA(SVertex *vA)
Definition Silhouette.h:719
Nature::EdgeNature getNature() const
Definition Silhouette.h:611
#define B
inherits from class Rep
Definition AppCanvas.cpp:20
BPy_Interface1D py_if1D
Definition BPy_FEdge.h:23
Freestyle::FEdge * fe
Definition BPy_FEdge.h:24
PyObject_HEAD Freestyle::Interface1D * if1D