Merged changes in the trunk up to revision 27063.

This commit is contained in:
2010-02-21 21:47:52 +00:00
131 changed files with 3323 additions and 1699 deletions

View File

@@ -82,11 +82,20 @@ static PyObject *bpy_prop_deferred_return(void *func, PyObject *kw)
{
PyObject *ret = PyTuple_New(2);
PyTuple_SET_ITEM(ret, 0, PyCapsule_New(func, NULL, NULL));
if(kw==NULL) kw= PyDict_New();
else Py_INCREF(kw);
PyTuple_SET_ITEM(ret, 1, kw);
Py_INCREF(kw);
return ret;
}
static int bpy_struct_id_used(StructRNA *srna, char *identifier)
{
PointerRNA ptr;
RNA_pointer_create(NULL, srna, NULL, &ptr);
return (RNA_struct_find_property(&ptr, identifier) != NULL);
}
/* Function that sets RNA, NOTE - self is NULL when called from python, but being abused from C so we can pass the srna allong
* This isnt incorrect since its a python object - but be careful */
static char BPy_BoolProperty_doc[] =
@@ -104,7 +113,7 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
StructRNA *srna;
if (PyTuple_GET_SIZE(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this.
PyErr_SetString(PyExc_ValueError, "all args must be keywords");
return NULL;
}
@@ -125,11 +134,17 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssiO!s:BoolProperty", (char **)kwlist, &id, &name, &description, &def, &PySet_Type, &pyopts, &pysubtype))
return NULL;
if(bpy_struct_id_used(srna, id)) {
// PyErr_Format(PyExc_TypeError, "BoolProperty(): '%s' already defined.", id);
// return NULL;
Py_RETURN_NONE;
}
if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "BoolProperty(options={...}):"))
return NULL;
if(pysubtype && RNA_enum_value_from_id(property_subtype_number_items, pysubtype, &subtype)==0) {
PyErr_Format(PyExc_TypeError, "BoolProperty(subtype='%s'): invalid subtype.");
PyErr_Format(PyExc_TypeError, "BoolProperty(subtype='%s'): invalid subtype.", pysubtype);
return NULL;
}
@@ -164,7 +179,7 @@ PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
StructRNA *srna;
if (PyTuple_GET_SIZE(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this.
PyErr_SetString(PyExc_ValueError, "all args must be keywords");
return NULL;
}
@@ -187,11 +202,17 @@ PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssOO!si:BoolVectorProperty", (char **)kwlist, &id, &name, &description, &pydef, &PySet_Type, &pyopts, &pysubtype, &size))
return NULL;
if(bpy_struct_id_used(srna, id)) {
// PyErr_Format(PyExc_TypeError, "BoolVectorProperty(): '%s' already defined.", id);
// return NULL;
Py_RETURN_NONE;
}
if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "BoolVectorProperty(options={...}):"))
return NULL;
if(pysubtype && RNA_enum_value_from_id(property_subtype_array_items, pysubtype, &subtype)==0) {
PyErr_Format(PyExc_TypeError, "BoolVectorProperty(subtype='%s'): invalid subtype.");
PyErr_Format(PyExc_TypeError, "BoolVectorProperty(subtype='%s'): invalid subtype.", pysubtype);
return NULL;
}
@@ -235,7 +256,7 @@ PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
StructRNA *srna;
if (PyTuple_GET_SIZE(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this.
PyErr_SetString(PyExc_ValueError, "all args must be keywords");
return NULL;
}
@@ -256,11 +277,17 @@ PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssiiiiiiO!s:IntProperty", (char **)kwlist, &id, &name, &description, &def, &min, &max, &soft_min, &soft_max, &step, &PySet_Type, &pyopts, &pysubtype))
return NULL;
if(bpy_struct_id_used(srna, id)) {
// PyErr_Format(PyExc_TypeError, "IntProperty(): '%s' already defined.", id);
// return NULL;
Py_RETURN_NONE;
}
if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "IntProperty(options={...}):"))
return NULL;
if(pysubtype && RNA_enum_value_from_id(property_subtype_number_items, pysubtype, &subtype)==0) {
PyErr_Format(PyExc_TypeError, "IntProperty(subtype='%s'): invalid subtype.");
PyErr_Format(PyExc_TypeError, "IntProperty(subtype='%s'): invalid subtype.", pysubtype);
return NULL;
}
@@ -296,7 +323,7 @@ PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
StructRNA *srna;
if (PyTuple_GET_SIZE(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this.
PyErr_SetString(PyExc_ValueError, "all args must be keywords");
return NULL;
}
@@ -319,11 +346,17 @@ PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssOiiiiO!si:IntVectorProperty", (char **)kwlist, &id, &name, &description, &pydef, &min, &max, &soft_min, &soft_max, &PySet_Type, &pyopts, &pysubtype, &size))
return NULL;
if(bpy_struct_id_used(srna, id)) {
// PyErr_Format(PyExc_TypeError, "IntVectorProperty(): '%s' already defined.", id);
// return NULL;
Py_RETURN_NONE;
}
if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "IntVectorProperty(options={...}):"))
return NULL;
if(pysubtype && RNA_enum_value_from_id(property_subtype_array_items, pysubtype, &subtype)==0) {
PyErr_Format(PyExc_TypeError, "IntVectorProperty(subtype='%s'): invalid subtype.");
PyErr_Format(PyExc_TypeError, "IntVectorProperty(subtype='%s'): invalid subtype.", pysubtype);
return NULL;
}
@@ -371,7 +404,7 @@ PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
StructRNA *srna;
if (PyTuple_GET_SIZE(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this.
PyErr_SetString(PyExc_ValueError, "all args must be keywords");
return NULL;
}
@@ -395,11 +428,17 @@ PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssffffffiO!ss:FloatProperty", (char **)kwlist, &id, &name, &description, &def, &min, &max, &soft_min, &soft_max, &step, &precision, &PySet_Type, &pyopts, &pysubtype, &pyunit))
return NULL;
if(bpy_struct_id_used(srna, id)) {
// PyErr_Format(PyExc_TypeError, "FloatProperty(): '%s' already defined.", id);
// return NULL;
Py_RETURN_NONE;
}
if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "FloatProperty(options={...}):"))
return NULL;
if(pysubtype && RNA_enum_value_from_id(property_subtype_number_items, pysubtype, &subtype)==0) {
PyErr_Format(PyExc_TypeError, "FloatProperty(subtype='%s'): invalid subtype.");
PyErr_Format(PyExc_TypeError, "FloatProperty(subtype='%s'): invalid subtype.", pysubtype);
return NULL;
}
@@ -440,7 +479,7 @@ PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
StructRNA *srna;
if (PyTuple_GET_SIZE(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this.
PyErr_SetString(PyExc_ValueError, "all args must be keywords");
return NULL;
}
@@ -463,11 +502,17 @@ PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssOfffffiO!si:FloatVectorProperty", (char **)kwlist, &id, &name, &description, &pydef, &min, &max, &soft_min, &soft_max, &step, &precision, &PySet_Type, &pyopts, &pysubtype, &size))
return NULL;
if(bpy_struct_id_used(srna, id)) {
// PyErr_Format(PyExc_TypeError, "FloatVectorProperty(): '%s' already defined.", id);
// return NULL;
Py_RETURN_NONE;
}
if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "FloatVectorProperty(options={...}):"))
return NULL;
if(pysubtype && RNA_enum_value_from_id(property_subtype_array_items, pysubtype, &subtype)==0) {
PyErr_Format(PyExc_TypeError, "FloatVectorProperty(subtype='%s'): invalid subtype.");
PyErr_Format(PyExc_TypeError, "FloatVectorProperty(subtype='%s'): invalid subtype.", pysubtype);
return NULL;
}
@@ -512,7 +557,7 @@ PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
StructRNA *srna;
if (PyTuple_GET_SIZE(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this.
PyErr_SetString(PyExc_ValueError, "all args must be keywords");
return NULL;
}
@@ -533,11 +578,17 @@ PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|sssiO!s:StringProperty", (char **)kwlist, &id, &name, &description, &def, &maxlen, &PySet_Type, &pyopts, &pysubtype))
return NULL;
if(bpy_struct_id_used(srna, id)) {
// PyErr_Format(PyExc_TypeError, "StringProperty(): '%s' already defined.", id);
// return NULL;
Py_RETURN_NONE;
}
if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "StringProperty(options={...}):"))
return NULL;
if(pysubtype && RNA_enum_value_from_id(property_subtype_string_items, pysubtype, &subtype)==0) {
PyErr_Format(PyExc_TypeError, "StringProperty(subtype='%s'): invalid subtype.");
PyErr_Format(PyExc_TypeError, "StringProperty(subtype='%s'): invalid subtype.", pysubtype);
return NULL;
}
@@ -618,7 +669,7 @@ PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
StructRNA *srna;
if (PyTuple_GET_SIZE(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this.
PyErr_SetString(PyExc_ValueError, "all args must be keywords");
return NULL;
}
@@ -639,6 +690,12 @@ PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|sssO!:EnumProperty", (char **)kwlist, &id, &items, &name, &description, &def, &PySet_Type, &pyopts))
return NULL;
if(bpy_struct_id_used(srna, id)) {
// PyErr_Format(PyExc_TypeError, "EnumProperty(): '%s' already defined.", id);
// return NULL;
Py_RETURN_NONE;
}
if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "EnumProperty(options={...}):"))
return NULL;
@@ -693,7 +750,7 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
StructRNA *srna;
if (PyTuple_GET_SIZE(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this.
PyErr_SetString(PyExc_ValueError, "all args must be keywords");
return NULL;
}
@@ -713,6 +770,12 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|ssO!:PointerProperty", (char **)kwlist, &id, &type, &name, &description, &PySet_Type, &pyopts))
return NULL;
if(bpy_struct_id_used(srna, id)) {
// PyErr_Format(PyExc_TypeError, "PointerProperty(): '%s' already defined.", id);
// return NULL;
Py_RETURN_NONE;
}
if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "PointerProperty(options={...}):"))
return NULL;
@@ -748,7 +811,7 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
StructRNA *srna;
if (PyTuple_GET_SIZE(args) > 0) {
PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this.
PyErr_SetString(PyExc_ValueError, "all args must be keywords");
return NULL;
}
@@ -768,6 +831,12 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|ssO!:CollectionProperty", (char **)kwlist, &id, &type, &name, &description, &PySet_Type, &pyopts))
return NULL;
if(bpy_struct_id_used(srna, id)) {
// PyErr_Format(PyExc_TypeError, "CollectionProperty(): '%s' already defined.", id);
// return NULL;
Py_RETURN_NONE;
}
if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "CollectionProperty(options={...}):"))
return NULL;

