2.5: UV Edit
[blender.git] / source / blender / makesrna / intern / rna_test.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * Contributor(s): Arystanbek Dyussenov
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 /* Defines a structure with properties used for array manipulation tests in BPY. */
26
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include "RNA_define.h"
31 #include "RNA_types.h"
32
33 #include "rna_internal.h"
34
35 #define ARRAY_SIZE 3
36 #define DYNAMIC_ARRAY_SIZE 64
37 #define MARRAY_DIM [3][4][5]
38 #define MARRAY_TOTDIM 3
39 #define MARRAY_DIMSIZE 4, 5
40 #define MARRAY_SIZE(type) (sizeof(type MARRAY_DIM) / sizeof(type))
41 #define DYNAMIC_MARRAY_DIM [3][4][5]
42 #define DYNAMIC_MARRAY_SIZE(type) (sizeof(type DYNAMIC_MARRAY_DIM) / sizeof(type))
43
44 #ifdef RNA_RUNTIME
45
46 #ifdef UNIT_TEST
47
48 #define DEF_VARS(type, prefix)                                                          \
49         static type prefix ## arr[ARRAY_SIZE];                                  \
50         static type prefix ## darr[DYNAMIC_ARRAY_SIZE];                 \
51         static int prefix ## darr_len= ARRAY_SIZE;                              \
52         static type prefix ## marr MARRAY_DIM;                                  \
53         static type prefix ## dmarr DYNAMIC_MARRAY_DIM;                 \
54         static int prefix ## dmarr_len= sizeof(prefix ## dmarr);
55
56 #define DEF_GET_SET(type, arr)                                                                                  \
57         void rna_Test_ ## arr ## _get(PointerRNA *ptr, type *values)            \
58         {                                                                                                                                       \
59                 memcpy(values, arr, sizeof(arr));                                                               \
60         }                                                                                                                                       \
61                                                                                                                                                 \
62         void rna_Test_ ## arr ## _set(PointerRNA *ptr, const type *values)      \
63         {                                                                                                                                       \
64                 memcpy(arr, values, sizeof(arr));                                                               \
65         }
66
67 #define DEF_GET_SET_LEN(arr, max)                                                                               \
68         static int rna_Test_ ## arr ## _get_length(PointerRNA *ptr)                     \
69         {                                                                                                                                       \
70                 return arr ## _len;                                                                                             \
71         }                                                                                                                                       \
72                                                                                                                                                 \
73         static int rna_Test_ ## arr ## _set_length(PointerRNA *ptr, int length) \
74         {                                                                                                                                       \
75                 if (length > max)                                                                                               \
76                         return 0;                                                                                                       \
77                                                                                                                                                 \
78                 arr ## _len= length;                                                                                    \
79                                                                                                                                                 \
80                 return 1;                                                                                                               \
81         }                                                                                                                                       \
82
83 DEF_VARS(float, f)
84 DEF_VARS(int, i)
85 DEF_VARS(int, b)
86
87 DEF_GET_SET(float, farr)
88 DEF_GET_SET(int, iarr)
89 DEF_GET_SET(int, barr)
90
91 DEF_GET_SET(float, fmarr)
92 DEF_GET_SET(int, imarr)
93 DEF_GET_SET(int, bmarr)
94
95 DEF_GET_SET(float, fdarr)
96 DEF_GET_SET_LEN(fdarr, DYNAMIC_ARRAY_SIZE)
97 DEF_GET_SET(int, idarr)
98 DEF_GET_SET_LEN(idarr, DYNAMIC_ARRAY_SIZE)
99 DEF_GET_SET(int, bdarr)
100 DEF_GET_SET_LEN(bdarr, DYNAMIC_ARRAY_SIZE)
101
102 DEF_GET_SET(float, fdmarr)
103 DEF_GET_SET_LEN(fdmarr, DYNAMIC_MARRAY_SIZE(float))
104 DEF_GET_SET(int, idmarr)
105 DEF_GET_SET_LEN(idmarr, DYNAMIC_MARRAY_SIZE(int))
106 DEF_GET_SET(int, bdmarr)
107 DEF_GET_SET_LEN(bdmarr, DYNAMIC_MARRAY_SIZE(int))
108
109 #endif
110
111 #else
112
113 void RNA_def_test(BlenderRNA *brna)
114 {
115 #ifdef UNIT_TEST
116         StructRNA *srna;
117         PropertyRNA *prop;
118         unsigned short dimsize[]= {MARRAY_DIMSIZE};
119
120         srna= RNA_def_struct(brna, "Test", NULL);
121         RNA_def_struct_sdna(srna, "Test");
122
123         prop= RNA_def_float_array(srna, "farr", ARRAY_SIZE, NULL, 0.0f, 0.0f, "farr", "float array", 0.0f, 0.0f);
124         RNA_def_property_float_funcs(prop, "rna_Test_farr_get", "rna_Test_farr_set", NULL);
125
126         prop= RNA_def_int_array(srna, "iarr", ARRAY_SIZE, NULL, 0, 0, "iarr", "int array", 0, 0);
127         RNA_def_property_int_funcs(prop, "rna_Test_iarr_get", "rna_Test_iarr_set", NULL);
128
129         prop= RNA_def_boolean_array(srna, "barr", ARRAY_SIZE, NULL, "barr", "boolean array");
130         RNA_def_property_boolean_funcs(prop, "rna_Test_barr_get", "rna_Test_barr_set");
131
132         /* dynamic arrays */
133
134         prop= RNA_def_float_array(srna, "fdarr", DYNAMIC_ARRAY_SIZE, NULL, 0.0f, 0.0f, "fdarr", "dynamic float array", 0.0f, 0.0f);
135         RNA_def_property_flag(prop, PROP_DYNAMIC);
136         RNA_def_property_dynamic_array_funcs(prop, "rna_Test_fdarr_get_length", "rna_Test_fdarr_set_length");
137         RNA_def_property_float_funcs(prop, "rna_Test_fdarr_get", "rna_Test_fdarr_set", NULL);
138
139         prop= RNA_def_int_array(srna, "idarr", DYNAMIC_ARRAY_SIZE, NULL, 0, 0, "idarr", "int array", 0, 0);
140         RNA_def_property_flag(prop, PROP_DYNAMIC);
141         RNA_def_property_dynamic_array_funcs(prop, "rna_Test_idarr_get_length", "rna_Test_idarr_set_length");
142         RNA_def_property_int_funcs(prop, "rna_Test_idarr_get", "rna_Test_idarr_set", NULL);
143         
144         prop= RNA_def_boolean_array(srna, "bdarr", DYNAMIC_ARRAY_SIZE, NULL, "bdarr", "boolean array");
145         RNA_def_property_flag(prop, PROP_DYNAMIC);
146         RNA_def_property_dynamic_array_funcs(prop, "rna_Test_bdarr_get_length", "rna_Test_bdarr_set_length");
147         RNA_def_property_boolean_funcs(prop, "rna_Test_bdarr_get", "rna_Test_bdarr_set");
148
149         /* multidimensional arrays */
150
151         prop= RNA_def_property(srna, "fmarr", PROP_FLOAT, PROP_NONE);
152         RNA_def_property_multidimensional_array(prop, MARRAY_SIZE(float), MARRAY_TOTDIM, dimsize);
153         RNA_def_property_float_funcs(prop, "rna_Test_fmarr_get", "rna_Test_fmarr_set", NULL);
154
155         prop= RNA_def_property(srna, "imarr", PROP_INT, PROP_NONE);
156         RNA_def_property_multidimensional_array(prop, MARRAY_SIZE(int), MARRAY_TOTDIM, dimsize);
157         RNA_def_property_int_funcs(prop, "rna_Test_imarr_get", "rna_Test_imarr_set", NULL);
158
159         prop= RNA_def_property(srna, "bmarr", PROP_BOOLEAN, PROP_NONE);
160         RNA_def_property_multidimensional_array(prop, MARRAY_SIZE(int), MARRAY_TOTDIM, dimsize);
161         RNA_def_property_boolean_funcs(prop, "rna_Test_bmarr_get", "rna_Test_bmarr_set");
162
163         /* dynamic multidimensional arrays */
164
165         prop= RNA_def_property(srna, "fdmarr", PROP_FLOAT, PROP_NONE);
166         RNA_def_property_multidimensional_array(prop, DYNAMIC_MARRAY_SIZE(float), MARRAY_TOTDIM, dimsize);
167         RNA_def_property_flag(prop, PROP_DYNAMIC);
168         RNA_def_property_dynamic_array_funcs(prop, "rna_Test_fdmarr_get_length", "rna_Test_fdmarr_set_length");
169         RNA_def_property_float_funcs(prop, "rna_Test_fdmarr_get", "rna_Test_fdmarr_set", NULL);
170
171         prop= RNA_def_property(srna, "idmarr", PROP_INT, PROP_NONE);
172         RNA_def_property_multidimensional_array(prop, DYNAMIC_MARRAY_SIZE(int), MARRAY_TOTDIM, dimsize);
173         RNA_def_property_flag(prop, PROP_DYNAMIC);
174         RNA_def_property_dynamic_array_funcs(prop, "rna_Test_idmarr_get_length", "rna_Test_idmarr_set_length");
175         RNA_def_property_int_funcs(prop, "rna_Test_idmarr_get", "rna_Test_idmarr_set", NULL);
176
177         prop= RNA_def_property(srna, "bdmarr", PROP_BOOLEAN, PROP_NONE);
178         RNA_def_property_multidimensional_array(prop, DYNAMIC_MARRAY_SIZE(int), MARRAY_TOTDIM, dimsize);
179         RNA_def_property_flag(prop, PROP_DYNAMIC);
180         RNA_def_property_dynamic_array_funcs(prop, "rna_Test_bdmarr_get_length", "rna_Test_bdmarr_set_length");
181         RNA_def_property_boolean_funcs(prop, "rna_Test_bdmarr_get", "rna_Test_bdmarr_set");
182
183 #endif
184 }
185
186 #endif  /* RNA_RUNTIME */
187
188