Popup menus for displaying names of groups available for selection
[plumiferos.git] / source / blender / src / editgroup.c
blob8c47a81b8a9a1f433c6aa2a607a3738fb6f08b5d
1 /**
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
12 * about this.
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 *****
33 #include <string.h>
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"
48 #include "BKE_main.h"
50 #include "BIF_interface.h"
51 #include "BIF_editgroup.h"
52 #include "BIF_space.h"
53 #include "BIF_toolbox.h"
55 #include "blendef.h"
56 #include "mydevice.h"
58 #ifdef HAVE_CONFIG_H
59 #include <config.h>
60 #endif
62 void add_selected_to_group(Group *group)
64 Base *base;
66 for(base=FIRSTBASE; base; base= base->next) {
67 if TESTBASE(base) {
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;
83 Base *base;
84 Group *group;
86 if (!ob) return;
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;
92 while(group) {
93 if(object_in_group(ob, group)) {
94 /* Assign groups to selected objects */
95 base= FIRSTBASE;
96 while(base) {
97 if(TESTBASE(base)) {
98 obt= base->object;
99 add_to_group(group, obt);
100 obt->flag |= OB_FROMGROUP;
101 base->flag |= OB_FROMGROUP;
103 base= base->next;
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)
117 Base *base;
118 Group *group;
120 for(base=FIRSTBASE; base; base= base->next) {
121 if TESTBASE(base) {
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)
139 Group *group= NULL;
140 int mode;
142 /* are there existing groups? */
143 for(group= G.main->group.first; group; group= group->id.next)
144 if(group->id.lib==NULL)
145 break;
147 if(group)
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");
149 else
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)
157 Group *group= NULL;
159 /* are there existing groups? */
160 for(group= G.main->group.first; group; group= group->id.next)
161 if(group->id.lib==NULL)
162 break;
164 if(mode>0) {
165 if(group==NULL || mode==1) group= add_group( "Group" );
166 if(mode==3) {
167 int tot= BLI_countlist(&G.main->group);
168 char *strp= MEM_callocN(tot*32 + 32, "group menu"), *strp1;
170 strp1= strp;
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);
177 MEM_freeN(strp);
178 if(tot>0) group= BLI_findlink(&G.main->group, tot-1);
179 else return;
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();