Blender  V2.59
rna_main.c
Go to the documentation of this file.
00001 /*
00002  * $Id: rna_main.c 37031 2011-05-31 02:14:25Z campbellbarton $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * Contributor(s): Blender Foundation (2008).
00021  *
00022  * ***** END GPL LICENSE BLOCK *****
00023  */
00024 
00030 #include <stdlib.h>
00031 #include <string.h>
00032 
00033 #include "RNA_define.h"
00034 
00035 #include "rna_internal.h"
00036 
00037 #ifdef RNA_RUNTIME
00038 
00039 #include "BKE_main.h"
00040 #include "BKE_mesh.h"
00041 #include "BKE_global.h"
00042 
00043 /* all the list begin functions are added manually here, Main is not in SDNA */
00044 
00045 static int rna_Main_is_saved_get(PointerRNA *UNUSED(ptr))
00046 {
00047         return G.relbase_valid;
00048 }
00049 
00050 static int rna_Main_is_dirty_get(PointerRNA *ptr)
00051 {
00052         /* XXX, not totally nice to do it this way, should store in main ? */
00053         Main *bmain= (Main*)ptr->data;
00054         wmWindowManager *wm;
00055         for(wm= bmain->wm.first; wm; wm= wm->id.next) {
00056                 return !wm->file_saved;
00057         }
00058 
00059         return TRUE;
00060 }
00061 
00062 static void rna_Main_filepath_get(PointerRNA *ptr, char *value)
00063 {
00064         Main *bmain= (Main*)ptr->data;
00065         BLI_strncpy(value, bmain->name, sizeof(bmain->name));
00066 }
00067 
00068 static int rna_Main_filepath_length(PointerRNA *ptr)
00069 {
00070         Main *bmain= (Main*)ptr->data;
00071         return strlen(bmain->name);
00072 }
00073 
00074 #if 0
00075 static void rna_Main_filepath_set(PointerRNA *ptr, const char *value)
00076 {
00077         Main *bmain= (Main*)ptr->data;
00078         BLI_strncpy(bmain->name, value, sizeof(bmain->name));
00079 }
00080 #endif
00081 
00082 static void rna_Main_scene_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00083 {
00084         Main *bmain= (Main*)ptr->data;
00085         rna_iterator_listbase_begin(iter, &bmain->scene, NULL);
00086 }
00087 
00088 static void rna_Main_object_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00089 {
00090         Main *bmain= (Main*)ptr->data;
00091         rna_iterator_listbase_begin(iter, &bmain->object, NULL);
00092 }
00093 
00094 static void rna_Main_lamp_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00095 {
00096         Main *bmain= (Main*)ptr->data;
00097         rna_iterator_listbase_begin(iter, &bmain->lamp, NULL);
00098 }
00099 
00100 static void rna_Main_library_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00101 {
00102         Main *bmain= (Main*)ptr->data;
00103         rna_iterator_listbase_begin(iter, &bmain->library, NULL);
00104 }
00105 
00106 static void rna_Main_mesh_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00107 {
00108         Main *bmain= (Main*)ptr->data;
00109         rna_iterator_listbase_begin(iter, &bmain->mesh, NULL);
00110 }
00111 
00112 static void rna_Main_curve_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00113 {
00114         Main *bmain= (Main*)ptr->data;
00115         rna_iterator_listbase_begin(iter, &bmain->curve, NULL);
00116 }
00117 
00118 static void rna_Main_mball_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00119 {
00120         Main *bmain= (Main*)ptr->data;
00121         rna_iterator_listbase_begin(iter, &bmain->mball, NULL);
00122 }
00123 
00124 static void rna_Main_mat_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00125 {
00126         Main *bmain= (Main*)ptr->data;
00127         rna_iterator_listbase_begin(iter, &bmain->mat, NULL);
00128 }
00129 
00130 static void rna_Main_tex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00131 {
00132         Main *bmain= (Main*)ptr->data;
00133         rna_iterator_listbase_begin(iter, &bmain->tex, NULL);
00134 }
00135 
00136 static void rna_Main_image_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00137 {
00138         Main *bmain= (Main*)ptr->data;
00139         rna_iterator_listbase_begin(iter, &bmain->image, NULL);
00140 }
00141 
00142 static void rna_Main_latt_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00143 {
00144         Main *bmain= (Main*)ptr->data;
00145         rna_iterator_listbase_begin(iter, &bmain->latt, NULL);
00146 }
00147 
00148 static void rna_Main_camera_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00149 {
00150         Main *bmain= (Main*)ptr->data;
00151         rna_iterator_listbase_begin(iter, &bmain->camera, NULL);
00152 }
00153 
00154 static void rna_Main_key_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00155 {
00156         Main *bmain= (Main*)ptr->data;
00157         rna_iterator_listbase_begin(iter, &bmain->key, NULL);
00158 }
00159 
00160 static void rna_Main_world_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00161 {
00162         Main *bmain= (Main*)ptr->data;
00163         rna_iterator_listbase_begin(iter, &bmain->world, NULL);
00164 }
00165 
00166 static void rna_Main_screen_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00167 {
00168         Main *bmain= (Main*)ptr->data;
00169         rna_iterator_listbase_begin(iter, &bmain->screen, NULL);
00170 }
00171 
00172 static void rna_Main_script_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00173 {
00174         Main *bmain= (Main*)ptr->data;
00175         rna_iterator_listbase_begin(iter, &bmain->script, NULL);
00176 }
00177 
00178 static void rna_Main_font_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00179 {
00180         Main *bmain= (Main*)ptr->data;
00181         rna_iterator_listbase_begin(iter, &bmain->vfont, NULL);
00182 }
00183 
00184 static void rna_Main_text_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00185 {
00186         Main *bmain= (Main*)ptr->data;
00187         rna_iterator_listbase_begin(iter, &bmain->text, NULL);
00188 }
00189 
00190 static void rna_Main_sound_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00191 {
00192         Main *bmain= (Main*)ptr->data;
00193         rna_iterator_listbase_begin(iter, &bmain->sound, NULL);
00194 }
00195 
00196 static void rna_Main_group_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00197 {
00198         Main *bmain= (Main*)ptr->data;
00199         rna_iterator_listbase_begin(iter, &bmain->group, NULL);
00200 }
00201 
00202 static void rna_Main_armature_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00203 {
00204         Main *bmain= (Main*)ptr->data;
00205         rna_iterator_listbase_begin(iter, &bmain->armature, NULL);
00206 }
00207 
00208 static void rna_Main_action_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00209 {
00210         Main *bmain= (Main*)ptr->data;
00211         rna_iterator_listbase_begin(iter, &bmain->action, NULL);
00212 }
00213 
00214 static void rna_Main_nodetree_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00215 {
00216         Main *bmain= (Main*)ptr->data;
00217         rna_iterator_listbase_begin(iter, &bmain->nodetree, NULL);
00218 }
00219 
00220 static void rna_Main_brush_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00221 {
00222         Main *bmain= (Main*)ptr->data;
00223         rna_iterator_listbase_begin(iter, &bmain->brush, NULL);
00224 }
00225 
00226 static void rna_Main_particle_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00227 {
00228         Main *bmain= (Main*)ptr->data;
00229         rna_iterator_listbase_begin(iter, &bmain->particle, NULL);
00230 }
00231 
00232 static void rna_Main_gpencil_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00233 {
00234         Main *bmain= (Main*)ptr->data;
00235         rna_iterator_listbase_begin(iter, &bmain->gpencil, NULL);
00236 }
00237 
00238 static void rna_Main_wm_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
00239 {
00240         Main *bmain= (Main*)ptr->data;
00241         rna_iterator_listbase_begin(iter, &bmain->wm, NULL);
00242 }
00243 
00244 #ifdef UNIT_TEST
00245 
00246 static PointerRNA rna_Test_test_get(PointerRNA *ptr)
00247 {
00248         PointerRNA ret= *ptr;
00249         ret.type= &RNA_Test;
00250 
00251         return ret;
00252 }
00253 
00254 #endif
00255 
00256 #else
00257 
00258 /* local convenience types */
00259 typedef void (CollectionDefFunc)(struct BlenderRNA *brna, struct PropertyRNA *cprop);
00260 
00261 typedef struct MainCollectionDef {
00262         const char      *identifier;
00263         const char      *type;
00264         const char      *iter_begin;
00265         const char      *name;
00266         const char      *description;
00267         CollectionDefFunc *func;
00268 } MainCollectionDef;
00269 
00270 void RNA_def_main(BlenderRNA *brna)
00271 {
00272         StructRNA *srna;
00273         PropertyRNA *prop;
00274         CollectionDefFunc *func;
00275 
00276         /* plural must match idtypes in readblenentry.c */
00277         MainCollectionDef lists[]= {
00278                 {"cameras", "Camera", "rna_Main_camera_begin", "Cameras", "Camera datablocks.", RNA_def_main_cameras},
00279                 {"scenes", "Scene", "rna_Main_scene_begin", "Scenes", "Scene datablocks.", RNA_def_main_scenes},
00280                 {"objects", "Object", "rna_Main_object_begin", "Objects", "Object datablocks.", RNA_def_main_objects},
00281                 {"materials", "Material", "rna_Main_mat_begin", "Materials", "Material datablocks.", RNA_def_main_materials},
00282                 {"node_groups", "NodeTree", "rna_Main_nodetree_begin", "Node Groups", "Node group datablocks.", RNA_def_main_node_groups},
00283                 {"meshes", "Mesh", "rna_Main_mesh_begin", "Meshes", "Mesh datablocks.", RNA_def_main_meshes},
00284                 {"lamps", "Lamp", "rna_Main_lamp_begin", "Lamps", "Lamp datablocks.", RNA_def_main_lamps},
00285                 {"libraries", "Library", "rna_Main_library_begin", "Libraries", "Library datablocks.", RNA_def_main_libraries},
00286                 {"screens", "Screen", "rna_Main_screen_begin", "Screens", "Screen datablocks.", RNA_def_main_screens},
00287                 {"window_managers", "WindowManager", "rna_Main_wm_begin", "Window Managers", "Window manager datablocks.", RNA_def_main_window_managers},
00288                 {"images", "Image", "rna_Main_image_begin", "Images", "Image datablocks.", RNA_def_main_images},
00289                 {"lattices", "Lattice", "rna_Main_latt_begin", "Lattices", "Lattice datablocks.", RNA_def_main_lattices},
00290                 {"curves", "Curve", "rna_Main_curve_begin", "Curves", "Curve datablocks.", RNA_def_main_curves} ,
00291                 {"metaballs", "MetaBall", "rna_Main_mball_begin", "Metaballs", "Metaball datablocks.", RNA_def_main_metaballs},
00292                 {"fonts", "VectorFont", "rna_Main_font_begin", "Vector Fonts", "Vector font datablocks.", RNA_def_main_fonts},
00293                 {"textures", "Texture", "rna_Main_tex_begin", "Textures", "Texture datablocks.", RNA_def_main_textures},
00294                 {"brushes", "Brush", "rna_Main_brush_begin", "Brushes", "Brush datablocks.", RNA_def_main_brushes},
00295                 {"worlds", "World", "rna_Main_world_begin", "Worlds", "World datablocks.", RNA_def_main_worlds},
00296                 {"groups", "Group", "rna_Main_group_begin", "Groups", "Group datablocks.", RNA_def_main_groups},
00297                 {"shape_keys", "Key", "rna_Main_key_begin", "Shape Keys", "Shape Key datablocks.", NULL},
00298                 {"scripts", "ID", "rna_Main_script_begin", "Scripts", "Script datablocks (DEPRECATED).", NULL},
00299                 {"texts", "Text", "rna_Main_text_begin", "Texts", "Text datablocks.", RNA_def_main_texts},
00300                 {"sounds", "Sound", "rna_Main_sound_begin", "Sounds", "Sound datablocks.", RNA_def_main_sounds},
00301                 {"armatures", "Armature", "rna_Main_armature_begin", "Armatures", "Armature datablocks.", RNA_def_main_armatures},
00302                 {"actions", "Action", "rna_Main_action_begin", "Actions", "Action datablocks.", RNA_def_main_actions},
00303                 {"particles", "ParticleSettings", "rna_Main_particle_begin", "Particles", "Particle datablocks.", RNA_def_main_particles},
00304                 {"grease_pencil", "GreasePencil", "rna_Main_gpencil_begin", "Grease Pencil", "Grease Pencil datablocks.", RNA_def_main_gpencil},
00305                 {NULL, NULL, NULL, NULL, NULL, NULL}};
00306 
00307         int i;
00308         
00309         srna= RNA_def_struct(brna, "BlendData", NULL);
00310         RNA_def_struct_ui_text(srna, "Blendfile Data", "Main data structure representing a .blend file and all its datablocks");
00311         RNA_def_struct_ui_icon(srna, ICON_BLENDER);
00312 
00313         prop= RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
00314         RNA_def_property_string_maxlength(prop, 240);
00315         RNA_def_property_string_funcs(prop, "rna_Main_filepath_get", "rna_Main_filepath_length", "rna_Main_filepath_set");
00316         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00317         RNA_def_property_ui_text(prop, "Filename", "Path to the .blend file");
00318         
00319         prop= RNA_def_property(srna, "is_dirty", PROP_BOOLEAN, PROP_NONE);
00320         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00321         RNA_def_property_boolean_funcs(prop, "rna_Main_is_dirty_get", NULL);
00322         RNA_def_property_ui_text(prop, "File is Saved", "Have recent edits been saved to disk");
00323 
00324         prop= RNA_def_property(srna, "is_saved", PROP_BOOLEAN, PROP_NONE);
00325         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
00326         RNA_def_property_boolean_funcs(prop, "rna_Main_is_saved_get", NULL);
00327         RNA_def_property_ui_text(prop, "File is Saved", "Has the current session been saved to disk as a .blend file");
00328 
00329         for(i=0; lists[i].name; i++)
00330         {
00331                 prop= RNA_def_property(srna, lists[i].identifier, PROP_COLLECTION, PROP_NONE);
00332                 RNA_def_property_struct_type(prop, lists[i].type);
00333                 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);
00334                 RNA_def_property_ui_text(prop, lists[i].name, lists[i].description);
00335 
00336                 /* collection functions */
00337                 func= lists[i].func;
00338                 if(func)
00339                         func(brna, prop);
00340         }
00341 
00342         RNA_api_main(srna);
00343 
00344 #ifdef UNIT_TEST
00345 
00346         RNA_define_verify_sdna(0);
00347 
00348         prop= RNA_def_property(srna, "test", PROP_POINTER, PROP_NONE);
00349         RNA_def_property_struct_type(prop, "Test");
00350         RNA_def_property_pointer_funcs(prop, "rna_Test_test_get", NULL, NULL, NULL);
00351 
00352         RNA_define_verify_sdna(1);
00353 
00354 #endif
00355 }
00356 
00357 #endif
00358