3143c5069e619add8e3a60d3dfdd8709e2789288
[blender.git] / source / blender / blenloader / intern / versioning_userdef.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  * ***** END GPL LICENSE BLOCK *****
19  *
20  */
21
22 /** \file blender/blenloader/intern/versioning_userdef.c
23  *  \ingroup blenloader
24  *
25  * Version patch user preferences.
26  */
27
28 #include <string.h>
29
30 #include "BLI_math.h"
31 #include "BLI_utildefines.h"
32
33 #include "DNA_userdef_types.h"
34 #include "DNA_curve_types.h"
35 #include "DNA_windowmanager_types.h"
36
37 #include "BKE_addon.h"
38 #include "BKE_colorband.h"
39 #include "BKE_idprop.h"
40 #include "BKE_main.h"
41 #include "BKE_keyconfig.h"
42
43 #include "BLO_readfile.h"  /* Own include. */
44
45 #include "wm_event_types.h"
46
47 /* Disallow access to global userdef. */
48 #define U (_error_)
49
50
51 static void do_versions_theme(UserDef *userdef, bTheme *btheme)
52 {
53
54 #define USER_VERSION_ATLEAST(ver, subver) MAIN_VERSION_ATLEAST(userdef, ver, subver)
55         if (!USER_VERSION_ATLEAST(280, 20)) {
56                 memcpy(btheme, &U_theme_default, sizeof(*btheme));
57         }
58
59         if (!USER_VERSION_ATLEAST(280, 25)) {
60                 copy_v4_v4_char(btheme->tact.anim_preview_range, btheme->tact.anim_active);
61                 copy_v4_v4_char(btheme->tnla.anim_preview_range, btheme->tnla.anim_active);
62                 copy_v4_v4_char(btheme->tipo.anim_preview_range, btheme->tact.anim_active);
63         }
64
65         if (!USER_VERSION_ATLEAST(280, 26)) {
66                 copy_v4_v4_char(btheme->tui.icon_collection, U_theme_default.tui.icon_collection);
67                 copy_v4_v4_char(btheme->tui.icon_object, U_theme_default.tui.icon_object);
68                 copy_v4_v4_char(btheme->tui.icon_object_data, U_theme_default.tui.icon_object_data);
69                 copy_v4_v4_char(btheme->tui.icon_modifier, U_theme_default.tui.icon_modifier);
70                 copy_v4_v4_char(btheme->tui.icon_shading, U_theme_default.tui.icon_shading);
71         }
72
73         if (!USER_VERSION_ATLEAST(280, 27)) {
74                 copy_v4_v4_char(btheme->tact.shade2, U_theme_default.tact.shade2);
75                 copy_v4_v4_char(btheme->tact.hilite, U_theme_default.tact.hilite);
76                 copy_v4_v4_char(btheme->tact.group, U_theme_default.tact.group);
77                 copy_v4_v4_char(btheme->tact.group_active, U_theme_default.tact.group_active);
78                 copy_v4_v4_char(btheme->tact.strip_select, U_theme_default.tact.strip_select);
79                 copy_v4_v4_char(btheme->tact.ds_channel, U_theme_default.tact.ds_channel);
80                 copy_v4_v4_char(btheme->tact.ds_subchannel, U_theme_default.tact.ds_subchannel);
81                 copy_v4_v4_char(btheme->tact.keytype_movehold, U_theme_default.tact.keytype_movehold);
82                 copy_v4_v4_char(btheme->tact.keytype_movehold_select, U_theme_default.tact.keytype_movehold_select);
83         }
84
85         if (!USER_VERSION_ATLEAST(280, 28)) {
86                 copy_v4_v4_char(btheme->tact.ds_ipoline, U_theme_default.tact.ds_ipoline);
87         }
88
89         if (!USER_VERSION_ATLEAST(280, 29)) {
90                 copy_v4_v4_char(btheme->tbuts.navigation_bar, U_theme_default.ttopbar.header);
91         }
92         if (!USER_VERSION_ATLEAST(280, 31)) {
93                 copy_v4_v4_char(btheme->tclip.list_text, U_theme_default.tclip.list_text);
94         }
95
96         if (!USER_VERSION_ATLEAST(280, 36)) {
97                 copy_v4_v4_char(btheme->tui.wcol_state.inner_changed, U_theme_default.tui.wcol_state.inner_changed);
98                 copy_v4_v4_char(btheme->tui.wcol_state.inner_changed_sel, U_theme_default.tui.wcol_state.inner_changed_sel);
99         }
100
101         if (!USER_VERSION_ATLEAST(280, 39)) {
102                 copy_v4_v4_char(btheme->tclip.metadatabg, U_theme_default.tima.metadatabg);
103                 copy_v4_v4_char(btheme->tclip.metadatatext, U_theme_default.tima.metadatatext);
104         }
105
106         if (!USER_VERSION_ATLEAST(280, 40)) {
107                 copy_v4_v4_char(btheme->tuserpref.navigation_bar, U_theme_default.tuserpref.navigation_bar);
108                 copy_v4_v4_char(btheme->tuserpref.execution_buts, btheme->tuserpref.navigation_bar);
109         }
110
111         if (!USER_VERSION_ATLEAST(280, 41)) {
112                 copy_v4_v4_char(btheme->tv3d.back, U_theme_default.tv3d.back);
113         }
114
115 #undef USER_VERSION_ATLEAST
116 }
117
118 /* UserDef.flag */
119 #define USER_LMOUSESELECT (1 << 14)  /* deprecated */
120
121 static void do_version_select_mouse(UserDef *userdef, wmKeyMapItem *kmi)
122 {
123         /* Remove select/action mouse from user defined keymaps. */
124         enum {
125                 ACTIONMOUSE = 0x0005,
126                 SELECTMOUSE = 0x0006,
127                 EVT_TWEAK_A = 0x5005,
128                 EVT_TWEAK_S = 0x5006,
129         };
130         const bool left = (userdef->flag & USER_LMOUSESELECT) != 0;
131
132         switch (kmi->type) {
133                 case SELECTMOUSE: kmi->type = (left) ? LEFTMOUSE : RIGHTMOUSE; break;
134                 case ACTIONMOUSE: kmi->type = (left) ? RIGHTMOUSE : LEFTMOUSE; break;
135                 case EVT_TWEAK_S: kmi->type = (left) ? EVT_TWEAK_L : EVT_TWEAK_R; break;
136                 case EVT_TWEAK_A: kmi->type = (left) ? EVT_TWEAK_R : EVT_TWEAK_L; break;
137                 default: break;
138         }
139 }
140
141 /* patching UserDef struct and Themes */
142 void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef)
143 {
144
145 #define USER_VERSION_ATLEAST(ver, subver) MAIN_VERSION_ATLEAST(bmain, ver, subver)
146
147         /* the UserDef struct is not corrected with do_versions() .... ugh! */
148         if (userdef->wheellinescroll == 0) userdef->wheellinescroll = 3;
149         if (userdef->menuthreshold1 == 0) {
150                 userdef->menuthreshold1 = 5;
151                 userdef->menuthreshold2 = 2;
152         }
153         if (userdef->tb_leftmouse == 0) {
154                 userdef->tb_leftmouse = 5;
155                 userdef->tb_rightmouse = 5;
156         }
157         if (userdef->mixbufsize == 0) userdef->mixbufsize = 2048;
158         if (userdef->autokey_mode == 0) {
159                 /* 'add/replace' but not on */
160                 userdef->autokey_mode = 2;
161         }
162         if (userdef->savetime <= 0) {
163                 userdef->savetime = 1;
164 // XXX          error(STRINGIFY(BLENDER_STARTUP_FILE)" is buggy, please consider removing it.\n");
165         }
166         if (userdef->gizmo_size == 0) {
167                 userdef->gizmo_size = 75;
168                 userdef->gizmo_flag |= USER_GIZMO_DRAW;
169         }
170         if (userdef->pad_rot_angle == 0.0f)
171                 userdef->pad_rot_angle = 15.0f;
172
173         /* graph editor - unselected F-Curve visibility */
174         if (userdef->fcu_inactive_alpha == 0) {
175                 userdef->fcu_inactive_alpha = 0.25f;
176         }
177
178         if (!USER_VERSION_ATLEAST(192, 0)) {
179                 strcpy(userdef->sounddir, "/");
180         }
181
182         /* patch to set Dupli Armature */
183         if (!USER_VERSION_ATLEAST(220, 0)) {
184                 userdef->dupflag |= USER_DUP_ARM;
185         }
186
187         /* added seam, normal color, undo */
188         if (!USER_VERSION_ATLEAST(235, 0)) {
189                 userdef->uiflag |= USER_GLOBALUNDO;
190                 if (userdef->undosteps == 0) userdef->undosteps = 32;
191         }
192         if (!USER_VERSION_ATLEAST(236, 0)) {
193                 /* illegal combo... */
194                 if (userdef->flag & USER_LMOUSESELECT)
195                         userdef->flag &= ~USER_TWOBUTTONMOUSE;
196         }
197         if (!USER_VERSION_ATLEAST(240, 0)) {
198                 userdef->uiflag |= USER_PLAINMENUS;
199                 if (userdef->obcenter_dia == 0) userdef->obcenter_dia = 6;
200         }
201         if (!USER_VERSION_ATLEAST(242, 0)) {
202                 /* set defaults for 3D View rotating axis indicator */
203                 /* since size can't be set to 0, this indicates it's not saved in startup.blend */
204                 if (userdef->rvisize == 0) {
205                         userdef->rvisize = 15;
206                         userdef->rvibright = 8;
207                         userdef->uiflag |= USER_SHOW_GIZMO_AXIS;
208                 }
209
210         }
211         if (!USER_VERSION_ATLEAST(244, 0)) {
212                 /* set default number of recently-used files (if not set) */
213                 if (userdef->recent_files == 0) userdef->recent_files = 10;
214         }
215         if (!USER_VERSION_ATLEAST(245, 3)) {
216                 if (userdef->coba_weight.tot == 0)
217                         BKE_colorband_init(&userdef->coba_weight, true);
218         }
219         if (!USER_VERSION_ATLEAST(245, 3)) {
220                 userdef->flag |= USER_ADD_VIEWALIGNED | USER_ADD_EDITMODE;
221         }
222         if (!USER_VERSION_ATLEAST(250, 0)) {
223                 /* adjust grease-pencil distances */
224                 userdef->gp_manhattendist = 1;
225                 userdef->gp_euclideandist = 2;
226
227                 /* adjust default interpolation for new IPO-curves */
228                 userdef->ipo_new = BEZT_IPO_BEZ;
229         }
230
231         if (!USER_VERSION_ATLEAST(250, 3)) {
232                 /* new audio system */
233                 if (userdef->audiochannels == 0)
234                         userdef->audiochannels = 2;
235                 if (userdef->audioformat == 0)
236                         userdef->audioformat = 0x24;
237                 if (userdef->audiorate == 0)
238                         userdef->audiorate = 48000;
239         }
240
241         if (!USER_VERSION_ATLEAST(250, 8)) {
242                 wmKeyMap *km;
243
244                 for (km = userdef->user_keymaps.first; km; km = km->next) {
245                         if (STREQ(km->idname, "Armature_Sketch"))
246                                 strcpy(km->idname, "Armature Sketch");
247                         else if (STREQ(km->idname, "View3D"))
248                                 strcpy(km->idname, "3D View");
249                         else if (STREQ(km->idname, "View3D Generic"))
250                                 strcpy(km->idname, "3D View Generic");
251                         else if (STREQ(km->idname, "EditMesh"))
252                                 strcpy(km->idname, "Mesh");
253                         else if (STREQ(km->idname, "UVEdit"))
254                                 strcpy(km->idname, "UV Editor");
255                         else if (STREQ(km->idname, "Animation_Channels"))
256                                 strcpy(km->idname, "Animation Channels");
257                         else if (STREQ(km->idname, "GraphEdit Keys"))
258                                 strcpy(km->idname, "Graph Editor");
259                         else if (STREQ(km->idname, "GraphEdit Generic"))
260                                 strcpy(km->idname, "Graph Editor Generic");
261                         else if (STREQ(km->idname, "Action_Keys"))
262                                 strcpy(km->idname, "Dopesheet");
263                         else if (STREQ(km->idname, "NLA Data"))
264                                 strcpy(km->idname, "NLA Editor");
265                         else if (STREQ(km->idname, "Node Generic"))
266                                 strcpy(km->idname, "Node Editor");
267                         else if (STREQ(km->idname, "Logic Generic"))
268                                 strcpy(km->idname, "Logic Editor");
269                         else if (STREQ(km->idname, "File"))
270                                 strcpy(km->idname, "File Browser");
271                         else if (STREQ(km->idname, "FileMain"))
272                                 strcpy(km->idname, "File Browser Main");
273                         else if (STREQ(km->idname, "FileButtons"))
274                                 strcpy(km->idname, "File Browser Buttons");
275                         else if (STREQ(km->idname, "Buttons Generic"))
276                                 strcpy(km->idname, "Property Editor");
277                 }
278         }
279
280         if (!USER_VERSION_ATLEAST(252, 3)) {
281                 if (userdef->flag & USER_LMOUSESELECT)
282                         userdef->flag &= ~USER_TWOBUTTONMOUSE;
283         }
284         if (!USER_VERSION_ATLEAST(252, 4)) {
285                 /* default new handle type is auto handles */
286                 userdef->keyhandles_new = HD_AUTO;
287         }
288
289         if (!USER_VERSION_ATLEAST(257, 0)) {
290                 /* clear "AUTOKEY_FLAG_ONLYKEYINGSET" flag from userprefs,
291                  * so that it doesn't linger around from old configs like a ghost */
292                 userdef->autokey_flag &= ~AUTOKEY_FLAG_ONLYKEYINGSET;
293         }
294
295         if (!USER_VERSION_ATLEAST(260, 3)) {
296                 /* if new keyframes handle default is stuff "auto", make it "auto-clamped" instead
297                  * was changed in 260 as part of GSoC11, but version patch was wrong
298                  */
299                 if (userdef->keyhandles_new == HD_AUTO)
300                         userdef->keyhandles_new = HD_AUTO_ANIM;
301
302                 /* enable (Cycles) addon by default */
303                 BKE_addon_ensure(&userdef->addons, "cycles");
304         }
305
306         if (!USER_VERSION_ATLEAST(261, 4)) {
307                 userdef->use_16bit_textures = true;
308         }
309
310         if (!USER_VERSION_ATLEAST(267, 0)) {
311
312                 /* GL Texture Garbage Collection */
313                 if (userdef->textimeout == 0) {
314                         userdef->texcollectrate = 60;
315                         userdef->textimeout = 120;
316                 }
317                 if (userdef->memcachelimit <= 0) {
318                         userdef->memcachelimit = 32;
319                 }
320                 if (userdef->dbl_click_time == 0) {
321                         userdef->dbl_click_time = 350;
322                 }
323                 if (userdef->v2d_min_gridsize == 0) {
324                         userdef->v2d_min_gridsize = 35;
325                 }
326                 if (userdef->dragthreshold == 0)
327                         userdef->dragthreshold = 5;
328                 if (userdef->widget_unit == 0)
329                         userdef->widget_unit = 20;
330                 if (userdef->anisotropic_filter <= 0)
331                         userdef->anisotropic_filter = 1;
332
333                 if (userdef->ndof_sensitivity == 0.0f) {
334                         userdef->ndof_sensitivity = 1.0f;
335                         userdef->ndof_flag = (NDOF_LOCK_HORIZON | NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM | NDOF_SHOULD_ROTATE);
336                 }
337
338                 if (userdef->ndof_orbit_sensitivity == 0.0f) {
339                         userdef->ndof_orbit_sensitivity = userdef->ndof_sensitivity;
340
341                         if (!(userdef->flag & USER_TRACKBALL))
342                                 userdef->ndof_flag |= NDOF_TURNTABLE;
343                 }
344                 if (userdef->tweak_threshold == 0)
345                         userdef->tweak_threshold = 10;
346         }
347
348         /* NOTE!! from now on use userdef->versionfile and userdef->subversionfile */
349 #undef USER_VERSION_ATLEAST
350 #define USER_VERSION_ATLEAST(ver, subver) MAIN_VERSION_ATLEAST(userdef, ver, subver)
351
352         if (!USER_VERSION_ATLEAST(271, 5)) {
353                 userdef->pie_menu_radius = 100;
354                 userdef->pie_menu_threshold = 12;
355                 userdef->pie_animation_timeout = 6;
356         }
357
358         if (!USER_VERSION_ATLEAST(275, 2)) {
359                 userdef->ndof_deadzone = 0.1;
360         }
361
362         if (!USER_VERSION_ATLEAST(275, 4)) {
363                 userdef->node_margin = 80;
364         }
365
366         if (!USER_VERSION_ATLEAST(278, 6)) {
367                 /* Clear preference flags for re-use. */
368                 userdef->flag &= ~(
369                     USER_FLAG_NUMINPUT_ADVANCED | USER_FLAG_DEPRECATED_2 | USER_FLAG_DEPRECATED_3 |
370                     USER_FLAG_DEPRECATED_6 | USER_FLAG_DEPRECATED_7 |
371                     USER_FLAG_DEPRECATED_9 | USER_DEVELOPER_UI);
372                 userdef->uiflag &= ~(
373                     USER_HEADER_BOTTOM);
374                 userdef->transopts &= ~(
375                     USER_TR_DEPRECATED_2 | USER_TR_DEPRECATED_3 | USER_TR_DEPRECATED_4 |
376                     USER_TR_DEPRECATED_6 | USER_TR_DEPRECATED_7);
377
378                 userdef->uiflag |= USER_LOCK_CURSOR_ADJUST;
379         }
380
381
382         if (!USER_VERSION_ATLEAST(280, 20)) {
383                 userdef->gpu_viewport_quality = 0.6f;
384
385                 /* Reset theme, old themes will not be compatible with minor version updates from now on. */
386                 for (bTheme *btheme = userdef->themes.first; btheme; btheme = btheme->next) {
387                         memcpy(btheme, &U_theme_default, sizeof(*btheme));
388                 }
389
390                 /* Annotations - new layer color
391                  * Replace anything that used to be set if it looks like was left
392                  * on the old default (i.e. black), which most users used
393                  */
394                 if ((userdef->gpencil_new_layer_col[3] < 0.1f) || (userdef->gpencil_new_layer_col[0] < 0.1f)) {
395                         /* - New color matches the annotation pencil icon
396                          * - Non-full alpha looks better!
397                          */
398                         ARRAY_SET_ITEMS(userdef->gpencil_new_layer_col, 0.38f, 0.61f, 0.78f, 0.9f);
399                 }
400         }
401
402         if (!USER_VERSION_ATLEAST(280, 31)) {
403                 /* Remove select/action mouse from user defined keymaps. */
404                 for (wmKeyMap *keymap = userdef->user_keymaps.first; keymap; keymap = keymap->next) {
405                         for (wmKeyMapDiffItem *kmdi = keymap->diff_items.first; kmdi; kmdi = kmdi->next) {
406                                 if (kmdi->remove_item) {
407                                         do_version_select_mouse(userdef, kmdi->remove_item);
408                                 }
409                                 if (kmdi->add_item) {
410                                         do_version_select_mouse(userdef, kmdi->add_item);
411                                 }
412                         }
413
414                         for (wmKeyMapItem *kmi = keymap->items.first; kmi; kmi = kmi->next) {
415                                 do_version_select_mouse(userdef, kmi);
416                         }
417                 }
418         }
419
420         if (!USER_VERSION_ATLEAST(280, 33)) {
421                 /* Enable GLTF addon by default. */
422                 BKE_addon_ensure(&userdef->addons, "io_scene_gltf2");
423         }
424
425         if (!USER_VERSION_ATLEAST(280, 35)) {
426                 /* Preserve RMB select setting after moving to Python and changing default value. */
427                 if (USER_VERSION_ATLEAST(280, 32) || !(userdef->flag & USER_LMOUSESELECT)) {
428                         BKE_keyconfig_pref_set_select_mouse(userdef, 1, false);
429                 }
430
431                 userdef->flag &= ~USER_LMOUSESELECT;
432         }
433
434         if (!USER_VERSION_ATLEAST(280, 38)) {
435
436                 /* (keep this block even if it becomes empty). */
437                 copy_v4_fl4(userdef->light_param[0].vec, -0.580952, 0.228571, 0.781185, 0.0);
438                 copy_v4_fl4(userdef->light_param[0].col, 0.900000, 0.900000, 0.900000, 1.000000);
439                 copy_v4_fl4(userdef->light_param[0].spec, 0.318547, 0.318547, 0.318547, 1.000000);
440                 userdef->light_param[0].flag = 1;
441                 userdef->light_param[0].smooth = 0.1;
442
443                 copy_v4_fl4(userdef->light_param[1].vec, 0.788218, 0.593482, -0.162765, 0.0);
444                 copy_v4_fl4(userdef->light_param[1].col, 0.267115, 0.269928, 0.358840, 1.000000);
445                 copy_v4_fl4(userdef->light_param[1].spec, 0.090838, 0.090838, 0.090838, 1.000000);
446                 userdef->light_param[1].flag = 1;
447                 userdef->light_param[1].smooth = 0.25;
448
449                 copy_v4_fl4(userdef->light_param[2].vec, 0.696472, -0.696472, -0.172785, 0.0);
450                 copy_v4_fl4(userdef->light_param[2].col, 0.293216, 0.304662, 0.401968, 1.000000);
451                 copy_v4_fl4(userdef->light_param[2].spec, 0.069399, 0.020331, 0.020331, 1.000000);
452                 userdef->light_param[2].flag = 1;
453                 userdef->light_param[2].smooth = 0.4;
454
455                 copy_v4_fl4(userdef->light_param[3].vec, 0.021053, -0.989474, 0.143173, 0.0);
456                 copy_v4_fl4(userdef->light_param[3].col, 0.0, 0.0, 0.0, 1.0);
457                 copy_v4_fl4(userdef->light_param[3].spec, 0.072234, 0.082253, 0.162642, 1.000000);
458                 userdef->light_param[3].flag = 1;
459                 userdef->light_param[3].smooth = 0.7;
460
461                 copy_v4_fl4(userdef->light_ambient, 0.025000, 0.025000, 0.025000, 1.000000);
462
463                 userdef->flag &= ~(
464                         USER_FLAG_DEPRECATED_4);
465
466                 userdef->uiflag &= ~(
467                         USER_UIFLAG_DEPRECATED_8 |
468                         USER_UIFLAG_DEPRECATED_12 |
469                         USER_UIFLAG_DEPRECATED_22);
470         }
471
472         if (!USER_VERSION_ATLEAST(280, 41)) {
473                 /* (keep this block even if it becomes empty). */
474
475                 if (userdef->pie_tap_timeout == 0) {
476                         userdef->pie_tap_timeout = 20;
477                 }
478         }
479
480         /**
481          * Include next version bump.
482          */
483         {
484                 /* (keep this block even if it becomes empty). */
485         }
486
487         if (userdef->pixelsize == 0.0f)
488                 userdef->pixelsize = 1.0f;
489
490         if (userdef->image_draw_method == 0)
491                 userdef->image_draw_method = IMAGE_DRAW_METHOD_2DTEXTURE;
492
493         // we default to the first audio device
494         userdef->audiodevice = 0;
495
496         for (bTheme *btheme = userdef->themes.first; btheme; btheme = btheme->next) {
497                 do_versions_theme(userdef, btheme);
498         }
499 #undef USER_VERSION_ATLEAST
500
501 }
502
503 #undef USER_LMOUSESELECT