2bf3eb7bae757e49c015d0133bd93d52c0666d98
[blender-staging.git] / source / blender / src / drawscene.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  * drawing graphics and editing
32  */
33         
34 #include <math.h>
35
36 #include "BLI_blenlib.h"
37 #include "BLI_arithb.h"
38
39 #include "DNA_scene_types.h"
40 #include "DNA_space_types.h"
41 #include "DNA_screen_types.h"
42 #include "DNA_userdef_types.h"
43 #include "DNA_view3d_types.h"
44
45 #include "BKE_global.h"
46 #include "BKE_main.h"
47 #include "BKE_scene.h"
48
49 #include "BDR_editobject.h"
50 #include "BDR_editface.h"
51 #include "BDR_vpaint.h"
52
53 #include "BIF_space.h"
54 #include "BIF_drawscene.h"
55 #include "BIF_poseobject.h"
56
57 #include "BSE_view.h"
58
59 #include "radio.h"
60
61 #include "blendef.h" /* old */
62 #include "mydevice.h"
63
64 #ifdef HAVE_CONFIG_H
65 #include <config.h>
66 #endif
67
68 void set_scene(Scene *sce)              /* also see scene.c: set_scene_bg() */
69 {
70         bScreen *sc;
71         
72         /* ending all modes */
73         if( G.obedit) 
74                 exit_editmode(2);
75         
76         if(G.f & G_FACESELECT)
77                 set_faceselect();
78         if(G.f & G_VERTEXPAINT)
79                 set_vpaint();
80         if(G.f & G_TEXTUREPAINT)
81                 G.f &= ~G_TEXTUREPAINT;
82         if(G.f & G_WEIGHTPAINT)
83                 set_wpaint();
84         
85         G.scene= sce;
86
87         sc= G.main->screen.first;
88         while(sc) {
89                 if((U.flag & USER_SCENEGLOBAL) || sc==G.curscreen) {
90                 
91                         if(sce != sc->scene) {
92                                 /* all areas endlocalview */
93                                 ScrArea *sa= sc->areabase.first;
94                                 while(sa) {
95                                         endlocalview(sa);
96                                         sa= sa->next;
97                                 }               
98                                 sc->scene= sce;
99                         }
100                         
101                 }
102                 sc= sc->id.next;
103         }
104         
105         copy_view3d_lock(0);    /* space.c */
106
107         /* are there cameras in the views that are not in the scene? */
108         sc= G.main->screen.first;
109         while(sc) {
110                 if( (U.flag & USER_SCENEGLOBAL) || sc==G.curscreen) {
111                         ScrArea *sa= sc->areabase.first;
112                         while(sa) {
113                                 SpaceLink *sl= sa->spacedata.first;
114                                 while(sl) {
115                                         if(sl->spacetype==SPACE_VIEW3D) {
116                                                 View3D *v3d= (View3D*) sl;
117                                                 if (!v3d->camera || !object_in_scene(v3d->camera, sce)) {
118                                                         v3d->camera= scene_find_camera(sc->scene);
119                                                         if (sc==G.curscreen) handle_view3d_lock();
120                                                         if (!v3d->camera && v3d->persp>1) v3d->persp= 1;
121                                                 }
122                                         }
123                                         sl= sl->next;
124                                 }
125                                 sa= sa->next;
126                         }
127                 }
128                 sc= sc->id.next;
129         }
130
131         set_scene_bg(G.scene);  
132         set_radglobal();
133                 
134         /* complete redraw */
135         allqueue(REDRAWALL, 0);
136         allqueue(REDRAWDATASELECT, 0);  /* does a remake */
137 }
138
139