2 * $Id: editgroup.c 10242 2007-03-11 16:25:17Z campbellbarton $
4 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version. The Blender
10 * Foundation also sells licenses for use in proprietary software under
11 * the Blender License. See http://www.blender.org/BL/ for information
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24 * All rights reserved.
26 * The Original Code is: all of this file.
28 * Contributor(s): none yet.
30 * ***** END GPL/BL DUAL LICENSE BLOCK *****
35 #include "MEM_guardedalloc.h"
37 #include "BLI_blenlib.h"
38 #include "BLI_arithb.h"
40 #include "DNA_group_types.h"
41 #include "DNA_object_types.h"
42 #include "DNA_scene_types.h"
43 #include "DNA_view3d_types.h"
45 #include "BKE_depsgraph.h"
46 #include "BKE_group.h"
47 #include "BKE_global.h"
50 #include "BIF_interface.h"
51 #include "BIF_editgroup.h"
52 #include "BIF_space.h"
53 #include "BIF_toolbox.h"
62 void add_selected_to_group(Group
*group
)
66 for(base
=FIRSTBASE
; base
; base
= base
->next
) {
68 add_to_group(group
, base
->object
);
69 base
->object
->flag
|= OB_FROMGROUP
;
70 base
->flag
|= OB_FROMGROUP
;
74 allqueue(REDRAWVIEW3D
, 0);
75 allqueue(REDRAWBUTSOBJECT
, 0);
76 DAG_scene_sort(G
.scene
);
77 BIF_undo_push("Add to Group");
80 void add_selected_to_act_ob_groups(void)
82 Object
*ob
= OBACT
, *obt
;
88 /* linking to same group requires its own loop so we can avoid
89 looking up the active objects groups each time */
91 group
= G
.main
->group
.first
;
93 if(object_in_group(ob
, group
)) {
94 /* Assign groups to selected objects */
99 add_to_group(group
, obt
);
100 obt
->flag
|= OB_FROMGROUP
;
101 base
->flag
|= OB_FROMGROUP
;
106 group
= group
->id
.next
;
108 allqueue(REDRAWVIEW3D
, 0);
109 allqueue(REDRAWBUTSOBJECT
, 0);
110 DAG_scene_sort(G
.scene
);
111 BIF_undo_push("Add to Active Objects Group");
115 void rem_selected_from_group(void)
120 for(base
=FIRSTBASE
; base
; base
= base
->next
) {
123 while( (group
= find_group(base
->object
)) ) {
124 rem_from_group(group
, base
->object
);
126 base
->object
->flag
&= ~OB_FROMGROUP
;
127 base
->flag
&= ~OB_FROMGROUP
;
131 DAG_scene_sort(G
.scene
);
132 allqueue(REDRAWVIEW3D
, 0);
133 allqueue(REDRAWBUTSOBJECT
, 0);
134 BIF_undo_push("Remove from Group");
137 void group_operation_with_menu(void)
142 /* are there existing groups? */
143 for(group
= G
.main
->group
.first
; group
; group
= group
->id
.next
)
144 if(group
->id
.lib
==NULL
)
148 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");
150 mode
= pupmenu("Groups %t|Add to New Group %x1|Remove from All Groups %x2");
152 group_operation(mode
);
155 void group_operation(int mode
)
159 /* are there existing groups? */
160 for(group
= G
.main
->group
.first
; group
; group
= group
->id
.next
)
161 if(group
->id
.lib
==NULL
)
165 if(group
==NULL
|| mode
==1) group
= add_group( "Group" );
167 int tot
= BLI_countlist(&G
.main
->group
);
168 char *strp
= MEM_callocN(tot
*32 + 32, "group menu"), *strp1
;
171 for(tot
=1, group
= G
.main
->group
.first
; group
; group
= group
->id
.next
, tot
++) {
172 if(group
->id
.lib
==NULL
) {
173 strp1
+= sprintf(strp1
, "%s %%x%d|", group
->id
.name
+2, tot
);
176 tot
= pupmenu_col(strp
, 20);
178 if(tot
>0) group
= BLI_findlink(&G
.main
->group
, tot
-1);
182 if(mode
==4) add_selected_to_act_ob_groups();
183 else if(mode
==1 || mode
==3) add_selected_to_group(group
);
184 else if(mode
==2) rem_selected_from_group();