Merge branch 'master' into blender2.8
[blender.git] / source / blender / makesrna / intern / rna_scene.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Blender Foundation (2008).
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/makesrna/intern/rna_scene.c
24  *  \ingroup RNA
25  */
26
27 #include <stdlib.h>
28
29 #include "DNA_brush_types.h"
30 #include "DNA_group_types.h"
31 #include "DNA_modifier_types.h"
32 #include "DNA_particle_types.h"
33 #include "DNA_rigidbody_types.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_layer_types.h"
36 #include "DNA_linestyle_types.h"
37 #include "DNA_userdef_types.h"
38 #include "DNA_world_types.h"
39 #include "DNA_gpencil_types.h"
40
41 #include "IMB_imbuf_types.h"
42
43 #include "BLI_math.h"
44 #include "BLI_string_utils.h"
45
46 #include "BLT_translation.h"
47
48 #include "BKE_editmesh.h"
49 #include "BKE_paint.h"
50
51 #include "ED_object.h"
52
53 #include "GPU_extensions.h"
54
55 #include "DRW_engine.h"
56
57 #include "RNA_define.h"
58 #include "RNA_enum_types.h"
59
60 #include "rna_internal.h"
61
62 /* Include for Bake Options */
63 #include "RE_engine.h"
64 #include "RE_pipeline.h"
65
66 #ifdef WITH_QUICKTIME
67 #  include "quicktime_export.h"
68 #  include AUD_TYPES_H
69 #endif
70
71 #ifdef WITH_FFMPEG
72 #  include "BKE_writeffmpeg.h"
73 #  include <libavcodec/avcodec.h>
74 #  include <libavformat/avformat.h>
75 #  include "ffmpeg_compat.h"
76 #endif
77
78 #include "ED_render.h"
79
80 #include "WM_api.h"
81 #include "WM_types.h"
82
83 #include "BLI_threads.h"
84
85 #ifdef WITH_OPENEXR
86 EnumPropertyItem rna_enum_exr_codec_items[] = {
87         {R_IMF_EXR_CODEC_NONE, "NONE", 0, "None", ""},
88         {R_IMF_EXR_CODEC_PXR24, "PXR24", 0, "Pxr24 (lossy)", ""},
89         {R_IMF_EXR_CODEC_ZIP, "ZIP", 0, "ZIP (lossless)", ""},
90         {R_IMF_EXR_CODEC_PIZ, "PIZ", 0, "PIZ (lossless)", ""},
91         {R_IMF_EXR_CODEC_RLE, "RLE", 0, "RLE (lossless)", ""},
92         {R_IMF_EXR_CODEC_ZIPS, "ZIPS", 0, "ZIPS (lossless)", ""},
93         {R_IMF_EXR_CODEC_B44, "B44", 0, "B44 (lossy)", ""},
94         {R_IMF_EXR_CODEC_B44A, "B44A", 0, "B44A (lossy)", ""},
95         {R_IMF_EXR_CODEC_DWAA, "DWAA", 0, "DWAA (lossy)", ""},
96         /* NOTE: Commented out for until new OpenEXR is released, see T50673. */
97         /* {R_IMF_EXR_CODEC_DWAB, "DWAB", 0, "DWAB (lossy)", ""}, */
98         {0, NULL, 0, NULL, NULL}
99 };
100 #endif
101
102 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
1573         if (type)
1574                 BLI_strncpy_utf8(rd->engine, type->idname, sizeof(rd->engine));
1575 }
1576
1577 static EnumPropertyItem *rna_RenderSettings_engine_itemf(
1578         bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
1579 {
1580         RenderEngineType *type;
1581         EnumPropertyItem *item = NULL;
1582         EnumPropertyItem tmp = {0, "", 0, "", ""};
1583         int a = 0, totitem = 0;
1584
1585         for (type = R_engines.first; type; type = type->next, a++) {
1586                 tmp.value = a;
1587                 tmp.identifier = type->idname;
1588                 tmp.name = type->name;
1589                 RNA_enum_item_add(&item, &totitem, &tmp);
1590         }
1591         
1592         RNA_enum_item_end(&item, &totitem);
1593         *r_free = true;
1594
1595         return item;
1596 }
1597
1598 static int rna_RenderSettings_engine_get(PointerRNA *ptr)
1599 {
1600         RenderData *rd = (RenderData *)ptr->data;
1601         RenderEngineType *type;
1602         int a = 0;
1603
1604         for (type = R_engines.first; type; type = type->next, a++)
1605                 if (STREQ(type->idname, rd->engine))
1606                         return a;
1607         
1608         return 0;
1609 }
1610
1611 static void rna_RenderSettings_engine_update(Main *bmain, Scene *UNUSED(unused), PointerRNA *UNUSED(ptr))
1612 {
1613         ED_render_engine_changed(bmain);
1614 }
1615
1616 static void rna_Scene_glsl_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
1617 {
1618         Scene *scene = (Scene *)ptr->id.data;
1619
1620         DEG_id_tag_update(&scene->id, 0);
1621 }
1622
1623 static void rna_Scene_world_update(Main *bmain, Scene *scene, PointerRNA *ptr)
1624 {
1625         Scene *sc = (Scene *)ptr->id.data;
1626
1627         rna_Scene_glsl_update(bmain, scene, ptr);
1628         WM_main_add_notifier(NC_WORLD | ND_WORLD, &sc->id);
1629 }
1630
1631 static void rna_Scene_freestyle_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
1632 {
1633         Scene *scene = (Scene *)ptr->id.data;
1634
1635         DEG_id_tag_update(&scene->id, 0);
1636 }
1637
1638 static void rna_Scene_use_view_map_cache_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
1639 {
1640 #ifdef WITH_FREESTYLE
1641         FRS_free_view_map_cache();
1642 #endif
1643 }
1644
1645 static IDProperty *rna_SceneRenderLayer_idprops(PointerRNA *ptr, bool create)
1646 {
1647         SceneRenderLayer *srl = (SceneRenderLayer *)ptr->data;
1648
1649         if (create && !srl->prop) {
1650                 IDPropertyTemplate val = {0};
1651                 srl->prop = IDP_New(IDP_GROUP, &val, "SceneRenderLayer ID properties");
1652         }
1653
1654         return srl->prop;
1655 }
1656
1657 static void rna_SceneRenderLayer_name_set(PointerRNA *ptr, const char *value)
1658 {
1659         Scene *scene = (Scene *)ptr->id.data;
1660         SceneRenderLayer *rl = (SceneRenderLayer *)ptr->data;
1661         char oldname[sizeof(rl->name)];
1662
1663         BLI_strncpy(oldname, rl->name, sizeof(rl->name));
1664
1665         BLI_strncpy_utf8(rl->name, value, sizeof(rl->name));
1666         BLI_uniquename(&scene->r.layers, rl, DATA_("RenderLayer"), '.', offsetof(SceneRenderLayer, name), sizeof(rl->name));
1667
1668         if (scene->nodetree) {
1669                 bNode *node;
1670                 int index = BLI_findindex(&scene->r.layers, rl);
1671
1672                 for (node = scene->nodetree->nodes.first; node; node = node->next) {
1673                         if (node->type == CMP_NODE_R_LAYERS && node->id == NULL) {
1674                                 if (node->custom1 == index)
1675                                         BLI_strncpy(node->name, rl->name, NODE_MAXSTR);
1676                         }
1677                 }
1678         }
1679
1680         /* fix all the animation data which may link to this */
1681         BKE_animdata_fix_paths_rename_all(NULL, "render.layers", oldname, rl->name);
1682 }
1683
1684 static char *rna_SceneRenderLayer_path(PointerRNA *ptr)
1685 {
1686         SceneRenderLayer *srl = (SceneRenderLayer *)ptr->data;
1687         char name_esc[sizeof(srl->name) * 2];
1688
1689         BLI_strescape(name_esc, srl->name, sizeof(name_esc));
1690         return BLI_sprintfN("render.layers[\"%s\"]", name_esc);
1691 }
1692
1693 static void rna_SceneRenderView_name_set(PointerRNA *ptr, const char *value)
1694 {
1695         Scene *scene = (Scene *)ptr->id.data;
1696         SceneRenderView *rv = (SceneRenderView *)ptr->data;
1697         BLI_strncpy_utf8(rv->name, value, sizeof(rv->name));
1698         BLI_uniquename(&scene->r.views, rv, DATA_("RenderView"), '.', offsetof(SceneRenderView, name), sizeof(rv->name));
1699 }
1700
1701 static char *rna_SceneRenderView_path(PointerRNA *ptr)
1702 {
1703         SceneRenderView *srv = (SceneRenderView *)ptr->data;
1704         return BLI_sprintfN("render.views[\"%s\"]", srv->name);
1705 }
1706
1707 static void rna_RenderSettings_views_format_set(PointerRNA *ptr, int value)
1708 {
1709         RenderData *rd = (RenderData *)ptr->data;
1710
1711         if (rd->views_format == SCE_VIEWS_FORMAT_MULTIVIEW &&
1712             value == SCE_VIEWS_FORMAT_STEREO_3D)
1713         {
1714                 /* make sure the actview is visible */
1715                 if (rd->actview > 1) rd->actview = 1;
1716         }
1717
1718         rd->views_format = value;
1719 }
1720
1721 static int rna_RenderSettings_multiple_engines_get(PointerRNA *UNUSED(ptr))
1722 {
1723         return (BLI_listbase_count(&R_engines) > 1);
1724 }
1725
1726 static int rna_RenderSettings_use_shading_nodes_get(PointerRNA *ptr)
1727 {
1728         Scene *scene = (Scene *)ptr->id.data;
1729         return BKE_scene_use_new_shading_nodes(scene);
1730 }
1731
1732 static int rna_RenderSettings_use_spherical_stereo_get(PointerRNA *ptr)
1733 {
1734         Scene *scene = (Scene *)ptr->id.data;
1735         return BKE_scene_use_spherical_stereo(scene);
1736 }
1737
1738 static int rna_RenderSettings_use_game_engine_get(PointerRNA *ptr)
1739 {
1740         RenderData *rd = (RenderData *)ptr->data;
1741         RenderEngineType *type;
1742
1743         for (type = R_engines.first; type; type = type->next)
1744                 if (STREQ(type->idname, rd->engine))
1745                         return (type->flag & RE_GAME) != 0;
1746         
1747         return 0;
1748 }
1749
1750 static void rna_SceneRenderLayer_layer_set(PointerRNA *ptr, const int *values)
1751 {
1752         SceneRenderLayer *rl = (SceneRenderLayer *)ptr->data;
1753         rl->lay = ED_view3d_scene_layer_set(rl->lay, values, NULL);
1754 }
1755
1756 static void rna_SceneRenderLayer_pass_update(Main *bmain, Scene *activescene, PointerRNA *ptr)
1757 {
1758         Scene *scene = (Scene *)ptr->id.data;
1759
1760         if (scene->nodetree)
1761                 ntreeCompositUpdateRLayers(scene->nodetree);
1762
1763         rna_Scene_glsl_update(bmain, activescene, ptr);
1764 }
1765
1766 static void rna_SceneRenderLayer_update_render_passes(ID *id)
1767 {
1768         Scene *scene = (Scene *)id;
1769         if (scene->nodetree)
1770                 ntreeCompositUpdateRLayers(scene->nodetree);
1771 }
1772
1773 static void rna_Scene_use_nodes_update(bContext *C, PointerRNA *ptr)
1774 {
1775         Scene *scene = (Scene *)ptr->data;
1776
1777         if (scene->use_nodes && scene->nodetree == NULL)
1778                 ED_node_composit_default(C, scene);
1779 }
1780
1781 static void rna_Physics_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
1782 {
1783         Scene *scene = (Scene *)ptr->id.data;
1784         FOREACH_SCENE_OBJECT(scene, ob)
1785         {
1786                 BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_DEPSGRAPH);
1787         }
1788         FOREACH_SCENE_OBJECT_END
1789 }
1790
1791 static void rna_Scene_editmesh_select_mode_set(PointerRNA *ptr, const int *value)
1792 {
1793         Scene *scene = (Scene *)ptr->id.data;
1794         SceneLayer *sl = BKE_scene_layer_context_active(scene);
1795         ToolSettings *ts = (ToolSettings *)ptr->data;
1796         int flag = (value[0] ? SCE_SELECT_VERTEX : 0) | (value[1] ? SCE_SELECT_EDGE : 0) | (value[2] ? SCE_SELECT_FACE : 0);
1797
1798         if (flag) {
1799                 ts->selectmode = flag;
1800
1801                 if (sl->basact) {
1802                         Mesh *me = BKE_mesh_from_object(sl->basact->object);
1803                         if (me && me->edit_btmesh && me->edit_btmesh->selectmode != flag) {
1804                                 me->edit_btmesh->selectmode = flag;
1805                                 EDBM_selectmode_set(me->edit_btmesh);
1806                         }
1807                 }
1808         }
1809 }
1810
1811 static void rna_Scene_editmesh_select_mode_update(Main *UNUSED(bmain), bContext *C, Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
1812 {
1813         SceneLayer *sl = CTX_data_scene_layer(C);
1814         Mesh *me = NULL;
1815
1816         if (sl->basact) {
1817                 me = BKE_mesh_from_object(sl->basact->object);
1818                 if (me && me->edit_btmesh == NULL)
1819                         me = NULL;
1820         }
1821
1822         WM_main_add_notifier(NC_GEOM | ND_SELECT, me);
1823         WM_main_add_notifier(NC_SCENE | ND_TOOLSETTINGS, NULL);
1824 }
1825
1826 static void object_simplify_update(Object *ob)
1827 {
1828         ModifierData *md;
1829         ParticleSystem *psys;
1830
1831         if ((ob->id.tag & LIB_TAG_DOIT) == 0) {
1832                 return;
1833         }
1834
1835         ob->id.tag &= ~LIB_TAG_DOIT;
1836
1837         for (md = ob->modifiers.first; md; md = md->next) {
1838                 if (ELEM(md->type, eModifierType_Subsurf, eModifierType_Multires, eModifierType_ParticleSystem)) {
1839                         DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
1840                 }
1841         }
1842
1843         for (psys = ob->particlesystem.first; psys; psys = psys->next)
1844                 psys->recalc |= PSYS_RECALC_CHILD;
1845         
1846         if (ob->dup_group) {
1847                 GroupObject *gob;
1848
1849                 for (gob = ob->dup_group->gobject.first; gob; gob = gob->next)
1850                         object_simplify_update(gob->ob);
1851         }
1852 }
1853
1854 static void rna_Scene_use_simplify_update(Main *bmain, Scene *scene, PointerRNA *ptr)
1855 {
1856         Scene *sce = ptr->id.data;
1857         Scene *sce_iter;
1858         Base *base;
1859
1860         BKE_main_id_tag_listbase(&bmain->object, LIB_TAG_DOIT, true);
1861         for (SETLOOPER(sce, sce_iter, base))
1862                 object_simplify_update(base->object);
1863         
1864         WM_main_add_notifier(NC_GEOM | ND_DATA, NULL);
1865         DEG_id_tag_update(&scene->id, 0);
1866 }
1867
1868 static void rna_Scene_simplify_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
1869 {
1870         Scene *sce = ptr->id.data;
1871
1872         if (sce->r.mode & R_SIMPLIFY)
1873                 rna_Scene_use_simplify_update(bmain, sce, ptr);
1874 }
1875
1876 static void rna_Scene_use_persistent_data_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
1877 {
1878         Scene *sce = ptr->id.data;
1879
1880         if (!(sce->r.mode & R_PERSISTENT_DATA))
1881                 RE_FreePersistentData();
1882 }
1883
1884 static int rna_Scene_use_audio_get(PointerRNA *ptr)
1885 {
1886         Scene *scene = (Scene *)ptr->data;
1887         return (scene->audio.flag & AUDIO_MUTE) != 0;
1888 }
1889
1890 static void rna_Scene_use_audio_set(PointerRNA *ptr, int value)
1891 {
1892         Scene *scene = (Scene *)ptr->data;
1893
1894         if (value)
1895                 scene->audio.flag |= AUDIO_MUTE;
1896         else
1897                 scene->audio.flag &= ~AUDIO_MUTE;
1898
1899         BKE_sound_mute_scene(scene, value);
1900 }
1901
1902 static int rna_Scene_sync_mode_get(PointerRNA *ptr)
1903 {
1904         Scene *scene = (Scene *)ptr->data;
1905         if (scene->audio.flag & AUDIO_SYNC)
1906                 return AUDIO_SYNC;
1907         return scene->flag & SCE_FRAME_DROP;
1908 }
1909
1910 static void rna_Scene_sync_mode_set(PointerRNA *ptr, int value)
1911 {
1912         Scene *scene = (Scene *)ptr->data;
1913
1914         if (value == AUDIO_SYNC) {
1915                 scene->audio.flag |= AUDIO_SYNC;
1916         }
1917         else if (value == SCE_FRAME_DROP) {
1918                 scene->audio.flag &= ~AUDIO_SYNC;
1919                 scene->flag |= SCE_FRAME_DROP;
1920         }
1921         else {
1922                 scene->audio.flag &= ~AUDIO_SYNC;
1923                 scene->flag &= ~SCE_FRAME_DROP;
1924         }
1925 }
1926
1927 static int rna_GameSettings_auto_start_get(PointerRNA *UNUSED(ptr))
1928 {
1929         return (G.fileflags & G_FILE_AUTOPLAY) != 0;
1930 }
1931
1932 static void rna_GameSettings_auto_start_set(PointerRNA *UNUSED(ptr), int value)
1933 {
1934         if (value)
1935                 G.fileflags |= G_FILE_AUTOPLAY;
1936         else
1937                 G.fileflags &= ~G_FILE_AUTOPLAY;
1938 }
1939
1940 static void rna_GameSettings_exit_key_set(PointerRNA *ptr, int value)
1941 {
1942         GameData *gm = (GameData *)ptr->data;
1943
1944         if (ISKEYBOARD(value))
1945                 gm->exitkey = value;
1946 }
1947
1948 static StructRNA *rna_SceneLayerSettings_refine(PointerRNA *ptr)
1949 {
1950         IDProperty *props = (IDProperty *)ptr->data;
1951         BLI_assert(props && props->type == IDP_GROUP);
1952
1953         switch (props->subtype) {
1954                 case IDP_GROUP_SUB_ENGINE_RENDER:
1955 #ifdef WITH_CLAY_ENGINE
1956                         if (STREQ(props->name, RE_engine_id_BLENDER_CLAY)) {
1957                                 return &RNA_SceneLayerEngineSettingsClay;
1958                         }
1959 #endif
1960                         if (STREQ(props->name, RE_engine_id_BLENDER_EEVEE)) {
1961                                 return &RNA_SceneLayerEngineSettingsEevee;
1962                         }
1963                         break;
1964                 case IDP_GROUP_SUB_MODE_OBJECT:
1965                 case IDP_GROUP_SUB_MODE_EDIT:
1966                 case IDP_GROUP_SUB_MODE_PAINT_WEIGHT:
1967                 case IDP_GROUP_SUB_MODE_PAINT_VERTEX:
1968                 default:
1969                         BLI_assert(!"Mode not fully implemented");
1970                         break;
1971         }
1972
1973         return &RNA_SceneLayerSettings;
1974 }
1975
1976 static StructRNA *rna_LayerCollectionSettings_refine(PointerRNA *ptr)
1977 {
1978         IDProperty *props = (IDProperty *)ptr->data;
1979         BLI_assert(props && props->type == IDP_GROUP);
1980
1981         switch (props->subtype) {
1982                 case IDP_GROUP_SUB_ENGINE_RENDER:
1983 #ifdef WITH_CLAY_ENGINE
1984                         if (STREQ(props->name, RE_engine_id_BLENDER_CLAY)) {
1985                                 return &RNA_LayerCollectionEngineSettingsClay;
1986                         }
1987 #endif
1988                         if (STREQ(props->name, RE_engine_id_BLENDER_EEVEE)) {
1989                                 /* printf("Mode not fully implemented\n"); */
1990                                 return &RNA_LayerCollectionSettings;
1991                         }
1992                         break;
1993                 case IDP_GROUP_SUB_MODE_OBJECT:
1994                         return &RNA_LayerCollectionModeSettingsObject;
1995                         break;
1996                 case IDP_GROUP_SUB_MODE_EDIT:
1997                         return &RNA_LayerCollectionModeSettingsEdit;
1998                         break;
1999                 case IDP_GROUP_SUB_MODE_PAINT_WEIGHT:
2000                         return &RNA_LayerCollectionModeSettingsPaintWeight;
2001                         break;
2002                 case IDP_GROUP_SUB_MODE_PAINT_VERTEX:
2003                         return &RNA_LayerCollectionModeSettingsPaintVertex;
2004                         break;
2005                 default:
2006                         BLI_assert(!"Mode not fully implemented");
2007                         break;
2008         }
2009
2010         return &RNA_LayerCollectionSettings;
2011 }
2012
2013 static TimeMarker *rna_TimeLine_add(Scene *scene, const char name[], int frame)
2014 {
2015         TimeMarker *marker = MEM_callocN(sizeof(TimeMarker), "TimeMarker");
2016         marker->flag = SELECT;
2017         marker->frame = frame;
2018         BLI_strncpy_utf8(marker->name, name, sizeof(marker->name));
2019         BLI_addtail(&scene->markers, marker);
2020
2021         WM_main_add_notifier(NC_SCENE | ND_MARKERS, NULL);
2022         WM_main_add_notifier(NC_ANIMATION | ND_MARKERS, NULL);
2023
2024         return marker;
2025 }
2026
2027 static void rna_TimeLine_remove(Scene *scene, ReportList *reports, PointerRNA *marker_ptr)
2028 {
2029         TimeMarker *marker = marker_ptr->data;
2030         if (BLI_remlink_safe(&scene->markers, marker) == false) {
2031                 BKE_reportf(reports, RPT_ERROR, "Timeline marker '%s' not found in scene '%s'",
2032                             marker->name, scene->id.name + 2);
2033                 return;
2034         }
2035
2036         MEM_freeN(marker);
2037         RNA_POINTER_INVALIDATE(marker_ptr);
2038
2039         WM_main_add_notifier(NC_SCENE | ND_MARKERS, NULL);
2040         WM_main_add_notifier(NC_ANIMATION | ND_MARKERS, NULL);
2041 }
2042
2043 static void rna_TimeLine_clear(Scene *scene)
2044 {
2045         BLI_freelistN(&scene->markers);
2046
2047         WM_main_add_notifier(NC_SCENE | ND_MARKERS, NULL);
2048         WM_main_add_notifier(NC_ANIMATION | ND_MARKERS, NULL);
2049 }
2050
2051 static KeyingSet *rna_Scene_keying_set_new(Scene *sce, ReportList *reports, const char idname[], const char name[])
2052 {
2053         KeyingSet *ks = NULL;
2054
2055         /* call the API func, and set the active keyingset index */
2056         ks = BKE_keyingset_add(&sce->keyingsets, idname, name, KEYINGSET_ABSOLUTE, 0);
2057         
2058         if (ks) {
2059                 sce->active_keyingset = BLI_listbase_count(&sce->keyingsets);
2060                 return ks;
2061         }
2062         else {
2063                 BKE_report(reports, RPT_ERROR, "Keying set could not be added");
2064                 return NULL;
2065         }
2066 }
2067
2068 static void rna_UnifiedPaintSettings_update(bContext *C, PointerRNA *UNUSED(ptr))
2069 {
2070         Scene *scene = CTX_data_scene(C);
2071         SceneLayer *sl = CTX_data_scene_layer(C);
2072         Brush *br = BKE_paint_brush(BKE_paint_get_active(scene, sl));
2073         WM_main_add_notifier(NC_BRUSH | NA_EDITED, br);
2074 }
2075
2076 static void rna_UnifiedPaintSettings_size_set(PointerRNA *ptr, int value)
2077 {
2078         UnifiedPaintSettings *ups = ptr->data;
2079
2080         /* scale unprojected radius so it stays consistent with brush size */
2081         BKE_brush_scale_unprojected_radius(&ups->unprojected_radius,
2082                                            value, ups->size);
2083         ups->size = value;
2084 }
2085
2086 static void rna_UnifiedPaintSettings_unprojected_radius_set(PointerRNA *ptr, float value)
2087 {
2088         UnifiedPaintSettings *ups = ptr->data;
2089
2090         /* scale brush size so it stays consistent with unprojected_radius */
2091         BKE_brush_scale_size(&ups->size, value, ups->unprojected_radius);
2092         ups->unprojected_radius = value;
2093 }
2094
2095 static void rna_UnifiedPaintSettings_radius_update(bContext *C, PointerRNA *ptr)
2096 {
2097         /* changing the unified size should invalidate the overlay but also update the brush */
2098         BKE_paint_invalidate_overlay_all();
2099         rna_UnifiedPaintSettings_update(C, ptr);
2100 }
2101
2102 static char *rna_UnifiedPaintSettings_path(PointerRNA *UNUSED(ptr))
2103 {
2104         return BLI_strdup("tool_settings.unified_paint_settings");
2105 }
2106
2107 static char *rna_CurvePaintSettings_path(PointerRNA *UNUSED(ptr))
2108 {
2109         return BLI_strdup("tool_settings.curve_paint_settings");
2110 }
2111
2112 /* generic function to recalc geometry */
2113 static void rna_EditMesh_update(Main *UNUSED(bmain), bContext *C, Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
2114 {
2115         SceneLayer *sl = CTX_data_scene_layer(C);
2116         Mesh *me = NULL;
2117
2118         if (sl->basact) {
2119                 me = BKE_mesh_from_object(sl->basact->object);
2120                 if (me && me->edit_btmesh == NULL)
2121                         me = NULL;
2122         }
2123
2124         if (me) {
2125                 DEG_id_tag_update(&me->id, OB_RECALC_DATA);
2126                 WM_main_add_notifier(NC_GEOM | ND_DATA, me);
2127         }
2128 }
2129
2130 static char *rna_MeshStatVis_path(PointerRNA *UNUSED(ptr))
2131 {
2132         return BLI_strdup("tool_settings.statvis");
2133 }
2134
2135 /* note: without this, when Multi-Paint is activated/deactivated, the colors
2136  * will not change right away when multiple bones are selected, this function
2137  * is not for general use and only for the few cases where changing scene
2138  * settings and NOT for general purpose updates, possibly this should be
2139  * given its own notifier. */
2140 static void rna_Scene_update_active_object_data(bContext *C, PointerRNA *UNUSED(ptr))
2141 {
2142         SceneLayer *sl = CTX_data_scene_layer(C);
2143         Object *ob = OBACT_NEW;
2144
2145         if (ob) {
2146                 DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
2147                 WM_main_add_notifier(NC_OBJECT | ND_DRAW, &ob->id);
2148         }
2149 }
2150
2151 static void rna_SceneCamera_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
2152 {
2153         Scene *scene = (Scene *)ptr->id.data;
2154         Object *camera = scene->camera;
2155
2156         if (camera)
2157                 DEG_id_tag_update(&camera->id, 0);
2158 }
2159
2160 static void rna_SceneSequencer_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
2161 {
2162         BKE_sequencer_cache_cleanup();
2163         BKE_sequencer_preprocessed_cache_cleanup();
2164 }
2165
2166 static char *rna_ToolSettings_path(PointerRNA *UNUSED(ptr))
2167 {
2168         return BLI_strdup("tool_settings");
2169 }
2170
2171 static PointerRNA rna_FreestyleLineSet_linestyle_get(PointerRNA *ptr)
2172 {
2173         FreestyleLineSet *lineset = (FreestyleLineSet *)ptr->data;
2174
2175         return rna_pointer_inherit_refine(ptr, &RNA_FreestyleLineStyle, lineset->linestyle);
2176 }
2177
2178 static void rna_FreestyleLineSet_linestyle_set(PointerRNA *ptr, PointerRNA value)
2179 {
2180         FreestyleLineSet *lineset = (FreestyleLineSet *)ptr->data;
2181
2182         if (lineset->linestyle)
2183                 id_us_min(&lineset->linestyle->id);
2184         lineset->linestyle = (FreestyleLineStyle *)value.data;
2185         id_us_plus(&lineset->linestyle->id);
2186 }
2187
2188 static FreestyleLineSet *rna_FreestyleSettings_lineset_add(
2189         ID *id, FreestyleSettings *config, Main *bmain, const char *name)
2190 {
2191         Scene *scene = (Scene *)id;
2192         FreestyleLineSet *lineset = BKE_freestyle_lineset_add(bmain, (FreestyleConfig *)config, name);
2193
2194         DEG_id_tag_update(&scene->id, 0);
2195         WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
2196
2197         return lineset;
2198 }
2199
2200 static void rna_FreestyleSettings_lineset_remove(
2201         ID *id, FreestyleSettings *config, ReportList *reports, PointerRNA *lineset_ptr)
2202 {
2203         FreestyleLineSet *lineset = lineset_ptr->data;
2204         Scene *scene = (Scene *)id;
2205
2206         if (!BKE_freestyle_lineset_delete((FreestyleConfig *)config, lineset)) {
2207                 BKE_reportf(reports, RPT_ERROR, "Line set '%s' could not be removed", lineset->name);
2208                 return;
2209         }
2210
2211         RNA_POINTER_INVALIDATE(lineset_ptr);
2212
2213         DEG_id_tag_update(&scene->id, 0);
2214         WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
2215 }
2216
2217 static PointerRNA rna_FreestyleSettings_active_lineset_get(PointerRNA *ptr)
2218 {
2219         FreestyleConfig *config = (FreestyleConfig *)ptr->data;
2220         FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
2221         return rna_pointer_inherit_refine(ptr, &RNA_FreestyleLineSet, lineset);
2222 }
2223
2224 static void rna_FreestyleSettings_active_lineset_index_range(
2225         PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
2226 {
2227         FreestyleConfig *config = (FreestyleConfig *)ptr->data;
2228
2229         *min = 0;
2230         *max = max_ii(0, BLI_listbase_count(&config->linesets) - 1);
2231 }
2232
2233 static int rna_FreestyleSettings_active_lineset_index_get(PointerRNA *ptr)
2234 {
2235         FreestyleConfig *config = (FreestyleConfig *)ptr->data;
2236         return BKE_freestyle_lineset_get_active_index(config);
2237 }
2238
2239 static void rna_FreestyleSettings_active_lineset_index_set(PointerRNA *ptr, int value)
2240 {
2241         FreestyleConfig *config = (FreestyleConfig *)ptr->data;
2242         BKE_freestyle_lineset_set_active_index(config, value);
2243 }
2244
2245 static FreestyleModuleConfig *rna_FreestyleSettings_module_add(ID *id, FreestyleSettings *config)
2246 {
2247         Scene *scene = (Scene *)id;
2248         FreestyleModuleConfig *module = BKE_freestyle_module_add((FreestyleConfig *)config);
2249
2250         DEG_id_tag_update(&scene->id, 0);
2251         WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
2252
2253         return module;
2254 }
2255
2256 static void rna_FreestyleSettings_module_remove(
2257         ID *id, FreestyleSettings *config, ReportList *reports, PointerRNA *module_ptr)
2258 {
2259         Scene *scene = (Scene *)id;
2260         FreestyleModuleConfig *module = module_ptr->data;
2261
2262         if (!BKE_freestyle_module_delete((FreestyleConfig *)config, module)) {
2263                 if (module->script)
2264                         BKE_reportf(reports, RPT_ERROR, "Style module '%s' could not be removed", module->script->id.name + 2);
2265                 else
2266                         BKE_report(reports, RPT_ERROR, "Style module could not be removed");
2267                 return;
2268         }
2269
2270         RNA_POINTER_INVALIDATE(module_ptr);
2271
2272         DEG_id_tag_update(&scene->id, 0);
2273         WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
2274 }
2275
2276 char *rna_GPUDOF_path(PointerRNA *ptr)
2277 {
2278         /* if there is ID-data, resolve the path using the index instead of by name,
2279          * since the name used is the name of the texture assigned, but the texture
2280          * may be used multiple times in the same stack
2281          */
2282         if (ptr->id.data) {
2283                 if (GS(((ID *)ptr->id.data)->name) == ID_CA) {
2284                         return BLI_strdup("gpu_dof");
2285                 }
2286         }
2287
2288         return BLI_strdup("");
2289 }
2290
2291 static void rna_GPUFXSettings_fx_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
2292 {
2293         GPUFXSettings *fx_settings = ptr->data;
2294
2295         BKE_screen_gpu_fx_validate(fx_settings);
2296 }
2297
2298 static void rna_GPUDOFSettings_blades_set(PointerRNA *ptr, const int value)
2299 {
2300         GPUDOFSettings *dofsettings = (GPUDOFSettings *)ptr->data;
2301
2302         if (value < 3 && dofsettings->num_blades > 2)
2303                 dofsettings->num_blades = 0;
2304         else if (value > 0 && dofsettings->num_blades == 0)
2305                 dofsettings->num_blades = 3;
2306         else
2307                 dofsettings->num_blades = value;
2308 }
2309
2310 static void rna_Stereo3dFormat_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
2311 {
2312         ID *id = ptr->id.data;
2313
2314         if (id && GS(id->name) == ID_IM) {
2315                 Image *ima = (Image *)id;
2316                 ImBuf *ibuf;
2317                 void *lock;
2318
2319                 if (!BKE_image_is_stereo(ima))
2320                         return;
2321
2322                 ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
2323
2324                 if (ibuf) {
2325                         BKE_image_signal(ima, NULL, IMA_SIGNAL_FREE);
2326                 }
2327                 BKE_image_release_ibuf(ima, ibuf, lock);
2328         }
2329 }
2330
2331 static int rna_gpu_is_hq_supported_get(PointerRNA *UNUSED(ptr))
2332 {
2333         return true;
2334 }
2335
2336 static void rna_SceneCollection_name_set(PointerRNA *ptr, const char *value)
2337 {
2338         Scene *scene = (Scene *)ptr->id.data;
2339         SceneCollection *sc = (SceneCollection *)ptr->data;
2340         BKE_collection_rename(scene, sc, value);
2341 }
2342
2343 static void rna_SceneCollection_filter_set(PointerRNA *ptr, const char *value)
2344 {
2345         Scene *scene = (Scene *)ptr->id.data;
2346         SceneCollection *sc = (SceneCollection *)ptr->data;
2347         BLI_strncpy_utf8(sc->filter, value, sizeof(sc->filter));
2348
2349         TODO_LAYER_SYNC_FILTER;
2350         (void)scene;
2351 }
2352
2353 static PointerRNA rna_SceneCollection_objects_get(CollectionPropertyIterator *iter)
2354 {
2355         ListBaseIterator *internal = &iter->internal.listbase;
2356
2357         /* we are actually iterating a LinkData list, so override get */
2358         return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((LinkData *)internal->link)->data);
2359 }
2360
2361 static int rna_SceneCollection_move_above(ID *id, SceneCollection *sc_src, Main *bmain, SceneCollection *sc_dst)
2362 {
2363         Scene *scene = (Scene *)id;
2364
2365         if (!BKE_collection_move_above(scene, sc_dst, sc_src)) {
2366                 return 0;
2367         }
2368
2369         DEG_relations_tag_update(bmain);
2370         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
2371
2372         return 1;
2373 }
2374
2375 static int rna_SceneCollection_move_below(ID *id, SceneCollection *sc_src, Main *bmain, SceneCollection *sc_dst)
2376 {
2377         Scene *scene = (Scene *)id;
2378
2379         if (!BKE_collection_move_below(scene, sc_dst, sc_src)) {
2380                 return 0;
2381         }
2382
2383         DEG_relations_tag_update(bmain);
2384         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
2385
2386         return 1;
2387 }
2388
2389 static int rna_SceneCollection_move_into(ID *id, SceneCollection *sc_src, Main *bmain, SceneCollection *sc_dst)
2390 {
2391         Scene *scene = (Scene *)id;
2392
2393         if (!BKE_collection_move_into(scene, sc_dst, sc_src)) {
2394                 return 0;
2395         }
2396
2397         DEG_relations_tag_update(bmain);
2398         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
2399
2400         return 1;
2401 }
2402
2403 static SceneCollection *rna_SceneCollection_new(
2404         ID *id, SceneCollection *sc_parent, Main *bmain, const char *name)
2405 {
2406         Scene *scene = (Scene *)id;
2407         SceneCollection *sc = BKE_collection_add(scene, sc_parent, name);
2408
2409         DEG_relations_tag_update(bmain);
2410         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
2411
2412         return sc;
2413 }
2414
2415 static void rna_SceneCollection_remove(
2416         ID *id, SceneCollection *sc_parent, Main *bmain, ReportList *reports, PointerRNA *sc_ptr)
2417 {
2418         Scene *scene = (Scene *)id;
2419         SceneCollection *sc = sc_ptr->data;
2420
2421         const int index = BLI_findindex(&sc_parent->scene_collections, sc);
2422         if (index == -1) {
2423                 BKE_reportf(reports, RPT_ERROR, "Collection '%s' is not a sub-collection of '%s'",
2424                             sc->name, sc_parent->name);
2425                 return;
2426         }
2427
2428         if (!BKE_collection_remove(scene, sc)) {
2429                 BKE_reportf(reports, RPT_ERROR, "Collection '%s' could not be removed from collection '%s'",
2430                             sc->name, sc_parent->name);
2431                 return;
2432         }
2433
2434         RNA_POINTER_INVALIDATE(sc_ptr);
2435
2436         DEG_relations_tag_update(bmain);
2437         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
2438 }
2439
2440 static int rna_SceneCollection_objects_active_index_get(PointerRNA *ptr)
2441 {
2442         SceneCollection *sc = (SceneCollection *)ptr->data;
2443         return sc->active_object_index;
2444 }
2445
2446 static void rna_SceneCollection_objects_active_index_set(PointerRNA *ptr, int value)
2447 {
2448         SceneCollection *sc = (SceneCollection *)ptr->data;
2449         sc->active_object_index = value;
2450 }
2451
2452 static void rna_SceneCollection_objects_active_index_range(
2453         PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
2454 {
2455         SceneCollection *sc = (SceneCollection *)ptr->data;
2456         *min = 0;
2457         *max = max_ii(0, BLI_listbase_count(&sc->objects) - 1);
2458 }
2459
2460 void rna_SceneCollection_object_link(
2461         ID *id, SceneCollection *sc, Main *bmain, ReportList *reports, Object *ob)
2462 {
2463         Scene *scene = (Scene *)id;
2464
2465         if (BLI_findptr(&sc->objects, ob, offsetof(LinkData, data))) {
2466                 BKE_reportf(reports, RPT_ERROR, "Object '%s' is already in collection '%s'", ob->id.name + 2, sc->name);
2467                 return;
2468         }
2469
2470         BKE_collection_object_add(scene, sc, ob);
2471
2472         /* TODO(sergey): Only update relations for the current scene. */
2473         DEG_relations_tag_update(bmain);
2474
2475         /* TODO(sergey): Use proper flag for tagging here. */
2476         DEG_id_tag_update(&scene->id, 0);
2477
2478         DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
2479
2480         WM_main_add_notifier(NC_SCENE | ND_LAYER | ND_OB_ACTIVE, scene);
2481 }
2482
2483 static void rna_SceneCollection_object_unlink(
2484         ID *id, SceneCollection *sc, Main *bmain, ReportList *reports, Object *ob)
2485 {
2486         Scene *scene = (Scene *)id;
2487
2488         if (!BLI_findptr(&sc->objects, ob, offsetof(LinkData, data))) {
2489                 BKE_reportf(reports, RPT_ERROR, "Object '%s' is not in collection '%s'", ob->id.name + 2, sc->name);
2490                 return;
2491         }
2492
2493         BKE_collection_object_remove(bmain, scene, sc, ob, false);
2494
2495         /* needed otherwise the depgraph will contain freed objects which can crash, see [#20958] */
2496         DEG_relations_tag_update(bmain);
2497
2498         WM_main_add_notifier(NC_SCENE | ND_LAYER | ND_OB_ACTIVE, scene);
2499 }
2500
2501 /****** layer collection engine settings *******/
2502
2503 #define RNA_LAYER_ENGINE_GET_SET(_TYPE_, _ENGINE_, _MODE_, _NAME_)                 \
2504 static _TYPE_ rna_LayerEngineSettings_##_ENGINE_##_##_NAME_##_get(PointerRNA *ptr) \
2505 {                                                                                  \
2506         IDProperty *props = (IDProperty *)ptr->data;                                   \
2507         return BKE_collection_engine_property_value_get_##_TYPE_(props, #_NAME_);      \
2508 }                                                                                  \
2509                                                                                        \
2510 static void rna_LayerEngineSettings_##_ENGINE_##_##_NAME_##_set(PointerRNA *ptr, _TYPE_ value)  \
2511 {                                                                                  \
2512         IDProperty *props = (IDProperty *)ptr->data;                                   \
2513         BKE_collection_engine_property_value_set_##_TYPE_(props, #_NAME_, value);      \
2514 }
2515
2516 #define RNA_LAYER_ENGINE_GET_SET_ARRAY(_TYPE_, _ENGINE_, _MODE_, _NAME_, _LEN_)    \
2517 static void rna_LayerEngineSettings_##_ENGINE_##_##_NAME_##_get(PointerRNA *ptr, _TYPE_ *values) \
2518 {                                                                                  \
2519         IDProperty *props = (IDProperty *)ptr->data;                                   \
2520         IDProperty *idprop = IDP_GetPropertyFromGroup(props, #_NAME_);                 \
2521         if (idprop != NULL) {                                                          \
2522                 memcpy(values, IDP_Array(idprop), sizeof(_TYPE_) * idprop->len);           \
2523         }                                                                              \
2524 }                                                                                  \
2525                                                                                        \
2526 static void rna_LayerEngineSettings_##_ENGINE_##_##_NAME_##_set(PointerRNA *ptr, const _TYPE_ *values) \
2527 {                                                                                  \
2528         IDProperty *props = (IDProperty *)ptr->data;                                   \
2529         BKE_collection_engine_property_value_set_##_TYPE_##_array(props, #_NAME_, values); \
2530 }
2531
2532 #define RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(_NAME_) \
2533         RNA_LAYER_ENGINE_GET_SET(float, Clay, COLLECTION_MODE_NONE, _NAME_)
2534
2535 #define RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT_ARRAY(_NAME_, _LEN_) \
2536         RNA_LAYER_ENGINE_GET_SET_ARRAY(float, Clay, COLLECTION_MODE_NONE, _NAME_, _LEN_)
2537
2538 #define RNA_LAYER_ENGINE_CLAY_GET_SET_INT(_NAME_) \
2539         RNA_LAYER_ENGINE_GET_SET(int, Clay, COLLECTION_MODE_NONE, _NAME_)
2540
2541 #define RNA_LAYER_ENGINE_CLAY_GET_SET_BOOL(_NAME_) \
2542         RNA_LAYER_ENGINE_GET_SET(bool, Clay, COLLECTION_MODE_NONE, _NAME_)
2543
2544 #define RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(_NAME_) \
2545         RNA_LAYER_ENGINE_GET_SET(float, Eevee, COLLECTION_MODE_NONE, _NAME_)
2546
2547 #define RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(_NAME_) \
2548         RNA_LAYER_ENGINE_GET_SET(int, Eevee, COLLECTION_MODE_NONE, _NAME_)
2549
2550 #define RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(_NAME_) \
2551         RNA_LAYER_ENGINE_GET_SET(bool, Eevee, COLLECTION_MODE_NONE, _NAME_)
2552
2553 /* mode engines */
2554
2555 #define RNA_LAYER_MODE_OBJECT_GET_SET_FLOAT(_NAME_) \
2556         RNA_LAYER_ENGINE_GET_SET(float, ObjectMode, COLLECTION_MODE_OBJECT, _NAME_)
2557
2558 #define RNA_LAYER_MODE_OBJECT_GET_SET_INT(_NAME_) \
2559         RNA_LAYER_ENGINE_GET_SET(int, ObjectMode, COLLECTION_MODE_OBJECT, _NAME_)
2560
2561 #define RNA_LAYER_MODE_OBJECT_GET_SET_BOOL(_NAME_) \
2562         RNA_LAYER_ENGINE_GET_SET(bool, ObjectMode, COLLECTION_MODE_OBJECT, _NAME_)
2563
2564 #define RNA_LAYER_MODE_EDIT_GET_SET_FLOAT(_NAME_) \
2565         RNA_LAYER_ENGINE_GET_SET(float, EditMode, COLLECTION_MODE_EDIT, _NAME_)
2566
2567 #define RNA_LAYER_MODE_EDIT_GET_SET_INT(_NAME_) \
2568         RNA_LAYER_ENGINE_GET_SET(int, EditMode, COLLECTION_MODE_EDIT, _NAME_)
2569
2570 #define RNA_LAYER_MODE_EDIT_GET_SET_BOOL(_NAME_) \
2571         RNA_LAYER_ENGINE_GET_SET(bool, EditMode, COLLECTION_MODE_EDIT, _NAME_)
2572
2573 #define RNA_LAYER_MODE_PAINT_WEIGHT_GET_SET_BOOL(_NAME_) \
2574         RNA_LAYER_ENGINE_GET_SET(bool, PaintWeightMode, COLLECTION_MODE_PAINT_WEIGHT, _NAME_)
2575
2576 #define RNA_LAYER_MODE_PAINT_VERTEX_GET_SET_BOOL(_NAME_) \
2577         RNA_LAYER_ENGINE_GET_SET(bool, PaintVertexMode, COLLECTION_MODE_PAINT_VERTEX, _NAME_)
2578
2579 /* clay engine */
2580 #ifdef WITH_CLAY_ENGINE
2581 /* SceneLayer settings. */
2582 RNA_LAYER_ENGINE_CLAY_GET_SET_INT(ssao_samples)
2583
2584 /* LayerCollection settings. */
2585 RNA_LAYER_ENGINE_CLAY_GET_SET_INT(matcap_icon)
2586 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(matcap_rotation)
2587 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(matcap_hue)
2588 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(matcap_saturation)
2589 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(matcap_value)
2590 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(ssao_factor_cavity)
2591 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(ssao_factor_edge)
2592 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(ssao_distance)
2593 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(ssao_attenuation)
2594 RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(hair_brightness_randomness)
2595 #endif /* WITH_CLAY_ENGINE */
2596
2597 /* eevee engine */
2598 /* SceneLayer settings. */
2599 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(gtao_enable)
2600 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(gtao_use_bent_normals)
2601 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(gtao_factor)
2602 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(gtao_distance)
2603 RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(gtao_samples)
2604 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(dof_enable)
2605 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bokeh_max_size)
2606 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bokeh_threshold)
2607 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(bloom_enable)
2608 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bloom_threshold)
2609 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bloom_knee)
2610 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bloom_radius)
2611 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bloom_intensity)
2612 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(motion_blur_enable)
2613 RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(motion_blur_samples)
2614 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(motion_blur_shutter)
2615 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(volumetric_enable)
2616 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(volumetric_start)
2617 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(volumetric_end)
2618 RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(volumetric_samples)
2619 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(volumetric_sample_distribution)
2620 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(volumetric_lights)
2621 RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(volumetric_light_clamp)
2622 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(volumetric_shadows)
2623 RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(volumetric_shadow_samples)
2624 RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(volumetric_colored_transmittance)
2625
2626 /* object engine */
2627 RNA_LAYER_MODE_OBJECT_GET_SET_BOOL(show_wire)
2628 RNA_LAYER_MODE_OBJECT_GET_SET_BOOL(show_backface_culling)
2629
2630 /* mesh engine */
2631 RNA_LAYER_MODE_EDIT_GET_SET_BOOL(show_occlude_wire)
2632 RNA_LAYER_MODE_EDIT_GET_SET_BOOL(show_weight)
2633 RNA_LAYER_MODE_EDIT_GET_SET_BOOL(face_normals_show)
2634 RNA_LAYER_MODE_EDIT_GET_SET_BOOL(vert_normals_show)
2635 RNA_LAYER_MODE_EDIT_GET_SET_BOOL(loop_normals_show)
2636 RNA_LAYER_MODE_EDIT_GET_SET_FLOAT(normals_length)
2637 RNA_LAYER_MODE_EDIT_GET_SET_FLOAT(backwire_opacity)
2638
2639 /* weight paint engine */
2640 RNA_LAYER_MODE_PAINT_WEIGHT_GET_SET_BOOL(use_shading)
2641 RNA_LAYER_MODE_PAINT_WEIGHT_GET_SET_BOOL(use_wire)
2642
2643 /* vertex paint engine */
2644 RNA_LAYER_MODE_PAINT_VERTEX_GET_SET_BOOL(use_shading)
2645 RNA_LAYER_MODE_PAINT_VERTEX_GET_SET_BOOL(use_wire)
2646
2647 #undef RNA_LAYER_ENGINE_GET_SET
2648
2649 static void rna_SceneLayerEngineSettings_update(bContext *C, PointerRNA *UNUSED(ptr))
2650 {
2651         Scene *scene = CTX_data_scene(C);
2652         /* TODO(sergey): Use proper flag for tagging here. */
2653         DEG_id_tag_update(&scene->id, 0);
2654 }
2655
2656 static void rna_LayerCollectionEngineSettings_update(bContext *C, PointerRNA *UNUSED(ptr))
2657 {
2658         Scene *scene = CTX_data_scene(C);
2659         /* TODO(sergey): Use proper flag for tagging here. */
2660         DEG_id_tag_update(&scene->id, 0);
2661 }
2662
2663 static void rna_LayerCollectionEngineSettings_wire_update(bContext *C, PointerRNA *UNUSED(ptr))
2664 {
2665         Scene *scene = CTX_data_scene(C);
2666         SceneLayer *sl = CTX_data_scene_layer(C);
2667         Object *ob = OBACT_NEW;
2668
2669         if (ob != NULL && ob->type == OB_MESH) {
2670                 BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_NOCHECK);
2671         }
2672
2673         /* TODO(sergey): Use proper flag for tagging here. */
2674         DEG_id_tag_update(&scene->id, 0);
2675 }
2676
2677 /***********************************/
2678
2679 static void engine_settings_use(IDProperty *root, IDProperty *props, PointerRNA *props_ptr, const char *identifier)
2680 {
2681         PropertyRNA *prop = RNA_struct_find_property(props_ptr, identifier);
2682
2683         switch (RNA_property_type(prop)) {
2684                 case PROP_FLOAT:
2685                 {
2686                         float value = BKE_collection_engine_property_value_get_float(props, identifier);
2687                         BKE_collection_engine_property_add_float(root, identifier, value);
2688                         break;
2689                 }
2690                 case PROP_ENUM:
2691                 {
2692                         int value = BKE_collection_engine_property_value_get_int(props, identifier);
2693                         BKE_collection_engine_property_add_int(root, identifier, value);
2694                         break;
2695                 }
2696                 case PROP_INT:
2697                 {
2698                         int value = BKE_collection_engine_property_value_get_int(props, identifier);
2699                         BKE_collection_engine_property_add_int(root, identifier, value);
2700                         break;
2701                 }
2702                 case PROP_BOOLEAN:
2703                 {
2704                         int value = BKE_collection_engine_property_value_get_int(props, identifier);
2705                         BKE_collection_engine_property_add_bool(root, identifier, value);
2706                         break;
2707                 }
2708                 case PROP_STRING:
2709                 case PROP_POINTER:
2710                 case PROP_COLLECTION:
2711                 default:
2712                         break;
2713         }
2714 }
2715
2716 static void rna_SceneLayerSettings_name_get(PointerRNA *ptr, char *value)
2717 {
2718         IDProperty *props = (IDProperty *)ptr->data;
2719         strcpy(value, props->name);
2720 }
2721
2722 static int rna_SceneLayerSettings_name_length(PointerRNA *ptr)
2723 {
2724         IDProperty *props = (IDProperty *)ptr->data;
2725         return strnlen(props->name, sizeof(props->name));
2726 }
2727
2728 static void rna_SceneLayerSettings_use(ID *id, IDProperty *props, const char *identifier)
2729 {
2730         Scene *scene = (Scene *)id;
2731         PointerRNA scene_props_ptr;
2732         IDProperty *scene_props;
2733
2734         scene_props = BKE_scene_layer_engine_scene_get(scene, COLLECTION_MODE_NONE, props->name);
2735         RNA_pointer_create(id, &RNA_SceneLayerSettings, scene_props, &scene_props_ptr);
2736
2737         engine_settings_use(props, scene_props, &scene_props_ptr, identifier);
2738
2739         /* TODO(sergey): Use proper flag for tagging here. */
2740         DEG_id_tag_update(id, 0);
2741 }
2742
2743 static void rna_SceneLayerSettings_unuse(ID *id, IDProperty *props, const char *identifier)
2744 {
2745         IDProperty *prop_to_remove = IDP_GetPropertyFromGroup(props, identifier);
2746         IDP_FreeFromGroup(props, prop_to_remove);
2747
2748         /* TODO(sergey): Use proper flag for tagging here. */
2749         DEG_id_tag_update(id, 0);
2750 }
2751
2752 static void rna_LayerCollectionSettings_name_get(PointerRNA *ptr, char *value)
2753 {
2754         IDProperty *props = (IDProperty *)ptr->data;
2755         strcpy(value, props->name);
2756 }
2757
2758 static int rna_LayerCollectionSettings_name_length(PointerRNA *ptr)
2759 {
2760         IDProperty *props = (IDProperty *)ptr->data;
2761         return strnlen(props->name, sizeof(props->name));
2762 }
2763
2764 static void rna_LayerCollectionSettings_use(ID *id, IDProperty *props, const char *identifier)
2765 {
2766         Scene *scene = (Scene *)id;
2767         PointerRNA scene_props_ptr;
2768         IDProperty *scene_props;
2769
2770         scene_props = BKE_layer_collection_engine_scene_get(scene, COLLECTION_MODE_NONE, props->name);
2771         RNA_pointer_create(id, &RNA_LayerCollectionSettings, scene_props, &scene_props_ptr);
2772         engine_settings_use(props, scene_props, &scene_props_ptr, identifier);
2773
2774         /* TODO(sergey): Use proper flag for tagging here. */
2775         DEG_id_tag_update(id, 0);
2776 }
2777
2778 static void rna_LayerCollectionSettings_unuse(ID *id, IDProperty *props, const char *identifier)
2779 {
2780         IDProperty *prop_to_remove = IDP_GetPropertyFromGroup(props, identifier);
2781         IDP_FreeFromGroup(props, prop_to_remove);
2782
2783         /* TODO(sergey): Use proper flag for tagging here. */
2784         DEG_id_tag_update(id, 0);
2785 }
2786
2787 static void rna_LayerCollection_name_get(PointerRNA *ptr, char *value)
2788 {
2789         SceneCollection *sc = ((LayerCollection *)ptr->data)->scene_collection;
2790         strcpy(value, sc->name);
2791 }
2792
2793 static int rna_LayerCollection_name_length(PointerRNA *ptr)
2794 {
2795         SceneCollection *sc = ((LayerCollection *)ptr->data)->scene_collection;
2796         return strnlen(sc->name, sizeof(sc->name));
2797 }
2798
2799 static void rna_LayerCollection_name_set(PointerRNA *ptr, const char *value)
2800 {
2801         Scene *scene = (Scene *)ptr->id.data;
2802         SceneCollection *sc = ((LayerCollection *)ptr->data)->scene_collection;
2803         BKE_collection_rename(scene, sc, value);
2804 }
2805
2806 static PointerRNA rna_LayerCollection_objects_get(CollectionPropertyIterator *iter)
2807 {
2808         ListBaseIterator *internal = &iter->internal.listbase;
2809         Base *base = ((LinkData *)internal->link)->data;
2810         return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, base->object);
2811 }
2812
2813 static int rna_LayerCollection_move_above(ID *id, LayerCollection *lc_src, Main *bmain, LayerCollection *lc_dst)
2814 {
2815         Scene *scene = (Scene *)id;
2816
2817         if (!BKE_layer_collection_move_above(scene, lc_dst, lc_src)) {
2818                 return 0;
2819         }
2820
2821         DEG_relations_tag_update(bmain);
2822         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
2823
2824         return 1;
2825 }
2826
2827 static int rna_LayerCollection_move_below(ID *id, LayerCollection *lc_src, Main *bmain, LayerCollection *lc_dst)
2828 {
2829         Scene *scene = (Scene *)id;
2830
2831         if (!BKE_layer_collection_move_below(scene, lc_dst, lc_src)) {
2832                 return 0;
2833         }
2834
2835         DEG_relations_tag_update(bmain);
2836         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
2837
2838         return 1;
2839 }
2840
2841 static int rna_LayerCollection_move_into(ID *id, LayerCollection *lc_src, Main *bmain, LayerCollection *lc_dst)
2842 {
2843         Scene *scene = (Scene *)id;
2844
2845         if (!BKE_layer_collection_move_into(scene, lc_dst, lc_src)) {
2846                 return 0;
2847         }
2848
2849         DEG_relations_tag_update(bmain);
2850         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
2851
2852         return 1;
2853 }
2854
2855 static void rna_LayerCollection_flag_update(bContext *C, PointerRNA *UNUSED(ptr))
2856 {
2857         Scene *scene = CTX_data_scene(C);
2858         /* TODO(sergey): Use proper flag for tagging here. */
2859         DEG_id_tag_update(&scene->id, 0);
2860         WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
2861 }
2862
2863 static int rna_LayerCollections_active_collection_index_get(PointerRNA *ptr)
2864 {
2865         SceneLayer *sl = (SceneLayer *)ptr->data;
2866         return sl->active_collection;
2867 }
2868
2869 static void rna_LayerCollections_active_collection_index_set(PointerRNA *ptr, int value)
2870 {
2871         SceneLayer *sl = (SceneLayer *)ptr->data;
2872         int num_collections = BKE_layer_collection_count(sl);
2873         sl->active_collection = min_ff(value, num_collections - 1);
2874 }
2875
2876 static void rna_LayerCollections_active_collection_index_range(
2877         PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
2878 {
2879         SceneLayer *sl = (SceneLayer *)ptr->data;
2880         *min = 0;
2881         *max = max_ii(0, BKE_layer_collection_count(sl) - 1);
2882 }
2883
2884 static PointerRNA rna_LayerCollections_active_collection_get(PointerRNA *ptr)
2885 {
2886         SceneLayer *sl = (SceneLayer *)ptr->data;
2887         LayerCollection *lc = BKE_layer_collection_get_active(sl);
2888         return rna_pointer_inherit_refine(ptr, &RNA_LayerCollection, lc);
2889 }
2890
2891 static void rna_LayerCollections_active_collection_set(PointerRNA *ptr, PointerRNA value)
2892 {
2893         SceneLayer *sl = (SceneLayer *)ptr->data;
2894         LayerCollection *lc = (LayerCollection *)value.data;
2895         const int index = BKE_layer_collection_findindex(sl, lc);
2896         if (index != -1) sl->active_collection = index;
2897 }
2898
2899 LayerCollection * rna_SceneLayer_collection_link(
2900         ID *id, SceneLayer *sl, Main *bmain, SceneCollection *sc)
2901 {
2902         Scene *scene = (Scene *)id;
2903         LayerCollection *lc = BKE_collection_link(sl, sc);
2904
2905         DEG_relations_tag_update(bmain);
2906         /* TODO(sergey): Use proper flag for tagging here. */
2907         DEG_id_tag_update(id, 0);
2908         WM_main_add_notifier(NC_SCENE | ND_LAYER, scene);
2909
2910         return lc;
2911 }
2912
2913 static void rna_SceneLayer_collection_unlink(
2914         ID *id, SceneLayer *sl, Main *bmain, ReportList *reports, LayerCollection *lc)
2915 {
2916         Scene *scene = (Scene *)id;
2917
2918         if (BLI_findindex(&sl->layer_collections, lc) == -1) {
2919                 BKE_reportf(reports, RPT_ERROR, "Layer collection '%s' is not in '%s'", lc->scene_collection->name, sl->name);
2920                 return;
2921         }
2922
2923         BKE_collection_unlink(sl, lc);
2924
2925         DEG_relations_tag_update(bmain);
2926         /* TODO(sergey): Use proper flag for tagging here. */
2927         DEG_id_tag_update(id, 0);
2928         WM_main_add_notifier(NC_SCENE | ND_LAYER | ND_OB_ACTIVE, scene);
2929 }
2930
2931 static PointerRNA rna_LayerObjects_active_object_get(PointerRNA *ptr)
2932 {
2933         SceneLayer *sl = (SceneLayer *)ptr->data;
2934         return rna_pointer_inherit_refine(ptr, &RNA_Object, sl->basact ? sl->basact->object : NULL);
2935 }
2936
2937 static void rna_LayerObjects_active_object_set(PointerRNA *ptr, PointerRNA value)
2938 {
2939         SceneLayer *sl = (SceneLayer *)ptr->data;
2940         if (value.data)
2941                 sl->basact = BKE_scene_layer_base_find(sl, (Object *)value.data);
2942         else
2943                 sl->basact = NULL;
2944 }
2945
2946 static void rna_SceneLayer_name_set(PointerRNA *ptr, const char *value)
2947 {
2948         Scene *scene = (Scene *)ptr->id.data;
2949         SceneLayer *sl = (SceneLayer *)ptr->data;
2950         char oldname[sizeof(sl->name)];
2951
2952         BLI_strncpy(oldname, sl->name, sizeof(sl->name));
2953
2954         BLI_strncpy_utf8(sl->name, value, sizeof(sl->name));
2955         BLI_uniquename(&scene->render_layers, sl, DATA_("SceneLayer"), '.', offsetof(SceneLayer, name), sizeof(sl->name));
2956
2957         if (scene->nodetree) {
2958                 bNode *node;
2959                 int index = BLI_findindex(&scene->render_layers, sl);
2960
2961                 for (node = scene->nodetree->nodes.first; node; node = node->next) {
2962                         if (node->type == CMP_NODE_R_LAYERS && node->id == NULL) {
2963                                 if (node->custom1 == index)
2964                                         BLI_strncpy(node->name, sl->name, NODE_MAXSTR);
2965                         }
2966                 }
2967         }
2968 }
2969
2970 static PointerRNA rna_SceneLayer_objects_get(CollectionPropertyIterator *iter)
2971 {
2972         ListBaseIterator *internal = &iter->internal.listbase;
2973
2974         /* we are actually iterating a ObjectBase list, so override get */
2975         Base *base = (Base *)internal->link;
2976         return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, base->object);
2977 }
2978
2979 static int rna_SceneLayer_objects_selected_skip(CollectionPropertyIterator *iter, void *UNUSED(data))
2980 {
2981         ListBaseIterator *internal = &iter->internal.listbase;
2982         Base *base = (Base *)internal->link;
2983
2984         if ((base->flag & BASE_SELECTED) != 0) {
2985                         return 0;
2986         }
2987
2988         return 1;
2989 };
2990
2991 static void rna_LayerObjects_selected_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
2992 {
2993         SceneLayer *sl = (SceneLayer *)ptr->data;
2994         rna_iterator_listbase_begin(iter, &sl->object_bases, rna_SceneLayer_objects_selected_skip);
2995 }
2996
2997 static void rna_SceneLayer_engine_set(PointerRNA *ptr, int value)
2998 {
2999         SceneLayer *sl = (SceneLayer *)ptr->data;
3000         RenderEngineType *type = BLI_findlink(&R_engines, value);
3001
3002         if (type)
3003                 BKE_scene_layer_engine_set(sl, type->idname);
3004 }
3005
3006 static EnumPropertyItem *rna_SceneLayer_engine_itemf(
3007         bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
3008 {
3009         RenderEngineType *type;
3010         EnumPropertyItem *item = NULL;
3011         EnumPropertyItem tmp = {0, "", 0, "", ""};
3012         int a = 0, totitem = 0;
3013
3014         for (type = R_engines.first; type; type = type->next, a++) {
3015                 tmp.value = a;
3016                 tmp.identifier = type->idname;
3017                 tmp.name = type->name;
3018                 RNA_enum_item_add(&item, &totitem, &tmp);
3019         }
3020
3021         RNA_enum_item_end(&item, &totitem);
3022         *r_free = true;
3023
3024         return item;
3025 }
3026
3027 static int rna_SceneLayer_engine_get(PointerRNA *ptr)
3028 {
3029         SceneLayer *sl = (SceneLayer *)ptr->data;
3030         RenderEngineType *type;
3031         int a = 0;
3032
3033         for (type = R_engines.first; type; type = type->next, a++)
3034                 if (STREQ(type->idname, sl->engine))
3035                         return a;
3036
3037         return 0;
3038 }
3039
3040 static void rna_SceneLayer_engine_update(Main *bmain, Scene *UNUSED(unused), PointerRNA *UNUSED(ptr))
3041 {
3042         ED_render_engine_changed(bmain);
3043 }
3044
3045 static int rna_SceneLayer_multiple_engines_get(PointerRNA *UNUSED(ptr))
3046 {
3047         return (BLI_listbase_count(&R_engines) > 1);
3048 }
3049
3050 static void rna_SceneLayer_update_tagged(SceneLayer *UNUSED(sl), bContext *C)
3051 {
3052         Depsgraph *graph = CTX_data_depsgraph(C);
3053         DEG_OBJECT_ITER(graph, ob, DEG_OBJECT_ITER_FLAG_ALL)
3054         {
3055                 /* Don't do anything, we just need to run the iterator to flush
3056                  * the base info to the objects. */
3057                 UNUSED_VARS(ob);
3058         }
3059         DEG_OBJECT_ITER_END
3060 }
3061
3062 static int rna_SceneLayer_active_layer_index_get(PointerRNA *ptr)
3063 {
3064         Scene *scene = (Scene *)ptr->data;
3065         return scene->active_layer;
3066 }
3067
3068 static void rna_SceneLayer_active_layer_index_set(PointerRNA *ptr, int value)
3069 {
3070         Scene *scene = (Scene *)ptr->data;
3071         int num_layers = BLI_listbase_count(&scene->render_layers);
3072         scene->active_layer = min_ff(value, num_layers - 1);
3073 }
3074
3075 static void rna_SceneLayer_active_layer_index_range(
3076         PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
3077 {
3078         Scene *scene = (Scene *)ptr->data;
3079
3080         *min = 0;
3081         *max = max_ii(0, BLI_listbase_count(&scene->render_layers) - 1);
3082 }
3083
3084 static PointerRNA rna_SceneLayer_active_layer_get(PointerRNA *ptr)
3085 {
3086         Scene *scene = (Scene *)ptr->data;
3087         SceneLayer *sl = BLI_findlink(&scene->render_layers, scene->active_layer);
3088
3089         return rna_pointer_inherit_refine(ptr, &RNA_SceneLayer, sl);
3090 }
3091
3092 static void rna_SceneLayer_active_layer_set(PointerRNA *ptr, PointerRNA value)
3093 {
3094         Scene *scene = (Scene *)ptr->data;
3095         SceneLayer *sl = (SceneLayer *)value.data;
3096         const int index = BLI_findindex(&scene->render_layers, sl);
3097         if (index != -1) scene->active_layer = index;
3098 }
3099
3100 static SceneLayer *rna_SceneLayer_new(
3101         ID *id, Scene *UNUSED(sce), Main *bmain, const char *name)
3102 {
3103         Scene *scene = (Scene *)id;
3104         SceneLayer *sl = BKE_scene_layer_add(scene, name);
3105
3106         DEG_id_tag_update(&scene->id, 0);
3107         DEG_relations_tag_update(bmain);
3108         WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
3109
3110         return sl;
3111 }
3112
3113 static void rna_SceneLayer_remove(
3114         ID *id, Scene *UNUSED(sce), Main *bmain, ReportList *reports, PointerRNA *sl_ptr)
3115 {
3116         Scene *scene = (Scene *)id;
3117         SceneLayer *sl = sl_ptr->data;
3118
3119         if (ED_scene_render_layer_delete(bmain, scene, sl, reports)) {
3120                 RNA_POINTER_INVALIDATE(sl_ptr);
3121         }
3122 }
3123
3124 static void rna_ObjectBase_select_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
3125 {
3126         Base *base = (Base *)ptr->data;
3127         short mode = (base->flag & BASE_SELECTED) ? BA_SELECT : BA_DESELECT;
3128         ED_object_base_select(base, mode);
3129 }
3130 #else
3131
3132 /* Grease Pencil Interpolation tool settings */
3133 static void rna_def_gpencil_interpolate(BlenderRNA *brna)
3134 {
3135         StructRNA *srna;
3136         PropertyRNA *prop;
3137         
3138         srna = RNA_def_struct(brna, "GPencilInterpolateSettings", NULL);
3139         RNA_def_struct_sdna(srna, "GP_Interpolate_Settings");
3140         RNA_def_struct_path_func(srna, "rna_GPencilInterpolateSettings_path");
3141         RNA_def_struct_ui_text(srna, "Grease Pencil Interpolate Settings",
3142                                "Settings for Grease Pencil interpolation tools");
3143         
3144         /* flags */
3145         prop = RNA_def_property(srna, "interpolate_all_layers", PROP_BOOLEAN, PROP_NONE);
3146         RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_TOOLFLAG_INTERPOLATE_ALL_LAYERS);
3147         RNA_def_property_ui_text(prop, "Interpolate All Layers", "Interpolate all layers, not only active");
3148         RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
3149
3150         prop = RNA_def_property(srna, "interpolate_selected_only", PROP_BOOLEAN, PROP_NONE);
3151         RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_TOOLFLAG_INTERPOLATE_ONLY_SELECTED);
3152         RNA_def_property_ui_text(prop, "Interpolate Selected Strokes", "Interpolate only selected strokes in the original frame");
3153         RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
3154         
3155         /* interpolation type */
3156         prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
3157         RNA_def_property_enum_sdna(prop, NULL, "type");
3158         RNA_def_property_enum_items(prop, rna_enum_gpencil_interpolation_mode_items);
3159         RNA_def_property_enum_funcs(prop, NULL, "rna_GPencilInterpolateSettings_type_set", NULL);
3160         RNA_def_property_ui_text(prop, "Type",
3161                                  "Interpolation method to use the next time 'Interpolate Sequence' is run");
3162         RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
3163         
3164         /* easing */
3165         prop = RNA_def_property(srna, "easing", PROP_ENUM, PROP_NONE);
3166         RNA_def_property_enum_sdna(prop, NULL, "easing");
3167         RNA_def_property_enum_items(prop, rna_enum_beztriple_interpolation_easing_items);
3168         RNA_def_property_ui_text(prop, "Easing", 
3169                                  "Which ends of the segment between the preceding and following grease pencil frames "
3170                                  "easing interpolation is applied to");
3171         RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
3172         
3173         /* easing options */
3174         prop = RNA_def_property(srna, "back", PROP_FLOAT, PROP_NONE);
3175         RNA_def_property_float_sdna(prop, NULL, "back");
3176         RNA_def_property_ui_text(prop, "Back", "Amount of overshoot for 'back' easing");
3177         RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
3178         
3179         prop = RNA_def_property(srna, "amplitude", PROP_FLOAT, PROP_NONE);
3180         RNA_def_property_float_sdna(prop, NULL, "amplitude");
3181         RNA_def_property_range(prop, 0.0f, FLT_MAX); /* only positive values... */
3182         RNA_def_property_ui_text(prop, "Amplitude", "Amount to boost elastic bounces for 'elastic' easing");
3183         RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
3184         
3185         prop = RNA_def_property(srna, "period", PROP_FLOAT, PROP_NONE);
3186         RNA_def_property_float_sdna(prop, NULL, "period");
3187         RNA_def_property_ui_text(prop, "Period", "Time between bounces for elastic easing");
3188         RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
3189         
3190         /* custom curvemap */
3191         prop = RNA_def_property(srna, "interpolation_curve", PROP_POINTER, PROP_NONE);
3192         RNA_def_property_pointer_sdna(prop, NULL, "custom_ipo");
3193         RNA_def_property_struct_type(prop, "CurveMapping");
3194         RNA_def_property_ui_text(prop, "Interpolation Curve", 
3195                                  "Custom curve to control 'sequence' interpolation between Grease Pencil frames");
3196         RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
3197 }
3198
3199 /* Grease Pencil Drawing Brushes */
3200 static void rna_def_gpencil_brush(BlenderRNA *brna)
3201 {
3202         StructRNA *srna;
3203         PropertyRNA *prop;
3204
3205         srna = RNA_def_struct(brna, "GPencilBrush", NULL);
3206         RNA_def_struct_sdna(srna, "bGPDbrush");
3207         RNA_def_struct_ui_text(srna, "Grease Pencil Brush",
3208                                "Collection of brushes being used to control the line style of new strokes");
3209         RNA_def_struct_ui_icon(srna, ICON_BRUSH_DATA);
3210
3211         /* Name */
3212         prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
3213         RNA_def_property_string_sdna(prop, NULL, "info");
3214         RNA_def_property_ui_text(prop, "Name", "Brush name");
3215         RNA_def_property_string_funcs(prop, NULL, NULL, "rna_GPencilBrush_name_set");
3216         RNA_def_struct_name_property(srna, prop);
3217         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3218
3219         /* Line Thickness */
3220         prop = RNA_def_property(srna, "line_width", PROP_INT, PROP_PIXEL);
3221         RNA_def_property_int_sdna(prop, NULL, "thickness");
3222         RNA_def_property_range(prop, 1, 300);
3223         RNA_def_property_ui_range(prop, 1, 10, 1, 0);
3224         RNA_def_property_ui_text(prop, "Thickness", "Thickness of strokes (in pixels)");
3225         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3226
3227         /* Sensitivity factor for new strokes */
3228         prop = RNA_def_property(srna, "pen_sensitivity_factor", PROP_FLOAT, PROP_NONE);
3229         RNA_def_property_float_sdna(prop, NULL, "draw_sensitivity");
3230         RNA_def_property_range(prop, 0.1f, 3.0f);
3231         RNA_def_property_ui_text(prop, "Sensitivity", "Pressure sensitivity factor for new strokes");
3232         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3233
3234         /* Strength factor for new strokes */
3235         prop = RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
3236         RNA_def_property_float_sdna(prop, NULL, "draw_strength");
3237         RNA_def_property_range(prop, 0.0f, 1.0f);
3238         RNA_def_property_ui_text(prop, "Strength", "Color strength for new strokes (affect alpha factor of color)");
3239         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3240
3241         /* Jitter factor for new strokes */
3242         prop = RNA_def_property(srna, "jitter", PROP_FLOAT, PROP_NONE);
3243         RNA_def_property_float_sdna(prop, NULL, "draw_jitter");
3244         RNA_def_property_range(prop, 0.0f, 1.0f);
3245         RNA_def_property_ui_text(prop, "Jitter", "Jitter factor for new strokes");
3246         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3247
3248         /* Randomnes factor for sensitivity and strength */
3249         prop = RNA_def_property(srna, "random_press", PROP_FLOAT, PROP_NONE);
3250         RNA_def_property_float_sdna(prop, NULL, "draw_random_press");
3251         RNA_def_property_range(prop, 0.0f, 1.0f);
3252         RNA_def_property_ui_text(prop, "Randomness", "Randomness factor for pressure and strength in new strokes");
3253         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3254
3255         /* Randomnes factor for subdivision */
3256         prop = RNA_def_property(srna, "random_subdiv", PROP_FLOAT, PROP_NONE);
3257         RNA_def_property_float_sdna(prop, NULL, "draw_random_sub");
3258         RNA_def_property_range(prop, 0.0f, 1.0f);
3259         RNA_def_property_ui_text(prop, "Random Subdivision", "Randomness factor for new strokes after subdivision");
3260         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3261
3262         /* Angle when brush is full size */
3263         prop = RNA_def_property(srna, "angle", PROP_FLOAT, PROP_ANGLE);
3264         RNA_def_property_float_sdna(prop, NULL, "draw_angle");
3265         RNA_def_property_range(prop, -M_PI_2, M_PI_2);
3266         RNA_def_property_ui_text(prop, "Angle",
3267                                  "Direction of the stroke at which brush gives maximal thickness "
3268                                  "(0° for horizontal)");
3269         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3270
3271         /* Factor to change brush size depending of angle */
3272         prop = RNA_def_property(srna, "angle_factor", PROP_FLOAT, PROP_NONE);
3273         RNA_def_property_float_sdna(prop, NULL, "draw_angle_factor");
3274         RNA_def_property_range(prop, 0.0f, 1.0f);
3275         RNA_def_property_ui_text(prop, "Angle Factor",
3276                                  "Reduce brush thickness by this factor when stroke is perpendicular to 'Angle' direction");
3277         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3278
3279         /* Smoothing factor for new strokes */
3280         prop = RNA_def_property(srna, "pen_smooth_factor", PROP_FLOAT, PROP_NONE);
3281         RNA_def_property_float_sdna(prop, NULL, "draw_smoothfac");
3282         RNA_def_property_range(prop, 0.0, 2.0f);
3283         RNA_def_property_ui_text(prop, "Smooth",
3284                                  "Amount of smoothing to apply to newly created strokes, to reduce jitter/noise");
3285         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3286
3287         /* Iterations of the Smoothing factor */
3288         prop = RNA_def_property(srna, "pen_smooth_steps", PROP_INT, PROP_NONE);
3289         RNA_def_property_int_sdna(prop, NULL, "draw_smoothlvl");
3290         RNA_def_property_range(prop, 1, 3);
3291         RNA_def_property_ui_text(prop, "Iterations",
3292                                  "Number of times to smooth newly created strokes");
3293         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3294
3295         /* Subdivision level for new strokes */
3296         prop = RNA_def_property(srna, "pen_subdivision_steps", PROP_INT, PROP_NONE);
3297         RNA_def_property_int_sdna(prop, NULL, "sublevel");
3298         RNA_def_property_range(prop, 0, 3);
3299         RNA_def_property_ui_text(prop, "Subdivision Steps",
3300                                  "Number of times to subdivide newly created strokes, for less jagged strokes");
3301         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3302
3303         /* Curves for pressure */
3304         prop = RNA_def_property(srna, "curve_sensitivity", PROP_POINTER, PROP_NONE);
3305         RNA_def_property_pointer_sdna(prop, NULL, "cur_sensitivity");
3306         RNA_def_property_struct_type(prop, "CurveMapping");
3307         RNA_def_property_ui_text(prop, "Curve Sensitivity", "Curve used for the sensitivity");
3308         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3309
3310         prop = RNA_def_property(srna, "curve_strength", PROP_POINTER, PROP_NONE);
3311         RNA_def_property_pointer_sdna(prop, NULL, "cur_strength");
3312         RNA_def_property_struct_type(prop, "CurveMapping");
3313         RNA_def_property_ui_text(prop, "Curve Strength", "Curve used for the strength");
3314         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3315
3316         prop = RNA_def_property(srna, "curve_jitter", PROP_POINTER, PROP_NONE);
3317         RNA_def_property_pointer_sdna(prop, NULL, "cur_jitter");
3318         RNA_def_property_struct_type(prop, "CurveMapping");
3319         RNA_def_property_ui_text(prop, "Curve Jitter", "Curve used for the jitter effect");
3320         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3321
3322         /* Flags */
3323         prop = RNA_def_property(srna, "use_pressure", PROP_BOOLEAN, PROP_NONE);
3324         RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_USE_PRESSURE);
3325         RNA_def_property_ui_icon(prop, ICON_STYLUS_PRESSURE, 0);
3326         RNA_def_property_ui_text(prop, "Use Pressure", "Use tablet pressure");
3327         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3328
3329         prop = RNA_def_property(srna, "use_strength_pressure", PROP_BOOLEAN, PROP_NONE);
3330         RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_USE_STENGTH_PRESSURE);
3331         RNA_def_property_ui_icon(prop, ICON_STYLUS_PRESSURE, 0);
3332         RNA_def_property_ui_text(prop, "Use Pressure Strength", "Use tablet pressure for color strength");
3333         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3334
3335         prop = RNA_def_property(srna, "use_jitter_pressure", PROP_BOOLEAN, PROP_NONE);
3336         RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_USE_JITTER_PRESSURE);
3337         RNA_def_property_ui_icon(prop, ICON_STYLUS_PRESSURE, 0);
3338         RNA_def_property_ui_text(prop, "Use Pressure Jitter", "Use tablet pressure for jitter");
3339         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3340
3341         prop = RNA_def_property(srna, "use_random_pressure", PROP_BOOLEAN, PROP_NONE);
3342         RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_USE_RANDOM_PRESSURE);
3343         RNA_def_property_ui_icon(prop, ICON_PARTICLES, 0);
3344         RNA_def_property_ui_text(prop, "Random Pressure", "Use random value for pressure");
3345         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3346
3347         prop = RNA_def_property(srna, "use_random_strength", PROP_BOOLEAN, PROP_NONE);
3348         RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_USE_RANDOM_STRENGTH);
3349         RNA_def_property_ui_icon(prop, ICON_PARTICLES, 0);
3350         RNA_def_property_ui_text(prop, "Random Strength", "Use random value for strength");
3351         RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
3352
3353 }
3354
3355 /* Grease Pencil Drawing Brushes API */
3356 static void rna_def_gpencil_brushes(BlenderRNA *brna, PropertyRNA *cprop)
3357 {
3358         StructRNA *srna;
3359         PropertyRNA *prop;
3360
3361         FunctionRNA *func;
3362         PropertyRNA *parm;
3363
3364         RNA_def_property_srna(cprop, "GreasePencilBrushes");
3365         srna = RNA_def_struct(brna, "GreasePencilBrushes", NULL);
3366         RNA_def_struct_sdna(srna, "ToolSettings");
3367         RNA_def_struct_ui_text(srna, "Grease Pencil Brushes", "Collection of grease pencil brushes");
3368
3369         func = RNA_def_function(srna, "new", "rna_GPencil_brush_new");
3370         RNA_def_function_ui_description(func, "Add a new grease pencil brush");
3371         parm = RNA_def_string(func, "name", "GPencilBrush", MAX_NAME, "Name", "Name of the brush");
3372         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
3373         RNA_def_boolean(func, "set_active", 0, "Set Active", "Set the newly created brush to the active brush");
3374         parm = RNA_def_pointer(func, "palette", "GPencilBrush", "", "The newly created brush");
3375         RNA_def_function_return(func, parm);
3376
3377         func = RNA_def_function(srna, "remove", "rna_GPencil_brush_remove");
3378         RNA_def_function_ui_description(func, "Remove a grease pencil brush");
3379         RNA_def_function_flag(func, FUNC_USE_REPORTS);
3380         parm = RNA_def_pointer(func, "brush", "GPencilBrush", "", "The brush to remove");
3381         RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
3382         RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
3383
3384         prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
3385         RNA_def_property_struct_type(prop, "GPencilBrush");
3386         RNA_def_property_pointer_funcs(prop, "rna_GPencilBrushes_active_get", "rna_GPencilBrushes_active_set", NULL, NULL);
3387         RNA_def_property_flag(prop, PROP_EDITABLE);
3388         RNA_def_property_ui_text(prop, "Active Brush", "Current active brush");
3389
3390         prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
3391         RNA_def_property_int_funcs(prop,
3392                 "rna_GPencilBrushes_index_get",
3393                 "rna_GPencilBrushes_index_set",
3394                 "rna_GPencilBrushes_index_range");
3395         RNA_def_property_ui_text(prop, "Active Brush Index", "Index of active brush");
3396 }
3397
3398 static void rna_def_tool_settings(BlenderRNA  *brna)
3399 {
3400         StructRNA *srna;
3401         PropertyRNA *prop;
3402
3403         static EnumPropertyItem uv_select_mode_items[] = {
3404                 {UV_SELECT_VERTEX, "VERTEX", ICON_UV_VERTEXSEL, "Vertex", "Vertex selection mode"},
3405                 {UV_SELECT_EDGE, "EDGE", ICON_UV_EDGESEL, "Edge", "Edge selection mode"},
3406                 {UV_SELECT_FACE, "FACE", ICON_UV_FACESEL, "Face", "Face selection mode"},
3407                 {UV_SELECT_ISLAND, "ISLAND", ICON_UV_ISLANDSEL, "Island", "Island selection mode"},
3408                 {0, NULL, 0, NULL, NULL}
3409         };
3410         
3411         /* the construction of this enum is quite special - everything is stored as bitflags,
3412          * with 1st position only for for on/off (and exposed as boolean), while others are mutually
3413          * exclusive options but which will only have any effect when autokey is enabled
3414          */
3415         static EnumPropertyItem auto_key_items[] = {
3416                 {AUTOKEY_MODE_NORMAL & ~AUTOKEY_ON, "ADD_REPLACE_KEYS", 0, "Add & Replace", ""},
3417                 {AUTOKEY_MODE_EDITKEYS & ~AUTOKEY_ON, "REPLACE_KEYS", 0, "Replace", ""},
3418                 {0, NULL, 0, NULL, NULL}
3419         };
3420
3421         static EnumPropertyItem retarget_roll_items[] = {
3422                 {SK_RETARGET_ROLL_NONE, "NONE", 0, "None", "Don't adjust roll"},
3423                 {SK_RETARGET_ROLL_VIEW, "VIEW", 0, "View", "Roll bones to face the view"},
3424                 {SK_RETARGET_ROLL_JOINT, "JOINT", 0, "Joint", "Roll bone to original joint plane offset"},
3425                 {0, NULL, 0, NULL, NULL}
3426         };
3427         
3428         static EnumPropertyItem sketch_convert_items[] = {
3429                 {SK_CONVERT_CUT_FIXED, "FIXED", 0, "Fixed", "Subdivide stroke in fixed number of bones"},
3430                 {SK_CONVERT_CUT_LENGTH, "LENGTH", 0, "Length", "Subdivide stroke in bones of specific length"},
3431                 {SK_CONVERT_CUT_ADAPTATIVE, "ADAPTIVE", 0, "Adaptive",
3432                  "Subdivide stroke adaptively, with more subdivision in curvier parts"},
3433                 {SK_CONVERT_RETARGET, "RETARGET", 0, "Retarget", "Retarget template bone chain to stroke"},
3434                 {0, NULL, 0, NULL, NULL}
3435         };
3436
3437         static EnumPropertyItem edge_tag_items[] = {
3438                 {EDGE_MODE_SELECT, "SELECT", 0, "Select", ""},
3439