6ca7bba1ed2de03fee53ac6f72d8c1a782f80887
[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_utildefines.h"
31
32 #include "DNA_userdef_types.h"
33 #include "DNA_curve_types.h"
34 #include "DNA_windowmanager_types.h"
35
36 #include "BKE_addon.h"
37 #include "BKE_colorband.h"
38 #include "BKE_main.h"
39
40 #include "BLO_readfile.h"  /* Own include. */
41
42 #define U (_error_)
43
44 /* patching UserDef struct and Themes */
45 void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef)
46 {
47 #define USER_VERSION_ATLEAST(ver, subver) MAIN_VERSION_ATLEAST(bmain, ver, subver)
48
49         /* the UserDef struct is not corrected with do_versions() .... ugh! */
50         if (userdef->wheellinescroll == 0) userdef->wheellinescroll = 3;
51         if (userdef->menuthreshold1 == 0) {
52                 userdef->menuthreshold1 = 5;
53                 userdef->menuthreshold2 = 2;
54         }
55         if (userdef->tb_leftmouse == 0) {
56                 userdef->tb_leftmouse = 5;
57                 userdef->tb_rightmouse = 5;
58         }
59         if (userdef->mixbufsize == 0) userdef->mixbufsize = 2048;
60         if (userdef->autokey_mode == 0) {
61                 /* 'add/replace' but not on */
62                 userdef->autokey_mode = 2;
63         }
64         if (userdef->savetime <= 0) {
65                 userdef->savetime = 1;
66 // XXX          error(STRINGIFY(BLENDER_STARTUP_FILE)" is buggy, please consider removing it.\n");
67         }
68         if (userdef->gizmo_size == 0) {
69                 userdef->gizmo_size = 75;
70                 userdef->gizmo_flag |= USER_GIZMO_DRAW;
71         }
72         if (userdef->pad_rot_angle == 0.0f)
73                 userdef->pad_rot_angle = 15.0f;
74
75         /* graph editor - unselected F-Curve visibility */
76         if (userdef->fcu_inactive_alpha == 0) {
77                 userdef->fcu_inactive_alpha = 0.25f;
78         }
79
80         if (!USER_VERSION_ATLEAST(192, 0)) {
81                 strcpy(userdef->sounddir, "/");
82         }
83
84         /* patch to set Dupli Armature */
85         if (!USER_VERSION_ATLEAST(220, 0)) {
86                 userdef->dupflag |= USER_DUP_ARM;
87         }
88
89         /* added seam, normal color, undo */
90         if (!USER_VERSION_ATLEAST(235, 0)) {
91                 userdef->uiflag |= USER_GLOBALUNDO;
92                 if (userdef->undosteps == 0) userdef->undosteps = 32;
93         }
94         if (!USER_VERSION_ATLEAST(236, 0)) {
95                 /* illegal combo... */
96                 if (userdef->flag & USER_LMOUSESELECT)
97                         userdef->flag &= ~USER_TWOBUTTONMOUSE;
98         }
99         if (!USER_VERSION_ATLEAST(240, 0)) {
100                 userdef->uiflag |= USER_PLAINMENUS;
101                 if (userdef->obcenter_dia == 0) userdef->obcenter_dia = 6;
102         }
103         if (!USER_VERSION_ATLEAST(242, 0)) {
104                 /* set defaults for 3D View rotating axis indicator */
105                 /* since size can't be set to 0, this indicates it's not saved in startup.blend */
106                 if (userdef->rvisize == 0) {
107                         userdef->rvisize = 15;
108                         userdef->rvibright = 8;
109                         userdef->uiflag |= USER_SHOW_GIZMO_AXIS;
110                 }
111
112         }
113         if (!USER_VERSION_ATLEAST(244, 0)) {
114                 /* set default number of recently-used files (if not set) */
115                 if (userdef->recent_files == 0) userdef->recent_files = 10;
116         }
117         if (!USER_VERSION_ATLEAST(245, 3)) {
118                 if (userdef->coba_weight.tot == 0)
119                         BKE_colorband_init(&userdef->coba_weight, true);
120         }
121         if (!USER_VERSION_ATLEAST(245, 3)) {
122                 userdef->flag |= USER_ADD_VIEWALIGNED | USER_ADD_EDITMODE;
123         }
124         if (!USER_VERSION_ATLEAST(250, 0)) {
125                 /* adjust grease-pencil distances */
126                 userdef->gp_manhattendist = 1;
127                 userdef->gp_euclideandist = 2;
128
129                 /* adjust default interpolation for new IPO-curves */
130                 userdef->ipo_new = BEZT_IPO_BEZ;
131         }
132
133         if (!USER_VERSION_ATLEAST(250, 3)) {
134                 /* new audio system */
135                 if (userdef->audiochannels == 0)
136                         userdef->audiochannels = 2;
137                 if (userdef->audioformat == 0)
138                         userdef->audioformat = 0x24;
139                 if (userdef->audiorate == 0)
140                         userdef->audiorate = 48000;
141         }
142
143         if (!USER_VERSION_ATLEAST(250, 8)) {
144                 wmKeyMap *km;
145
146                 for (km = userdef->user_keymaps.first; km; km = km->next) {
147                         if (STREQ(km->idname, "Armature_Sketch"))
148                                 strcpy(km->idname, "Armature Sketch");
149                         else if (STREQ(km->idname, "View3D"))
150                                 strcpy(km->idname, "3D View");
151                         else if (STREQ(km->idname, "View3D Generic"))
152                                 strcpy(km->idname, "3D View Generic");
153                         else if (STREQ(km->idname, "EditMesh"))
154                                 strcpy(km->idname, "Mesh");
155                         else if (STREQ(km->idname, "UVEdit"))
156                                 strcpy(km->idname, "UV Editor");
157                         else if (STREQ(km->idname, "Animation_Channels"))
158                                 strcpy(km->idname, "Animation Channels");
159                         else if (STREQ(km->idname, "GraphEdit Keys"))
160                                 strcpy(km->idname, "Graph Editor");
161                         else if (STREQ(km->idname, "GraphEdit Generic"))
162                                 strcpy(km->idname, "Graph Editor Generic");
163                         else if (STREQ(km->idname, "Action_Keys"))
164                                 strcpy(km->idname, "Dopesheet");
165                         else if (STREQ(km->idname, "NLA Data"))
166                                 strcpy(km->idname, "NLA Editor");
167                         else if (STREQ(km->idname, "Node Generic"))
168                                 strcpy(km->idname, "Node Editor");
169                         else if (STREQ(km->idname, "Logic Generic"))
170                                 strcpy(km->idname, "Logic Editor");
171                         else if (STREQ(km->idname, "File"))
172                                 strcpy(km->idname, "File Browser");
173                         else if (STREQ(km->idname, "FileMain"))
174                                 strcpy(km->idname, "File Browser Main");
175                         else if (STREQ(km->idname, "FileButtons"))
176                                 strcpy(km->idname, "File Browser Buttons");
177                         else if (STREQ(km->idname, "Buttons Generic"))
178                                 strcpy(km->idname, "Property Editor");
179                 }
180         }
181
182         if (!USER_VERSION_ATLEAST(252, 3)) {
183                 if (userdef->flag & USER_LMOUSESELECT)
184                         userdef->flag &= ~USER_TWOBUTTONMOUSE;
185         }
186         if (!USER_VERSION_ATLEAST(252, 4)) {
187                 /* default new handle type is auto handles */
188                 userdef->keyhandles_new = HD_AUTO;
189         }
190
191         if (!USER_VERSION_ATLEAST(257, 0)) {
192                 /* clear "AUTOKEY_FLAG_ONLYKEYINGSET" flag from userprefs,
193                  * so that it doesn't linger around from old configs like a ghost */
194                 userdef->autokey_flag &= ~AUTOKEY_FLAG_ONLYKEYINGSET;
195         }
196
197         if (!USER_VERSION_ATLEAST(260, 3)) {
198                 /* if new keyframes handle default is stuff "auto", make it "auto-clamped" instead
199                  * was changed in 260 as part of GSoC11, but version patch was wrong
200                  */
201                 if (userdef->keyhandles_new == HD_AUTO)
202                         userdef->keyhandles_new = HD_AUTO_ANIM;
203
204                 /* enable (Cycles) addon by default */
205                 BKE_addon_ensure(&userdef->addons, "cycles");
206         }
207
208         if (!USER_VERSION_ATLEAST(261, 4)) {
209                 userdef->use_16bit_textures = true;
210         }
211
212         if (!USER_VERSION_ATLEAST(267, 0)) {
213
214                 /* GL Texture Garbage Collection */
215                 if (userdef->textimeout == 0) {
216                         userdef->texcollectrate = 60;
217                         userdef->textimeout = 120;
218                 }
219                 if (userdef->memcachelimit <= 0) {
220                         userdef->memcachelimit = 32;
221                 }
222                 if (userdef->dbl_click_time == 0) {
223                         userdef->dbl_click_time = 350;
224                 }
225                 if (userdef->v2d_min_gridsize == 0) {
226                         userdef->v2d_min_gridsize = 35;
227                 }
228                 if (userdef->dragthreshold == 0)
229                         userdef->dragthreshold = 5;
230                 if (userdef->widget_unit == 0)
231                         userdef->widget_unit = 20;
232                 if (userdef->anisotropic_filter <= 0)
233                         userdef->anisotropic_filter = 1;
234
235                 if (userdef->ndof_sensitivity == 0.0f) {
236                         userdef->ndof_sensitivity = 1.0f;
237                         userdef->ndof_flag = (NDOF_LOCK_HORIZON | NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM | NDOF_SHOULD_ROTATE);
238                 }
239
240                 if (userdef->ndof_orbit_sensitivity == 0.0f) {
241                         userdef->ndof_orbit_sensitivity = userdef->ndof_sensitivity;
242
243                         if (!(userdef->flag & USER_TRACKBALL))
244                                 userdef->ndof_flag |= NDOF_TURNTABLE;
245                 }
246                 if (userdef->tweak_threshold == 0)
247                         userdef->tweak_threshold = 10;
248         }
249
250         /* NOTE!! from now on use userdef->versionfile and userdef->subversionfile */
251 #undef USER_VERSION_ATLEAST
252 #define USER_VERSION_ATLEAST(ver, subver) MAIN_VERSION_ATLEAST(userdef, ver, subver)
253
254         if (!USER_VERSION_ATLEAST(271, 5)) {
255                 userdef->pie_menu_radius = 100;
256                 userdef->pie_menu_threshold = 12;
257                 userdef->pie_animation_timeout = 6;
258         }
259
260         if (!USER_VERSION_ATLEAST(275, 2)) {
261                 userdef->ndof_deadzone = 0.1;
262         }
263
264         if (!USER_VERSION_ATLEAST(275, 4)) {
265                 userdef->node_margin = 80;
266         }
267
268         if (!USER_VERSION_ATLEAST(278, 6)) {
269                 /* Clear preference flags for re-use. */
270                 userdef->flag &= ~(
271                     USER_FLAG_NUMINPUT_ADVANCED | USER_FLAG_DEPRECATED_2 | USER_FLAG_DEPRECATED_3 |
272                     USER_FLAG_DEPRECATED_6 | USER_FLAG_DEPRECATED_7 |
273                     USER_FLAG_DEPRECATED_9 | USER_DEVELOPER_UI);
274                 userdef->uiflag &= ~(
275                     USER_UIFLAG_DEPRECATED_7);
276                 userdef->transopts &= ~(
277                     USER_TR_DEPRECATED_2 | USER_TR_DEPRECATED_3 | USER_TR_DEPRECATED_4 |
278                     USER_TR_DEPRECATED_6 | USER_TR_DEPRECATED_7);
279
280                 userdef->uiflag |= USER_LOCK_CURSOR_ADJUST;
281         }
282
283
284         if (!USER_VERSION_ATLEAST(280, 20)) {
285                 userdef->gpu_viewport_quality = 0.6f;
286
287                 /* Reset theme, old themes will not be compatible with minor version updates from now on. */
288                 for (bTheme *btheme = userdef->themes.first; btheme; btheme = btheme->next) {
289                         memcpy(btheme, &U_theme_default, sizeof(*btheme));
290                 }
291
292                 /* Annotations - new layer color
293                  * Replace anything that used to be set if it looks like was left
294                  * on the old default (i.e. black), which most users used
295                  */
296                 if ((userdef->gpencil_new_layer_col[3] < 0.1f) || (userdef->gpencil_new_layer_col[0] < 0.1f)) {
297                         /* - New color matches the annotation pencil icon
298                          * - Non-full alpha looks better!
299                          */
300                         ARRAY_SET_ITEMS(userdef->gpencil_new_layer_col, 0.38f, 0.61f, 0.78f, 0.9f);
301                 }
302         }
303
304         /**
305          * Include next version bump.
306          */
307         {
308                 /* (keep this block even if it becomes empty). */
309         }
310
311         if (userdef->pixelsize == 0.0f)
312                 userdef->pixelsize = 1.0f;
313
314         if (userdef->image_draw_method == 0)
315                 userdef->image_draw_method = IMAGE_DRAW_METHOD_2DTEXTURE;
316
317         // we default to the first audio device
318         userdef->audiodevice = 0;
319
320         /* Not versioning, just avoid errors. */
321 #ifndef WITH_CYCLES
322         BKE_addon_remove_safe(&userdef->addons, "cycles");
323 #endif
324         /* this timer uses U */
325 // XXX  reset_autosave();
326 }