Esempio n. 1
0
PyObject *pyrna_py_from_array(PointerRNA *ptr, PropertyRNA *prop)
{
	PyObject *ret;

	ret = pyrna_math_object_from_array(ptr, prop);

	/* is this a maths object? */
	if (ret) return ret;

	return pyrna_prop_CreatePyObject(ptr, prop);
}
PyObject *pyrna_py_from_array_index(BPy_PropertyArrayRNA *self, PointerRNA *ptr, PropertyRNA *prop, int index)
{
	int totdim, arraydim, arrayoffset, dimsize[MAX_ARRAY_DIMENSION], i, len;
	BPy_PropertyArrayRNA *ret = NULL;

	arraydim = self ? self->arraydim : 0;
	arrayoffset = self ? self->arrayoffset : 0;

	/* just in case check */
	len = RNA_property_multi_array_length(ptr, prop, arraydim);
	if (index >= len || index < 0) {
		/* this shouldn't happen because higher level funcs must check for invalid index */
		if (G.debug & G_DEBUG_PYTHON)
			printf("%s: invalid index %d for array with length=%d\n", __func__, index, len);

		PyErr_SetString(PyExc_IndexError, "out of range");
		return NULL;
	}

	totdim = RNA_property_array_dimension(ptr, prop, dimsize);

	if (arraydim + 1 < totdim) {
		ret = (BPy_PropertyArrayRNA *)pyrna_prop_CreatePyObject(ptr, prop);
		ret->arraydim = arraydim + 1;

		/* arr[3][4][5]
		 *
		 *    x = arr[2]
		 *    index = 0 + 2 * 4 * 5
		 * 
		 *    x = arr[2][3]
		 *    index = offset + 3 * 5 */

		for (i = arraydim + 1; i < totdim; i++)
			index *= dimsize[i];

		ret->arrayoffset = arrayoffset + index;
	}
	else {
		index = arrayoffset + index;
		ret = (BPy_PropertyArrayRNA *)pyrna_array_index(ptr, prop, index);
	}

	return (PyObject *)ret;
}