Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * Contributor(s): Arystanbek Dyussenov 00019 * 00020 * ***** END GPL LICENSE BLOCK ***** 00021 */ 00022 00028 /* Defines a structure with properties used for array manipulation tests in BPY. */ 00029 00030 #include <stdlib.h> 00031 #include <string.h> 00032 00033 #include "RNA_define.h" 00034 00035 #include "rna_internal.h" 00036 00037 #define ARRAY_SIZE 3 00038 #define DYNAMIC_ARRAY_SIZE 64 00039 #define MARRAY_DIM [3][4][5] 00040 #define MARRAY_TOTDIM 3 00041 #define MARRAY_DIMSIZE 4, 5 00042 #define MARRAY_SIZE(type) (sizeof(type MARRAY_DIM) / sizeof(type)) 00043 #define DYNAMIC_MARRAY_DIM [3][4][5] 00044 #define DYNAMIC_MARRAY_SIZE(type) (sizeof(type DYNAMIC_MARRAY_DIM) / sizeof(type)) 00045 00046 #ifdef RNA_RUNTIME 00047 00048 #ifdef UNIT_TEST 00049 00050 #define DEF_VARS(type, prefix) \ 00051 static type prefix ## arr[ARRAY_SIZE]; \ 00052 static type prefix ## darr[DYNAMIC_ARRAY_SIZE]; \ 00053 static int prefix ## darr_len= ARRAY_SIZE; \ 00054 static type prefix ## marr MARRAY_DIM; \ 00055 static type prefix ## dmarr DYNAMIC_MARRAY_DIM; \ 00056 static int prefix ## dmarr_len= sizeof(prefix ## dmarr); 00057 00058 #define DEF_GET_SET(type, arr) \ 00059 void rna_Test_ ## arr ## _get(PointerRNA *ptr, type *values) \ 00060 { \ 00061 memcpy(values, arr, sizeof(arr)); \ 00062 } \ 00063 \ 00064 void rna_Test_ ## arr ## _set(PointerRNA *ptr, const type *values) \ 00065 { \ 00066 memcpy(arr, values, sizeof(arr)); \ 00067 } 00068 00069 #define DEF_GET_SET_LEN(arr, max) \ 00070 static int rna_Test_ ## arr ## _get_length(PointerRNA *ptr) \ 00071 { \ 00072 return arr ## _len; \ 00073 } \ 00074 \ 00075 static int rna_Test_ ## arr ## _set_length(PointerRNA *ptr, int length) \ 00076 { \ 00077 if (length > max) \ 00078 return 0; \ 00079 \ 00080 arr ## _len= length; \ 00081 \ 00082 return 1; \ 00083 } \ 00084 00085 DEF_VARS(float, f) 00086 DEF_VARS(int, i) 00087 DEF_VARS(int, b) 00088 00089 DEF_GET_SET(float, farr) 00090 DEF_GET_SET(int, iarr) 00091 DEF_GET_SET(int, barr) 00092 00093 DEF_GET_SET(float, fmarr) 00094 DEF_GET_SET(int, imarr) 00095 DEF_GET_SET(int, bmarr) 00096 00097 DEF_GET_SET(float, fdarr) 00098 DEF_GET_SET_LEN(fdarr, DYNAMIC_ARRAY_SIZE) 00099 DEF_GET_SET(int, idarr) 00100 DEF_GET_SET_LEN(idarr, DYNAMIC_ARRAY_SIZE) 00101 DEF_GET_SET(int, bdarr) 00102 DEF_GET_SET_LEN(bdarr, DYNAMIC_ARRAY_SIZE) 00103 00104 DEF_GET_SET(float, fdmarr) 00105 DEF_GET_SET_LEN(fdmarr, DYNAMIC_MARRAY_SIZE(float)) 00106 DEF_GET_SET(int, idmarr) 00107 DEF_GET_SET_LEN(idmarr, DYNAMIC_MARRAY_SIZE(int)) 00108 DEF_GET_SET(int, bdmarr) 00109 DEF_GET_SET_LEN(bdmarr, DYNAMIC_MARRAY_SIZE(int)) 00110 00111 #endif 00112 00113 #else 00114 00115 void RNA_def_test(BlenderRNA *brna) 00116 { 00117 #ifdef UNIT_TEST 00118 StructRNA *srna; 00119 PropertyRNA *prop; 00120 unsigned short dimsize[]= {MARRAY_DIMSIZE}; 00121 00122 srna= RNA_def_struct(brna, "Test", NULL); 00123 RNA_def_struct_sdna(srna, "Test"); 00124 00125 prop= RNA_def_float_array(srna, "farr", ARRAY_SIZE, NULL, 0.0f, 0.0f, "farr", "float array", 0.0f, 0.0f); 00126 RNA_def_property_float_funcs(prop, "rna_Test_farr_get", "rna_Test_farr_set", NULL); 00127 00128 prop= RNA_def_int_array(srna, "iarr", ARRAY_SIZE, NULL, 0, 0, "iarr", "int array", 0, 0); 00129 RNA_def_property_int_funcs(prop, "rna_Test_iarr_get", "rna_Test_iarr_set", NULL); 00130 00131 prop= RNA_def_boolean_array(srna, "barr", ARRAY_SIZE, NULL, "barr", "boolean array"); 00132 RNA_def_property_boolean_funcs(prop, "rna_Test_barr_get", "rna_Test_barr_set"); 00133 00134 /* dynamic arrays */ 00135 00136 prop= RNA_def_float_array(srna, "fdarr", DYNAMIC_ARRAY_SIZE, NULL, 0.0f, 0.0f, "fdarr", "dynamic float array", 0.0f, 0.0f); 00137 RNA_def_property_flag(prop, PROP_DYNAMIC); 00138 RNA_def_property_dynamic_array_funcs(prop, "rna_Test_fdarr_get_length", "rna_Test_fdarr_set_length"); 00139 RNA_def_property_float_funcs(prop, "rna_Test_fdarr_get", "rna_Test_fdarr_set", NULL); 00140 00141 prop= RNA_def_int_array(srna, "idarr", DYNAMIC_ARRAY_SIZE, NULL, 0, 0, "idarr", "int array", 0, 0); 00142 RNA_def_property_flag(prop, PROP_DYNAMIC); 00143 RNA_def_property_dynamic_array_funcs(prop, "rna_Test_idarr_get_length", "rna_Test_idarr_set_length"); 00144 RNA_def_property_int_funcs(prop, "rna_Test_idarr_get", "rna_Test_idarr_set", NULL); 00145 00146 prop= RNA_def_boolean_array(srna, "bdarr", DYNAMIC_ARRAY_SIZE, NULL, "bdarr", "boolean array"); 00147 RNA_def_property_flag(prop, PROP_DYNAMIC); 00148 RNA_def_property_dynamic_array_funcs(prop, "rna_Test_bdarr_get_length", "rna_Test_bdarr_set_length"); 00149 RNA_def_property_boolean_funcs(prop, "rna_Test_bdarr_get", "rna_Test_bdarr_set"); 00150 00151 /* multidimensional arrays */ 00152 00153 prop= RNA_def_property(srna, "fmarr", PROP_FLOAT, PROP_NONE); 00154 RNA_def_property_multidimensional_array(prop, MARRAY_SIZE(float), MARRAY_TOTDIM, dimsize); 00155 RNA_def_property_float_funcs(prop, "rna_Test_fmarr_get", "rna_Test_fmarr_set", NULL); 00156 00157 prop= RNA_def_property(srna, "imarr", PROP_INT, PROP_NONE); 00158 RNA_def_property_multidimensional_array(prop, MARRAY_SIZE(int), MARRAY_TOTDIM, dimsize); 00159 RNA_def_property_int_funcs(prop, "rna_Test_imarr_get", "rna_Test_imarr_set", NULL); 00160 00161 prop= RNA_def_property(srna, "bmarr", PROP_BOOLEAN, PROP_NONE); 00162 RNA_def_property_multidimensional_array(prop, MARRAY_SIZE(int), MARRAY_TOTDIM, dimsize); 00163 RNA_def_property_boolean_funcs(prop, "rna_Test_bmarr_get", "rna_Test_bmarr_set"); 00164 00165 /* dynamic multidimensional arrays */ 00166 00167 prop= RNA_def_property(srna, "fdmarr", PROP_FLOAT, PROP_NONE); 00168 RNA_def_property_multidimensional_array(prop, DYNAMIC_MARRAY_SIZE(float), MARRAY_TOTDIM, dimsize); 00169 RNA_def_property_flag(prop, PROP_DYNAMIC); 00170 RNA_def_property_dynamic_array_funcs(prop, "rna_Test_fdmarr_get_length", "rna_Test_fdmarr_set_length"); 00171 RNA_def_property_float_funcs(prop, "rna_Test_fdmarr_get", "rna_Test_fdmarr_set", NULL); 00172 00173 prop= RNA_def_property(srna, "idmarr", PROP_INT, PROP_NONE); 00174 RNA_def_property_multidimensional_array(prop, DYNAMIC_MARRAY_SIZE(int), MARRAY_TOTDIM, dimsize); 00175 RNA_def_property_flag(prop, PROP_DYNAMIC); 00176 RNA_def_property_dynamic_array_funcs(prop, "rna_Test_idmarr_get_length", "rna_Test_idmarr_set_length"); 00177 RNA_def_property_int_funcs(prop, "rna_Test_idmarr_get", "rna_Test_idmarr_set", NULL); 00178 00179 prop= RNA_def_property(srna, "bdmarr", PROP_BOOLEAN, PROP_NONE); 00180 RNA_def_property_multidimensional_array(prop, DYNAMIC_MARRAY_SIZE(int), MARRAY_TOTDIM, dimsize); 00181 RNA_def_property_flag(prop, PROP_DYNAMIC); 00182 RNA_def_property_dynamic_array_funcs(prop, "rna_Test_bdmarr_get_length", "rna_Test_bdmarr_set_length"); 00183 RNA_def_property_boolean_funcs(prop, "rna_Test_bdmarr_get", "rna_Test_bdmarr_set"); 00184 00185 #endif 00186 } 00187 00188 #endif /* RNA_RUNTIME */ 00189 00190