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