Node UI:
[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         ob = context.object
32         snode = context.space_data
33         snode_id = snode.id
34         id_from = snode.id_from
35         toolsettings = context.tool_settings
36
37         row = layout.row(align=True)
38         row.template_header()
39
40         if context.area.show_menus:
41             row.menu("NODE_MT_view")
42             row.menu("NODE_MT_select")
43             row.menu("NODE_MT_add")
44             row.menu("NODE_MT_node")
45
46         layout.prop(snode, "tree_type", text="", expand=True)
47
48         if snode.tree_type == 'ShaderNodeTree':
49             if scene.render.use_shading_nodes:
50                 layout.prop(snode, "shader_type", text="", expand=True)
51
52             if (not scene.render.use_shading_nodes or snode.shader_type == 'OBJECT') and ob:
53                 # Show material.new when no active ID/slot exists
54                 if not id_from and ob.type in {'MESH', 'CURVE', 'SURFACE', 'FONT', 'METABALL'}:
55                     layout.template_ID(ob, "active_material", new="material.new")
56                 # Material ID, but not for Lamps
57                 if id_from and ob.type != 'LAMP':
58                     layout.template_ID(id_from, "active_material", new="material.new")
59                 # Don't show "Use Nodes" Button when Engine is BI for Lamps
60                 if snode_id and not (scene.render.use_shading_nodes == 0 and ob.type == 'LAMP'):
61                     layout.prop(snode_id, "use_nodes")
62
63             if snode.shader_type == 'WORLD':
64                 layout.template_ID(scene, "world", new="world.new")
65                 if snode_id:
66                     layout.prop(snode_id, "use_nodes")
67
68         elif snode.tree_type == 'TextureNodeTree':
69             layout.prop(snode, "texture_type", text="", expand=True)
70
71             if id_from:
72                 if snode.texture_type == 'BRUSH':
73                     layout.template_ID(id_from, "texture", new="texture.new")
74                 else:
75                     layout.template_ID(id_from, "active_texture", new="texture.new")
76             if snode_id:
77                 layout.prop(snode_id, "use_nodes")
78
79         elif snode.tree_type == 'CompositorNodeTree':
80             layout.prop(snode_id, "use_nodes")
81             layout.prop(snode_id.render, "use_free_unused_nodes", text="Free Unused")
82             layout.prop(snode, "show_backdrop")
83             if snode.show_backdrop:
84                 row = layout.row(align=True)
85                 row.prop(snode, "backdrop_channels", text="", expand=True)
86             layout.prop(snode, "use_auto_render")
87
88         else:
89             # Custom node tree is edited as independent ID block
90             layout.template_ID(snode, "node_tree", new="node.new_node_tree")
91
92         layout.prop(snode, "pin", text="")
93         layout.operator("node.tree_path_parent", text="", icon='FILE_PARENT')
94
95         layout.separator()
96
97         # Snap
98         row = layout.row(align=True)
99         row.prop(toolsettings, "use_snap", text="")
100         row.prop(toolsettings, "snap_node_element", text="", icon_only=True)
101         if toolsettings.snap_node_element != 'INCREMENT':
102             row.prop(toolsettings, "snap_target", text="")
103
104         row = layout.row(align=True)
105         row.operator("node.clipboard_copy", text="", icon='COPYDOWN')
106         row.operator("node.clipboard_paste", text="", icon='PASTEDOWN')
107
108         layout.template_running_jobs()
109
110
111 class NODE_MT_view(Menu):
112     bl_label = "View"
113
114     def draw(self, context):
115         layout = self.layout
116
117         layout.operator("node.properties", icon='MENU_PANEL')
118         layout.operator("node.toolbar", icon='MENU_PANEL')
119         
120         layout.separator()
121
122         layout.operator("view2d.zoom_in")
123         layout.operator("view2d.zoom_out")
124
125         layout.separator()
126
127         layout.operator("node.view_selected")
128         layout.operator("node.view_all")
129
130         if context.space_data.show_backdrop:
131             layout.separator()
132
133             layout.operator("node.backimage_move", text="Backdrop move")
134             layout.operator("node.backimage_zoom", text="Backdrop zoom in").factor = 1.2
135             layout.operator("node.backimage_zoom", text="Backdrop zoom out").factor = 0.833
136
137         layout.separator()
138
139         layout.operator("screen.area_dupli")
140         layout.operator("screen.screen_full_area")
141
142
143 class NODE_MT_select(Menu):
144     bl_label = "Select"
145
146     def draw(self, context):
147         layout = self.layout
148
149         layout.operator("node.select_border")
150
151         layout.separator()
152         layout.operator("node.select_all").action = 'TOGGLE'
153         layout.operator("node.select_all", text="Inverse").action = 'INVERT'
154         layout.operator("node.select_linked_from")
155         layout.operator("node.select_linked_to")
156
157         layout.separator()
158
159         layout.operator("node.select_same_type")
160         layout.operator("node.select_same_type_step").prev = True
161         layout.operator("node.select_same_type_step").prev = False
162
163         layout.separator()
164
165         layout.operator("node.find_node")
166
167
168 class NODE_MT_node(Menu):
169     bl_label = "Node"
170
171     def draw(self, context):
172         layout = self.layout
173
174         layout.operator("transform.translate")
175         layout.operator("transform.rotate")
176         layout.operator("transform.resize")
177
178         layout.separator()
179
180         layout.operator("node.duplicate_move")
181         layout.operator("node.delete")
182         layout.operator("node.delete_reconnect")
183
184         layout.separator()
185
186         layout.operator("node.join", text="Join in new Frame")
187         layout.operator("node.detach", text="Remove from Frame")
188
189         layout.separator()
190
191         layout.operator("node.link_make")
192         layout.operator("node.link_make", text="Make and Replace Links").replace = True
193         layout.operator("node.links_cut")
194         layout.operator("node.links_detach")
195
196         layout.separator()
197
198         layout.operator("node.group_edit")
199         layout.operator("node.group_ungroup")
200         layout.operator("node.group_make")
201         layout.operator("node.group_insert")
202
203         layout.separator()
204
205         layout.operator("node.hide_toggle")
206         layout.operator("node.mute_toggle")
207         layout.operator("node.preview_toggle")
208         layout.operator("node.hide_socket_toggle")
209         layout.operator("node.options_toggle")
210         layout.operator("node.collapse_hide_unused_toggle")
211
212         layout.separator()
213
214         layout.operator("node.show_cyclic_dependencies")
215         layout.operator("node.read_renderlayers")
216         layout.operator("node.read_fullsamplelayers")
217
218
219 # Node Backdrop options
220 class NODE_PT_properties(Panel):
221     bl_space_type = 'NODE_EDITOR'
222     bl_region_type = 'UI'
223     bl_label = "Backdrop"
224
225     @classmethod
226     def poll(cls, context):
227         snode = context.space_data
228         return snode.tree_type == 'CompositorNodeTree'
229
230     def draw_header(self, context):
231         snode = context.space_data
232         self.layout.prop(snode, "show_backdrop", text="")
233
234     def draw(self, context):
235         layout = self.layout
236
237         snode = context.space_data
238         layout.active = snode.show_backdrop
239         layout.prop(snode, "backdrop_channels", text="")
240         layout.prop(snode, "backdrop_zoom", text="Zoom")
241
242         col = layout.column(align=True)
243         col.label(text="Offset:")
244         col.prop(snode, "backdrop_x", text="X")
245         col.prop(snode, "backdrop_y", text="Y")
246         col.operator("node.backimage_move", text="Move")
247
248
249 class NODE_PT_quality(bpy.types.Panel):
250     bl_space_type = 'NODE_EDITOR'
251     bl_region_type = 'UI'
252     bl_label = "Performance"
253
254     @classmethod
255     def poll(cls, context):
256         snode = context.space_data
257         return snode.tree_type == 'CompositorNodeTree' and snode.node_tree is not None
258
259     def draw(self, context):
260         layout = self.layout
261
262         snode = context.space_data
263         tree = snode.node_tree
264
265         col = layout.column()
266         col.prop(tree, "render_quality", text="Render")
267         col.prop(tree, "edit_quality", text="Edit")
268         col.prop(tree, "chunk_size")
269
270         col = layout.column()
271         col.prop(tree, "use_opencl")
272         col.prop(tree, "use_groupnode_buffer")
273         col.prop(tree, "two_pass")
274         col.prop(tree, "use_viewer_border")
275         col.prop(snode, "show_highlight")
276         col.prop(snode, "use_hidden_preview")
277
278
279 class NODE_MT_node_color_presets(Menu):
280     """Predefined node color"""
281     bl_label = "Color Presets"
282     preset_subdir = "node_color"
283     preset_operator = "script.execute_preset"
284     draw = Menu.draw_preset
285
286
287 class NODE_MT_node_color_specials(Menu):
288     bl_label = "Node Color Specials"
289
290     def draw(self, context):
291         layout = self.layout
292
293         layout.operator("node.node_copy_color", icon='COPY_ID')
294
295
296 class NODE_UL_interface_sockets(bpy.types.UIList):
297     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
298         socket = item
299         color = socket.draw_color(context)
300
301         if self.layout_type in {'DEFAULT', 'COMPACT'}:
302             row = layout.row(align=True)
303
304             # inputs get icon on the left
305             if socket.in_out == 'IN':
306                 row.template_node_socket(color)
307
308             row.label(text=socket.name, icon_value=icon)
309
310             # outputs get icon on the right
311             if socket.in_out == 'OUT':
312                 row.template_node_socket(color)
313
314         elif self.layout_type in {'GRID'}:
315             layout.alignment = 'CENTER'
316             layout.template_node_socket(color)
317
318
319 if __name__ == "__main__":  # only for live edit.
320     bpy.utils.register_module(__name__)