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