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