RNA
[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 #ifdef RNA_RUNTIME
32
33 #include "BKE_main.h"
34
35 /* all the list begin functions are added manually here, Main is not in SDNA */
36
37 static void rna_Main_filename_get(PointerRNA *ptr, char *value)
38 {
39         Main *bmain= (Main*)ptr->data;
40         BLI_strncpy(value, bmain->name, sizeof(bmain->name));
41 }
42
43 static int rna_Main_filename_length(PointerRNA *ptr)
44 {
45         Main *bmain= (Main*)ptr->data;
46         return strlen(bmain->name);
47 }
48
49 static void rna_Main_filename_set(PointerRNA *ptr, const char *value)
50 {
51         Main *bmain= (Main*)ptr->data;
52         BLI_strncpy(bmain->name, value, sizeof(bmain->name));
53 }
54
55 static void rna_Main_scene_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
56 {
57         Main *bmain= (Main*)ptr->data;
58         rna_iterator_listbase_begin(iter, &bmain->scene, NULL);
59 }
60
61 static void rna_Main_object_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
62 {
63         Main *bmain= (Main*)ptr->data;
64         rna_iterator_listbase_begin(iter, &bmain->object, NULL);
65 }
66
67 static void rna_Main_lamp_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
68 {
69         Main *bmain= (Main*)ptr->data;
70         rna_iterator_listbase_begin(iter, &bmain->lamp, NULL);
71 }
72
73 static void rna_Main_library_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
74 {
75         Main *bmain= (Main*)ptr->data;
76         rna_iterator_listbase_begin(iter, &bmain->library, NULL);
77 }
78
79 static void rna_Main_mesh_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
80 {
81         Main *bmain= (Main*)ptr->data;
82         rna_iterator_listbase_begin(iter, &bmain->mesh, NULL);
83 }
84
85 static void rna_Main_curve_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
86 {
87         Main *bmain= (Main*)ptr->data;
88         rna_iterator_listbase_begin(iter, &bmain->curve, NULL);
89 }
90
91 static void rna_Main_mball_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
92 {
93         Main *bmain= (Main*)ptr->data;
94         rna_iterator_listbase_begin(iter, &bmain->mball, NULL);
95 }
96
97 static void rna_Main_mat_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
98 {
99         Main *bmain= (Main*)ptr->data;
100         rna_iterator_listbase_begin(iter, &bmain->mat, NULL);
101 }
102
103 static void rna_Main_tex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
104 {
105         Main *bmain= (Main*)ptr->data;
106         rna_iterator_listbase_begin(iter, &bmain->tex, NULL);
107 }
108
109 static void rna_Main_image_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
110 {
111         Main *bmain= (Main*)ptr->data;
112         rna_iterator_listbase_begin(iter, &bmain->image, NULL);
113 }
114
115 static void rna_Main_latt_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
116 {
117         Main *bmain= (Main*)ptr->data;
118         rna_iterator_listbase_begin(iter, &bmain->latt, NULL);
119 }
120
121 static void rna_Main_camera_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
122 {
123         Main *bmain= (Main*)ptr->data;
124         rna_iterator_listbase_begin(iter, &bmain->camera, NULL);
125 }
126
127 static void rna_Main_ipo_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
128 {
129         Main *bmain= (Main*)ptr->data;
130         rna_iterator_listbase_begin(iter, &bmain->ipo, NULL);
131 }
132
133 static void rna_Main_key_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
134 {
135         Main *bmain= (Main*)ptr->data;
136         rna_iterator_listbase_begin(iter, &bmain->key, NULL);
137 }
138
139 static void rna_Main_world_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
140 {
141         Main *bmain= (Main*)ptr->data;
142         rna_iterator_listbase_begin(iter, &bmain->world, NULL);
143 }
144
145 static void rna_Main_screen_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
146 {
147         Main *bmain= (Main*)ptr->data;
148         rna_iterator_listbase_begin(iter, &bmain->screen, NULL);
149 }
150
151 static void rna_Main_script_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
152 {
153         Main *bmain= (Main*)ptr->data;
154         rna_iterator_listbase_begin(iter, &bmain->script, NULL);
155 }
156
157 static void rna_Main_vfont_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
158 {
159         Main *bmain= (Main*)ptr->data;
160         rna_iterator_listbase_begin(iter, &bmain->vfont, NULL);
161 }
162
163 static void rna_Main_text_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
164 {
165         Main *bmain= (Main*)ptr->data;
166         rna_iterator_listbase_begin(iter, &bmain->text, NULL);
167 }
168
169 static void rna_Main_sound_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
170 {
171         Main *bmain= (Main*)ptr->data;
172         rna_iterator_listbase_begin(iter, &bmain->sound, NULL);
173 }
174
175 static void rna_Main_group_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
176 {
177         Main *bmain= (Main*)ptr->data;
178         rna_iterator_listbase_begin(iter, &bmain->group, NULL);
179 }
180
181 static void rna_Main_armature_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
182 {
183         Main *bmain= (Main*)ptr->data;
184         rna_iterator_listbase_begin(iter, &bmain->armature, NULL);
185 }
186
187 static void rna_Main_action_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
188 {
189         Main *bmain= (Main*)ptr->data;
190         rna_iterator_listbase_begin(iter, &bmain->action, NULL);
191 }
192
193 static void rna_Main_nodetree_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
194 {
195         Main *bmain= (Main*)ptr->data;
196         rna_iterator_listbase_begin(iter, &bmain->nodetree, NULL);
197 }
198
199 static void rna_Main_brush_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
200 {
201         Main *bmain= (Main*)ptr->data;
202         rna_iterator_listbase_begin(iter, &bmain->brush, NULL);
203 }
204
205 static void rna_Main_particle_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
206 {
207         Main *bmain= (Main*)ptr->data;
208         rna_iterator_listbase_begin(iter, &bmain->particle, NULL);
209 }
210
211 static void rna_Main_wm_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
212 {
213         Main *bmain= (Main*)ptr->data;
214         rna_iterator_listbase_begin(iter, &bmain->wm, NULL);
215 }
216
217 #else
218
219 void RNA_def_main(BlenderRNA *brna)
220 {
221         StructRNA *srna;
222         PropertyRNA *prop;
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                 {"ipos", "Ipo", "rna_Main_ipo_begin", "Ipos", "Ipo datablocks."},
241                 {"brushes", "Brush", "rna_Main_brush_begin", "Brushes", "Brush datablocks."},
242                 {"worlds", "World", "rna_Main_world_begin", "Worlds", "World datablocks."},
243                 {"groups", "Group", "rna_Main_group_begin", "Groups", "Group datablocks."},
244                 {"keys", "ID", "rna_Main_key_begin", "Keys", "Key datablocks."},
245                 {"scripts", "ID", "rna_Main_script_begin", "Scripts", "Script datablocks."},
246                 {"texts", "Text", "rna_Main_text_begin", "Texts", "Text datablocks."},
247                 {"sounds", "ID", "rna_Main_sound_begin", "Sounds", "Sound datablocks."},
248                 {"armatures", "Armature", "rna_Main_armature_begin", "Armatures", "Armature datablocks."},
249                 {"actions", "Action", "rna_Main_action_begin", "Actions", "Action datablocks."},
250                 {"particles", "ID", "rna_Main_particle_begin", "Particles", "Particle datablocks."},
251                 {NULL, NULL, NULL, NULL, NULL}};
252         int i;
253         
254         srna= RNA_def_struct(brna, "Main", NULL);
255         RNA_def_struct_ui_text(srna, "Main", "Main data structure representing a .blend file and all its datablocks.");
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_flag(prop, PROP_NOT_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, 0);
268                 RNA_def_property_ui_text(prop, lists[i][3], lists[i][4]);
269         }
270 }
271
272 #endif
273