[Bf-blender-cvs] [9563bde] master: Freestyle: use mathutils_array_parse() instead of its own helper functions.

Tamito Kajiyama noreply at git.blender.org
Tue Jun 24 16:33:55 CEST 2014


Commit: 9563bde9a5457a3b04b61b8727d798da3ab689d3
Author: Tamito Kajiyama
Date:   Tue Jun 24 22:48:15 2014 +0900
https://developer.blender.org/rB9563bde9a5457a3b04b61b8727d798da3ab689d3

Freestyle: use mathutils_array_parse() instead of its own helper functions.

Patch contribution by flokkievids (Folkert de Vries).  Thanks!

===================================================================

M	source/blender/freestyle/intern/python/BPy_Convert.cpp
M	source/blender/freestyle/intern/python/BPy_Convert.h
M	source/blender/freestyle/intern/python/BPy_Freestyle.cpp
M	source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp
M	source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp
M	source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp
M	source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp
M	source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp
M	source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp
M	source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp

===================================================================

diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp
index dfa81a0..78c3599 100644
--- a/source/blender/freestyle/intern/python/BPy_Convert.cpp
+++ b/source/blender/freestyle/intern/python/BPy_Convert.cpp
@@ -718,7 +718,7 @@ bool Vec3r_ptr_from_PyTuple(PyObject *obj, Vec3r &vec)
 	return true;
 }
 
-// helper for argument parsing
+// helpers for argument parsing
 
 bool float_array_from_PyObject(PyObject *obj, float *v, int n)
 {
@@ -745,6 +745,22 @@ bool float_array_from_PyObject(PyObject *obj, float *v, int n)
 	return 0;
 }
 
+int convert_v4(PyObject *obj, void *v)
+{
+	return mathutils_array_parse((float *)v, 4, 4, obj, "Error parsing 4D vector");
+}
+
+int convert_v3(PyObject *obj, void *v)
+{
+	return mathutils_array_parse((float *)v, 3, 3, obj, "Error parsing 3D vector");
+}
+
+int convert_v2(PyObject *obj, void *v)
+{
+	return mathutils_array_parse((float *)v, 2, 2, obj, "Error parsing 2D vector");
+}
+
+
 ///////////////////////////////////////////////////////////////////////////////////////////
 
 #ifdef __cplusplus
diff --git a/source/blender/freestyle/intern/python/BPy_Convert.h b/source/blender/freestyle/intern/python/BPy_Convert.h
index cf55ba3..e6e763e 100644
--- a/source/blender/freestyle/intern/python/BPy_Convert.h
+++ b/source/blender/freestyle/intern/python/BPy_Convert.h
@@ -170,6 +170,9 @@ bool Vec3r_ptr_from_PyTuple(PyObject *obj, Vec3r &vec);
 
 bool float_array_from_PyObject(PyObject *obj, float *v, int n);
 
+int convert_v4(PyObject *obj, void *v);
+int convert_v3(PyObject *obj, void *v);
+int convert_v2(PyObject *obj, void *v);
 
 ///////////////////////////////////////////////////////////////////////////////////////////
 
diff --git a/source/blender/freestyle/intern/python/BPy_Freestyle.cpp b/source/blender/freestyle/intern/python/BPy_Freestyle.cpp
index f390e93..2cfd365 100644
--- a/source/blender/freestyle/intern/python/BPy_Freestyle.cpp
+++ b/source/blender/freestyle/intern/python/BPy_Freestyle.cpp
@@ -138,14 +138,16 @@ static PyObject *Freestyle_blendRamp(PyObject *self, PyObject *args)
 		PyErr_SetString(PyExc_TypeError, "argument 1 is an unknown ramp blend type");
 		return NULL;
 	}
