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