03a30e96e57d02eb21ccba7536c3f6fe38197155
[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         View3D *vd;
59         
60         vd= MEM_callocN(sizeof(View3D), "initview3d");
61         
62         vd->spacetype= SPACE_VIEW3D;
63         vd->blockscale= 0.7f;
64         vd->viewquat[0]= 1.0f;
65         vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0f;
66         vd->persp= 1;
67         vd->drawtype= OB_WIRE;
68         vd->view= 7;
69         vd->dist= 10.0;
70         vd->lens= 35.0f;
71         vd->near= 0.01f;
72         vd->far= 500.0f;
73         vd->grid= 1.0f;
74         vd->gridlines= 16;
75         vd->gridsubdiv = 10;
76         
77         vd->lay= vd->layact= 1;
78         if(G.scene) {
79                 vd->lay= vd->layact= G.scene->lay;
80                 vd->camera= G.scene->camera;
81         }
82         vd->scenelock= 1;
83         vd->gridflag |= V3D_SHOW_X;
84         vd->gridflag |= V3D_SHOW_Y;
85         vd->gridflag |= V3D_SHOW_FLOOR;
86         vd->gridflag &= ~V3D_SHOW_Z;
87         
88         vd->depths= NULL;
89         
90         return (SpaceLink *)vd;
91 }
92
93 /* not spacelink itself */
94 static void view3d_free(SpaceLink *sl)
95 {
96         View3D *vd= (View3D *) sl;
97         
98         if(vd->bgpic) {
99                 if(vd->bgpic->ima) vd->bgpic->ima->id.us--;
100                 MEM_freeN(vd->bgpic);
101         }
102         
103         if(vd->localvd) MEM_freeN(vd->localvd);
104         if(vd->clipbb) MEM_freeN(vd->clipbb);
105         if(vd->depths) {
106                 if(vd->depths->depths) MEM_freeN(vd->depths->depths);
107                 MEM_freeN(vd->depths);
108                 vd->depths= NULL;
109         }
110         
111 // XXX  retopo_free_view_data(vd);
112         
113         if(vd->properties_storage) MEM_freeN(vd->properties_storage);
114         if(vd->ri) { 
115 // XXX          BIF_view3d_previewrender_free(vd);
116         }
117         
118 }
119
120
121 /* spacetype; init callback */
122 static void view3d_init(struct wmWindowManager *wm, ScrArea *sa)
123 {
124
125 }
126
127 static SpaceLink *view3d_duplicate(SpaceLink *sl)
128 {
129         View3D *v3do= (View3D *)sl;
130         View3D *v3dn= MEM_dupallocN(sl);
131         
132         /* clear or remove stuff from old */
133         
134 // XXX  BIF_view3d_previewrender_free(v3do);
135         v3do->depths= NULL;
136         v3do->retopo_view_data= NULL;
137         
138         if(v3do->localvd) {
139 // XXX          restore_localviewdata(v3do);
140                 v3do->localvd= NULL;
141                 v3do->properties_storage= NULL;
142                 v3do->localview= 0;
143                 v3do->lay &= 0xFFFFFF;
144         }
145         
146         /* copy or clear inside new stuff */
147
148         if(v3dn->bgpic) {
149                 v3dn->bgpic= MEM_dupallocN(v3dn->bgpic);
150                 if(v3dn->bgpic->ima) v3dn->bgpic->ima->id.us++;
151         }
152         v3dn->clipbb= MEM_dupallocN(v3dn->clipbb);
153         v3dn->ri= NULL;
154         v3dn->properties_storage= NULL;
155         
156         return (SpaceLink *)v3dn;
157 }
158
159 void view3d_operatortypes(void)
160 {
161 }
162
163 void view3d_keymap(struct wmWindowManager *wm)
164 {
165 }
166
167 /* only called once, from screen/spacetypes.c */
168 void ED_spacetype_view3d(void)
169 {
170         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype time");
171         ARegionType *art;
172         
173         st->spaceid= SPACE_VIEW3D;
174         
175         st->new= view3d_new;
176         st->free= view3d_free;
177         st->init= view3d_init;
178         st->duplicate= view3d_duplicate;
179         st->operatortypes= view3d_operatortypes;
180         st->keymap= view3d_keymap;
181         
182         /* regions: main window */
183         art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
184         art->regionid = RGN_TYPE_WINDOW;
185         
186         BLI_addhead(&st->regiontypes, art);
187         
188         /* regions: header */
189         art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
190         art->regionid = RGN_TYPE_HEADER;
191         art->minsizey= HEADERY;
192         
193         BLI_addhead(&st->regiontypes, art);
194         
195         BKE_spacetype_register(st);
196 }
197