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