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