f55f07986a427edf781d315cc2c166d18e619656
[blender.git] / source / blender / src / editgroup.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
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.
13  *
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.
18  *
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.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <string.h>
34
35 #include "MEM_guardedalloc.h"
36
37 #include "BLI_blenlib.h"
38 #include "BLI_arithb.h"
39
40 #include "DNA_group_types.h"
41 #include "DNA_object_types.h"
42 #include "DNA_scene_types.h"
43 #include "DNA_view3d_types.h"
44
45 #include "BKE_group.h"
46 #include "BKE_global.h"
47 #include "BKE_main.h"
48
49 #include "BIF_space.h"
50 #include "BIF_interface.h"
51 #include "BIF_toolbox.h"
52 #include "BIF_editgroup.h"
53
54 #include "blendef.h"
55 #include "mydevice.h"
56
57 #ifdef HAVE_CONFIG_H
58 #include <config.h>
59 #endif
60
61 void set_active_group(void)
62 {
63         /* with active object, find active group */
64         Group *group;
65         GroupObject *go;
66         
67         G.scene->group= NULL;
68         
69         if(BASACT) {
70                 group= G.main->group.first;
71                 while(group) {
72                         go= group->gobject.first;
73                         while(go) {
74                                 if(go->ob == OBACT) {
75                                         G.scene->group= group;
76                                         return;
77                                 }
78                                 go= go->next;
79                         }
80                         group= group->id.next;
81                 }
82         }
83 }
84
85
86 void add_selected_to_group(void)
87 {
88         Base *base= FIRSTBASE;
89         Group *group;
90         
91         if(BASACT==NULL) {
92                 error("No active object");
93                 return;
94         }
95         
96         if(okee("Add selected to group")==0) return;
97         
98         if(G.scene->group==NULL) G.scene->group= add_group();
99         
100         while(base) {
101                 if TESTBASE(base) {
102                         
103                         /* each object only in one group */
104                         group= find_group(base->object);
105                         if(group==G.scene->group);
106                         else {
107                                 if(group) {
108                                         rem_from_group(group, base->object);
109                                 }
110                                 add_to_group(G.scene->group, base->object);
111                                 base->object->flag |= OB_FROMGROUP;
112                                 base->flag |= OB_FROMGROUP;
113                         }
114                 }
115                 base= base->next;
116         }
117         
118         allqueue(REDRAWVIEW3D, 0);
119         allqueue(REDRAWBUTSOBJECT, 0);
120 }
121
122 void rem_selected_from_group(void)
123 {
124         Base *base=FIRSTBASE;
125         Group *group;
126         
127         if(okee("Remove selected from group")==0) return;
128
129         while(base) {
130                 if TESTBASE(base) {
131
132                         group= find_group(base->object);
133                         if(group) {
134                                 rem_from_group(group, base->object);
135                         
136                                 base->object->flag &= ~OB_FROMGROUP;
137                                 base->flag &= ~OB_FROMGROUP;
138                         }
139                 }
140                 base= base->next;
141         }
142         
143         allqueue(REDRAWVIEW3D, 0);
144         allqueue(REDRAWBUTSOBJECT, 0);
145 }
146
147 void prev_group_key(Group *group)
148 {
149         GroupKey *gk= group->active;
150         
151         if(gk) gk= gk->prev;
152         
153         if(gk==NULL) group->active= group->gkey.last;
154         else group->active= gk;
155         
156         set_group_key(group);
157 }
158
159 void next_group_key(Group *group)
160 {
161         GroupKey *gk= group->active;
162         
163         if(gk) gk= gk->next;
164         
165         if(gk==NULL) group->active= group->gkey.first;
166         else group->active= gk;
167         
168         set_group_key(group);
169         
170 }
171
172