Cycles / Sky Texture:
[blender-staging.git] / release / scripts / startup / bl_ui / space_node.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 Header, Menu, Panel
22
23
24 class NODE_HT_header(Header):
25     bl_space_type = 'NODE_EDITOR'
26
27     def draw(self, context):
28         layout = self.layout
29
30         scene = context.scene
31         snode = context.space_data
32         snode_id = snode.id
33         id_from = snode.id_from
34         toolsettings = context.tool_settings
35
36         row = layout.row(align=True)
37         row.template_header()
38
39         if context.area.show_menus:
40             row.menu("NODE_MT_view")
41             row.menu("NODE_MT_select")
42             row.menu("NODE_MT_add")
43             row.menu("NODE_MT_node")
44
45         layout.prop(snode, "tree_type", text="", expand=True)
46
47         if snode.tree_type == 'ShaderNodeTree':
48             if scene.render.use_shading_nodes:
49                 layout.prop(snode, "shader_type", text="", expand=True)
50
51             ob = context.object
52             if (not scene.render.use_shading_nodes or snode.shader_type == 'OBJECT') and ob:
53                 row = layout.row()
54                 # disable material slot buttons when pinned, cannot find correct slot within id_from (#36589)
55                 row.enabled = not snode.pin
56                 # Show material.new when no active ID/slot exists
57                 if not id_from and ob.type in {'MESH', 'CURVE', 'SURFACE', 'FONT', 'METABALL'}:
58                     row.template_ID(ob, "active_material", new="material.new")
59                 # Material ID, but not for Lamps
60                 if id_from and ob.type != 'LAMP':
61                     row.template_ID(id_from, "active_material", new="material.new")
62
63                 # Don't show "Use Nodes" Button when Engine is BI for Lamps
64                 if snode_id and not (scene.render.use_shading_nodes == 0 and ob.type == 'LAMP'):
65                     layout.prop(snode_id, "use_nodes")
66
67             if snode.shader_type == 'WORLD':
68                 row.template_ID(scene, "world", new="world.new")
69                 if snode_id:
70                     row.prop(snode_id, "use_nodes")
71
72         elif snode.tree_type == 'TextureNodeTree':
73             layout.prop(snode, "texture_type", text="", expand=True)
74
75             if id_from:
76                 if snode.texture_type == 'BRUSH':
77                     layout.template_ID(id_from, "texture", new="texture.new")
78                 else:
79                     layout.template_ID(id_from, "active_texture", new="texture.new")
80             if snode_id:
81                 layout.prop(snode_id, "use_nodes")
82
83         elif snode.tree_type == 'CompositorNodeTree':
84             if snode_id:
85                 layout.prop(snode_id, "use_nodes")
86                 layout.prop(snode_id.render, "use_free_unused_nodes", text="Free Unused")
87             layout.prop(snode, "show_backdrop")
88             if snode.show_backdrop:
89                 row = layout.row(align=True)
90                 row.prop(snode, "backdrop_channels", text="", expand=True)
91             layout.prop(snode, "use_auto_render")
92
93         else:
94             # Custom node tree is edited as independent ID block
95             layout.template_ID(snode, "node_tree", new="node.new_node_tree")
96
97         layout.prop(snode, "pin", text="")
98         layout.operator("node.tree_path_parent", text="", icon='FILE_PARENT')
99
100         layout.separator()
101
102         # Snap
103         row = layout.row(align=True)
104         row.prop(toolsettings, "use_snap", text="")
105         row.prop(toolsettings, "snap_node_element", text="", icon_only=True)
106         if toolsettings.snap_node_element != 'INCREMENT':
107             row.prop(toolsettings, "snap_target", text="")
108
109         row = layout.row(align=True)
110         row.operator("node.clipboard_copy", text="", icon='COPYDOWN')
111         row.operator("node.clipboard_paste", text="", icon='PASTEDOWN')
112
113         layout.template_running_jobs()
114
115
116 class NODE_MT_add(bpy.types.Menu):
117     bl_space_type = 'NODE_EDITOR'
118     bl_label = "Add"
119
120     def draw(self, context):
121         layout = self.layout
122
123         layout.operator_context = 'INVOKE_DEFAULT'
124         props = layout.operator("node.add_search", text="Search ...")
125         props.use_transform = True
126
127         # actual node submenus are added by draw functions from node categories
128
129
130 class NODE_MT_view(Menu):
131     bl_label = "View"
132
133     def draw(self, context):
134         layout = self.layout
135
136         layout.operator("node.properties", icon='MENU_PANEL')
137         layout.operator("node.toolbar", icon='MENU_PANEL')
138
139         layout.separator()
140
141         layout.operator("view2d.zoom_in")
142         layout.operator("view2d.zoom_out")
143
144         layout.separator()
145
146         layout.operator("node.view_selected")
147         layout.operator("node.view_all")
148
149         if context.space_data.show_backdrop:
150             layout.separator()
151
152             layout.operator("node.backimage_move", text="Backdrop move")
153             layout.operator("node.backimage_zoom", text="Backdrop zoom in").factor = 1.2
154             layout.operator("node.backimage_zoom", text="Backdrop zoom out").factor = 0.833
155
156         layout.separator()
157
158         layout.operator("screen.area_dupli")
159         layout.operator("screen.screen_full_area")
160
161
162 class NODE_MT_select(Menu):
163     bl_label = "Select"
164
165     def draw(self, context):
166         layout = self.layout
167
168         layout.operator("node.select_border")
169
170         layout.separator()
171         layout.operator("node.select_all").action = 'TOGGLE'
172         layout.operator("node.select_all", text="Inverse").action = 'INVERT'
173         layout.operator("node.select_linked_from")
174         layout.operator("node.select_linked_to")
175
176         layout.separator()
177
178         layout.operator("node.select_same_type")
179         layout.operator("node.select_same_type_step").prev = True
180         layout.operator("node.select_same_type_step").prev = False
181
182         layout.separator()
183
184         layout.operator("node.find_node")
185
186
187 class NODE_MT_node(Menu):
188     bl_label = "Node"
189
190     def draw(self, context):
191         layout = self.layout
192
193         layout.operator("transform.translate")
194         layout.operator("transform.rotate")
195         layout.operator("transform.resize")
196
197         layout.separator()
198
199         layout.operator("node.duplicate_move")
200         layout.operator("node.delete")
201         layout.operator("node.delete_reconnect")
202
203         layout.separator()
204
205         layout.operator("node.join", text="Join in new Frame")
206         layout.operator("node.detach", text="Remove from Frame")
207
208         layout.separator()
209
210         layout.operator("node.link_make")
211         layout.operator("node.link_make", text="Make and Replace Links").replace = True
212         layout.operator("node.links_cut")
213         layout.operator("node.links_detach")
214
215         layout.separator()
216
217         layout.operator("node.group_edit")
218         layout.operator("node.group_ungroup")
219         layout.operator("node.group_make")
220         layout.operator("node.group_insert")
221
222         layout.separator()
223
224         layout.operator("node.hide_toggle")
225         layout.operator("node.mute_toggle")
226         layout.operator("node.preview_toggle")
227         layout.operator("node.hide_socket_toggle")
228         layout.operator("node.options_toggle")
229         layout.operator("node.collapse_hide_unused_toggle")
230
231         layout.separator()
232
233         layout.operator("node.show_cyclic_dependencies")
234         layout.operator("node.read_renderlayers")
235         layout.operator("node.read_fullsamplelayers")
236
237
238 class NODE_MT_node_color_presets(Menu):
239     """Predefined node color"""
240     bl_label = "Color Presets"
241     preset_subdir = "node_color"
242     preset_operator = "script.execute_preset"
243     draw = Menu.draw_preset
244
245
246 class NODE_MT_node_color_specials(Menu):
247     bl_label = "Node Color Specials"
248
249     def draw(self, context):
250         layout = self.layout
251
252         layout.operator("node.node_copy_color", icon='COPY_ID')
253
254
255 class NODE_PT_active_node_generic(Panel):
256     bl_space_type = 'NODE_EDITOR'
257     bl_region_type = 'UI'
258     bl_label = "Node"
259 #    bl_options = {'HIDE_HEADER'}
260
261     @classmethod
262     def poll(cls, context):
263         space = context.space_data
264         return context.active_node is not None
265
266     def draw(self, context):
267         layout = self.layout
268         node = context.active_node
269
270         layout.prop(node, "name", icon='NODE')
271         layout.prop(node, "label", icon='NODE')
272
273
274 class NODE_PT_active_node_color(Panel):
275     bl_space_type = 'NODE_EDITOR'
276     bl_region_type = 'UI'
277     bl_label = "Color"
278     bl_options = {'DEFAULT_CLOSED'}
279
280     @classmethod
281     def poll(cls, context):
282         space = context.space_data
283         return context.active_node is not None
284
285     def draw_header(self, context):
286         node = context.active_node
287         self.layout.prop(node, "use_custom_color", text="")
288
289     def draw(self, context):
290         layout = self.layout
291         node = context.active_node
292
293         layout.enabled = node.use_custom_color
294
295         row = layout.row()
296         col = row.column()
297         col.menu("NODE_MT_node_color_presets")
298         col.prop(node, "color", text="")
299         col = row.column(align=True)
300         col.operator("node.node_color_preset_add", text="", icon='ZOOMIN').remove_active = False
301         col.operator("node.node_color_preset_add", text="", icon='ZOOMOUT').remove_active = True
302         col.menu("NODE_MT_node_color_specials", text="", icon='DOWNARROW_HLT')
303
304
305 class NODE_PT_active_node_properties(Panel):
306     bl_space_type = 'NODE_EDITOR'
307     bl_region_type = 'UI'
308     bl_label = "Properties"
309
310     @classmethod
311     def poll(cls, context):
312         space = context.space_data
313         return context.active_node is not None
314
315     def draw(self, context):
316         layout = self.layout
317         node = context.active_node
318         # set "node" context pointer for the panel layout
319         layout.context_pointer_set("node", node)
320
321         if hasattr(node, "draw_buttons_ext"):
322             node.draw_buttons_ext(context, layout)
323         elif hasattr(node, "draw_buttons"):
324             node.draw_buttons(context, layout)
325
326         # XXX this could be filtered further to exclude socket types which don't have meaningful input values (e.g. cycles shader)
327         value_inputs = [socket for socket in node.inputs if socket.enabled and not socket.is_linked]
328         if value_inputs:
329             layout.separator()
330             layout.label("Inputs:")
331             for socket in value_inputs:
332                 row = layout.row()
333                 socket.draw(context, row, node, socket.name)
334
335
336 # Node Backdrop options
337 class NODE_PT_backdrop(Panel):
338     bl_space_type = 'NODE_EDITOR'
339     bl_region_type = 'UI'
340     bl_label = "Backdrop"
341
342     @classmethod
343     def poll(cls, context):
344         snode = context.space_data
345         return snode.tree_type == 'CompositorNodeTree'
346
347     def draw_header(self, context):
348         snode = context.space_data
349         self.layout.prop(snode, "show_backdrop", text="")
350
351     def draw(self, context):
352         layout = self.layout
353
354         snode = context.space_data
355         layout.active = snode.show_backdrop
356         layout.prop(snode, "backdrop_channels", text="")
357         layout.prop(snode, "backdrop_zoom", text="Zoom")
358
359         col = layout.column(align=True)
360         col.label(text="Offset:")
361         col.prop(snode, "backdrop_x", text="X")
362         col.prop(snode, "backdrop_y", text="Y")
363         col.operator("node.backimage_move", text="Move")
364
365
366 class NODE_PT_quality(bpy.types.Panel):
367     bl_space_type = 'NODE_EDITOR'
368     bl_region_type = 'UI'
369     bl_label = "Performance"
370
371     @classmethod
372     def poll(cls, context):
373         snode = context.space_data
374         return snode.tree_type == 'CompositorNodeTree' and snode.node_tree is not None
375
376     def draw(self, context):
377         layout = self.layout
378
379         snode = context.space_data
380         tree = snode.node_tree
381
382         col = layout.column()
383         col.prop(tree, "render_quality", text="Render")
384         col.prop(tree, "edit_quality", text="Edit")
385         col.prop(tree, "chunk_size")
386
387         col = layout.column()
388         col.prop(tree, "use_opencl")
389         col.prop(tree, "use_groupnode_buffer")
390         col.prop(tree, "use_two_pass")
391         col.prop(tree, "use_viewer_border")
392         col.prop(snode, "show_highlight")
393         col.prop(snode, "use_hidden_preview")
394
395
396 class NODE_UL_interface_sockets(bpy.types.UIList):
397     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
398         socket = item
399         color = socket.draw_color(context)
400
401         if self.layout_type in {'DEFAULT', 'COMPACT'}:
402             row = layout.row(align=True)
403
404             # inputs get icon on the left
405             if socket.in_out == 'IN':
406                 row.template_node_socket(color)
407
408             row.label(text=socket.name, icon_value=icon)
409
410             # outputs get icon on the right
411             if socket.in_out == 'OUT':
412                 row.template_node_socket(color)
413
414         elif self.layout_type in {'GRID'}:
415             layout.alignment = 'CENTER'
416             layout.template_node_socket(color)
417
418
419 def node_draw_tree_view(layout, context):
420     pass
421
422
423 if __name__ == "__main__":  # only for live edit.
424     bpy.utils.register_module(__name__)