Blender  V2.93
BPy_ViewEdgeIterator.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_ViewEdgeIterator.h"
22 
23 #include "../BPy_Convert.h"
24 #include "../Interface1D/BPy_ViewEdge.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 using namespace Freestyle;
31 
33 
34 //------------------------INSTANCE METHODS ----------------------------------
35 
36 PyDoc_STRVAR(ViewEdgeIterator_doc,
37  "Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator`\n"
38  "\n"
39  "Base class for iterators over ViewEdges of the :class:`ViewMap` Graph.\n"
40  "Basically the increment() operator of this class should be able to\n"
41  "take the decision of \"where\" (on which ViewEdge) to go when pointing\n"
42  "on a given ViewEdge.\n"
43  "\n"
44  ".. method:: __init__(begin=None, orientation=True)\n"
45  " __init__(brother)\n"
46  "\n"
47  " Builds a ViewEdgeIterator from a starting ViewEdge and its\n"
48  " orientation or the copy constructor.\n"
49  "\n"
50  " :arg begin: The ViewEdge from where to start the iteration.\n"
51  " :type begin: :class:`ViewEdge` or None\n"
52  " :arg orientation: If true, we'll look for the next ViewEdge among\n"
53  " the ViewEdges that surround the ending ViewVertex of begin. If\n"
54  " false, we'll search over the ViewEdges surrounding the ending\n"
55  " ViewVertex of begin.\n"
56  " :type orientation: bool\n"
57  " :arg brother: A ViewEdgeIterator object.\n"
58  " :type brother: :class:`ViewEdgeIterator`");
59 
60 static int check_begin(PyObject *obj, void *v)
61 {
62  if (obj != nullptr && obj != Py_None && !BPy_ViewEdge_Check(obj)) {
63  return 0;
64  }
65  *((PyObject **)v) = obj;
66  return 1;
67 }
68 
69 static int ViewEdgeIterator_init(BPy_ViewEdgeIterator *self, PyObject *args, PyObject *kwds)
70 {
71  static const char *kwlist_1[] = {"brother", nullptr};
72  static const char *kwlist_2[] = {"begin", "orientation", nullptr};
73  PyObject *obj1 = nullptr, *obj2 = nullptr;
74 
75  if (PyArg_ParseTupleAndKeywords(
76  args, kwds, "O!", (char **)kwlist_1, &ViewEdgeIterator_Type, &obj1)) {
77  self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(*(((BPy_ViewEdgeIterator *)obj1)->ve_it));
78  }
79  else if ((void)PyErr_Clear(),
80  (void)(obj1 = obj2 = nullptr),
81  PyArg_ParseTupleAndKeywords(
82  args, kwds, "|O&O!", (char **)kwlist_2, check_begin, &obj1, &PyBool_Type, &obj2)) {
83  ViewEdge *begin = (!obj1 || obj1 == Py_None) ? nullptr : ((BPy_ViewEdge *)obj1)->ve;
84  bool orientation = (!obj2) ? true : bool_from_PyBool(obj2);
85  self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(begin, orientation);
86  }
87  else {
88  PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
89  return -1;
90  }
91  self->py_it.it = self->ve_it;
92  return 0;
93 }
94 
95 PyDoc_STRVAR(ViewEdgeIterator_change_orientation_doc,
96  ".. method:: change_orientation()\n"
97  "\n"
98  " Changes the current orientation.");
99 
101 {
102  self->ve_it->changeOrientation();
103  Py_RETURN_NONE;
104 }
105 
106 static PyMethodDef BPy_ViewEdgeIterator_methods[] = {
107  {"change_orientation",
109  METH_NOARGS,
110  ViewEdgeIterator_change_orientation_doc},
111  {nullptr, nullptr, 0, nullptr},
112 };
113 
114 /*----------------------ViewEdgeIterator get/setters ----------------------------*/
115 
116 PyDoc_STRVAR(ViewEdgeIterator_object_doc,
117  "The ViewEdge object currently pointed by this iterator.\n"
118  "\n"
119  ":type: :class:`ViewEdge`");
120 
121 static PyObject *ViewEdgeIterator_object_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure))
122 {
123  if (!self->ve_it->isEnd()) {
124  PyErr_SetString(PyExc_RuntimeError, "iteration has stopped");
125  return nullptr;
126  }
127  ViewEdge *ve = self->ve_it->operator*();
128  if (ve) {
129  return BPy_ViewEdge_from_ViewEdge(*ve);
130  }
131  Py_RETURN_NONE;
132 }
133 
134 PyDoc_STRVAR(ViewEdgeIterator_current_edge_doc,
135  "The ViewEdge object currently pointed by this iterator.\n"
136  "\n"
137  ":type: :class:`ViewEdge`");
138 
140  void *UNUSED(closure))
141 {
142  ViewEdge *ve = self->ve_it->getCurrentEdge();
143  if (ve) {
144  return BPy_ViewEdge_from_ViewEdge(*ve);
145  }
146  Py_RETURN_NONE;
147 }
148 
150  PyObject *value,
151  void *UNUSED(closure))
152 {
153  if (!BPy_ViewEdge_Check(value)) {
154  PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge");
155  return -1;
156  }
157  self->ve_it->setCurrentEdge(((BPy_ViewEdge *)value)->ve);
158  return 0;
159 }
160 
161 PyDoc_STRVAR(ViewEdgeIterator_orientation_doc,
162  "The orientation of the pointed ViewEdge in the iteration.\n"
163  "If true, the iterator looks for the next ViewEdge among those ViewEdges\n"
164  "that surround the ending ViewVertex of the \"begin\" ViewEdge. If false,\n"
165  "the iterator searches over the ViewEdges surrounding the ending ViewVertex\n"
166  "of the \"begin\" ViewEdge.\n"
167  "\n"
168  ":type: bool");
169 
171  void *UNUSED(closure))
172 {
173  return PyBool_from_bool(self->ve_it->getOrientation());
174 }
175 
177  PyObject *value,
178  void *UNUSED(closure))
179 {
180  if (!PyBool_Check(value)) {
181  PyErr_SetString(PyExc_TypeError, "value must be a boolean");
182  return -1;
183  }
184  self->ve_it->setOrientation(bool_from_PyBool(value));
185  return 0;
186 }
187 
188 PyDoc_STRVAR(ViewEdgeIterator_begin_doc,
189  "The first ViewEdge used for the iteration.\n"
190  "\n"
191  ":type: :class:`ViewEdge`");
192 
193 static PyObject *ViewEdgeIterator_begin_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure))
194 {
195  ViewEdge *ve = self->ve_it->getBegin();
196  if (ve) {
197  return BPy_ViewEdge_from_ViewEdge(*ve);
198  }
199  Py_RETURN_NONE;
200 }
201 
203  PyObject *value,
204  void *UNUSED(closure))
205 {
206  if (!BPy_ViewEdge_Check(value)) {
207  PyErr_SetString(PyExc_TypeError, "value must be a ViewEdge");
208  return -1;
209  }
210  self->ve_it->setBegin(((BPy_ViewEdge *)value)->ve);
211  return 0;
212 }
213 
214 static PyGetSetDef BPy_ViewEdgeIterator_getseters[] = {
215  {"object",
217  (setter) nullptr,
218  ViewEdgeIterator_object_doc,
219  nullptr},
220  {"current_edge",
223  ViewEdgeIterator_current_edge_doc,
224  nullptr},
225  {"orientation",
228  ViewEdgeIterator_orientation_doc,
229  nullptr},
230  {"begin",
233  ViewEdgeIterator_begin_doc,
234  nullptr},
235  {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
236 };
237 
238 /*-----------------------BPy_ViewEdgeIterator type definition ------------------------------*/
239 
240 PyTypeObject ViewEdgeIterator_Type = {
241  PyVarObject_HEAD_INIT(nullptr, 0) "ViewEdgeIterator", /* tp_name */
242  sizeof(BPy_ViewEdgeIterator), /* tp_basicsize */
243  0, /* tp_itemsize */
244  nullptr, /* tp_dealloc */
245  0, /* tp_vectorcall_offset */
246  nullptr, /* tp_getattr */
247  nullptr, /* tp_setattr */
248  nullptr, /* tp_reserved */
249  nullptr, /* tp_repr */
250  nullptr, /* tp_as_number */
251  nullptr, /* tp_as_sequence */
252  nullptr, /* tp_as_mapping */
253  nullptr, /* tp_hash */
254  nullptr, /* tp_call */
255  nullptr, /* tp_str */
256  nullptr, /* tp_getattro */
257  nullptr, /* tp_setattro */
258  nullptr, /* tp_as_buffer */
259  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
260  ViewEdgeIterator_doc, /* tp_doc */
261  nullptr, /* tp_traverse */
262  nullptr, /* tp_clear */
263  nullptr, /* tp_richcompare */
264  0, /* tp_weaklistoffset */
265  nullptr, /* tp_iter */
266  nullptr, /* tp_iternext */
267  BPy_ViewEdgeIterator_methods, /* tp_methods */
268  nullptr, /* tp_members */
269  BPy_ViewEdgeIterator_getseters, /* tp_getset */
270  &Iterator_Type, /* tp_base */
271  nullptr, /* tp_dict */
272  nullptr, /* tp_descr_get */
273  nullptr, /* tp_descr_set */
274  0, /* tp_dictoffset */
275  (initproc)ViewEdgeIterator_init, /* tp_init */
276  nullptr, /* tp_alloc */
277  nullptr, /* tp_new */
278 };
279 
281 
282 #ifdef __cplusplus
283 }
284 #endif
#define UNUSED(x)
PyObject * PyBool_from_bool(bool b)
Definition: BPy_Convert.cpp:73
bool bool_from_PyBool(PyObject *b)
PyObject * BPy_ViewEdge_from_ViewEdge(ViewEdge &ve)
PyTypeObject Iterator_Type
static PyObject * ViewEdgeIterator_orientation_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure))
static int check_begin(PyObject *obj, void *v)
static int ViewEdgeIterator_current_edge_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure))
static PyObject * ViewEdgeIterator_begin_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure))
static int ViewEdgeIterator_init(BPy_ViewEdgeIterator *self, PyObject *args, PyObject *kwds)
static int ViewEdgeIterator_begin_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure))
static PyMethodDef BPy_ViewEdgeIterator_methods[]
PyTypeObject ViewEdgeIterator_Type
static PyGetSetDef BPy_ViewEdgeIterator_getseters[]
static PyObject * ViewEdgeIterator_object_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure))
static int ViewEdgeIterator_orientation_set(BPy_ViewEdgeIterator *self, PyObject *value, void *UNUSED(closure))
PyDoc_STRVAR(ViewEdgeIterator_doc, "Class hierarchy: :class:`Iterator` > :class:`ViewEdgeIterator`\n" "\n" "Base class for iterators over ViewEdges of the :class:`ViewMap` Graph.\n" "Basically the increment() operator of this class should be able to\n" "take the decision of \"where\" (on which ViewEdge) to go when pointing\n" "on a given ViewEdge.\n" "\n" ".. method:: __init__(begin=None, orientation=True)\n" " __init__(brother)\n" "\n" " Builds a ViewEdgeIterator from a starting ViewEdge and its\n" " orientation or the copy constructor.\n" "\n" " :arg begin: The ViewEdge from where to start the iteration.\n" " :type begin: :class:`ViewEdge` or None\n" " :arg orientation: If true, we'll look for the next ViewEdge among\n" " the ViewEdges that surround the ending ViewVertex of begin. If\n" " false, we'll search over the ViewEdges surrounding the ending\n" " ViewVertex of begin.\n" " :type orientation: bool\n" " :arg brother: A ViewEdgeIterator object.\n" " :type brother: :class:`ViewEdgeIterator`")
static PyObject * ViewEdgeIterator_current_edge_get(BPy_ViewEdgeIterator *self, void *UNUSED(closure))
static PyObject * ViewEdgeIterator_change_orientation(BPy_ViewEdgeIterator *self)
#define BPy_ViewEdge_Check(v)
Definition: BPy_ViewEdge.h:35
ATTR_WARN_UNUSED_RESULT const BMVert * v
PyObject * self
Definition: bpy_driver.c:185
inherits from class Rep
Definition: AppCanvas.cpp:32