Blender  V2.93
BPy_ViewEdge.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_ViewEdge.h"
22 
23 #include "../BPy_Convert.h"
24 #include "../BPy_Id.h"
25 #include "../BPy_Nature.h"
26 #include "../BPy_ViewShape.h"
27 #include "../Interface0D/BPy_ViewVertex.h"
28 #include "../Interface1D/BPy_FEdge.h"
29 #include "../Interface1D/BPy_ViewEdge.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 using namespace Freestyle;
36 
38 
39 /*----------------------ViewEdge methods ----------------------------*/
40 
42  ViewEdge_doc,
43  "Class hierarchy: :class:`Interface1D` > :class:`ViewEdge`\n"
44  "\n"
45  "Class defining a ViewEdge. A ViewEdge in an edge of the image graph.\n"
46  "it connects two :class:`ViewVertex` objects. It is made by connecting\n"
47  "a set of FEdges.\n"
48  "\n"
49  ".. method:: __init__()\n"
50  " __init__(brother)\n"
51  "\n"
52  " Builds a :class:`ViewEdge` using the default constructor or the copy constructor.\n"
53  "\n"
54  " :arg brother: A ViewEdge object.\n"
55  " :type brother: :class:`ViewEdge`");
56 
57 static int ViewEdge_init(BPy_ViewEdge *self, PyObject *args, PyObject *kwds)
58 {
59  static const char *kwlist[] = {"brother", nullptr};
60  PyObject *brother = nullptr;
61 
62  if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &ViewEdge_Type, &brother)) {
63  return -1;
64  }
65  if (!brother) {
66  self->ve = new ViewEdge();
67  }
68  else {
69  self->ve = new ViewEdge(*(((BPy_ViewEdge *)brother)->ve));
70  }
71  self->py_if1D.if1D = self->ve;
72  self->py_if1D.borrowed = false;
73  return 0;
74 }
75 
76 PyDoc_STRVAR(ViewEdge_update_fedges_doc,
77  ".. method:: update_fedges()\n"
78  "\n"
79  " Sets Viewedge to this for all embedded fedges.\n");
80 
81 static PyObject *ViewEdge_update_fedges(BPy_ViewEdge *self)
82 {
83  self->ve->UpdateFEdges();
84  Py_RETURN_NONE;
85 }
86 
87 static PyMethodDef BPy_ViewEdge_methods[] = {
88  {"update_fedges",
89  (PyCFunction)ViewEdge_update_fedges,
90  METH_NOARGS,
91  ViewEdge_update_fedges_doc},
92  {nullptr, nullptr, 0, nullptr},
93 };
94 
95 /*----------------------ViewEdge get/setters ----------------------------*/
96 
97 PyDoc_STRVAR(ViewEdge_first_viewvertex_doc,
98  "The first ViewVertex.\n"
99  "\n"
100  ":type: :class:`ViewVertex`");
101 
102 static PyObject *ViewEdge_first_viewvertex_get(BPy_ViewEdge *self, void *UNUSED(closure))
103 {
104  ViewVertex *v = self->ve->A();
105  if (v) {
107  }
108  Py_RETURN_NONE;
109 }
110 
112  PyObject *value,
113  void *UNUSED(closure))
114 {
115  if (!BPy_ViewVertex_Check(value)) {
116  return -1;
117  }
118  self->ve->setA(((BPy_ViewVertex *)value)->vv);
119  return 0;
120 }
121 
122 PyDoc_STRVAR(ViewEdge_last_viewvertex_doc,
123  "The second ViewVertex.\n"
124  "\n"
125  ":type: :class:`ViewVertex`");
126 
127 static PyObject *ViewEdge_last_viewvertex_get(BPy_ViewEdge *self, void *UNUSED(closure))
128 {
129  ViewVertex *v = self->ve->B();
130  if (v) {
132  }
133  Py_RETURN_NONE;
134 }
135 
136 static int ViewEdge_last_viewvertex_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
137 {
138  if (!BPy_ViewVertex_Check(value)) {
139  return -1;
140  }
141  self->ve->setB(((BPy_ViewVertex *)value)->vv);
142  return 0;
143 }
144 
145 PyDoc_STRVAR(ViewEdge_first_fedge_doc,
146  "The first FEdge that constitutes this ViewEdge.\n"
147  "\n"
148  ":type: :class:`FEdge`");
149 
150 static PyObject *ViewEdge_first_fedge_get(BPy_ViewEdge *self, void *UNUSED(closure))
151 {
152  FEdge *fe = self->ve->fedgeA();
153  if (fe) {
154  return Any_BPy_FEdge_from_FEdge(*fe);
155  }
156  Py_RETURN_NONE;
157 }
158 
159 static int ViewEdge_first_fedge_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
160 {
161  if (!BPy_FEdge_Check(value)) {
162  return -1;
163  }
164  self->ve->setFEdgeA(((BPy_FEdge *)value)->fe);
165  return 0;
166 }
167 
168 PyDoc_STRVAR(ViewEdge_last_fedge_doc,
169  "The last FEdge that constitutes this ViewEdge.\n"
170  "\n"
171  ":type: :class:`FEdge`");
172 
173 static PyObject *ViewEdge_last_fedge_get(BPy_ViewEdge *self, void *UNUSED(closure))
174 {
175  FEdge *fe = self->ve->fedgeB();
176  if (fe) {
177  return Any_BPy_FEdge_from_FEdge(*fe);
178  }
179  Py_RETURN_NONE;
180 }
181 
182 static int ViewEdge_last_fedge_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
183 {
184  if (!BPy_FEdge_Check(value)) {
185  return -1;
186  }
187  self->ve->setFEdgeB(((BPy_FEdge *)value)->fe);
188  return 0;
189 }
190 
191 PyDoc_STRVAR(ViewEdge_viewshape_doc,
192  "The ViewShape to which this ViewEdge belongs to.\n"
193  "\n"
194  ":type: :class:`ViewShape`");
195 
196 static PyObject *ViewEdge_viewshape_get(BPy_ViewEdge *self, void *UNUSED(closure))
197 {
198  ViewShape *vs = self->ve->viewShape();
199  if (vs) {
200  return BPy_ViewShape_from_ViewShape(*vs);
201  }
202  Py_RETURN_NONE;
203 }
204 
205 static int ViewEdge_viewshape_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
206 {
207  if (!BPy_ViewShape_Check(value)) {
208  return -1;
209  }
210  self->ve->setShape(((BPy_ViewShape *)value)->vs);
211  return 0;
212 }
213 
214 PyDoc_STRVAR(ViewEdge_occludee_doc,
215  "The shape that is occluded by the ViewShape to which this ViewEdge\n"
216  "belongs to. If no object is occluded, this property is set to None.\n"
217  "\n"
218  ":type: :class:`ViewShape`");
219 
220 static PyObject *ViewEdge_occludee_get(BPy_ViewEdge *self, void *UNUSED(closure))
221 {
222  ViewShape *vs = self->ve->aShape();
223  if (vs) {
224  return BPy_ViewShape_from_ViewShape(*vs);
225  }
226  Py_RETURN_NONE;
227 }
228 
229 static int ViewEdge_occludee_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
230 {
231  if (!BPy_ViewShape_Check(value)) {
232  return -1;
233  }
234  self->ve->setaShape(((BPy_ViewShape *)value)->vs);
235  return 0;
236 }
237 
238 PyDoc_STRVAR(ViewEdge_is_closed_doc,
239  "True if this ViewEdge forms a closed loop.\n"
240  "\n"
241  ":type: bool");
242 
243 static PyObject *ViewEdge_is_closed_get(BPy_ViewEdge *self, void *UNUSED(closure))
244 {
245  return PyBool_from_bool(self->ve->isClosed());
246 }
247 
248 PyDoc_STRVAR(ViewEdge_id_doc,
249  "The Id of this ViewEdge.\n"
250  "\n"
251  ":type: :class:`Id`");
252 
253 static PyObject *ViewEdge_id_get(BPy_ViewEdge *self, void *UNUSED(closure))
254 {
255  Id id(self->ve->getId());
256  return BPy_Id_from_Id(id); // return a copy
257 }
258 
259 static int ViewEdge_id_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
260 {
261  if (!BPy_Id_Check(value)) {
262  PyErr_SetString(PyExc_TypeError, "value must be an Id");
263  return -1;
264  }
265  self->ve->setId(*(((BPy_Id *)value)->id));
266  return 0;
267 }
268 
269 PyDoc_STRVAR(ViewEdge_nature_doc,
270  "The nature of this ViewEdge.\n"
271  "\n"
272  ":type: :class:`Nature`");
273 
274 static PyObject *ViewEdge_nature_get(BPy_ViewEdge *self, void *UNUSED(closure))
275 {
276  return BPy_Nature_from_Nature(self->ve->getNature());
277 }
278 
279 static int ViewEdge_nature_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
280 {
281  if (!BPy_Nature_Check(value)) {
282  PyErr_SetString(PyExc_TypeError, "value must be a Nature");
283  return -1;
284  }
285  self->ve->setNature(PyLong_AsLong((PyObject *)&((BPy_Nature *)value)->i));
286  return 0;
287 }
288 
289 PyDoc_STRVAR(ViewEdge_qi_doc,
290  "The quantitative invisibility.\n"
291  "\n"
292  ":type: int");
293 
294 static PyObject *ViewEdge_qi_get(BPy_ViewEdge *self, void *UNUSED(closure))
295 {
296  return PyLong_FromLong(self->ve->qi());
297 }
298 
299 static int ViewEdge_qi_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
300 {
301  int qi;
302 
303  if ((qi = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) {
304  return -1;
305  }
306  self->ve->setQI(qi);
307  return 0;
308 }
309 
310 PyDoc_STRVAR(ViewEdge_chaining_time_stamp_doc,
311  "The time stamp of this ViewEdge.\n"
312  "\n"
313  ":type: int");
314 
315 static PyObject *ViewEdge_chaining_time_stamp_get(BPy_ViewEdge *self, void *UNUSED(closure))
316 {
317  return PyLong_FromLong(self->ve->getChainingTimeStamp());
318 }
319 
321  PyObject *value,
322  void *UNUSED(closure))
323 {
324  int timestamp;
325 
326  if ((timestamp = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) {
327  return -1;
328  }
329  self->ve->setChainingTimeStamp(timestamp);
330  return 0;
331 }
332 
333 static PyGetSetDef BPy_ViewEdge_getseters[] = {
334  {"first_viewvertex",
337  ViewEdge_first_viewvertex_doc,
338  nullptr},
339  {"last_viewvertex",
342  ViewEdge_last_viewvertex_doc,
343  nullptr},
344  {"first_fedge",
345  (getter)ViewEdge_first_fedge_get,
346  (setter)ViewEdge_first_fedge_set,
347  ViewEdge_first_fedge_doc,
348  nullptr},
349  {"last_fedge",
350  (getter)ViewEdge_last_fedge_get,
351  (setter)ViewEdge_last_fedge_set,
352  ViewEdge_last_fedge_doc,
353  nullptr},
354  {"viewshape",
355  (getter)ViewEdge_viewshape_get,
356  (setter)ViewEdge_viewshape_set,
357  ViewEdge_viewshape_doc,
358  nullptr},
359  {"occludee",
360  (getter)ViewEdge_occludee_get,
361  (setter)ViewEdge_occludee_set,
362  ViewEdge_occludee_doc,
363  nullptr},
364  {"is_closed",
365  (getter)ViewEdge_is_closed_get,
366  (setter) nullptr,
367  ViewEdge_is_closed_doc,
368  nullptr},
369  {"id", (getter)ViewEdge_id_get, (setter)ViewEdge_id_set, ViewEdge_id_doc, nullptr},
370  {"nature",
371  (getter)ViewEdge_nature_get,
372  (setter)ViewEdge_nature_set,
373  ViewEdge_nature_doc,
374  nullptr},
375  {"qi", (getter)ViewEdge_qi_get, (setter)ViewEdge_qi_set, ViewEdge_qi_doc, nullptr},
376  {"chaining_time_stamp",
379  ViewEdge_chaining_time_stamp_doc,
380  nullptr},
381  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
382 };
383 
384 /*-----------------------BPy_ViewEdge type definition ------------------------------*/
385 
386 PyTypeObject ViewEdge_Type = {
387  PyVarObject_HEAD_INIT(nullptr, 0) "ViewEdge", /* tp_name */
388  sizeof(BPy_ViewEdge), /* tp_basicsize */
389  0, /* tp_itemsize */
390  nullptr, /* tp_dealloc */
391  0, /* tp_vectorcall_offset */
392  nullptr, /* tp_getattr */
393  nullptr, /* tp_setattr */
394  nullptr, /* tp_reserved */
395  nullptr, /* tp_repr */
396  nullptr, /* tp_as_number */
397  nullptr, /* tp_as_sequence */
398  nullptr, /* tp_as_mapping */
399  nullptr, /* tp_hash */
400  nullptr, /* tp_call */
401  nullptr, /* tp_str */
402  nullptr, /* tp_getattro */
403  nullptr, /* tp_setattro */
404  nullptr, /* tp_as_buffer */
405  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
406  ViewEdge_doc, /* tp_doc */
407  nullptr, /* tp_traverse */
408  nullptr, /* tp_clear */
409  nullptr, /* tp_richcompare */
410  0, /* tp_weaklistoffset */
411  nullptr, /* tp_iter */
412  nullptr, /* tp_iternext */
413  BPy_ViewEdge_methods, /* tp_methods */
414  nullptr, /* tp_members */
415  BPy_ViewEdge_getseters, /* tp_getset */
416  &Interface1D_Type, /* tp_base */
417  nullptr, /* tp_dict */
418  nullptr, /* tp_descr_get */
419  nullptr, /* tp_descr_set */
420  0, /* tp_dictoffset */
421  (initproc)ViewEdge_init, /* tp_init */
422  nullptr, /* tp_alloc */
423  nullptr, /* tp_new */
424 };
425 
427 
428 #ifdef __cplusplus
429 }
430 #endif
#define UNUSED(x)
PyObject * PyBool_from_bool(bool b)
Definition: BPy_Convert.cpp:73
PyObject * BPy_ViewShape_from_ViewShape(ViewShape &vs)
PyObject * Any_BPy_FEdge_from_FEdge(FEdge &fe)
PyObject * BPy_Id_from_Id(Id &id)
PyObject * BPy_Nature_from_Nature(unsigned short n)
PyObject * Any_BPy_ViewVertex_from_ViewVertex(ViewVertex &vv)
#define BPy_FEdge_Check(v)
Definition: BPy_FEdge.h:35
#define BPy_Id_Check(v)
Definition: BPy_Id.h:39
PyTypeObject Interface1D_Type
#define BPy_Nature_Check(v)
Definition: BPy_Nature.h:37
static PyObject * ViewEdge_last_fedge_get(BPy_ViewEdge *self, void *UNUSED(closure))
static PyObject * ViewEdge_first_fedge_get(BPy_ViewEdge *self, void *UNUSED(closure))
static int ViewEdge_last_viewvertex_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
static PyGetSetDef BPy_ViewEdge_getseters[]
static PyObject * ViewEdge_update_fedges(BPy_ViewEdge *self)
static int ViewEdge_qi_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
static PyObject * ViewEdge_id_get(BPy_ViewEdge *self, void *UNUSED(closure))
static PyObject * ViewEdge_first_viewvertex_get(BPy_ViewEdge *self, void *UNUSED(closure))
static int ViewEdge_chaining_time_stamp_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
static PyObject * ViewEdge_nature_get(BPy_ViewEdge *self, void *UNUSED(closure))
static PyObject * ViewEdge_viewshape_get(BPy_ViewEdge *self, void *UNUSED(closure))
static PyObject * ViewEdge_qi_get(BPy_ViewEdge *self, void *UNUSED(closure))
static int ViewEdge_last_fedge_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
static PyObject * ViewEdge_is_closed_get(BPy_ViewEdge *self, void *UNUSED(closure))
static int ViewEdge_occludee_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
static int ViewEdge_init(BPy_ViewEdge *self, PyObject *args, PyObject *kwds)
static int ViewEdge_id_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
static PyObject * ViewEdge_occludee_get(BPy_ViewEdge *self, void *UNUSED(closure))
static PyObject * ViewEdge_last_viewvertex_get(BPy_ViewEdge *self, void *UNUSED(closure))
static PyMethodDef BPy_ViewEdge_methods[]
static int ViewEdge_first_viewvertex_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
static int ViewEdge_nature_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
PyDoc_STRVAR(ViewEdge_doc, "Class hierarchy: :class:`Interface1D` > :class:`ViewEdge`\n" "\n" "Class defining a ViewEdge. A ViewEdge in an edge of the image graph.\n" "it connects two :class:`ViewVertex` objects. It is made by connecting\n" "a set of FEdges.\n" "\n" ".. method:: __init__()\n" " __init__(brother)\n" "\n" " Builds a :class:`ViewEdge` using the default constructor or the copy constructor.\n" "\n" " :arg brother: A ViewEdge object.\n" " :type brother: :class:`ViewEdge`")
static int ViewEdge_first_fedge_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
static PyObject * ViewEdge_chaining_time_stamp_get(BPy_ViewEdge *self, void *UNUSED(closure))
static int ViewEdge_viewshape_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure))
PyTypeObject ViewEdge_Type
#define BPy_ViewShape_Check(v)
Definition: BPy_ViewShape.h:39
#define BPy_ViewVertex_Check(v)
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