feature request from peach, remove selected objects from 1 group.
authorCampbell Barton <ideasman42@gmail.com>
Sun, 3 Feb 2008 19:03:18 +0000 (19:03 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 3 Feb 2008 19:03:18 +0000 (19:03 +0000)
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
source/blender/blenkernel/intern/group.c
source/blender/src/buttons_object.c
source/blender/src/editgroup.c
source/creator/creator.c

index bdc56b2cbd10cff70a3346b02918e014c02f9880..f7158daa9370ea9b989f52ede7985166682f0a78 100644 (file)
@@ -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);
index a85f0f52ad282b8fe59dfd9348da1d12be0fa9af..706bdf1245cc41c92f29722cfe5312ebe98ae101 100644 (file)
@@ -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)
index a6470faa987ac3fae68d69928e5233532c303f75..0c8768bd195c79598ee2f97802ef932fbfa26e72 100644 (file)
@@ -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;
        }
index 4dfa339ed1570981c4b5569ab67b3e3c97d54519..9fd80d7eb41ef9eb5eba2a9ea463a05f6a1d8554 100644 (file)
@@ -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();
        }
 }
index 11065155f12a8dac1b6768e7bc78ffa40a41ed8f..7c7e81b5b4518938a32a5d1f2197c62842f949db 100644 (file)
@@ -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 <file>\tRender <file> in background\n");
+       printf ("  -b <file>\tRender <file> 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 <name>\tSet scene <name>\n");
        printf ("    -f <frame>\tRender frame <frame> and save it\n");