- removed makeDispList, set_displist_onlyzero
[blender.git] / source / blender / src / poseobject.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  * support for animation modes - Reevan McKay
32  */
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 #include <stdlib.h>
39
40 #include "BLI_arithb.h"
41 #include "BLI_blenlib.h"
42
43 #include "DNA_action_types.h"
44 #include "DNA_armature_types.h"
45 #include "DNA_constraint_types.h"
46 #include "DNA_object_types.h"
47 #include "DNA_scene_types.h"
48 #include "DNA_screen_types.h"
49 #include "DNA_view3d_types.h"
50
51 #include "BKE_action.h"
52 #include "BKE_armature.h"
53 #include "BKE_constraint.h"
54 #include "BKE_global.h"
55 #include "BKE_displist.h"
56
57 #include "BIF_gl.h"
58 #include "BIF_graphics.h"
59 #include "BIF_interface.h"
60 #include "BIF_space.h"
61 #include "BIF_toolbox.h"
62 #include "BIF_screen.h"
63 #include "BIF_poseobject.h"
64
65 #include "BDR_editobject.h"
66
67 #include "BSE_edit.h"
68
69 #include "mydevice.h"
70 #include "blendef.h"
71
72 void enter_posemode(void)
73 {
74         Base *base;
75         Object *ob;
76         bArmature *arm;
77         
78         if(G.scene->id.lib) return;
79         base= BASACT;
80         if(base==NULL) return;
81         if((base->lay & G.vd->lay)==0) return;
82         
83         ob= base->object;
84         if(ob->data==NULL) return;
85         
86         if (ob->id.lib){
87                 error ("Can't pose libdata");
88                 return;
89         }
90
91         switch (ob->type){
92         case OB_ARMATURE:
93                 arm= get_armature(ob);
94                 if( arm==NULL ) return;
95                 
96                 G.obpose= ob;
97                 ob->flag |= OB_POSEMODE;
98                 base->flag= ob->flag;
99                 
100                 allqueue(REDRAWHEADERS, 0);     
101                 allqueue(REDRAWBUTSALL, 0);     
102                 allqueue(REDRAWOOPS, 0);
103                 allqueue(REDRAWVIEW3D, 0);
104                 break;
105         default:
106                 return;
107         }
108
109         if (G.obedit) exit_editmode(1);
110         G.f &= ~(G_VERTEXPAINT | G_FACESELECT | G_TEXTUREPAINT | G_WEIGHTPAINT);
111
112
113 }
114
115 void set_pose_keys (Object *ob)
116 {
117         bPoseChannel *chan;
118
119         if (ob->pose){
120                 for (chan=ob->pose->chanbase.first; chan; chan=chan->next){
121                         Bone *bone= chan->bone;
122                         if(bone && (bone->flag & BONE_SELECTED)) {
123                                 chan->flag |= POSE_KEY;         
124                         }
125                         else {
126                                 chan->flag &= ~POSE_KEY;
127                         }
128                 }
129         }
130 }
131
132
133 void exit_posemode (int freedata)
134 {
135         Object *ob;
136         Base *base= BASACT;
137
138         if(G.obpose==NULL) return;
139
140         ob= G.obpose;
141         ob->flag &= ~OB_POSEMODE;
142         base->flag= ob->flag;
143         
144         G.obpose= NULL;
145
146         if(freedata) {
147                 setcursor_space(SPACE_VIEW3D, CURSOR_STD);
148                 
149                 countall();
150                 allqueue(REDRAWVIEW3D, 0);
151                 allqueue(REDRAWOOPS, 0);
152                 allqueue(REDRAWHEADERS, 0);     
153                 allqueue(REDRAWBUTSALL, 0);     
154         }
155         else {
156                 G.obpose= ob;
157         }
158
159         scrarea_queue_headredraw(curarea);
160 }
161
162 void pose_special_editmenu(void)
163 {
164         bPoseChannel *pchan;
165         short nr;
166         
167         for(pchan= G.obpose->pose->chanbase.first; pchan; pchan= pchan->next)
168                 if(pchan->bone->flag & BONE_ACTIVE) break;
169         if(pchan==NULL) return;
170         
171         nr= pupmenu("Specials%t|Select constraint target%x1");
172         if(nr==1) {
173                 bConstraint *con;
174                 
175                 for(con= pchan->constraints.first; con; con= con->next) {
176                         char *subtarget;
177                         Object *ob= get_constraint_target(con, &subtarget);
178                         
179                         if(ob==G.obpose) {
180                                 if(subtarget) {
181                                         pchan= get_pose_channel(G.obpose->pose, subtarget);
182                                         pchan->bone->flag |= BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL;
183                                 }
184                         }
185                 }
186                 allqueue(REDRAWVIEW3D, 0);
187         }
188 }
189
190