2.5
[blender.git] / source / blender / editors / space_view3d / space_view3d.c
1 /**
2  * $Id:
3  *
4  * ***** BEGIN GPL 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. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "DNA_object_types.h"
33 #include "DNA_space_types.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_screen_types.h"
36 #include "DNA_view3d_types.h"
37
38 #include "MEM_guardedalloc.h"
39
40 #include "BLI_blenlib.h"
41 #include "BLI_arithb.h"
42 #include "BLI_rand.h"
43
44 #include "BKE_global.h"
45 #include "BKE_screen.h"
46
47 #include "ED_area.h"
48 #include "ED_screen.h"
49
50 #include "BIF_gl.h"
51
52 #include "view3d_intern.h"      // own include
53
54 /* ******************** default callbacks for view3d space ***************** */
55
56 static SpaceLink *view3d_new(void)
57 {
58         ARegion *ar;
59         View3D *vd;
60         
61         vd= MEM_callocN(sizeof(View3D), "initview3d");
62         vd->spacetype= SPACE_VIEW3D;
63         vd->blockscale= 0.7f;
64         vd->lay= vd->layact= 1;
65         if(G.scene) {
66                 vd->lay= vd->layact= G.scene->lay;
67                 vd->camera= G.scene->camera;
68         }
69         vd->scenelock= 1;
70         vd->grid= 1.0f;
71         vd->gridlines= 16;
72         vd->gridsubdiv = 10;
73         vd->drawtype= OB_WIRE;
74         
75         vd->gridflag |= V3D_SHOW_X;
76         vd->gridflag |= V3D_SHOW_Y;
77         vd->gridflag |= V3D_SHOW_FLOOR;
78         vd->gridflag &= ~V3D_SHOW_Z;
79         
80         vd->depths= NULL;
81         
82         /* XXX move view data to region? */
83         vd->viewquat[0]= 1.0f;
84         vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0f;
85         vd->persp= 1;
86         vd->view= 7;
87         vd->dist= 10.0;
88         vd->lens= 35.0f;
89         vd->near= 0.01f;
90         vd->far= 500.0f;
91         
92         /* header */
93         ar= MEM_callocN(sizeof(ARegion), "header for view3d");
94         
95         BLI_addtail(&vd->regionbase, ar);
96         ar->regiontype= RGN_TYPE_HEADER;
97         
98         /* main area */
99         ar= MEM_callocN(sizeof(ARegion), "main area for view3d");
100         
101         BLI_addtail(&vd->regionbase, ar);
102         ar->regiontype= RGN_TYPE_WINDOW;
103         
104         return (SpaceLink *)vd;
105 }
106
107 /* not spacelink itself */
108 static void view3d_free(SpaceLink *sl)
109 {
110         View3D *vd= (View3D *) sl;
111         
112         if(vd->bgpic) {
113                 if(vd->bgpic->ima) vd->bgpic->ima->id.us--;
114                 MEM_freeN(vd->bgpic);
115         }
116         
117         if(vd->localvd) MEM_freeN(vd->localvd);
118         if(vd->clipbb) MEM_freeN(vd->clipbb);
119         if(vd->depths) {
120                 if(vd->depths->depths) MEM_freeN(vd->depths->depths);
121                 MEM_freeN(vd->depths);
122                 vd->depths= NULL;
123         }
124         
125 // XXX  retopo_free_view_data(vd);
126         
127         if(vd->properties_storage) MEM_freeN(vd->properties_storage);
128         if(vd->ri) { 
129 // XXX          BIF_view3d_previewrender_free(vd);
130         }
131         
132 }
133
134
135 /* spacetype; init callback */
136 static void view3d_init(struct wmWindowManager *wm, ScrArea *sa)
137 {
138
139 }
140
141 static SpaceLink *view3d_duplicate(SpaceLink *sl)
142 {
143         View3D *v3do= (View3D *)sl;
144         View3D *v3dn= MEM_dupallocN(sl);
145         
146         /* clear or remove stuff from old */
147         
148 // XXX  BIF_view3d_previewrender_free(v3do);
149         v3do->depths= NULL;
150         v3do->retopo_view_data= NULL;
151         
152         if(v3do->localvd) {
153 // XXX          restore_localviewdata(v3do);
154                 v3do->localvd= NULL;
155                 v3do->properties_storage= NULL;
156                 v3do->localview= 0;
157                 v3do->lay &= 0xFFFFFF;
158         }
159         
160         /* copy or clear inside new stuff */
161
162         if(v3dn->bgpic) {
163                 v3dn->bgpic= MEM_dupallocN(v3dn->bgpic);
164                 if(v3dn->bgpic->ima) v3dn->bgpic->ima->id.us++;
165         }
166         v3dn->clipbb= MEM_dupallocN(v3dn->clipbb);
167         v3dn->ri= NULL;
168         v3dn->properties_storage= NULL;
169         
170         return (SpaceLink *)v3dn;
171 }
172
173 void view3d_operatortypes(void)
174 {
175 }
176
177 void view3d_keymap(struct wmWindowManager *wm)
178 {
179 }
180
181 /* only called once, from screen/spacetypes.c */
182 void ED_spacetype_view3d(void)
183 {
184         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype time");
185         ARegionType *art;
186         
187         st->spaceid= SPACE_VIEW3D;
188         
189         st->new= view3d_new;
190         st->free= view3d_free;
191         st->init= view3d_init;
192         st->duplicate= view3d_duplicate;
193         st->operatortypes= view3d_operatortypes;
194         st->keymap= view3d_keymap;
195         
196         /* regions: main window */
197         art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
198         art->regionid = RGN_TYPE_WINDOW;
199         
200         BLI_addhead(&st->regiontypes, art);
201         
202         /* regions: header */
203         art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
204         art->regionid = RGN_TYPE_HEADER;
205         art->minsizey= HEADERY;
206         
207         BLI_addhead(&st->regiontypes, art);
208         
209         BKE_spacetype_register(st);
210 }
211