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