Workspace: Move engines to workspace and Properties Editor cleanup
[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 #include "BLI_string.h"
32
33 #include "DNA_brush_types.h"
34 #include "DNA_freestyle_types.h"
35 #include "DNA_linestyle_types.h"
36 #include "DNA_scene_types.h"
37 #include "DNA_screen_types.h"
38 #include "DNA_space_types.h"
39 #include "DNA_userdef_types.h"
40 #include "DNA_mesh_types.h"
41 #include "DNA_material_types.h"
42 #include "DNA_object_types.h"
43 #include "DNA_workspace_types.h"
44
45 #include "BKE_brush.h"
46 #include "BKE_library.h"
47 #include "BKE_main.h"
48 #include "BKE_scene.h"
49 #include "BKE_workspace.h"
50
51 #include "BLO_readfile.h"
52
53
54 /**
55  * Override values in in-memory startup.blend, avoids resaving for small changes.
56  */
57 void BLO_update_defaults_userpref_blend(void)
58 {
59         /* defaults from T37518 */
60
61         U.uiflag |= USER_ZBUF_CURSOR;
62         U.uiflag |= USER_QUIT_PROMPT;
63         U.uiflag |= USER_CONTINUOUS_MOUSE;
64
65         /* See T45301 */
66         U.uiflag |= USER_LOCK_CURSOR_ADJUST;
67
68         U.versions = 1;
69         U.savetime = 2;
70
71         /* default from T47064 */
72         U.audiorate = 48000;
73
74         /* Keep this a very small, non-zero number so zero-alpha doesn't mask out objects behind it.
75          * but take care since some hardware has driver bugs here (T46962).
76          * Further hardware workarounds should be made in gpu_extensions.c */
77         U.glalphaclip = (1.0f / 255);
78
79         /* default so DPI is detected automatically */
80         U.dpi = 0;
81         U.ui_scale = 1.0f;
82
83 #ifdef WITH_PYTHON_SECURITY
84         /* use alternative setting for security nuts
85          * otherwise we'd need to patch the binary blob - startup.blend.c */
86         U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE;
87 #else
88         U.flag &= ~USER_SCRIPT_AUTOEXEC_DISABLE;
89 #endif
90 }
91
92 /**
93  * New workspace design: Remove all screens/workspaces except of "Default" one and rename the workspace to "General".
94  * For compatibility, a new workspace has been created for each screen of old files,
95  * we only want one workspace and one screen in the default startup file however.
96  */
97 static void update_defaults_startup_workspaces(Main *bmain)
98 {
99         WorkSpace *workspace_default = NULL;
100
101         for (WorkSpace *workspace = bmain->workspaces.first, *workspace_next; workspace; workspace = workspace_next) {
102                 workspace_next = workspace->id.next;
103
104                 if (STREQ(workspace->id.name + 2, "Default")) {
105                         /* don't rename within iterator, renaming causes listbase to be re-sorted */
106                         workspace_default = workspace;
107                         BKE_viewrender_init(&workspace->view_render);
108                 }
109                 else {
110                         BKE_workspace_remove(bmain, workspace);
111                 }
112         }
113
114         /* rename "Default" workspace to "General" */
115         BKE_libblock_rename(bmain, (ID *)workspace_default, "General");
116         BLI_assert(BLI_listbase_count(BKE_workspace_layouts_get(workspace_default)) == 1);
117 }
118
119 /**
120  * Update defaults in startup.blend, without having to save and embed the file.
121  * This function can be emptied each time the startup.blend is updated. */
122 void BLO_update_defaults_startup_blend(Main *bmain)
123 {
124         for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
125                 BLI_strncpy(scene->view_render.engine_id, RE_engine_id_BLENDER_EEVEE, sizeof(scene->view_render.engine_id));
126
127                 scene->r.im_format.planes = R_IMF_PLANES_RGBA;
128                 scene->r.im_format.compress = 15;
129
130                 for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
131                         srl->freestyleConfig.sphere_radius = 0.1f;
132                         srl->pass_alpha_threshold = 0.5f;
133                 }
134
135                 if (scene->toolsettings) {
136                         ToolSettings *ts = scene->toolsettings;
137
138                         if (ts->sculpt) {
139                                 Sculpt *sculpt = ts->sculpt;
140                                 sculpt->paint.symmetry_flags |= PAINT_SYMM_X;
141                                 sculpt->flags |= SCULPT_DYNTOPO_COLLAPSE;
142                                 sculpt->detail_size = 12;
143                         }
144                         
145                         if (ts->vpaint) {
146                                 VPaint *vp = ts->vpaint;
147                                 vp->radial_symm[0] = vp->radial_symm[1] = vp->radial_symm[2] = 1;
148                         }
149
150                         if (ts->wpaint) {
151                                 VPaint *wp = ts->wpaint;
152                                 wp->radial_symm[0] = wp->radial_symm[1] = wp->radial_symm[2] = 1;
153                         }
154
155                         if (ts->gp_sculpt.brush[0].size == 0) {
156                                 GP_BrushEdit_Settings *gset = &ts->gp_sculpt;
157                                 GP_EditBrush_Data *brush;
158                                 
159                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_SMOOTH];
160                                 brush->size = 25;
161                                 brush->strength = 0.3f;
162                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF | GP_EDITBRUSH_FLAG_SMOOTH_PRESSURE;
163                                 
164                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_THICKNESS];
165                                 brush->size = 25;
166                                 brush->strength = 0.5f;
167                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
168                                 
169                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_STRENGTH];
170                                 brush->size = 25;
171                                 brush->strength = 0.5f;
172                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
173
174                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB];
175                                 brush->size = 50;
176                                 brush->strength = 0.3f;
177                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
178                                 
179                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PUSH];
180                                 brush->size = 25;
181                                 brush->strength = 0.3f;
182                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
183                                 
184                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_TWIST];
185                                 brush->size = 50;
186                                 brush->strength = 0.3f; // XXX?
187                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
188                                 
189                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_PINCH];
190                                 brush->size = 50;
191                                 brush->strength = 0.5f; // XXX?
192                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
193                                 
194                                 brush = &gset->brush[GP_EDITBRUSH_TYPE_RANDOMIZE];
195                                 brush->size = 25;
196                                 brush->strength = 0.5f;
197                                 brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF;
198                         }
199                         
200                         ts->gpencil_v3d_align = GP_PROJECT_VIEWSPACE;
201                         ts->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
202                         ts->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
203                         ts->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
204
205                         ParticleEditSettings *pset = &ts->particle;
206                         for (int a = 0; a < PE_TOT_BRUSH; a++) {
207                                 pset->brush[a].strength = 0.5f;
208                                 pset->brush[a].count = 10;
209                         }
210                         pset->brush[PE_BRUSH_CUT].strength = 1.0f;
211                 }
212
213                 scene->gm.lodflag |= SCE_LOD_USE_HYST;
214                 scene->gm.scehysteresis = 10;
215
216                 scene->r.ffcodecdata.audio_mixrate = 48000;
217         }
218
219         for (FreestyleLineStyle *linestyle = bmain->linestyle.first; linestyle; linestyle = linestyle->id.next) {
220                 linestyle->flag = LS_SAME_OBJECT | LS_NO_SORTING | LS_TEXTURE;
221                 linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
222                 linestyle->integration_type = LS_INTEGRATION_MEAN;
223                 linestyle->texstep = 1.0;
224                 linestyle->chain_count = 10;
225         }
226
227         update_defaults_startup_workspaces(bmain);
228
229         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
230                 for (ScrArea *area = screen->areabase.first; area; area = area->next) {
231                         for (SpaceLink *space_link = area->spacedata.first; space_link; space_link = space_link->next) {
232                                 if (space_link->spacetype == SPACE_CLIP) {
233                                         SpaceClip *space_clip = (SpaceClip *) space_link;
234                                         space_clip->flag &= ~SC_MANUAL_CALIBRATION;
235                                 }
236                         }
237
238                         for (ARegion *ar = area->regionbase.first; ar; ar = ar->next) {
239                                 /* Remove all stored panels, we want to use defaults (order, open/closed) as defined by UI code here! */
240                                 BLI_freelistN(&ar->panels);
241
242                                 /* some toolbars have been saved as initialized,
243                                  * we don't want them to have odd zoom-level or scrolling set, see: T47047 */
244                                 if (ELEM(ar->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS)) {
245                                         ar->v2d.flag &= ~V2D_IS_INITIALISED;
246                                 }
247                         }
248                 }
249         }
250
251         for (Mesh *me = bmain->mesh.first; me; me = me->id.next) {
252                 me->smoothresh = DEG2RADF(180.0f);
253                 me->flag &= ~ME_TWOSIDED;
254         }
255
256         for (Material *mat = bmain->mat.first; mat; mat = mat->id.next) {
257                 mat->line_col[0] = mat->line_col[1] = mat->line_col[2] = 0.0f;
258                 mat->line_col[3] = 1.0f;
259         }
260
261         {
262                 Object *ob;
263
264                 ob = (Object *)BKE_libblock_find_name_ex(bmain, ID_OB, "Camera");
265                 if (ob) {
266                         ob->rot[1] = 0.0f;
267                 }
268         }
269
270         {
271                 Brush *br;
272
273                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Fill");
274                 if (!br) {
275                         br = BKE_brush_add(bmain, "Fill", OB_MODE_TEXTURE_PAINT);
276                         br->imagepaint_tool = PAINT_TOOL_FILL;
277                         br->ob_mode = OB_MODE_TEXTURE_PAINT;
278                 }
279
280                 /* Vertex/Weight Paint */
281                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Average");
282                 if (!br) {
283                         br = BKE_brush_add(bmain, "Average", OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT);
284                         br->vertexpaint_tool = PAINT_BLEND_AVERAGE;
285                         br->ob_mode = OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT;
286                 }
287                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Smear");
288                 if (!br) {
289                         br = BKE_brush_add(bmain, "Smear", OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT);
290                         br->vertexpaint_tool = PAINT_BLEND_SMEAR;
291                         br->ob_mode = OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT;
292                 }
293
294                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Mask");
295                 if (br) {
296                         br->imagepaint_tool = PAINT_TOOL_MASK;
297                         br->ob_mode |= OB_MODE_TEXTURE_PAINT;
298                 }
299
300                 /* remove polish brush (flatten/contrast does the same) */
301                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Polish");
302                 if (br) {
303                         BKE_libblock_delete(bmain, br);
304                 }
305
306                 /* remove brush brush (huh?) from some modes (draw brushes do the same) */
307                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Brush");
308                 if (br) {
309                         BKE_libblock_delete(bmain, br);
310                 }
311
312                 /* remove draw brush from texpaint (draw brushes do the same) */
313                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Draw");
314                 if (br) {
315                         br->ob_mode &= ~OB_MODE_TEXTURE_PAINT;
316                 }
317
318                 /* rename twist brush to rotate brush to match rotate tool */
319                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Twist");
320                 if (br) {
321                         BKE_libblock_rename(bmain, &br->id, "Rotate");
322                 }
323
324                 /* use original normal for grab brush (otherwise flickers with normal weighting). */
325                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Grab");
326                 if (br) {
327                         br->flag |= BRUSH_ORIGINAL_NORMAL;
328                 }
329
330                 /* increase strength, better for smoothing method */
331                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Blur");
332                 if (br) {
333                         br->alpha = 1.0f;
334                 }
335
336                 br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Flatten/Contrast");
337                 if (br) {
338                         br->flag |= BRUSH_ACCUMULATE;
339                 }
340         }
341 }
342