Merged changes in the trunk up to revision 35203.
[blender.git] / source / blender / makesrna / intern / rna_main.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * Contributor(s): Blender Foundation (2008).
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "RNA_define.h"
29
30 #include "rna_internal.h"
31
32 #ifdef RNA_RUNTIME
33
34 #include "BKE_main.h"
35 #include "BKE_mesh.h"
36 #include "BKE_global.h"
37
38 /* all the list begin functions are added manually here, Main is not in SDNA */
39
40 static int rna_Main_is_dirty_get(PointerRNA *ptr)
41 {
42         return !G.relbase_valid;
43 }
44
45 static void rna_Main_filepath_get(PointerRNA *ptr, char *value)
46 {
47         Main *bmain= (Main*)ptr->data;
48         BLI_strncpy(value, bmain->name, sizeof(bmain->name));
49 }
50
51 static int rna_Main_filepath_length(PointerRNA *ptr)
52 {
53         Main *bmain= (Main*)ptr->data;
54         return strlen(bmain->name);
55 }
56
57 #if 0
58 static void rna_Main_filepath_set(PointerRNA *ptr, const char *value)
59 {
60         Main *bmain= (Main*)ptr->data;
61         BLI_strncpy(bmain->name, value, sizeof(bmain->name));
62 }
63 #endif
64
65 static void rna_Main_scene_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
66 {
67         Main *bmain= (Main*)ptr->data;
68         rna_iterator_listbase_begin(iter, &bmain->scene, NULL);
69 }
70
71 static void rna_Main_object_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
72 {
73         Main *bmain= (Main*)ptr->data;
74         rna_iterator_listbase_begin(iter, &bmain->object, NULL);
75 }
76
77 static void rna_Main_lamp_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
78 {
79         Main *bmain= (Main*)ptr->data;
80         rna_iterator_listbase_begin(iter, &bmain->lamp, NULL);
81 }
82
83 static void rna_Main_library_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
84 {
85         Main *bmain= (Main*)ptr->data;
86         rna_iterator_listbase_begin(iter, &bmain->library, NULL);
87 }
88
89 static void rna_Main_mesh_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
90 {
91         Main *bmain= (Main*)ptr->data;
92         rna_iterator_listbase_begin(iter, &bmain->mesh, NULL);
93 }
94
95 static void rna_Main_curve_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
96 {
97         Main *bmain= (Main*)ptr->data;
98         rna_iterator_listbase_begin(iter, &bmain->curve, NULL);
99 }
100
101 static void rna_Main_mball_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
102 {
103         Main *bmain= (Main*)ptr->data;
104         rna_iterator_listbase_begin(iter, &bmain->mball, NULL);
105 }
106
107 static void rna_Main_mat_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
108 {
109         Main *bmain= (Main*)ptr->data;
110         rna_iterator_listbase_begin(iter, &bmain->mat, NULL);
111 }
112
113 static void rna_Main_tex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
114 {
115         Main *bmain= (Main*)ptr->data;
116         rna_iterator_listbase_begin(iter, &bmain->tex, NULL);
117 }
118
119 static void rna_Main_image_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
120 {
121         Main *bmain= (Main*)ptr->data;
122         rna_iterator_listbase_begin(iter, &bmain->image, NULL);
123 }
124
125 static void rna_Main_latt_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
126 {
127         Main *bmain= (Main*)ptr->data;
128         rna_iterator_listbase_begin(iter, &bmain->latt, NULL);
129 }
130
131 static void rna_Main_camera_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
132 {
133         Main *bmain= (Main*)ptr->data;
134         rna_iterator_listbase_begin(iter, &bmain->camera, NULL);
135 }
136
137 static void rna_Main_key_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
138 {
139         Main *bmain= (Main*)ptr->data;
140         rna_iterator_listbase_begin(iter, &bmain->key, NULL);
141 }
142
143 static void rna_Main_world_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
144 {
145         Main *bmain= (Main*)ptr->data;
146         rna_iterator_listbase_begin(iter, &bmain->world, NULL);
147 }
148
149 static void rna_Main_screen_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
150 {
151         Main *bmain= (Main*)ptr->data;
152         rna_iterator_listbase_begin(iter, &bmain->screen, NULL);
153 }
154
155 static void rna_Main_script_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
156 {
157         Main *bmain= (Main*)ptr->data;
158         rna_iterator_listbase_begin(iter, &bmain->script, NULL);
159 }
160
161 static void rna_Main_font_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
162 {
163         Main *bmain= (Main*)ptr->data;
164         rna_iterator_listbase_begin(iter, &bmain->vfont, NULL);
165 }
166
167 static void rna_Main_text_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
168 {
169         Main *bmain= (Main*)ptr->data;
170         rna_iterator_listbase_begin(iter, &bmain->text, NULL);
171 }
172
173 static void rna_Main_sound_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
174 {
175         Main *bmain= (Main*)ptr->data;
176         rna_iterator_listbase_begin(iter, &bmain->sound, NULL);
177 }
178
179 static void rna_Main_group_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
180 {
181         Main *bmain= (Main*)ptr->data;
182         rna_iterator_listbase_begin(iter, &bmain->group, NULL);
183 }
184
185 static void rna_Main_armature_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
186 {
187         Main *bmain= (Main*)ptr->data;
188         rna_iterator_listbase_begin(iter, &bmain->armature, NULL);
189 }
190
191 static void rna_Main_action_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
192 {
193         Main *bmain= (Main*)ptr->data;
194         rna_iterator_listbase_begin(iter, &bmain->action, NULL);
195 }
196
197 static void rna_Main_nodetree_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
198 {
199         Main *bmain= (Main*)ptr->data;
200         rna_iterator_listbase_begin(iter, &bmain->nodetree, NULL);
201 }
202
203 static void rna_Main_brush_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
204 {
205         Main *bmain= (Main*)ptr->data;
206         rna_iterator_listbase_begin(iter, &bmain->brush, NULL);
207 }
208
209 static void rna_Main_particle_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
210 {
211         Main *bmain= (Main*)ptr->data;
212         rna_iterator_listbase_begin(iter, &bmain->particle, NULL);
213 }
214
215 static void rna_Main_gpencil_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
216 {
217         Main *bmain= (Main*)ptr->data;
218         rna_iterator_listbase_begin(iter, &bmain->gpencil, NULL);
219 }
220
221 static void rna_Main_wm_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
222 {
223         Main *bmain= (Main*)ptr->data;
224         rna_iterator_listbase_begin(iter, &bmain->wm, NULL);
225 }
226
227 static void rna_Main_linestyle_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
228 {
229         Main *bmain= (Main*)ptr->data;
230         rna_iterator_listbase_begin(iter, &bmain->linestyle, NULL);
231 }
232
233 #ifdef UNIT_TEST
234
235 static PointerRNA rna_Test_test_get(PointerRNA *ptr)
236 {
237         PointerRNA ret= *ptr;
238         ret.type= &RNA_Test;
239
240         return ret;
241 }
242
243 #endif
244
245 #else
246
247 /* local convenience types */
248 typedef void (CollectionDefFunc)(struct BlenderRNA *brna, struct PropertyRNA *cprop);
249
250 typedef struct MainCollectionDef {
251         const char      *identifier;
252         const char      *type;
253         const char      *iter_begin;
254         const char      *name;
255         const char      *description;
256         CollectionDefFunc *func;
257 } MainCollectionDef;
258
259 void RNA_def_main(BlenderRNA *brna)
260 {
261         StructRNA *srna;
262         PropertyRNA *prop;
263         CollectionDefFunc *func;
264
265         /* plural must match idtypes in readblenentry.c */
266         MainCollectionDef lists[]= {
267                 {"cameras", "Camera", "rna_Main_camera_begin", "Cameras", "Camera datablocks.", RNA_def_main_cameras},
268                 {"scenes", "Scene", "rna_Main_scene_begin", "Scenes", "Scene datablocks.", RNA_def_main_scenes},
269                 {"objects", "Object", "rna_Main_object_begin", "Objects", "Object datablocks.", RNA_def_main_objects},
270                 {"materials", "Material", "rna_Main_mat_begin", "Materials", "Material datablocks.", RNA_def_main_materials},
271                 {"node_groups", "NodeTree", "rna_Main_nodetree_begin", "Node Groups", "Node group datablocks.", RNA_def_main_node_groups},
272                 {"meshes", "Mesh", "rna_Main_mesh_begin", "Meshes", "Mesh datablocks.", RNA_def_main_meshes},
273                 {"lamps", "Lamp", "rna_Main_lamp_begin", "Lamps", "Lamp datablocks.", RNA_def_main_lamps},
274                 {"libraries", "Library", "rna_Main_library_begin", "Libraries", "Library datablocks.", RNA_def_main_libraries},
275                 {"screens", "Screen", "rna_Main_screen_begin", "Screens", "Screen datablocks.", RNA_def_main_screens},
276                 {"window_managers", "WindowManager", "rna_Main_wm_begin", "Window Managers", "Window manager datablocks.", RNA_def_main_window_managers},
277                 {"images", "Image", "rna_Main_image_begin", "Images", "Image datablocks.", RNA_def_main_images},
278                 {"lattices", "Lattice", "rna_Main_latt_begin", "Lattices", "Lattice datablocks.", RNA_def_main_lattices},
279                 {"curves", "Curve", "rna_Main_curve_begin", "Curves", "Curve datablocks.", RNA_def_main_curves} ,
280                 {"metaballs", "MetaBall", "rna_Main_mball_begin", "Metaballs", "Metaball datablocks.", RNA_def_main_metaballs},
281                 {"fonts", "VectorFont", "rna_Main_font_begin", "Vector Fonts", "Vector font datablocks.", RNA_def_main_fonts},
282                 {"textures", "Texture", "rna_Main_tex_begin", "Textures", "Texture datablocks.", RNA_def_main_textures},
283                 {"brushes", "Brush", "rna_Main_brush_begin", "Brushes", "Brush datablocks.", RNA_def_main_brushes},
284                 {"worlds", "World", "rna_Main_world_begin", "Worlds", "World datablocks.", RNA_def_main_worlds},
285                 {"groups", "Group", "rna_Main_group_begin", "Groups", "Group datablocks.", RNA_def_main_groups},
286                 {"shape_keys", "Key", "rna_Main_key_begin", "Keys", "Key datablocks.", NULL},
287                 {"scripts", "ID", "rna_Main_script_begin", "Scripts", "Script datablocks (DEPRECATED).", NULL},
288                 {"texts", "Text", "rna_Main_text_begin", "Texts", "Text datablocks.", RNA_def_main_texts},
289                 {"sounds", "Sound", "rna_Main_sound_begin", "Sounds", "Sound datablocks.", RNA_def_main_sounds},
290                 {"armatures", "Armature", "rna_Main_armature_begin", "Armatures", "Armature datablocks.", RNA_def_main_armatures},
291                 {"actions", "Action", "rna_Main_action_begin", "Actions", "Action datablocks.", RNA_def_main_actions},
292                 {"particles", "ParticleSettings", "rna_Main_particle_begin", "Particles", "Particle datablocks.", RNA_def_main_particles},
293                 {"grease_pencil", "GreasePencil", "rna_Main_gpencil_begin", "Grease Pencil", "Grease Pencil datablocks.", RNA_def_main_gpencil},
294                 {"linestyles", "FreestyleLineStyle", "rna_Main_linestyle_begin", "Line Styles", "Line Style datablocks.", RNA_def_main_linestyles},
295                 {NULL, NULL, NULL, NULL, NULL, NULL}};
296
297         int i;
298         
299         srna= RNA_def_struct(brna, "BlendData", NULL);
300         RNA_def_struct_ui_text(srna, "Blendfile Data", "Main data structure representing a .blend file and all its datablocks");
301         RNA_def_struct_ui_icon(srna, ICON_BLENDER);
302
303         prop= RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
304         RNA_def_property_string_maxlength(prop, 240);
305         RNA_def_property_string_funcs(prop, "rna_Main_filepath_get", "rna_Main_filepath_length", "rna_Main_filepath_set");
306         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
307         RNA_def_property_ui_text(prop, "Filename", "Path to the .blend file");
308         
309         prop= RNA_def_property(srna, "is_dirty", PROP_BOOLEAN, PROP_NONE);
310         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
311         RNA_def_property_boolean_funcs(prop, "rna_Main_is_dirty_get", NULL);
312         RNA_def_property_ui_text(prop, "File is Saved", "Has the current session been saved to disk as a .blend file");
313
314         for(i=0; lists[i].name; i++)
315         {
316                 prop= RNA_def_property(srna, lists[i].identifier, PROP_COLLECTION, PROP_NONE);
317                 RNA_def_property_struct_type(prop, lists[i].type);
318                 RNA_def_property_collection_funcs(prop, lists[i].iter_begin, "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0);
319                 RNA_def_property_ui_text(prop, lists[i].name, lists[i].description);
320
321                 /* collection functions */
322                 func= lists[i].func;
323                 if(func)
324                         func(brna, prop);
325         }
326
327         RNA_api_main(srna);
328
329 #ifdef UNIT_TEST
330
331         RNA_define_verify_sdna(0);
332
333         prop= RNA_def_property(srna, "test", PROP_POINTER, PROP_NONE);
334         RNA_def_property_struct_type(prop, "Test");
335         RNA_def_property_pointer_funcs(prop, "rna_Test_test_get", NULL, NULL, NULL);
336
337         RNA_define_verify_sdna(1);
338
339 #endif
340 }
341
342 #endif
343