View File

@@ -62,9 +62,15 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyRNA *self, Pointer
static Py_ssize_t pyrna_prop_array_length(BPy_PropertyRNA *self);
static Py_ssize_t pyrna_prop_collection_length( BPy_PropertyRNA *self );
/* bpyrna vector/euler/quat callbacks */
static int mathutils_rna_array_cb_index= -1; /* index for our callbacks */
/* not used yet but may want to use the subtype below */
#define MATHUTILS_CB_SUBTYPE_EUL 0
#define MATHUTILS_CB_SUBTYPE_VEC 1
#define MATHUTILS_CB_SUBTYPE_QUAT 2
static int mathutils_rna_generic_check(BPy_PropertyRNA *self)
{
return self->prop?1:0;
@@ -83,7 +89,7 @@ static int mathutils_rna_vector_set(BPy_PropertyRNA *self, int subtype, float *v
{
if(self->prop==NULL)
return 0;
/* TODO, clamp */
RNA_property_float_set_array(&self->ptr, self->prop, vec_to);
RNA_property_update(BPy_GetContext(), &self->ptr, self->prop);
return 1;
@@ -103,6 +109,7 @@ static int mathutils_rna_vector_set_index(BPy_PropertyRNA *self, int subtype, fl
if(self->prop==NULL)
return 0;
RNA_property_float_clamp(&self->ptr, self->prop, &vec_to[index]);
RNA_property_float_set_index(&self->ptr, self->prop, index, vec_to[index]);
RNA_property_update(BPy_GetContext(), &self->ptr, self->prop);
return 1;
@@ -133,7 +140,7 @@ static int mathutils_rna_matrix_set(BPy_PropertyRNA *self, int subtype, float *m
{
if(self->prop==NULL)
return 0;
/* can ignore clamping here */
RNA_property_float_set_array(&self->ptr, self->prop, mat_to);
RNA_property_update(BPy_GetContext(), &self->ptr, self->prop);
return 1;
@@ -181,7 +188,7 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop)
RNA_property_float_get_array(ptr, prop, ((VectorObject *)ret)->vec);
}
else {
PyObject *vec_cb= newVectorObject_cb(ret, len, mathutils_rna_array_cb_index, FALSE);
PyObject *vec_cb= newVectorObject_cb(ret, len, mathutils_rna_array_cb_index, MATHUTILS_CB_SUBTYPE_VEC);
Py_DECREF(ret); /* the vector owns now */
ret= vec_cb; /* return the vector instead */
}
@@ -215,11 +222,11 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop)
case PROP_QUATERNION:
if(len==3) { /* euler */
if(is_thick) {
ret= newEulerObject(NULL, Py_NEW, NULL);
ret= newEulerObject(NULL, 0, Py_NEW, NULL); // TODO, get order from RNA
RNA_property_float_get_array(ptr, prop, ((EulerObject *)ret)->eul);
}
else {
PyObject *eul_cb= newEulerObject_cb(ret, mathutils_rna_array_cb_index, FALSE);
PyObject *eul_cb= newEulerObject_cb(ret, 0, mathutils_rna_array_cb_index, MATHUTILS_CB_SUBTYPE_EUL); // TODO, get order from RNA
Py_DECREF(ret); /* the matrix owns now */
ret= eul_cb; /* return the matrix instead */
}
@@ -230,7 +237,7 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop)
RNA_property_float_get_array(ptr, prop, ((QuaternionObject *)ret)->quat);
}
else {
PyObject *quat_cb= newQuaternionObject_cb(ret, mathutils_rna_array_cb_index, FALSE);
PyObject *quat_cb= newQuaternionObject_cb(ret, mathutils_rna_array_cb_index, MATHUTILS_CB_SUBTYPE_QUAT);
Py_DECREF(ret); /* the matrix owns now */
ret= quat_cb; /* return the matrix instead */
}
@@ -799,6 +806,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
PyErr_Format(PyExc_TypeError, "%.200s expected an int type", error_prefix);
return -1;
} else {
RNA_property_int_clamp(ptr, prop, &param);
if(data) *((int*)data)= param;
else RNA_property_int_set(ptr, prop, param);
}
@@ -811,6 +819,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
PyErr_Format(PyExc_TypeError, "%.200s expected a float type", error_prefix);
return -1;
} else {
RNA_property_float_clamp(ptr, prop, (float *)&param);
if(data) *((float*)data)= param;
else RNA_property_float_set(ptr, prop, param);
}
@@ -1024,6 +1033,7 @@ static int pyrna_py_to_prop_index(BPy_PropertyRNA *self, int index, PyObject *va
PyErr_SetString(PyExc_TypeError, "expected an int type");
ret = -1;
} else {
RNA_property_int_clamp(ptr, prop, &param);
RNA_property_int_set_index(ptr, prop, index, param);
}
break;
@@ -1035,6 +1045,7 @@ static int pyrna_py_to_prop_index(BPy_PropertyRNA *self, int index, PyObject *va
PyErr_SetString(PyExc_TypeError, "expected a float type");
ret = -1;
} else {
RNA_property_float_clamp(ptr, prop, &param);
RNA_property_float_set_index(ptr, prop, index, param);
}
break;
@@ -1298,14 +1309,21 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop, in
case PROP_FLOAT:
{
float values_stack[PYRNA_STACK_ARRAY];
float *values;
float *values, fval;
float min, max;
RNA_property_float_range(ptr, prop, &min, &max);
if(length > PYRNA_STACK_ARRAY) { values= values_alloc= PyMem_MALLOC(sizeof(float) * length); }
else { values= values_stack; }
if(start != 0 || stop != length) /* partial assignment? - need to get the array */
RNA_property_float_get_array(ptr, prop, values);
for(count=start; count<stop; count++)
values[count] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, count-start));
for(count=start; count<stop; count++) {
fval = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, count-start));
CLAMP(fval, min, max);
values[count] = fval;
}
if(PyErr_Occurred()) ret= -1;
else RNA_property_float_set_array(ptr, prop, values);
@@ -1331,15 +1349,22 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop, in
case PROP_INT:
{
int values_stack[PYRNA_STACK_ARRAY];
int *values;
int *values, ival;
int min, max;
RNA_property_int_range(ptr, prop, &min, &max);
if(length > PYRNA_STACK_ARRAY) { values= values_alloc= PyMem_MALLOC(sizeof(int) * length); }
else { values= values_stack; }
if(start != 0 || stop != length) /* partial assignment? - need to get the array */
RNA_property_int_get_array(ptr, prop, values);
for(count=start; count<stop; count++)
values[count] = PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value, count-start));
for(count=start; count<stop; count++) {
ival = PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value, count-start));
CLAMP(ival, min, max);
values[count] = ival;
}
if(PyErr_Occurred()) ret= -1;
else RNA_property_int_set_array(ptr, prop, values);