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