Merge branch 'master' into blender2.8
[blender.git] / source / blender / makesrna / intern / rna_scene.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 (2008).
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/makesrna/intern/rna_scene.c
24  *  \ingroup RNA
25  */
26
27 #include <stdlib.h>
28
29 #include "DNA_brush_types.h"
30 #include "DNA_group_types.h"
31 #include "DNA_modifier_types.h"
32 #include "DNA_particle_types.h"
33 #include "DNA_rigidbody_types.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_layer_types.h"
36 #include "DNA_linestyle_types.h"
37 #include "DNA_userdef_types.h"
38 #include "DNA_world_types.h"
39 #include "DNA_gpencil_types.h"
40
41 #include "IMB_imbuf_types.h"
42
43 #include "BLI_math.h"
44 #include "BLI_string_utils.h"
45
46 #include "BLT_translation.h"
47
48 #include "BKE_editmesh.h"
49 #include "BKE_paint.h"
50
51 #include "ED_object.h"
52
53 #include "GPU_extensions.h"
54
55 #include "DRW_engine.h"
56
57 #include "RNA_define.h"
58 #include "RNA_enum_types.h"
59
60 #include "rna_internal.h"
61
62 /* Include for Bake Options */
63 #include "RE_engine.h"
64 #include "RE_pipeline.h"
65
66 #ifdef WITH_QUICKTIME
67 #  include "quicktime_export.h"
68 #  include AUD_TYPES_H
69 #endif
70
71 #ifdef WITH_FFMPEG
72 #  include "BKE_writeffmpeg.h"
73 #  include <libavcodec/avcodec.h>
74 #  include <libavformat/avformat.h>
75 #  include "ffmpeg_compat.h"
76 #endif
77
78 #include "ED_render.h"
79
80 #include "WM_api.h"
81 #include "WM_types.h"
82
83 #include "BLI_threads.h"
84
85 #ifdef WITH_OPENEXR
86 EnumPropertyItem rna_enum_exr_codec_items[] = {
87         {R_IMF_EXR_CODEC_NONE, "NONE", 0, "None", ""},
88         {R_IMF_EXR_CODEC_PXR24, "PXR24", 0, "Pxr24 (lossy)", ""},
89         {R_IMF_EXR_CODEC_ZIP, "ZIP", 0, "ZIP (lossless)", ""},
90         {R_IMF_EXR_CODEC_PIZ, "PIZ", 0, "PIZ (lossless)", ""},
91         {R_IMF_EXR_CODEC_RLE, "RLE", 0, "RLE (lossless)", ""},
92         {R_IMF_EXR_CODEC_ZIPS, "ZIPS", 0, "ZIPS (lossless)", ""},
93         {R_IMF_EXR_CODEC_B44, "B44", 0, "B44 (lossy)", ""},
94         {R_IMF_EXR_CODEC_B44A, "B44A", 0, "B44A (lossy)", ""},
95         {R_IMF_EXR_CODEC_DWAA, "DWAA", 0, "DWAA (lossy)", ""},
96         /* NOTE: Commented out for until new OpenEXR is released, see T50673. */
97         /* {R_IMF_EXR_CODEC_DWAB, "DWAB", 0, "DWAB (lossy)", ""}, */
98         {0, NULL, 0, NULL, NULL}
99 };
100 #endif
101
102 #ifndef RNA_RUNTIME
103 static EnumPropertyItem uv_sculpt_relaxation_items[] = {
104         {UV_SCULPT_TOOL_RELAX_LAPLACIAN, "LAPLACIAN", 0, "Laplacian", "Use Laplacian method for relaxation"},
105         {UV_SCULPT_TOOL_RELAX_HC, "HC", 0, "HC", "Use HC method for relaxation"},
106         {0, NULL, 0, NULL, NULL}
107 };
108 #endif
109
110 EnumPropertyItem rna_enum_uv_sculpt_tool_items[] = {
111         {UV_SCULPT_TOOL_PINCH, "PINCH", 0, "Pinch", "Pinch UVs"},
112         {UV_SCULPT_TOOL_RELAX, "RELAX", 0, "Relax", "Relax UVs"},
113         {UV_SCULPT_TOOL_GRAB, "GRAB", 0, "Grab", "Grab UVs"},
114         {0, NULL, 0, NULL, NULL}
115 };
116
117
118 EnumPropertyItem rna_enum_snap_target_items[] = {
119         {SCE_SNAP_TARGET_CLOSEST, "CLOSEST", 0, "Closest", "Snap closest point onto target"},
120         {SCE_SNAP_TARGET_CENTER, "CENTER", 0, "Center", "Snap center onto target"},
121         {SCE_SNAP_TARGET_MEDIAN, "MEDIAN", 0, "Median", "Snap median onto target"},
122         {SCE_SNAP_TARGET_ACTIVE, "ACTIVE", 0, "Active", "Snap active onto target"},
123         {0, NULL, 0, NULL, NULL}
124 };
125         
126 EnumPropertyItem rna_enum_proportional_falloff_items[] = {
127         {PROP_SMOOTH, "SMOOTH", ICON_SMOOTHCURVE, "Smooth", "Smooth falloff"},
128         {PROP_SPHERE, "SPHERE", ICON_SPHERECURVE, "Sphere", "Spherical falloff"},
129         {PROP_ROOT, "ROOT", ICON_ROOTCURVE, "Root", "Root falloff"},
130         {PROP_INVSQUARE, "INVERSE_SQUARE", ICON_ROOTCURVE, "Inverse Square", "Inverse Square falloff"},
131         {PROP_SHARP, "SHARP", ICON_SHARPCURVE, "Sharp", "Sharp falloff"},
132         {PROP_LIN, "LINEAR", ICON_LINCURVE, "Linear", "Linear falloff"},
133         {PROP_CONST, "CONSTANT", ICON_NOCURVE, "Constant", "Constant falloff"},
134         {PROP_RANDOM, "RANDOM", ICON_RNDCURVE, "Random", "Random falloff"},
135         {0, NULL, 0, NULL, NULL}
136 };
137
138 /* subset of the enum - only curves, missing random and const */
139 EnumPropertyItem rna_enum_proportional_falloff_curve_only_items[] = {
140         {PROP_SMOOTH, "SMOOTH", ICON_SMOOTHCURVE, "Smooth", "Smooth falloff"},
141         {PROP_SPHERE, "SPHERE", ICON_SPHERECURVE, "Sphere", "Spherical falloff"},
142         {PROP_ROOT, "ROOT", ICON_ROOTCURVE, "Root", "Root falloff"},
143         {PROP_INVSQUARE, "INVERSE_SQUARE", ICON_ROOTCURVE, "Inverse Square", "Inverse Square falloff"},
144         {PROP_SHARP, "SHARP", ICON_SHARPCURVE, "Sharp", "Sharp falloff"},
145         {PROP_LIN, "LINEAR", ICON_LINCURVE, "Linear", "Linear falloff"},
146         {0, NULL, 0, NULL, NULL}
147 };
148
149
150 EnumPropertyItem rna_enum_proportional_editing_items[] = {
151         {PROP_EDIT_OFF, "DISABLED", ICON_PROP_OFF, "Disable", "Proportional Editing disabled"},
152         {PROP_EDIT_ON, "ENABLED", ICON_PROP_ON, "Enable", "Proportional Editing enabled"},
153         {PROP_EDIT_PROJECTED, "PROJECTED", ICON_PROP_ON, "Projected (2D)",
154                               "Proportional Editing using screen space locations"},
155         {PROP_EDIT_CONNECTED, "CONNECTED", ICON_PROP_CON, "Connected",
156                               "Proportional Editing using connected geometry only"},
157         {0, NULL, 0, NULL, NULL}
158 };
159
160 /* keep for operators, not used here */
161 EnumPropertyItem rna_enum_mesh_select_mode_items[] = {
162         {SCE_SELECT_VERTEX, "VERTEX", ICON_VERTEXSEL, "Vertex", "Vertex selection mode"},
163         {SCE_SELECT_EDGE, "EDGE", ICON_EDGESEL, "Edge", "Edge selection mode"},
164         {SCE_SELECT_FACE, "FACE", ICON_FACESEL, "Face", "Face selection mode"},
165         {0, NULL, 0, NULL, NULL}
166 };
167
168 EnumPropertyItem rna_enum_snap_element_items[] = {
169         {SCE_SNAP_MODE_INCREMENT, "INCREMENT", ICON_SNAP_INCREMENT, "Increment", "Snap to increments of grid"},
170         {SCE_SNAP_MODE_VERTEX, "VERTEX", ICON_SNAP_VERTEX, "Vertex", "Snap to vertices"},
171         {SCE_SNAP_MODE_EDGE, "EDGE", ICON_SNAP_EDGE, "Edge", "Snap to edges"},
172         {SCE_SNAP_MODE_FACE, "FACE", ICON_SNAP_FACE, "Face", "Snap to faces"},
173         {SCE_SNAP_MODE_VOLUME, "VOLUME", ICON_SNAP_VOLUME, "Volume", "Snap to volume"},
174         {0, NULL, 0, NULL, NULL}
175 };
176
177 EnumPropertyItem rna_enum_snap_node_element_items[] = {
178         {SCE_SNAP_MODE_GRID, "GRID", ICON_SNAP_GRID, "Grid", "Snap to grid"},
179         {SCE_SNAP_MODE_NODE_X, "NODE_X", ICON_SNAP_EDGE, "Node X", "Snap to left/right node border"},
180         {SCE_SNAP_MODE_NODE_Y, "NODE_Y", ICON_SNAP_EDGE, "Node Y", "Snap to top/bottom node border"},
181         {SCE_SNAP_MODE_NODE_XY, "NODE_XY", ICON_SNAP_EDGE, "Node X / Y", "Snap to any node border"},
182         {0, NULL, 0, NULL, NULL}
183 };
184
185 #ifndef RNA_RUNTIME
186 static EnumPropertyItem snap_uv_element_items[] = {
187         {SCE_SNAP_MODE_INCREMENT, "INCREMENT", ICON_SNAP_INCREMENT, "Increment", "Snap to increments of grid"},
188         {SCE_SNAP_MODE_VERTEX, "VERTEX", ICON_SNAP_VERTEX, "Vertex", "Snap to vertices"},
189         {0, NULL, 0, NULL, NULL}
190 };
191 #endif
192
193 EnumPropertyItem rna_enum_curve_fit_method_items[] = {
194         {CURVE_PAINT_FIT_METHOD_REFIT, "REFIT", 0, "Refit", "Incrementally re-fit the curve (high quality)"},
195         {CURVE_PAINT_FIT_METHOD_SPLIT, "SPLIT", 0, "Split", "Split the curve until the tolerance is met (fast)"},
196         {0, NULL, 0, NULL, NULL}};
197
198 /* workaround for duplicate enums,
199  * have each enum line as a define then conditionally set it or not
200  */
201
202 #define R_IMF_ENUM_BMP      {R_IMF_IMTYPE_BMP, "BMP", ICON_FILE_IMAGE, "BMP", "Output image in bitmap format"},
203 #define R_IMF_ENUM_IRIS     {R_IMF_IMTYPE_IRIS, "IRIS", ICON_FILE_IMAGE, "Iris", \
204                                                 "Output image in (old!) SGI IRIS format"},
205 #define R_IMF_ENUM_PNG      {R_IMF_IMTYPE_PNG, "PNG", ICON_FILE_IMAGE, "PNG", "Output image in PNG format"},
206 #define R_IMF_ENUM_JPEG     {R_IMF_IMTYPE_JPEG90, "JPEG", ICON_FILE_IMAGE, "JPEG", "Output image in JPEG format"},
207 #define R_IMF_ENUM_TAGA     {R_IMF_IMTYPE_TARGA, "TARGA", ICON_FILE_IMAGE, "Targa", "Output image in Targa format"},
208 #define R_IMF_ENUM_TAGA_RAW {R_IMF_IMTYPE_RAWTGA, "TARGA_RAW", ICON_FILE_IMAGE, "Targa Raw", \
209                                                   "Output image in uncompressed Targa format"},
210
211 #if 0 /* UNUSED (so far) */
212 #ifdef WITH_DDS
213 #  define R_IMF_ENUM_DDS {R_IMF_IMTYPE_DDS, "DDS", ICON_FILE_IMAGE, "DDS", "Output image in DDS format"},
214 #else
215 #  define R_IMF_ENUM_DDS
216 #endif
217 #endif
218
219 #ifdef WITH_OPENJPEG
220 #  define R_IMF_ENUM_JPEG2K {R_IMF_IMTYPE_JP2, "JPEG2000", ICON_FILE_IMAGE, "JPEG 2000", \
221                                                "Output image in JPEG 2000 format"},
222 #else
223 #  define R_IMF_ENUM_JPEG2K
224 #endif
225
226 #ifdef WITH_CINEON
227 #  define R_IMF_ENUM_CINEON {R_IMF_IMTYPE_CINEON, "CINEON", ICON_FILE_IMAGE, "Cineon", \
228                                                   "Output image in Cineon format"},
229 #  define R_IMF_ENUM_DPX    {R_IMF_IMTYPE_DPX, "DPX", ICON_FILE_IMAGE, "DPX", "Output image in DPX format"},
230 #else
231 #  define R_IMF_ENUM_CINEON
232 #  define R_IMF_ENUM_DPX
233 #endif
234
235 #ifdef WITH_OPENEXR
236 #  define R_IMF_ENUM_EXR_MULTILAYER  {R_IMF_IMTYPE_MULTILAYER, "OPEN_EXR_MULTILAYER", ICON_FILE_IMAGE, \
237                                                           "OpenEXR MultiLayer", \
238                                                           "Output image in multilayer OpenEXR format"},
239 #  define R_IMF_ENUM_EXR        {R_IMF_IMTYPE_OPENEXR, "OPEN_EXR", ICON_FILE_IMAGE, "OpenEXR", \
240                                                        "Output image in OpenEXR format"},
241 #else
242 #  define R_IMF_ENUM_EXR_MULTILAYER
243 #  define R_IMF_ENUM_EXR
244 #endif
245
246 #ifdef WITH_HDR
247 #  define R_IMF_ENUM_HDR  {R_IMF_IMTYPE_RADHDR, "HDR", ICON_FILE_IMAGE, "Radiance HDR", \
248                                                 "Output image in Radiance HDR format"},
249 #else
250 #  define R_IMF_ENUM_HDR
251 #endif
252
253 #ifdef WITH_TIFF
254 #  define R_IMF_ENUM_TIFF {R_IMF_IMTYPE_TIFF, "TIFF", ICON_FILE_IMAGE, "TIFF", "Output image in TIFF format"},
255 #else
256 #  define R_IMF_ENUM_TIFF
257 #endif
258
259 #define IMAGE_TYPE_ITEMS_IMAGE_ONLY                                           \
260         R_IMF_ENUM_BMP                                                            \
261         /* DDS save not supported yet R_IMF_ENUM_DDS */                           \
262         R_IMF_ENUM_IRIS                                                           \
263         R_IMF_ENUM_PNG                                                            \
264         R_IMF_ENUM_JPEG                                                           \
265         R_IMF_ENUM_JPEG2K                                                         \
266         R_IMF_ENUM_TAGA                                                           \
267         R_IMF_ENUM_TAGA_RAW                                                       \
268         {0, "", 0, " ", NULL},                                                    \
269         R_IMF_ENUM_CINEON                                                         \
270         R_IMF_ENUM_DPX                                                            \
271         R_IMF_ENUM_EXR_MULTILAYER                                                 \
272         R_IMF_ENUM_EXR                                                            \
273         R_IMF_ENUM_HDR                                                            \
274         R_IMF_ENUM_TIFF                                                           \
275
276
277 #ifdef RNA_RUNTIME
278 static EnumPropertyItem image_only_type_items[] = {
279
280         IMAGE_TYPE_ITEMS_IMAGE_ONLY
281
282         {0, NULL, 0, NULL, NULL}
283 };
284 #endif
285
286 EnumPropertyItem rna_enum_image_type_items[] = {
287         {0, "", 0, N_("Image"), NULL},
288
289         IMAGE_TYPE_ITEMS_IMAGE_ONLY
290
291         {0, "", 0, N_("Movie"), NULL},
292         {R_IMF_IMTYPE_AVIJPEG, "AVI_JPEG", ICON_FILE_MOVIE, "AVI JPEG", "Output video in AVI JPEG format"},
293         {R_IMF_IMTYPE_AVIRAW, "AVI_RAW", ICON_FILE_MOVIE, "AVI Raw", "Output video in AVI Raw format"},
294 #ifdef WITH_FRAMESERVER
295         {R_IMF_IMTYPE_FRAMESERVER, "FRAMESERVER", ICON_FILE_SCRIPT, "Frame Server", "Output image to a frameserver"},
296 #endif
297 #ifdef WITH_FFMPEG
298         {R_IMF_IMTYPE_FFMPEG, "FFMPEG", ICON_FILE_MOVIE, "FFmpeg video", "The most versatile way to output video files"},
299 #endif
300 #ifdef WITH_QUICKTIME
301         {R_IMF_IMTYPE_QUICKTIME, "QUICKTIME", ICON_FILE_MOVIE, "QuickTime", "Output video in Quicktime format"},
302 #endif
303         {0, NULL, 0, NULL, NULL}
304 };
305
306 EnumPropertyItem rna_enum_image_color_mode_items[] = {
307         {R_IMF_PLANES_BW, "BW", 0, "BW", "Images get saved in 8 bits grayscale (only PNG, JPEG, TGA, TIF)"},
308         {R_IMF_PLANES_RGB, "RGB", 0, "RGB", "Images are saved with RGB (color) data"},
309         {R_IMF_PLANES_RGBA, "RGBA", 0, "RGBA", "Images are saved with RGB and Alpha data (if supported)"},
310         {0, NULL, 0, NULL, NULL}
311 };
312
313 #ifdef RNA_RUNTIME
314 #define IMAGE_COLOR_MODE_BW   rna_enum_image_color_mode_items[0]
315 #define IMAGE_COLOR_MODE_RGB  rna_enum_image_color_mode_items[1]
316 #define IMAGE_COLOR_MODE_RGBA rna_enum_image_color_mode_items[2]
317 #endif
318
319 EnumPropertyItem rna_enum_image_color_depth_items[] = {
320         /* 1 (monochrome) not used */
321         {R_IMF_CHAN_DEPTH_8,   "8", 0, "8",  "8 bit color channels"},
322         {R_IMF_CHAN_DEPTH_10, "10", 0, "10", "10 bit color channels"},
323         {R_IMF_CHAN_DEPTH_12, "12", 0, "12", "12 bit color channels"},
324         {R_IMF_CHAN_DEPTH_16, "16", 0, "16", "16 bit color channels"},
325         /* 24 not used */
326         {R_IMF_CHAN_DEPTH_32, "32", 0, "32", "32 bit color channels"},
327         {0, NULL, 0, NULL, NULL}
328 };
329
330 EnumPropertyItem rna_enum_normal_space_items[] = {
331         {R_BAKE_SPACE_OBJECT, "OBJECT", 0, "Object", "Bake the normals in object space"},
332         {R_BAKE_SPACE_TANGENT, "TANGENT", 0, "Tangent", "Bake the normals in tangent space"},
333         {0, NULL, 0, NULL, NULL}
334 };
335
336 EnumPropertyItem rna_enum_normal_swizzle_items[] = {
337         {R_BAKE_POSX, "POS_X", 0, "+X", ""},
338         {R_BAKE_POSY, "POS_Y", 0, "+Y", ""},
339         {R_BAKE_POSZ, "POS_Z", 0, "+Z", ""},
340         {R_BAKE_NEGX, "NEG_X", 0, "-X", ""},
341         {R_BAKE_NEGY, "NEG_Y", 0, "-Y", ""},
342         {R_BAKE_NEGZ, "NEG_Z", 0, "-Z", ""},
343         {0, NULL, 0, NULL, NULL}
344 };
345
346 EnumPropertyItem rna_enum_bake_save_mode_items[] = {
347         {R_BAKE_SAVE_INTERNAL, "INTERNAL", 0, "Internal", "Save the baking map in an internal image data-block"},
348         {R_BAKE_SAVE_EXTERNAL, "EXTERNAL", 0, "External", "Save the baking map in an external file"},
349         {0, NULL, 0, NULL, NULL}
350 };
351
352 #define R_IMF_VIEWS_ENUM_IND      {R_IMF_VIEWS_INDIVIDUAL, "INDIVIDUAL", 0, "Individual", \
353                                    "Individual files for each view with the prefix as defined by the scene views"},
354 #define R_IMF_VIEWS_ENUM_S3D      {R_IMF_VIEWS_STEREO_3D, "STEREO_3D", 0, "Stereo 3D", \
355                                    "Single file with an encoded stereo pair"},
356 #define R_IMF_VIEWS_ENUM_MV       {R_IMF_VIEWS_MULTIVIEW, "MULTIVIEW", 0, "Multi-View", "Single file with all the views"},
357
358 EnumPropertyItem rna_enum_views_format_items[] = {
359         R_IMF_VIEWS_ENUM_IND
360         R_IMF_VIEWS_ENUM_S3D
361         {0, NULL, 0, NULL, NULL}
362 };
363
364 EnumPropertyItem rna_enum_views_format_multilayer_items[] = {
365         R_IMF_VIEWS_ENUM_IND
366         R_IMF_VIEWS_ENUM_MV
367         {0, NULL, 0, NULL, NULL}
368 };
369
370 EnumPropertyItem rna_enum_views_format_multiview_items[] = {
371         R_IMF_VIEWS_ENUM_IND
372         R_IMF_VIEWS_ENUM_S3D
373         R_IMF_VIEWS_ENUM_MV
374         {0, NULL, 0, NULL, NULL}
375 };
376
377 #undef R_IMF_VIEWS_ENUM_IND
378 #undef R_IMF_VIEWS_ENUM_S3D
379 #undef R_IMF_VIEWS_ENUM_MV
380
381 EnumPropertyItem rna_enum_stereo3d_display_items[] = {
382         {S3D_DISPLAY_ANAGLYPH, "ANAGLYPH", 0, "Anaglyph",
383          "Render views for left and right eyes as two differently filtered colors in a single image "
384          "(anaglyph glasses are required)"},
385         {S3D_DISPLAY_INTERLACE, "INTERLACE", 0, "Interlace",
386          "Render views for left and right eyes interlaced in a single image (3D-ready monitor is required)"},
387         {S3D_DISPLAY_PAGEFLIP, "TIMESEQUENTIAL", 0, "Time Sequential",
388          "Render alternate eyes (also known as page flip, quad buffer support in the graphic card is required)"},
389         {S3D_DISPLAY_SIDEBYSIDE, "SIDEBYSIDE", 0, "Side-by-Side", "Render views for left and right eyes side-by-side"},
390         {S3D_DISPLAY_TOPBOTTOM, "TOPBOTTOM", 0, "Top-Bottom", "Render views for left and right eyes one above another"},
391         {0, NULL, 0, NULL, NULL}
392 };
393
394 EnumPropertyItem rna_enum_stereo3d_anaglyph_type_items[] = {
395         {S3D_ANAGLYPH_REDCYAN, "RED_CYAN", 0, "Red-Cyan", ""},
396         {S3D_ANAGLYPH_GREENMAGENTA, "GREEN_MAGENTA", 0, "Green-Magenta", ""},
397         {S3D_ANAGLYPH_YELLOWBLUE, "YELLOW_BLUE", 0, "Yellow-Blue", ""},
398         {0, NULL, 0, NULL, NULL}
399 };
400
401 EnumPropertyItem rna_enum_stereo3d_interlace_type_items[] = {
402         {S3D_INTERLACE_ROW, "ROW_INTERLEAVED", 0, "Row Interleaved", ""},
403         {S3D_INTERLACE_COLUMN, "COLUMN_INTERLEAVED", 0, "Column Interleaved", ""},
404         {S3D_INTERLACE_CHECKERBOARD, "CHECKERBOARD_INTERLEAVED", 0, "Checkerboard Interleaved", ""},
405         {0, NULL, 0, NULL, NULL}
406 };
407
408 EnumPropertyItem rna_enum_bake_pass_filter_type_items[] = {
409         {R_BAKE_PASS_FILTER_NONE, "NONE", 0, "None", ""},
410         {R_BAKE_PASS_FILTER_AO, "AO", 0, "AO", ""},
411         {R_BAKE_PASS_FILTER_EMIT, "EMIT", 0, "Emit", ""},
412         {R_BAKE_PASS_FILTER_DIRECT, "DIRECT", 0, "Direct", ""},
413         {R_BAKE_PASS_FILTER_INDIRECT, "INDIRECT", 0, "Indirect", ""},
414         {R_BAKE_PASS_FILTER_COLOR, "COLOR", 0, "Color", ""},
415         {R_BAKE_PASS_FILTER_DIFFUSE, "DIFFUSE", 0, "Diffuse", ""},
416         {R_BAKE_PASS_FILTER_GLOSSY, "GLOSSY", 0, "Glossy", ""},
417         {R_BAKE_PASS_FILTER_TRANSM, "TRANSMISSION", 0, "Transmission", ""},
418         {R_BAKE_PASS_FILTER_SUBSURFACE, "SUBSURFACE", 0, "Subsurface", ""},
419         {0, NULL, 0, NULL, NULL}
420 };
421
422 #ifndef RNA_RUNTIME
423 static EnumPropertyItem rna_enum_gpencil_interpolation_mode_items[] = {
424         /* interpolation */
425         {0, "", 0, N_("Interpolation"), "Standard transitions between keyframes"},
426         {GP_IPO_LINEAR,   "LINEAR", ICON_IPO_LINEAR, "Linear", "Straight-line interpolation between A and B (i.e. no ease in/out)"},
427         {GP_IPO_CURVEMAP, "CUSTOM", ICON_IPO_BEZIER, "Custom", "Custom interpolation defined using a curve map"},
428         
429         /* easing */
430         {0, "", 0, N_("Easing (by strength)"), "Predefined inertial transitions, useful for motion graphics (from least to most ''dramatic'')"},
431         {GP_IPO_SINE, "SINE", ICON_IPO_SINE, "Sinusoidal", "Sinusoidal easing (weakest, almost linear but with a slight curvature)"},
432         {GP_IPO_QUAD, "QUAD", ICON_IPO_QUAD, "Quadratic", "Quadratic easing"},
433         {GP_IPO_CUBIC, "CUBIC", ICON_IPO_CUBIC, "Cubic", "Cubic easing"},
434         {GP_IPO_QUART, "QUART", ICON_IPO_QUART, "Quartic", "Quartic easing"},
435         {GP_IPO_QUINT, "QUINT", ICON_IPO_QUINT, "Quintic", "Quintic easing"},
436         {GP_IPO_EXPO, "EXPO", ICON_IPO_EXPO, "Exponential", "Exponential easing (dramatic)"},
437         {GP_IPO_CIRC, "CIRC", ICON_IPO_CIRC, "Circular", "Circular easing (strongest and most dynamic)"},
438         
439         {0, "", 0, N_("Dynamic Effects"), "Simple physics-inspired easing effects"},
440         {GP_IPO_BACK, "BACK", ICON_IPO_BACK, "Back", "Cubic easing with overshoot and settle"},
441         {GP_IPO_BOUNCE, "BOUNCE", ICON_IPO_BOUNCE, "Bounce", "Exponentially decaying parabolic bounce, like when objects collide"},
442         {GP_IPO_ELASTIC, "ELASTIC", ICON_IPO_ELASTIC, "Elastic", "Exponentially decaying sine wave, like an elastic band"},
443         
444         {0, NULL, 0, NULL, NULL}
445 };
446
447 #endif
448
449 EnumPropertyItem rna_enum_layer_collection_mode_settings_type_items[] = {
450         {COLLECTION_MODE_OBJECT, "OBJECT", 0, "Object", ""},
451         {COLLECTION_MODE_EDIT, "EDIT", 0, "Edit", ""},
452         {COLLECTION_MODE_PAINT_WEIGHT, "PAINT_WEIGHT", 0, "Weight Paint", ""},
453         {COLLECTION_MODE_PAINT_WEIGHT, "PAINT_VERTEX", 0, "Vertex Paint", ""},
454         {0, NULL, 0, NULL, NULL}
455 };
456
457 #ifdef RNA_RUNTIME
458
459 #include "DNA_anim_types.h"
460 #include "DNA_color_types.h"
461 #include "DNA_node_types.h"
462 #include "DNA_object_types.h"
463 #include "DNA_mesh_types.h"
464 #include "DNA_text_types.h"
465
466 #include "RNA_access.h"
467
468 #include "MEM_guardedalloc.h"
469
470 #include "BKE_brush.h"
471 #include "BKE_collection.h"
472 #include "BKE_colortools.h"
473 #include "BKE_context.h"
474 #include "BKE_global.h"
475 #include "BKE_idprop.h"
476 #include "BKE_image.h"
477 #include "BKE_layer.h"
478 #include "BKE_main.h"
479 #include "BKE_node.h"
480 #include "BKE_pointcache.h"
481 #include "BKE_scene.h"
482 #include "BKE_idprop.h"
483 #include "BKE_mesh.h"
484 #include "BKE_sound.h"
485 #include "BKE_screen.h"
486 #include "BKE_sequencer.h"
487 #include "BKE_animsys.h"
488 #include "BKE_freestyle.h"
489 #include "BKE_gpencil.h"
490
491 #include "DEG_depsgraph.h"
492 #include "DEG_depsgraph_build.h"
493
494 #include "ED_info.h"
495 #include "ED_node.h"
496 #include "ED_view3d.h"
497 #include "ED_mesh.h"
498 #include "ED_keyframing.h"
499 #include "ED_image.h"
500 #include "ED_scene.h"
501
502 #include "DEG_depsgraph.h"
503 #include "DEG_depsgraph_query.h"
504
505 #ifdef WITH_FREESTYLE
506 #include "FRS_freestyle.h"
507 #endif
508
509 /* Grease Pencil Interpolation settings */
510 static char *rna_GPencilInterpolateSettings_path(PointerRNA *UNUSED(ptr))
511 {
512         return BLI_strdup("tool_settings.gpencil_interpolate");
513 }
514
515 static void rna_GPencilInterpolateSettings_type_set(PointerRNA *ptr, int value)
516 {
517         GP_Interpolate_Settings *settings = (GP_Interpolate_Settings *)ptr->data;
518         
519         /* NOTE: This cast should be fine, as we have a small + finite set of values (eGP_Interpolate_Type)
520          * that should fit well within a char
521          */
522         settings->type = (char)value;
523         
524         /* init custom interpolation curve here now the first time it's used */
525         if ((settings->type == GP_IPO_CURVEMAP) &&
526             (settings->custom_ipo == NULL))
527         {
528                 settings->custom_ipo = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
529         }
530 }
531
532 /* Grease pencil Drawing Brushes */
533 static bGPDbrush *rna_GPencil_brush_new(ToolSettings *ts, const char *name, int setactive)
534 {
535         bGPDbrush *brush = BKE_gpencil_brush_addnew(ts, name, setactive != 0);
536
537         WM_main_add_notifier(NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
538
539         return brush;
540 }
541
542 static void rna_GPencil_brush_remove(ToolSettings *ts, ReportList *reports, PointerRNA *brush_ptr)
543 {
544         bGPDbrush *brush = brush_ptr->data;
545         if (BLI_findindex(&ts->gp_brushes, brush) == -1) {
546                 BKE_report(reports, RPT_ERROR, "Brush not found in grease pencil data");
547                 return;
548         }
549
550         BKE_gpencil_brush_delete(ts, brush);
551         RNA_POINTER_INVALIDATE(brush_ptr);
552
553         WM_main_add_notifier(NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
554 }
555
556 static PointerRNA rna_GPencilBrushes_active_get(PointerRNA *ptr)
557 {
558         ToolSettings *ts = (ToolSettings *) ptr->data;
559
560         bGPDbrush *brush;
561
562         for (brush = ts->gp_brushes.first; brush; brush = brush->next) {
563                 if (brush->flag & GP_BRUSH_ACTIVE) {
564                         break;
565                 }
566         }
567
568         if (brush) {
569                 return rna_pointer_inherit_refine(ptr, &RNA_GPencilBrush, brush);
570         }
571
572         return rna_pointer_inherit_refine(ptr, NULL, NULL);
573 }
574
575 static void rna_GPencilBrushes_active_set(PointerRNA *ptr, PointerRNA value)
576 {
577         ToolSettings *ts = (ToolSettings *) ptr->data;
578
579         bGPDbrush *brush;
580
581         for (brush = ts->gp_brushes.first; brush; brush = brush->next) {
582                 if (brush == value.data) {
583                         brush->flag |= GP_BRUSH_ACTIVE;
584                 }
585                 else {
586                         brush->flag &= ~GP_BRUSH_ACTIVE;
587                 }
588         }
589         WM_main_add_notifier(NC_GPENCIL | NA_EDITED, NULL);
590 }
591
592 static int rna_GPencilBrushes_index_get(PointerRNA *ptr)
593 {
594         ToolSettings *ts = (ToolSettings *) ptr->data;
595         bGPDbrush *brush = BKE_gpencil_brush_getactive(ts);
596
597         return BLI_findindex(&ts->gp_brushes, brush);
598 }
599
600 static void rna_GPencilBrushes_index_set(PointerRNA *ptr, int value)
601 {
602         ToolSettings *ts = (ToolSettings *) ptr->data;
603
604         bGPDbrush *brush = BLI_findlink(&ts->gp_brushes, value);
605
606         BKE_gpencil_brush_setactive(ts, brush);
607         WM_main_add_notifier(NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
608 }
609
610 static void rna_GPencilBrushes_index_range(PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax)
611 {
612         ToolSettings *ts = (ToolSettings *) ptr->data;
613
614         *min = 0;
615         *max = max_ii(0, BLI_listbase_count(&ts->gp_brushes) - 1);
616
617         *softmin = *min;
618         *softmax = *max;
619 }
620
621 static void rna_GPencilBrush_name_set(PointerRNA *ptr, const char *value)
622 {
623         ToolSettings *ts = ((Scene *) ptr->id.data)->toolsettings;
624         bGPDbrush *brush = ptr->data;
625
626         /* copy the new name into the name slot */
627         BLI_strncpy_utf8(brush->info, value, sizeof(brush->info));
628
629         BLI_uniquename(&ts->gp_brushes, brush, DATA_("GP_Brush"), '.', offsetof(bGPDbrush, info), sizeof(brush->info));
630 }
631
632 /* ----------------- end of Grease pencil drawing brushes ------------*/
633
634 static void rna_SpaceImageEditor_uv_sculpt_update(Main *bmain, Scene *scene, PointerRNA *UNUSED(ptr))
635 {
636         ED_space_image_uv_sculpt_update(bmain->wm.first, scene);
637 }
638
639 static int rna_Scene_object_bases_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
640 {
641         Scene *scene = (Scene *)ptr->data;
642         BaseLegacy *base;
643
644         for (base = scene->base.first; base; base = base->next) {
645                 if (STREQLEN(base->object->id.name + 2, key, sizeof(base->object->id.name) - 2)) {
646                         *r_ptr = rna_pointer_inherit_refine(ptr, &RNA_ObjectBaseLegacy, base);
647                         return true;
648                 }
649         }
650
651         return false;
652 }
653
654 static PointerRNA rna_Scene_objects_get(CollectionPropertyIterator *iter)
655 {
656         ListBaseIterator *internal = &iter->internal.listbase;
657
658         /* we are actually iterating a Base list, so override get */
659         return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((BaseLegacy *)internal->link)->object);
660 }
661
662 static BaseLegacy *rna_Scene_object_link(Scene *scene, bContext *C, ReportList *reports, Object *ob)
663 {
664         Scene *scene_act = CTX_data_scene(C);
665         BaseLegacy *base;
666
667         if (BKE_scene_base_find(scene, ob)) {
668                 BKE_reportf(reports, RPT_ERROR, "Object '%s' is already in scene '%s'", ob->id.name + 2, scene->id.name + 2);
669                 return NULL;
670         }
671
672         base = BKE_scene_base_add(scene, ob);
673         id_us_plus(&ob->id);
674
675         /* this is similar to what object_add_type and BKE_object_add do */
676         base->lay = scene->lay;
677
678         /* when linking to an inactive scene don't touch the layer */
679         if (scene == scene_act)
680                 ob->lay = base->lay;
681
682         /* TODO(sergey): Only update relations for the current scene. */
683         DEG_relations_tag_update(CTX_data_main(C));
684         DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
685
686         /* slows down importers too much, run scene.update() */
687         /* DEG_srelations_tag_update(G.main); */
688
689         WM_main_add_notifier(NC_SCENE | ND_OB_ACTIVE, scene);
690
691         return base;
692 }
693
694 static void rna_Scene_object_unlink(Scene *scene, ReportList *reports, Object *ob)
695 {
696         BaseLegacy *base = BKE_scene_base_find(scene, ob);
697         if (!base) {
698                 BKE_reportf(reports, RPT_ERROR, "Object '%s' is not in this scene '%s'", ob->id.name + 2, scene->id.name + 2);
699                 return;
700         }
701         if (base == scene->basact && ob->mode != OB_MODE_OBJECT) {
702                 BKE_reportf(reports, RPT_ERROR, "Object '%s' must be in object mode to unlink", ob->id.name + 2);
703                 return;
704         }
705         if (scene->basact == base) {
706                 scene->basact = NULL;
707         }
708
709         BKE_scene_base_unlink(scene, base);
710         MEM_freeN(base);
711
712         id_us_min(&ob->id);
713
714         /* needed otherwise the depgraph will contain freed objects which can crash, see [#20958] */
715         DEG_relations_tag_update(G.main);
716
717         WM_main_add_notifier(NC_SCENE | ND_OB_ACTIVE, scene);
718 }
719
720 static void rna_Scene_skgen_etch_template_set(PointerRNA *ptr, PointerRNA value)
721 {
722         ToolSettings *ts = (ToolSettings *)ptr->data;
723         if (value.data && ((Object *)value.data)->type == OB_ARMATURE)
724                 ts->skgen_template = value.data;
725         else
726                 ts->skgen_template = NULL;
727 }
728
729 static PointerRNA rna_Scene_active_object_get(PointerRNA *ptr)
730 {
731         Scene *scene = (Scene *)ptr->data;
732         return rna_pointer_inherit_refine(ptr, &RNA_Object, scene->basact ? scene->basact->object : NULL);
733 }
734
735 static void rna_Scene_active_object_set(PointerRNA *ptr, PointerRNA value)
736 {
737         Scene *scene = (Scene *)ptr->data;
738         if (value.data)
739                 scene->basact = BKE_scene_base_find(scene, (Object *)value.data);
740         else
741                 scene->basact = NULL;
742 }
743
744 static void rna_Scene_set_set(PointerRNA *ptr, PointerRNA value)
745 {
746         Scene *scene = (Scene *)ptr->data;
747         Scene *set = (Scene *)value.data;
748         Scene *nested_set;
749
750         for (nested_set = set; nested_set; nested_set = nested_set->set) {
751                 if (nested_set == scene)
752                         return;
753                 /* prevent eternal loops, set can point to next, and next to set, without problems usually */
754                 if (nested_set->set == set)
755                         return;
756         }
757
758         id_lib_extern((ID *)set);
759         scene->set = set;
760 }
761
762 static void rna_Scene_layer_set(PointerRNA *ptr, const int *values)
763 {
764         Scene *scene = (Scene *)ptr->data;
765
766         scene->lay = ED_view3d_scene_layer_set(scene->lay, values, &scene->layact);
767 }
768
769 static int rna_Scene_active_layer_get(PointerRNA *ptr)
770 {
771         Scene *scene = (Scene *)ptr->data;
772
773         return (int)(log(scene->layact) / M_LN2);
774 }
775
776 static void rna_Scene_view3d_update(Main *bmain, Scene *UNUSED(scene_unused), PointerRNA *ptr)
777 {
778         wmWindowManager *wm = bmain->wm.first;
779         Scene *scene = (Scene *)ptr->data;
780
781         WM_windows_scene_data_sync(&wm->windows, scene);
782 }
783
784 static void rna_Scene_layer_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
785 {
786         /* XXX We would need do_time=true here, else we can have update issues like [#36289]...
787          *     However, this has too much drawbacks (like slower layer switch, undesired updates...).
788          *     That's TODO for future DAG updates.
789          */
790         DEG_on_visible_update(bmain, false);
791
792         /* No need to sync scene data here (WM_windows_scene_data_sync), handled through notifier. */
793 }
794
795 static void rna_Scene_fps_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
796 {
797         BKE_sound_update_fps(scene);
798         BKE_sequencer_update_sound_bounds_all(scene);
799 }
800
801 static void rna_Scene_listener_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
802 {
803         BKE_sound_update_scene_listener(scene);
804 }
805
806 static void rna_Scene_volume_set(PointerRNA *ptr, float value)
807 {
808         Scene *scene = (Scene *)(ptr->data);
809
810         scene->audio.volume = value;
811         if (scene->sound_scene)
812                 BKE_sound_set_scene_volume(scene, value);
813 }
814
815 static void rna_Scene_framelen_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
816 {
817         scene->r.framelen = (float)scene->r.framapto / (float)scene->r.images;
818 }
819
820
821 static void rna_Scene_frame_current_set(PointerRNA *ptr, int value)
822 {
823         Scene *data = (Scene *)ptr->data;
824         
825         /* if negative frames aren't allowed, then we can't use them */
826         FRAMENUMBER_MIN_CLAMP(value);
827         data->r.cfra = value;
828 }
829
830 static float rna_Scene_frame_float_get(PointerRNA *ptr)
831 {
832         Scene *data = (Scene *)ptr->data;
833         return (float)data->r.cfra + data->r.subframe;
834 }
835
836 static void rna_Scene_frame_float_set(PointerRNA *ptr, float value)
837 {
838         Scene *data = (Scene *)ptr->data;
839         /* if negative frames aren't allowed, then we can't use them */
840         FRAMENUMBER_MIN_CLAMP(value);
841         data->r.cfra = (int)value;
842         data->r.subframe = value - data->r.cfra;
843 }
844
845 static float rna_Scene_frame_current_final_get(PointerRNA *ptr)
846 {
847         Scene *scene = (Scene *)ptr->data;
848
849         return BKE_scene_frame_get_from_ctime(scene, (float)scene->r.cfra);
850 }
851
852 static void rna_Scene_start_frame_set(PointerRNA *ptr, int value)
853 {
854         Scene *data = (Scene *)ptr->data;
855         /* MINFRAME not MINAFRAME, since some output formats can't taken negative frames */
856         CLAMP(value, MINFRAME, MAXFRAME);
857         data->r.sfra = value;
858
859         if (data->r.sfra >= data->r.efra) {
860                 data->r.efra = MIN2(data->r.sfra, MAXFRAME);
861         }
862 }
863
864 static void rna_Scene_end_frame_set(PointerRNA *ptr, int value)
865 {
866         Scene *data = (Scene *)ptr->data;
867         CLAMP(value, MINFRAME, MAXFRAME);
868         data->r.efra = value;
869
870         if (data->r.sfra >= data->r.efra) {
871                 data->r.sfra = MAX2(data->r.efra, MINFRAME);
872         }
873 }
874
875 static void rna_Scene_use_preview_range_set(PointerRNA *ptr, int value)
876 {
877         Scene *data = (Scene *)ptr->data;
878         
879         if (value) {
880                 /* copy range from scene if not set before */
881                 if ((data->r.psfra == data->r.pefra) && (data->r.psfra == 0)) {
882                         data->r.psfra = data->r.sfra;
883                         data->r.pefra = data->r.efra;
884                 }
885                 
886                 data->r.flag |= SCER_PRV_RANGE;
887         }
888         else
889                 data->r.flag &= ~SCER_PRV_RANGE;
890 }
891
892
893 static void rna_Scene_preview_range_start_frame_set(PointerRNA *ptr, int value)
894 {
895         Scene *data = (Scene *)ptr->data;
896         
897         /* check if enabled already */
898         if ((data->r.flag & SCER_PRV_RANGE) == 0) {
899                 /* set end of preview range to end frame, then clamp as per normal */
900                 /* TODO: or just refuse to set instead? */
901                 data->r.pefra = data->r.efra;
902         }
903         
904         /* now set normally */
905         CLAMP(value, MINAFRAME, data->r.pefra);
906         data->r.psfra = value;
907 }
908
909 static void rna_Scene_preview_range_end_frame_set(PointerRNA *ptr, int value)
910 {
911         Scene *data = (Scene *)ptr->data;
912         
913         /* check if enabled already */
914         if ((data->r.flag & SCER_PRV_RANGE) == 0) {
915                 /* set start of preview range to start frame, then clamp as per normal */
916                 /* TODO: or just refuse to set instead? */
917                 data->r.psfra = data->r.sfra;
918         }
919         
920         /* now set normally */
921         CLAMP(value, data->r.psfra, MAXFRAME);
922         data->r.pefra = value;
923 }
924
925 static void rna_Scene_show_subframe_update(Main *UNUSED(bmain), Scene *UNUSED(current_scene), PointerRNA *ptr)
926 {
927         Scene *scene = (Scene *)ptr->id.data;
928         scene->r.subframe = 0.0f;
929 }
930
931 static void rna_Scene_frame_update(Main *bmain, Scene *UNUSED(current_scene), PointerRNA *ptr)
932 {
933         Scene *scene = (Scene *)ptr->id.data;
934         BKE_sound_seek_scene(bmain, scene);
935 }
936
937 static PointerRNA rna_Scene_active_keying_set_get(PointerRNA *ptr)
938 {
939         Scene *scene = (Scene *)ptr->data;
940         return rna_pointer_inherit_refine(ptr, &RNA_KeyingSet, ANIM_scene_get_active_keyingset(scene));
941 }
942
943 static void rna_Scene_active_keying_set_set(PointerRNA *ptr, PointerRNA value)
944 {
945         Scene *scene = (Scene *)ptr->data;
946         KeyingSet *ks = (KeyingSet *)value.data;
947         
948         scene->active_keyingset = ANIM_scene_get_keyingset_index(scene, ks);
949 }
950
951 /* get KeyingSet index stuff for list of Keying Sets editing UI
952  *      - active_keyingset-1 since 0 is reserved for 'none'
953  *      - don't clamp, otherwise can never set builtins types as active...
954  */
955 static int rna_Scene_active_keying_set_index_get(PointerRNA *ptr)
956 {
957         Scene *scene = (Scene *)ptr->data;
958         return scene->active_keyingset - 1;
959 }
960
961 /* get KeyingSet index stuff for list of Keying Sets editing UI
962  *      - value+1 since 0 is reserved for 'none'
963  */
964 static void rna_Scene_active_keying_set_index_set(PointerRNA *ptr, int value)
965 {
966         Scene *scene = (Scene *)ptr->data;
967         scene->active_keyingset = value + 1;
968 }
969
970 /* XXX: evil... builtin_keyingsets is defined in keyingsets.c! */
971 /* TODO: make API function to retrieve this... */
972 extern ListBase builtin_keyingsets;
973
974 static void rna_Scene_all_keyingsets_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
975 {
976         Scene *scene = (Scene *)ptr->data;
977         
978         /* start going over the scene KeyingSets first, while we still have pointer to it
979          * but only if we have any Keying Sets to use...
980          */
981         if (scene->keyingsets.first)
982                 rna_iterator_listbase_begin(iter, &scene->keyingsets, NULL);
983         else
984                 rna_iterator_listbase_begin(iter, &builtin_keyingsets, NULL);
985 }
986
987 static void rna_Scene_all_keyingsets_next(CollectionPropertyIterator *iter)
988 {
989         ListBaseIterator *internal = &iter->internal.listbase;
990         KeyingSet *ks = (KeyingSet *)internal->link;
991         
992         /* if we've run out of links in Scene list, jump over to the builtins list unless we're there already */
993         if ((ks->next == NULL) && (ks != builtin_keyingsets.last))
994                 internal->link = (Link *)builtin_keyingsets.first;
995         else
996                 internal->link = (Link *)ks->next;
997                 
998         iter->valid = (internal->link != NULL);
999 }
1000
1001 static int rna_RenderSettings_stereoViews_skip(CollectionPropertyIterator *iter, void *UNUSED(data))
1002 {
1003         ListBaseIterator *internal = &iter->internal.listbase;
1004         SceneRenderView *srv = (SceneRenderView *)internal->link;
1005
1006         if ((STREQ(srv->name, STEREO_LEFT_NAME)) ||
1007             (STREQ(srv->name, STEREO_RIGHT_NAME)))
1008         {
1009                 return 0;
1010         }
1011
1012         return 1;
1013 };
1014
1015 static void rna_RenderSettings_stereoViews_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1016 {
1017         RenderData *rd = (RenderData *)ptr->data;
1018         rna_iterator_listbase_begin(iter, &rd->views, rna_RenderSettings_stereoViews_skip);
1019 }
1020
1021 static char *rna_RenderSettings_path(PointerRNA *UNUSED(ptr))
1022 {
1023         return BLI_sprintfN("render");
1024 }
1025
1026 static char *rna_ImageFormatSettings_path(PointerRNA *ptr)
1027 {
1028         ImageFormatData *imf = (ImageFormatData *)ptr->data;
1029         ID *id = ptr->id.data;
1030
1031         switch (GS(id->name)) {
1032                 case ID_SCE:
1033                 {
1034                         Scene *scene = (Scene *)id;
1035
1036                         if (&scene->r.im_format == imf) {
1037                                 return BLI_sprintfN("render.image_settings");
1038                         }
1039                         else if (&scene->r.bake.im_format == imf) {
1040                                 return BLI_sprintfN("render.bake.image_settings");
1041                         }
1042                         return BLI_sprintfN("..");
1043                 }
1044                 case ID_NT:
1045                 {
1046                         bNodeTree *ntree = (bNodeTree *)id;
1047                         bNode *node;
1048
1049                         for (node = ntree->nodes.first; node; node = node->next) {
1050                                 if (node->type == CMP_NODE_OUTPUT_FILE) {
1051                                         if (&((NodeImageMultiFile *)node->storage)->format == imf) {
1052                                                 return BLI_sprintfN("nodes['%s'].format", node->name);
1053                                         }
1054                                         else {
1055                                                 bNodeSocket *sock;
1056
1057                                                 for (sock = node->inputs.first; sock; sock = sock->next) {
1058                                                         NodeImageMultiFileSocket *sockdata = sock->storage;
1059                                                         if (&sockdata->format == imf) {
1060                                                                 return BLI_sprintfN("nodes['%s'].file_slots['%s'].format", node->name, sockdata->path);
1061                                                         }
1062                                                 }
1063                                         }
1064                                 }
1065                         }
1066                         return BLI_sprintfN("..");
1067                 }
1068                 default:
1069                         return BLI_sprintfN("..");
1070         }
1071 }
1072
1073 static int rna_RenderSettings_threads_get(PointerRNA *ptr)
1074 {
1075         RenderData *rd = (RenderData *)ptr->data;
1076         return BKE_render_num_threads(rd);
1077 }
1078
1079 static int rna_RenderSettings_threads_mode_get(PointerRNA *ptr)
1080 {
1081         RenderData *rd = (RenderData *)ptr->data;
1082         int override = BLI_system_num_threads_override_get();
1083
1084         if (override > 0)
1085                 return R_FIXED_THREADS;
1086         else
1087                 return (rd->mode & R_FIXED_THREADS);
1088 }
1089
1090 static int rna_RenderSettings_is_movie_format_get(PointerRNA *ptr)
1091 {
1092         RenderData *rd = (RenderData *)ptr->data;
1093         return BKE_imtype_is_movie(rd->im_format.imtype);
1094 }
1095
1096 static int rna_RenderSettings_save_buffers_get(PointerRNA *ptr)
1097 {
1098         RenderData *rd = (RenderData *)ptr->data;
1099         Scene *scene = (Scene *)ptr->id.data;
1100         
1101         if (!BKE_scene_use_new_shading_nodes(scene))
1102                 return (rd->scemode & (R_EXR_TILE_FILE | R_FULL_SAMPLE)) != 0;
1103         else 
1104                 return (rd->scemode & R_EXR_TILE_FILE) != 0;
1105 }
1106
1107 static void rna_ImageFormatSettings_file_format_set(PointerRNA *ptr, int value)
1108 {
1109         ImageFormatData *imf = (ImageFormatData *)ptr->data;
1110         ID *id = ptr->id.data;
1111         const bool is_render = (id && GS(id->name) == ID_SCE);
1112         /* see note below on why this is */
1113         const char chan_flag = BKE_imtype_valid_channels(imf->imtype, true) | (is_render ? IMA_CHAN_FLAG_BW : 0);
1114
1115         imf->imtype = value;
1116
1117         /* ensure depth and color settings match */
1118         if ( ((imf->planes == R_IMF_PLANES_BW) &&   !(chan_flag & IMA_CHAN_FLAG_BW)) ||
1119              ((imf->planes == R_IMF_PLANES_RGBA) && !(chan_flag & IMA_CHAN_FLAG_ALPHA)))
1120         {
1121                 imf->planes = R_IMF_PLANES_RGB;
1122         }
1123
1124         /* ensure usable depth */
1125         {
1126                 const int depth_ok = BKE_imtype_valid_depths(imf->imtype);
1127                 if ((imf->depth & depth_ok) == 0) {
1128                         /* set first available depth */
1129                         char depth_ls[] = {R_IMF_CHAN_DEPTH_32,
1130                                            R_IMF_CHAN_DEPTH_24,
1131                                            R_IMF_CHAN_DEPTH_16,
1132                                            R_IMF_CHAN_DEPTH_12,
1133                                            R_IMF_CHAN_DEPTH_10,
1134                                            R_IMF_CHAN_DEPTH_8,
1135                                            R_IMF_CHAN_DEPTH_1,
1136                                            0};
1137                         int i;
1138
1139                         for (i = 0; depth_ls[i]; i++) {
1140                                 if (depth_ok & depth_ls[i]) {
1141                                         imf->depth = depth_ls[i];
1142                                         break;
1143                                 }
1144                         }
1145                 }
1146         }
1147
1148         if (id && GS(id->name) == ID_SCE) {
1149                 Scene *scene = ptr->id.data;
1150                 RenderData *rd = &scene->r;
1151 #ifdef WITH_FFMPEG
1152                 BKE_ffmpeg_image_type_verify(rd, imf);
1153 #endif
1154 #ifdef WITH_QUICKTIME
1155                 quicktime_verify_image_type(rd, imf);
1156 #endif
1157                 (void)rd;
1158         }
1159 }
1160
1161 static EnumPropertyItem *rna_ImageFormatSettings_file_format_itemf(
1162         bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *UNUSED(r_free))
1163 {
1164         ID *id = ptr->id.data;
1165         if (id && GS(id->name) == ID_SCE) {
1166                 return rna_enum_image_type_items;
1167         }
1168         else {
1169                 return image_only_type_items;
1170         }
1171 }
1172
1173 static EnumPropertyItem *rna_ImageFormatSettings_color_mode_itemf(
1174         bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free)
1175 {
1176         ImageFormatData *imf = (ImageFormatData *)ptr->data;
1177         ID *id = ptr->id.data;
1178         const bool is_render = (id && GS(id->name) == ID_SCE);
1179
1180         /* note, we need to act differently for render
1181          * where 'BW' will force grayscale even if the output format writes
1182          * as RGBA, this is age old blender convention and not sure how useful
1183          * it really is but keep it for now - campbell */
1184         char chan_flag = BKE_imtype_valid_channels(imf->imtype, true) | (is_render ? IMA_CHAN_FLAG_BW : 0);
1185
1186 #ifdef WITH_FFMPEG
1187         /* a WAY more crappy case than B&W flag: depending on codec, file format MIGHT support
1188          * alpha channel. for example MPEG format with h264 codec can't do alpha channel, but
1189          * the same MPEG format with QTRLE codec can easily handle alpha channel.
1190          * not sure how to deal with such cases in a nicer way (sergey) */
1191         if (is_render) {
1192                 Scene *scene = ptr->id.data;
1193                 RenderData *rd = &scene->r;
1194
1195                 if (BKE_ffmpeg_alpha_channel_is_supported(rd))
1196                         chan_flag |= IMA_CHAN_FLAG_ALPHA;
1197         }
1198 #endif
1199
1200         if (chan_flag == (IMA_CHAN_FLAG_BW | IMA_CHAN_FLAG_RGB | IMA_CHAN_FLAG_ALPHA)) {
1201                 return rna_enum_image_color_mode_items;
1202         }
1203         else {
1204                 int totitem = 0;
1205                 EnumPropertyItem *item = NULL;
1206
1207                 if (chan_flag & IMA_CHAN_FLAG_BW)    RNA_enum_item_add(&item, &totitem, &IMAGE_COLOR_MODE_BW);
1208                 if (chan_flag & IMA_CHAN_FLAG_RGB)   RNA_enum_item_add(&item, &totitem, &IMAGE_COLOR_MODE_RGB);
1209                 if (chan_flag & IMA_CHAN_FLAG_ALPHA) RNA_enum_item_add(&item, &totitem, &IMAGE_COLOR_MODE_RGBA);
1210
1211                 RNA_enum_item_end(&item, &totitem);
1212                 *r_free = true;
1213
1214                 return item;
1215         }
1216 }
1217
1218 static EnumPropertyItem *rna_ImageFormatSettings_color_depth_itemf(
1219         bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free)
1220 {
1221         ImageFormatData *imf = (ImageFormatData *)ptr->data;
1222
1223         if (imf == NULL) {
1224                 return rna_enum_image_color_depth_items;
1225         }
1226         else {
1227                 const int depth_ok = BKE_imtype_valid_depths(imf->imtype);
1228                 const int is_float = ELEM(imf->imtype, R_IMF_IMTYPE_RADHDR, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER);
1229
1230                 EnumPropertyItem *item_8bit =  &rna_enum_image_color_depth_items[0];
1231                 EnumPropertyItem *item_10bit = &rna_enum_image_color_depth_items[1];
1232                 EnumPropertyItem *item_12bit = &rna_enum_image_color_depth_items[2];
1233                 EnumPropertyItem *item_16bit = &rna_enum_image_color_depth_items[3];
1234                 EnumPropertyItem *item_32bit = &rna_enum_image_color_depth_items[4];
1235
1236                 int totitem = 0;
1237                 EnumPropertyItem *item = NULL;
1238                 EnumPropertyItem tmp = {0, "", 0, "", ""};
1239
1240                 if (depth_ok & R_IMF_CHAN_DEPTH_8) {
1241                         RNA_enum_item_add(&item, &totitem, item_8bit);
1242                 }
1243
1244                 if (depth_ok & R_IMF_CHAN_DEPTH_10) {
1245                         RNA_enum_item_add(&item, &totitem, item_10bit);
1246                 }
1247
1248                 if (depth_ok & R_IMF_CHAN_DEPTH_12) {
1249                         RNA_enum_item_add(&item, &totitem, item_12bit);
1250                 }
1251
1252                 if (depth_ok & R_IMF_CHAN_DEPTH_16) {
1253                         if (is_float) {
1254                                 tmp = *item_16bit;
1255                                 tmp.name = "Float (Half)";
1256                                 RNA_enum_item_add(&item, &totitem, &tmp);
1257                         }
1258                         else {
1259                                 RNA_enum_item_add(&item, &totitem, item_16bit);
1260                         }
1261                 }
1262
1263                 if (depth_ok & R_IMF_CHAN_DEPTH_32) {
1264                         if (is_float) {
1265                                 tmp = *item_32bit;
1266                                 tmp.name = "Float (Full)";
1267                                 RNA_enum_item_add(&item, &totitem, &tmp);
1268                         }
1269                         else {
1270                                 RNA_enum_item_add(&item, &totitem, item_32bit);
1271                         }
1272                 }
1273
1274                 RNA_enum_item_end(&item, &totitem);
1275                 *r_free = true;
1276
1277                 return item;
1278         }
1279 }
1280
1281 static EnumPropertyItem *rna_ImageFormatSettings_views_format_itemf(
1282         bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *UNUSED(r_free))
1283 {
1284         ImageFormatData *imf = (ImageFormatData *)ptr->data;
1285
1286         if (imf == NULL) {
1287                 return rna_enum_views_format_items;
1288         }
1289         else if (imf->imtype == R_IMF_IMTYPE_OPENEXR) {
1290                 return rna_enum_views_format_multiview_items;
1291         }
1292         else if (imf->imtype == R_IMF_IMTYPE_MULTILAYER) {
1293                 return rna_enum_views_format_multilayer_items;
1294         }
1295         else {
1296                 return rna_enum_views_format_items;
1297         }
1298 }
1299
1300 #ifdef WITH_OPENEXR
1301         /* OpenEXR */
1302
1303 static EnumPropertyItem *rna_ImageFormatSettings_exr_codec_itemf(
1304         bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free)
1305 {
1306         ImageFormatData *imf = (ImageFormatData *)ptr->data;
1307
1308         EnumPropertyItem *item = NULL;
1309         int i = 1, totitem = 0;
1310
1311         if (imf->depth == 16)
1312                 return rna_enum_exr_codec_items; /* All compression types are defined for halfs */
1313
1314         for (i = 0; i < R_IMF_EXR_CODEC_MAX; i++) {
1315                 if ((i == R_IMF_EXR_CODEC_B44 || i == R_IMF_EXR_CODEC_B44A)) {
1316                         continue; /* B44 and B44A are not defined for 32 bit floats */
1317                 }
1318
1319                 RNA_enum_item_add(&item, &totitem, &rna_enum_exr_codec_items[i]);
1320         }
1321
1322         RNA_enum_item_end(&item, &totitem);
1323         *r_free = true;
1324
1325         return item;
1326 }
1327
1328 #endif
1329 static int rna_SceneRender_file_ext_length(PointerRNA *ptr)
1330 {
1331         RenderData *rd = (RenderData *)ptr->data;
1332         char ext[8];
1333         ext[0] = '\0';
1334         BKE_image_path_ensure_ext_from_imformat(ext, &rd->im_format);
1335         return strlen(ext);
1336 }
1337
1338 static void rna_SceneRender_file_ext_get(PointerRNA *ptr, char *str)
1339 {
1340         RenderData *rd = (RenderData *)ptr->data;
1341         str[0] = '\0';
1342         BKE_image_path_ensure_ext_from_imformat(str, &rd->im_format);
1343 }
1344
1345 #ifdef WITH_QUICKTIME
1346 static int rna_RenderSettings_qtcodecsettings_codecType_get(PointerRNA *ptr)
1347 {
1348         QuicktimeCodecSettings *settings = (QuicktimeCodecSettings *)ptr->data;
1349         
1350         return quicktime_rnatmpvalue_from_videocodectype(settings->codecType);
1351 }
1352
1353 static void rna_RenderSettings_qtcodecsettings_codecType_set(PointerRNA *ptr, int value)
1354 {
1355         QuicktimeCodecSettings *settings = (QuicktimeCodecSettings *)ptr->data;
1356
1357         settings->codecType = quicktime_videocodecType_from_rnatmpvalue(value);
1358 }
1359
1360 static EnumPropertyItem *rna_RenderSettings_qtcodecsettings_codecType_itemf(
1361         bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
1362 {
1363         EnumPropertyItem *item = NULL;
1364         EnumPropertyItem tmp = {0, "", 0, "", ""};
1365         QuicktimeCodecTypeDesc *codecTypeDesc;
1366         int i = 1, totitem = 0;
1367
1368         for (i = 0; i < quicktime_get_num_videocodecs(); i++) {
1369                 codecTypeDesc = quicktime_get_videocodecType_desc(i);
1370                 if (!codecTypeDesc) break;
1371
1372                 tmp.value = codecTypeDesc->rnatmpvalue;
1373                 tmp.identifier = codecTypeDesc->codecName;
1374                 tmp.name = codecTypeDesc->codecName;
1375                 RNA_enum_item_add(&item, &totitem, &tmp);
1376         }
1377         
1378         RNA_enum_item_end(&item, &totitem);
1379         *r_free = true;
1380         
1381         return item;
1382 }
1383
1384 static int rna_RenderSettings_qtcodecsettings_audiocodecType_get(PointerRNA *ptr)
1385 {
1386         QuicktimeCodecSettings *settings = (QuicktimeCodecSettings *)ptr->data;
1387         
1388         return quicktime_rnatmpvalue_from_audiocodectype(settings->audiocodecType);
1389 }
1390
1391 static void rna_RenderSettings_qtcodecsettings_audiocodecType_set(PointerRNA *ptr, int value)
1392 {
1393         QuicktimeCodecSettings *settings = (QuicktimeCodecSettings *)ptr->data;
1394         
1395         settings->audiocodecType = quicktime_audiocodecType_from_rnatmpvalue(value);
1396 }
1397
1398 static EnumPropertyItem *rna_RenderSettings_qtcodecsettings_audiocodecType_itemf(
1399         bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
1400 {
1401         EnumPropertyItem *item = NULL;
1402         EnumPropertyItem tmp = {0, "", 0, "", ""};
1403         QuicktimeCodecTypeDesc *codecTypeDesc;
1404         int i = 1, totitem = 0;
1405         
1406         for (i = 0; i < quicktime_get_num_audiocodecs(); i++) {
1407                 codecTypeDesc = quicktime_get_audiocodecType_desc(i);
1408                 if (!codecTypeDesc) break;
1409                 
1410                 tmp.value = codecTypeDesc->rnatmpvalue;
1411                 tmp.identifier = codecTypeDesc->codecName;
1412                 tmp.name = codecTypeDesc->codecName;
1413                 RNA_enum_item_add(&item, &totitem, &tmp);
1414         }
1415         
1416         RNA_enum_item_end(&item, &totitem);
1417         *r_free = true;
1418         
1419         return item;
1420 }
1421 #endif
1422
1423 #ifdef WITH_FFMPEG
1424 static void rna_FFmpegSettings_lossless_output_set(PointerRNA *ptr, int value)
1425 {
1426         Scene *scene = (Scene *) ptr->id.data;
1427         RenderData *rd = &scene->r;
1428
1429         if (value)
1430                 rd->ffcodecdata.flags |= FFMPEG_LOSSLESS_OUTPUT;
1431         else
1432                 rd->ffcodecdata.flags &= ~FFMPEG_LOSSLESS_OUTPUT;
1433
1434         BKE_ffmpeg_codec_settings_verify(rd);
1435 }
1436
1437 static void rna_FFmpegSettings_codec_settings_update(Main *UNUSED(bmain), Scene *UNUSED(scene_unused), PointerRNA *ptr)
1438 {
1439         Scene *scene = (Scene *) ptr->id.data;
1440         RenderData *rd = &scene->r;
1441
1442         BKE_ffmpeg_codec_settings_verify(rd);
1443 }
1444 #endif
1445
1446 static int rna_RenderSettings_active_layer_index_get(PointerRNA *ptr)
1447 {
1448         RenderData *rd = (RenderData *)ptr->data;
1449         return rd->actlay;
1450 }
1451
1452 static void rna_RenderSettings_active_layer_index_set(PointerRNA *ptr, int value)
1453 {
1454         RenderData *rd = (RenderData *)ptr->data;
1455         int num_layers = BLI_listbase_count(&rd->layers);
1456         rd->actlay = min_ff(value, num_layers - 1);
1457 }
1458
1459 static void rna_RenderSettings_active_layer_index_range(
1460         PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
1461 {
1462         RenderData *rd = (RenderData *)ptr->data;
1463
1464         *min = 0;
1465         *max = max_ii(0, BLI_listbase_count(&rd->layers) - 1);
1466 }
1467
1468 static PointerRNA rna_RenderSettings_active_layer_get(PointerRNA *ptr)
1469 {
1470         RenderData *rd = (RenderData *)ptr->data;
1471         SceneRenderLayer *srl = BLI_findlink(&rd->layers, rd->actlay);
1472         
1473         return rna_pointer_inherit_refine(ptr, &RNA_SceneRenderLayer, srl);
1474 }
1475
1476 static void rna_RenderSettings_active_layer_set(PointerRNA *ptr, PointerRNA value)
1477 {
1478         RenderData *rd = (RenderData *)ptr->data;
1479         SceneRenderLayer *srl = (SceneRenderLayer *)value.data;
1480         const int index = BLI_findindex(&rd->layers, srl);
1481         if (index != -1) rd->actlay = index;
1482 }
1483
1484 static SceneRenderLayer *rna_RenderLayer_new(ID *id, RenderData *UNUSED(rd), const char *name)
1485 {
1486         Scene *scene = (Scene *)id;
1487         SceneRenderLayer *srl = BKE_scene_add_render_layer(scene, name);
1488
1489         DEG_id_tag_update(&scene->id, 0);
1490         WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
1491
1492         return srl;
1493 }
1494
1495 static void rna_RenderLayer_remove(
1496         ID *id, RenderData *UNUSED(rd), Main *bmain, ReportList *reports, PointerRNA *srl_ptr)
1497 {
1498         SceneRenderLayer *srl = srl_ptr->data;
1499         Scene *scene = (Scene *)id;
1500
1501         if (!BKE_scene_remove_render_layer(bmain, scene, srl)) {
1502                 BKE_reportf(reports, RPT_ERROR, "Render layer '%s' could not be removed from scene '%s'",
1503                             srl->name, scene->id.name + 2);
1504                 return;
1505         }
1506
1507         RNA_POINTER_INVALIDATE(srl_ptr);
1508
1509         DEG_id_tag_update(&scene->id, 0);
1510         WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
1511 }
1512
1513 static int rna_RenderSettings_active_view_index_get(PointerRNA *ptr)
1514 {
1515         RenderData *rd = (RenderData *)ptr->data;
1516         return rd->actview;
1517 }
1518
1519 static void rna_RenderSettings_active_view_index_set(PointerRNA *ptr, int value)
1520 {
1521         RenderData *rd = (RenderData *)ptr->data;
1522         rd->actview = value;
1523 }
1524
1525 static void rna_RenderSettings_active_view_index_range(
1526         PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
1527 {
1528         RenderData *rd = (RenderData *)ptr->data;
1529
1530         *min = 0;
1531         *max = max_ii(0, BLI_listbase_count(&rd->views) - 1);
1532 }
1533
1534 static PointerRNA rna_RenderSettings_active_view_get(PointerRNA *ptr)
1535 {
1536         RenderData *rd = (RenderData *)ptr->data;
1537         SceneRenderView *srv = BLI_findlink(&rd->views, rd->actview);
1538
1539         return rna_pointer_inherit_refine(ptr, &RNA_SceneRenderView, srv);
1540 }
1541
1542 static void rna_RenderSettings_active_view_set(PointerRNA *ptr, PointerRNA value)
1543 {
1544         RenderData *rd = (RenderData *)ptr->data;
1545         SceneRenderView *srv = (SceneRenderView *)value.data;
1546         const int index = BLI_findindex(&rd->views, srv);
1547         if (index != -1) rd->actview = index;
1548 }
1549
1550 static SceneRenderView *rna_RenderView_new(ID *id, RenderData *UNUSED(rd), const char *name)
1551 {
1552         Scene *scene = (Scene *)id;
1553         SceneRenderView *srv = BKE_scene_add_render_view(scene, name);
1554
1555         WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
1556
1557         return srv;
1558 }
1559
1560 static void rna_RenderView_remove(
1561         ID *id, RenderData *UNUSED(rd), Main *UNUSED(bmain), ReportList *reports, PointerRNA *srv_ptr)
1562 {
1563         SceneRenderView *srv = srv_ptr->data;
1564         Scene *scene = (Scene *)id;
1565
1566         if (!BKE_scene_remove_render_view(scene, srv)) {
1567                 BKE_reportf(reports, RPT_ERROR, "Render view '%s' could not be removed from scene '%s'",
1568                             srv->name, scene->id.name + 2);
1569                 return;
1570         }
1571
1572         RNA_POINTER_INVALIDATE(srv_ptr);
1573
1574         WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
1575 }
1576
1577 static void rna_RenderSettings_engine_set(PointerRNA *ptr, int value)
1578 {
1579         RenderData *rd = (RenderData *)ptr->data;
1580         RenderEngineType *type = BLI_findlink(&R_engines, value);
1581         Scene *scene = (Scene *)ptr->id.data;
1582
1583         if (type)
1584                 BLI_strncpy_utf8(rd->engine, type->idname, sizeof(rd->engine));
1585
1586         DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE);
1587 }
1588
1589 static EnumPropertyItem *rna_RenderSettings_engine_itemf(
1590         bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
1591 {
1592         RenderEngineType *type;
1593         EnumPropertyItem *item = NULL;
1594         EnumPropertyItem tmp = {0, "", 0, "", ""};
1595         int a = 0, totitem = 0;
1596
1597         for (type = R_engines.first; type; type = type->next, a++) {
1598                 tmp.value = a;
1599                 tmp.identifier = type->idname;
1600                 tmp.name = type->name;
1601                 RNA_enum_item_add(&item, &totitem, &tmp);
1602         }
1603         
1604         RNA_enum_item_end(&item, &totitem);
1605         *r_free = true;
1606
1607         return item;
1608 }
1609
1610 static int rna_RenderSettings_engine_get(PointerRNA *ptr)
1611 {
1612         RenderData *rd = (RenderData *)ptr->data;
1613         RenderEngineType *type;
1614         int a = 0;
1615
1616         for (type = R_engines.first; type; type = type->next, a++)
1617                 if (STREQ(type->idname, rd->engine))
1618                         return a;
1619         
1620         return 0;
1621 }
1622
1623 static void rna_RenderSettings_engine_update(Main *bmain, Scene *UNUSED(unused), PointerRNA *UNUSED(ptr))
1624 {
1625         ED_render_engine_changed(bmain);
1626 }
1627
1628 static void rna_Scene_glsl_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
1629 {
1630         Scene *scene = (Scene *)ptr->id.data;
1631
1632         DEG_id_tag_update(&scene->id, 0);
1633 }
1634
1635 static void rna_Scene_world_update(Main *bmain, Scene *scene, PointerRNA *ptr)
1636 {
1637         Scene *sc = (Scene *)ptr->id.data;
1638
1639         rna_Scene_glsl_update(bmain, scene, ptr);
1640         WM_main_add_notifier(NC_WORLD | ND_WORLD, &sc->id);
1641 }
1642
1643 static void rna_Scene_freestyle_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
1644 {
1645         Scene *scene = (Scene *)ptr->id.data;
1646
1647         DEG_id_tag_update(&scene->id, 0);
1648 }
1649
1650 static void rna_Scene_use_view_map_cache_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
1651 {
1652 #ifdef WITH_FREESTYLE
1653         FRS_free_view_map_cache();
1654 #endif
1655 }
1656
1657 static IDProperty *rna_SceneRenderLayer_idprops(PointerRNA *ptr, bool create)
1658 {
1659         SceneRenderLayer *srl = (SceneRenderLayer *)ptr->data;
1660
1661         if (create && !srl->prop) {
1662                 IDPropertyTemplate val = {0};
1663                 srl->prop = IDP_New(IDP_GROUP, &val, "SceneRenderLayer ID properties");
1664         }
1665
1666         return srl->prop;
1667 }
1668
1669 static void rna_SceneRenderLayer_name_set(PointerRNA *ptr, const char *value)
1670 {
1671         Scene *scene = (Scene *)ptr->id.data;
1672         SceneRenderLayer *rl = (SceneRenderLayer *)ptr->data;
1673         char oldname[sizeof(rl->name)];
1674
1675         BLI_strncpy(oldname, rl->name, sizeof(rl->name));
1676
1677         BLI_strncpy_utf8(rl->name, value, sizeof(rl->name));
1678         BLI_uniquename(&scene->r.layers, rl, DATA_("RenderLayer"), '.', offsetof(SceneRenderLayer, name), sizeof(rl->name));
1679
1680         if (scene->nodetree) {
1681                 bNode *node;
1682                 int index = BLI_findindex(&scene->r.layers, rl);
1683
1684                 for (node = scene->nodetree->nodes.first; node; node = node->next) {
1685                         if (node->type == CMP_NODE_R_LAYERS && node->id == NULL) {
1686                                 if (node->custom1 == index)
1687                                         BLI_strncpy(node->name, rl->name, NODE_MAXSTR);
1688                         }
1689                 }
1690         }
1691
1692         /* fix all the animation data which may link to this */
1693         BKE_animdata_fix_paths_rename_all(NULL, "render.layers", oldname, rl->name);
1694 }
1695
1696 static char *rna_SceneRenderLayer_path(PointerRNA *ptr)
1697 {
1698         SceneRenderLayer *srl = (SceneRenderLayer *)ptr->data;
1699         char name_esc[sizeof(srl->name) * 2];
1700
1701         BLI_strescape(name_esc, srl->name, sizeof(name_esc));
1702         return BLI_sprintfN("render.layers[\"%s\"]", name_esc);
1703 }
1704
1705 static void rna_SceneRenderView_name_set(PointerRNA *ptr, const char *value)
1706 {
1707         Scene *scene = (Scene *)ptr->id.data;
1708         SceneRenderView *rv = (SceneRenderView *)ptr->data;
1709         BLI_strncpy_utf8(rv->name, value, sizeof(rv->name));
1710         BLI_uniquename(&scene->r.views, rv, DATA_("RenderView"), '.', offsetof(SceneRenderView, name), sizeof(rv->name));
1711 }
1712
1713 static char *rna_SceneRenderView_path(PointerRNA *ptr)
1714 {
1715         SceneRenderView *srv = (SceneRenderView *)ptr->data;
1716         return BLI_sprintfN("render.views[\"%s\"]", srv->name);
1717 }
1718
1719 static void rna_RenderSettings_views_format_set(PointerRNA *ptr, int value)
1720 {
1721         RenderData *rd = (RenderData *)ptr->data;
1722
1723         if (rd->views_format == SCE_VIEWS_FORMAT_MULTIVIEW &&
1724             value == SCE_VIEWS_FORMAT_STEREO_3D)
1725         {
1726                 /* make sure the actview is visible */
1727                 if (rd->actview > 1) rd->actview = 1;
1728         }
1729
1730         rd->views_format = value;
1731 }
1732
1733 static int rna_RenderSettings_multiple_engines_get(PointerRNA *UNUSED(ptr))
1734 {
1735         return (BLI_listbase_count(&R_engines) > 1);
1736 }
1737
1738 static int rna_RenderSettings_use_shading_nodes_get(PointerRNA *ptr)
1739 {
1740         Scene *scene = (Scene *)ptr->id.data;
1741         return BKE_scene_use_new_shading_nodes(scene);
1742 }
1743
1744 static int rna_RenderSettings_use_spherical_stereo_get(PointerRNA *ptr)
1745 {
1746         Scene *scene = (Scene *)ptr->id.data;
1747         return BKE_scene_use_spherical_stereo(scene);
1748 }
1749
1750 static int rna_RenderSettings_use_game_engine_get(PointerRNA *ptr)
1751 {
1752         RenderData *rd = (RenderData *)ptr->data;
1753         RenderEngineType *type;
1754
1755         for (type = R_engines.first; type; type = type->next)
1756                 if (STREQ(type->idname, rd->engine))
1757                         return (type->flag & RE_GAME) != 0;
1758         
1759         return 0;
1760 }
1761
1762 static void rna_SceneRenderLayer_layer_set(PointerRNA *ptr, const int *values)
1763 {
1764         SceneRenderLayer *rl = (SceneRenderLayer *)ptr->data;
1765         rl->lay = ED_view3d_scene_layer_set(rl->lay, values, NULL);
1766 }
1767
1768 static void rna_SceneRenderLayer_pass_update(Main *bmain, Scene *activescene, PointerRNA *ptr)
1769 {
1770         Scene *scene = (Scene *)ptr->id.data;
1771
1772         if (scene->nodetree)
1773                 ntreeCompositUpdateRLayers(scene->nodetree);
1774
1775         rna_Scene_glsl_update(bmain, activescene, ptr);
1776 }
1777
1778 static void rna_SceneRenderLayer_update_render_passes(ID *id)
1779 {
1780         Scene *scene = (Scene *)id;
1781         if (scene->nodetree)
1782                 ntreeCompositUpdateRLayers(scene->nodetree);
1783 }
1784
1785 static void rna_Scene_use_nodes_update(bContext *C, PointerRNA *ptr)
1786 {
1787         Scene *scene = (Scene *)ptr->data;
1788
1789         if (scene->use_nodes && scene->nodetree == NULL)
1790                 ED_node_composit_default(C, scene);
1791 }
1792
1793 static void rna_Physics_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
1794 {
1795         Scene *scene = (Scene *)ptr->id.data;
1796         FOREACH_SCENE_OBJECT(scene, ob)
1797         {
1798                 BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_DEPSGRAPH);
1799         }
1800         FOREACH_SCENE_OBJECT_END
1801 }
1802
1803 static void rna_Scene_editmesh_select_mode_set(PointerRNA *ptr, const int *value)
1804 {
1805         Scene *scene = (Scene *)ptr->id.data;
1806         SceneLayer *sl = BKE_scene_layer_context_active_PLACEHOLDER(scene);
1807         ToolSettings *ts = (ToolSettings *)ptr->data;
1808         int flag = (value[0] ? SCE_SELECT_VERTEX : 0) | (value[1] ? SCE_SELECT_EDGE : 0) | (value[2] ? SCE_SELECT_FACE : 0);
1809
1810         if (flag) {
1811                 ts->selectmode = flag;
1812
1813                 if (sl->basact) {
1814                         Mesh *me = BKE_mesh_from_object(sl->basact->object);
1815                         if (me && me->edit_btmesh && me->edit_btmesh->selectmode != flag) {
1816                                 me->edit_btmesh->selectmode = flag;
1817                                 EDBM_selectmode_set(me->edit_btmesh);
1818                         }
1819                 }
1820         }
1821 }
1822
1823 static void rna_Scene_editmesh_select_mode_update(Main *UNUSED(bmain), bContext *C, Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
1824 {
1825         SceneLayer *sl = CTX_data_scene_layer(C);
1826         Mesh *me = NULL;
1827
1828         if (sl->basact) {
1829                 me = BKE_mesh_from_object(sl->basact->object);
1830                 if (me && me->edit_btmesh == NULL)
1831                         me = NULL;
1832         }
1833
1834         WM_main_add_notifier(NC_GEOM | ND_SELECT, me);
1835         WM_main_add_notifier(NC_SCENE | ND_TOOLSETTINGS, NULL);
1836 }
1837
1838 static void object_simplify_update(Object *ob)
1839 {
1840         ModifierData *md;
1841         ParticleSystem *psys;
1842
1843         if ((ob->id.tag & LIB_TAG_DOIT) == 0) {
1844                 return;
1845         }
1846
1847         ob->id.tag &= ~LIB_TAG_DOIT;
1848
1849         for (md = ob->modifiers.first; md; md = md->next) {
1850                 if (ELEM(md->type, eModifierType_Subsurf, eModifierType_Multires, eModifierType_ParticleSystem)) {
1851                         DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
1852                 }
1853         }
1854
1855         for (psys = ob->particlesystem.first; psys; psys = psys->next)
1856                 psys->recalc |= PSYS_RECALC_CHILD;
1857         
1858         if (ob->dup_group) {
1859                 GroupObject *gob;
1860
1861                 for (gob = ob->dup_group->gobject.first; gob; gob = gob->next)
1862                         object_simplify_update(gob->ob);
1863         }
1864 }
1865
1866 static void rna_Scene_use_simplify_update(Main *bmain, Scene *scene, PointerRNA *ptr)
1867 {
1868         Scene *sce = ptr->id.data;
1869         Scene *sce_iter;
1870         Base *base;
1871
1872         BKE_main_id_tag_listbase(&bmain->object, LIB_TAG_DOIT, true);
1873         for (SETLOOPER(sce, sce_iter, base))
1874                 object_simplify_update(base->object);
1875         
1876         WM_main_add_notifier(NC_GEOM | ND_DATA, NULL);
1877         DEG_id_tag_update(&scene->id, 0);
1878 }
1879
1880 static void rna_Scene_simplify_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
1881 {
1882         Scene *sce = ptr->id.data;
1883
1884         if (sce->r.mode & R_SIMPLIFY)
1885                 rna_Scene_use_simplify_update(bmain, sce, ptr);
1886 }
1887
1888 static void rna_Scene_use_persistent_data_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
1889 {
1890         Scene *sce = ptr->id.data;
1891
1892         if (!(sce->r.mode & R_PERSISTENT_DATA))
1893                 RE_FreePersistentData();
1894 }
1895
1896 static int rna_Scene_use_audio_get(PointerRNA *ptr)
1897 {
1898         Scene *scene = (Scene *)ptr->data;
1899         return (scene->audio.flag & AUDIO_MUTE) != 0;
1900 }
1901
1902 static void rna_Scene_use_audio_set(PointerRNA *ptr, int value)
1903 {
1904         Scene *scene = (Scene *)ptr->data;
1905
1906         if (value)
1907                 scene->audio.flag |= AUDIO_MUTE;
1908         else
1909                 scene->audio.flag &= ~AUDIO_MUTE;
1910
1911         BKE_sound_mute_scene(scene, value);
1912 }
1913
1914 static int rna_Scene_sync_mode_get(PointerRNA *ptr)
1915 {
1916         Scene *scene = (Scene *)ptr->data;
1917         if (scene->audio.flag & AUDIO_SYNC)
1918                 return AUDIO_SYNC;
1919         return scene->flag & SCE_FRAME_DROP;
1920 }
1921
1922 static void rna_Scene_sync_mode_set(PointerRNA *ptr, int value)
1923 {
1924         Scene *scene = (Scene *)ptr->data;
1925
1926         if (value == AUDIO_SYNC) {
1927                 scene->audio.flag |= AUDIO_SYNC;
1928         }
1929         else if (value == SCE_FRAME_DROP) {
1930                 scene->audio.flag &= ~AUDIO_SYNC;
1931                 scene->flag |= SCE_FRAME_DROP;
1932         }
1933         else {
1934                 scene->audio.flag &= ~AUDIO_SYNC;
1935                 scene->flag &= ~SCE_FRAME_DROP;
1936         }
1937 }
1938
1939 static int rna_GameSettings_auto_start_get(PointerRNA *UNUSED(ptr))
1940 {
1941         return (G.fileflags & G_FILE_AUTOPLAY) != 0;
1942 }
1943
1944 static void rna_GameSettings_auto_start_set(PointerRNA *UNUSED(ptr), int value)
1945 {
1946         if (value)
1947                 G.fileflags |= G_FILE_AUTOPLAY;
1948         else
1949                 G.fileflags &= ~G_FILE_AUTOPLAY;
1950 }
1951
1952 static void rna_GameSettings_exit_key_set(PointerRNA *ptr, int value)
1953 {
1954         GameData *gm = (GameData *)ptr->data;
1955
1956         if (ISKEYBOARD(value))
1957                 gm->exitkey = value;
1958 }
1959
1960 static StructRNA *rna_SceneLayerSettings_refine(PointerRNA *ptr)
1961 {
1962         IDProperty *props = (IDProperty *)ptr->data;
1963         BLI_assert(props && props->type == IDP_GROUP);
1964
1965         switch (props->subtype) {
1966                 case IDP_GROUP_SUB_ENGINE_RENDER:
1967 #ifdef WITH_CLAY_ENGINE
1968                         if (STREQ(props->name, RE_engine_id_BLENDER_CLAY)) {
1969                                 return &RNA_SceneLayerEngineSettingsClay;
1970                         }
1971 #endif
1972                         if (STREQ(props->name, RE_engine_id_BLENDER_EEVEE)) {
1973                                 return &RNA_SceneLayerEngineSettingsEevee;
1974                         }
1975                         break;
1976                 case IDP_GROUP_SUB_MODE_OBJECT:
1977                 case IDP_GROUP_SUB_MODE_EDIT:
1978                 case IDP_GROUP_SUB_MODE_PAINT_WEIGHT:
1979                 case IDP_GROUP_SUB_MODE_PAINT_VERTEX:
1980                 default:
1981                         BLI_assert(!"Mode not fully implemented");
1982                         break;
1983         }
1984
1985         return &RNA_SceneLayerSettings;
1986 }
1987
1988 static StructRNA *rna_LayerCollectionSettings_refine(PointerRNA *ptr)
1989 {
1990         IDProperty *props = (IDProperty *)ptr->data;
1991         BLI_assert(props && props->type == IDP_GROUP);
1992
1993         switch (props->subtype) {
1994                 case IDP_GROUP_SUB_ENGINE_RENDER:
1995 #ifdef WITH_CLAY_ENGINE
1996                         if (STREQ(props->name, RE_engine_id_BLENDER_CLAY)) {
1997                                 return &RNA_LayerCollectionEngineSettingsClay;
1998                         }
1999 #endif
2000                         if (STREQ(props->name, RE_engine_id_BLENDER_EEVEE)) {
2001                                 /* printf("Mode not fully implemented\n"); */
2002                                 return &RNA_LayerCollectionSettings;
2003                         }
2004                         break;
2005                 case IDP_GROUP_SUB_MODE_OBJECT:
2006                         return &RNA_LayerCollectionModeSettingsObject;
2007                         break;
2008                 case IDP_GROUP_SUB_MODE_EDIT:
2009                         return &RNA_LayerCollectionModeSettingsEdit;
2010                         break;
2011                 case IDP_GROUP_SUB_MODE_PAINT_WEIGHT:
2012                         return &RNA_LayerCollectionModeSettingsPaintWeight;
2013                         break;
2014                 case IDP_GROUP_SUB_MODE_PAINT_VERTEX:
2015                         return &RNA_LayerCollectionModeSettingsPaintVertex;
2016                         break;
2017                 default:
2018                         BLI_assert(!"Mode not fully implemented");
2019                         break;
2020         }
2021
2022         return &RNA_LayerCollectionSettings;
2023 }
2024
2025 static TimeMarker *rna_TimeLine_add(Scene *scene, const char name[], int frame)
2026 {
2027         TimeMarker *marker = MEM_callocN(sizeof(TimeMarker), "TimeMarker");
2028         marker->flag = SELECT;
2029         marker->frame = frame;
2030         BLI_strncpy_utf8(marker->name, name, sizeof(marker->name));
2031         BLI_addtail(&scene->markers, marker);
2032
2033         WM_main_add_notifier(NC_SCENE | ND_MARKERS, NULL);
2034         WM_main_add_notifier(NC_ANIMATION | ND_MARKERS, NULL);
2035
2036         return marker;
2037 }
2038
2039 static void rna_TimeLine_remove(Scene *scene, ReportList *reports, PointerRNA *marker_ptr)
2040 {
2041         TimeMarker *marker = marker_ptr->data;
2042         if (BLI_remlink_safe(&scene->markers, marker) == false) {
2043                 BKE_reportf(reports, RPT_ERROR, "Timeline marker '%s' not found in scene '%s'",
2044                             marker->name, scene->id.name + 2);
2045                 return;
2046         }
2047
2048         MEM_freeN(marker);
2049         RNA_POINTER_INVALIDATE(marker_ptr);
2050
2051         WM_main_add_notifier(NC_SCENE | ND_MARKERS, NULL);
2052         WM_main_add_notifier(NC_ANIMATION | ND_MARKERS, NULL);
2053 }
2054
2055 static void rna_TimeLine_clear(Scene *scene)
2056 {
2057         BLI_freelistN(&scene->markers);
2058
2059         WM_main_add_notifier(NC_SCENE | ND_MARKERS, NULL);
2060         WM_main_add_notifier(NC_ANIMATION | ND_MARKERS, NULL);
2061 }
2062
2063 static KeyingSet *rna_Scene_keying_set_new(Scene *sce, ReportList *reports, const char idname[], const char name[])
2064 {
2065         KeyingSet *ks = NULL;
2066
2067         /* call the API func, and set the active keyingset index */
2068         ks = BKE_keyingset_add(&sce->keyingsets, idname, name, KEYINGSET_ABSOLUTE, 0);
2069         
2070         if (ks) {
2071                 sce->active_keyingset = BLI_listbase_count(&sce->keyingsets);
2072                 return ks;
2073         }
2074         else {
2075                 BKE_report(reports, RPT_ERROR, "Keying set could not be added");
2076                 return NULL;
2077         }
2078 }
2079
2080 static void rna_UnifiedPaintSettings_update(bContext *C, PointerRNA *UNUSED(ptr))
2081 {
2082         Scene *scene = CTX_data_scene(C);
2083         SceneLayer *sl = CTX_data_scene_layer(C);
2084         Brush *br = BKE_paint_brush(BKE_paint_get_active(scene, sl));
2085         WM_main_add_notifier(NC_BRUSH | NA_EDITED, br);
2086 }
2087
2088 static void rna_UnifiedPaintSettings_size_set(PointerRNA *ptr, int value)
2089 {
2090         UnifiedPaintSettings *ups = ptr->data;
2091
2092         /* scale unprojected radius so it stays consistent with brush size */
2093         BKE_brush_scale_unprojected_radius(&ups->unprojected_radius,
2094                                            value, ups->size);
2095         ups->size = value;
2096 }
2097
2098 static void rna_UnifiedPaintSettings_unprojected_radius_set(PointerRNA *ptr, float value)
2099 {
2100         UnifiedPaintSettings *ups = ptr->data;
2101
2102         /* scale brush size so it stays consistent with unprojected_radius */
2103         BKE_brush_scale_size(&ups->size, value, ups->unprojected_radius);
2104         ups->unprojected_radius = value;
2105 }
2106
2107 static void rna_UnifiedPaintSettings_radius_update(bContext *C, PointerRNA *ptr)
2108 {
2109         /* changing the unified size should invalidate the overlay but also update the brush */
2110         BKE_paint_invalidate_overlay_all();
2111         rna_UnifiedPaintSettings_update(C, ptr);
2112 }
2113
2114 static char *rna_UnifiedPaintSettings_path(PointerRNA *UNUSED(ptr))
2115 {
2116         return BLI_strdup("tool_settings.unified_paint_settings");
2117 }
2118
2119 static char *rna_CurvePaintSettings_path(PointerRNA *UNUSED(ptr))
2120 {
2121         return BLI_strdup("tool_settings.curve_paint_settings");
2122 }
2123
2124 /* generic function to recalc geometry */
2125 static void rna_EditMesh_update(Main *UNUSED(bmain), bContext *C, Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
2126 {
2127         SceneLayer *sl = CTX_data_scene_layer(C);
2128         Mesh *me = NULL;
2129
2130         if (sl->basact) {
2131                 me = BKE_mesh_from_object(sl->basact->object);
2132                 if (me && me->edit_btmesh == NULL)
2133                         me = NULL;
2134         }
2135
2136         if (me) {
2137                 DEG_id_tag_update(&me->id, OB_RECALC_DATA);
2138                 WM_main_add_notifier(NC_GEOM | ND_DATA, me);
2139         }
2140 }
2141
2142 static char *rna_MeshStatVis_path(PointerRNA *UNUSED(ptr))
2143 {
2144         return BLI_strdup("tool_settings.statvis");
2145 }
2146
2147 /* note: without this, when Multi-Paint is activated/deactivated, the colors
2148  * will not change right away when multiple bones are selected, this function
2149  * is not for general use and only for the few cases where changing scene
2150  * settings and NOT for general purpose updates, possibly this should be
2151  * given its own notifier. */
2152 static void rna_Scene_update_active_object_data(bContext *C, PointerRNA *UNUSED(ptr))
2153 {
2154         SceneLayer *sl = CTX_data_scene_layer(C);
2155         Object *ob = OBACT_NEW;
2156
2157         if (ob) {
2158                 DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
2159                 WM_main_add_notifier(NC_OBJECT | ND_DRAW, &ob->id);
2160         }
2161 }
2162
2163 static void rna_SceneCamera_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
2164 {
2165         Scene *scene = (Scene *)ptr->id.data;
2166         Object *camera = scene->camera;
2167
2168         if (camera)
2169                 DEG_id_tag_update(&camera->id, 0);
2170 }
2171
2172 static void rna_SceneSequencer_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
2173 {
2174         BKE_sequencer_cache_cleanup();
2175         BKE_sequencer_preprocessed_cache_cleanup();
2176 }
2177
2178 static char *rna_ToolSettings_path(PointerRNA *UNUSED(ptr))
2179 {
2180         return BLI_strdup("tool_settings");
2181 }
2182
2183 static PointerRNA rna_FreestyleLineSet_linestyle_get(PointerRNA *ptr)
2184 {
2185         FreestyleLineSet *lineset = (FreestyleLineSet *)ptr->data;
2186
2187         return rna_pointer_inherit_refine(ptr, &RNA_FreestyleLineStyle, lineset->linestyle);
2188 }
2189
2190 static void rna_FreestyleLineSet_linestyle_set(PointerRNA *ptr, PointerRNA value)
2191 {
2192         FreestyleLineSet *lineset = (FreestyleLineSet *)ptr->data;
2193
2194         if (lineset->linestyle)
2195                 id_us_min(&lineset->linestyle->id);
2196         lineset->linestyle = (FreestyleLineStyle *)value.data;
2197         id_us_plus(&lineset->linestyle->id);
2198 }
2199
2200 static FreestyleLineSet *rna_FreestyleSettings_lineset_add(
2201         ID *id, FreestyleSettings *config, Main *bmain, const char *name)
2202 {
2203         Scene *scene = (Scene *)id;
2204         FreestyleLineSet *lineset = BKE_freestyle_lineset_add(bmain, (FreestyleConfig *)config, name);
2205
2206         DEG_id_tag_update(&scene->id, 0);
2207         WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
2208
2209         return lineset;
2210 }
2211
2212 static void rna_FreestyleSettings_lineset_remove(
2213         ID *id, FreestyleSettings *config, ReportList *reports, PointerRNA *lineset_ptr)
2214 {
2215         FreestyleLineSet *lineset = lineset_ptr->data;
2216         Scene *scene = (Scene *)id;
2217
2218         if (!BKE_freestyle_lineset_delete((FreestyleConfig *)config, lineset)) {
2219                 BKE_reportf(reports, RPT_ERROR, "Line set '%s' could not be removed", lineset->name);
2220                 return;
2221         }
2222
2223         RNA_POINTER_INVALIDATE(lineset_ptr);
2224
2225         DEG_id_tag_update(&scene->id, 0);
2226         WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
2227 }
2228
2229 static PointerRNA rna_FreestyleSettings_active_lineset_get(PointerRNA *ptr)
2230 {
2231         FreestyleConfig *config = (FreestyleConfig *)ptr->data;
2232         FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
2233         return rna_pointer_inherit_refine(ptr, &RNA_FreestyleLineSet, lineset);
2234 }
2235
2236 static void rna_FreestyleSettings_active_lineset_index_range(
2237         PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
2238 {
2239         FreestyleConfig *config = (FreestyleConfig *)ptr->data;
2240
2241         *min = 0;
2242         *max = max_ii(0, BLI_listbase_count(&config->linesets) - 1);
2243 }
2244
2245 static int rna_FreestyleSettings_active_lineset_index_get(PointerRNA *ptr)
2246 {
2247         FreestyleConfig *config = (FreestyleConfig *)ptr->data;
2248         return BKE_freestyle_lineset_get_active_index(config);
2249 }
2250
2251 static void rna_FreestyleSettings_active_lineset_index_set(PointerRNA *ptr, int value)
2252 {
2253         FreestyleConfig *config = (FreestyleConfig *)ptr->data;
2254         BKE_freestyle_lineset_set_active_index(config, value);
2255 }
2256
2257 static FreestyleModuleConfig *rna_FreestyleSettings_module_add(ID *id, FreestyleSettings *config)
2258 {
2259         Scene *scene = (Scene *)id;
2260         FreestyleModuleConfig *module = BKE_freestyle_module_add((FreestyleConfig *)config);
2261
2262         DEG_id_tag_update(&scene->id, 0);
2263         WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
2264
2265         return module;
2266 }
2267
2268 static void rna_FreestyleSettings_module_remove(
2269         ID *id, FreestyleSettings *config, ReportList *reports, PointerRNA *module_ptr)
2270 {
2271         Scene *scene = (Scene *)id;
2272         FreestyleModuleConfig *module = module_ptr->data;
2273
2274         if (!BKE_freestyle_module_delete((FreestyleConfig *)config, module)) {
2275                 if (module->script)
2276                         BKE_reportf(reports, RPT_ERROR, "Style module '%s' could not be removed", module->script->id.name + 2);
2277                 else
2278                         BKE_report(reports, RPT_ERROR, "Style module could not be removed");
2279                 return;
2280         }
2281
2282         RNA_POINTER_INVALIDATE(module_ptr);
2283
2284         DEG_id_tag_update(&scene->id, 0);
2285         WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
2286 }
2287
2288 char *rna_GPUDOF_path(PointerRNA *ptr)
2289 {
2290         /* if there is ID-data, resolve the path using the index instead of by name,
2291          * since the name used is the name of the texture assigned, but the texture
2292          * may be used multiple times in the same stack
2293          */
2294         if (ptr->id.data) {
2295                 if (GS(((ID *)ptr->id.data)->name) == ID_CA) {
2296                         return BLI_strdup("gpu_dof");
2297                 }
2298         }
2299
2300         return BLI_strdup("");
2301 }
2302
2303 static void rna_GPUFXSettings_fx_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
2304 {
2305         GPUFXSettings *fx_settings = ptr->data;
2306
2307         BKE_screen_gpu_fx_validate(fx_settings);
2308 }
2309
2310 static void rna_GPUDOFSettings_blades_set(PointerRNA *ptr, const int value)
2311 {
2312         GPUDOFSettings *dofsettings = (GPUDOFSettings *)ptr->data;
2313
2314         if (value < 3 && dofsettings->num_blades > 2)
2315                 dofsettings->num_blades = 0;
2316         else if (value > 0 && dofsettings->num_blades == 0)
2317                 dofsettings->num_blades = 3;
2318         else
2319                 dofsettings->num_blades = value;
2320 }
2321
2322 static void rna_Stereo3dFormat_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
2323 {
2324         ID *id = ptr->id.data;
2325
2326         if (id && GS(id->name) == ID_IM) {
2327                 Image *ima = (Image *)id;
2328                 ImBuf *ibuf;
2329                 void *lock;
2330
2331                 if (!BKE_image_is_stereo(ima))
2332                         return;
2333
2334                 ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
2335
2336                 if (ibuf) {
2337                         BKE_image_signal(ima, NULL, IMA_SIGNAL_FREE);
2338                 }
2339                 BKE_image_release_ibuf(ima, ibuf, lock);
2340         }
2341 }
2342
2343 static int rna_gpu_is_hq_supported_get(PointerRNA *UNUSED(ptr))
2344 {
2345         return true;
2346 }
2347
2348 static void rna_SceneCollection_name_set(PointerRNA *ptr, const char *value)
2349 {
2350         Scene *scene = (Scene *)ptr->id.data;
2351         SceneCollection *sc = (SceneCollection *)ptr->data;
2352         BKE_collection_rename(scene, sc, value);
2353 }
2354
2355 static void rna_SceneCollection_filter_set(PointerRNA *ptr, const char *value)
2356 {
2357         Scene *scene = (Scene *)ptr->id.data;
2358         SceneCollection *sc = (SceneCollection *)ptr->data;
2359         BLI_strncpy_utf8(sc->filter, value, sizeof(sc->filter));
2360
2361         TODO_LAYER_SYNC_FILTER;
2362         (void)scene;
2363 }
2364
2365 static PointerRNA rna_SceneCollection_objects_get(CollectionPropertyIterator *iter)
2366 {
2367         ListBaseIterator *internal = &iter->internal.listbase;
2368
2369         /* we are actually iterating a LinkData list, so override get */
2370         return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((LinkData *)internal->link)->data);
2371 }
2372
2373 static int rna_SceneCollection_move_above(ID *id, SceneCollection *sc_src, Main *bmain, SceneCollection *sc_dst)
2374 {
2375         Scene *scene = (Scene *)id;
2376
2377         if (!BKE_collection_move_above(scene, sc_dst, sc_src)) {
2378                 return 0;
2379         }
2380
2381         DEG_relations_tag_update(bmain);
2382         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
2383
2384         return 1;
2385 }
2386
2387 static int rna_SceneCollection_move_below(ID *id, SceneCollection *sc_src, Main *bmain, SceneCollection *sc_dst)
2388 {
2389         Scene *scene = (Scene *)id;
2390
2391         if (!BKE_collection_move_below(scene, sc_dst, sc_src)) {
2392                 return 0;
2393         }
2394
2395         DEG_relations_tag_update(bmain);
2396         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
2397
2398         return 1;
2399 }
2400
2401 static int rna_SceneCollection_move_into(ID *id, SceneCollection *sc_src, Main *bmain, SceneCollection *sc_dst)
2402 {
2403         Scene *scene = (Scene *)id;
2404
2405         if (!BKE_collection_move_into(scene, sc_dst, sc_src)) {
2406                 return 0;
2407         }
2408
2409         DEG_relations_tag_update(bmain);
2410         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
2411
2412         return 1;
2413 }
2414
2415 static SceneCollection *rna_SceneCollection_new(
2416         ID *id, SceneCollection *sc_parent, Main *bmain, const char *name)
2417 {
2418         Scene *scene = (Scene *)id;
2419         SceneCollection *sc = BKE_collection_add(scene, sc_parent, name);
2420
2421         DEG_relations_tag_update(bmain);
2422         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
2423
2424         return sc;
2425 }
2426
2427 static void rna_SceneCollection_remove(
2428         ID *id, SceneCollection *sc_parent, Main *bmain, ReportList *reports, PointerRNA *sc_ptr)
2429 {
2430         Scene *scene = (Scene *)id;
2431         SceneCollection *sc = sc_ptr->data;
2432
2433         const int index = BLI_findindex(&sc_parent->scene_collections, sc);
2434         if (index == -1) {
2435                 BKE_reportf(reports, RPT_ERROR, "Collection '%s' is not a sub-collection of '%s'",
2436                             sc->name, sc_parent->name);
2437                 return;
2438         }
2439
2440         if (!BKE_collection_remove(scene, sc)) {
2441                 BKE_reportf(reports, RPT_ERROR, "Collection '%s' could not be removed from collection '%s'",
2442                             sc->name, sc_parent->name);
2443                 return;
2444         }
2445
2446         RNA_POINTER_INVALIDATE(sc_ptr);
2447
2448         DEG_relations_tag_update(bmain);
2449         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
2450 }
2451
2452 static int rna_SceneCollection_objects_active_index_get(PointerRNA *ptr)
2453 {
2454         SceneCollection *sc = (SceneCollection *)ptr->data;
2455         return sc->active_object_index;
2456 }
2457
2458 static void rna_SceneCollection_objects_active_index_set(PointerRNA *ptr, int value)
2459 {
2460         SceneCollection *sc = (SceneCollection *)ptr->data;
2461         sc->active_object_index = value;
2462 }
2463
2464 static void rna_SceneCollection_objects_active_index_range(
2465         PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
2466 {
2467         SceneCollection *sc = (SceneCollection *)ptr->data;
2468         *min = 0;
2469         *max = max_ii(0, BLI_listbase_count(&sc->objects) - 1);
2470 }
2471
2472 void rna_SceneCollection_object_link(
2473         ID *id, SceneCollection *sc, Main *bmain, ReportList *reports, Object *ob)
2474 {
2475         Scene *scene = (Scene *)id;
2476
2477         if (BLI_findptr(&sc->objects, ob, offsetof(LinkData, data))) {
2478                 BKE_reportf(reports, RPT_ERROR, "Object '%s' is already in collection '%s'", ob->id.name + 2, sc->name);
2479                 return;
2480         }
2481
2482         BKE_collection_object_add(scene, sc, ob);
2483
2484         /* TODO(sergey): Only update relations for the current scene. */
2485         DEG_relations_tag_update(bmain);
2486
2487         /* TODO(sergey): Use proper flag for tagging here. */
2488         DEG_id_tag_update(&scene->id, 0);
2489
2490         DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
2491
2492         WM_main_add_notifier(NC_SCENE | ND_LAYER | ND_OB_ACTIVE, scene);
2493 }
2494
2495 static void rna_SceneCollection_object_unlink(
2496         ID *id, SceneCollection *sc, Main *bmain, ReportList *reports, Object *ob)
2497 {
2498         Scene *scene = (Scene *)id;
2499
2500         if (!BLI_findptr(&sc->objects, ob, offsetof(LinkData, data))) {
2501                 BKE_reportf(reports, RPT_ERROR, "Object '%s' is not in collection '%s'", ob->id.name + 2, sc->name);
2502                 return;
2503         }
2504
2505         BKE_collection_object_remove(bmain, scene, sc, ob, false);
2506
2507         /* needed otherwise the depgraph will contain freed objects which can crash, see [#20958] */
2508         DEG_relations_tag_update(bmain);
2509
2510         WM_main_add_notifier(NC_SCENE | ND_LAYER | ND_OB_ACTIVE, scene);
2511 }
2512
2513 /****** layer collection engine settings *******/
2514
2515 #define RNA_LAYER_ENGINE_GET_SET(_TYPE_, _ENGINE_, _MODE_, _NAME_)                 \
2516 static _TYPE_ rna_LayerEngineSettings_##_ENGINE_##_##_NAME_##_get(PointerRNA *ptr) \
2517 {                                                                                  \
2518         IDProperty *props = (IDProperty *)ptr->data;                                   \
2519         return BKE_collection_engine_property_value_get_##_TYPE_(props, #_NAME_);      \
2520 }                                                                                  \
2521                                                                                        \
2522 static void rna_LayerEngineSettings_##_ENGINE_##_##_NAME_##_set(PointerRNA *ptr, _TYPE_ value)  \
2523 {                                                                                  \
2524         IDProperty *props = (IDProperty *)ptr->data;                                   \
2525         BKE_collection_engine_property_value_set_##_TYPE_(props, #_NAME_, value);      \
2526 }
2527
2528 #define RNA_LAYER_ENGINE_GET_SET_ARRAY(_TYPE_, _ENGINE_, _MODE_, _NAME_, _LEN_)    \
2529 static void rna_LayerEngineSettings_##_ENGINE_##_##_NAME_##_get(PointerRNA *ptr, _TYPE_ *values) \
2530 {                                                                                  \
2531         IDProperty *props = (IDProperty *)ptr->data;                                   \
2532         IDProperty *idprop = IDP_GetPropertyFromGroup(props, #_NAME_);                 \
2533         if (idprop != NULL) {                                                          \
2534                 memcpy(values, IDP_Array(idprop), sizeof(_TYPE_) * idprop->len);           \
2535         }                                                                              \
2536 }                                                                                  \
2537                                                                                        \
2538 static void rna_LayerEngineSettings_##_ENGINE_##_##_NAME_##_set(PointerRNA *ptr, const _TYPE_ *values) \
2539 {                                                                                  \
2540         IDProperty *props = (IDProperty *)ptr->data;                                   \
2541         BKE_collection_engine_property_value_set_##_TYPE_##_array(props, #_NAME_, values); \
2542 }
2543
2544 #define RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(_NAME_) \
2545         RNA_LAYER_ENGINE_GET_SET(float, Clay, COLLECTION_MODE_NONE, _NAME_)
2546
2547 #define RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT_ARRAY(_NAME_, _LEN_) \
2548         RNA_LAYER_ENGINE_GET_SET_ARRAY(float, Clay, COLLECTION_MODE_NONE, _NAME_, _LEN_)
2549
2550 #define RNA_LAYER_ENGINE_CLAY_GET_SET_INT(_NAME_) \
2551         RNA_LAYER_ENGINE_GET_SET(int, Clay, COLLECTION_MODE_NONE, _NAME_)
2552
2553 #define RNA_LAYER_ENGINE_CLAY_GET_SET_BOOL(_NAME_) \
2554         RNA_LAYER_ENGINE_GET_SET(bool, Clay, COLLECTION_MODE_NONE, _NAME_)
2555
2556 #define RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(_NAME_) \
2557         RNA_LAYER_ENGINE_GET_SET(float, Eevee, COLLECTION_MODE_NONE, _NAME_)
2558
2559 #define RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(_NAME_) \
2560         RNA_LAYER_ENGINE_GET_SET(int, Eevee, COLLECTION_MODE_NONE, _NAME_)
2561
2562 #define RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(_NAME_) \
2563         RNA_LAYER_ENGINE_GET_SET(bool, Eevee, COLLECTION_MODE_NONE, _NAME_)
2564
2565 /* mode engines */
2566
2567 #define RNA_LAYER_MODE_OBJECT_GET_SET_FLOAT(_NAME_) \
2568         RNA_LAYER_ENGINE_GET_SET(float, ObjectMode, COLLECTION_MODE_OBJECT, _NAME_)
2569
2570 #define RNA_LAYER_MODE_OBJECT_GET_SET_INT(_NAME_) \
2571         RNA_LAYER_ENGINE_GET_SET(int, ObjectMode, COLLECTION_MODE_OBJECT, _NAME_)
2572
2573 #define RNA_LAYER_MODE_OBJECT_GET_SET_BOOL(_NAME_) \
2574         RNA_LAYER_ENGINE_GET_SET(bool, ObjectMode, COLLECTION_MODE_OBJECT, _NAME_)
2575
2576 #define RNA_LAYER_MODE_EDIT_GET_SET_FLOAT(_NAME_) \
2577         RNA_LAYER_ENGINE_GET_SET(float, EditMode, COLLECTION_MODE_EDIT, _NAME_)
2578
2579 #define RNA_LAYER_MODE_EDIT_GET_SET_INT(_NAME_) \
2580         RNA_LAYER_ENGINE_GET_SET(int, EditMode, COLLECTION_MODE_EDIT, _NAME_)
2581
2582 #define RNA_LAYER_MODE_EDIT_GET_SET_BOOL(_NAME_) \
2583         RNA_LAYER_ENGINE_GET_SET(bool, EditMode, COLLECTION_MODE_EDIT, _NAME_)
2584
2585 #define RNA_LAYER_MODE_PAINT_WEIGHT_GET_SET_BOOL(_NAME_) \
2586         RNA_LAYER_ENGINE_GET_SET(bool, PaintWeightMode, COLLECTION_MODE_PAINT_WEIGHT, _NAME_)
2587
2588 #define RNA_LAYER_MODE_PAINT_VERTEX_GET_SET_BOOL(_NAME_) \
2589         RNA_LAYER_ENGINE_GET_SET(bool, PaintVertexMode, COLLECTION_MODE_PAINT_VERTEX, _NAME_)
2590
2591 /* clay engine */
2592 #ifdef WITH_CLAY_ENGINE
2593 /* SceneLayer settings. */
2594 RNA_LAYER_ENGINE_CLAY_GET_SET_INT(ssao_samples)
2595
2596 /* LayerCollection settings. */
2597 RNA_LAYER_ENGINE_CLAY_GET_SET_INT(matcap_icon)
2598 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(matcap_rotation)
2599 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(matcap_hue)
2600 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(matcap_saturation)
2601 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(matcap_value)
2602 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(ssao_factor_cavity)
2603 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(ssao_factor_edge)
2604 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(ssao_distance)
2605 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(ssao_attenuation)
2606 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(hair_brightness_randomness)
2607 #endif /* WITH_CLAY_ENGINE */
2608
2609 /* eevee engine */
2610 /* SceneLayer settings. */
2611 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(gtao_enable)
2612 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(gtao_use_bent_normals)
2613 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(gtao_factor)
2614 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(gtao_distance)
2615 RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(gtao_samples)
2616 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(dof_enable)
2617 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bokeh_max_size)
2618 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bokeh_threshold)
2619 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(bloom_enable)
2620 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bloom_threshold)
2621 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bloom_knee)
2622 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bloom_radius)
2623 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bloom_intensity)
2624 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(motion_blur_enable)
2625 RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(motion_blur_samples)
2626 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(motion_blur_shutter)
2627 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(volumetric_enable)
2628 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(volumetric_start)
2629 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(volumetric_end)
2630 RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(volumetric_samples)
2631 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(volumetric_sample_distribution)
2632 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(volumetric_lights)
2633 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(volumetric_light_clamp)
2634 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(volumetric_shadows)
2635 RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(volumetric_shadow_samples)
2636 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(volumetric_colored_transmittance)
2637 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(ssr_refraction)
2638 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(ssr_enable)
2639 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(ssr_halfres)
2640 RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(ssr_ray_count)
2641 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(ssr_quality)
2642 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(ssr_max_roughness)
2643 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(ssr_thickness)
2644 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(ssr_border_fade)
2645 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(ssr_firefly_fac)
2646
2647 /* object engine */
2648 RNA_LAYER_MODE_OBJECT_GET_SET_BOOL(show_wire)
2649 RNA_LAYER_MODE_OBJECT_GET_SET_BOOL(show_backface_culling)
2650
2651 /* mesh engine */
2652 RNA_LAYER_MODE_EDIT_GET_SET_BOOL(show_occlude_wire)
2653 RNA_LAYER_MODE_EDIT_GET_SET_BOOL(show_weight)
2654 RNA_LAYER_MODE_EDIT_GET_SET_BOOL(face_normals_show)
2655 RNA_LAYER_MODE_EDIT_GET_SET_BOOL(vert_normals_show)
2656 RNA_LAYER_MODE_EDIT_GET_SET_BOOL(loop_normals_show)
2657 RNA_LAYER_MODE_EDIT_GET_SET_FLOAT(normals_length)
2658 RNA_LAYER_MODE_EDIT_GET_SET_FLOAT(backwire_opacity)
2659
2660 /* weight paint engine */
2661 RNA_LAYER_MODE_PAINT_WEIGHT_GET_SET_BOOL(use_shading)
2662 RNA_LAYER_MODE_PAINT_WEIGHT_GET_SET_BOOL(use_wire)
2663
2664 /* vertex paint engine */
2665 RNA_LAYER_MODE_PAINT_VERTEX_GET_SET_BOOL(use_shading)
2666 RNA_LAYER_MODE_PAINT_VERTEX_GET_SET_BOOL(use_wire)
2667
2668 #undef RNA_LAYER_ENGINE_GET_SET
2669
2670 static void rna_SceneLayerEngineSettings_update(bContext *C, PointerRNA *UNUSED(ptr))
2671 {
2672         Scene *scene = CTX_data_scene(C);
2673         /* TODO(sergey): Use proper flag for tagging here. */
2674         DEG_id_tag_update(&scene->id, 0);
2675 }
2676
2677 static void rna_LayerCollectionEngineSettings_update(bContext *C, PointerRNA *UNUSED(ptr))
2678 {
2679         Scene *scene = CTX_data_scene(C);
2680         /* TODO(sergey): Use proper flag for tagging here. */
2681         DEG_id_tag_update(&scene->id, 0);
2682 }
2683
2684 static void rna_LayerCollectionEngineSettings_wire_update(bContext *C, PointerRNA *UNUSED(ptr))
2685 {
2686         Scene *scene = CTX_data_scene(C);
2687         SceneLayer *sl = CTX_data_scene_layer(C);
2688         Object *ob = OBACT_NEW;
2689
2690         if (ob != NULL && ob->type == OB_MESH) {
2691                 BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_NOCHECK);
2692         }
2693
2694         /* TODO(sergey): Use proper flag for tagging here. */
2695         DEG_id_tag_update(&scene->id, 0);
2696 }
2697
2698 /***********************************/
2699
2700 static void engine_settings_use(IDProperty *root, IDProperty *props, PointerRNA *props_ptr, const char *identifier)
2701 {
2702         PropertyRNA *prop = RNA_struct_find_property(props_ptr, identifier);
2703
2704         switch (RNA_property_type(prop)) {
2705                 case PROP_FLOAT:
2706                 {
2707                         float value = BKE_collection_engine_property_value_get_float(props, identifier);
2708                         BKE_collection_engine_property_add_float(root, identifier, value);
2709                         break;
2710                 }
2711                 case PROP_ENUM:
2712                 {
2713                         int value = BKE_collection_engine_property_value_get_int(props, identifier);
2714                         BKE_collection_engine_property_add_int(root, identifier, value);
2715                         break;
2716                 }
2717                 case PROP_INT:
2718                 {
2719                         int value = BKE_collection_engine_property_value_get_int(props, identifier);
2720                         BKE_collection_engine_property_add_int(root, identifier, value);
2721                         break;
2722                 }
2723                 case PROP_BOOLEAN:
2724                 {
2725                         int value = BKE_collection_engine_property_value_get_int(props, identifier);
2726                         BKE_collection_engine_property_add_bool(root, identifier, value);
2727                         break;
2728                 }
2729                 case PROP_STRING:
2730                 case PROP_POINTER:
2731                 case PROP_COLLECTION:
2732                 default:
2733                         break;
2734         }
2735 }
2736
2737 static void rna_SceneLayerSettings_name_get(PointerRNA *ptr, char *value)
2738 {
2739         IDProperty *props = (IDProperty *)ptr->data;
2740         strcpy(value, props->name);
2741 }
2742
2743 static int rna_SceneLayerSettings_name_length(PointerRNA *ptr)
2744 {
2745         IDProperty *props = (IDProperty *)ptr->data;
2746         return strnlen(props->name, sizeof(props->name));
2747 }
2748
2749 static void rna_SceneLayerSettings_use(ID *id, IDProperty *props, const char *identifier)
2750 {
2751         Scene *scene = (Scene *)id;
2752         PointerRNA scene_props_ptr;
2753         IDProperty *scene_props;
2754
2755         scene_props = BKE_scene_layer_engine_scene_get(scene, COLLECTION_MODE_NONE, props->name);
2756         RNA_pointer_create(id, &RNA_SceneLayerSettings, scene_props, &scene_props_ptr);
2757
2758         engine_settings_use(props, scene_props, &scene_props_ptr, identifier);
2759
2760         /* TODO(sergey): Use proper flag for tagging here. */
2761         DEG_id_tag_update(id, 0);
2762 }
2763
2764 static void rna_SceneLayerSettings_unuse(ID *id, IDProperty *props, const char *identifier)
2765 {
2766         IDProperty *prop_to_remove = IDP_GetPropertyFromGroup(props, identifier);
2767         IDP_FreeFromGroup(props, prop_to_remove);
2768
2769         /* TODO(sergey): Use proper flag for tagging here. */
2770         DEG_id_tag_update(id, 0);
2771 }
2772
2773 static void rna_LayerCollectionSettings_name_get(PointerRNA *ptr, char *value)
2774 {
2775         IDProperty *props = (IDProperty *)ptr->data;
2776         strcpy(value, props->name);
2777 }
2778
2779 static int rna_LayerCollectionSettings_name_length(PointerRNA *ptr)
2780 {
2781         IDProperty *props = (IDProperty *)ptr->data;
2782         return strnlen(props->name, sizeof(props->name));
2783 }
2784
2785 static void rna_LayerCollectionSettings_use(ID *id, IDProperty *props, const char *identifier)
2786 {
2787         Scene *scene = (Scene *)id;
2788         PointerRNA scene_props_ptr;
2789         IDProperty *scene_props;
2790
2791         scene_props = BKE_layer_collection_engine_scene_get(scene, COLLECTION_MODE_NONE, props->name);
2792         RNA_pointer_create(id, &RNA_LayerCollectionSettings, scene_props, &scene_props_ptr);
2793         engine_settings_use(props, scene_props, &scene_props_ptr, identifier);
2794
2795         /* TODO(sergey): Use proper flag for tagging here. */
2796         DEG_id_tag_update(id, 0);
2797 }
2798
2799 static void rna_LayerCollectionSettings_unuse(ID *id, IDProperty *props, const char *identifier)
2800 {
2801         IDProperty *prop_to_remove = IDP_GetPropertyFromGroup(props, identifier);
2802         IDP_FreeFromGroup(props, prop_to_remove);
2803
2804         /* TODO(sergey): Use proper flag for tagging here. */
2805         DEG_id_tag_update(id, 0);
2806 }
2807
2808 static void rna_LayerCollection_name_get(PointerRNA *ptr, char *value)
2809 {
2810         SceneCollection *sc = ((LayerCollection *)ptr->data)->scene_collection;
2811         strcpy(value, sc->name);
2812 }
2813
2814 static int rna_LayerCollection_name_length(PointerRNA *ptr)
2815 {
2816         SceneCollection *sc = ((LayerCollection *)ptr->data)->scene_collection;
2817         return strnlen(sc->name, sizeof(sc->name));
2818 }
2819
2820 static void rna_LayerCollection_name_set(PointerRNA *ptr, const char *value)
2821 {
2822         Scene *scene = (Scene *)ptr->id.data;
2823         SceneCollection *sc = ((LayerCollection *)ptr->data)->scene_collection;
2824         BKE_collection_rename(scene, sc, value);
2825 }
2826
2827 static PointerRNA rna_LayerCollection_objects_get(CollectionPropertyIterator *iter)
2828 {
2829         ListBaseIterator *internal = &iter->internal.listbase;
2830         Base *base = ((LinkData *)internal->link)->data;
2831         return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, base->object);
2832 }
2833
2834 static int rna_LayerCollection_move_above(ID *id, LayerCollection *lc_src, Main *bmain, LayerCollection *lc_dst)
2835 {
2836         Scene *scene = (Scene *)id;
2837
2838         if (!BKE_layer_collection_move_above(scene, lc_dst, lc_src)) {
2839                 return 0;
2840         }
2841
2842         DEG_relations_tag_update(bmain);
2843         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
2844
2845         return 1;
2846 }
2847
2848 static int rna_LayerCollection_move_below(ID *id, LayerCollection *lc_src, Main *bmain, LayerCollection *lc_dst)
2849 {
2850         Scene *scene = (Scene *)id;
2851
2852         if (!BKE_layer_collection_move_below(scene, lc_dst, lc_src)) {
2853                 return 0;
2854         }
2855
2856         DEG_relations_tag_update(bmain);
2857         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
2858
2859         return 1;
2860 }
2861
2862 static int rna_LayerCollection_move_into(ID *id, LayerCollection *lc_src, Main *bmain, LayerCollection *lc_dst)
2863 {
2864         Scene *scene = (Scene *)id;
2865
2866         if (!BKE_layer_collection_move_into(scene, lc_dst, lc_src)) {
2867                 return 0;
2868         }
2869
2870         DEG_relations_tag_update(bmain);
2871         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
2872
2873         return 1;
2874 }
2875
2876 static void rna_LayerCollection_flag_update(bContext *C, PointerRNA *UNUSED(ptr))
2877 {
2878         Scene *scene = CTX_data_scene(C);
2879         /* TODO(sergey): Use proper flag for tagging here. */
2880         DEG_id_tag_update(&scene->id, 0);
2881         WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
2882 }
2883
2884 static int rna_LayerCollections_active_collection_index_get(PointerRNA *ptr)
2885 {
2886         SceneLayer *sl = (SceneLayer *)ptr->data;
2887         return sl->active_collection;
2888 }
2889
2890 static void rna_LayerCollections_active_collection_index_set(PointerRNA *ptr, int value)
2891 {
2892         SceneLayer *sl = (SceneLayer *)ptr->data;
2893         int num_collections = BKE_layer_collection_count(sl);
2894         sl->active_collection = min_ff(value, num_collections - 1);
2895 }
2896
2897 static void rna_LayerCollections_active_collection_index_range(
2898         PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
2899 {
2900         SceneLayer *sl = (SceneLayer *)ptr->data;
2901         *min = 0;
2902         *max = max_ii(0, BKE_layer_collection_count(sl) - 1);
2903 }
2904
2905 static PointerRNA rna_LayerCollections_active_collection_get(PointerRNA *ptr)
2906 {
2907         SceneLayer *sl = (SceneLayer *)ptr->data;
2908         LayerCollection *lc = BKE_layer_collection_get_active(sl);
2909         return rna_pointer_inherit_refine(ptr, &RNA_LayerCollection, lc);
2910 }
2911
2912 static void rna_LayerCollections_active_collection_set(PointerRNA *ptr, PointerRNA value)
2913 {
2914         SceneLayer *sl = (SceneLayer *)ptr->data;
2915         LayerCollection *lc = (LayerCollection *)value.data;
2916         const int index = BKE_layer_collection_findindex(sl, lc);
2917         if (index != -1) sl->active_collection = index;
2918 }
2919
2920 LayerCollection * rna_SceneLayer_collection_link(
2921         ID *id, SceneLayer *sl, Main *bmain, SceneCollection *sc)
2922 {
2923         Scene *scene = (Scene *)id;
2924         LayerCollection *lc = BKE_collection_link(sl, sc);
2925
2926         DEG_relations_tag_update(bmain);
2927         /* TODO(sergey): Use proper flag for tagging here. */
2928         DEG_id_tag_update(id, 0);
2929         WM_main_add_notifier(NC_SCENE | ND_LAYER, scene);
2930
2931         return lc;
2932 }
2933
2934 static void rna_SceneLayer_collection_unlink(
2935         ID *id, SceneLayer *sl, Main *bmain, ReportList *reports, LayerCollection *lc)
2936 {
2937         Scene *scene = (Scene *)id;
2938
2939         if (BLI_findindex(&sl->layer_collections, lc) == -1) {
2940                 BKE_reportf(reports, RPT_ERROR, "Layer collection '%s' is not in '%s'", lc->scene_collection->name, sl->name);
2941                 return;
2942         }
2943
2944         BKE_collection_unlink(sl, lc);
2945
2946         DEG_relations_tag_update(bmain);
2947         /* TODO(sergey): Use proper flag for tagging here. */
2948         DEG_id_tag_update(id, 0);
2949         WM_main_add_notifier(NC_SCENE | ND_LAYER | ND_OB_ACTIVE, scene);
2950 }
2951
2952 static PointerRNA rna_LayerObjects_active_object_get(PointerRNA *ptr)
2953 {
2954         SceneLayer *sl = (SceneLayer *)ptr->data;
2955         return rna_pointer_inherit_refine(ptr, &RNA_Object, sl->basact ? sl->basact->object : NULL);
2956 }
2957
2958 static void rna_LayerObjects_active_object_set(PointerRNA *ptr, PointerRNA value)
2959 {
2960         SceneLayer *sl = (SceneLayer *)ptr->data;
2961         if (value.data)
2962                 sl->basact = BKE_scene_layer_base_find(sl, (Object *)value.data);
2963         else
2964                 sl->basact = NULL;
2965 }
2966
2967 static void rna_SceneLayer_name_set(PointerRNA *ptr, const char *value)
2968 {
2969         Scene *scene = (Scene *)ptr->id.data;
2970         SceneLayer *sl = (SceneLayer *)ptr->data;
2971         char oldname[sizeof(sl->name)];
2972
2973         BLI_strncpy(oldname, sl->name, sizeof(sl->name));
2974
2975         BLI_strncpy_utf8(sl->name, value, sizeof(sl->name));
2976         BLI_uniquename(&scene->render_layers, sl, DATA_("SceneLayer"), '.', offsetof(SceneLayer, name), sizeof(sl->name));
2977
2978         if (scene->nodetree) {
2979                 bNode *node;
2980                 int index = BLI_findindex(&scene->render_layers, sl);
2981
2982                 for (node = scene->nodetree->nodes.first; node; node = node->next) {
2983                         if (node->type == CMP_NODE_R_LAYERS && node->id == NULL) {
2984                                 if (node->custom1 == index)
2985                                         BLI_strncpy(node->name, sl->name, NODE_MAXSTR);
2986                         }
2987                 }
2988         }
2989 }
2990
2991 static PointerRNA rna_SceneLayer_objects_get(CollectionPropertyIterator *iter)
2992 {
2993         ListBaseIterator *internal = &iter->internal.listbase;
2994
2995         /* we are actually iterating a ObjectBase list, so override get */
2996         Base *base = (Base *)internal->link;
2997         return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, base->object);
2998 }
2999
3000 static int rna_SceneLayer_objects_selected_skip(CollectionPropertyIterator *iter, void *UNUSED(data))
3001 {
3002         ListBaseIterator *internal = &iter->internal.listbase;
3003         Base *base = (Base *)internal->link;
3004
3005         if ((base->flag & BASE_SELECTED) != 0) {
3006                         return 0;
3007         }
3008
3009         return 1;
3010 };
3011
3012 static void rna_LayerObjects_selected_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
3013 {
3014         SceneLayer *sl = (SceneLayer *)ptr->data;
3015         rna_iterator_listbase_begin(iter, &sl->object_bases, rna_SceneLayer_objects_selected_skip);
3016 }
3017
3018 static void rna_SceneLayer_engine_set(PointerRNA *ptr, int value)
3019 {
3020         SceneLayer *sl = (SceneLayer *)ptr->data;
3021         RenderEngineType *type = BLI_findlink(&R_engines, value);
3022
3023         if (type)
3024                 BKE_scene_layer_engine_set(sl, type->idname);
3025 }
3026
3027 static EnumPropertyItem *rna_SceneLayer_engine_itemf(
3028         bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
3029 {
3030         RenderEngineType *type;
3031         EnumPropertyItem *item = NULL;
3032         EnumPropertyItem tmp = {0, "", 0, "", ""};
3033         int a = 0, totitem = 0;
3034
3035         for (type = R_engines.first; type; type = type->next, a++) {
3036                 tmp.value = a;
3037                 tmp.identifier = type->idname;
3038                 tmp.name = type->name;
3039                 RNA_enum_item_add(&item, &totitem, &tmp);
3040         }
3041
3042         RNA_enum_item_end(&item, &totitem);
3043         *r_free = true;
3044
3045         return item;
3046 }
3047
3048 static int rna_SceneLayer_engine_get(PointerRNA *ptr)
3049 {
3050         SceneLayer *sl = (SceneLayer *)ptr->data;
3051         RenderEngineType *type;
3052         int a = 0;
3053
3054         for (type = R_engines.first; type; type = type->next, a++)
3055                 if (STREQ(type->idname, sl->engine))
3056                         return a;
3057
3058         return 0;
3059 }
3060
3061 static void rna_SceneLayer_engine_update(Main *bmain, Scene *UNUSED(unused), PointerRNA *UNUSED(ptr))
3062 {
3063         ED_render_engine_changed(bmain);
3064 }
3065
3066 static int rna_SceneLayer_multiple_engines_get(PointerRNA *UNUSED(ptr))
3067 {
3068         return (BLI_listbase_count(&R_engines) > 1);
3069 }
3070
3071 static void rna_SceneLayer_update_tagged(SceneLayer *UNUSED(sl), bContext *C)
3072 {
3073         Depsgraph *graph = CTX_data_depsgraph(C);
3074         DEG_OBJECT_ITER(graph, ob, DEG_OBJECT_ITER_FLAG_ALL)
3075         {
3076                 /* Don't do anything, we just need to run the iterator to flush
3077                  * the base info to the objects. */
3078                 UNUSED_VARS(ob);
3079         }
3080         DEG_OBJECT_ITER_END
3081 }
3082
3083 static int rna_SceneLayer_active_layer_index_get(PointerRNA *ptr)
3084 {
3085         Scene *scene = (Scene *)ptr->data;
3086         return scene->active_layer;
3087 }
3088
3089 static void rna_SceneLayer_active_layer_index_set(PointerRNA *ptr, int value)
3090 {
3091         Scene *scene = (Scene *)ptr->data;
3092         int num_layers = BLI_listbase_count(&scene->render_layers);
3093         scene->active_layer = min_ff(value, num_layers - 1);
3094 }
3095
3096 static void rna_SceneLayer_active_layer_index_range(
3097         PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
3098 {
3099         Scene *scene = (Scene *)ptr->data;
3100
3101         *min = 0;
3102         *max = max_ii(0, BLI_listbase_count(&scene->render_layers) - 1);
3103 }
3104
3105 static PointerRNA rna_SceneLayer_active_layer_get(PointerRNA *ptr)
3106 {
3107         Scene *scene = (Scene *)ptr->data;
3108         SceneLayer *sl = BLI_findlink(&scene->render_layers, scene->active_layer);
3109
3110         return rna_pointer_inherit_refine(ptr, &RNA_SceneLayer, sl);
3111 }
3112
3113 static void rna_SceneLayer_active_layer_set(PointerRNA *ptr, PointerRNA value)
3114 {
3115         Scene *scene = (Scene *)ptr->data;
3116         SceneLayer *sl = (SceneLayer *)value.data;
3117         const int index = BLI_findindex(&scene->render_layers, sl);
3118         if (index != -1) scene->active_layer = index;
3119 }
3120
3121 static SceneLayer *rna_SceneLayer_new(
3122         ID *id, Scene *UNUSED(sce), Main *bmain, const char *name)
3123 {
3124         Scene *scene = (Scene *)id;
3125         SceneLayer *sl = BKE_scene_layer_add(scene, name);
3126
3127         DEG_id_tag_update(&scene->id, 0);
3128         DEG_relations_tag_update(bmain);
3129         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
3130
3131         return sl;
3132 }
3133
3134 static void rna_SceneLayer_remove(
3135         ID *id, Scene *UNUSED(sce), Main *bmain, ReportList *reports, PointerRNA *sl_ptr)
3136 {
3137         Scene *scene = (Scene *)id;
3138         SceneLayer *sl = sl_ptr->data;
3139
3140         if (ED_scene_render_layer_delete(bmain, scene, sl, reports)) {
3141                 RNA_POINTER_INVALIDATE(sl_ptr);
3142         }
3143 }
3144
3145 static void rna_ObjectBase_select_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
3146 {
3147         Base *base = (Base *)ptr->data;
3148         short mode = (base->flag & BASE_SELECTED) ? BA_SELECT : BA_DESELECT;
3149         ED_object_base_select(base, mode);
3150 }
3151 #else
3152
3153 /* Grease Pencil Interpolation tool settings */
3154 static void rna_def_gpencil_interpolate(BlenderRNA *brna)
3155 {
3156         StructRNA *srna;
3157         PropertyRNA *prop;
3158         
3159         srna = RNA_def_struct(brna, "GPencilInterpolateSettings", NULL);
3160         RNA_def_struct_sdna(srna, "GP_Interpolate_Settings");
3161         RNA_def_struct_path_func(srna, "rna_GPencilInterpolateSettings_path");
3162         RNA_def_struct_ui_text(srna, "Grease Pencil Interpolate Settings",
3163                                "Settings for Grease Pencil interpolation tools");
3164         
3165         /* flags */
3166         prop = RNA_def_property(srna, "interpolate_all_layers", PROP_BOOLEAN, PROP_NONE);
3167         RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_TOOLFLAG_INTERPOLATE_ALL_LAYERS);
3168         RNA_def_property_ui_text(prop, "Interpolate All Layers", "Interpolate all layers, not only active");
3169         RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
3170
3171         prop = RNA_def_property(srna, "interpolate_selected_only", PROP_BOOLEAN, PROP_NONE);
3172         RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_TOOLFLAG_INTERPOLATE_ONLY_SELECTED);
3173         RNA_def_property_ui_text(prop, "Interpolate Selected Strokes", "Interpolate only selected strokes in the original frame");
3174         RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
3175         
3176         /* interpolation type */
3177         prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
3178         RNA_def_property_enum_sdna(prop, NULL, "type");
3179         RNA_def_property_enum_items(prop, rna_enum_gpencil_interpolation_mode_items);
3180         RNA_def_property_enum_funcs(prop, NULL, "rna_GPencilInterpolateSettings_type_set", NULL);
3181         RNA_def_property_ui_text(prop, "Type",
3182                                  "Interpolation method to use the next time 'Interpolate Sequence' is run");
3183         RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
3184         
3185         /* easing */
3186         prop = RNA_def_property(srna, "easing", PROP_ENUM, PROP_NONE);
3187         RNA_def_property_enum_sdna(prop, NULL, "easing");
3188         RNA_def_property_enum_items(prop, rna_enum_beztriple_interpolation_easing_items);
3189         RNA_def_property_ui_text(prop, "Easing", 
3190                                  "Which ends of the segment between the preceding and following grease pencil frames "
3191                                  "easing interpolation is applied to");
3192         RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
3193         
3194         /* easing options */
3195         prop = RNA_def_property(srna, "back", PROP_FLOAT, PROP_NONE);
3196         RNA_def_property_float_sdna(prop, NULL, "back");
3197         RNA_def_property_ui_text(prop, "Back", "Amount of overshoot for 'back' easing");
3198         RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
3199         
3200         prop = RNA_def_property(srna, "amplitude", PROP_FLOAT, PROP_NONE);
3201         RNA_def_property_float_sdna(prop, NULL, "amplitude");
3202         RNA_def_property_range(prop, 0.0f, FLT_MAX); /* only positive values... */
3203         RNA_def_property_ui_text(prop, "Amplitude", "Amount to boost elastic bounces for 'elastic' easing");
3204         RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
3205         
3206         prop = RNA_def_property(srna, "period", PROP_FLOAT, PROP_NONE);
3207         RNA_def_property_float_sdna(prop, NULL, "period");
3208         RNA_def_property_ui_text(prop, "Period", "Time between bounces for elastic easing");
3209         RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
3210         
3211         /* custom curvemap */
3212         prop = RNA_def_property(srna, "interpolation_curve", PROP_POINTER, PROP_NONE);
3213         RNA_def_property_pointer_sdna(prop, NULL, "custom_ipo");
3214         RNA_def_property_struct_type(prop, "CurveMapping");
3215         RNA_def_property_ui_text(prop, "Interpolation Curve", 
3216                                  "Custom curve to control 'sequence' interpolation between Grease Pencil frames");
3217         RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
3218 }
3219
3220 /* Grease Pencil Drawing Brushes */
3221 static void rna_def_gpencil_brush(BlenderRNA *brna)
3222 {
3223         StructRNA *srna;
3224         PropertyRNA *prop;
3225
3226         srna = RNA_def_struct(brna, "GPencilBrush", NULL);
3227         RNA_def_struct_sdna(srna, "bGPDbrush");
3228         RNA_def_struct_ui_text(srna, "Grease Pencil Brush",
3229                                "Collection of brushes being used to control the line style of new strokes");
3230         RNA_def_struct_ui_icon(srna, ICON_BRUSH_DATA);
3231
3232         /* Name */
3233         prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
3234         RNA_def_property_string_sdna(prop, NULL, "info");
3235         RNA_def_property_ui_text(prop, "Name", "Brush name");
3236         RNA_def_property_string_funcs(prop, NULL, NULL, "rna_GPencilBrush_name_set");
3237         RNA_def_struct_name_property(srna, prop);
3238         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3239
3240         /* Line Thickness */
3241         prop = RNA_def_property(srna, "line_width", PROP_INT, PROP_PIXEL);
3242         RNA_def_property_int_sdna(prop, NULL, "thickness");
3243         RNA_def_property_range(prop, 1, 300);
3244         RNA_def_property_ui_range(prop, 1, 10, 1, 0);
3245         RNA_def_property_ui_text(prop, "Thickness", "Thickness of strokes (in pixels)");
3246         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3247
3248         /* Sensitivity factor for new strokes */
3249         prop = RNA_def_property(srna, "pen_sensitivity_factor", PROP_FLOAT, PROP_NONE);
3250         RNA_def_property_float_sdna(prop, NULL, "draw_sensitivity");
3251         RNA_def_property_range(prop, 0.1f, 3.0f);
3252         RNA_def_property_ui_text(prop, "Sensitivity", "Pressure sensitivity factor for new strokes");
3253         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3254
3255         /* Strength factor for new strokes */
3256         prop = RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
3257         RNA_def_property_float_sdna(prop, NULL, "draw_strength");
3258         RNA_def_property_range(prop, 0.0f, 1.0f);
3259         RNA_def_property_ui_text(prop, "Strength", "Color strength for new strokes (affect alpha factor of color)");
3260         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3261
3262         /* Jitter factor for new strokes */
3263         prop = RNA_def_property(srna, "jitter", PROP_FLOAT, PROP_NONE);
3264         RNA_def_property_float_sdna(prop, NULL, "draw_jitter");
3265         RNA_def_property_range(prop, 0.0f, 1.0f);
3266         RNA_def_property_ui_text(prop, "Jitter", "Jitter factor for new strokes");
3267         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3268
3269         /* Randomnes factor for sensitivity and strength */
3270         prop = RNA_def_property(srna, "random_press", PROP_FLOAT, PROP_NONE);
3271         RNA_def_property_float_sdna(prop, NULL, "draw_random_press");
3272         RNA_def_property_range(prop, 0.0f, 1.0f);
3273         RNA_def_property_ui_text(prop, "Randomness", "Randomness factor for pressure and strength in new strokes");
3274         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3275
3276         /* Randomnes factor for subdivision */
3277         prop = RNA_def_property(srna, "random_subdiv", PROP_FLOAT, PROP_NONE);
3278         RNA_def_property_float_sdna(prop, NULL, "draw_random_sub");
3279         RNA_def_property_range(prop, 0.0f, 1.0f);
3280         RNA_def_property_ui_text(prop, "Random Subdivision", "Randomness factor for new strokes after subdivision");
3281         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3282
3283         /* Angle when brush is full size */
3284         prop = RNA_def_property(srna, "angle", PROP_FLOAT, PROP_ANGLE);
3285         RNA_def_property_float_sdna(prop, NULL, "draw_angle");
3286         RNA_def_property_range(prop, -M_PI_2, M_PI_2);
3287         RNA_def_property_ui_text(prop, "Angle",
3288                                  "Direction of the stroke at which brush gives maximal thickness "
3289                                  "(0° for horizontal)");
3290         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3291
3292         /* Factor to change brush size depending of angle */
3293         prop = RNA_def_property(srna, "angle_factor", PROP_FLOAT, PROP_NONE);
3294         RNA_def_property_float_sdna(prop, NULL, "draw_angle_factor");
3295         RNA_def_property_range(prop, 0.0f, 1.0f);
3296         RNA_def_property_ui_text(prop, "Angle Factor",
3297                                  "Reduce brush thickness by this factor when stroke is perpendicular to 'Angle' direction");
3298         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3299
3300         /* Smoothing factor for new strokes */
3301         prop = RNA_def_property(srna, "pen_smooth_factor", PROP_FLOAT, PROP_NONE);
3302         RNA_def_property_float_sdna(prop, NULL, "draw_smoothfac");
3303         RNA_def_property_range(prop, 0.0, 2.0f);
3304         RNA_def_property_ui_text(prop, "Smooth",
3305                                  "Amount of smoothing to apply to newly created strokes, to reduce jitter/noise");
3306         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3307
3308         /* Iterations of the Smoothing factor */
3309         prop = RNA_def_property(srna, "pen_smooth_steps", PROP_INT, PROP_NONE);
3310         RNA_def_property_int_sdna(prop, NULL, "draw_smoothlvl");
3311         RNA_def_property_range(prop, 1, 3);
3312         RNA_def_property_ui_text(prop, "Iterations",
3313                                  "Number of times to smooth newly created strokes");
3314         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3315
3316         /* Subdivision level for new strokes */
3317         prop = RNA_def_property(srna, "pen_subdivision_steps", PROP_INT, PROP_NONE);
3318         RNA_def_property_int_sdna(prop, NULL, "sublevel");
3319         RNA_def_property_range(prop, 0, 3);
3320         RNA_def_property_ui_text(prop, "Subdivision Steps",
3321                                  "Number of times to subdivide newly created strokes, for less jagged strokes");
3322         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3323
3324         /* Curves for pressure */
3325         prop = RNA_def_property(srna, "curve_sensitivity", PROP_POINTER, PROP_NONE);
3326         RNA_def_property_pointer_sdna(prop, NULL, "cur_sensitivity");
3327         RNA_def_property_struct_type(prop, "CurveMapping");
3328         RNA_def_property_ui_text(prop, "Curve Sensitivity", "Curve used for the sensitivity");
3329         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3330
3331         prop = RNA_def_property(srna, "curve_strength", PROP_POINTER, PROP_NONE);
3332         RNA_def_property_pointer_sdna(prop, NULL, "cur_strength");
3333         RNA_def_property_struct_type(prop, "CurveMapping");
3334         RNA_def_property_ui_text(prop, "Curve Strength", "Curve used for the strength");
3335         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3336
3337         prop = RNA_def_property(srna, "curve_jitter", PROP_POINTER, PROP_NONE);
3338         RNA_def_property_pointer_sdna(prop, NULL, "cur_jitter");
3339         RNA_def_property_struct_type(prop, "CurveMapping");
3340         RNA_def_property_ui_text(prop, "Curve Jitter", "Curve used for the jitter effect");
3341         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3342
3343         /* Flags */
3344         prop = RNA_def_property(srna, "use_pressure", PROP_BOOLEAN, PROP_NONE);
3345         RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_USE_PRESSURE);
3346         RNA_def_property_ui_icon(prop, ICON_STYLUS_PRESSURE, 0);
3347         RNA_def_property_ui_text(prop, "Use Pressure", "Use tablet pressure");
3348         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3349
3350         prop = RNA_def_property(srna, "use_strength_pressure", PROP_BOOLEAN, PROP_NONE);
3351         RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_USE_STENGTH_PRESSURE);
3352         RNA_def_property_ui_icon(prop, ICON_STYLUS_PRESSURE, 0);
3353         RNA_def_property_ui_text(prop, "Use Pressure Strength", "Use tablet pressure for color strength");
3354         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3355
3356         prop = RNA_def_property(srna, "use_jitter_pressure", PROP_BOOLEAN, PROP_NONE);
3357         RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_USE_JITTER_PRESSURE);
3358         RNA_def_property_ui_icon(prop, ICON_STYLUS_PRESSURE, 0);
3359         RNA_def_property_ui_text(prop, "Use Pressure Jitter", "Use tablet pressure for jitter");
3360         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3361
3362         prop = RNA_def_property(srna, "use_random_pressure", PROP_BOOLEAN, PROP_NONE);
3363         RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_USE_RANDOM_PRESSURE);
3364         RNA_def_property_ui_icon(prop, ICON_PARTICLES, 0);
3365         RNA_def_property_ui_text(prop, "Random Pressure", "Use random value for pressure");
3366         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3367
3368         prop = RNA_def_property(srna, "use_random_strength", PROP_BOOLEAN, PROP_NONE);
3369         RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_USE_RANDOM_STRENGTH);
3370         RNA_def_property_ui_icon(prop, ICON_PARTICLES, 0);
3371         RNA_def_property_ui_text(prop, "Random Strength", "Use random value for strength");
3372         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3373
3374 }
3375
3376 /* Grease Pencil Drawing Brushes API */
3377 static void rna_def_gpencil_brushes(BlenderRNA *brna, PropertyRNA *cprop)
3378 {
3379         StructRNA *srna;
3380         PropertyRNA *prop;
3381
3382         FunctionRNA *func;
3383         PropertyRNA *parm;
3384
3385         RNA_def_property_srna(cprop, "GreasePencilBrushes");
3386         srna = RNA_def_struct(brna, "GreasePencilBrushes", NULL);
3387         RNA_def_struct_sdna(srna, "ToolSettings");
3388         RNA_def_struct_ui_text(srna, "Grease Pencil Brushes", "Collection of grease pencil brushes");
3389
3390         func = RNA_def_function(srna, "new", "rna_GPencil_brush_new");
3391         RNA_def_function_ui_description(func, "Add a new grease pencil brush");
3392         parm = RNA_def_string(func, "name", "GPencilBrush", MAX_NAME, "Name", "Name of the brush");
3393         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
3394         RNA_def_boolean(func, "set_active", 0, "Set Active", "Set the newly created brush to the active brush");
3395         parm = RNA_def_pointer(func, "palette", "GPencilBrush", "", "The newly created brush");
3396         RNA_def_function_return(func, parm);
3397
3398         func = RNA_def_function(srna, "remove", "rna_GPencil_brush_remove");
3399         RNA_def_function_ui_description(func, "Remove a grease pencil brush");
3400         RNA_def_function_flag(func, FUNC_USE_REPORTS);
3401         parm = RNA_def_pointer(func, "brush", "GPencilBrush", "", "The brush to remove");
3402         RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
3403         RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
3404
3405         prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
3406         RNA_def_property_struct_type(prop, "GPencilBrush");
3407         RNA_def_property_pointer_funcs(prop, "rna_GPencilBrushes_active_get", "rna_GPencilBrushes_active_set", NULL, NULL);
3408         RNA_def_property_flag(prop, PROP_EDITABLE);
3409         RNA_def_property_ui_text(prop, "Active Brush", "Current active brush");
3410
3411         prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
3412         RNA_def_property_int_funcs(prop,
3413                 "rna_GPencilBrushes_index_get",
3414                 "rna_GPencilBrushes_index_set",
3415                 "rna_GPencilBrushes_index_range");
3416         RNA_def_property_ui_text(prop, "Active Brush Index", "Index of active brush");
3417 }
3418
3419 static void rna_def_tool_settings(BlenderRNA  *brna)
3420 {
3421         StructRNA *srna;
3422         PropertyRNA *prop;
3423
3424         static EnumPropertyItem uv_select_mode_items[] = {
3425                 {UV_SELECT_VERTEX, "VERTEX", ICON_UV_VERTEXSEL, "Vertex", "Vertex selection mode"},
3426                 {UV_SELECT_EDGE, "EDGE", ICON_UV_EDGESEL, "Edge", "Edge selection mode"},
3427                 {UV_SELECT_FACE, "FACE", ICON_UV_FACESEL, "Face", "Face selection mode"},
3428                 {UV_SELECT_ISLAND, "ISLAND", ICON_UV_ISLANDSEL, "Island", "Island selection mode"},
3429                 {0, NULL, 0, NULL, NULL}
3430         };
3431         
3432         /* the construction of this enum is quite special - everything is stored as bitflags,
3433          * with 1st position only for for on/off (and exposed as boolean), while others are mutually
3434          * exclusive options but which will only have any effect when autokey is enabled
3435          */
3436         static EnumPropertyItem auto_key_items[] = {
3437                 {AUTOKEY_MODE_NORMAL & ~AUTOKEY_ON, "ADD_REPLACE_KEYS", 0, "Add & Replace", ""},
3438                 {AUTOKEY_MODE_EDITKEYS & ~AUTOKEY_ON, "REPLACE_KEYS", 0, "Replace", ""},
3439                 {0, NULL, 0, NULL, NULL}
3440         };
3441
3442         static EnumPropertyItem retarget_roll_items[] = {
3443                 {SK_RETARGET_ROLL_NONE, "NONE", 0, "None", "Don't adjust roll"},
3444                 {SK_RETARGET_ROLL_VIEW, "VIEW", 0, "View", "Roll bones to face the view"},
3445                 {SK_RETARGET_ROLL_JOINT, "JOINT", 0, "Joint", "Ro