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/rna_main_api.c | |
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/rna_main_api.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_main_api.c | 435 |
1 files changed, 339 insertions, 96 deletions
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 |