diff options
Diffstat (limited to 'source/blender/editors/object/object_group.c')
-rw-r--r-- | source/blender/editors/object/object_group.c | 105 |
1 files changed, 47 insertions, 58 deletions
diff --git a/source/blender/editors/object/object_group.c b/source/blender/editors/object/object_group.c index 73ca6e02132..f000485466f 100644 --- a/source/blender/editors/object/object_group.c +++ b/source/blender/editors/object/object_group.c @@ -29,7 +29,6 @@ #include <string.h> -#include "MEM_guardedalloc.h" #include "BLI_blenlib.h" @@ -39,11 +38,9 @@ #include "BKE_context.h" #include "BKE_depsgraph.h" -#include "BKE_global.h" #include "BKE_group.h" #include "BKE_main.h" #include "BKE_report.h" -#include "BKE_scene.h" #include "ED_screen.h" @@ -52,6 +49,7 @@ #include "RNA_access.h" #include "RNA_define.h" +#include "RNA_enum_types.h" #include "object_intern.h" @@ -59,6 +57,7 @@ static int objects_add_active_exec(bContext *C, wmOperator *op) { + Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); Object *ob= OBACT; Group *group; @@ -69,7 +68,7 @@ static int objects_add_active_exec(bContext *C, wmOperator *op) /* linking to same group requires its own loop so we can avoid looking up the active objects groups each time */ - for(group= G.main->group.first; group; group=group->id.next) { + for(group= bmain->group.first; group; group=group->id.next) { if(object_in_group(ob, group)) { /* Assign groups to selected objects */ CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { @@ -82,7 +81,7 @@ static int objects_add_active_exec(bContext *C, wmOperator *op) if(!ok) BKE_report(op->reports, RPT_ERROR, "Active Object contains no groups"); - DAG_scene_sort(scene); + DAG_scene_sort(bmain, scene); WM_event_add_notifier(C, NC_GROUP|NA_EDITED, NULL); return OPERATOR_FINISHED; @@ -105,6 +104,7 @@ void GROUP_OT_objects_add_active(wmOperatorType *ot) static int objects_remove_active_exec(bContext *C, wmOperator *op) { + Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); Object *ob= OBACT; Group *group; @@ -115,7 +115,7 @@ static int objects_remove_active_exec(bContext *C, wmOperator *op) /* linking to same group requires its own loop so we can avoid looking up the active objects groups each time */ - for(group= G.main->group.first; group; group=group->id.next) { + for(group= bmain->group.first; group; group=group->id.next) { if(object_in_group(ob, group)) { /* Assign groups to selected objects */ CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { @@ -128,7 +128,7 @@ static int objects_remove_active_exec(bContext *C, wmOperator *op) if(!ok) BKE_report(op->reports, RPT_ERROR, "Active Object contains no groups"); - DAG_scene_sort(scene); + DAG_scene_sort(bmain, scene); WM_event_add_notifier(C, NC_GROUP|NA_EDITED, NULL); return OPERATOR_FINISHED; @@ -151,6 +151,7 @@ void GROUP_OT_objects_remove_active(wmOperatorType *ot) static int group_objects_remove_exec(bContext *C, wmOperator *op) { + Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); Group *group= NULL; @@ -161,7 +162,7 @@ static int group_objects_remove_exec(bContext *C, wmOperator *op) } CTX_DATA_END; - DAG_scene_sort(scene); + DAG_scene_sort(bmain, scene); WM_event_add_notifier(C, NC_GROUP|NA_EDITED, NULL); return OPERATOR_FINISHED; @@ -184,6 +185,7 @@ void GROUP_OT_objects_remove(wmOperatorType *ot) static int group_create_exec(bContext *C, wmOperator *op) { + Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); Group *group= NULL; char name[32]; /* id name */ @@ -197,7 +199,7 @@ static int group_create_exec(bContext *C, wmOperator *op) } CTX_DATA_END; - DAG_scene_sort(scene); + DAG_scene_sort(bmain, scene); WM_event_add_notifier(C, NC_GROUP|NA_EDITED, NULL); return OPERATOR_FINISHED; @@ -224,84 +226,71 @@ void GROUP_OT_create(wmOperatorType *ot) static int group_add_exec(bContext *C, wmOperator *op) { - Main *bmain= CTX_data_main(C); Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - Base *base; Group *group; - int value= RNA_enum_get(op->ptr, "group"); - if(!ob) + if(ob == NULL) return OPERATOR_CANCELLED; - - base= object_in_scene(ob, scene); - if(!base) - return OPERATOR_CANCELLED; - - if(value == -1) - group= add_group( "Group" ); - else - group= BLI_findlink(&bmain->group, value); - if(group) { - add_to_group(group, ob, scene, NULL); /* base will be used if found */ - } + group= add_group("Group"); + add_to_group(group, ob, scene, NULL); WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - + return OPERATOR_FINISHED; } -static EnumPropertyItem group_items[]= { - {-1, "ADD_NEW", 0, "Add New Group", ""}, - {0, NULL, 0, NULL, NULL}}; - -static EnumPropertyItem *group_itemf(bContext *C, PointerRNA *ptr, int *free) -{ - Main *bmain= CTX_data_main(C); - Group *group; - EnumPropertyItem tmp = {0, "", 0, "", ""}; - EnumPropertyItem *item= NULL; - int a, totitem= 0; +void OBJECT_OT_group_add(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Add to Group"; + ot->idname= "OBJECT_OT_group_add"; + ot->description = "Add an object to a new group"; - RNA_enum_items_add_value(&item, &totitem, group_items, -1); + /* api callbacks */ + ot->exec= group_add_exec; - if (bmain) { - if(bmain->group.first) - RNA_enum_item_add_separator(&item, &totitem); + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} - for(a=0, group=bmain->group.first; group; group=group->id.next, a++) { - tmp.value= a; - tmp.identifier= group->id.name+2; - tmp.name= group->id.name+2; - RNA_enum_item_add(&item, &totitem, &tmp); - } - } +static int group_link_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + Group *group= BLI_findlink(&CTX_data_main(C)->group, RNA_enum_get(op->ptr, "group")); - RNA_enum_item_end(&item, &totitem); - *free= 1; + if(ELEM(NULL, ob, group)) + return OPERATOR_CANCELLED; + + add_to_group(group, ob, scene, NULL); - return item; + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + + return OPERATOR_FINISHED; } -void OBJECT_OT_group_add(wmOperatorType *ot) +void OBJECT_OT_group_link(wmOperatorType *ot) { PropertyRNA *prop; /* identifiers */ - ot->name= "Add to Group"; - ot->idname= "OBJECT_OT_group_add"; - ot->description = "Add an object to an existing group, or create new"; + ot->name= "Link to Group"; + ot->idname= "OBJECT_OT_group_link"; + ot->description = "Add an object to an existing group"; /* api callbacks */ - ot->exec= group_add_exec; + ot->exec= group_link_exec; + ot->invoke= WM_enum_search_invoke; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ - prop= RNA_def_enum(ot->srna, "group", group_items, -1, "Group", "Group to add object to."); - RNA_def_enum_funcs(prop, group_itemf); + prop= RNA_def_enum(ot->srna, "group", DummyRNA_NULL_items, 0, "Group", ""); + RNA_def_enum_funcs(prop, RNA_group_local_itemf); + ot->prop= prop; } static int group_remove_exec(bContext *C, wmOperator *op) |