Smart Extrude (hotkeys are tentative)
[blender-staging.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 #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 #if 0
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 #endif
139
140 static void rna_Main_world_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
141 {
142         Main *bmain= (Main*)ptr->data;
143         rna_iterator_listbase_begin(iter, &bmain->world, NULL);
144 }
145
146 static void rna_Main_screen_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
147 {
148         Main *bmain= (Main*)ptr->data;
149         rna_iterator_listbase_begin(iter, &bmain->screen, NULL);
150 }
151
152 static void rna_Main_script_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
153 {
154         Main *bmain= (Main*)ptr->data;
155         rna_iterator_listbase_begin(iter, &bmain->script, NULL);
156 }
157
158 static void rna_Main_vfont_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
159 {
160         Main *bmain= (Main*)ptr->data;
161         rna_iterator_listbase_begin(iter, &bmain->vfont, NULL);
162 }
163
164 static void rna_Main_text_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
165 {
166         Main *bmain= (Main*)ptr->data;
167         rna_iterator_listbase_begin(iter, &bmain->text, NULL);
168 }
169
170 static void rna_Main_sound_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
171 {
172         Main *bmain= (Main*)ptr->data;
173         rna_iterator_listbase_begin(iter, &bmain->sound, NULL);
174 }
175
176 static void rna_Main_group_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
177 {
178         Main *bmain= (Main*)ptr->data;
179         rna_iterator_listbase_begin(iter, &bmain->group, NULL);
180 }
181
182 static void rna_Main_armature_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
183 {
184         Main *bmain= (Main*)ptr->data;
185         rna_iterator_listbase_begin(iter, &bmain->armature, NULL);
186 }
187
188 static void rna_Main_action_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
189 {
190         Main *bmain= (Main*)ptr->data;
191         rna_iterator_listbase_begin(iter, &bmain->action, NULL);
192 }
193
194 static void rna_Main_nodetree_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
195 {
196         Main *bmain= (Main*)ptr->data;
197         rna_iterator_listbase_begin(iter, &bmain->nodetree, NULL);
198 }
199
200 static void rna_Main_brush_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
201 {
202         Main *bmain= (Main*)ptr->data;
203         rna_iterator_listbase_begin(iter, &bmain->brush, NULL);
204 }
205
206 static void rna_Main_particle_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
207 {
208         Main *bmain= (Main*)ptr->data;
209         rna_iterator_listbase_begin(iter, &bmain->particle, NULL);
210 }
211
212 static void rna_Main_gpencil_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
213 {
214         Main *bmain= (Main*)ptr->data;
215         rna_iterator_listbase_begin(iter, &bmain->gpencil, NULL);
216 }
217
218 static void rna_Main_wm_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
219 {
220         Main *bmain= (Main*)ptr->data;
221         rna_iterator_listbase_begin(iter, &bmain->wm, NULL);
222 }
223
224 #ifdef UNIT_TEST
225
226 static PointerRNA rna_Test_test_get(PointerRNA *ptr)
227 {
228         PointerRNA ret= *ptr;
229         ret.type= &RNA_Test;
230
231         return ret;
232 }
233
234 #endif
235
236 #else
237
238 /* local convenience types */
239 typedef void (CollectionDefFunc)(struct BlenderRNA *brna, struct PropertyRNA *cprop);
240
241 typedef struct MainCollectionDef {
242     const char  *identifier;
243     const char  *type;
244     const char  *iter_begin;
245     const char  *name;
246     const char  *description;
247     CollectionDefFunc *func;
248 } MainCollectionDef;
249
250 void RNA_def_main(BlenderRNA *brna)
251 {
252         StructRNA *srna;
253         PropertyRNA *prop;
254         CollectionDefFunc *func;
255
256         MainCollectionDef lists[]= {
257                 {"cameras", "Camera", "rna_Main_camera_begin", "Cameras", "Camera datablocks.", RNA_def_main_cameras},
258                 {"scenes", "Scene", "rna_Main_scene_begin", "Scenes", "Scene datablocks.", RNA_def_main_scenes},
259                 {"objects", "Object", "rna_Main_object_begin", "Objects", "Object datablocks.", RNA_def_main_objects},
260                 {"materials", "Material", "rna_Main_mat_begin", "Materials", "Material datablocks.", RNA_def_main_materials},
261                 {"node_groups", "NodeTree", "rna_Main_nodetree_begin", "Node Groups", "Node group datablocks.", RNA_def_main_node_groups},
262                 {"meshes", "Mesh", "rna_Main_mesh_begin", "Meshes", "Mesh datablocks.", RNA_def_main_meshes},
263                 {"lamps", "Lamp", "rna_Main_lamp_begin", "Lamps", "Lamp datablocks.", RNA_def_main_lamps},
264                 {"libraries", "Library", "rna_Main_library_begin", "Libraries", "Library datablocks.", RNA_def_main_libraries},
265                 {"screens", "Screen", "rna_Main_screen_begin", "Screens", "Screen datablocks.", RNA_def_main_screens},
266                 {"window_managers", "WindowManager", "rna_Main_wm_begin", "Window Managers", "Window manager datablocks.", RNA_def_main_window_managers},
267                 {"images", "Image", "rna_Main_image_begin", "Images", "Image datablocks.", RNA_def_main_images},
268                 {"lattices", "Lattice", "rna_Main_latt_begin", "Lattices", "Lattice datablocks.", RNA_def_main_lattices},
269                 {"curves", "Curve", "rna_Main_curve_begin", "Curves", "Curve datablocks.", RNA_def_main_curves} ,
270                 {"metaballs", "MetaBall", "rna_Main_mball_begin", "Metaballs", "Metaball datablocks.", RNA_def_main_metaballs},
271                 {"vfonts", "VectorFont", "rna_Main_vfont_begin", "Vector Fonts", "Vector font datablocks.", RNA_def_main_vfonts},
272                 {"textures", "Texture", "rna_Main_tex_begin", "Textures", "Texture datablocks.", RNA_def_main_textures},
273                 {"brushes", "Brush", "rna_Main_brush_begin", "Brushes", "Brush datablocks.", RNA_def_main_brushes},
274                 {"worlds", "World", "rna_Main_world_begin", "Worlds", "World datablocks.", RNA_def_main_worlds},
275                 {"groups", "Group", "rna_Main_group_begin", "Groups", "Group datablocks.", RNA_def_main_groups},
276 /*              {"keys", "Key", "rna_Main_key_begin", "Keys", "Key datablocks.", NULL}, */
277                 {"scripts", "ID", "rna_Main_script_begin", "Scripts", "Script datablocks (DEPRECATED).", NULL},
278                 {"texts", "Text", "rna_Main_text_begin", "Texts", "Text datablocks.", RNA_def_main_texts},
279                 {"sounds", "Sound", "rna_Main_sound_begin", "Sounds", "Sound datablocks.", RNA_def_main_sounds},
280                 {"armatures", "Armature", "rna_Main_armature_begin", "Armatures", "Armature datablocks.", RNA_def_main_armatures},
281                 {"actions", "Action", "rna_Main_action_begin", "Actions", "Action datablocks.", RNA_def_main_actions},
282                 {"particles", "ParticleSettings", "rna_Main_particle_begin", "Particles", "Particle datablocks.", RNA_def_main_particles},
283                 {"gpencil", "GreasePencil", "rna_Main_gpencil_begin", "Grease Pencil", "Grease Pencil datablocks.", RNA_def_main_gpencil},
284                 {NULL, NULL, NULL, NULL, NULL, NULL}};
285
286         int i;
287         
288         srna= RNA_def_struct(brna, "Main", NULL);
289         RNA_def_struct_ui_text(srna, "Main", "Main data structure representing a .blend file and all its datablocks");
290         RNA_def_struct_ui_icon(srna, ICON_BLENDER);
291
292         prop= RNA_def_property(srna, "filename", PROP_STRING, PROP_FILEPATH);
293         RNA_def_property_string_maxlength(prop, 240);
294         RNA_def_property_string_funcs(prop, "rna_Main_filename_get", "rna_Main_filename_length", "rna_Main_filename_set");
295         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
296         RNA_def_property_ui_text(prop, "Filename", "Path to the .blend file");
297
298         for(i=0; lists[i].name; i++)
299         {
300                 prop= RNA_def_property(srna, lists[i].identifier, PROP_COLLECTION, PROP_NONE);
301                 RNA_def_property_struct_type(prop, lists[i].type);
302                 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);
303                 RNA_def_property_ui_text(prop, lists[i].name, lists[i].description);
304
305                 /* collection functions */
306                 func= lists[i].func;
307                 if(func)
308                         func(brna, prop);
309         }
310
311         RNA_api_main(srna);
312
313 #ifdef UNIT_TEST
314
315         RNA_define_verify_sdna(0);
316
317         prop= RNA_def_property(srna, "test", PROP_POINTER, PROP_NONE);
318         RNA_def_property_struct_type(prop, "Test");
319         RNA_def_property_pointer_funcs(prop, "rna_Test_test_get", NULL, NULL);
320
321         RNA_define_verify_sdna(1);
322
323 #endif
324 }
325
326 #endif
327