NLA SoC: Merge from 2.5
[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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 #include "RNA_types.h"
30
31 #include "rna_internal.h"
32
33 #ifdef RNA_RUNTIME
34
35 #include "BKE_main.h"
36 #include "BKE_mesh.h"
37
38 /* all the list begin functions are added manually here, Main is not in SDNA */
39
40 static void rna_Main_filename_get(PointerRNA *ptr, char *value)
41 {
42         Main *bmain= (Main*)ptr->data;
43         BLI_strncpy(value, bmain->name, sizeof(bmain->name));
44 }
45
46 static int rna_Main_filename_length(PointerRNA *ptr)
47 {
48         Main *bmain= (Main*)ptr->data;
49         return strlen(bmain->name);
50 }
51
52 #if 0
53 static void rna_Main_filename_set(PointerRNA *ptr, const char *value)
54 {
55         Main *bmain= (Main*)ptr->data;
56         BLI_strncpy(bmain->name, value, sizeof(bmain->name));
57 }
58 #endif
59
60 static void rna_Main_scene_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
61 {
62         Main *bmain= (Main*)ptr->data;
63         rna_iterator_listbase_begin(iter, &bmain->scene, NULL);
64 }
65
66 static void rna_Main_object_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
67 {
68         Main *bmain= (Main*)ptr->data;
69         rna_iterator_listbase_begin(iter, &bmain->object, NULL);
70 }
71
72 static void rna_Main_lamp_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
73 {
74         Main *bmain= (Main*)ptr->data;
75         rna_iterator_listbase_begin(iter, &bmain->lamp, NULL);
76 }
77
78 static void rna_Main_library_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
79 {
80         Main *bmain= (Main*)ptr->data;
81         rna_iterator_listbase_begin(iter, &bmain->library, NULL);
82 }
83
84 static void rna_Main_mesh_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
85 {
86         Main *bmain= (Main*)ptr->data;
87         rna_iterator_listbase_begin(iter, &bmain->mesh, NULL);
88 }
89
90 static void rna_Main_curve_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
91 {
92         Main *bmain= (Main*)ptr->data;
93         rna_iterator_listbase_begin(iter, &bmain->curve, NULL);
94 }
95
96 static void rna_Main_mball_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
97 {
98         Main *bmain= (Main*)ptr->data;
99         rna_iterator_listbase_begin(iter, &bmain->mball, NULL);
100 }
101
102 static void rna_Main_mat_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
103 {
104         Main *bmain= (Main*)ptr->data;
105         rna_iterator_listbase_begin(iter, &bmain->mat, NULL);
106 }
107
108 static void rna_Main_tex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
109 {
110         Main *bmain= (Main*)ptr->data;
111         rna_iterator_listbase_begin(iter, &bmain->tex, NULL);
112 }
113
114 static void rna_Main_image_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
115 {
116         Main *bmain= (Main*)ptr->data;
117         rna_iterator_listbase_begin(iter, &bmain->image, NULL);
118 }
119
120 static void rna_Main_latt_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
121 {
122         Main *bmain= (Main*)ptr->data;
123         rna_iterator_listbase_begin(iter, &bmain->latt, NULL);
124 }
125
126 static void rna_Main_camera_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
127 {
128         Main *bmain= (Main*)ptr->data;
129         rna_iterator_listbase_begin(iter, &bmain->camera, NULL);
130 }
131
132 static void rna_Main_key_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
133 {
134         Main *bmain= (Main*)ptr->data;
135         rna_iterator_listbase_begin(iter, &bmain->key, NULL);
136 }
137
138 static void rna_Main_world_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
139 {
140         Main *bmain= (Main*)ptr->data;
141         rna_iterator_listbase_begin(iter, &bmain->world, NULL);
142 }
143
144 static void rna_Main_screen_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
145 {
146         Main *bmain= (Main*)ptr->data;
147         rna_iterator_listbase_begin(iter, &bmain->screen, NULL);
148 }
149
150 static void rna_Main_script_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
151 {
152         Main *bmain= (Main*)ptr->data;
153         rna_iterator_listbase_begin(iter, &bmain->script, NULL);
154 }
155
156 static void rna_Main_vfont_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
157 {
158         Main *bmain= (Main*)ptr->data;
159         rna_iterator_listbase_begin(iter, &bmain->vfont, NULL);
160 }
161
162 static void rna_Main_text_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
163 {
164         Main *bmain= (Main*)ptr->data;
165         rna_iterator_listbase_begin(iter, &bmain->text, NULL);
166 }
167
168 static void rna_Main_sound_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
169 {
170         Main *bmain= (Main*)ptr->data;
171         rna_iterator_listbase_begin(iter, &bmain->sound, NULL);
172 }
173
174 static void rna_Main_group_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
175 {
176         Main *bmain= (Main*)ptr->data;
177         rna_iterator_listbase_begin(iter, &bmain->group, NULL);
178 }
179
180 static void rna_Main_armature_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
181 {
182         Main *bmain= (Main*)ptr->data;
183         rna_iterator_listbase_begin(iter, &bmain->armature, NULL);
184 }
185
186 static void rna_Main_action_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
187 {
188         Main *bmain= (Main*)ptr->data;
189         rna_iterator_listbase_begin(iter, &bmain->action, NULL);
190 }
191
192 static void rna_Main_nodetree_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
193 {
194         Main *bmain= (Main*)ptr->data;
195         rna_iterator_listbase_begin(iter, &bmain->nodetree, NULL);
196 }
197
198 static void rna_Main_brush_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
199 {
200         Main *bmain= (Main*)ptr->data;
201         rna_iterator_listbase_begin(iter, &bmain->brush, NULL);
202 }
203
204 static void rna_Main_particle_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
205 {
206         Main *bmain= (Main*)ptr->data;
207         rna_iterator_listbase_begin(iter, &bmain->particle, NULL);
208 }
209
210 static void rna_Main_wm_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
211 {
212         Main *bmain= (Main*)ptr->data;
213         rna_iterator_listbase_begin(iter, &bmain->wm, NULL);
214 }
215
216 #else
217
218 void RNA_def_main(BlenderRNA *brna)
219 {
220         StructRNA *srna;
221         PropertyRNA *prop;
222
223         const char *lists[][5]= {
224                 {"cameras", "Camera", "rna_Main_camera_begin", "Cameras", "Camera datablocks."},
225                 {"scenes", "Scene", "rna_Main_scene_begin", "Scenes", "Scene datablocks."},
226                 {"objects", "Object", "rna_Main_object_begin", "Objects", "Object datablocks."},
227                 {"materials", "Material", "rna_Main_mat_begin", "Materials", "Material datablocks."},
228                 {"nodetrees", "NodeTree", "rna_Main_nodetree_begin", "Node Trees", "Nodetree datablocks."},
229                 {"meshes", "Mesh", "rna_Main_mesh_begin", "Meshes", "Mesh datablocks."}, 
230                 {"lamps", "Lamp", "rna_Main_lamp_begin", "Lamps", "Lamp datablocks."},
231                 {"libraries", "Library", "rna_Main_library_begin", "Libraries", "Library datablocks."},
232                 {"screens", "Screen", "rna_Main_screen_begin", "Screens", "Screen datablocks."},
233                 {"windowmanagers", "WindowManager", "rna_Main_wm_begin", "Window Managers", "Window manager datablocks."},
234                 {"images", "Image", "rna_Main_image_begin", "Images", "Image datablocks."},
235                 {"lattices", "Lattice", "rna_Main_latt_begin", "Lattices", "Lattice datablocks."},
236                 {"curves", "Curve", "rna_Main_curve_begin", "Curves", "Curve datablocks."}, 
237                 {"metaballs", "MetaBall", "rna_Main_mball_begin", "Metaballs", "Metaball datablocks."},
238                 {"vfonts", "VectorFont", "rna_Main_vfont_begin", "Vector Fonts", "Vector font datablocks."},
239                 {"textures", "Texture", "rna_Main_tex_begin", "Textures", "Texture datablocks."},
240                 {"brushes", "Brush", "rna_Main_brush_begin", "Brushes", "Brush datablocks."},
241                 {"worlds", "World", "rna_Main_world_begin", "Worlds", "World datablocks."},
242                 {"groups", "Group", "rna_Main_group_begin", "Groups", "Group datablocks."},
243                 {"keys", "ID", "rna_Main_key_begin", "Keys", "Key datablocks."},
244                 {"scripts", "ID", "rna_Main_script_begin", "Scripts", "Script datablocks."},
245                 {"texts", "Text", "rna_Main_text_begin", "Texts", "Text datablocks."},
246                 {"sounds", "ID", "rna_Main_sound_begin", "Sounds", "Sound datablocks."},
247                 {"armatures", "Armature", "rna_Main_armature_begin", "Armatures", "Armature datablocks."},
248                 {"actions", "Action", "rna_Main_action_begin", "Actions", "Action datablocks."},
249                 {"particles", "ParticleSettings", "rna_Main_particle_begin", "Particles", "Particle datablocks."},
250                 {NULL, NULL, NULL, NULL, NULL}};
251         int i;
252         
253         srna= RNA_def_struct(brna, "Main", NULL);
254         RNA_def_struct_ui_text(srna, "Main", "Main data structure representing a .blend file and all its datablocks.");
255         RNA_def_struct_ui_icon(srna, ICON_BLENDER);
256
257         prop= RNA_def_property(srna, "filename", PROP_STRING, PROP_FILEPATH);
258         RNA_def_property_string_maxlength(prop, 240);
259         RNA_def_property_string_funcs(prop, "rna_Main_filename_get", "rna_Main_filename_length", "rna_Main_filename_set");
260         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
261         RNA_def_property_ui_text(prop, "Filename", "Path to the .blend file.");
262
263         for(i=0; lists[i][0]; i++)
264         {
265                 prop= RNA_def_property(srna, lists[i][0], PROP_COLLECTION, PROP_NONE);
266                 RNA_def_property_struct_type(prop, lists[i][1]);
267                 RNA_def_property_collection_funcs(prop, lists[i][2], "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0, "add_mesh", "remove_mesh");
268                 RNA_def_property_ui_text(prop, lists[i][3], lists[i][4]);
269         }
270
271         RNA_api_main(srna);
272 }
273
274 #endif
275