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