svn merge -r39781:39792 https://svn.blender.org/svnroot/bf-blender/trunk/blender...
[blender-staging.git] / release / scripts / startup / bl_ui / properties_scene.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import Operator, Panel
22 from rna_prop_ui import PropertyPanel
23
24
25 class SceneButtonsPanel():
26     bl_space_type = 'PROPERTIES'
27     bl_region_type = 'WINDOW'
28     bl_context = "scene"
29
30     @classmethod
31     def poll(cls, context):
32         return context.scene
33
34
35 class SCENE_PT_scene(SceneButtonsPanel, Panel):
36     bl_label = "Scene"
37     COMPAT_ENGINES = {'BLENDER_RENDER'}
38
39     def draw(self, context):
40         layout = self.layout
41         scene = context.scene
42
43         layout.prop(scene, "camera")
44         layout.prop(scene, "background_set", text="Background")
45
46
47 class SCENE_PT_audio(SceneButtonsPanel, Panel):
48     bl_label = "Audio"
49     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
50
51     def draw(self, context):
52         layout = self.layout
53         scene = context.scene
54         rd = context.scene.render
55
56         layout.prop(scene, "audio_volume")
57         layout.operator("sound.bake_animation")
58
59         split = layout.split()
60
61         col = split.column()
62
63         col.label("Listener:")
64         col.prop(scene, "audio_distance_model", text="")
65         col.prop(scene, "audio_doppler_speed", text="Speed")
66         col.prop(scene, "audio_doppler_factor", text="Doppler")
67
68         col = split.column()
69
70         col.label("Format:")
71         col.prop(rd, "ffmpeg_audio_channels", text="")
72         col.prop(rd, "ffmpeg_audio_mixrate", text="Rate")
73
74         layout.operator("sound.mixdown")
75
76
77 class SCENE_PT_unit(SceneButtonsPanel, Panel):
78     bl_label = "Units"
79     COMPAT_ENGINES = {'BLENDER_RENDER'}
80
81     def draw(self, context):
82         layout = self.layout
83         unit = context.scene.unit_settings
84
85         col = layout.column()
86         col.row().prop(unit, "system", expand=True)
87         col.row().prop(unit, "system_rotation", expand=True)
88
89         row = layout.row()
90         row.active = (unit.system != 'NONE')
91         row.prop(unit, "scale_length", text="Scale")
92         row.prop(unit, "use_separate")
93
94
95 class SCENE_PT_keying_sets(SceneButtonsPanel, Panel):
96     bl_label = "Keying Sets"
97
98     def draw(self, context):
99         layout = self.layout
100
101         scene = context.scene
102         row = layout.row()
103
104         col = row.column()
105         col.template_list(scene, "keying_sets", scene.keying_sets, "active_index", rows=2)
106
107         col = row.column(align=True)
108         col.operator("anim.keying_set_add", icon='ZOOMIN', text="")
109         col.operator("anim.keying_set_remove", icon='ZOOMOUT', text="")
110
111         ks = scene.keying_sets.active
112         if ks and ks.is_path_absolute:
113             row = layout.row()
114
115             col = row.column()
116             col.prop(ks, "name")
117
118             subcol = col.column()
119             subcol.operator_context = 'INVOKE_DEFAULT'
120             op = subcol.operator("anim.keying_set_export", text="Export to File")
121             op.filepath = "keyingset.py"
122
123             col = row.column()
124             col.label(text="Keyframing Settings:")
125             col.prop(ks, "bl_options")
126
127
128 class SCENE_PT_keying_set_paths(SceneButtonsPanel, Panel):
129     bl_label = "Active Keying Set"
130
131     @classmethod
132     def poll(cls, context):
133         ks = context.scene.keying_sets.active
134         return (ks and ks.is_path_absolute)
135
136     def draw(self, context):
137         layout = self.layout
138
139         scene = context.scene
140         ks = scene.keying_sets.active
141
142         row = layout.row()
143         row.label(text="Paths:")
144
145         row = layout.row()
146
147         col = row.column()
148         col.template_list(ks, "paths", ks.paths, "active_index", rows=2)
149
150         col = row.column(align=True)
151         col.operator("anim.keying_set_path_add", icon='ZOOMIN', text="")
152         col.operator("anim.keying_set_path_remove", icon='ZOOMOUT', text="")
153
154         ksp = ks.paths.active
155         if ksp:
156             col = layout.column()
157             col.label(text="Target:")
158             col.template_any_ID(ksp, "id", "id_type")
159             col.template_path_builder(ksp, "data_path", ksp.id)
160
161             row = layout.row()
162
163             col = row.column()
164             col.label(text="Array Target:")
165             col.prop(ksp, "use_entire_array")
166             if ksp.use_entire_array is False:
167                 col.prop(ksp, "array_index")
168
169             col = row.column()
170             col.label(text="F-Curve Grouping:")
171             col.prop(ksp, "group_method")
172             if ksp.group_method == 'NAMED':
173                 col.prop(ksp, "group")
174
175             col.prop(ksp, "bl_options")
176
177
178 class SCENE_PT_physics(SceneButtonsPanel, Panel):
179     bl_label = "Gravity"
180     COMPAT_ENGINES = {'BLENDER_RENDER'}
181
182     def draw_header(self, context):
183         self.layout.prop(context.scene, "use_gravity", text="")
184
185     def draw(self, context):
186         layout = self.layout
187
188         scene = context.scene
189
190         layout.active = scene.use_gravity
191
192         layout.prop(scene, "gravity", text="")
193
194
195 class SCENE_PT_simplify(SceneButtonsPanel, Panel):
196     bl_label = "Simplify"
197     COMPAT_ENGINES = {'BLENDER_RENDER'}
198
199     def draw_header(self, context):
200         scene = context.scene
201         rd = scene.render
202         self.layout.prop(rd, "use_simplify", text="")
203
204     def draw(self, context):
205         layout = self.layout
206         scene = context.scene
207         rd = scene.render
208
209         layout.active = rd.use_simplify
210
211         split = layout.split()
212
213         col = split.column()
214         col.prop(rd, "simplify_subdivision", text="Subdivision")
215         col.prop(rd, "simplify_child_particles", text="Child Particles")
216
217         col.prop(rd, "use_simplify_triangulate")
218
219         col = split.column()
220         col.prop(rd, "simplify_shadow_samples", text="Shadow Samples")
221         col.prop(rd, "simplify_ao_sss", text="AO and SSS")
222
223
224 class SCENE_PT_custom_props(SceneButtonsPanel, PropertyPanel, Panel):
225     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
226     _context_path = "scene"
227     _property_type = bpy.types.Scene
228
229 #  XXX, move operator to op/ dir
230
231
232 class ANIM_OT_keying_set_export(Operator):
233     "Export Keying Set to a python script."
234     bl_idname = "anim.keying_set_export"
235     bl_label = "Export Keying Set..."
236
237     filepath = bpy.props.StringProperty(name="File Path", description="Filepath to write file to.")
238     filter_folder = bpy.props.BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'})
239     filter_text = bpy.props.BoolProperty(name="Filter text", description="", default=True, options={'HIDDEN'})
240     filter_python = bpy.props.BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'})
241
242     def execute(self, context):
243         if not self.filepath:
244             raise Exception("Filepath not set.")
245
246         f = open(self.filepath, "w")
247         if not f:
248             raise Exception("Could not open file.")
249
250         scene = context.scene
251         ks = scene.keying_sets.active
252
253         f.write("# Keying Set: %s\n" % ks.name)
254
255         f.write("import bpy\n\n")
256         f.write("scene= bpy.data.scenes[0]\n\n")  # XXX, why not use the current scene?
257
258         # Add KeyingSet and set general settings
259         f.write("# Keying Set Level declarations\n")
260         f.write("ks= scene.keying_sets.new(name=\"%s\")\n" % ks.name)
261
262         if not ks.is_path_absolute:
263             f.write("ks.is_path_absolute = False\n")
264         f.write("\n")
265
266         f.write("ks.bl_options = %r\n" % ks.bl_options)
267         f.write("\n")
268
269         # generate and write set of lookups for id's used in paths
270         id_to_paths_cache = {}  # cache for syncing ID-blocks to bpy paths + shorthands
271
272         for ksp in ks.paths:
273             if ksp.id is None:
274                 continue
275             if ksp.id in id_to_paths_cache:
276                 continue
277
278             # - idtype_list is used to get the list of id-datablocks from bpy.data.*
279             #   since this info isn't available elsewhere
280             # - id.bl_rna.name gives a name suitable for UI,
281             #   with a capitalised first letter, but we need
282             #   the plural form that's all lower case
283             idtype_list = ksp.id.bl_rna.name.lower() + "s"
284             id_bpy_path = "bpy.data.%s[\"%s\"]" % (idtype_list, ksp.id.name)
285
286             # shorthand ID for the ID-block (as used in the script)
287             short_id = "id_%d" % len(id_to_paths_cache)
288
289             # store this in the cache now
290             id_to_paths_cache[ksp.id] = [short_id, id_bpy_path]
291
292         f.write("# ID's that are commonly used\n")
293         for id_pair in id_to_paths_cache.values():
294             f.write("%s = %s\n" % (id_pair[0], id_pair[1]))
295         f.write("\n")
296
297         # write paths
298         f.write("# Path Definitions\n")
299         for ksp in ks.paths:
300             f.write("ksp = ks.paths.add(")
301
302             # id-block + data_path
303             if ksp.id:
304                 # find the relevant shorthand from the cache
305                 id_bpy_path = id_to_paths_cache[ksp.id][0]
306             else:
307                 id_bpy_path = "None"  # XXX...
308             f.write("%s, '%s'" % (id_bpy_path, ksp.data_path))
309
310             # array index settings (if applicable)
311             if ksp.use_entire_array:
312                 f.write(", index=-1")
313             else:
314                 f.write(", index=%d" % ksp.array_index)
315
316             # grouping settings (if applicable)
317             # NOTE: the current default is KEYINGSET, but if this changes, change this code too
318             if ksp.group_method == 'NAMED':
319                 f.write(", group_method='%s', group_name=\"%s\"" % (ksp.group_method, ksp.group))
320             elif ksp.group_method != 'KEYINGSET':
321                 f.write(", group_method='%s'" % ksp.group_method)
322
323             # finish off
324             f.write(")\n")
325
326         f.write("\n")
327         f.close()
328
329         return {'FINISHED'}
330
331     def invoke(self, context, event):
332         wm = context.window_manager
333         wm.fileselect_add(self)
334         return {'RUNNING_MODAL'}
335
336 if __name__ == "__main__":  # only for live edit.
337     bpy.utils.register_module(__name__)