Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-02-21 06:57:44 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-02-21 06:57:44 +0400
commit39f8c6e189c89f4097f5d979612cb71bd8773030 (patch)
treed9a4ace57a1dc75f9e968ac0c1cae92ef995c145 /source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp
parent92436c94d3adbbfc285bd7b3041db36e66dae5d5 (diff)
Freestyle Python API improvements - part 5.
Handling of keyword arguments in Python wrapper class constructors was revised. This revision is mainly focused on Interface0D, Interface1D, Iterator, and their subclasses, as well as a few additional view map component classes. Implementation notes: Because of the extensive use of constructor overloading in the underlying C++ classes, the corresponding Python wrappers try to parse arguments through multiple calls of PyArg_ParseTupleAndKeywords() if needed. The downside of this implementation is that most argument errors result in the same error message ("invalid argument(s)") without indicating what is wrong. For now this issue is left for future work. * Now the instantiation of ViewVertex is prohibited since the underlying C++ class is an abstract class. * Removed the .cast_to_interface0diterator() method from CurvePointIterator and StrokeVertexIterator. Instead the constructor of Interface0DIterator now accepts the instances of these two iterator classes to construct a nested Interface0DIterator instance that can be passed to Function0D functor objects. Specifically, an iterator 'it' is passed to a functor 'func' as follows: func(Interface0DIterator(it)) instead of: func(it.cast_to_interface0diterator()) * Boolean arguments of class constructors only accept values of boolean type. Input values of other types are considered as error. * Additional code clean-up was made.
Diffstat (limited to 'source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp')
-rw-r--r--source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp55
1 files changed, 29 insertions, 26 deletions
diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp
index efc64913932..cfa0a6dcb8d 100644
--- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp
+++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainSilhouetteIterator.cpp
@@ -11,7 +11,7 @@ extern "C" {
//------------------------INSTANCE METHODS ----------------------------------
-// ChainSilhouetteIterator (bool iRestrictToSelection=true, ViewEdge *begin=NULL, bool orientation=true)
+// ChainSilhouetteIterator (bool restrict_to_selection=true, ViewEdge *begin=NULL, bool orientation=true)
// ChainSilhouetteIterator (const ChainSilhouetteIterator &brother)
PyDoc_STRVAR(ChainSilhouetteIterator_doc,
@@ -24,14 +24,14 @@ PyDoc_STRVAR(ChainSilhouetteIterator_doc,
"ViewEdge that are both Silhouette and Crease, there will be a\n"
"precedence of the silhouette over the crease criterion.\n"
"\n"
-".. method:: __init__(iRestrictToSelection=True, begin=None, orientation=True)\n"
+".. method:: __init__(restrict_to_selection=True, begin=None, orientation=True)\n"
"\n"
" Builds a ChainSilhouetteIterator from the first ViewEdge used for\n"
" iteration and its orientation.\n"
"\n"
-" :arg iRestrictToSelection: Indicates whether to force the chaining\n"
+" :arg restrict_to_selection: Indicates whether to force the chaining\n"
" to stay within the set of selected ViewEdges or not.\n"
-" :type iRestrictToSelection: bool\n"
+" :type restrict_to_selection: bool\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"
@@ -47,36 +47,39 @@ PyDoc_STRVAR(ChainSilhouetteIterator_doc,
" :arg brother: A ChainSilhouetteIterator object.\n"
" :type brother: :class:`ChainSilhouetteIterator`");
-static int ChainSilhouetteIterator_init(BPy_ChainSilhouetteIterator *self, PyObject *args)
+static int check_begin(PyObject *obj, void *v)
{
- PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0;
+ if (obj != 0 && obj != Py_None && !BPy_ViewEdge_Check(obj))
+ return 0;
+ *((PyObject **)v) = obj;
+ return 1;
+}
- if (!(PyArg_ParseTuple(args, "|OOO", &obj1, &obj2, &obj3)))
- return -1;
+static int ChainSilhouetteIterator_init(BPy_ChainSilhouetteIterator *self, PyObject *args, PyObject *kwds)
+{
+ static const char *kwlist_1[] = {"brother", NULL};
+ static const char *kwlist_2[] = {"restrict_to_selection", "begin", "orientation", NULL};
+ PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0;
- if (obj1 && BPy_ChainSilhouetteIterator_Check(obj1)) {
+ if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &ChainSilhouetteIterator_Type, &obj1)) {
self->cs_it = new ChainSilhouetteIterator(*(((BPy_ChainSilhouetteIterator *)obj1)->cs_it));
-
- } else {
- bool restrictToSelection = (obj1) ? bool_from_PyBool(obj1) : true;
- ViewEdge *begin;
- if (!obj2 || obj2 == Py_None)
- begin = NULL;
- else if (BPy_ViewEdge_Check(obj2))
- begin = ((BPy_ViewEdge *)obj2)->ve;
- else {
- PyErr_SetString(PyExc_TypeError, "2nd argument must be either a ViewEdge object or None");
- return -1;
- }
- bool orientation = (obj3) ? bool_from_PyBool(obj3) : true;
-
- self->cs_it = new ChainSilhouetteIterator(restrictToSelection, begin, orientation);
}
-
+ else if (PyErr_Clear(), (obj1 = obj2 = obj3 = 0),
+ PyArg_ParseTupleAndKeywords(args, kwds, "|O!O&O!", (char **)kwlist_2,
+ &PyBool_Type, &obj1, check_begin, &obj2, &PyBool_Type, &obj3))
+ {
+ bool restrict_to_selection = (!obj1) ? true : bool_from_PyBool(obj1);
+ ViewEdge *begin = (!obj2 || obj2 == Py_None) ? NULL : ((BPy_ViewEdge *)obj2)->ve;
+ bool orientation = (!obj3) ? true : bool_from_PyBool(obj3);
+ self->cs_it = new ChainSilhouetteIterator(restrict_to_selection, begin, orientation);
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
+ return -1;
+ }
self->py_c_it.c_it = self->cs_it;
self->py_c_it.py_ve_it.ve_it = self->cs_it;
self->py_c_it.py_ve_it.py_it.it = self->cs_it;
-
return 0;
}