diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-11-20 13:00:54 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-11-20 13:00:54 +0300 |
commit | 3119eaf2844e2e5f2be6da74ddd06f0fa0626f9e (patch) | |
tree | cb5aa6ee6ff8e44e6e0b68511967e236cf3a247f /source/blender/makesrna | |
parent | e7413bf791cfe1ede2bfbe5147e7b72b041c4ce8 (diff) |
- dir() now works for collection functions
- group.objects.link/unlink use exceptions rather then return values
- scene.add_object/remove_object --> scene.objects.link/unlink
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/intern/rna_group.c | 26 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 63 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_scene_api.c | 40 |
3 files changed, 54 insertions, 75 deletions
diff --git a/source/blender/makesrna/intern/rna_group.c b/source/blender/makesrna/intern/rna_group.c index 7cd0bac402a..a05485986d1 100644 --- a/source/blender/makesrna/intern/rna_group.c +++ b/source/blender/makesrna/intern/rna_group.c @@ -49,16 +49,24 @@ static PointerRNA rna_Group_objects_get(CollectionPropertyIterator *iter) return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((GroupObject*)internal->link)->ob); } -static int rna_Group_objects_link(Group *group, bContext *C, Object *object) +static void rna_Group_objects_link(Group *group, bContext *C, ReportList *reports, Object *object) { + if(!add_to_group(group, object, CTX_data_scene(C), NULL)) { + BKE_reportf(reports, RPT_ERROR, "Object \"%s\" already in group \"%s\".", object->id.name+2, group->id.name+2); + return; + } + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, &object->id); - return add_to_group(group, object, CTX_data_scene(C), NULL); } -static int rna_Group_objects_unlink(Group *group, bContext *C, Object *object) +static void rna_Group_objects_unlink(Group *group, bContext *C, ReportList *reports, Object *object) { + if(!rem_from_group(group, object, CTX_data_scene(C), NULL)) { + BKE_reportf(reports, RPT_ERROR, "Object \"%s\" not in group \"%s\".", object->id.name+2, group->id.name+2); + return; + } + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, &object->id); - return rem_from_group(group, object, CTX_data_scene(C), NULL); } #else @@ -79,11 +87,8 @@ static void rna_def_group_objects(BlenderRNA *brna, PropertyRNA *cprop) /* add object */ func= RNA_def_function(srna, "link", "rna_Group_objects_link"); - RNA_def_function_flag(func, FUNC_USE_CONTEXT); + RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Add this object to a group"); - /* return type */ - parm= RNA_def_boolean(func, "success", 0, "Success", ""); - RNA_def_function_return(func, parm); /* object to add */ parm= RNA_def_pointer(func, "object", "Object", "", "Object to add."); RNA_def_property_flag(parm, PROP_REQUIRED); @@ -91,10 +96,7 @@ static void rna_def_group_objects(BlenderRNA *brna, PropertyRNA *cprop) /* remove object */ func= RNA_def_function(srna, "unlink", "rna_Group_objects_unlink"); RNA_def_function_ui_description(func, "Remove this object to a group"); - RNA_def_function_flag(func, FUNC_USE_CONTEXT); - /* return type */ - parm= RNA_def_boolean(func, "success", 0, "Success", ""); - RNA_def_function_return(func, parm); + RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS); /* object to remove */ parm= RNA_def_pointer(func, "object", "Object", "", "Object to remove."); RNA_def_property_flag(parm, PROP_REQUIRED); diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index b9f5d64333f..64a9f8d521f 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -80,6 +80,7 @@ EnumPropertyItem proportional_editing_items[] = { #include "BKE_node.h" #include "BKE_pointcache.h" #include "BKE_scene.h" +#include "BKE_depsgraph.h" #include "BLI_threads.h" @@ -97,6 +98,34 @@ 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) +{ + Base *base= object_in_scene(ob, sce); + if (base) { + BKE_report(reports, RPT_ERROR, "Object is already in this scene."); + return; + } + base= scene_add_base(sce, ob); + ob->id.us++; + + /* this is similar to what object_add_type and add_object do */ + ob->lay= base->lay= sce->lay; + ob->recalc |= OB_RECALC; + + DAG_scene_sort(sce); +} + +static void rna_Scene_unlink_object(Scene *sce, ReportList *reports, Object *ob) +{ + Base *base= object_in_scene(ob, sce); + if (!base) { + BKE_report(reports, RPT_ERROR, "Object is not in this scene."); + return; + } + /* as long as ED_base_object_free_and_unlink calls free_libblock_us, we don't have to decrement ob->id.us */ + ED_base_object_free_and_unlink(sce, base); +} + static void rna_Scene_skgen_etch_template_set(PointerRNA *ptr, PointerRNA value) { ToolSettings *ts = (ToolSettings*)ptr->data; @@ -2176,37 +2205,25 @@ static void rna_def_scene_objects(BlenderRNA *brna, PropertyRNA *cprop) StructRNA *srna; PropertyRNA *prop; -// FunctionRNA *func; -// PropertyRNA *parm; + FunctionRNA *func; + PropertyRNA *parm; RNA_def_property_srna(cprop, "SceneObjects"); srna= RNA_def_struct(brna, "SceneObjects", NULL); - RNA_def_struct_sdna(srna, "Object"); + RNA_def_struct_sdna(srna, "Scene"); RNA_def_struct_ui_text(srna, "Scene Objects", "Collection of scene objects."); -#if 0 - /* add object */ - func= RNA_def_function(srna, "link", "rna_Scene_objects_link"); - RNA_def_function_flag(func, FUNC_USE_CONTEXT); - RNA_def_function_ui_description(func, "Add this object to this scene"); - /* return type */ - parm= RNA_def_boolean(func, "success", 0, "Success", ""); - RNA_def_function_return(func, parm); - /* object to add */ - parm= RNA_def_pointer(func, "object", "Object", "", "Object to add."); + func= RNA_def_function(srna, "link", "rna_Scene_link_object"); + RNA_def_function_ui_description(func, "Link object to scene."); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + parm= RNA_def_pointer(func, "object", "Object", "", "Object to add to scene."); RNA_def_property_flag(parm, PROP_REQUIRED); - /* remove object */ - func= RNA_def_function(srna, "unlink", "rna_Scene_objects_unlink"); - RNA_def_function_ui_description(func, "Remove this object to a scene"); - RNA_def_function_flag(func, FUNC_USE_CONTEXT); - /* return type */ - parm= RNA_def_boolean(func, "success", 0, "Success", ""); - RNA_def_function_return(func, parm); - /* object to remove */ - parm= RNA_def_pointer(func, "object", "Object", "", "Object to remove."); + func= RNA_def_function(srna, "unlink", "rna_Scene_unlink_object"); + RNA_def_function_ui_description(func, "Unlink object from scene."); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + parm= RNA_def_pointer(func, "object", "Object", "", "Object to remove from scene."); RNA_def_property_flag(parm, PROP_REQUIRED); -#endif prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "Object"); diff --git a/source/blender/makesrna/intern/rna_scene_api.c b/source/blender/makesrna/intern/rna_scene_api.c index 40f2db6d4a4..6b21f886712 100644 --- a/source/blender/makesrna/intern/rna_scene_api.c +++ b/source/blender/makesrna/intern/rna_scene_api.c @@ -47,34 +47,6 @@ #include "WM_api.h" -static void rna_Scene_add_object(Scene *sce, ReportList *reports, Object *ob) -{ - Base *base= object_in_scene(ob, sce); - if (base) { - BKE_report(reports, RPT_ERROR, "Object is already in this scene."); - return; - } - base= scene_add_base(sce, ob); - ob->id.us++; - - /* this is similar to what object_add_type and add_object do */ - ob->lay= base->lay= sce->lay; - ob->recalc |= OB_RECALC; - - DAG_scene_sort(sce); -} - -static void rna_Scene_remove_object(Scene *sce, ReportList *reports, Object *ob) -{ - Base *base= object_in_scene(ob, sce); - if (!base) { - BKE_report(reports, RPT_ERROR, "Object is not in this scene."); - return; - } - /* as long as ED_base_object_free_and_unlink calls free_libblock_us, we don't have to decrement ob->id.us */ - ED_base_object_free_and_unlink(sce, base); -} - static void rna_Scene_set_frame(Scene *sce, bContext *C, int frame) { sce->r.cfra= frame; @@ -118,18 +90,6 @@ void RNA_api_scene(StructRNA *srna) FunctionRNA *func; PropertyRNA *parm; - func= RNA_def_function(srna, "add_object", "rna_Scene_add_object"); - RNA_def_function_ui_description(func, "Add object to scene."); - RNA_def_function_flag(func, FUNC_USE_REPORTS); - parm= RNA_def_pointer(func, "object", "Object", "", "Object to add to scene."); - RNA_def_property_flag(parm, PROP_REQUIRED); - - func= RNA_def_function(srna, "remove_object", "rna_Scene_remove_object"); - RNA_def_function_ui_description(func, "Remove object from scene."); - RNA_def_function_flag(func, FUNC_USE_REPORTS); - parm= RNA_def_pointer(func, "object", "Object", "", "Object to remove from scene."); - RNA_def_property_flag(parm, PROP_REQUIRED); - func= RNA_def_function(srna, "set_frame", "rna_Scene_set_frame"); RNA_def_function_flag(func, FUNC_USE_CONTEXT); RNA_def_function_ui_description(func, "Set scene frame updating all objects immediately."); |