Use default movie cache size of 4GiB
[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 "MEM_guardedalloc.h"
29
30 #include "BLI_utildefines.h"
31 #include "BLI_listbase.h"
32 #include "BLI_math.h"
33 #include "BLI_string.h"
34
35 #include "DNA_gpencil_types.h"
36 #include "DNA_mesh_types.h"
37 #include "DNA_object_types.h"
38 #include "DNA_scene_types.h"
39 #include "DNA_screen_types.h"
40 #include "DNA_space_types.h"
41 #include "DNA_userdef_types.h"
42 #include "DNA_windowmanager_types.h"
43 #include "DNA_workspace_types.h"
44
45 #include "BKE_brush.h"
46 #include "BKE_colortools.h"
47 #include "BKE_layer.h"
48 #include "BKE_library.h"
49 #include "BKE_main.h"
50 #include "BKE_node.h"
51 #include "BKE_paint.h"
52 #include "BKE_screen.h"
53 #include "BKE_workspace.h"
54
55 #include "BLO_readfile.h"
56
57 /**
58  * Override values in in-memory startup.blend, avoids resaving for small changes.
59  */
60 void BLO_update_defaults_userpref_blend(void)
61 {
62         /* default so DPI is detected automatically */
63         U.dpi = 0;
64         U.ui_scale = 1.0f;
65
66 #ifdef WITH_PYTHON_SECURITY
67         /* use alternative setting for security nuts
68          * otherwise we'd need to patch the binary blob - startup.blend.c */
69         U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE;
70 #else
71         U.flag &= ~USER_SCRIPT_AUTOEXEC_DISABLE;
72 #endif
73
74         /* Ignore the theme saved in the blend file,
75          * instead use the theme from 'userdef_default_theme.c' */
76         {
77                 bTheme *theme = U.themes.first;
78                 memcpy(theme, &U_theme_default, sizeof(bTheme));
79         }
80
81         /* Leave temp directory empty, will then get appropriate value per OS. */
82         U.tempdir[0] = '\0';
83
84         /* Only enable tooltips translation by default, without actually enabling translation itself, for now. */
85         U.transopts = USER_TR_TOOLTIPS;
86         U.memcachelimit = 4096;
87 }
88
89 /**
90  * Update defaults in startup.blend, without having to save and embed the file.
91  * This function can be emptied each time the startup.blend is updated. */
92 void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
93 {
94         /* For all startup.blend files. */
95         for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
96                 for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
97                         for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
98                                 /* Remove all stored panels, we want to use defaults (order, open/closed) as defined by UI code here! */
99                                 BKE_area_region_panels_free(&ar->panels);
100
101                                 /* some toolbars have been saved as initialized,
102                                  * we don't want them to have odd zoom-level or scrolling set, see: T47047 */
103                                 if (ELEM(ar->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS)) {
104                                         ar->v2d.flag &= ~V2D_IS_INITIALISED;
105                                 }
106                         }
107
108                         for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
109                                 switch (sl->spacetype) {
110                                         case SPACE_VIEW3D:
111                                         {
112                                                 View3D *v3d = (View3D *)sl;
113                                                 v3d->overlay.weight_paint_mode_opacity = 1.0f;
114                                                 /* grease pencil settings */
115                                                 v3d->vertex_opacity = 1.0f;
116                                                 v3d->gp_flag |= V3D_GP_SHOW_EDIT_LINES;
117                                         }
118                                 }
119                         }
120                 }
121         }
122
123         if (app_template == NULL) {
124                 /* Name all screens by their workspaces (avoids 'Default.###' names). */
125                 {
126                         /* Default only has one window. */
127                         wmWindow *win = ((wmWindowManager *)bmain->wm.first)->windows.first;
128                         for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) {
129                                 WorkSpaceLayout *layout = BKE_workspace_hook_layout_for_workspace_get(win->workspace_hook, workspace);
130                                 bScreen *screen = layout->screen;
131                                 BLI_strncpy(screen->id.name + 2, workspace->id.name + 2, sizeof(screen->id.name) - 2);
132                         }
133                 }
134
135                 {
136                         /* 'UV Editing' should use UV mode. */
137                         bScreen *screen = BLI_findstring(&bmain->screen, "UV Editing", offsetof(ID, name) + 2);
138                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
139                                 for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
140                                         if (sl->spacetype == SPACE_IMAGE) {
141                                                 SpaceImage *sima = (SpaceImage *)sl;
142                                                 if (sima->mode == SI_MODE_VIEW) {
143                                                         sima->mode = SI_MODE_UV;
144                                                 }
145                                         }
146                                 }
147                         }
148                 }
149         }
150
151         /* For 2D animation template. */
152         if (app_template && STREQ(app_template, "2D_Animation")) {
153                 for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) {
154                         const char *name = workspace->id.name + 2;
155
156                         if (STREQ(name, "Drawing")) {
157                                 workspace->object_mode = OB_MODE_GPENCIL_PAINT;
158                         }
159                 }
160                 /* set object in drawing mode */
161                 for (Object *object = bmain->object.first; object; object = object->id.next) {
162                         if (object->type == OB_GPENCIL) {
163                                 bGPdata *gpd = (bGPdata *)object->data;
164                                 object->mode = OB_MODE_GPENCIL_PAINT;
165                                 gpd->flag |= GP_DATA_STROKE_PAINTMODE;
166                                 break;
167                         }
168                 }
169
170                 /* Be sure curfalloff is initializated */
171                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
172                         ToolSettings *ts = scene->toolsettings;
173                         if (ts->gp_sculpt.cur_falloff == NULL) {
174                                 ts->gp_sculpt.cur_falloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
175                                 CurveMapping *gp_falloff_curve = ts->gp_sculpt.cur_falloff;
176                                 curvemapping_initialize(gp_falloff_curve);
177                                 curvemap_reset(gp_falloff_curve->cm,
178                                         &gp_falloff_curve->clipr,
179                                         CURVE_PRESET_GAUSS,
180                                         CURVEMAP_SLOPE_POSITIVE);
181                         }
182                 }
183         }
184
185         /* For all builtin templates shipped with Blender. */
186         bool builtin_template = !app_template ||
187                                 STREQ(app_template, "2D_Animation") ||
188                                 STREQ(app_template, "Sculpting") ||
189                                 STREQ(app_template, "VFX") ||
190                                 STREQ(app_template, "Video_Editing");
191
192         if (builtin_template) {
193                 /* Clear all tools to use default options instead, ignore the tool saved in the file. */
194                 for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) {
195                         while (!BLI_listbase_is_empty(&workspace->tools)) {
196                                 BKE_workspace_tool_remove(workspace, workspace->tools.first);
197                         }
198                 }
199
200                 for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
201                         /* Hide channels in timelines. */
202                         for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
203                                 SpaceAction *saction = (sa->spacetype == SPACE_ACTION) ? sa->spacedata.first : NULL;
204
205                                 if (saction && saction->mode == SACTCONT_TIMELINE) {
206                                         for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
207                                                 if (ar->regiontype == RGN_TYPE_CHANNELS) {
208                                                         ar->flag |= RGN_FLAG_HIDDEN;
209                                                 }
210                                         }
211                                 }
212                         }
213                 }
214
215                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
216                         BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
217
218                         scene->r.cfra = 1.0f;
219                         scene->r.displaymode = R_OUTPUT_WINDOW;
220
221                         /* AV Sync break physics sim caching, disable until that is fixed. */
222                         if (!(app_template && STREQ(app_template, "Video_Editing"))) {
223                                 scene->audio.flag &= ~AUDIO_SYNC;
224                                 scene->flag &= ~SCE_FRAME_DROP;
225                         }
226
227                         /* Don't enable compositing nodes. */
228                         if (scene->nodetree) {
229                                 ntreeFreeTree(scene->nodetree);
230                                 MEM_freeN(scene->nodetree);
231                                 scene->nodetree = NULL;
232                                 scene->use_nodes = false;
233                         }
234
235                         /* Rename render layers. */
236                         BKE_view_layer_rename(bmain, scene, scene->view_layers.first, "View Layer");
237                 }
238
239                 for (Mesh *mesh = bmain->mesh.first; mesh; mesh = mesh->id.next) {
240                         /* Match default for new meshes. */
241                         mesh->smoothresh = DEG2RADF(30);
242                 }
243         }
244
245         /* Grease Pencil New Eraser Brush */
246         if (builtin_template) {
247                 Brush *br;
248                 /* Rename old Hard Eraser */
249                 br = (Brush *)BKE_libblock_find_name(bmain, ID_BR, "Eraser Hard");
250                 if (br) {
251                         strcpy(br->id.name, "BREraser Point");
252                 }
253                 for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
254                         ToolSettings *ts = scene->toolsettings;
255                         /* create new hard brush (only create one, but need ToolSettings) */
256                         br = (Brush *)BKE_libblock_find_name(bmain, ID_BR, "Eraser Hard");
257                         if (!br) {
258                                 Paint *paint = &ts->gp_paint->paint;
259                                 Brush *old_brush = paint->brush;
260
261                                 br = BKE_brush_add_gpencil(bmain, ts, "Eraser Hard");
262                                 br->size = 30.0f;
263                                 br->gpencil_settings->draw_strength = 1.0f;
264                                 br->gpencil_settings->flag = (GP_BRUSH_ENABLE_CURSOR | GP_BRUSH_DEFAULT_ERASER);
265                                 br->gpencil_settings->icon_id = GP_BRUSH_ICON_ERASE_HARD;
266                                 br->gpencil_tool = GPAINT_TOOL_ERASE;
267                                 br->gpencil_settings->eraser_mode = GP_BRUSH_ERASER_SOFT;
268                                 br->gpencil_settings->era_strength_f = 100.0f;
269                                 br->gpencil_settings->era_thickness_f = 50.0f;
270
271                                 /* back to default brush */
272                                 BKE_paint_brush_set(paint, old_brush);
273                         }
274                 }
275         }
276 }