diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-04-27 01:04:42 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-04-27 01:04:42 +0400 |
commit | 6bb55fd93eb728b07a04dbe5c440a6525dd6cef1 (patch) | |
tree | dd538dea8bb24f7fda6a8ea3c47d015af8ec5361 | |
parent | 523b95898bc6ec94171eccee9f3a8801e10c233a (diff) |
py/rna, euler objects order is now wrapped correctly...
eg:
eul = bpy.context.object.rotation_euler
eul.order = 'XZY' # will update the objects setting.
-rw-r--r-- | source/blender/python/generic/mathutils.c | 8 | ||||
-rw-r--r-- | source/blender/python/generic/mathutils.h | 20 | ||||
-rw-r--r-- | source/blender/python/generic/mathutils_color.c | 8 | ||||
-rw-r--r-- | source/blender/python/generic/mathutils_euler.c | 12 | ||||
-rw-r--r-- | source/blender/python/generic/mathutils_matrix.c | 18 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 46 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.cpp | 30 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_ObjectActuator.cpp | 22 |
8 files changed, 97 insertions, 67 deletions
diff --git a/source/blender/python/generic/mathutils.c b/source/blender/python/generic/mathutils.c index a9a682bf998..83477fefd97 100644 --- a/source/blender/python/generic/mathutils.c +++ b/source/blender/python/generic/mathutils.c @@ -646,7 +646,7 @@ int Mathutils_RegisterCallback(Mathutils_Callback *cb) int _BaseMathObject_ReadCallback(BaseMathObject *self) { Mathutils_Callback *cb= mathutils_callbacks[self->cb_type]; - if(cb->get(self->cb_user, self->cb_subtype, self->data)) + if(cb->get(self, self->cb_subtype, self->data)) return 1; PyErr_Format(PyExc_SystemError, "%s user has become invalid", Py_TYPE(self)->tp_name); @@ -656,7 +656,7 @@ int _BaseMathObject_ReadCallback(BaseMathObject *self) int _BaseMathObject_WriteCallback(BaseMathObject *self) { Mathutils_Callback *cb= mathutils_callbacks[self->cb_type]; - if(cb->set(self->cb_user, self->cb_subtype, self->data)) + if(cb->set(self, self->cb_subtype, self->data)) return 1; PyErr_Format(PyExc_SystemError, "%s user has become invalid", Py_TYPE(self)->tp_name); @@ -666,7 +666,7 @@ int _BaseMathObject_WriteCallback(BaseMathObject *self) int _BaseMathObject_ReadIndexCallback(BaseMathObject *self, int index) { Mathutils_Callback *cb= mathutils_callbacks[self->cb_type]; - if(cb->get_index(self->cb_user, self->cb_subtype, self->data, index)) + if(cb->get_index(self, self->cb_subtype, self->data, index)) return 1; PyErr_Format(PyExc_SystemError, "%s user has become invalid", Py_TYPE(self)->tp_name); @@ -676,7 +676,7 @@ int _BaseMathObject_ReadIndexCallback(BaseMathObject *self, int index) int _BaseMathObject_WriteIndexCallback(BaseMathObject *self, int index) { Mathutils_Callback *cb= mathutils_callbacks[self->cb_type]; - if(cb->set_index(self->cb_user, self->cb_subtype, self->data, index)) + if(cb->set_index(self, self->cb_subtype, self->data, index)) return 1; PyErr_Format(PyExc_SystemError, "%s user has become invalid", Py_TYPE(self)->tp_name); diff --git a/source/blender/python/generic/mathutils.h b/source/blender/python/generic/mathutils.h index eb6ddf3492e..49d198dff76 100644 --- a/source/blender/python/generic/mathutils.h +++ b/source/blender/python/generic/mathutils.h @@ -88,18 +88,18 @@ int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps); typedef struct Mathutils_Callback Mathutils_Callback; -typedef int (*BaseMathCheckFunc)(PyObject *); -typedef int (*BaseMathGetFunc)(PyObject *, int, float *); -typedef int (*BaseMathSetFunc)(PyObject *, int, float *); -typedef int (*BaseMathGetIndexFunc)(PyObject *, int, float *, int); -typedef int (*BaseMathSetIndexFunc)(PyObject *, int, float *, int); +typedef int (*BaseMathCheckFunc)(BaseMathObject *); /* checks the user is still valid */ +typedef int (*BaseMathGetFunc)(BaseMathObject *, int, float *); /* gets the vector from the user */ +typedef int (*BaseMathSetFunc)(BaseMathObject *, int, float *); /* sets the users vector values once the vector is modified */ +typedef int (*BaseMathGetIndexFunc)(BaseMathObject *, int, float *, int); /* same as above but only for an index */ +typedef int (*BaseMathSetIndexFunc)(BaseMathObject *, int, float *, int); /* same as above but only for an index */ struct Mathutils_Callback { - int (*check)(PyObject *user); /* checks the user is still valid */ - int (*get)(PyObject *user, int subtype, float *from); /* gets the vector from the user */ - int (*set)(PyObject *user, int subtype, float *to); /* sets the users vector values once the vector is modified */ - int (*get_index)(PyObject *user, int subtype, float *from,int index); /* same as above but only for an index */ - int (*set_index)(PyObject *user, int subtype, float *to, int index); /* same as above but only for an index */ + BaseMathCheckFunc check; + BaseMathGetFunc get; + BaseMathSetFunc set; + BaseMathGetIndexFunc get_index; + BaseMathSetIndexFunc set_index; }; int Mathutils_RegisterCallback(Mathutils_Callback *cb); diff --git a/source/blender/python/generic/mathutils_color.c b/source/blender/python/generic/mathutils_color.c index ce2a81c5005..34c8dd88b4b 100644 --- a/source/blender/python/generic/mathutils_color.c +++ b/source/blender/python/generic/mathutils_color.c @@ -280,13 +280,13 @@ static PyObject *Color_subscript(ColorObject *self, PyObject *item) return Color_slice(self, start, stop); } else { - PyErr_SetString(PyExc_TypeError, "slice steps not supported with eulers"); + PyErr_SetString(PyExc_TypeError, "slice steps not supported with color"); return NULL; } } else { PyErr_Format(PyExc_TypeError, - "euler indices must be integers, not %.200s", + "color indices must be integers, not %.200s", item->ob_type->tp_name); return NULL; } @@ -311,13 +311,13 @@ static int Color_ass_subscript(ColorObject *self, PyObject *item, PyObject *valu if (step == 1) return Color_ass_slice(self, start, stop, value); else { - PyErr_SetString(PyExc_TypeError, "slice steps not supported with euler"); + PyErr_SetString(PyExc_TypeError, "slice steps not supported with color"); return -1; } } else { PyErr_Format(PyExc_TypeError, - "euler indices must be integers, not %.200s", + "color indices must be integers, not %.200s", item->ob_type->tp_name); return -1; } diff --git a/source/blender/python/generic/mathutils_euler.c b/source/blender/python/generic/mathutils_euler.c index e3635012d91..3bda1b3a991 100644 --- a/source/blender/python/generic/mathutils_euler.c +++ b/source/blender/python/generic/mathutils_euler.c @@ -587,7 +587,11 @@ static int Euler_setAxis( EulerObject * self, PyObject * value, void * type ) /* rotation order */ static PyObject *Euler_getOrder(EulerObject *self, void *type) { - static char order[][4] = {"XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX"}; + const char order[][4] = {"XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX"}; + + if(!BaseMath_ReadCallback(self)) /* can read order too */ + return NULL; + return PyUnicode_FromString(order[self->order-EULER_ORDER_XYZ]); } @@ -599,12 +603,8 @@ static int Euler_setOrder( EulerObject * self, PyObject * value, void * type ) if(order == -1) return -1; - if(self->cb_user) { - PyErr_SetString(PyExc_TypeError, "euler.order: assignment is not allowed on eulers with an owner"); - return -1; - } - self->order= order; + BaseMath_WriteCallback(self); /* order can be written back */ return 0; } diff --git a/source/blender/python/generic/mathutils_matrix.c b/source/blender/python/generic/mathutils_matrix.c index 79b6b6f0fde..24f1e283c8a 100644 --- a/source/blender/python/generic/mathutils_matrix.c +++ b/source/blender/python/generic/mathutils_matrix.c @@ -37,15 +37,15 @@ static PyObject *column_vector_multiplication(MatrixObject * mat, VectorObject* /* matrix vector callbacks */ int mathutils_matrix_vector_cb_index= -1; -static int mathutils_matrix_vector_check(PyObject *self_p) +static int mathutils_matrix_vector_check(BaseMathObject *self_p) { - MatrixObject *self= (MatrixObject*)self_p; + MatrixObject *self= (MatrixObject *)self_p; return BaseMath_ReadCallback(self); } -static int mathutils_matrix_vector_get(PyObject *self_p, int subtype, float *vec_from) +static int mathutils_matrix_vector_get(BaseMathObject *self_p, int subtype, float *vec_from) { - MatrixObject *self= (MatrixObject*)self_p; + MatrixObject *self= (MatrixObject *)self_p; int i; if(!BaseMath_ReadCallback(self)) @@ -57,9 +57,9 @@ static int mathutils_matrix_vector_get(PyObject *self_p, int subtype, float *vec return 1; } -static int mathutils_matrix_vector_set(PyObject *self_p, int subtype, float *vec_to) +static int mathutils_matrix_vector_set(BaseMathObject *self_p, int subtype, float *vec_to) { - MatrixObject *self= (MatrixObject*)self_p; + MatrixObject *self= (MatrixObject *)self_p; int i; if(!BaseMath_ReadCallback(self)) @@ -72,9 +72,9 @@ static int mathutils_matrix_vector_set(PyObject *self_p, int subtype, float *vec return 1; } -static int mathutils_matrix_vector_get_index(PyObject *self_p, int subtype, float *vec_from, int index) +static int mathutils_matrix_vector_get_index(BaseMathObject *self_p, int subtype, float *vec_from, int index) { - MatrixObject *self= (MatrixObject*)self_p; + MatrixObject *self= (MatrixObject *)self_p; if(!BaseMath_ReadCallback(self)) return 0; @@ -83,7 +83,7 @@ static int mathutils_matrix_vector_get_index(PyObject *self_p, int subtype, floa return 1; } -static int mathutils_matrix_vector_set_index(PyObject *self_p, int subtype, float *vec_to, int index) +static int mathutils_matrix_vector_set_index(BaseMathObject *self_p, int subtype, float *vec_to, int index) { MatrixObject *self= (MatrixObject*)self_p; diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 0f408ea3310..77657f35a15 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -68,22 +68,34 @@ static int mathutils_rna_array_cb_index= -1; /* index for our callbacks */ #define MATHUTILS_CB_SUBTYPE_QUAT 2 #define MATHUTILS_CB_SUBTYPE_COLOR 0 -static int mathutils_rna_generic_check(BPy_PropertyRNA *self) +static int mathutils_rna_generic_check(BaseMathObject *bmo) { - return self->prop?1:0; + BPy_PropertyRNA *self= (BPy_PropertyRNA *)bmo->cb_user; + return self->prop ? 1:0; } -static int mathutils_rna_vector_get(BPy_PropertyRNA *self, int subtype, float *vec_from) +static int mathutils_rna_vector_get(BaseMathObject *bmo, int subtype, float *vec_from) { + BPy_PropertyRNA *self= (BPy_PropertyRNA *)bmo->cb_user; if(self->prop==NULL) return 0; RNA_property_float_get_array(&self->ptr, self->prop, vec_from); + + /* Euler order exception */ + if(subtype==MATHUTILS_CB_SUBTYPE_EUL) { + PropertyRNA *prop_eul_order= RNA_struct_find_property(&self->ptr, "rotation_mode"); + if(prop_eul_order) { + ((EulerObject *)bmo)->order= RNA_property_enum_get(&self->ptr, prop_eul_order); + } + } + return 1; } -static int mathutils_rna_vector_set(BPy_PropertyRNA *self, int subtype, float *vec_to) +static int mathutils_rna_vector_set(BaseMathObject *bmo, int subtype, float *vec_to) { + BPy_PropertyRNA *self= (BPy_PropertyRNA *)bmo->cb_user; float min, max; if(self->prop==NULL) return 0; @@ -98,12 +110,24 @@ static int mathutils_rna_vector_set(BPy_PropertyRNA *self, int subtype, float *v } RNA_property_float_set_array(&self->ptr, self->prop, vec_to); + + /* Euler order exception */ + if(subtype==MATHUTILS_CB_SUBTYPE_EUL) { + PropertyRNA *prop_eul_order= RNA_struct_find_property(&self->ptr, "rotation_mode"); + if(prop_eul_order) { + RNA_property_enum_set(&self->ptr, prop_eul_order, ((EulerObject *)bmo)->order); + RNA_property_update(BPy_GetContext(), &self->ptr, prop_eul_order); + } + } + RNA_property_update(BPy_GetContext(), &self->ptr, self->prop); return 1; } -static int mathutils_rna_vector_get_index(BPy_PropertyRNA *self, int subtype, float *vec_from, int index) +static int mathutils_rna_vector_get_index(BaseMathObject *bmo, int subtype, float *vec_from, int index) { + BPy_PropertyRNA *self= (BPy_PropertyRNA *)bmo->cb_user; + if(self->prop==NULL) return 0; @@ -111,8 +135,10 @@ static int mathutils_rna_vector_get_index(BPy_PropertyRNA *self, int subtype, fl return 1; } -static int mathutils_rna_vector_set_index(BPy_PropertyRNA *self, int subtype, float *vec_to, int index) +static int mathutils_rna_vector_set_index(BaseMathObject *bmo, int subtype, float *vec_to, int index) { + BPy_PropertyRNA *self= (BPy_PropertyRNA *)bmo->cb_user; + if(self->prop==NULL) return 0; @@ -134,8 +160,10 @@ Mathutils_Callback mathutils_rna_array_cb = { /* bpyrna matrix callbacks */ static int mathutils_rna_matrix_cb_index= -1; /* index for our callbacks */ -static int mathutils_rna_matrix_get(BPy_PropertyRNA *self, int subtype, float *mat_from) +static int mathutils_rna_matrix_get(BaseMathObject *bmo, int subtype, float *mat_from) { + BPy_PropertyRNA *self= (BPy_PropertyRNA *)bmo->cb_user; + if(self->prop==NULL) return 0; @@ -143,8 +171,10 @@ static int mathutils_rna_matrix_get(BPy_PropertyRNA *self, int subtype, float *m return 1; } -static int mathutils_rna_matrix_set(BPy_PropertyRNA *self, int subtype, float *mat_to) +static int mathutils_rna_matrix_set(BaseMathObject *bmo, int subtype, float *mat_to) { + BPy_PropertyRNA *self= (BPy_PropertyRNA *)bmo->cb_user; + if(self->prop==NULL) return 0; /* can ignore clamping here */ diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index c62a20aa852..776207ef209 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1252,18 +1252,18 @@ void KX_GameObject::Relink(GEN_Map<GEN_HashedPtr, void*> *map_parameter) static int mathutils_kxgameob_vector_cb_index= -1; /* index for our callbacks */ -static int mathutils_kxgameob_generic_check(PyObject *self_v) +static int mathutils_kxgameob_generic_check(BaseMathObject *bmo) { - KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(self_v); + KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(bmo->cb_user); if(self==NULL) return 0; return 1; } -static int mathutils_kxgameob_vector_get(PyObject *self_v, int subtype, float *vec_from) +static int mathutils_kxgameob_vector_get(BaseMathObject *bmo, int subtype, float *vec_from) { - KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(self_v); + KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(bmo->cb_user); if(self==NULL) return 0; @@ -1309,9 +1309,9 @@ static int mathutils_kxgameob_vector_get(PyObject *self_v, int subtype, float *v return 1; } -static int mathutils_kxgameob_vector_set(PyObject *self_v, int subtype, float *vec_to) +static int mathutils_kxgameob_vector_set(BaseMathObject *bmo, int subtype, float *vec_to) { - KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(self_v); + KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(bmo->cb_user); if(self==NULL) return 0; @@ -1353,27 +1353,27 @@ static int mathutils_kxgameob_vector_set(PyObject *self_v, int subtype, float *v return 1; } -static int mathutils_kxgameob_vector_get_index(PyObject *self_v, int subtype, float *vec_from, int index) +static int mathutils_kxgameob_vector_get_index(BaseMathObject *bmo, int subtype, float *vec_from, int index) { float f[4]; /* lazy, avoid repeteing the case statement */ - if(!mathutils_kxgameob_vector_get(self_v, subtype, f)) + if(!mathutils_kxgameob_vector_get(bmo, subtype, f)) return 0; vec_from[index]= f[index]; return 1; } -static int mathutils_kxgameob_vector_set_index(PyObject *self_v, int subtype, float *vec_to, int index) +static int mathutils_kxgameob_vector_set_index(BaseMathObject *bmo, int subtype, float *vec_to, int index) { float f= vec_to[index]; /* lazy, avoid repeteing the case statement */ - if(!mathutils_kxgameob_vector_get(self_v, subtype, vec_to)) + if(!mathutils_kxgameob_vector_get(bmo, subtype, vec_to)) return 0; vec_to[index]= f; - mathutils_kxgameob_vector_set(self_v, subtype, vec_to); + mathutils_kxgameob_vector_set(bmo, subtype, vec_to); return 1; } @@ -1392,9 +1392,9 @@ Mathutils_Callback mathutils_kxgameob_vector_cb = { static int mathutils_kxgameob_matrix_cb_index= -1; /* index for our callbacks */ -static int mathutils_kxgameob_matrix_get(PyObject *self_v, int subtype, float *mat_from) +static int mathutils_kxgameob_matrix_get(BaseMathObject *bmo, int subtype, float *mat_from) { - KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(self_v); + KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(bmo->cb_user); if(self==NULL) return 0; @@ -1411,9 +1411,9 @@ static int mathutils_kxgameob_matrix_get(PyObject *self_v, int subtype, float *m } -static int mathutils_kxgameob_matrix_set(PyObject *self_v, int subtype, float *mat_to) +static int mathutils_kxgameob_matrix_set(BaseMathObject *bmo, int subtype, float *mat_to) { - KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(self_v); + KX_GameObject* self= static_cast<KX_GameObject*>BGE_PROXY_REF(bmo->cb_user); if(self==NULL) return 0; diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp index c93ebe2ee8b..824017f5704 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp @@ -383,18 +383,18 @@ PyAttributeDef KX_ObjectActuator::Attributes[] = { static int mathutils_kxobactu_vector_cb_index= -1; /* index for our callbacks */ -static int mathutils_obactu_generic_check(PyObject *self_v) +static int mathutils_obactu_generic_check(BaseMathObject *bmo) { - KX_ObjectActuator* self= static_cast<KX_ObjectActuator*>BGE_PROXY_REF(self_v); + KX_ObjectActuator* self= static_cast<KX_ObjectActuator*>BGE_PROXY_REF(bmo->cb_user); if(self==NULL) return 0; return 1; } -static int mathutils_obactu_vector_get(PyObject *self_v, int subtype, float *vec_from) +static int mathutils_obactu_vector_get(BaseMathObject *bmo, int subtype, float *vec_from) { - KX_ObjectActuator* self= static_cast<KX_ObjectActuator*>BGE_PROXY_REF(self_v); + KX_ObjectActuator* self= static_cast<KX_ObjectActuator*>BGE_PROXY_REF(bmo->cb_user); if(self==NULL) return 0; @@ -410,9 +410,9 @@ static int mathutils_obactu_vector_get(PyObject *self_v, int subtype, float *vec return 1; } -static int mathutils_obactu_vector_set(PyObject *self_v, int subtype, float *vec_to) +static int mathutils_obactu_vector_set(BaseMathObject *bmo, int subtype, float *vec_to) { - KX_ObjectActuator* self= static_cast<KX_ObjectActuator*>BGE_PROXY_REF(self_v); + KX_ObjectActuator* self= static_cast<KX_ObjectActuator*>BGE_PROXY_REF(bmo->cb_user); if(self==NULL) return 0; @@ -428,27 +428,27 @@ static int mathutils_obactu_vector_set(PyObject *self_v, int subtype, float *vec return 1; } -static int mathutils_obactu_vector_get_index(PyObject *self_v, int subtype, float *vec_from, int index) +static int mathutils_obactu_vector_get_index(BaseMathObject *bmo, int subtype, float *vec_from, int index) { float f[4]; /* lazy, avoid repeteing the case statement */ - if(!mathutils_obactu_vector_get(self_v, subtype, f)) + if(!mathutils_obactu_vector_get(bmo, subtype, f)) return 0; vec_from[index]= f[index]; return 1; } -static int mathutils_obactu_vector_set_index(PyObject *self_v, int subtype, float *vec_to, int index) +static int mathutils_obactu_vector_set_index(BaseMathObject *bmo, int subtype, float *vec_to, int index) { float f= vec_to[index]; /* lazy, avoid repeteing the case statement */ - if(!mathutils_obactu_vector_get(self_v, subtype, vec_to)) + if(!mathutils_obactu_vector_get(bmo, subtype, vec_to)) return 0; vec_to[index]= f; - mathutils_obactu_vector_set(self_v, subtype, vec_to); + mathutils_obactu_vector_set(bmo, subtype, vec_to); return 1; } |