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