diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-02-21 06:57:44 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-02-21 06:57:44 +0400 |
commit | 39f8c6e189c89f4097f5d979612cb71bd8773030 (patch) | |
tree | d9a4ace57a1dc75f9e968ac0c1cae92ef995c145 /source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp | |
parent | 92436c94d3adbbfc285bd7b3041db36e66dae5d5 (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/Interface1D/BPy_Stroke.cpp')
-rw-r--r-- | source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp | 45 |
1 files changed, 9 insertions, 36 deletions
diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp index f0cc91b9a79..7896471fb0a 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp @@ -16,7 +16,7 @@ extern "C" { /*----------------------Stroke methods ----------------------------*/ // Stroke () -// template<class InputVertexIterator> Stroke (InputVertexIterator iBegin, InputVertexIterator iEnd) +// template<class InputVertexIterator> Stroke (InputVertexIterator begin, InputVertexIterator end) // // pb: - need to be able to switch representation: InputVertexIterator <=> position // - is it even used ? not even in SWIG version @@ -33,50 +33,23 @@ PyDoc_STRVAR(Stroke_doc, "\n" " Default constructor\n" "\n" -".. method:: Stroke(iBrother)\n" +".. method:: Stroke(brother)\n" "\n" -" Copy constructor\n" -"\n" -" :arg iBrother: \n" -" :type iBrother: :class:`Stroke`\n" -"\n" -".. method:: Stroke(iBegin, iEnd)\n" -"\n" -" Builds a stroke from a set of StrokeVertex. This constructor is\n" -" templated by an iterator type. This iterator type must allow the\n" -" vertices parsing using the ++ operator.\n" -"\n" -" :arg iBegin: The iterator pointing to the first vertex.\n" -" :type iBegin: InputVertexIterator\n" -" :arg iEnd: The iterator pointing to the end of the vertex list.\n" -" :type iEnd: InputVertexIterator"); +" Copy constructor"); static int Stroke_init(BPy_Stroke *self, PyObject *args, PyObject *kwds) { - PyObject *obj1 = NULL, *obj2 = NULL; + static const char *kwlist[] = {"brother", NULL}; + PyObject *brother = 0; - if (!PyArg_ParseTuple(args, "|OO", &obj1, &obj2)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &Stroke_Type, &brother)) return -1; - - if (!obj1) { + if (!brother) self->s = new Stroke(); - - } else if (!obj2 && BPy_Stroke_Check(obj1)) { - self->s = new Stroke(*(((BPy_Stroke *)obj1)->s)); - - } else if (obj2) { - PyErr_SetString(PyExc_TypeError, - "Stroke(InputVertexIterator iBegin, InputVertexIterator iEnd) not implemented"); - return -1; - - } else { - PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); - return -1; - } - + else + self->s = new Stroke(*(((BPy_Stroke *)brother)->s)); self->py_if1D.if1D = self->s; self->py_if1D.borrowed = 0; - return 0; } |