diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-07-18 12:13:30 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-07-18 12:13:30 +0400 |
commit | 64cc69cafc2fda9b70c40a1806abd371c7e80df1 (patch) | |
tree | e9813b7bb0d1898625879e2b4087f311e377610f /source | |
parent | 52d2bae2bfb40831590a1b2ff2050fc6f8414481 (diff) |
adding objects active groups now gives menu of which group to add to.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/object/object_group.c | 149 |
1 files changed, 81 insertions, 68 deletions
diff --git a/source/blender/editors/object/object_group.c b/source/blender/editors/object/object_group.c index 7328cdbf9f2..3b9d54d76d6 100644 --- a/source/blender/editors/object/object_group.c +++ b/source/blender/editors/object/object_group.c @@ -59,57 +59,113 @@ /********************* 3d view operators ***********************/ +/* can be called with C == NULL */ +static EnumPropertyItem *group_object_active_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free) +{ + Object *ob; + EnumPropertyItem *item = NULL, item_tmp = {0}; + int totitem = 0; + + if (C == NULL) { + return DummyRNA_NULL_items; + } + + ob = ED_object_context(C); + + /* check that the action exists */ + if (ob) { + Group *group = NULL; + int i = 0; + + while ((group = find_group(ob, group))) { + item_tmp.identifier = item_tmp.name = group->id.name + 2; + /* item_tmp.icon = ICON_ARMATURE_DATA; */ + item_tmp.value = i; + RNA_enum_item_add(&item, &totitem, &item_tmp); + i++; + } + } + + RNA_enum_item_end(&item, &totitem); + *free = 1; + + return item; +} + +/* get the group back from the enum index, quite awkward and UI specific */ +static Group *group_object_active_find_index(Object *ob, const int group_object_index) +{ + Group *group = NULL; + int i = 0; + while ((group = find_group(ob, group))) { + if (i == group_object_index) { + break; + } + i++; + } + + return group; +} + static int objects_add_active_exec(bContext *C, wmOperator *op) { + Object *ob = ED_object_context(C); Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - Object *ob = OBACT; - Group *group; - int ok = 0, cycle = 0; - - if (!ob) return OPERATOR_CANCELLED; - - /* linking to same group requires its own loop so we can avoid - * looking up the active objects groups each time */ + int group_object_index = RNA_enum_get(op->ptr, "group"); + int cycle = FALSE; + + if (ob) { + Group *group = group_object_active_find_index(ob, group_object_index); + + /* now add all selected objects from the group */ + if (group) { - 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) { - if (base->object->dup_group != group) + if (base->object->dup_group != group) { add_to_group(group, base->object, scene, base); - else - cycle = 1; - ok = 1; + } + else { + cycle = TRUE; + } } CTX_DATA_END; + + DAG_scene_sort(bmain, scene); + WM_event_add_notifier(C, NC_GROUP | NA_EDITED, NULL); + + return OPERATOR_FINISHED; } } - - if (!ok) BKE_report(op->reports, RPT_ERROR, "Active Object contains no groups"); + if (cycle) BKE_report(op->reports, RPT_WARNING, "Skipped some groups because of cycle detected"); - - DAG_scene_sort(bmain, scene); - WM_event_add_notifier(C, NC_GROUP | NA_EDITED, NULL); - - return OPERATOR_FINISHED; + + return OPERATOR_CANCELLED; } void GROUP_OT_objects_add_active(wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name = "Add Selected To Active Group"; ot->description = "Add the object to an object group that contains the active object"; ot->idname = "GROUP_OT_objects_add_active"; /* api callbacks */ - ot->exec = objects_add_active_exec; + ot->exec = objects_add_active_exec; + ot->invoke = WM_menu_invoke; ot->poll = ED_operator_objectmode; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + prop = RNA_def_enum(ot->srna, "group", DummyRNA_NULL_items, 0, "Group", "The group to add other selected objects to"); + RNA_def_enum_funcs(prop, group_object_active_itemf); + ot->prop = prop; } static int objects_remove_active_exec(bContext *C, wmOperator *op) @@ -202,17 +258,8 @@ static int group_objects_remove_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); int group_object_index = RNA_enum_get(op->ptr, "group"); - /* first get the group back from the enum index, quite awkward and UI specific */ if (ob) { - Group *group = NULL; - int i = 0; - - while ((group = find_group(ob, group))) { - if (i == group_object_index) { - break; - } - i++; - } + Group *group = group_object_active_find_index(ob, group_object_index); /* now remove all selected objects from the group */ if (group) { @@ -233,40 +280,6 @@ static int group_objects_remove_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - -/* can be called with C == NULL */ -static EnumPropertyItem *group_objects_remove_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free) -{ - Object *ob; - EnumPropertyItem *item = NULL, item_tmp = {0}; - int totitem = 0; - - if (C == NULL) { - return DummyRNA_NULL_items; - } - - ob = ED_object_context(C); - - /* check that the action exists */ - if (ob) { - Group *group = NULL; - int i = 0; - - while ((group = find_group(ob, group))) { - item_tmp.identifier = item_tmp.name = group->id.name + 2; - /* item_tmp.icon = ICON_ARMATURE_DATA; */ - item_tmp.value = i; - RNA_enum_item_add(&item, &totitem, &item_tmp); - i++; - } - } - - RNA_enum_item_end(&item, &totitem); - *free = 1; - - return item; -} - void GROUP_OT_objects_remove(wmOperatorType *ot) { PropertyRNA *prop; @@ -286,7 +299,7 @@ void GROUP_OT_objects_remove(wmOperatorType *ot) /* properties */ prop = RNA_def_enum(ot->srna, "group", DummyRNA_NULL_items, 0, "Group", "The group to remove this object from"); - RNA_def_enum_funcs(prop, group_objects_remove_itemf); + RNA_def_enum_funcs(prop, group_object_active_itemf); ot->prop = prop; } |