From a9518afc67d1350b2bdf369dd5be891956ddb5f1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 3 Feb 2008 19:03:18 +0000 Subject: [PATCH] feature request from peach, remove selected objects from 1 group. Also made rem_from_group return if it removed the object which save some looping. Added a node in the blender help message that background mode dosnt load the .B.blend file as a bug was reported recently because of this. --- source/blender/blenkernel/BKE_group.h | 2 +- source/blender/blenkernel/intern/group.c | 9 ++- source/blender/src/buttons_object.c | 3 +- source/blender/src/editgroup.c | 78 +++++++++++++++++++++++- source/creator/creator.c | 2 +- 5 files changed, 84 insertions(+), 10 deletions(-) diff --git a/source/blender/blenkernel/BKE_group.h b/source/blender/blenkernel/BKE_group.h index bdc56b2cbd1..f7158daa937 100644 --- a/source/blender/blenkernel/BKE_group.h +++ b/source/blender/blenkernel/BKE_group.h @@ -44,7 +44,7 @@ void free_group(struct Group *group); void unlink_group(struct Group *group); struct Group *add_group(char *name); void add_to_group(struct Group *group, struct Object *ob); -void rem_from_group(struct Group *group, struct Object *ob); +int rem_from_group(struct Group *group, struct Object *ob); struct Group *find_group(struct Object *ob, struct Group *group); int object_in_group(struct Object *ob, struct Group *group); int group_is_animated(struct Object *parent, struct Group *group); diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c index a85f0f52ad2..706bdf1245c 100644 --- a/source/blender/blenkernel/intern/group.c +++ b/source/blender/blenkernel/intern/group.c @@ -134,11 +134,11 @@ void add_to_group(Group *group, Object *ob) } /* also used for ob==NULL */ -void rem_from_group(Group *group, Object *ob) +int rem_from_group(Group *group, Object *ob) { GroupObject *go, *gon; - - if(group==NULL) return; + int removed = 0; + if(group==NULL) return 0; go= group->gobject.first; while(go) { @@ -146,9 +146,12 @@ void rem_from_group(Group *group, Object *ob) if(go->ob==ob) { BLI_remlink(&group->gobject, go); free_group_object(go); + removed = 1; + /* should break here since an object being in a group twice cant happen? */ } go= gon; } + return removed; } int object_in_group(Object *ob, Group *group) diff --git a/source/blender/src/buttons_object.c b/source/blender/src/buttons_object.c index a6470faa987..0c8768bd195 100644 --- a/source/blender/src/buttons_object.c +++ b/source/blender/src/buttons_object.c @@ -2492,8 +2492,7 @@ static void group_ob_rem(void *gr_v, void *ob_v) { Object *ob= OBACT; - rem_from_group(gr_v, ob); - if(find_group(ob, NULL)==NULL) { + if(rem_from_group(gr_v, ob) && find_group(ob, NULL)==NULL) { ob->flag &= ~OB_FROMGROUP; BASACT->flag &= ~OB_FROMGROUP; } diff --git a/source/blender/src/editgroup.c b/source/blender/src/editgroup.c index 4dfa339ed15..9fd80d7eb41 100644 --- a/source/blender/src/editgroup.c +++ b/source/blender/src/editgroup.c @@ -112,7 +112,7 @@ void add_selected_to_act_ob_groups(void) } -void rem_selected_from_group(void) +void rem_selected_from_all_groups(void) { Base *base; Group *group; @@ -134,6 +134,77 @@ void rem_selected_from_group(void) BIF_undo_push("Remove from Group"); } + +void rem_selected_from_group(void) +{ + char menutext[30+(22*22)], *menupt; + int i=0; + short ret; + Group *group= NULL; + Object *ob; + Base *base; + Group *group_array[24] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + + /* UnSet Tags for Objects and Groups */ + for(group= G.main->group.first; group; group= group->id.next) { + if(group->id.lib==NULL) { + group->id.flag &= ~LIB_DOIT; + } + } + for(ob=G.main->object.first; ob; ob= ob->id.next) { + ob->id.flag &= ~LIB_DOIT; + } + + /* Not tag selected objects */ + for(base=FIRSTBASE; base; base= base->next) { + if TESTBASELIB(base) { + base->object->id.flag |= LIB_DOIT; + } + } + + menupt = menutext; + /* Build a list of groups that contain selected objects */ + for(group= G.main->group.first; group && i<24; group= group->id.next) { + if(group->id.lib==NULL) { + GroupObject *go; + for(go= group->gobject.first; go; go= go->next) { + if(go->ob->id.flag & LIB_DOIT) { + group_array[i] = group; + menupt += sprintf(menupt, "|%s", group->id.name+2); + i++; + break; /* Only want to know if this group should go in the list*/ + } + } + } + } + + /* do we have any groups? */ + if (group_array[0] == NULL) { + error("Object selection contains no groups"); + } else { + ret = pupmenu(menutext); + if (ret==-1) { + return; + } else { + group = group_array[ret-1]; + for(base=FIRSTBASE; base; base= base->next) { + if TESTBASELIB(base) { + /* if we are removed and are not in any group, set our flag */ + if(rem_from_group(group, base->object) && find_group(base->object, NULL)==NULL) { + base->object->flag &= ~OB_FROMGROUP; + base->flag &= ~OB_FROMGROUP; + } + } + } + } + } + + allqueue(REDRAWVIEW3D, 0); + allqueue(REDRAWBUTSOBJECT, 0); + DAG_scene_sort(G.scene); + BIF_undo_push("Remove from Group"); +} + void group_operation_with_menu(void) { Group *group= NULL; @@ -145,7 +216,7 @@ void group_operation_with_menu(void) break; if(group) - mode= pupmenu("Groups %t|Add to Existing Group %x3|Add to Active Objects Groups %x4|Add to New Group %x1|Remove from All Groups %x2"); + mode= pupmenu("Groups %t|Add to Existing Group %x3|Add to Active Objects Groups %x4|Add to New Group %x1|Remove from Group %x5|Remove from All Groups %x2"); else mode= pupmenu("Groups %t|Add to New Group %x1|Remove from All Groups %x2"); @@ -181,6 +252,7 @@ void group_operation(int mode) if(mode==4) add_selected_to_act_ob_groups(); else if(mode==1 || mode==3) add_selected_to_group(group); - else if(mode==2) rem_selected_from_group(); + else if(mode==2) rem_selected_from_all_groups(); + else if(mode==5) rem_selected_from_group(); } } diff --git a/source/creator/creator.c b/source/creator/creator.c index 11065155f12..7c7e81b5b45 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -182,7 +182,7 @@ static void print_help(void) printf (" ...may not render to /tmp because loading the blend file overwrites the output path that was set\n"); printf (" \"blender -b test.blend -o /tmp -f 1\" works as expected.\n"); printf ("\nRender options:\n"); - printf (" -b \tRender in background\n"); + printf (" -b \tRender in background (doesn't load the user defaults .B.blend file)\n"); printf (" -a render frames from start to end (inclusive), only works when used after -b\n"); printf (" -S \tSet scene \n"); printf (" -f \tRender frame and save it\n");