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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-04-20 02:02:53 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-04-20 02:02:53 +0400
commit4d39e0410288497455ace549a931d2b07fe49f86 (patch)
tree8a359045b118e7cd05b3446b23fa8c04eef19229 /source
parent4a993039674403815ab144cbaad80c805e9c36b4 (diff)
change mathutils 'repr' functions to closer match input
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/generic/mathutils_color.c15
-rw-r--r--source/blender/python/generic/mathutils_euler.c15
-rw-r--r--source/blender/python/generic/mathutils_matrix.c22
-rw-r--r--source/blender/python/generic/mathutils_quat.c17
-rw-r--r--source/blender/python/generic/mathutils_vector.c33
-rw-r--r--source/blender/python/intern/bpy_rna.c2
6 files changed, 69 insertions, 35 deletions
diff --git a/source/blender/python/generic/mathutils_color.c b/source/blender/python/generic/mathutils_color.c
index d44515d1551..564afbdd038 100644
--- a/source/blender/python/generic/mathutils_color.c
+++ b/source/blender/python/generic/mathutils_color.c
@@ -104,13 +104,22 @@ static PyObject *Color_copy(ColorObject * self, PyObject *args)
//print the object to screen
static PyObject *Color_repr(ColorObject * self)
{
- char str[64];
+ PyObject *r, *g, *b, *ret;
if(!BaseMath_ReadCallback(self))
return NULL;
- sprintf(str, "[%.6f, %.6f, %.6f](color)", self->col[0], self->col[1], self->col[2]);
- return PyUnicode_FromString(str);
+ r= PyFloat_FromDouble(self->col[0]);
+ g= PyFloat_FromDouble(self->col[1]);
+ b= PyFloat_FromDouble(self->col[2]);
+
+ ret= PyUnicode_FromFormat("Color(%R, %R, %R)", r, g, b);
+
+ Py_DECREF(r);
+ Py_DECREF(g);
+ Py_DECREF(b);
+
+ return ret;
}
//------------------------tp_richcmpr
//returns -1 execption, 0 false, 1 true
diff --git a/source/blender/python/generic/mathutils_euler.c b/source/blender/python/generic/mathutils_euler.c
index 04f80dd4116..c347478bce8 100644
--- a/source/blender/python/generic/mathutils_euler.c
+++ b/source/blender/python/generic/mathutils_euler.c
@@ -314,13 +314,22 @@ static PyObject *Euler_copy(EulerObject * self, PyObject *args)
//print the object to screen
static PyObject *Euler_repr(EulerObject * self)
{
- char str[64];
+ PyObject *x, *y, *z, *ret;
if(!BaseMath_ReadCallback(self))
return NULL;
- sprintf(str, "[%.6f, %.6f, %.6f](euler)", self->eul[0], self->eul[1], self->eul[2]);
- return PyUnicode_FromString(str);
+ x= PyFloat_FromDouble(self->eul[0]);
+ y= PyFloat_FromDouble(self->eul[1]);
+ z= PyFloat_FromDouble(self->eul[2]);
+
+ ret= PyUnicode_FromFormat("Euler(%R, %R, %R)", x, y, z);
+
+ Py_DECREF(x);
+ Py_DECREF(y);
+ Py_DECREF(z);
+
+ return ret;
}
//------------------------tp_richcmpr
//returns -1 execption, 0 false, 1 true
diff --git a/source/blender/python/generic/mathutils_matrix.c b/source/blender/python/generic/mathutils_matrix.c
index 0ce5641b07c..ddc14f83218 100644
--- a/source/blender/python/generic/mathutils_matrix.c
+++ b/source/blender/python/generic/mathutils_matrix.c
@@ -723,27 +723,25 @@ PyObject *Matrix_copy(MatrixObject * self)
static PyObject *Matrix_repr(MatrixObject * self)
{
int x, y;
- char buffer[48], str[1024];
+ char str[1024]="Matrix((", *str_p;
if(!BaseMath_ReadCallback(self))
return NULL;
-
- BLI_strncpy(str,"",1024);
+
+ str_p= &str[8];
+
for(x = 0; x < self->colSize; x++){
- sprintf(buffer, "[");
- strcat(str,buffer);
for(y = 0; y < (self->rowSize - 1); y++) {
- sprintf(buffer, "%.6f, ", self->matrix[y][x]);
- strcat(str,buffer);
+ str_p += sprintf(str_p, "%f, ", self->matrix[y][x]);
}
if(x < (self->colSize-1)){
- sprintf(buffer, "%.6f](matrix [row %d])\n", self->matrix[y][x], x);
- strcat(str,buffer);
- }else{
- sprintf(buffer, "%.6f](matrix [row %d])", self->matrix[y][x], x);
- strcat(str,buffer);
+ str_p += sprintf(str_p, "%f), (", self->matrix[y][x]);
+ }
+ else{
+ str_p += sprintf(str_p, "%f)", self->matrix[y][x]);
}
}
+ strcat(str_p, ")");
return PyUnicode_FromString(str);
}
diff --git a/source/blender/python/generic/mathutils_quat.c b/source/blender/python/generic/mathutils_quat.c
index 38fb2ae4903..3ee44b0378b 100644
--- a/source/blender/python/generic/mathutils_quat.c
+++ b/source/blender/python/generic/mathutils_quat.c
@@ -351,13 +351,24 @@ static PyObject *Quaternion_copy(QuaternionObject * self)
//print the object to screen
static PyObject *Quaternion_repr(QuaternionObject * self)
{
- char str[64];
+ PyObject *w, *x, *y, *z, *ret;
if(!BaseMath_ReadCallback(self))
return NULL;
- sprintf(str, "[%.6f, %.6f, %.6f, %.6f](quaternion)", self->quat[0], self->quat[1], self->quat[2], self->quat[3]);
- return PyUnicode_FromString(str);
+ w= PyFloat_FromDouble(self->quat[0]);
+ x= PyFloat_FromDouble(self->quat[1]);
+ y= PyFloat_FromDouble(self->quat[2]);
+ z= PyFloat_FromDouble(self->quat[3]);
+
+ ret= PyUnicode_FromFormat("Quaternion(%R, %R, %R, %R)", w, x, y, z);
+
+ Py_DECREF(w);
+ Py_DECREF(x);
+ Py_DECREF(y);
+ Py_DECREF(z);
+
+ return ret;
}
//------------------------tp_richcmpr
//returns -1 execption, 0 false, 1 true
diff --git a/source/blender/python/generic/mathutils_vector.c b/source/blender/python/generic/mathutils_vector.c
index e013a358393..1f51724c731 100644
--- a/source/blender/python/generic/mathutils_vector.c
+++ b/source/blender/python/generic/mathutils_vector.c
@@ -704,26 +704,33 @@ static PyObject *Vector_copy(VectorObject * self)
print the object to screen */
static PyObject *Vector_repr(VectorObject * self)
{
+ PyObject *axis[4], *ret;
int i;
- char buffer[48], str[1024];
if(!BaseMath_ReadCallback(self))
return NULL;
-
- BLI_strncpy(str,"[",1024);
- for(i = 0; i < self->size; i++){
- if(i < (self->size - 1)){
- sprintf(buffer, "%.6f, ", self->vec[i]);
- strcat(str,buffer);
- }else{
- sprintf(buffer, "%.6f", self->vec[i]);
- strcat(str,buffer);
- }
+
+ for(i = 0; i < self->size; i++)
+ axis[i] = PyFloat_FromDouble(self->vec[i]);
+
+ switch(self->size) {
+ case 2:
+ ret= PyUnicode_FromFormat("Vector(%R, %R)", axis[0], axis[1]);
+ break;
+ case 3:
+ ret= PyUnicode_FromFormat("Vector(%R, %R, %R)", axis[0], axis[1], axis[2]);
+ break;
+ case 4:
+ ret= PyUnicode_FromFormat("Vector(%R, %R, %R, %R)", axis[0], axis[1], axis[2], axis[3]);
+ break;
}
- strcat(str, "](vector)");
- return PyUnicode_FromString(str);
+ for(i = 0; i < self->size; i++)
+ Py_DECREF(axis[i]);
+
+ return ret;
}
+
/*---------------------SEQUENCE PROTOCOLS------------------------
----------------------------len(object)------------------------
sequence length*/
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 47c208608a4..7a0bde4fddb 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -1346,7 +1346,7 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop, in
return -1;
}
- if(!(value=PySequence_Fast(value_orig, "bpy_prop_array[slice] = value: type is not a sequence"))) {
+ if(!(value=PySequence_Fast(value_orig, "bpy_prop_array[slice] = value: assignment is not a sequence type"))) {
return -1;
}