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/Interface1D
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/Interface1D')
-rw-r--r--source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp46
-rw-r--r--source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp44
-rw-r--r--source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp45
-rw-r--r--source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp16
-rw-r--r--source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp36
-rw-r--r--source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp44
-rw-r--r--source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp46
7 files changed, 127 insertions, 150 deletions
diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp
index be3d97f5f78..2090a4523f0 100644
--- a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp
+++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp
@@ -31,46 +31,46 @@ PyDoc_STRVAR(FEdge_doc,
"\n"
" Default constructor.\n"
"\n"
-".. method:: FEdge(iBrother)\n"
+".. method:: FEdge(brother)\n"
"\n"
" Copy constructor.\n"
"\n"
-" :arg iBrother: An FEdge object.\n"
-" :type iBrother: :class:`FEdge`\n"
+" :arg brother: An FEdge object.\n"
+" :type brother: :class:`FEdge`\n"
"\n"
-".. method:: FEdge(vA, vB)\n"
+".. method:: FEdge(first_vertex, second_vertex)\n"
"\n"
-" Builds an FEdge going from vA to vB.\n"
+" Builds an FEdge going from the first vertex to the second.\n"
"\n"
-" :arg vA: The first SVertex.\n"
-" :type vA: :class:`SVertex`\n"
-" :arg vB: The second SVertex.\n"
-" :type vB: :class:`SVertex`");
+" :arg first_vertex: The first SVertex.\n"
+" :type first_vertex: :class:`SVertex`\n"
+" :arg second_vertex: The second SVertex.\n"
+" :type second_vertex: :class:`SVertex`");
static int FEdge_init(BPy_FEdge *self, PyObject *args, PyObject *kwds)
{
+ static const char *kwlist_1[] = {"brother", NULL};
+ static const char *kwlist_2[] = {"first_vertex", "second_vertex", NULL};
PyObject *obj1 = 0, *obj2 = 0;
- if (!PyArg_ParseTuple(args, "|OO", &obj1, &obj2))
- return -1;
-
- if (!obj1) {
- self->fe = new FEdge();
-
- } else if(!obj2 && BPy_FEdge_Check(obj1)) {
- self->fe = new FEdge(*(((BPy_FEdge *)obj1)->fe));
-
- } else if(obj2 && BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2)) {
+ if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdge_Type, &obj1)) {
+ if (!obj1)
+ self->fe = new FEdge();
+ else
+ self->fe = new FEdge(*(((BPy_FEdge *)obj1)->fe));
+ }
+ else if (PyErr_Clear(),
+ PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist_2,
+ &SVertex_Type, &obj1, &SVertex_Type, &obj2))
+ {
self->fe = new FEdge(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv);
-
- } else {
+ }
+ else {
PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
return -1;
}
-
self->py_if1D.if1D = self->fe;
self->py_if1D.borrowed = 0;
-
return 0;
}
diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp
index e5b984e41bd..43e960007a0 100644
--- a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp
+++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp
@@ -24,45 +24,43 @@ PyDoc_STRVAR(FrsCurve_doc,
"\n"
" Default Constructor.\n"
"\n"
-".. method:: __init__(iBrother)\n"
+".. method:: __init__(brother)\n"
"\n"
" Copy Constructor.\n"
"\n"
-" :arg iBrother: A Curve object.\n"
-" :type iBrother: :class:`Curve`\n"
+" :arg brother: A Curve object.\n"
+" :type brother: :class:`Curve`\n"
"\n"
-".. method:: __init__(iId)\n"
+".. method:: __init__(id)\n"
"\n"
" Builds a Curve from its Id.\n"
"\n"
-" :arg iId: An Id object.\n"
-" :type iId: :class:`Id`");
+" :arg id: An Id object.\n"
+" :type id: :class:`Id`");
static int FrsCurve_init(BPy_FrsCurve *self, PyObject *args, PyObject *kwds)
{
-
+ static const char *kwlist_1[] = {"brother", NULL};
+ static const char *kwlist_2[] = {"id", NULL};
PyObject *obj = 0;
- if (!PyArg_ParseTuple(args, "|O", &obj))
- return -1;
-
- if (!obj) {
- self->c = new Curve();
-
- } else if (BPy_FrsCurve_Check(obj)) {
- self->c = new Curve(*( ((BPy_FrsCurve *) obj)->c ));
-
- } else if (BPy_Id_Check(obj)) {
- self->c = new Curve(*( ((BPy_Id *) obj)->id ));
-
- } else {
- PyErr_SetString(PyExc_TypeError, "invalid argument");
+ if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FrsCurve_Type, &obj)) {
+ if (!obj)
+ self->c = new Curve();
+ else
+ self->c = new Curve(*(((BPy_FrsCurve *)obj)->c));
+ }
+ else if (PyErr_Clear(),
+ PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Id_Type, &obj))
+ {
+ self->c = new Curve(*(((BPy_Id *)obj)->id));
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
return -1;
}
-
self->py_if1D.if1D = self->c;
self->py_if1D.borrowed = 0;
-
return 0;
}
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;
}
diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp
index 8e1cb42f37c..cdba2746812 100644
--- a/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp
+++ b/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp
@@ -27,18 +27,24 @@ PyDoc_STRVAR(ViewEdge_doc,
"\n"
" Default constructor.\n"
"\n"
-".. method:: __init__(iBrother)\n"
+".. method:: __init__(brother)\n"
"\n"
" Copy constructor.\n"
"\n"
-" :arg iBrother: A ViewEdge object.\n"
-" :type iBrother: :class:`ViewEdge`");
+" :arg brother: A ViewEdge object.\n"
+" :type brother: :class:`ViewEdge`");
static int ViewEdge_init(BPy_ViewEdge *self, PyObject *args, PyObject *kwds)
{
- if (!PyArg_ParseTuple(args, ""))
+ static const char *kwlist[] = {"brother", NULL};
+ PyObject *brother = 0;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &ViewEdge_Type, &brother))
return -1;
- self->ve = new ViewEdge();
+ if (!brother)
+ self->ve = new ViewEdge();
+ else
+ self->ve = new ViewEdge(*(((BPy_ViewEdge *)brother)->ve));
self->py_if1D.if1D = self->ve;
self->py_if1D.borrowed = 0;
return 0;
diff --git a/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp b/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp
index 793fc206389..16769e2cf74 100644
--- a/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp
+++ b/source/blender/freestyle/intern/python/Interface1D/Curve/BPy_Chain.cpp
@@ -23,12 +23,12 @@ PyDoc_STRVAR(Chain_doc,
"\n"
" Defult constructor.\n"
"\n"
-".. method:: __init__(iBrother)\n"
+".. method:: __init__(brother)\n"
"\n"
" Copy constructor.\n"
"\n"
-" :arg iBrother: A Chain object.\n"
-" :type iBrother: :class:`Chain`\n"
+" :arg brother: A Chain object.\n"
+" :type brother: :class:`Chain`\n"
"\n"
".. method:: __init__(id)\n"
"\n"
@@ -39,30 +39,28 @@ PyDoc_STRVAR(Chain_doc,
static int Chain_init(BPy_Chain *self, PyObject *args, PyObject *kwds)
{
-
+ static const char *kwlist_1[] = {"brother", NULL};
+ static const char *kwlist_2[] = {"id", NULL};
PyObject *obj = 0;
- if (!PyArg_ParseTuple(args, "|O", &obj))
- return -1;
-
- if (!obj) {
- self->c = new Chain();
-
- } else if (BPy_Chain_Check(obj)) {
- self->c = new Chain(*(((BPy_Chain *)obj)->c));
-
- } else if (BPy_Id_Check(obj)) {
+ if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &Chain_Type, &obj)) {
+ if (!obj)
+ self->c = new Chain();
+ else
+ self->c = new Chain(*(((BPy_Chain *)obj)->c));
+ }
+ else if (PyErr_Clear(),
+ PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_2, &Id_Type, &obj))
+ {
self->c = new Chain(*(((BPy_Id *)obj)->id));
-
- } else {
- PyErr_SetString(PyExc_TypeError, "invalid argument");
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
return -1;
}
-
self->py_c.c = self->c;
self->py_c.py_if1D.if1D = self->c;
self->py_c.py_if1D.borrowed = 0;
-
return 0;
}
diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp
index 49da570a9fc..a4b32cf72df 100644
--- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp
+++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp
@@ -25,39 +25,41 @@ PyDoc_STRVAR(FEdgeSharp_doc,
"\n"
" Default constructor.\n"
"\n"
-".. method:: __init__(iBrother)\n"
+".. method:: __init__(brother)\n"
"\n"
" Copy constructor.\n"
"\n"
-" :arg iBrother: An FEdgeSharp object.\n"
-" :type iBrother: :class:`FEdgeSharp`\n"
+" :arg brother: An FEdgeSharp object.\n"
+" :type brother: :class:`FEdgeSharp`\n"
"\n"
-".. method:: __init__(vA, vB)\n"
+".. method:: __init__(first_vertex, second_vertex)\n"
"\n"
-" Builds an FEdgeSharp going from vA to vB.\n"
+" Builds an FEdgeSharp going from the first vertex to the second.\n"
"\n"
-" :arg vA: The first SVertex object.\n"
-" :type vA: :class:`SVertex`\n"
-" :arg vB: The second SVertex object.\n"
-" :type vB: :class:`SVertex`");
+" :arg first_vertex: The first SVertex object.\n"
+" :type first_vertex: :class:`SVertex`\n"
+" :arg second_vertex: The second SVertex object.\n"
+" :type second_vertex: :class:`SVertex`");
static int FEdgeSharp_init(BPy_FEdgeSharp *self, PyObject *args, PyObject *kwds)
{
+ static const char *kwlist_1[] = {"brother", NULL};
+ static const char *kwlist_2[] = {"first_vertex", "second_vertex", NULL};
PyObject *obj1 = 0, *obj2 = 0;
- if (!PyArg_ParseTuple(args, "|OO", &obj1, &obj2))
- return -1;
-
- if (!obj1) {
- self->fes = new FEdgeSharp();
-
- } else if (!obj2 && BPy_FEdgeSharp_Check(obj1)) {
- self->fes = new FEdgeSharp(*(((BPy_FEdgeSharp *)obj1)->fes));
-
- } else if (obj2 && BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2)) {
+ if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdgeSharp_Type, &obj1)) {
+ if (!obj1)
+ self->fes = new FEdgeSharp();
+ else
+ self->fes = new FEdgeSharp(*(((BPy_FEdgeSharp *)obj1)->fes));
+ }
+ else if (PyErr_Clear(),
+ PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist_2,
+ &SVertex_Type, &obj1, &SVertex_Type, &obj2))
+ {
self->fes = new FEdgeSharp(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv);
-
- } else {
+ }
+ else {
PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
return -1;
}
diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp
index 847794c74c0..9b51dab4edb 100644
--- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp
+++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp
@@ -22,47 +22,47 @@ PyDoc_STRVAR(FEdgeSmooth_doc,
"\n"
" Default constructor.\n"
"\n"
-".. method:: __init__(iBrother)\n"
+".. method:: __init__(brother)\n"
"\n"
" Copy constructor.\n"
"\n"
-" :arg iBrother: An FEdgeSmooth object.\n"
-" :type iBrother: :class:`FEdgeSmooth`\n"
+" :arg brother: An FEdgeSmooth object.\n"
+" :type brother: :class:`FEdgeSmooth`\n"
"\n"
-".. method:: __init__(vA, vB)\n"
+".. method:: __init__(first_vertex, second_vertex)\n"
"\n"
-" Builds an FEdgeSmooth going from vA to vB.\n"
+" Builds an FEdgeSmooth going from the first to the second.\n"
"\n"
-" :arg vA: The first SVertex object.\n"
-" :type vA: :class:`SVertex`\n"
-" :arg vB: The second SVertex object.\n"
-" :type vB: :class:`SVertex`");
+" :arg first_vertex: The first SVertex object.\n"
+" :type first_vertex: :class:`SVertex`\n"
+" :arg second_vertex: The second SVertex object.\n"
+" :type second_vertex: :class:`SVertex`");
static int FEdgeSmooth_init(BPy_FEdgeSmooth *self, PyObject *args, PyObject *kwds)
{
+ static const char *kwlist_1[] = {"brother", NULL};
+ static const char *kwlist_2[] = {"first_vertex", "second_vertex", NULL};
PyObject *obj1 = 0, *obj2 = 0;
- if (!PyArg_ParseTuple(args, "|OO", &obj1, &obj2))
- return -1;
-
- if (!obj1) {
- self->fes = new FEdgeSmooth();
-
- } else if (!obj2 && BPy_FEdgeSmooth_Check(obj1)) {
- self->fes = new FEdgeSmooth(*(((BPy_FEdgeSmooth *)obj1)->fes));
-
- } else if (obj2 && BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2)) {
+ if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FEdgeSmooth_Type, &obj1)) {
+ if (!obj1)
+ self->fes = new FEdgeSmooth();
+ else
+ self->fes = new FEdgeSmooth(*(((BPy_FEdgeSmooth *)obj1)->fes));
+ }
+ else if (PyErr_Clear(),
+ PyArg_ParseTupleAndKeywords(args, kwds, "O!O!", (char **)kwlist_2,
+ &SVertex_Type, &obj1, &SVertex_Type, &obj2))
+ {
self->fes = new FEdgeSmooth(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv);
-
- } else {
+ }
+ else {
PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
return -1;
}
-
self->py_fe.fe = self->fes;
self->py_fe.py_if1D.if1D = self->fes;
self->py_fe.py_if1D.borrowed = 0;
-
return 0;
}