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:
authorCampbell Barton <ideasman42@gmail.com>2012-03-30 15:35:58 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-03-30 15:35:58 +0400
commit89b83f00608dfb2a7750476035f0635885473d21 (patch)
tree4f11557bb830061c37826aacb6fa54f8213cd609 /source/blender/python/mathutils
parent785373b03abd7bfd258a50a0f274c81229fbf98a (diff)
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.
Diffstat (limited to 'source/blender/python/mathutils')
-rw-r--r--source/blender/python/mathutils/mathutils.c7
-rw-r--r--source/blender/python/mathutils/mathutils.h1
-rw-r--r--source/blender/python/mathutils/mathutils_Color.c9
-rw-r--r--source/blender/python/mathutils/mathutils_Euler.c9
-rw-r--r--source/blender/python/mathutils/mathutils_Matrix.c8
-rw-r--r--source/blender/python/mathutils/mathutils_Quaternion.c10
-rw-r--r--source/blender/python/mathutils/mathutils_Vector.c8
7 files changed, 49 insertions, 3 deletions
diff --git a/source/blender/python/mathutils/mathutils.c b/source/blender/python/mathutils/mathutils.c
index 5d3de702fb4..5f9e68f07d8 100644
--- a/source/blender/python/mathutils/mathutils.c
+++ b/source/blender/python/mathutils/mathutils.c
@@ -282,6 +282,13 @@ PyObject *mathutils_dynstr_to_py(struct DynStr *ds)
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 */
diff --git a/source/blender/python/mathutils/mathutils.h b/source/blender/python/mathutils/mathutils.h
index 75ea18c2df1..b98928eb79d 100644
--- a/source/blender/python/mathutils/mathutils.h
+++ b/source/blender/python/mathutils/mathutils.h
@@ -124,5 +124,6 @@ int column_vector_multiplication(float rvec[4], VectorObject *vec, MatrixObject
/* dynstr as python string utility funcions */
PyObject *mathutils_dynstr_to_py(struct DynStr *ds);
+int mathutils_deepcopy_args_check(PyObject *args);
#endif /* __MATHUTILS_H__ */
diff --git a/source/blender/python/mathutils/mathutils_Color.c b/source/blender/python/mathutils/mathutils_Color.c
index 3b60d6655d6..9b06214b8ec 100644
--- a/source/blender/python/mathutils/mathutils_Color.c
+++ b/source/blender/python/mathutils/mathutils_Color.c
@@ -107,6 +107,12 @@ static PyObject *Color_copy(ColorObject *self)
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 @@ static PyGetSetDef Color_getseters[] = {
//-----------------------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}
};
diff --git a/source/blender/python/mathutils/mathutils_Euler.c b/source/blender/python/mathutils/mathutils_Euler.c
index ecd0cee03b5..4e3b5f8d52e 100644
--- a/source/blender/python/mathutils/mathutils_Euler.c
+++ b/source/blender/python/mathutils/mathutils_Euler.c
@@ -299,6 +299,12 @@ static PyObject *Euler_copy(EulerObject *self)
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 @@ static struct PyMethodDef Euler_methods[] = {
{"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}
};
diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c
index 472933fab57..4079d69b87d 100644
--- a/source/blender/python/mathutils/mathutils_Matrix.c
+++ b/source/blender/python/mathutils/mathutils_Matrix.c
@@ -44,6 +44,7 @@ typedef enum eMatrixAccess_t {
} 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 @@ static PyObject *Matrix_copy(MatrixObject *self)
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 @@ static struct PyMethodDef Matrix_methods[] = {
{"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},
diff --git a/source/blender/python/mathutils/mathutils_Quaternion.c b/source/blender/python/mathutils/mathutils_Quaternion.c
index da27c7a57bb..2a1cef5a241 100644
--- a/source/blender/python/mathutils/mathutils_Quaternion.c
+++ b/source/blender/python/mathutils/mathutils_Quaternion.c
@@ -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 @@ static PyObject *Quaternion_copy(QuaternionObject *self)
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 @@ static struct PyMethodDef Quaternion_methods[] = {
{"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}
};
diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c
index fbf30bcb387..17fa9cdd802 100644
--- a/source/blender/python/mathutils/mathutils_Vector.c
+++ b/source/blender/python/mathutils/mathutils_Vector.c
@@ -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 @@ static PyObject *Vector_copy(VectorObject *self)
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 @@ static struct PyMethodDef Vector_methods[] = {
{"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}
};