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