Changes to rename_id function:
[blender.git] / source / blender / blenloader / intern / versioning_defaults.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Blender Foundation
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  *
22  */
23
24 /** \file blender/blenloader/intern/versioning_defaults.c
25  *  \ingroup blenloader
26  */
27
28 #include "BLI_utildefines.h"
29 #include "BLI_listbase.h"
30 #include "BLI_math.h"
31
32 #include "DNA_brush_types.h"
33 #include "DNA_freestyle_types.h"
34 #include "DNA_linestyle_types.h"
35 #include "DNA_scene_types.h"
36 #include "DNA_screen_types.h"
37 #include "DNA_space_types.h"
38 #include "DNA_userdef_types.h"
39 #include "DNA_mesh_types.h"
40 #include "DNA_material_types.h"
41 #include "DNA_object_types.h"
42
43 #include "BKE_brush.h"
44 #include "BKE_library.h"
45 #include "BKE_main.h"
46
47 #include "BLO_readfile.h"
48
49
50 /**
51  * Override values in in-memory startup.blend, avoids resaving for small changes.
52  */
53 void BLO_update_defaults_userpref_blend(void)
54 {
55         /* defaults from T37518 */
56
57         U.uiflag |= USER_ZBUF_CURSOR;
58         U.uiflag |= USER_QUIT_PROMPT;
59         U.uiflag |= USER_CONTINUOUS_MOUSE;
60
61         U.versions = 1;
62         U.savetime = 2;
63
64         /* default from T47064 */
65         U.audiorate = 48000;
66 }
67
68 /**
69  * Update defaults in startup.blend, without having to save and embed the file.
70  * This function can be emptied each time the startup.blend is updated. */
71 void BLO_update_defaults_startup_blend(Main *bmain)
72 {
73         Scene *scene;
74         SceneRenderLayer *srl;
75         FreestyleLineStyle *linestyle;
76         Mesh *me;
77         Material *mat;
78
79         for (scene = bmain->scene.first; scene; scene = scene->id.next) {
80                 scene->r.im_format.planes = R_IMF_PLANES_RGBA;
81                 scene->r.im_format.compress = 15;
82
83                 for (srl = scene->r.layers.first; srl; srl = srl->next) {
84                         srl->freestyleConfig.sphere_radius = 0.1f;
85                         srl->pass_alpha_threshold = 0.5f;
86                 }
87
88                 if (scene->toolsettings) {
89                         ToolSettings *ts = scene->toolsettings;
90
91                         if (ts->sculpt) {
92                                 Sculpt *sculpt = ts->sculpt;
93                                 sculpt->paint.symmetry_flags |= PAINT_SYMM_X;
94                                 sculpt->flags |= SCULPT_DYNTOPO_COLLAPSE;
95                                 sculpt->detail_size = 12;
96                         }
97                         
98                         if (ts->gp_sculpt.brush[0].size == 0) {
99                                 GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
100                                 GP_EditBrush_Data *brush;
101                                 
102                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_SMOOTH];
103                                 brush->size = 25;
104                                 brush->strength = 0.3f;
105                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF | GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE;
106                                 
107                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_THICKNESS];
108                                 brush->size = 25;
109                                 brush->strength = 0.5f;
110                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
111                                 
112                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB];
113                                 brush->size = 50;
114                                 brush->strength = 0.3f;
115                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
116                                 
117                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PUSH];
118                                 brush->size = 25;
119                                 brush->strength = 0.3f;
120                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
121                                 
122                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_TWIST];
123                                 brush->size = 50;
124                                 brush->strength = 0.3f; // XXX?
125                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
126                                 
127                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PINCH];
128                                 brush->size = 50;
129                                 brush->strength = 0.5f; // XXX?
130                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
131                                 
132                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_RANDOMIZE];
133                                 brush->size = 25;
134                                 brush->strength = 0.5f;
135                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
136                         }
137                         
138                         ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
139                         ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
140                         ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
141                         ts->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
142                 }
143
144                 scene->gm.lodflag |= SCE_LOD_USE_HYST;
145                 scene->gm.scehysteresis = 10;
146
147                 scene->r.ffcodecdata.audio_mixrate = 48000;
148         }
149
150         for (linestyle = bmain->linestyle.first; linestyle; linestyle = linestyle->id.next) {
151                 linestyle->flag = LS_SAME_OBJECT | LS_NO_SORTING | LS_TEXTURE;
152                 linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
153                 linestyle->integration_type = LS_INTEGRATION_MEAN;
154                 linestyle->texstep = 1.0;
155                 linestyle->chain_count = 10;
156         }
157
158         {
159                 bScreen *screen;
160
161                 for (screen = bmain->screen.first; screen; screen = screen->id.next) {
162                         ScrArea *area;
163                         for (area = screen->areabase.first; area; area = area->next) {
164                                 SpaceLink *space_link;
165                                 ARegion *ar;
166
167                                 for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
168                                         if (space_link->spacetype == SPACE_CLIP) {
169                                                 SpaceClip *space_clip = (SpaceClip *) space_link;
170                                                 space_clip->flag &= ~SC_MANUAL_CALIBRATION;
171                                         }
172                                 }
173
174                                 for (ar = area->regionbase.first; ar; ar = ar->next) {
175                                         /* Remove all stored panels, we want to use defaults (order, open/closed) as defined by UI code here! */
176                                         BLI_freelistN(&ar->panels);
177
178                                         /* simple fix for 3d view properties scrollbar being not set to top */
179                                         if (ar->regiontype == RGN_TYPE_UI) {
180                                                 float offset = ar->v2d.tot.ymax - ar->v2d.cur.ymax;
181                                                 ar->v2d.cur.ymax += offset;
182                                                 ar->v2d.cur.ymin += offset;
183                                         }
184                                 }
185                         }
186                 }
187         }
188
189         for (me = bmain->mesh.first; me; me = me->id.next) {
190                 me->smoothresh = DEG2RADF(180.0f);
191                 me->flag &= ~ME_TWOSIDED;
192         }
193
194         for (mat = bmain->mat.first; mat; mat = mat->id.next) {
195                 mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
196                 mat->line_col[3] = 1.0f;
197         }
198
199         {
200                 Brush *br;
201
202                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Fill");
203                 if (!br) {
204                         br = BKE_brush_add(bmain, "Fill", OB_MODE_TEXTURE_PAINT);
205                         br->imagepaint_tool = PAINT_TOOL_FILL;
206                         br->ob_mode = OB_MODE_TEXTURE_PAINT;
207                 }
208
209                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Mask");
210                 if (br) {
211                         br->imagepaint_tool = PAINT_TOOL_MASK;
212                         br->ob_mode |= OB_MODE_TEXTURE_PAINT;
213                 }
214
215                 /* remove polish brush (flatten/contrast does the same) */
216                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Polish");
217                 if (br) {
218                         BKE_libblock_free(bmain, br);
219                 }
220
221                 /* remove brush brush (huh?) from some modes (draw brushes do the same) */
222                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Brush");
223                 if (br) {
224                         BKE_libblock_free(bmain, br);
225                 }
226
227                 /* remove draw brush from texpaint (draw brushes do the same) */
228                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Draw");
229                 if (br) {
230                         br->ob_mode &= ~OB_MODE_TEXTURE_PAINT;
231                 }
232
233                 /* rename twist brush to rotate brush to match rotate tool */
234                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Twist");
235                 if (br)
236                 {
237                         BKE_rename_id(bmain, &br->id, "Rotate");
238                 }
239         }
240 }
241