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