- pyrna support for (value in array), currently only 1 dimensional arrays.

- use python malloc's in bpy_array.c
- automatically blending bone locations is disabled if the target bone has locked location
- neck had incorrect roll
This commit is contained in:
Campbell Barton 2009-12-08 09:40:30 +00:00
parent c146ce977c
commit fccceaa87f
5 changed files with 119 additions and 21 deletions

@ -272,7 +272,8 @@ def blend_bone_list(obj, apply_bones, from_bones, to_bones, target_bone=None, ta
new_pbone = obj.pose.bones[new_bone_name]
if not new_pbone.bone.connected:
# if the bone is connected or its location is totally locked then dont add location blending.
if not (new_pbone.bone.connected or (False not in new_pbone.lock_location)):
blend_location(new_pbone, from_bone_name, to_bone_name)
blend_rotation(new_pbone, from_bone_name, to_bone_name)

@ -160,7 +160,7 @@ def main(obj, bone_definition, base_names):
neck_e_parent = arm.edit_bones.new("MCH-rot_%s" % neck_e.name)
neck_e_parent.head = neck_e.head
neck_e_parent.tail = neck_e.head + ((mt.head_e.tail - mt.head_e.head).normalize() * neck_chain_segment_length / 2.0)
neck_e_parent.roll = neck_e.roll
neck_e_parent.roll = mt.head_e.roll
orig_parent = neck_e.parent

@ -32,8 +32,6 @@
#include "BKE_global.h"
#include "MEM_guardedalloc.h"
#define MAX_ARRAY_DIMENSION 10
typedef void (*ItemConvertFunc)(PyObject *, char *);
@ -258,7 +256,7 @@ static int py_to_array(PyObject *py, PointerRNA *ptr, PropertyRNA *prop, char *p
if (totitem) {
if (!param_data || RNA_property_flag(prop) & PROP_DYNAMIC)
data= MEM_callocN(item_size * totitem, "pyrna primitive type array");
data= PyMem_MALLOC(item_size * totitem);
else
data= param_data;
@ -273,7 +271,7 @@ static int py_to_array(PyObject *py, PointerRNA *ptr, PropertyRNA *prop, char *p
else {
/* NULL can only pass through in case RNA property arraylength is 0 (impossible?) */
rna_set_array(ptr, prop, data);
MEM_freeN(data);
PyMem_FREE(data);
}
}
@ -513,3 +511,94 @@ PyObject *pyrna_py_from_array(PointerRNA *ptr, PropertyRNA *prop)
return pyrna_prop_CreatePyObject(ptr, prop);
}
/* TODO, multi-dimensional arrays */
int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
{
int len= RNA_property_array_length(ptr, prop);
int type;
int i;
if(len==0) /* possible with dynamic arrays */
return 0;
if (RNA_property_array_dimension(ptr, prop, NULL) > 1) {
PyErr_SetString(PyExc_TypeError, "PropertyRNA - multi dimensional arrays not supported yet");
return -1;
}
type= RNA_property_type(prop);
switch (type) {
case PROP_FLOAT:
{
float value_f= PyFloat_AsDouble(value);
if(value_f==-1 && PyErr_Occurred()) {
PyErr_Clear();
return 0;
}
else {
float tmp[32];
float *tmp_arr;
if(len * sizeof(float) > sizeof(tmp)) {
tmp_arr= PyMem_MALLOC(len * sizeof(float));
}
else {
tmp_arr= tmp;
}
RNA_property_float_get_array(ptr, prop, tmp_arr);
for(i=0; i<len; i++)
if(tmp_arr[i] == value_f)
break;
if(tmp_arr != tmp)
PyMem_FREE(tmp_arr);
return i<len ? 1 : 0;
}
break;
}
case PROP_BOOLEAN:
case PROP_INT:
{
int value_i= PyLong_AsSsize_t(value);
if(value_i==-1 && PyErr_Occurred()) {
PyErr_Clear();
return 0;
}
else {
int tmp[32];
int *tmp_arr;
if(len * sizeof(int) > sizeof(tmp)) {
tmp_arr= PyMem_MALLOC(len * sizeof(int));
}
else {
tmp_arr= tmp;
}
if(type==PROP_BOOLEAN)
RNA_property_boolean_get_array(ptr, prop, tmp_arr);
else
RNA_property_int_get_array(ptr, prop, tmp_arr);
for(i=0; i<len; i++)
if(tmp_arr[i] == value_i)
break;
if(tmp_arr != tmp)
PyMem_FREE(tmp_arr);
return i<len ? 1 : 0;
}
break;
}
}
/* should never reach this */
PyErr_SetString(PyExc_TypeError, "PropertyRNA - type not in float/bool/int");
return -1;
}

@ -1167,22 +1167,29 @@ static PyMappingMethods pyrna_prop_as_mapping = {
static int pyrna_prop_contains(BPy_PropertyRNA *self, PyObject *value)
{
PointerRNA newptr; /* not used, just so RNA_property_collection_lookup_string runs */
char *keyname = _PyUnicode_AsString(value);
if(keyname==NULL) {
PyErr_SetString(PyExc_TypeError, "PropertyRNA - key in prop, key must be a string type");
if (RNA_property_type(self->prop) == PROP_COLLECTION) {
/* key in dict style check */
char *keyname = _PyUnicode_AsString(value);
if(keyname==NULL) {
PyErr_SetString(PyExc_TypeError, "PropertyRNA - key in prop, key must be a string type");
return -1;
}
if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr))
return 1;
}
else if (RNA_property_array_check(&self->ptr, self->prop)) {
/* value in list style check */
return pyrna_array_contains_py(&self->ptr, self->prop, value);
}
else {
PyErr_SetString(PyExc_TypeError, "PropertyRNA - type is not an array or a collection");
return -1;
}
if (RNA_property_type(self->prop) != PROP_COLLECTION) {
PyErr_SetString(PyExc_TypeError, "PropertyRNA - key in prop, is only valid for collection types");
return -1;
}
if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr))
return 1;
return 0;
}
@ -2264,6 +2271,9 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set)
}
}
if(array)
PyMem_Free(array);
if(PyErr_Occurred()) {
/* Maybe we could make our own error */
PyErr_Print();
@ -2275,9 +2285,6 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set)
return NULL;
}
if(array)
PyMem_Free(array);
Py_RETURN_NONE;
}

@ -103,5 +103,6 @@ int pyrna_py_to_array_index(PointerRNA *ptr, PropertyRNA *prop, int arraydim, in
PyObject *pyrna_py_from_array(PointerRNA *ptr, PropertyRNA *prop);
PyObject *pyrna_py_from_array_index(BPy_PropertyRNA *self, int index);
PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop);
int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value);
#endif