Comments and other text editing:
[blender.git] / source / blender / makesrna / intern / rna_main.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Blender Foundation (2008).
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/makesrna/intern/rna_main.c
24  *  \ingroup RNA
25  */
26
27
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "RNA_define.h"
32
33 #include "rna_internal.h"
34
35 #ifdef RNA_RUNTIME
36
37 #include "BKE_main.h"
38 #include "BKE_mesh.h"
39 #include "BKE_global.h"
40
41 /* all the list begin functions are added manually here, Main is not in SDNA */
42
43 static int rna_Main_is_saved_get(PointerRNA *UNUSED(ptr))
44 {
45         return G.relbase_valid;
46 }
47
48 static int rna_Main_is_dirty_get(PointerRNA *ptr)
49 {
50         /* XXX, not totally nice to do it this way, should store in main ? */
51         Main *bmain= (Main*)ptr->data;
52         wmWindowManager *wm;
53         for(wm= bmain->wm.first; wm; wm= wm->id.next) {
54                 return !wm->file_saved;
55         }
56
57         return TRUE;
58 }
59
60 static void rna_Main_filepath_get(PointerRNA *ptr, char *value)
61 {
62         Main *bmain= (Main*)ptr->data;
63         BLI_strncpy(value, bmain->name, sizeof(bmain->name));
64 }
65
66 static int rna_Main_filepath_length(PointerRNA *ptr)
67 {
68         Main *bmain= (Main*)ptr->data;
69         return strlen(bmain->name);
70 }
71
72 #if 0
73 static void rna_Main_filepath_set(PointerRNA *ptr, const char *value)
74 {
75         Main *bmain= (Main*)ptr->data;
76         BLI_strncpy(bmain->name, value, sizeof(bmain->name));
77 }
78 #endif
79
80 static void rna_Main_scene_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
81 {
82         Main *bmain= (Main*)ptr->data;
83         rna_iterator_listbase_begin(iter, &bmain->scene, NULL);
84 }
85
86 static void rna_Main_object_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
87 {
88         Main *bmain= (Main*)ptr->data;
89         rna_iterator_listbase_begin(iter, &bmain->object, NULL);
90 }
91
92 static void rna_Main_lamp_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
93 {
94         Main *bmain= (Main*)ptr->data;
95         rna_iterator_listbase_begin(iter, &bmain->lamp, NULL);
96 }
97
98 static void rna_Main_library_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
99 {
100         Main *bmain= (Main*)ptr->data;
101         rna_iterator_listbase_begin(iter, &bmain->library, NULL);
102 }
103
104 static void rna_Main_mesh_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
105 {
106         Main *bmain= (Main*)ptr->data;
107         rna_iterator_listbase_begin(iter, &bmain->mesh, NULL);
108 }
109
110 static void rna_Main_curve_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
111 {
112         Main *bmain= (Main*)ptr->data;
113         rna_iterator_listbase_begin(iter, &bmain->curve, NULL);
114 }
115
116 static void rna_Main_mball_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
117 {
118         Main *bmain= (Main*)ptr->data;
119         rna_iterator_listbase_begin(iter, &bmain->mball, NULL);
120 }
121
122 static void rna_Main_mat_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
123 {
124         Main *bmain= (Main*)ptr->data;
125         rna_iterator_listbase_begin(iter, &bmain->mat, NULL);
126 }
127
128 static void rna_Main_tex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
129 {
130         Main *bmain= (Main*)ptr->data;
131         rna_iterator_listbase_begin(iter, &bmain->tex, NULL);
132 }
133
134 static void rna_Main_image_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
135 {
136         Main *bmain= (Main*)ptr->data;
137         rna_iterator_listbase_begin(iter, &bmain->image, NULL);
138 }
139
140 static void rna_Main_latt_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
141 {
142         Main *bmain= (Main*)ptr->data;
143         rna_iterator_listbase_begin(iter, &bmain->latt, NULL);
144 }
145
146 static void rna_Main_camera_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
147 {
148         Main *bmain= (Main*)ptr->data;
149         rna_iterator_listbase_begin(iter, &bmain->camera, NULL);
150 }
151
152 static void rna_Main_key_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
153 {
154         Main *bmain= (Main*)ptr->data;
155         rna_iterator_listbase_begin(iter, &bmain->key, NULL);
156 }
157
158 static void rna_Main_world_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
159 {
160         Main *bmain= (Main*)ptr->data;
161         rna_iterator_listbase_begin(iter, &bmain->world, NULL);
162 }
163
164 static void rna_Main_screen_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
165 {
166         Main *bmain= (Main*)ptr->data;
167         rna_iterator_listbase_begin(iter, &bmain->screen, NULL);
168 }
169
170 static void rna_Main_script_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
171 {
172         Main *bmain= (Main*)ptr->data;
173         rna_iterator_listbase_begin(iter, &bmain->script, NULL);
174 }
175
176 static void rna_Main_font_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
177 {
178         Main *bmain= (Main*)ptr->data;
179         rna_iterator_listbase_begin(iter, &bmain->vfont, NULL);
180 }
181
182 static void rna_Main_text_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
183 {
184         Main *bmain= (Main*)ptr->data;
185         rna_iterator_listbase_begin(iter, &bmain->text, NULL);
186 }
187
188 static void rna_Main_speaker_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
189 {
190         Main *bmain= (Main*)ptr->data;
191         rna_iterator_listbase_begin(iter, &bmain->speaker, NULL);
192 }
193
194 static void rna_Main_sound_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
195 {
196         Main *bmain= (Main*)ptr->data;
197         rna_iterator_listbase_begin(iter, &bmain->sound, NULL);
198 }
199
200 static void rna_Main_group_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
201 {
202         Main *bmain= (Main*)ptr->data;
203         rna_iterator_listbase_begin(iter, &bmain->group, NULL);
204 }
205
206 static void rna_Main_armature_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
207 {
208         Main *bmain= (Main*)ptr->data;
209         rna_iterator_listbase_begin(iter, &bmain->armature, NULL);
210 }
211
212 static void rna_Main_action_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
213 {
214         Main *bmain= (Main*)ptr->data;
215         rna_iterator_listbase_begin(iter, &bmain->action, NULL);
216 }
217
218 static void rna_Main_nodetree_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
219 {
220         Main *bmain= (Main*)ptr->data;
221         rna_iterator_listbase_begin(iter, &bmain->nodetree, NULL);
222 }
223
224 static void rna_Main_brush_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
225 {
226         Main *bmain= (Main*)ptr->data;
227         rna_iterator_listbase_begin(iter, &bmain->brush, NULL);
228 }
229
230 static void rna_Main_particle_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
231 {
232         Main *bmain= (Main*)ptr->data;
233         rna_iterator_listbase_begin(iter, &bmain->particle, NULL);
234 }
235
236 static void rna_Main_gpencil_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
237 {
238         Main *bmain= (Main*)ptr->data;
239         rna_iterator_listbase_begin(iter, &bmain->gpencil, NULL);
240 }
241
242 static void rna_Main_wm_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
243 {
244         Main *bmain= (Main*)ptr->data;
245         rna_iterator_listbase_begin(iter, &bmain->wm, NULL);
246 }
247
248 #ifdef UNIT_TEST
249
250 static PointerRNA rna_Test_test_get(PointerRNA *ptr)
251 {
252         PointerRNA ret= *ptr;
253         ret.type= &RNA_Test;
254
255         return ret;
256 }
257
258 #endif
259
260 #else
261
262 /* local convenience types */
263 typedef void (CollectionDefFunc)(struct BlenderRNA *brna, struct PropertyRNA *cprop);
264
265 typedef struct MainCollectionDef {
266         const char      *identifier;
267         const char      *type;
268         const char      *iter_begin;
269         const char      *name;
270         const char      *description;
271         CollectionDefFunc *func;
272 } MainCollectionDef;
273
274 void RNA_def_main(BlenderRNA *brna)
275 {
276         StructRNA *srna;
277         PropertyRNA *prop;
278         CollectionDefFunc *func;
279
280         /* plural must match idtypes in readblenentry.c */
281         MainCollectionDef lists[]= {
282                 {"cameras", "Camera", "rna_Main_camera_begin", "Cameras", "Camera datablocks", RNA_def_main_cameras},
283                 {"scenes", "Scene", "rna_Main_scene_begin", "Scenes", "Scene datablocks", RNA_def_main_scenes},
284                 {"objects", "Object", "rna_Main_object_begin", "Objects", "Object datablocks", RNA_def_main_objects},
285                 {"materials", "Material", "rna_Main_mat_begin", "Materials", "Material datablocks", RNA_def_main_materials},
286                 {"node_groups", "NodeTree", "rna_Main_nodetree_begin", "Node Groups", "Node group datablocks", RNA_def_main_node_groups},
287                 {"meshes", "Mesh", "rna_Main_mesh_begin", "Meshes", "Mesh datablocks", RNA_def_main_meshes},
288                 {"lamps", "Lamp", "rna_Main_lamp_begin", "Lamps", "Lamp datablocks", RNA_def_main_lamps},
289                 {"libraries", "Library", "rna_Main_library_begin", "Libraries", "Library datablocks", RNA_def_main_libraries},
290                 {"screens", "Screen", "rna_Main_screen_begin", "Screens", "Screen datablocks", RNA_def_main_screens},
291                 {"window_managers", "WindowManager", "rna_Main_wm_begin", "Window Managers", "Window manager datablocks", RNA_def_main_window_managers},
292                 {"images", "Image", "rna_Main_image_begin", "Images", "Image datablocks", RNA_def_main_images},
293                 {"lattices", "Lattice", "rna_Main_latt_begin", "Lattices", "Lattice datablocks", RNA_def_main_lattices},
294                 {"curves", "Curve", "rna_Main_curve_begin", "Curves", "Curve datablocks", RNA_def_main_curves} ,
295                 {"metaballs", "MetaBall", "rna_Main_mball_begin", "Metaballs", "Metaball datablocks", RNA_def_main_metaballs},
296                 {"fonts", "VectorFont", "rna_Main_font_begin", "Vector Fonts", "Vector font datablocks", RNA_def_main_fonts},
297                 {"textures", "Texture", "rna_Main_tex_begin", "Textures", "Texture datablocks", RNA_def_main_textures},
298                 {"brushes", "Brush", "rna_Main_brush_begin", "Brushes", "Brush datablocks", RNA_def_main_brushes},
299                 {"worlds", "World", "rna_Main_world_begin", "Worlds", "World datablocks", RNA_def_main_worlds},
300                 {"groups", "Group", "rna_Main_group_begin", "Groups", "Group datablocks", RNA_def_main_groups},
301                 {"shape_keys", "Key", "rna_Main_key_begin", "Shape Keys", "Shape Key datablocks", NULL},
302                 {"scripts", "ID", "rna_Main_script_begin", "Scripts", "Script datablocks (DEPRECATED)", NULL},
303                 {"texts", "Text", "rna_Main_text_begin", "Texts", "Text datablocks", RNA_def_main_texts},
304                 {"speakers", "Speaker", "rna_Main_speaker_begin", "Speakers", "Speaker datablocks", RNA_def_main_speakers},
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                 {NULL, NULL, NULL, NULL, NULL, NULL}};
311
312         int i;
313         
314         srna= RNA_def_struct(brna, "BlendData", NULL);
315         RNA_def_struct_ui_text(srna, "Blendfile Data", "Main data structure representing a .blend file and all its datablocks");
316         RNA_def_struct_ui_icon(srna, ICON_BLENDER);
317
318         prop= RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
319         RNA_def_property_string_maxlength(prop, 240);
320         RNA_def_property_string_funcs(prop, "rna_Main_filepath_get", "rna_Main_filepath_length", "rna_Main_filepath_set");
321         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
322         RNA_def_property_ui_text(prop, "Filename", "Path to the .blend file");
323         
324         prop= RNA_def_property(srna, "is_dirty", PROP_BOOLEAN, PROP_NONE);
325         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
326         RNA_def_property_boolean_funcs(prop, "rna_Main_is_dirty_get", NULL);
327         RNA_def_property_ui_text(prop, "File Has Unsaved Changes", "Have recent edits been saved to disk");
328
329         prop= RNA_def_property(srna, "is_saved", PROP_BOOLEAN, PROP_NONE);
330         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
331         RNA_def_property_boolean_funcs(prop, "rna_Main_is_saved_get", NULL);
332         RNA_def_property_ui_text(prop, "File is Saved", "Has the current session been saved to disk as a .blend file");
333
334         for(i=0; lists[i].name; i++)
335         {
336                 prop= RNA_def_property(srna, lists[i].identifier, PROP_COLLECTION, PROP_NONE);
337                 RNA_def_property_struct_type(prop, lists[i].type);
338                 RNA_def_property_collection_funcs(prop, lists[i].iter_begin, "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", NULL, NULL, NULL, NULL);
339                 RNA_def_property_ui_text(prop, lists[i].name, lists[i].description);
340
341                 /* collection functions */
342                 func= lists[i].func;
343                 if(func)
344                         func(brna, prop);
345         }
346
347         RNA_api_main(srna);
348
349 #ifdef UNIT_TEST
350
351         RNA_define_verify_sdna(0);
352
353         prop= RNA_def_property(srna, "test", PROP_POINTER, PROP_NONE);
354         RNA_def_property_struct_type(prop, "Test");
355         RNA_def_property_pointer_funcs(prop, "rna_Test_test_get", NULL, NULL, NULL);
356
357         RNA_define_verify_sdna(1);
358
359 #endif
360 }
361
362 #endif
363