Code cleanup: remove unused includes
[blender.git] / source / blender / blenloader / intern / versioning_270.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  * Contributor(s): Blender Foundation
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  *
22  */
23
24 /** \file blender/blenloader/intern/versioning_270.c
25  *  \ingroup blenloader
26  */
27
28 #include "BLI_utildefines.h"
29 #include "BLI_compiler_attrs.h"
30
31 /* for MinGW32 definition of NULL, could use BLI_blenlib.h instead too */
32 #include <stddef.h>
33
34 /* allow readfile to use deprecated functionality */
35 #define DNA_DEPRECATED_ALLOW
36
37 #include "DNA_constraint_types.h"
38 #include "DNA_sdna_types.h"
39 #include "DNA_space_types.h"
40 #include "DNA_screen_types.h"
41 #include "DNA_object_types.h"
42 #include "DNA_mesh_types.h"
43 #include "DNA_modifier_types.h"
44 #include "DNA_linestyle_types.h"
45
46 #include "DNA_genfile.h"
47
48 #include "BLI_blenlib.h"
49 #include "BLI_math.h"
50
51 #include "BKE_main.h"
52 #include "BKE_node.h"
53
54 #include "BLO_readfile.h"
55
56 #include "readfile.h"
57
58
59 static void do_version_constraints_radians_degrees_270_1(ListBase *lb)
60 {
61         bConstraint *con;
62
63         for (con = lb->first; con; con = con->next) {
64                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
65                         bTransformConstraint *data = (bTransformConstraint *)con->data;
66                         const float deg_to_rad_f = DEG2RADF(1.0f);
67
68                         if (data->from == TRANS_ROTATION) {
69                                 mul_v3_fl(data->from_min, deg_to_rad_f);
70                                 mul_v3_fl(data->from_max, deg_to_rad_f);
71                         }
72
73                         if (data->to == TRANS_ROTATION) {
74                                 mul_v3_fl(data->to_min, deg_to_rad_f);
75                                 mul_v3_fl(data->to_max, deg_to_rad_f);
76                         }
77                 }
78         }
79 }
80
81 static void do_version_constraints_radians_degrees_270_5(ListBase *lb)
82 {
83         bConstraint *con;
84
85         for (con = lb->first; con; con = con->next) {
86                 if (con->type == CONSTRAINT_TYPE_TRANSFORM) {
87                         bTransformConstraint *data = (bTransformConstraint *)con->data;
88
89                         if (data->from == TRANS_ROTATION) {
90                                 copy_v3_v3(data->from_min_rot, data->from_min);
91                                 copy_v3_v3(data->from_max_rot, data->from_max);
92                         }
93                         else if (data->from == TRANS_SCALE) {
94                                 copy_v3_v3(data->from_min_scale, data->from_min);
95                                 copy_v3_v3(data->from_max_scale, data->from_max);
96                         }
97
98                         if (data->to == TRANS_ROTATION) {
99                                 copy_v3_v3(data->to_min_rot, data->to_min);
100                                 copy_v3_v3(data->to_max_rot, data->to_max);
101                         }
102                         else if (data->to == TRANS_SCALE) {
103                                 copy_v3_v3(data->to_min_scale, data->to_min);
104                                 copy_v3_v3(data->to_max_scale, data->to_max);
105                         }
106                 }
107         }
108 }
109
110 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
111 {
112         if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
113
114                 if (!DNA_struct_elem_find(fd->filesdna, "BevelModifierData", "float", "profile")) {
115                         Object *ob;
116
117                         for (ob = main->object.first; ob; ob = ob->id.next) {
118                                 ModifierData *md;
119                                 for (md = ob->modifiers.first; md; md = md->next) {
120                                         if (md->type == eModifierType_Bevel) {
121                                                 BevelModifierData *bmd = (BevelModifierData *)md;
122                                                 bmd->profile = 0.5f;
123                                                 bmd->val_flags = MOD_BEVEL_AMT_OFFSET;
124                                         }
125                                 }
126                         }
127                 }
128
129                 /* nodes don't use fixed node->id any more, clean up */
130                 FOREACH_NODETREE(main, ntree, id) {
131                         if (ntree->type == NTREE_COMPOSIT) {
132                                 bNode *node;
133                                 for (node = ntree->nodes.first; node; node = node->next) {
134                                         if (ELEM(node->type, CMP_NODE_COMPOSITE, CMP_NODE_OUTPUT_FILE)) {
135                                                 node->id = NULL;
136                                         }
137                                 }
138                         }
139                 } FOREACH_NODETREE_END
140
141                 {
142                         bScreen *screen;
143
144                         for (screen = main->screen.first; screen; screen = screen->id.next) {
145                                 ScrArea *area;
146                                 for (area = screen->areabase.first; area; area = area->next) {
147                                         SpaceLink *space_link;
148                                         for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
149                                                 if (space_link->spacetype == SPACE_CLIP) {
150                                                         SpaceClip *space_clip = (SpaceClip *) space_link;
151                                                         if (space_clip->mode != SC_MODE_MASKEDIT) {
152                                                                 space_clip->mode = SC_MODE_TRACKING;
153                                                         }
154                                                 }
155                                         }
156                                 }
157                         }
158                 }
159
160                 if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingSettings", "float", "default_weight")) {
161                         MovieClip *clip;
162                         for (clip = main->movieclip.first; clip; clip = clip->id.next) {
163                                 clip->tracking.settings.default_weight = 1.0f;
164                         }
165                 }
166         }
167
168         if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
169                 Scene *sce;
170                 Object *ob;
171
172                 /* Update Transform constraint (another deg -> rad stuff). */
173                 for (ob = main->object.first; ob; ob = ob->id.next) {
174                         do_version_constraints_radians_degrees_270_1(&ob->constraints);
175
176                         if (ob->pose) {
177                                 /* Bones constraints! */
178                                 bPoseChannel *pchan;
179                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
180                                         do_version_constraints_radians_degrees_270_1(&pchan->constraints);
181                                 }
182                         }
183                 }
184
185                 for (sce = main->scene.first; sce; sce = sce->id.next) {
186                         if (sce->r.raytrace_structure == R_RAYSTRUCTURE_BLIBVH) {
187                                 sce->r.raytrace_structure = R_RAYSTRUCTURE_AUTO;
188                         }
189                 }
190         }
191
192         if (!MAIN_VERSION_ATLEAST(main, 270, 2)) {
193                 Mesh *me;
194
195                 /* Mesh smoothresh deg->rad. */
196                 for (me = main->mesh.first; me; me = me->id.next) {
197                         me->smoothresh = DEG2RADF(me->smoothresh);
198                 }
199         }
200
201         if (!MAIN_VERSION_ATLEAST(main, 270, 3)) {
202                 FreestyleLineStyle *linestyle;
203
204                 for (linestyle = main->linestyle.first; linestyle; linestyle = linestyle->id.next) {
205                         linestyle->flag |= LS_NO_SORTING;
206                         linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
207                         linestyle->integration_type = LS_INTEGRATION_MEAN;
208                 }
209         }
210
211         if (!MAIN_VERSION_ATLEAST(main, 270, 4)) {
212                 /* ui_previews were not handled correctly when copying areas, leading to corrupted files (see T39847).
213                  * This will always reset situation to a valid state.
214                  */
215                 bScreen *sc;
216
217                 for (sc = main->screen.first; sc; sc = sc->id.next) {
218                         ScrArea *sa;
219                         for (sa = sc->areabase.first; sa; sa = sa->next) {
220                                 SpaceLink *sl;
221
222                                 for (sl = sa->spacedata.first; sl; sl = sl->next) {
223                                         ARegion *ar;
224                                         ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
225
226                                         for (ar = lb->first; ar; ar = ar->next) {
227                                                 BLI_listbase_clear(&ar->ui_previews);
228                                         }
229                                 }
230                         }
231                 }
232         }
233
234         if (!MAIN_VERSION_ATLEAST(main, 270, 5)) {
235                 Object *ob;
236
237                 /* Update Transform constraint (again :|). */
238                 for (ob = main->object.first; ob; ob = ob->id.next) {
239                         do_version_constraints_radians_degrees_270_5(&ob->constraints);
240
241                         if (ob->pose) {
242                                 /* Bones constraints! */
243                                 bPoseChannel *pchan;
244                                 for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
245                                         do_version_constraints_radians_degrees_270_5(&pchan->constraints);
246                                 }
247                         }
248                 }
249         }
250
251         if (!DNA_struct_elem_find(fd->filesdna, "Material", "int", "mode2")) { /* will be replaced with version check when other new flag is added to mode2 */
252                 Material *ma;
253
254                 for (ma = main->mat.first; ma; ma = ma->id.next)
255                         ma->mode2 = MA_CASTSHADOW;
256         }
257 }