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