diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-01-10 02:44:01 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-01-10 02:44:01 +0300 |
commit | 08c9ecb3b043322f34e55f335f76dc2657c187ef (patch) | |
tree | 8dc0954f4bd0ca83c76afa407aa7b5ffb1e9de38 /source/blender/makesrna/intern | |
parent | 99b713e8b0fc7a395515c32616b47b8209dcd0c2 (diff) |
RNA/Py API
change how data is added. eg.
bpy.data.add_mesh(name) --> bpy.data.meshes.new(name)
bpy.data.remove_lamp(lamp) --> bpy.data.lamps.remove(lamp)
image and texture stil use add_* funcs
Diffstat (limited to 'source/blender/makesrna/intern')
-rw-r--r-- | source/blender/makesrna/intern/rna_internal.h | 27 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_main.c | 67 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_main_api.c | 435 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 21 |
4 files changed, 418 insertions, 132 deletions
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index b154647e10e..3d18804036a 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -231,6 +231,33 @@ void RNA_api_text(struct StructRNA *srna); void RNA_api_ui_layout(struct StructRNA *srna); void RNA_api_wm(struct StructRNA *srna); +/* main collection functions */ +void RNA_def_main_cameras(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_scenes(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_objects(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_materials(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_node_groups(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_meshes(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_lamps(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_libraries(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_screens(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_window_managers(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_images(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_lattices(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_curves(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_metaballs(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_vfonts(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_textures(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_brushes(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_worlds(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_groups(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_texts(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_sounds(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_armatures(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_actions(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_particles(BlenderRNA *brna, PropertyRNA *cprop); +void RNA_def_main_gpencil(BlenderRNA *brna, PropertyRNA *cprop); + /* ID Properties */ extern StringPropertyRNA rna_IDProperty_string; diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c index 82988a06af9..4b5a404b268 100644 --- a/source/blender/makesrna/intern/rna_main.c +++ b/source/blender/makesrna/intern/rna_main.c @@ -235,40 +235,44 @@ static PointerRNA rna_Test_test_get(PointerRNA *ptr) #else +typedef void (*CollectionDefFunc)(struct BlenderRNA *brna, struct PropertyRNA *cprop); + void RNA_def_main(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; + CollectionDefFunc func; + + const char *lists[][6]= { + {"cameras", "Camera", "rna_Main_camera_begin", "Cameras", "Camera datablocks.", (char *)RNA_def_main_cameras}, + {"scenes", "Scene", "rna_Main_scene_begin", "Scenes", "Scene datablocks.", (char *)RNA_def_main_scenes}, + {"objects", "Object", "rna_Main_object_begin", "Objects", "Object datablocks.", (char *)RNA_def_main_objects}, + {"materials", "Material", "rna_Main_mat_begin", "Materials", "Material datablocks.", (char *)RNA_def_main_materials}, + {"node_groups", "NodeTree", "rna_Main_nodetree_begin", "Node Groups", "Node group datablocks.", (char *)RNA_def_main_node_groups}, + {"meshes", "Mesh", "rna_Main_mesh_begin", "Meshes", "Mesh datablocks.", (char *)RNA_def_main_meshes}, + {"lamps", "Lamp", "rna_Main_lamp_begin", "Lamps", "Lamp datablocks.", (char *)RNA_def_main_lamps}, + {"libraries", "Library", "rna_Main_library_begin", "Libraries", "Library datablocks.", (char *)RNA_def_main_libraries}, + {"screens", "Screen", "rna_Main_screen_begin", "Screens", "Screen datablocks.", (char *)RNA_def_main_screens}, + {"window_managers", "WindowManager", "rna_Main_wm_begin", "Window Managers", "Window manager datablocks.", (char *)RNA_def_main_window_managers}, + {"images", "Image", "rna_Main_image_begin", "Images", "Image datablocks.", (char *)RNA_def_main_images}, + {"lattices", "Lattice", "rna_Main_latt_begin", "Lattices", "Lattice datablocks.", (char *)RNA_def_main_lattices}, + {"curves", "Curve", "rna_Main_curve_begin", "Curves", "Curve datablocks.", (char *)RNA_def_main_curves} , + {"metaballs", "MetaBall", "rna_Main_mball_begin", "Metaballs", "Metaball datablocks.", (char *)RNA_def_main_metaballs}, + {"vfonts", "VectorFont", "rna_Main_vfont_begin", "Vector Fonts", "Vector font datablocks.", (char *)RNA_def_main_vfonts}, + {"textures", "Texture", "rna_Main_tex_begin", "Textures", "Texture datablocks.", (char *)RNA_def_main_textures}, + {"brushes", "Brush", "rna_Main_brush_begin", "Brushes", "Brush datablocks.", (char *)RNA_def_main_brushes}, + {"worlds", "World", "rna_Main_world_begin", "Worlds", "World datablocks.", (char *)RNA_def_main_worlds}, + {"groups", "Group", "rna_Main_group_begin", "Groups", "Group datablocks.", (char *)RNA_def_main_groups}, +/* {"keys", "Key", "rna_Main_key_begin", "Keys", "Key datablocks.", NULL}, */ + {"scripts", "ID", "rna_Main_script_begin", "Scripts", "Script datablocks (DEPRECATED).", (char *)NULL}, + {"texts", "Text", "rna_Main_text_begin", "Texts", "Text datablocks.", (char *)RNA_def_main_texts}, + {"sounds", "Sound", "rna_Main_sound_begin", "Sounds", "Sound datablocks.", (char *)RNA_def_main_sounds}, + {"armatures", "Armature", "rna_Main_armature_begin", "Armatures", "Armature datablocks.", (char *)RNA_def_main_armatures}, + {"actions", "Action", "rna_Main_action_begin", "Actions", "Action datablocks.", (char *)RNA_def_main_actions}, + {"particles", "ParticleSettings", "rna_Main_particle_begin", "Particles", "Particle datablocks.", (char *)RNA_def_main_particles}, + {"gpencil", "GreasePencil", "rna_Main_gpencil_begin", "Grease Pencil", "Grease Pencil datablocks.", (char *)RNA_def_main_gpencil}, + {NULL, NULL, NULL, NULL, NULL, NULL}}; - const char *lists[][5]= { - {"cameras", "Camera", "rna_Main_camera_begin", "Cameras", "Camera datablocks."}, - {"scenes", "Scene", "rna_Main_scene_begin", "Scenes", "Scene datablocks."}, - {"objects", "Object", "rna_Main_object_begin", "Objects", "Object datablocks."}, - {"materials", "Material", "rna_Main_mat_begin", "Materials", "Material datablocks."}, - {"nodegroups", "NodeTree", "rna_Main_nodetree_begin", "Node Groups", "Node group datablocks."}, - {"meshes", "Mesh", "rna_Main_mesh_begin", "Meshes", "Mesh datablocks."}, // "add_mesh", "remove_mesh" - {"lamps", "Lamp", "rna_Main_lamp_begin", "Lamps", "Lamp datablocks."}, - {"libraries", "Library", "rna_Main_library_begin", "Libraries", "Library datablocks."}, - {"screens", "Screen", "rna_Main_screen_begin", "Screens", "Screen datablocks."}, - {"windowmanagers", "WindowManager", "rna_Main_wm_begin", "Window Managers", "Window manager datablocks."}, - {"images", "Image", "rna_Main_image_begin", "Images", "Image datablocks."}, - {"lattices", "Lattice", "rna_Main_latt_begin", "Lattices", "Lattice datablocks."}, - {"curves", "Curve", "rna_Main_curve_begin", "Curves", "Curve datablocks."} , - {"metaballs", "MetaBall", "rna_Main_mball_begin", "Metaballs", "Metaball datablocks."}, - {"vfonts", "VectorFont", "rna_Main_vfont_begin", "Vector Fonts", "Vector font datablocks."}, - {"textures", "Texture", "rna_Main_tex_begin", "Textures", "Texture datablocks."}, - {"brushes", "Brush", "rna_Main_brush_begin", "Brushes", "Brush datablocks."}, - {"worlds", "World", "rna_Main_world_begin", "Worlds", "World datablocks."}, - {"groups", "Group", "rna_Main_group_begin", "Groups", "Group datablocks."}, -/* {"keys", "Key", "rna_Main_key_begin", "Keys", "Key datablocks."}, */ - {"scripts", "ID", "rna_Main_script_begin", "Scripts", "Script datablocks (DEPRECATED)."}, - {"texts", "Text", "rna_Main_text_begin", "Texts", "Text datablocks."}, - {"sounds", "Sound", "rna_Main_sound_begin", "Sounds", "Sound datablocks."}, - {"armatures", "Armature", "rna_Main_armature_begin", "Armatures", "Armature datablocks."}, - {"actions", "Action", "rna_Main_action_begin", "Actions", "Action datablocks."}, - {"particles", "ParticleSettings", "rna_Main_particle_begin", "Particles", "Particle datablocks."}, - {"gpencil", "GreasePencil", "rna_Main_gpencil_begin", "Grease Pencil", "Grease Pencil datablocks."}, - {NULL, NULL, NULL, NULL, NULL}}; int i; srna= RNA_def_struct(brna, "Main", NULL); @@ -287,6 +291,11 @@ void RNA_def_main(BlenderRNA *brna) RNA_def_property_struct_type(prop, lists[i][1]); RNA_def_property_collection_funcs(prop, lists[i][2], "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0); RNA_def_property_ui_text(prop, lists[i][3], lists[i][4]); + + /* collection functions */ + func= (CollectionDefFunc *)lists[i][5]; + if(func) + func(brna, prop); } RNA_api_main(srna); diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index 5069bbd6ae6..ecaf6f813da 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -43,108 +43,143 @@ #include "BKE_material.h" #include "BKE_image.h" #include "BKE_texture.h" +#include "BKE_scene.h" #include "DNA_armature_types.h" +#include "DNA_camera_types.h" #include "DNA_lamp_types.h" #include "DNA_material_types.h" #include "DNA_mesh_types.h" #include "DNA_object_types.h" -static Mesh *rna_Main_add_mesh(Main *bmain, char *name) +static Tex *rna_Main_add_texture(Main *bmain, char *name) { - Mesh *me= add_mesh(name); - me->id.us--; - return me; + return add_texture(name); } -static void rna_Main_remove_mesh(Main *bmain, ReportList *reports, Mesh *me) +/* TODO: remove texture? */ + +static Image *rna_Main_add_image(Main *bmain, char *filename) { - if(me->id.us == 0) - free_libblock(&bmain->mesh, me); - else - BKE_report(reports, RPT_ERROR, "Mesh must have zero users to be removed."); - - /* XXX python now has invalid pointer? */ + return BKE_add_image_file(filename, 0); } -static void rna_Main_remove_armature(Main *bmain, ReportList *reports, bArmature *arm) +static Camera *rna_Main_cameras_new(bContext *C, char* name) { - if(arm->id.us == 0) - free_libblock(&bmain->armature, arm); + return add_camera(name); +} +static void rna_Main_cameras_remove(bContext *C, ReportList *reports, struct Camera *camera) +{ + Main *bmain= CTX_data_main(C); + if(camera->id.us == 0) + free_libblock(&bmain->camera, camera); else - BKE_report(reports, RPT_ERROR, "Armature must have zero users to be removed."); + BKE_reportf(reports, RPT_ERROR, "Camera \"%s\" must have zero users to be removed, found %d.", camera->id.name+2, camera->id.us); /* XXX python now has invalid pointer? */ } -static bArmature *rna_Main_add_armature(Main *bmain, char *name) +static Scene *rna_Main_scenes_new(bContext *C, char* name) { - bArmature *arm= add_armature(name); - arm->id.us--; - return arm; -} - -static Lamp *rna_Main_add_lamp(Main *bmain, char *name) -{ - Lamp *la= add_lamp(name); - la->id.us--; - return la; + return add_scene(name); } - -/* -static void rna_Main_remove_lamp(Main *bmain, ReportList *reports, Lamp *la) +static void rna_Main_scenes_remove(bContext *C, ReportList *reports, struct Scene *scene) { - if(la->id.us == 0) - free_libblock(&main->lamp, la); - else - BKE_report(reports, RPT_ERROR, "Lamp must have zero users to be removed."); + Main *bmain= CTX_data_main(C); + free_libblock(&bmain->scene, scene); } -*/ -static Object* rna_Main_add_object(Main *bmain, int type, char *name) +static Object *rna_Main_objects_new(bContext *C, char* name, int type) { Object *ob= add_only_object(type, name); ob->id.us--; return ob; } +static void rna_Main_objects_remove(bContext *C, ReportList *reports, struct Object *object) +{ + /* + NOTE: the following example shows when this function should _not_ be called -/* - NOTE: the following example shows when this function should _not_ be called + ob = bpy.data.add_object() + scene.add_object(ob) - ob = bpy.data.add_object() - scene.add_object(ob) + # ob is freed here + scene.remove_object(ob) - # ob is freed here - scene.remove_object(ob) + # don't do this since ob is already freed! + bpy.data.remove_object(ob) + */ + Main *bmain= CTX_data_main(C); + if(object->id.us == 0) + free_libblock(&bmain->object, object); + else + BKE_reportf(reports, RPT_ERROR, "Object \"%s\" must have zero users to be removed, found %d.", object->id.name+2, object->id.us); +} - # don't do this since ob is already freed! - bpy.data.remove_object(ob) -*/ -static void rna_Main_remove_object(Main *bmain, ReportList *reports, Object *ob) +static Material *rna_Main_materials_new(bContext *C, char* name) { - if(ob->id.us == 0) - free_libblock(&bmain->object, ob); + return add_material(name); +} +static void rna_Main_materials_remove(bContext *C, ReportList *reports, struct Material *material) +{ + Main *bmain= CTX_data_main(C); + if(material->id.us == 0) + free_libblock(&bmain->mat, material); else - BKE_report(reports, RPT_ERROR, "Object must have zero users to be removed."); + BKE_reportf(reports, RPT_ERROR, "Material \"%s\" must have zero users to be removed, found %d.", material->id.name+2, material->id.us); + + /* XXX python now has invalid pointer? */ } -static Material *rna_Main_add_material(Main *bmain, char *name) +static Mesh *rna_Main_meshes_new(bContext *C, char* name) { - return add_material(name); + Mesh *me= add_mesh(name); + me->id.us--; + return me; } +static void rna_Main_meshes_remove(bContext *C, ReportList *reports, Mesh *mesh) +{ + Main *bmain= CTX_data_main(C); + if(mesh->id.us == 0) + free_libblock(&bmain->mesh, mesh); + else + BKE_reportf(reports, RPT_ERROR, "Mesh \"%s\" must have zero users to be removed, found %d.", mesh->id.name+2, mesh->id.us); -/* TODO: remove material? */ + /* XXX python now has invalid pointer? */ +} -struct Tex *rna_Main_add_texture(Main *bmain, char *name) +static Lamp *rna_Main_lamps_new(bContext *C, char* name) { - return add_texture(name); + Lamp *lamp= add_lamp(name); + lamp->id.us--; + return lamp; } +static void rna_Main_lamps_remove(bContext *C, ReportList *reports, Lamp *lamp) +{ + Main *bmain= CTX_data_main(C); + if(lamp->id.us == 0) + free_libblock(&bmain->lamp, lamp); + else + BKE_reportf(reports, RPT_ERROR, "Lamp \"%s\" must have zero users to be removed, found %d.", lamp->id.name+2, lamp->id.us); -/* TODO: remove texture? */ + /* XXX python now has invalid pointer? */ +} -struct Image *rna_Main_add_image(Main *bmain, char *filename) +static bArmature *rna_Main_armatures_new(bContext *C, char* name) { - return BKE_add_image_file(filename, 0); + bArmature *arm= add_armature(name); + arm->id.us--; + return arm; +} +static void rna_Main_armatures_remove(bContext *C, ReportList *reports, bArmature *arm) +{ + Main *bmain= CTX_data_main(C); + if(arm->id.us == 0) + free_libblock(&bmain->armature, arm); + else + BKE_reportf(reports, RPT_ERROR, "Armature \"%s\" must have zero users to be removed, found %d.", arm->id.name+2, arm->id.us); + + /* XXX python now has invalid pointer? */ } #else @@ -154,73 +189,281 @@ void RNA_api_main(StructRNA *srna) FunctionRNA *func; PropertyRNA *parm; - func= RNA_def_function(srna, "add_object", "rna_Main_add_object"); - RNA_def_function_ui_description(func, "Add a new object."); - parm= RNA_def_enum(func, "type", object_type_items, 0, "", "Type of Object."); + func= RNA_def_function(srna, "add_texture", "rna_Main_add_texture"); + RNA_def_function_ui_description(func, "Add a new texture."); + parm= RNA_def_string(func, "name", "Tex", 0, "", "New name for the datablock."); /* optional */ + parm= RNA_def_pointer(func, "texture", "Texture", "", "New texture."); + RNA_def_function_return(func, parm); + + func= RNA_def_function(srna, "add_image", "rna_Main_add_image"); + RNA_def_function_ui_description(func, "Add a new image."); + parm= RNA_def_string(func, "filename", "", 0, "", "Filename to load image from."); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm= RNA_def_pointer(func, "image", "Image", "", "New image."); + RNA_def_function_return(func, parm); + +} + +void RNA_def_main_cameras(BlenderRNA *brna, PropertyRNA *cprop) +{ + StructRNA *srna; + FunctionRNA *func; + PropertyRNA *parm; + + RNA_def_property_srna(cprop, "MainCameras"); + srna= RNA_def_struct(brna, "MainCameras", NULL); + RNA_def_struct_sdna(srna, "Camera"); + RNA_def_struct_ui_text(srna, "Main Cameras", "Collection of cameras."); + + func= RNA_def_function(srna, "new", "rna_Main_cameras_new"); + RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Add a new camera to the main database"); + parm= RNA_def_string(func, "name", "Camera", 0, "", "New name for the datablock."); + RNA_def_property_flag(parm, PROP_REQUIRED); + /* return type */ + parm= RNA_def_pointer(func, "camera", "Camera", "", "New camera datablock."); + RNA_def_function_return(func, parm); + + func= RNA_def_function(srna, "remove", "rna_Main_cameras_remove"); + RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT|FUNC_USE_REPORTS); + RNA_def_function_ui_description(func, "Remove a camera from the current blendfile."); + parm= RNA_def_pointer(func, "camera", "Camera", "", "Camera to remove."); + RNA_def_property_flag(parm, PROP_REQUIRED); +} + +void RNA_def_main_scenes(BlenderRNA *brna, PropertyRNA *cprop) +{ + StructRNA *srna; + FunctionRNA *func; + PropertyRNA *parm; + + RNA_def_property_srna(cprop, "MainScenes"); + srna= RNA_def_struct(brna, "MainScenes", NULL); + RNA_def_struct_sdna(srna, "Scene"); + RNA_def_struct_ui_text(srna, "Main Scenes", "Collection of scenes."); + + func= RNA_def_function(srna, "new", "rna_Main_scenes_new"); + RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Add a new scene to the main database"); + parm= RNA_def_string(func, "name", "Scene", 0, "", "New name for the datablock."); + RNA_def_property_flag(parm, PROP_REQUIRED); + /* return type */ + parm= RNA_def_pointer(func, "scene", "Scene", "", "New scene datablock."); + RNA_def_function_return(func, parm); + + func= RNA_def_function(srna, "remove", "rna_Main_scenes_remove"); + RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT|FUNC_USE_REPORTS); + parm= RNA_def_pointer(func, "scene", "Scene", "", "Scene to remove."); + RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_function_ui_description(func, "Remove a scene from the current blendfile."); RNA_def_property_flag(parm, PROP_REQUIRED); +} + +void RNA_def_main_objects(BlenderRNA *brna, PropertyRNA *cprop) +{ + StructRNA *srna; + FunctionRNA *func; + PropertyRNA *parm; + + RNA_def_property_srna(cprop, "MainObjects"); + srna= RNA_def_struct(brna, "MainObjects", NULL); + RNA_def_struct_sdna(srna, "Object"); + RNA_def_struct_ui_text(srna, "Main Objects", "Collection of objects."); + + func= RNA_def_function(srna, "new", "rna_Main_objects_new"); + RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Add a new object to the main database"); parm= RNA_def_string(func, "name", "Object", 0, "", "New name for the datablock."); RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_pointer(func, "object", "Object", "", "New object."); + parm= RNA_def_enum(func, "type", object_type_items, 0, "", "Type of Object."); + RNA_def_property_flag(parm, PROP_REQUIRED); + + /* return type */ + parm= RNA_def_pointer(func, "object", "Object", "", "New object datablock."); RNA_def_function_return(func, parm); - func= RNA_def_function(srna, "remove_object", "rna_Main_remove_object"); - RNA_def_function_flag(func, FUNC_USE_REPORTS); - RNA_def_function_ui_description(func, "Remove an object if it has zero users."); + func= RNA_def_function(srna, "remove", "rna_Main_objects_remove"); + RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT|FUNC_USE_REPORTS); parm= RNA_def_pointer(func, "object", "Object", "", "Object to remove."); RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_function_ui_description(func, "Remove a object from the current blendfile."); +} - func= RNA_def_function(srna, "add_mesh", "rna_Main_add_mesh"); - RNA_def_function_ui_description(func, "Add a new mesh."); - parm= RNA_def_string(func, "name", "Mesh", 0, "", "New name for the datablock."); +void RNA_def_main_materials(BlenderRNA *brna, PropertyRNA *cprop) +{ + StructRNA *srna; + FunctionRNA *func; + PropertyRNA *parm; + + RNA_def_property_srna(cprop, "MainMaterials"); + srna= RNA_def_struct(brna, "MainMaterials", NULL); + RNA_def_struct_sdna(srna, "Material"); + RNA_def_struct_ui_text(srna, "Main Material", "Collection of materials."); + + func= RNA_def_function(srna, "new", "rna_Main_materials_new"); + RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Add a new material to the main database"); + parm= RNA_def_string(func, "name", "Material", 0, "", "New name for the datablock."); RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_pointer(func, "mesh", "Mesh", "", "New mesh."); + /* return type */ + parm= RNA_def_pointer(func, "material", "Material", "", "New material datablock."); RNA_def_function_return(func, parm); - func= RNA_def_function(srna, "remove_mesh", "rna_Main_remove_mesh"); - RNA_def_function_flag(func, FUNC_USE_REPORTS); - RNA_def_function_ui_description(func, "Remove a mesh if it has zero users."); - parm= RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh to remove."); + func= RNA_def_function(srna, "remove", "rna_Main_materials_remove"); + RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT|FUNC_USE_REPORTS); + RNA_def_function_ui_description(func, "Remove a material from the current blendfile."); + parm= RNA_def_pointer(func, "material", "Material", "", "Material to remove."); RNA_def_property_flag(parm, PROP_REQUIRED); +} +void RNA_def_main_node_groups(BlenderRNA *brna, PropertyRNA *cprop) +{ - func= RNA_def_function(srna, "add_armature", "rna_Main_add_armature"); - RNA_def_function_ui_description(func, "Add a new armature."); - parm= RNA_def_string(func, "name", "Armature", 0, "", "New name for the datablock."); +} +void RNA_def_main_meshes(BlenderRNA *brna, PropertyRNA *cprop) +{ + StructRNA *srna; + FunctionRNA *func; + PropertyRNA *parm; + + RNA_def_property_srna(cprop, "MainMeshes"); + srna= RNA_def_struct(brna, "MainMeshes", NULL); + RNA_def_struct_sdna(srna, "Mesh"); + RNA_def_struct_ui_text(srna, "Main Meshes", "Collection of meshes."); + + func= RNA_def_function(srna, "new", "rna_Main_meshes_new"); + RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Add a new mesh to the main database"); + parm= RNA_def_string(func, "name", "Mesh", 0, "", "New name for the datablock."); RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_pointer(func, "armature", "Armature", "", "New armature."); + /* return type */ + parm= RNA_def_pointer(func, "mesh", "Mesh", "", "New mesh datablock."); RNA_def_function_return(func, parm); - func= RNA_def_function(srna, "remove_armature", "rna_Main_remove_armature"); - RNA_def_function_flag(func, FUNC_USE_REPORTS); - RNA_def_function_ui_description(func, "Remove an armature if it has zero users."); - parm= RNA_def_pointer(func, "armature", "Armature", "", "Armature to remove."); + func= RNA_def_function(srna, "remove", "rna_Main_meshes_remove"); + RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT|FUNC_USE_REPORTS); + RNA_def_function_ui_description(func, "Remove a mesh from the current blendfile."); + parm= RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh to remove."); RNA_def_property_flag(parm, PROP_REQUIRED); +} +void RNA_def_main_lamps(BlenderRNA *brna, PropertyRNA *cprop) +{ + StructRNA *srna; + FunctionRNA *func; + PropertyRNA *parm; + + RNA_def_property_srna(cprop, "MainLamps"); + srna= RNA_def_struct(brna, "MainLamps", NULL); + RNA_def_struct_sdna(srna, "Lamp"); + RNA_def_struct_ui_text(srna, "Main Lamps", "Collection of lamps."); - func= RNA_def_function(srna, "add_lamp", "rna_Main_add_lamp"); - RNA_def_function_ui_description(func, "Add a new lamp."); + func= RNA_def_function(srna, "new", "rna_Main_lamps_new"); + RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Add a new lamp to the main database"); parm= RNA_def_string(func, "name", "Lamp", 0, "", "New name for the datablock."); RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_pointer(func, "mesh", "Lamp", "", "New lamp."); + /* return type */ + parm= RNA_def_pointer(func, "lamp", "Lamp", "", "New lamp datablock."); RNA_def_function_return(func, parm); - func= RNA_def_function(srna, "add_material", "rna_Main_add_material"); - RNA_def_function_ui_description(func, "Add a new material."); - parm= RNA_def_string(func, "name", "Material", 0, "", "New name for the datablock."); /* optional */ - parm= RNA_def_pointer(func, "material", "Material", "", "New material."); - RNA_def_function_return(func, parm); + func= RNA_def_function(srna, "remove", "rna_Main_lamps_remove"); + RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT|FUNC_USE_REPORTS); + RNA_def_function_ui_description(func, "Remove a lamp from the current blendfile."); + parm= RNA_def_pointer(func, "lamp", "Lamp", "", "Lamp to remove."); + RNA_def_property_flag(parm, PROP_REQUIRED); +} +void RNA_def_main_libraries(BlenderRNA *brna, PropertyRNA *cprop) +{ - func= RNA_def_function(srna, "add_texture", "rna_Main_add_texture"); - RNA_def_function_ui_description(func, "Add a new texture."); - parm= RNA_def_string(func, "name", "Tex", 0, "", "New name for the datablock."); /* optional */ - parm= RNA_def_pointer(func, "texture", "Texture", "", "New texture."); - RNA_def_function_return(func, parm); +} +void RNA_def_main_screens(BlenderRNA *brna, PropertyRNA *cprop) +{ - func= RNA_def_function(srna, "add_image", "rna_Main_add_image"); - RNA_def_function_ui_description(func, "Add a new image."); - parm= RNA_def_string(func, "filename", "", 0, "", "Filename to load image from."); +} +void RNA_def_main_window_managers(BlenderRNA *brna, PropertyRNA *cprop) +{ + +} +void RNA_def_main_images(BlenderRNA *brna, PropertyRNA *cprop) +{ + +} +void RNA_def_main_lattices(BlenderRNA *brna, PropertyRNA *cprop) +{ + +} +void RNA_def_main_curves(BlenderRNA *brna, PropertyRNA *cprop) +{ + +} +void RNA_def_main_metaballs(BlenderRNA *brna, PropertyRNA *cprop) +{ + +} +void RNA_def_main_vfonts(BlenderRNA *brna, PropertyRNA *cprop) +{ + +} +void RNA_def_main_textures(BlenderRNA *brna, PropertyRNA *cprop) +{ + +} +void RNA_def_main_brushes(BlenderRNA *brna, PropertyRNA *cprop) +{ + +} +void RNA_def_main_worlds(BlenderRNA *brna, PropertyRNA *cprop) +{ + +} +void RNA_def_main_groups(BlenderRNA *brna, PropertyRNA *cprop) +{ + +} +void RNA_def_main_texts(BlenderRNA *brna, PropertyRNA *cprop) +{ + +} +void RNA_def_main_sounds(BlenderRNA *brna, PropertyRNA *cprop) +{ + +} +void RNA_def_main_armatures(BlenderRNA *brna, PropertyRNA *cprop) +{ + StructRNA *srna; + FunctionRNA *func; + PropertyRNA *parm; + + RNA_def_property_srna(cprop, "MainArmatures"); + srna= RNA_def_struct(brna, "MainArmatures", NULL); + RNA_def_struct_sdna(srna, "Armature"); + RNA_def_struct_ui_text(srna, "Main Armatures", "Collection of armatures."); + + func= RNA_def_function(srna, "new", "rna_Main_armatures_new"); + RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Add a new armature to the main database"); + parm= RNA_def_string(func, "name", "Armature", 0, "", "New name for the datablock."); RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_pointer(func, "image", "Image", "", "New image."); + /* return type */ + parm= RNA_def_pointer(func, "armature", "Armature", "", "New armature datablock."); RNA_def_function_return(func, parm); + func= RNA_def_function(srna, "remove", "rna_Main_armatures_remove"); + RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT|FUNC_USE_REPORTS); + RNA_def_function_ui_description(func, "Remove a armature from the current blendfile."); + parm= RNA_def_pointer(func, "armature", "Armature", "", "Armature to remove."); + RNA_def_property_flag(parm, PROP_REQUIRED); +} +void RNA_def_main_actions(BlenderRNA *brna, PropertyRNA *cprop) +{ + +} +void RNA_def_main_particles(BlenderRNA *brna, PropertyRNA *cprop) +{ + +} +void RNA_def_main_gpencil(BlenderRNA *brna, PropertyRNA *cprop) +{ + } #endif diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 72a5ac9a552..82c7de36eab 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -126,21 +126,28 @@ static PointerRNA rna_Scene_objects_get(CollectionPropertyIterator *iter) return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((Base*)internal->link)->object); } -static void rna_Scene_link_object(Scene *sce, ReportList *reports, Object *ob) +static void rna_Scene_link_object(Scene *scene, ReportList *reports, Object *ob) { - Base *base= object_in_scene(ob, sce); - if (base) { - BKE_report(reports, RPT_ERROR, "Object is already in this scene."); + Base *base; + + if (ob->type != OB_EMPTY && ob->data==NULL) { + BKE_reportf(reports, RPT_ERROR, "Object \"%s\" is not an Empty type and has no Object Data set."); return; } - base= scene_add_base(sce, ob); + + if (object_in_scene(ob, scene)) { + BKE_reportf(reports, RPT_ERROR, "Object \"%s\" is already in scene \"%s\".", ob->id.name+2, scene->id.name+2); + return; + } + + base= scene_add_base(scene, ob); ob->id.us++; /* this is similar to what object_add_type and add_object do */ - ob->lay= base->lay= sce->lay; + ob->lay= base->lay= scene->lay; ob->recalc |= OB_RECALC; - DAG_scene_sort(sce); + DAG_scene_sort(scene); } static void rna_Scene_unlink_object(Scene *sce, ReportList *reports, Object *ob) |