-	if (!float_array_from_PyObject(obj1, a, 3)) {
-		PyErr_SetString(PyExc_TypeError,
-		                "argument 2 must be a 3D vector (either a tuple/list of 3 elements or Vector)");
+	if (mathutils_array_parse(a, 3, 3, obj1,
+	                          "argument 2 must be a 3D vector "
+	                          "(either a tuple/list of 3 elements or Vector)") == -1)
+	{
 		return NULL;
 	}
-	if (!float_array_from_PyObject(obj2, b, 3)) {
-		PyErr_SetString(PyExc_TypeError,
-		                "argument 4 must be a 3D vector (either a tuple/list of 3 elements or Vector)");
+	if (mathutils_array_parse(b, 3, 3, obj2,
+	                          "argument 4 must be a 3D vector "
+	                          "(either a tuple/list of 3 elements or Vector)") == -1)
+	{
 		return NULL;
 	}
 	ramp_blend(type, a, fac, b);
diff --git a/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp b/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp
index 7fe03dc..f967fc6 100644
--- a/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp
+++ b/source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp
@@ -80,11 +80,6 @@ PyDoc_STRVAR(FrsMaterial_doc,
 "   :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)
 {
 	static const char *kwlist_1[] = {"brother", NULL};
@@ -299,8 +294,9 @@ static PyObject *FrsMaterial_diffuse_get(BPy_FrsMaterial *self, void *UNUSED(clo
 static int FrsMaterial_diffuse_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure))
 {
 	float color[4];
-	if (!float_array_from_PyObject(value, color, 4)) {
-		PyErr_SetString(PyExc_ValueError, "value must be a 4-dimensional vector");
+	if (mathutils_array_parse(color, 4, 4, value,
+	                          "value must be a 4-dimensional vector") == -1)
+	{
 		return -1;
 	}
 	self->m->setDiffuse(color[0], color[1], color[2], color[3]);
@@ -320,8 +316,9 @@ static PyObject *FrsMaterial_specular_get(BPy_FrsMaterial *self, void *UNUSED(cl
 static int FrsMaterial_specular_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure))
 {
 	float color[4];
-	if (!float_array_from_PyObject(value, color, 4)) {
-		PyErr_SetString(PyExc_ValueError, "value must be a 4-dimensional vector");
+	if (mathutils_array_parse(color, 4, 4, value,
+	                          "value must be a 4-dimensional vector") == -1)
+	{
 		return -1;
 	}
 	self->m->setSpecular(color[0], color[1], color[2], color[3]);
@@ -341,8 +338,9 @@ static PyObject *FrsMaterial_ambient_get(BPy_FrsMaterial *self, void *UNUSED(clo
 static int FrsMaterial_ambient_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure))
 {
 	float color[4];
-	if (!float_array_from_PyObject(value, color, 4)) {
-		PyErr_SetString(PyExc_ValueError, "value must be a 4-dimensional vector");
+	if (mathutils_array_parse(color, 4, 4, value,
+	                          "value must be a 4-dimensional vector") == -1)
+	{
 		return -1;
 	}
 	self->m->setAmbient(color[0], color[1], color[2], color[3]);
@@ -362,8 +360,9 @@ static PyObject *FrsMaterial_emission_get(BPy_FrsMaterial *self, void *UNUSED(cl
 static int FrsMaterial_emission_set(BPy_FrsMaterial *self, PyObject *value, void *UNUSED(closure))
 {
 	float color[4];
-	if (!float_array_from_PyObject(value, color, 4)) {
-		PyErr_SetString(PyExc_ValueError, "value must be a 4-dimensional vector");
+	if (mathutils_array_parse(color, 4, 4, value,
+	                          "value must be a 4-dimensional vector") == -1)
+	{
 		return -1;
 	}
 	self->m->setEmission(color[0], color[1], color[2], color[3]);
diff --git a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp
index 69d5312..22ffded 100644
--- a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp
+++ b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp
@@ -525,8 +525,9 @@ static PyObject *StrokeAttribute_color_get(BPy_StrokeAttribute *self, void *UNUS
 static int StrokeAttribute_color_set(BPy_StrokeAttribute *self, PyObject *value, void *UNUSED(closure))
 {
 	float v[3];
-	if (!float_array_from_PyObject(value, v, 3)) {
-		PyErr_SetString(PyExc_ValueError, "value must be a 3-dimensional vector");
+	if (mathutils_array_parse(v, 3, 3, value,
+	                          "value must be a 3-dimensional vector") == -1)
+	{
 		return -1;
 	}
 	self->sa->setColor(v[0], v[1], v[2]);
@@ -549,8 +550,9 @@ static PyObject *StrokeAttribute_thickness_get(BPy_StrokeAttribute *self, void *
 static int StrokeAttribute_thickness_set(BPy_StrokeAttribute *self, PyObject *value, void *UNUSED(closure))
 {
 	float v[2];
-	if (!float_array_from_PyObject(value, v, 2)) {
-		PyErr_SetString(PyExc_ValueError, "value must be a 2-dimensional vector");
+	if (mathutils_array_parse(v, 2, 2, value,
+	                          "value must be a 2-dimensional vector") == -1)
+	{
 		return -1;
 	}
 	self->sa->setThickness(v[0], v[1]);
diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp
index 7317479..af9f719 100644
--- a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp
+++ b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp
@@ -61,11 +61,6 @@ PyDoc_STRVAR(SVertex_doc,
 "   :arg id: An Id object.\n"
 "   :type id: :class:`Id`");
 
-static int convert_v3(PyObject *obj, void *v)
-{
-	return float_array_from_PyObject(obj, (float *)v, 3);
-}
-
 static int SVertex_init(BPy_SVertex *self, PyObject *args, PyObject *kwds)
 {
 	static const char *kwlist_1[] = {"brother", NULL};
@@ -283,8 +278,9 @@ static PyObject *SVertex_point_3d_get(BPy_SVertex *self, void *UNUSED(closure))
 static int SVertex_point_3d_set(BPy_SVertex *self, PyObject *value, void *UNUSED(closure))
 {
 	float v[3];
-	if (!float_array_from_PyObject(value, v, 3)) {
-		PyErr_SetString(PyExc_ValueError, "value must be a 3-dimensional vector");
+	if (mathutils_array_parse(v, 3, 3, value,
+	                          "value must be a 3-dimensional vector") == -1)
+	{
 		return -1;
 	}
 	Vec3r p(v[0], v[1], v[2]);
@@ -305,8 +301,9 @@ static PyObject *SVertex_point_2d_get(BPy_SVertex *self, void *UNUSED(closure))
 static int SVertex_point_2d_set(BPy_SVertex *self, PyObject *value, void *UNUSED(closure))
 {
 	float v[3];
-	if (!float_array_from_PyObject(value, v, 3)) {
-		PyErr_SetString(PyExc_ValueError, "value must be a 3-dimensional vector");
+	if (mathutils_array_parse(v, 3, 3, value,
+	                          "value must be a 3-dimensional vector") == -1)
+	{
 		return -1;
 	}
 	Vec3r p(v[0], v[1], v[2]);
diff --git a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp
index 18f0f81..65d8028 100644
--- a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp
+++ b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp
@@ -277,8 +277,9 @@ static PyObject *StrokeVertex_point_get(BPy_StrokeVertex *self, void *UNUSED(clo
 static int StrokeVertex_point_set(BPy_StrokeVertex *self, PyObject *value, void *UNUSED(closure))
 {
 	float v[2];
-	if (!float_array_from_PyObject(value, v, 2)) {
-		PyErr_SetString(PyExc_ValueError, "value must be a 2-dimensional vector");
+	if (mathutils_array_parse(v, 2, 2, value,
+	                          "value must be a 2-dimensional vector") == -1)
+	{
 		return -1;
 	}
 	self->sv->setX(v[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 1f79a57..acdd598 100644
--- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp
+++ b/source/blender/fre

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list