Blender  V3.3
BPy_ChainPredicateIterator.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
8 
9 #include "../BPy_BinaryPredicate1D.h"
10 #include "../BPy_Convert.h"
11 #include "../BPy_UnaryPredicate1D.h"
12 #include "../Interface1D/BPy_ViewEdge.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 using namespace Freestyle;
19 
21 
22 //------------------------INSTANCE METHODS ----------------------------------
23 
25  ChainPredicateIterator_doc,
26 
27  "Class hierarchy: :class:`freestyle.types.Iterator` >\n"
28  ":class:`freestyle.types.ViewEdgeIterator` >\n"
29  ":class:`freestyle.types.ChainingIterator` >\n"
30  ":class:`ChainPredicateIterator`\n"
31  "\n"
32  "A \"generic\" user-controlled ViewEdge iterator. This iterator is in\n"
33  "particular built from a unary predicate and a binary predicate.\n"
34  "First, the unary predicate is evaluated for all potential next\n"
35  "ViewEdges in order to only keep the ones respecting a certain\n"
36  "constraint. Then, the binary predicate is evaluated on the current\n"
37  "ViewEdge together with each ViewEdge of the previous selection. The\n"
38  "first ViewEdge respecting both the unary predicate and the binary\n"
39  "predicate is kept as the next one. If none of the potential next\n"
40  "ViewEdge respects these two predicates, None is returned.\n"
41  "\n"
42  ".. method:: __init__(upred, bpred, restrict_to_selection=True, "
43  " restrict_to_unvisited=True, begin=None, "
44  " orientation=True)\n"
45  " __init__(brother)\n"
46  "\n"
47  " Builds a ChainPredicateIterator from a unary predicate, a binary\n"
48  " predicate, a starting ViewEdge and its orientation or using the copy constructor.\n"
49  "\n"
50  " :arg upred: The unary predicate that the next ViewEdge must satisfy.\n"
51  " :type upred: :class:`freestyle.types.UnaryPredicate1D`\n"
52  " :arg bpred: The binary predicate that the next ViewEdge must\n"
53  " satisfy together with the actual pointed ViewEdge.\n"
54  " :type bpred: :class:`freestyle.types.BinaryPredicate1D`\n"
55  " :arg restrict_to_selection: Indicates whether to force the chaining\n"
56  " to stay within the set of selected ViewEdges or not.\n"
57  " :type restrict_to_selection: bool\n"
58  " :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n"
59  " already been chained must be ignored ot not.\n"
60  " :type restrict_to_unvisited: bool\n"
61  " :arg begin: The ViewEdge from where to start the iteration.\n"
62  " :type begin: :class:`freestyle.types.ViewEdge` or None\n"
63  " :arg orientation: If true, we'll look for the next ViewEdge among\n"
64  " the ViewEdges that surround the ending ViewVertex of begin. If\n"
65  " false, we'll search over the ViewEdges surrounding the ending\n"
66  " ViewVertex of begin.\n"
67  " :type orientation: bool\n"
68  " :arg brother: A ChainPredicateIterator object.\n"
69  " :type brother: :class:`ChainPredicateIterator`");
70 
71 static int check_begin(PyObject *obj, void *v)
72 {
73  if (obj != nullptr && obj != Py_None && !BPy_ViewEdge_Check(obj)) {
74  return 0;
75  }
76  *((PyObject **)v) = obj;
77  return 1;
78 }
79 
81  PyObject *args,
82  PyObject *kwds)
83 {
84  static const char *kwlist_1[] = {"brother", nullptr};
85  static const char *kwlist_2[] = {"upred",
86  "bpred",
87  "restrict_to_selection",
88  "restrict_to_unvisited",
89  "begin",
90  "orientation",
91  nullptr};
92  PyObject *obj1 = nullptr, *obj2 = nullptr, *obj3 = nullptr, *obj4 = nullptr, *obj5 = nullptr,
93  *obj6 = nullptr;
94 
95  if (PyArg_ParseTupleAndKeywords(
96  args, kwds, "O!", (char **)kwlist_1, &ChainPredicateIterator_Type, &obj1)) {
97  self->cp_it = new ChainPredicateIterator(*(((BPy_ChainPredicateIterator *)obj1)->cp_it));
98  self->upred = ((BPy_ChainPredicateIterator *)obj1)->upred;
99  self->bpred = ((BPy_ChainPredicateIterator *)obj1)->bpred;
100  Py_INCREF(self->upred);
101  Py_INCREF(self->bpred);
102  }
103  else if ((void)PyErr_Clear(),
104  (void)(obj3 = obj4 = obj5 = obj6 = nullptr),
105  PyArg_ParseTupleAndKeywords(args,
106  kwds,
107  "O!O!|O!O!O&O!",
108  (char **)kwlist_2,
110  &obj1,
112  &obj2,
113  &PyBool_Type,
114  &obj3,
115  &PyBool_Type,
116  &obj4,
117  check_begin,
118  &obj5,
119  &PyBool_Type,
120  &obj6)) {
121  UnaryPredicate1D *up1D = ((BPy_UnaryPredicate1D *)obj1)->up1D;
122  BinaryPredicate1D *bp1D = ((BPy_BinaryPredicate1D *)obj2)->bp1D;
123  bool restrict_to_selection = (!obj3) ? true : bool_from_PyBool(obj3);
124  bool restrict_to_unvisited = (!obj4) ? true : bool_from_PyBool(obj4);
125  ViewEdge *begin = (!obj5 || obj5 == Py_None) ? nullptr : ((BPy_ViewEdge *)obj5)->ve;
126  bool orientation = (!obj6) ? true : bool_from_PyBool(obj6);
127  self->cp_it = new ChainPredicateIterator(
128  *up1D, *bp1D, restrict_to_selection, restrict_to_unvisited, begin, orientation);
129  self->upred = obj1;
130  self->bpred = obj2;
131  Py_INCREF(self->upred);
132  Py_INCREF(self->bpred);
133  }
134  else {
135  PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
136  return -1;
137  }
138  self->py_c_it.c_it = self->cp_it;
139  self->py_c_it.py_ve_it.ve_it = self->cp_it;
140  self->py_c_it.py_ve_it.py_it.it = self->cp_it;
141  return 0;
142 }
143 
145 {
146  Py_XDECREF(self->upred);
147  Py_XDECREF(self->bpred);
148  ChainingIterator_Type.tp_dealloc((PyObject *)self);
149 }
150 
151 /*-----------------------BPy_ChainPredicateIterator type definition ----------------------------*/
152 
154  PyVarObject_HEAD_INIT(nullptr, 0) "ChainPredicateIterator", /* tp_name */
155  sizeof(BPy_ChainPredicateIterator), /* tp_basicsize */
156  0, /* tp_itemsize */
157  (destructor)ChainPredicateIterator_dealloc, /* tp_dealloc */
158  0, /* tp_vectorcall_offset */
159  nullptr, /* tp_getattr */
160  nullptr, /* tp_setattr */
161  nullptr, /* tp_reserved */
162  nullptr, /* tp_repr */
163  nullptr, /* tp_as_number */
164  nullptr, /* tp_as_sequence */
165  nullptr, /* tp_as_mapping */
166  nullptr, /* tp_hash */
167  nullptr, /* tp_call */
168  nullptr, /* tp_str */
169  nullptr, /* tp_getattro */
170  nullptr, /* tp_setattro */
171  nullptr, /* tp_as_buffer */
172  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
173  ChainPredicateIterator_doc, /* tp_doc */
174  nullptr, /* tp_traverse */
175  nullptr, /* tp_clear */
176  nullptr, /* tp_richcompare */
177  0, /* tp_weaklistoffset */
178  nullptr, /* tp_iter */
179  nullptr, /* tp_iternext */
180  nullptr, /* tp_methods */
181  nullptr, /* tp_members */
182  nullptr, /* tp_getset */
183  &ChainingIterator_Type, /* tp_base */
184  nullptr, /* tp_dict */
185  nullptr, /* tp_descr_get */
186  nullptr, /* tp_descr_set */
187  0, /* tp_dictoffset */
188  (initproc)ChainPredicateIterator_init, /* tp_init */
189  nullptr, /* tp_alloc */
190  nullptr, /* tp_new */
191 };
192 
194 
195 #ifdef __cplusplus
196 }
197 #endif
PyTypeObject BinaryPredicate1D_Type
static int check_begin(PyObject *obj, void *v)
PyTypeObject ChainPredicateIterator_Type
static int ChainPredicateIterator_init(BPy_ChainPredicateIterator *self, PyObject *args, PyObject *kwds)
PyDoc_STRVAR(ChainPredicateIterator_doc, "Class hierarchy: :class:`freestyle.types.Iterator` >\n" ":class:`freestyle.types.ViewEdgeIterator` >\n" ":class:`freestyle.types.ChainingIterator` >\n" ":class:`ChainPredicateIterator`\n" "\n" "A \"generic\" user-controlled ViewEdge iterator. This iterator is in\n" "particular built from a unary predicate and a binary predicate.\n" "First, the unary predicate is evaluated for all potential next\n" "ViewEdges in order to only keep the ones respecting a certain\n" "constraint. Then, the binary predicate is evaluated on the current\n" "ViewEdge together with each ViewEdge of the previous selection. The\n" "first ViewEdge respecting both the unary predicate and the binary\n" "predicate is kept as the next one. If none of the potential next\n" "ViewEdge respects these two predicates, None is returned.\n" "\n" ".. method:: __init__(upred, bpred, restrict_to_selection=True, " " restrict_to_unvisited=True, begin=None, " " orientation=True)\n" " __init__(brother)\n" "\n" " Builds a ChainPredicateIterator from a unary predicate, a binary\n" " predicate, a starting ViewEdge and its orientation or using the copy constructor.\n" "\n" " :arg upred: The unary predicate that the next ViewEdge must satisfy.\n" " :type upred: :class:`freestyle.types.UnaryPredicate1D`\n" " :arg bpred: The binary predicate that the next ViewEdge must\n" " satisfy together with the actual pointed ViewEdge.\n" " :type bpred: :class:`freestyle.types.BinaryPredicate1D`\n" " :arg restrict_to_selection: Indicates whether to force the chaining\n" " to stay within the set of selected ViewEdges or not.\n" " :type restrict_to_selection: bool\n" " :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" " already been chained must be ignored ot not.\n" " :type restrict_to_unvisited: bool\n" " :arg begin: The ViewEdge from where to start the iteration.\n" " :type begin: :class:`freestyle.types.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 ChainPredicateIterator object.\n" " :type brother: :class:`ChainPredicateIterator`")
static void ChainPredicateIterator_dealloc(BPy_ChainPredicateIterator *self)
PyTypeObject ChainingIterator_Type
bool bool_from_PyBool(PyObject *b)
PyTypeObject UnaryPredicate1D_Type
#define BPy_ViewEdge_Check(v)
Definition: BPy_ViewEdge.h:21
ATTR_WARN_UNUSED_RESULT const BMVert * v
PyObject * self
Definition: bpy_driver.c:165
inherits from class Rep
Definition: AppCanvas.cpp:18