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>2014-06-24 17:48:15 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2014-06-24 18:13:56 +0400
commit9563bde9a5457a3b04b61b8727d798da3ab689d3 (patch)
tree13d9205314245e57fc62db8af0d5a9457fd45ad6 /source/blender/freestyle
parent252eaed483ca8c0d89708b3d0a2a82076f944229 (diff)
Freestyle: use mathutils_array_parse() instead of its own helper functions.
Patch contribution by flokkievids (Folkert de Vries). Thanks!
Diffstat (limited to 'source/blender/freestyle')
-rw-r--r--source/blender/freestyle/intern/python/BPy_Convert.cpp18
-rw-r--r--source/blender/freestyle/intern/python/BPy_Convert.h3
-rw-r--r--source/blender/freestyle/intern/python/BPy_Freestyle.cpp14
-rw-r--r--source/blender/freestyle/intern/python/BPy_FrsMaterial.cpp25
-rw-r--r--source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp10
-rw-r--r--source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp15
-rw-r--r--source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp5
-rw-r--r--source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp10
-rw-r--r--source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp5
-rw-r--r--source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp5
10 files changed, 64 insertions, 46 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_Convert.cpp b/source/blender/freestyle/intern/python/BPy_Convert.cpp
index dfa81a062b6..78c3599b7cd 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 cf55ba335cd..e6e763e763e 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 f390e937aac..2cfd3658189 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 7fe03dcc9a0..f967fc64ac6 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 69d5312f9e5..22ffdedb3d9 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 7317479a878..af9f7198748 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 18f0f81b0ec..65d80283fca 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 1f79a571321..acdd5989511 100644
--- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp
+++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp
@@ -231,8 +231,9 @@ static PyObject *FEdgeSharp_normal_right_get(BPy_FEdgeSharp *self, void *UNUSED(
static int FEdgeSharp_normal_right_set(BPy_FEdgeSharp *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]);
@@ -253,8 +254,9 @@ static PyObject *FEdgeSharp_normal_left_get(BPy_FEdgeSharp *self, void *UNUSED(c
static int FEdgeSharp_normal_left_set(BPy_FEdgeSharp *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/Interface1D/FEdge/BPy_FEdgeSmooth.cpp b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp
index 15acb56d0fc..a2079c7d685 100644
--- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp
+++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp
@@ -164,8 +164,9 @@ static PyObject *FEdgeSmooth_normal_get(BPy_FEdgeSmooth *self, void *UNUSED(clos
static int FEdgeSmooth_normal_set(BPy_FEdgeSmooth *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/StrokeShader/BPy_CalligraphicShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp
index 814d03b42d4..6b0c1424d61 100644
--- a/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp
+++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp
@@ -67,11 +67,6 @@ static char CalligraphicShader___doc__[] =
" :arg stroke: A Stroke object.\n"
" :type stroke: :class:`Stroke`\n";
-static int convert_v2(PyObject *obj, void *v)
-{
- return float_array_from_PyObject(obj, (float *)v, 2);
-}
-
static int CalligraphicShader___init__(BPy_CalligraphicShader *self, PyObject *args, PyObject *kwds)
{
static const char *kwlist[] = {"thickness_min", "thickness_max", "orientation", "clamp", NULL};