Whole lot of changes.... here a shortlist:
[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
49 #include "BIF_gl.h"
50
51 #include "view3d_intern.h"      // own include
52
53 /* ******************** default callbacks for view3d space ***************** */
54
55 static SpaceLink *view3d_new(void)
56 {
57         View3D *vd;
58         
59         vd= MEM_callocN(sizeof(View3D), "initview3d");
60         
61         vd->spacetype= SPACE_VIEW3D;
62         vd->blockscale= 0.7f;
63         vd->viewquat[0]= 1.0f;
64         vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0f;
65         vd->persp= 1;
66         vd->drawtype= OB_WIRE;
67         vd->view= 7;
68         vd->dist= 10.0;
69         vd->lens= 35.0f;
70         vd->near= 0.01f;
71         vd->far= 500.0f;
72         vd->grid= 1.0f;
73         vd->gridlines= 16;
74         vd->gridsubdiv = 10;
75         
76         vd->lay= vd->layact= 1;
77         if(G.scene) {
78                 vd->lay= vd->layact= G.scene->lay;
79                 vd->camera= G.scene->camera;
80         }
81         vd->scenelock= 1;
82         vd->gridflag |= V3D_SHOW_X;
83         vd->gridflag |= V3D_SHOW_Y;
84         vd->gridflag |= V3D_SHOW_FLOOR;
85         vd->gridflag &= ~V3D_SHOW_Z;
86         
87         vd->depths= NULL;
88         
89         return (SpaceLink *)vd;
90 }
91
92 /* not spacelink itself */
93 static void view3d_free(SpaceLink *sl)
94 {
95         View3D *vd= (View3D *) sl;
96         
97         if(vd->bgpic) {
98                 if(vd->bgpic->ima) vd->bgpic->ima->id.us--;
99                 MEM_freeN(vd->bgpic);
100         }
101         
102         if(vd->localvd) MEM_freeN(vd->localvd);
103         if(vd->clipbb) MEM_freeN(vd->clipbb);
104         if(vd->depths) {
105                 if(vd->depths->depths) MEM_freeN(vd->depths->depths);
106                 MEM_freeN(vd->depths);
107                 vd->depths= NULL;
108         }
109         
110 // XXX  retopo_free_view_data(vd);
111         
112         if(vd->properties_storage) MEM_freeN(vd->properties_storage);
113         if(vd->ri) { 
114 // XXX          BIF_view3d_previewrender_free(vd);
115         }
116         
117 }
118
119
120 /* spacetype; init callback */
121 static void view3d_init(ScrArea *sa)
122 {
123         ARegion *ar;
124         
125         /* link area to SpaceXXX struct */
126         
127         /* define how many regions, the order and types */
128         
129         /* add types to regions */
130         for(ar= sa->regionbase.first; ar; ar= ar->next) {
131                 static ARegionType art={NULL, NULL, NULL, NULL};
132                 
133                 /* for time being; register 1 type */
134                 ar->type= &art;
135                 
136         }
137 }
138
139 /* spacetype; context changed */
140 static void view3d_refresh(bContext *C, ScrArea *sa)
141 {
142         
143 }
144
145 static SpaceLink *view3d_duplicate(SpaceLink *sl)
146 {
147         View3D *v3do= (View3D *)sl;
148         View3D *v3dn= MEM_dupallocN(sl);
149         
150         /* clear or remove stuff from old */
151         
152 // XXX  BIF_view3d_previewrender_free(v3do);
153         v3do->depths= NULL;
154         v3do->retopo_view_data= NULL;
155         
156         if(v3do->localvd) {
157 // XXX          restore_localviewdata(v3do);
158                 v3do->localvd= NULL;
159                 v3do->properties_storage= NULL;
160                 v3do->localview= 0;
161                 v3do->lay &= 0xFFFFFF;
162         }
163         
164         /* copy or clear inside new stuff */
165
166         if(v3dn->bgpic) {
167                 v3dn->bgpic= MEM_dupallocN(v3dn->bgpic);
168                 if(v3dn->bgpic->ima) v3dn->bgpic->ima->id.us++;
169         }
170         v3dn->clipbb= MEM_dupallocN(v3dn->clipbb);
171         v3dn->ri= NULL;
172         v3dn->properties_storage= NULL;
173         
174         return (SpaceLink *)v3dn;
175 }
176
177 /* only called once, from screen/spacetypes.c */
178 void ED_spacetype_view3d(void)
179 {
180         static SpaceType st;
181         
182         st.spaceid= SPACE_VIEW3D;
183         
184         st.new= view3d_new;
185         st.free= view3d_free;
186         st.init= view3d_init;
187         st.refresh= view3d_refresh;
188         st.duplicate= view3d_duplicate;
189         
190         BKE_spacetype_register(&st);
191         
192         
193 }
194
195
196