[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45289] trunk/blender/source/blender/ python/mathutils: patch to add __deepcopy__ to mathutils types, this is no different to __copy__, except some py utilities expect __deepcopy__ to exist, so better have them .
Campbell Barton
ideasman42 at gmail.com
Fri Mar 30 13:36:11 CEST 2012
Revision: 45289
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45289
Author: campbellbarton
Date: 2012-03-30 11:35:58 +0000 (Fri, 30 Mar 2012)
Log Message:
-----------
patch to add __deepcopy__ to mathutils types, this is no different to __copy__, except some py utilities expect __deepcopy__ to exist, so better have them.
Modified Paths:
--------------
trunk/blender/source/blender/python/mathutils/mathutils.c
trunk/blender/source/blender/python/mathutils/mathutils.h
trunk/blender/source/blender/python/mathutils/mathutils_Color.c
trunk/blender/source/blender/python/mathutils/mathutils_Euler.c
trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c
trunk/blender/source/blender/python/mathutils/mathutils_Quaternion.c
trunk/blender/source/blender/python/mathutils/mathutils_Vector.c
Modified: trunk/blender/source/blender/python/mathutils/mathutils.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils.c 2012-03-30 10:37:49 UTC (rev 45288)
+++ trunk/blender/source/blender/python/mathutils/mathutils.c 2012-03-30 11:35:58 UTC (rev 45289)
@@ -282,6 +282,13 @@
return ret;
}
+/* silly function, we dont use arg. just check its compatible with __deepcopy__ */
+int mathutils_deepcopy_args_check(PyObject *args)
+{
+ PyObject *dummy_pydict;
+ return PyArg_ParseTuple(args, "|O!:__deepcopy__", &PyDict_Type, &dummy_pydict) == 0;
+}
+
/* Mathutils Callbacks */
/* for mathutils internal use only, eventually should re-alloc but to start with we only have a few users */
Modified: trunk/blender/source/blender/python/mathutils/mathutils.h
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils.h 2012-03-30 10:37:49 UTC (rev 45288)
+++ trunk/blender/source/blender/python/mathutils/mathutils.h 2012-03-30 11:35:58 UTC (rev 45289)
@@ -124,5 +124,6 @@
/* dynstr as python string utility funcions */
PyObject *mathutils_dynstr_to_py(struct DynStr *ds);
+int mathutils_deepcopy_args_check(PyObject *args);
#endif /* __MATHUTILS_H__ */
Modified: trunk/blender/source/blender/python/mathutils/mathutils_Color.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_Color.c 2012-03-30 10:37:49 UTC (rev 45288)
+++ trunk/blender/source/blender/python/mathutils/mathutils_Color.c 2012-03-30 11:35:58 UTC (rev 45289)
@@ -107,6 +107,12 @@
return Color_CreatePyObject(self->col, Py_NEW, Py_TYPE(self));
}
+static PyObject *Color_deepcopy(ColorObject *self, PyObject *args)
+{
+ if (mathutils_deepcopy_args_check(args))
+ return NULL;
+ return Color_copy(self);
+}
//----------------------------print object (internal)--------------
//print the object to screen
@@ -789,8 +795,9 @@
//-----------------------METHOD DEFINITIONS ----------------------
static struct PyMethodDef Color_methods[] = {
+ {"copy", (PyCFunction) Color_copy, METH_NOARGS, Color_copy_doc},
{"__copy__", (PyCFunction) Color_copy, METH_NOARGS, Color_copy_doc},
- {"copy", (PyCFunction) Color_copy, METH_NOARGS, Color_copy_doc},
+ {"__deepcopy__", (PyCFunction) Color_deepcopy, METH_VARARGS, Color_copy_doc},
{NULL, NULL, 0, NULL}
};
Modified: trunk/blender/source/blender/python/mathutils/mathutils_Euler.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_Euler.c 2012-03-30 10:37:49 UTC (rev 45288)
+++ trunk/blender/source/blender/python/mathutils/mathutils_Euler.c 2012-03-30 11:35:58 UTC (rev 45289)
@@ -299,6 +299,12 @@
return Euler_CreatePyObject(self->eul, self->order, Py_NEW, Py_TYPE(self));
}
+static PyObject *Euler_deepcopy(EulerObject *self, PyObject *args)
+{
+ if (mathutils_deepcopy_args_check(args))
+ return NULL;
+ return Euler_copy(self);
+}
//----------------------------print object (internal)--------------
//print the object to screen
@@ -632,8 +638,9 @@
{"rotate_axis", (PyCFunction) Euler_rotate_axis, METH_VARARGS, Euler_rotate_axis_doc},
{"rotate", (PyCFunction) Euler_rotate, METH_O, Euler_rotate_doc},
{"make_compatible", (PyCFunction) Euler_make_compatible, METH_O, Euler_make_compatible_doc},
+ {"copy", (PyCFunction) Euler_copy, METH_NOARGS, Euler_copy_doc},
{"__copy__", (PyCFunction) Euler_copy, METH_NOARGS, Euler_copy_doc},
- {"copy", (PyCFunction) Euler_copy, METH_NOARGS, Euler_copy_doc},
+ {"__deepcopy__", (PyCFunction) Euler_deepcopy, METH_VARARGS, Euler_copy_doc},
{NULL, NULL, 0, NULL}
};
Modified: trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c 2012-03-30 10:37:49 UTC (rev 45288)
+++ trunk/blender/source/blender/python/mathutils/mathutils_Matrix.c 2012-03-30 11:35:58 UTC (rev 45289)
@@ -44,6 +44,7 @@
} eMatrixAccess_t;
static PyObject *Matrix_copy(MatrixObject *self);
+static PyObject *Matrix_deepcopy(MatrixObject *self, PyObject *args);
static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *value);
static PyObject *matrix__apply_to_copy(PyNoArgsFunction matrix_func, MatrixObject *self);
static PyObject *MatrixAccess_CreatePyObject(MatrixObject *matrix, const eMatrixAccess_t type);
@@ -1519,6 +1520,12 @@
return Matrix_CreatePyObject((float (*))self->matrix, self->num_col, self->num_row, Py_NEW, Py_TYPE(self));
}
+static PyObject *Matrix_deepcopy(MatrixObject *self, PyObject *args)
+{
+ if (mathutils_deepcopy_args_check(args))
+ return NULL;
+ return Matrix_copy(self);
+}
/*----------------------------print object (internal)-------------*/
/* print the object to screen */
@@ -2269,6 +2276,7 @@
{"lerp", (PyCFunction) Matrix_lerp, METH_VARARGS, Matrix_lerp_doc},
{"copy", (PyCFunction) Matrix_copy, METH_NOARGS, Matrix_copy_doc},
{"__copy__", (PyCFunction) Matrix_copy, METH_NOARGS, Matrix_copy_doc},
+ {"__deepcopy__", (PyCFunction) Matrix_deepcopy, METH_VARARGS, Matrix_copy_doc},
/* class methods */
{"Identity", (PyCFunction) C_Matrix_Identity, METH_VARARGS | METH_CLASS, C_Matrix_Identity_doc},
Modified: trunk/blender/source/blender/python/mathutils/mathutils_Quaternion.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_Quaternion.c 2012-03-30 10:37:49 UTC (rev 45288)
+++ trunk/blender/source/blender/python/mathutils/mathutils_Quaternion.c 2012-03-30 11:35:58 UTC (rev 45289)
@@ -42,6 +42,7 @@
static PyObject *quat__apply_to_copy(PyNoArgsFunction quat_func, QuaternionObject *self);
static void quat__axis_angle_sanitize(float axis[3], float *angle);
static PyObject *Quaternion_copy(QuaternionObject *self);
+static PyObject *Quaternion_deepcopy(QuaternionObject *self, PyObject *args);
//-----------------------------METHODS------------------------------
@@ -478,6 +479,12 @@
return Quaternion_CreatePyObject(self->quat, Py_NEW, Py_TYPE(self));
}
+static PyObject *Quaternion_deepcopy(QuaternionObject *self, PyObject *args)
+{
+ if (mathutils_deepcopy_args_check(args))
+ return NULL;
+ return Quaternion_copy(self);
+}
//----------------------------print object (internal)--------------
//print the object to screen
@@ -1157,8 +1164,9 @@
{"slerp", (PyCFunction) Quaternion_slerp, METH_VARARGS, Quaternion_slerp_doc},
{"rotate", (PyCFunction) Quaternion_rotate, METH_O, Quaternion_rotate_doc},
+ {"copy", (PyCFunction) Quaternion_copy, METH_NOARGS, Quaternion_copy_doc},
{"__copy__", (PyCFunction) Quaternion_copy, METH_NOARGS, Quaternion_copy_doc},
- {"copy", (PyCFunction) Quaternion_copy, METH_NOARGS, Quaternion_copy_doc},
+ {"__deepcopy__", (PyCFunction) Quaternion_deepcopy, METH_VARARGS, Quaternion_copy_doc},
{NULL, NULL, 0, NULL}
};
Modified: trunk/blender/source/blender/python/mathutils/mathutils_Vector.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_Vector.c 2012-03-30 10:37:49 UTC (rev 45288)
+++ trunk/blender/source/blender/python/mathutils/mathutils_Vector.c 2012-03-30 11:35:58 UTC (rev 45289)
@@ -47,6 +47,7 @@
#define SWIZZLE_AXIS 0x3
static PyObject *Vector_copy(VectorObject *self);
+static PyObject *Vector_deepcopy(VectorObject *self, PyObject *args);
static PyObject *Vector_to_tuple_ext(VectorObject *self, int ndigits);
static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *vec, MatrixObject *mat);
@@ -1211,6 +1212,12 @@
return Vector_CreatePyObject(self->vec, self->size, Py_NEW, Py_TYPE(self));
}
+static PyObject *Vector_deepcopy(VectorObject *self, PyObject *args)
+{
+ if (mathutils_deepcopy_args_check(args))
+ return NULL;
+ return Vector_copy(self);
+}
static PyObject *Vector_repr(VectorObject *self)
{
@@ -2767,6 +2774,7 @@
{"copy", (PyCFunction) Vector_copy, METH_NOARGS, Vector_copy_doc},
{"__copy__", (PyCFunction) Vector_copy, METH_NOARGS, NULL},
+ {"__deepcopy__", (PyCFunction) Vector_deepcopy, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}
};
More information about the Bf-blender-cvs
mailing list