Cleanup: don't use single sets for comparisons
[blender-staging.git] / release / scripts / startup / bl_ui / properties_render_layer.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 Panel, UIList
22
23
24 class RenderLayerButtonsPanel:
25     bl_space_type = 'PROPERTIES'
26     bl_region_type = 'WINDOW'
27     bl_context = "render_layer"
28     # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
29
30     @classmethod
31     def poll(cls, context):
32         scene = context.scene
33         return scene and (scene.render.engine in cls.COMPAT_ENGINES)
34
35
36 class RENDERLAYER_UL_renderlayers(UIList):
37     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
38         # assert(isinstance(item, bpy.types.SceneRenderLayer)
39         layer = item
40         if self.layout_type in {'DEFAULT', 'COMPACT'}:
41             layout.prop(layer, "name", text="", icon_value=icon, emboss=False)
42             layout.prop(layer, "use", text="", index=index)
43         elif self.layout_type == 'GRID':
44             layout.alignment = 'CENTER'
45             layout.label("", icon_value=icon)
46
47
48 class RENDERLAYER_PT_layers(RenderLayerButtonsPanel, Panel):
49     bl_label = "Layer List"
50     bl_options = {'HIDE_HEADER'}
51     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
52
53     def draw(self, context):
54         layout = self.layout
55
56         scene = context.scene
57         rd = scene.render
58
59         if rd.engine == 'BLENDER_GAME':
60             layout.label("Not available in the Game Engine")
61             return
62
63         row = layout.row()
64         col = row.column()
65         col.template_list("RENDERLAYER_UL_renderlayers", "", rd, "layers", rd.layers, "active_index", rows=2)
66
67         col = row.column()
68         sub = col.column(align=True)
69         sub.operator("scene.render_layer_add", icon='ZOOMIN', text="")
70         sub.operator("scene.render_layer_remove", icon='ZOOMOUT', text="")
71         col.prop(rd, "use_single_layer", icon_only=True)
72
73
74 class RENDERLAYER_PT_layer_options(RenderLayerButtonsPanel, Panel):
75     bl_label = "Layer"
76     COMPAT_ENGINES = {'BLENDER_RENDER'}
77
78     def draw(self, context):
79         layout = self.layout
80
81         scene = context.scene
82         rd = scene.render
83         rl = rd.layers.active
84
85         split = layout.split()
86
87         col = split.column()
88         col.prop(scene, "layers", text="Scene")
89         col.label(text="")
90         col.prop(rl, "light_override", text="Light")
91         col.prop(rl, "material_override", text="Material")
92
93         col = split.column()
94         col.prop(rl, "layers", text="Layer")
95         col.prop(rl, "layers_zmask", text="Mask Layer")
96
97         layout.separator()
98         layout.label(text="Include:")
99
100         split = layout.split()
101
102         col = split.column()
103         col.prop(rl, "use_zmask")
104         row = col.row()
105         row.prop(rl, "invert_zmask", text="Negate")
106         row.active = rl.use_zmask
107         col.prop(rl, "use_all_z")
108
109         col = split.column()
110         col.prop(rl, "use_solid")
111         col.prop(rl, "use_halo")
112         col.prop(rl, "use_ztransp")
113
114         col = split.column()
115         col.prop(rl, "use_sky")
116         col.prop(rl, "use_edge_enhance")
117         col.prop(rl, "use_strand")
118         if bpy.app.build_options.freestyle:
119             row = col.row()
120             row.prop(rl, "use_freestyle")
121             row.active = rd.use_freestyle
122
123
124 class RENDERLAYER_PT_layer_passes(RenderLayerButtonsPanel, Panel):
125     bl_label = "Passes"
126     bl_options = {'DEFAULT_CLOSED'}
127     COMPAT_ENGINES = {'BLENDER_RENDER'}
128
129     def draw_pass_type_buttons(self, box, rl, pass_type):
130         # property names
131         use_pass_type = "use_pass_" + pass_type
132         exclude_pass_type = "exclude_" + pass_type
133         # draw pass type buttons
134         row = box.row()
135         row.prop(rl, use_pass_type)
136         row.prop(rl, exclude_pass_type, text="")
137
138     def draw(self, context):
139         layout = self.layout
140
141         scene = context.scene
142         rd = scene.render
143         rl = rd.layers.active
144
145         split = layout.split()
146
147         col = split.column()
148         col.prop(rl, "use_pass_combined")
149         col.prop(rl, "use_pass_z")
150         col.prop(rl, "use_pass_vector")
151         col.prop(rl, "use_pass_normal")
152         col.prop(rl, "use_pass_uv")
153         col.prop(rl, "use_pass_mist")
154         col.prop(rl, "use_pass_object_index")
155         col.prop(rl, "use_pass_material_index")
156         col.prop(rl, "use_pass_color")
157
158         col = split.column()
159         col.prop(rl, "use_pass_diffuse")
160         self.draw_pass_type_buttons(col, rl, "specular")
161         self.draw_pass_type_buttons(col, rl, "shadow")
162         self.draw_pass_type_buttons(col, rl, "emit")
163         self.draw_pass_type_buttons(col, rl, "ambient_occlusion")
164         self.draw_pass_type_buttons(col, rl, "environment")
165         self.draw_pass_type_buttons(col, rl, "indirect")
166         self.draw_pass_type_buttons(col, rl, "reflection")
167         self.draw_pass_type_buttons(col, rl, "refraction")
168
169
170 class RENDERLAYER_UL_renderviews(UIList):
171     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
172         # assert(isinstance(item, bpy.types.SceneRenderView)
173         view = item
174         if self.layout_type in {'DEFAULT', 'COMPACT'}:
175             if view.name in {'left', 'right'}:
176                 layout.label(view.name, icon_value=icon + (not view.use))
177             else:
178                 layout.prop(view, "name", text="", index=index, icon_value=icon, emboss=False)
179             layout.prop(view, "use", text="", index=index)
180
181         elif self.layout_type == 'GRID':
182             layout.alignment = 'CENTER'
183             layout.label("", icon_value=icon + (not view.use))
184
185
186 class RENDERLAYER_PT_views(RenderLayerButtonsPanel, Panel):
187     bl_label = "Views"
188     COMPAT_ENGINES = {'BLENDER_RENDER'}
189
190     def draw_header(self, context):
191         rd = context.scene.render
192         self.layout.prop(rd, "use_multiview", text="")
193
194     def draw(self, context):
195         layout = self.layout
196
197         scene = context.scene
198         rd = scene.render
199         rv = rd.views.active
200
201         layout.active = rd.use_multiview
202         basic_stereo = rd.views_format == 'STEREO_3D'
203
204         row = layout.row()
205         row.prop(rd, "views_format", expand=True)
206
207         if basic_stereo:
208             row = layout.row()
209             row.template_list("RENDERLAYER_UL_renderviews", "name", rd, "stereo_views", rd.views, "active_index", rows=2)
210
211             row = layout.row()
212             row.label(text="File Suffix:")
213             row.prop(rv, "file_suffix", text="")
214
215         else:
216             row = layout.row()
217             row.template_list("RENDERLAYER_UL_renderviews", "name", rd, "views", rd.views, "active_index", rows=2)
218
219             col = row.column(align=True)
220             col.operator("scene.render_view_add", icon='ZOOMIN', text="")
221             col.operator("scene.render_view_remove", icon='ZOOMOUT', text="")
222
223             row = layout.row()
224             row.label(text="Camera Suffix:")
225             row.prop(rv, "camera_suffix", text="")
226
227
228 if __name__ == "__main__":  # only for live edit.
229     bpy.utils.register_module(__name__)