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/BPy_FrsMaterial.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/BPy_FrsMaterial.cpp')
-rw-r--r--source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp95
1 files changed, 50 insertions, 45 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp b/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp
index 8d651c702b0..9664fa56b8d 100644
--- a/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp
+++ b/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp
@@ -6,19 +6,17 @@
extern "C" {
#endif
-#include "BLI_math.h"
-
///////////////////////////////////////////////////////////////////////////////////////////
//-------------------MODULE INITIALIZATION--------------------------------
-int FrsMaterial_Init( PyObject *module )
+int FrsMaterial_Init(PyObject *module)
{
if (module == NULL)
return -1;
- if (PyType_Ready( &FrsMaterial_Type ) < 0)
+ if (PyType_Ready(&FrsMaterial_Type) < 0)
return -1;
- Py_INCREF( &FrsMaterial_Type );
+ Py_INCREF(&FrsMaterial_Type);
PyModule_AddObject(module, "Material", (PyObject *)&FrsMaterial_Type);
FrsMaterial_mathutils_register_callback();
@@ -35,59 +33,67 @@ PyDoc_STRVAR(FrsMaterial_doc,
"\n"
" Default constructor.\n"
"\n"
-".. method:: __init__(m)\n"
+".. method:: __init__(brother)\n"
"\n"
" Copy constructor.\n"
"\n"
-" :arg m: A Material object.\n"
-" :type m: :class:`Material`\n"
+" :arg brother: A Material object.\n"
+" :type brother: :class:`Material`\n"
"\n"
-".. method:: __init__(iDiffuse, iAmbiant, iSpecular, iEmission, iShininess)\n"
+".. method:: __init__(diffuse, ambient, specular, emission, shininess)\n"
"\n"
-" Builds a Material from its diffuse, ambiant, specular, emissive\n"
+" Builds a Material from its diffuse, ambient, specular, emissive\n"
" colors and a shininess coefficient.\n"
"\n"
-" :arg iDiffuse: The diffuse color.\n"
-" :type iDiffuse: :class:`mathutils.Vector`, list or tuple of 4 float values\n"
-" :arg iAmbiant: The ambiant color.\n"
-" :type iAmbiant: :class:`mathutils.Vector`, list or tuple of 4 float values\n"
-" :arg iSpecular: The specular color.\n"
-" :type iSpecular: :class:`mathutils.Vector`, list or tuple of 4 float values\n"
-" :arg iEmission: The emissive color.\n"
-" :type iEmission: :class:`mathutils.Vector`, list or tuple of 4 float values\n"
-" :arg iShininess: The shininess coefficient.\n"
-" :type iShininess: :class:float");
+" :arg diffuse: The diffuse color.\n"
+" :type diffuse: :class:`mathutils.Vector`, list or tuple of 4 float values\n"
+" :arg ambient: The ambient color.\n"
+" :type ambient: :class:`mathutils.Vector`, list or tuple of 4 float values\n"
+" :arg specular: The specular color.\n"
+" :type specular: :class:`mathutils.Vector`, list or tuple of 4 float values\n"
+" :arg emission: The emissive color.\n"
+" :type emission: :class:`mathutils.Vector`, list or tuple of 4 float values\n"
+" :arg shininess: The shininess coefficient.\n"
+" :type shininess: :class:float");
+
+static int convert_v4(PyObject *obj, void *v)
+{
+ return float_array_from_PyObject(obj, (float *)v, 4);
+}
static int FrsMaterial_init(BPy_FrsMaterial *self, PyObject *args, PyObject *kwds)
{
- PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0;
- float f1[4], f2[4], f3[4], f4[4], f5 = 0.;
-
- if (!PyArg_ParseTuple(args, "|OOOOf", &obj1, &obj2, &obj3, &obj4, &f5))
- return -1;
-
- if (!obj1) {
- self->m = new FrsMaterial();
-
- } else if (BPy_FrsMaterial_Check(obj1) && !obj2) {
- FrsMaterial *m = ((BPy_FrsMaterial *) obj1)->m;
- if (!m) {
- PyErr_SetString(PyExc_RuntimeError, "invalid FrsMaterial object");
- return -1;
+ static const char *kwlist_1[] = {"brother", NULL};
+ static const char *kwlist_2[] = {"diffuse", "ambient", "specular", "emission", "shininess", NULL};
+ PyObject *brother = 0;
+ float diffuse[4], ambient[4], specular[4], emission[4], shininess;
+
+ if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &FrsMaterial_Type, &brother)) {
+ if (!brother) {
+ self->m = new FrsMaterial();
+ } else {
+ FrsMaterial *m = ((BPy_FrsMaterial *)brother)->m;
+ if (!m) {
+ PyErr_SetString(PyExc_RuntimeError, "invalid Material object");
+ return -1;
+ }
+ self->m = new FrsMaterial(*m);
}
- self->m = new FrsMaterial(*m);
-
- } else if (float_array_from_PyObject(obj1, f1, 4) && obj2 &&
- float_array_from_PyObject(obj2, f2, 4) && obj3 &&
- float_array_from_PyObject(obj3, f3, 4) && obj4 &&
- float_array_from_PyObject(obj4, f4, 4)) {
- self->m = new FrsMaterial(f1, f2, f3, f4, f5);
-
- } else {
+ }
+ else if (PyErr_Clear(),
+ PyArg_ParseTupleAndKeywords(args, kwds, "O&O&O&O&f", (char **)kwlist_2,
+ convert_v4, diffuse,
+ convert_v4, ambient,
+ convert_v4, specular,
+ convert_v4, emission,
+ &shininess))
+ {
+ self->m = new FrsMaterial(diffuse, ambient, specular, emission, shininess);
+ }
+ else {
PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
return -1;
}
-
return 0;
}
@@ -97,7 +103,6 @@ static void FrsMaterial_dealloc(BPy_FrsMaterial* self)
Py_TYPE(self)->tp_free((PyObject*)self);
}
-
static PyObject * FrsMaterial_repr(BPy_FrsMaterial* self)
{
return PyUnicode_FromFormat("Material - address: %p", self->m);