25 #include "../generic/py_capi_utils.h"
30 # include "../mathutils/mathutils.h"
33 #define MAX_ARRAY_DIMENSION 10
81 const bool is_dynamic,
83 const char *item_type_str,
84 const char *error_prefix)
89 if (dim + 1 < totdim) {
91 const int seq_size = PySequence_Size(seq);
93 PyErr_Format(PyExc_ValueError,
94 "%s sequence expected at dimension %d, not '%s'",
97 Py_TYPE(seq)->tp_name);
100 for (i = 0; i < seq_size; i++) {
101 Py_ssize_t item_seq_size;
104 item = PySequence_GetItem(seq, i);
107 PyErr_Format(PyExc_TypeError,
108 "%s sequence type '%s' failed to retrieve index %d",
110 Py_TYPE(seq)->tp_name,
114 else if ((item_seq_size = PySequence_Size(item)) == -1) {
116 PyErr_Format(PyExc_TypeError,
117 "%s expected a sequence of %s, not %s",
120 Py_TYPE(item)->tp_name);
128 else if (item_seq_size != dimsize[dim + 1]) {
132 PyErr_Format(PyExc_ValueError,
133 "%s sequences of dimension %d should contain %d items, not %d",
147 error_prefix) == -1) {
160 const int seq_size = PySequence_Size(seq);
161 if (seq_size == -1) {
162 PyErr_Format(PyExc_ValueError,
163 "%s sequence expected at dimension %d, not '%s'",
166 Py_TYPE(seq)->tp_name);
169 if ((seq_size != dimsize[dim]) && (is_dynamic ==
false)) {
170 PyErr_Format(PyExc_ValueError,
171 "%s sequences of dimension %d should contain %d items, not %d",
179 for (i = 0; i < seq_size; i++) {
180 PyObject *item = PySequence_GetItem(seq, i);
183 PyErr_Format(PyExc_TypeError,
184 "%s sequence type '%s' failed to retrieve index %d",
186 Py_TYPE(seq)->tp_name,
190 if (!check_item_type(item)) {
195 error_str, error_str_size,
"sequence items should be of type %s", item_type_str);
197 PyErr_Format(PyExc_TypeError,
198 "%s expected sequence items of type %s, not %s",
201 Py_TYPE(item)->tp_name);
218 const Py_ssize_t seq_size = PySequence_Size(seq);
220 for (i = 0; i < seq_size; i++) {
221 PyObject *item = PySequence_GetItem(seq, i);
240 totitem = PySequence_Size(seq);
252 const char *error_prefix)
255 int tot, totdim,
len;
261 PyErr_Format(PyExc_ValueError,
262 "%s %.200s.%.200s, error validating the sequence length",
272 if (!RNA_property_dynamic_array_set_length(
ptr, prop, tot)) {
276 PyErr_Format(PyExc_ValueError,
277 "%s %s.%s: array length cannot be changed to %d",
317 for (i = lvalue_dim; i < totdim; i++) {
324 PyErr_Format(PyExc_ValueError,
325 "%s %.200s.%.200s, sequence must have %d items total, not %d",
345 const char *item_type_str,
347 const char *error_prefix)
355 if (lvalue_dim == 0) {
364 PyErr_Format(PyExc_ValueError,
365 "%s %.200s.%.200s, matrix assign to non float array",
372 PyErr_Format(PyExc_ValueError,
373 "%s %.200s.%.200s, matrix assign array with %d dimensions",
380 if (pymat->
col_num != dimsize[0] || pymat->
row_num != dimsize[1]) {
381 PyErr_Format(PyExc_ValueError,
382 "%s %.200s.%.200s, matrix assign dimension size mismatch, "
383 "is %dx%d, expected be %dx%d",
394 *r_totitem = dimsize[0] * dimsize[1];
409 error_prefix) == -1) {
431 char *value = (
void *)&value_buf;
433 convert_item->
func(&convert_item->
arg, item, value);
434 rna_set_index(
ptr, prop, *index, value);
438 convert_item->
func(&convert_item->
arg, item,
data);
456 const Py_ssize_t seq_size = PySequence_Size(seq);
468 if (seq_size == -1) {
480 memcpy(
data, pymat->matrix, allocsize);
490 for (i = 0; i < seq_size; i++) {
491 PyObject *item = PySequence_GetItem(seq, i);
493 if (dim + 1 < totdim) {
495 item,
ptr, prop, dim + 1,
data, item_size, index, convert_item, rna_set_index);
499 item,
ptr, prop,
data, item_size, index, convert_item, rna_set_index);
519 const char *item_type_str,
523 const char *error_prefix)
531 if (
validate_array(seq,
ptr, prop, 0, check_item_type, item_type_str, &totitem, error_prefix) ==
548 else if (param_data) {
552 data = PyMem_MALLOC(item_size * totitem);
558 if (param_data ==
NULL) {
560 rna_set_array(
ptr, prop,
data);
565 if (param_data ==
NULL) {
569 PyErr_Format(PyExc_TypeError,
570 "%s internal error parsing sequence of type '%s' after successful validation",
572 Py_TYPE(seq)->tp_name);
587 const char *item_type_str,
590 const char *error_prefix)
609 for (i = lvalue_dim; i < totdim; i++) {
613 index += arrayoffset;
615 if (lvalue_dim == totdim) {
616 if (!check_item_type(py)) {
617 PyErr_Format(PyExc_TypeError,
618 "%s %.200s.%.200s, expected a %s type, not %s",
623 Py_TYPE(py)->tp_name);
630 py,
ptr, prop, lvalue_dim, check_item_type, item_type_str, &totitem, error_prefix) ==
645 float value = (
float)PyFloat_AsDouble(py);
646 CLAMP(value, range[0], range[1]);
647 *(
float *)
data = value;
652 const int *range = arg->
int_data.range;
653 int value = PyC_Long_AsI32(py);
654 CLAMP(value, range[0], range[1]);
655 *(
int *)
data = value;
660 *(
bool *)
data = (
bool)PyObject_IsTrue(py);
666 return PyNumber_Check(py);
672 return PyLong_Check(py);
677 return PyBool_Check(py);
774 PyErr_SetString(PyExc_TypeError,
"not an array type");
789 const char *error_prefix)
845 PyErr_SetString(PyExc_TypeError,
"not an array type");
869 PyErr_SetString(PyExc_TypeError,
"not an array type");
880 static PyObject *pyrna_py_from_array_internal(
PointerRNA *
ptr,
891 tuple = PyTuple_New(
len);
893 for (i = 0; i <
len; i++) {
896 if (dim + 1 < totdim) {
897 item = pyrna_py_from_array_internal(
ptr, prop, dim + 1, index);
909 PyTuple_SET_ITEM(tuple, i, item);
924 arraydim =
self ?
self->arraydim : 0;
925 arrayoffset =
self ?
self->arrayoffset : 0;
929 if (index >=
len || index < 0) {
933 PyErr_SetString(PyExc_IndexError,
"out of range");
939 if (arraydim + 1 < totdim) {
941 ret->arraydim = arraydim + 1;
951 for (i = arraydim + 1; i < totdim; i++) {
955 ret->arrayoffset = arrayoffset + index;
958 index = arrayoffset + index;
962 return (PyObject *)
ret;
993 PyErr_SetString(PyExc_TypeError,
"PropertyRNA - multi dimensional arrays not supported yet");
1001 const float value_f = PyFloat_AsDouble(value);
1002 if (value_f == -1 && PyErr_Occurred()) {
1010 if (
len *
sizeof(
float) >
sizeof(tmp)) {
1011 tmp_arr = PyMem_MALLOC(
len *
sizeof(
float));
1019 for (i = 0; i <
len; i++) {
1020 if (tmp_arr[i] == value_f) {
1025 if (tmp_arr != tmp) {
1026 PyMem_FREE(tmp_arr);
1029 return i <
len ? 1 : 0;
1034 const int value_i = PyC_Long_AsI32(value);
1035 if (value_i == -1 && PyErr_Occurred()) {
1043 if (
len *
sizeof(
int) >
sizeof(tmp)) {
1044 tmp_arr = PyMem_MALLOC(
len *
sizeof(
int));
1052 for (i = 0; i <
len; i++) {
1053 if (tmp_arr[i] == value_i) {
1058 if (tmp_arr != tmp) {
1059 PyMem_FREE(tmp_arr);
1062 return i <
len ? 1 : 0;
1068 if (value_i == -1 && PyErr_Occurred()) {
1076 if (
len *
sizeof(
bool) >
sizeof(tmp)) {
1077 tmp_arr = PyMem_MALLOC(
len *
sizeof(
bool));
1085 for (i = 0; i <
len; i++) {
1086 if (tmp_arr[i] == value_i) {
1091 if (tmp_arr != tmp) {
1092 PyMem_FREE(tmp_arr);
1095 return i <
len ? 1 : 0;
1102 PyErr_SetString(PyExc_TypeError,
"PropertyRNA - type not in float/bool/int");
typedef float(TangentPoint)[2]
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
struct CLG_LogRef * BPY_LOG_RNA
#define CLOG_WARN(clg_ref,...)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
PyObject * pyrna_prop_CreatePyObject(PointerRNA *ptr, PropertyRNA *prop)
PyObject * pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop)
int pyrna_py_to_array(PointerRNA *ptr, PropertyRNA *prop, char *param_data, PyObject *py, const char *error_prefix)
static void py_to_int(const struct ItemConvertArgData *arg, PyObject *py, char *data)
static void int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, void *value)
#define MAX_ARRAY_DIMENSION
static int validate_array_length(PyObject *rvalue, PointerRNA *ptr, PropertyRNA *prop, int lvalue_dim, int *r_totitem, const char *error_prefix)
static void convert_item_init_int(PointerRNA *ptr, PropertyRNA *prop, ItemConvert_FuncArg *convert_item)
static int validate_array_type(PyObject *seq, int dim, int totdim, int dimsize[], const bool is_dynamic, ItemTypeCheckFunc check_item_type, const char *item_type_str, const char *error_prefix)
static int py_float_check(PyObject *py)
static void convert_item_init_bool(PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), ItemConvert_FuncArg *convert_item)
static int py_int_check(PyObject *py)
int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
static void bool_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, void *value)
void(* ItemConvertFunc)(const struct ItemConvertArgData *arg, PyObject *, char *)
int pyrna_py_to_array_index(PointerRNA *ptr, PropertyRNA *prop, int arraydim, int arrayoffset, int index, PyObject *py, const char *error_prefix)
static int validate_array(PyObject *rvalue, PointerRNA *ptr, PropertyRNA *prop, int lvalue_dim, ItemTypeCheckFunc check_item_type, const char *item_type_str, int *r_totitem, const char *error_prefix)
PyObject * pyrna_array_index(PointerRNA *ptr, PropertyRNA *prop, int index)
static char * copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, int dim, char *data, uint item_size, int *index, const ItemConvert_FuncArg *convert_item, RNA_SetIndexFunc rna_set_index)
static void float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, void *value)
static int count_items(PyObject *seq, int dim)
static void py_to_float(const struct ItemConvertArgData *arg, PyObject *py, char *data)
static void convert_item_init_float(PointerRNA *ptr, PropertyRNA *prop, ItemConvert_FuncArg *convert_item)
void(* RNA_SetIndexFunc)(PointerRNA *, PropertyRNA *, int index, void *)
PyObject * pyrna_py_from_array(PointerRNA *ptr, PropertyRNA *prop)
static void py_to_bool(const struct ItemConvertArgData *UNUSED(arg), PyObject *py, char *data)
struct ItemConvert_FuncArg ItemConvert_FuncArg
PyObject * pyrna_py_from_array_index(BPy_PropertyArrayRNA *self, PointerRNA *ptr, PropertyRNA *prop, int index)
static int py_to_array(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop, char *param_data, ItemTypeCheckFunc check_item_type, const char *item_type_str, int item_size, const ItemConvert_FuncArg *convert_item, RNA_SetArrayFunc rna_set_array, const char *error_prefix)
static char * copy_value_single(PyObject *item, PointerRNA *ptr, PropertyRNA *prop, char *data, uint item_size, int *index, const ItemConvert_FuncArg *convert_item, RNA_SetIndexFunc rna_set_index)
static int py_to_array_index(PyObject *py, PointerRNA *ptr, PropertyRNA *prop, int lvalue_dim, int arrayoffset, int index, ItemTypeCheckFunc check_item_type, const char *item_type_str, const ItemConvert_FuncArg *convert_item, RNA_SetIndexFunc rna_set_index, const char *error_prefix)
void(* RNA_SetArrayFunc)(PointerRNA *, PropertyRNA *, const char *)
int(* ItemTypeCheckFunc)(PyObject *)
static int py_bool_check(PyObject *py)
SyclQueue void void size_t num_bytes void
void *(* MEM_callocN)(size_t len, const char *str)
#define BaseMath_ReadCallback(_self)
#define MatrixObject_Check(v)
int PyC_Long_AsBool(PyObject *value)
const char * RNA_struct_identifier(const StructRNA *type)
void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, bool value)
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
const char * RNA_property_identifier(const PropertyRNA *prop)
void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value)
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax)
void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, bool *values)
PropertyType RNA_property_type(PropertyRNA *prop)
void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
int RNA_property_array_dimension(const PointerRNA *ptr, PropertyRNA *prop, int length[])
int RNA_property_flag(PropertyRNA *prop)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, int *hardmax)
bool RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
int RNA_property_multi_array_length(PointerRNA *ptr, PropertyRNA *prop, int dim)
void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const bool *values)
struct ItemConvertArgData::@1164::@1166 int_data
struct ItemConvertArgData::@1164::@1167 float_data
struct ItemConvertArgData arg