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