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