Moving classes to separate listing broke panel order
[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 import nodeitems_utils
22 from bpy.types import Header, Menu, Panel
23 from bpy.app.translations import pgettext_iface as iface_
24 from bl_ui.properties_grease_pencil_common import (
25         GreasePencilDrawingToolsPanel,
26         GreasePencilStrokeEditPanel,
27         GreasePencilStrokeSculptPanel,
28         GreasePencilBrushPanel,
29         GreasePencilBrushCurvesPanel,
30         GreasePencilDataPanel,
31         GreasePencilPaletteColorPanel,
32         GreasePencilToolsPanel
33         )
34
35
36 class NODE_HT_header(Header):
37     bl_space_type = 'NODE_EDITOR'
38
39     def draw(self, context):
40         layout = self.layout
41
42         scene = context.scene
43         snode = context.space_data
44         snode_id = snode.id
45         id_from = snode.id_from
46         toolsettings = context.tool_settings
47
48         row = layout.row(align=True)
49         row.template_header()
50
51         NODE_MT_editor_menus.draw_collapsible(context, layout)
52
53         layout.prop(snode, "tree_type", text="", expand=True)
54
55         if snode.tree_type == 'ShaderNodeTree':
56             if scene.render.use_shading_nodes:
57                 layout.prop(snode, "shader_type", text="", expand=True)
58
59             ob = context.object
60             if (not scene.render.use_shading_nodes or snode.shader_type == 'OBJECT') and ob:
61                 row = layout.row()
62                 # disable material slot buttons when pinned, cannot find correct slot within id_from (#36589)
63                 row.enabled = not snode.pin
64                 # Show material.new when no active ID/slot exists
65                 if not id_from and ob.type in {'MESH', 'CURVE', 'SURFACE', 'FONT', 'METABALL'}:
66                     row.template_ID(ob, "active_material", new="material.new")
67                 # Material ID, but not for Lamps
68                 if id_from and ob.type != 'LAMP':
69                     row.template_ID(id_from, "active_material", new="material.new")
70
71                 # Don't show "Use Nodes" Button when Engine is BI for Lamps
72                 if snode_id and not (scene.render.use_shading_nodes == 0 and ob.type == 'LAMP'):
73                     layout.prop(snode_id, "use_nodes")
74
75             if scene.render.use_shading_nodes and snode.shader_type == 'WORLD':
76                 row = layout.row()
77                 row.enabled = not snode.pin
78                 row.template_ID(scene, "world", new="world.new")
79                 if snode_id:
80                     row.prop(snode_id, "use_nodes")
81
82             if scene.render.use_shading_nodes and snode.shader_type == 'LINESTYLE':
83                 rl = context.scene.render.layers.active
84                 lineset = rl.freestyle_settings.linesets.active
85                 if lineset is not None:
86                     row = layout.row()
87                     row.enabled = not snode.pin
88                     row.template_ID(lineset, "linestyle", new="scene.freestyle_linestyle_new")
89                     if snode_id:
90                         row.prop(snode_id, "use_nodes")
91
92         elif snode.tree_type == 'TextureNodeTree':
93             layout.prop(snode, "texture_type", text="", expand=True)
94
95             if id_from:
96                 if snode.texture_type == 'BRUSH':
97                     layout.template_ID(id_from, "texture", new="texture.new")
98                 else:
99                     layout.template_ID(id_from, "active_texture", new="texture.new")
100             if snode_id:
101                 layout.prop(snode_id, "use_nodes")
102
103         elif snode.tree_type == 'CompositorNodeTree':
104             if snode_id:
105                 layout.prop(snode_id, "use_nodes")
106             layout.prop(snode, "show_backdrop")
107             if snode.show_backdrop:
108                 row = layout.row(align=True)
109                 row.prop(snode, "backdrop_channels", text="", expand=True)
110             layout.prop(snode, "use_auto_render")
111
112         else:
113             # Custom node tree is edited as independent ID block
114             layout.template_ID(snode, "node_tree", new="node.new_node_tree")
115
116         layout.prop(snode, "pin", text="")
117         layout.operator("node.tree_path_parent", text="", icon='FILE_PARENT')
118
119         layout.separator()
120
121         # Auto-offset nodes (called "insert_offset" in code)
122         layout.prop(snode, "use_insert_offset", text="")
123
124         # Snap
125         row = layout.row(align=True)
126         row.prop(toolsettings, "use_snap", text="")
127         row.prop(toolsettings, "snap_node_element", icon_only=True)
128         if toolsettings.snap_node_element != 'GRID':
129             row.prop(toolsettings, "snap_target", text="")
130
131         row = layout.row(align=True)
132         row.operator("node.clipboard_copy", text="", icon='COPYDOWN')
133         row.operator("node.clipboard_paste", text="", icon='PASTEDOWN')
134
135         layout.template_running_jobs()
136
137
138 class NODE_MT_editor_menus(Menu):
139     bl_idname = "NODE_MT_editor_menus"
140     bl_label = ""
141
142     def draw(self, context):
143         self.draw_menus(self.layout, context)
144
145     @staticmethod
146     def draw_menus(layout, context):
147         layout.menu("NODE_MT_view")
148         layout.menu("NODE_MT_select")
149         layout.menu("NODE_MT_add")
150         layout.menu("NODE_MT_node")
151
152
153 class NODE_MT_add(bpy.types.Menu):
154     bl_space_type = 'NODE_EDITOR'
155     bl_label = "Add"
156
157     def draw(self, context):
158         layout = self.layout
159
160         layout.operator_context = 'INVOKE_DEFAULT'
161         props = layout.operator("node.add_search", text="Search ...")
162         props.use_transform = True
163
164         # actual node submenus are defined by draw functions from node categories
165         nodeitems_utils.draw_node_categories_menu(self, context)
166
167
168 class NODE_MT_view(Menu):
169     bl_label = "View"
170
171     def draw(self, context):
172         layout = self.layout
173
174         layout.operator("node.properties", icon='MENU_PANEL')
175         layout.operator("node.toolbar", icon='MENU_PANEL')
176
177         layout.separator()
178
179         layout.operator("view2d.zoom_in")
180         layout.operator("view2d.zoom_out")
181
182         layout.separator()
183
184         layout.operator("node.view_selected")
185         layout.operator("node.view_all")
186
187         if context.space_data.show_backdrop:
188             layout.separator()
189
190             layout.operator("node.backimage_move", text="Backdrop move")
191             layout.operator("node.backimage_zoom", text="Backdrop zoom in").factor = 1.2
192             layout.operator("node.backimage_zoom", text="Backdrop zoom out").factor = 0.83333
193             layout.operator("node.backimage_fit", text="Fit backdrop to available space")
194
195         layout.separator()
196
197         layout.operator("screen.area_dupli")
198         layout.operator("screen.screen_full_area")
199         layout.operator("screen.screen_full_area", text="Toggle Fullscreen Area").use_hide_panels = True
200
201
202 class NODE_MT_select(Menu):
203     bl_label = "Select"
204
205     def draw(self, context):
206         layout = self.layout
207
208         layout.operator("node.select_border").tweak = False
209         layout.operator("node.select_circle")
210
211         layout.separator()
212         layout.operator("node.select_all").action = 'TOGGLE'
213         layout.operator("node.select_all", text="Inverse").action = 'INVERT'
214         layout.operator("node.select_linked_from")
215         layout.operator("node.select_linked_to")
216
217         layout.separator()
218
219         layout.operator("node.select_grouped").extend = False
220         layout.operator("node.select_same_type_step", text="Activate Same Type Previous").prev = True
221         layout.operator("node.select_same_type_step", text="Activate Same Type Next").prev = False
222
223         layout.separator()
224
225         layout.operator("node.find_node")
226
227
228 class NODE_MT_node(Menu):
229     bl_label = "Node"
230
231     def draw(self, context):
232         layout = self.layout
233
234         layout.operator("transform.translate")
235         layout.operator("transform.rotate")
236         layout.operator("transform.resize")
237
238         layout.separator()
239
240         layout.operator("node.duplicate_move")
241         layout.operator("node.delete")
242         layout.operator("node.delete_reconnect")
243
244         layout.separator()
245
246         layout.operator("node.join", text="Join in new Frame")
247         layout.operator("node.detach", text="Remove from Frame")
248
249         layout.separator()
250
251         layout.operator("node.link_make").replace = False
252         layout.operator("node.link_make", text="Make and Replace Links").replace = True
253         layout.operator("node.links_cut")
254         layout.operator("node.links_detach")
255
256         layout.separator()
257
258         layout.operator("node.group_edit").exit = False
259         layout.operator("node.group_ungroup")
260         layout.operator("node.group_make")
261         layout.operator("node.group_insert")
262
263         layout.separator()
264
265         layout.operator("node.hide_toggle")
266         layout.operator("node.mute_toggle")
267         layout.operator("node.preview_toggle")
268         layout.operator("node.hide_socket_toggle")
269         layout.operator("node.options_toggle")
270         layout.operator("node.collapse_hide_unused_toggle")
271
272         layout.separator()
273
274         layout.operator("node.read_renderlayers")
275         layout.operator("node.read_fullsamplelayers")
276
277
278 class NODE_MT_node_color_presets(Menu):
279     """Predefined node color"""
280     bl_label = "Color Presets"
281     preset_subdir = "node_color"
282     preset_operator = "script.execute_preset"
283     draw = Menu.draw_preset
284
285
286 class NODE_MT_node_color_specials(Menu):
287     bl_label = "Node Color Specials"
288
289     def draw(self, context):
290         layout = self.layout
291
292         layout.operator("node.node_copy_color", icon='COPY_ID')
293
294
295 class NODE_PT_active_node_generic(Panel):
296     bl_space_type = 'NODE_EDITOR'
297     bl_region_type = 'UI'
298     bl_label = "Node"
299 #    bl_options = {'HIDE_HEADER'}
300
301     @classmethod
302     def poll(cls, context):
303         return context.active_node is not None
304
305     def draw(self, context):
306         layout = self.layout
307         node = context.active_node
308
309         layout.prop(node, "name", icon='NODE')
310         layout.prop(node, "label", icon='NODE')
311
312
313 class NODE_PT_active_node_color(Panel):
314     bl_space_type = 'NODE_EDITOR'
315     bl_region_type = 'UI'
316     bl_label = "Color"
317     bl_options = {'DEFAULT_CLOSED'}
318
319     @classmethod
320     def poll(cls, context):
321         return context.active_node is not None
322
323     def draw_header(self, context):
324         node = context.active_node
325         self.layout.prop(node, "use_custom_color", text="")
326
327     def draw(self, context):
328         layout = self.layout
329         node = context.active_node
330
331         layout.enabled = node.use_custom_color
332
333         row = layout.row()
334         col = row.column()
335         col.menu("NODE_MT_node_color_presets")
336         col.prop(node, "color", text="")
337         col = row.column(align=True)
338         col.operator("node.node_color_preset_add", text="", icon='ZOOMIN').remove_active = False
339         col.operator("node.node_color_preset_add", text="", icon='ZOOMOUT').remove_active = True
340         col.menu("NODE_MT_node_color_specials", text="", icon='DOWNARROW_HLT')
341
342
343 class NODE_PT_active_node_properties(Panel):
344     bl_space_type = 'NODE_EDITOR'
345     bl_region_type = 'UI'
346     bl_label = "Properties"
347
348     @classmethod
349     def poll(cls, context):
350         return context.active_node is not None
351
352     def draw(self, context):
353         layout = self.layout
354         node = context.active_node
355         # set "node" context pointer for the panel layout
356         layout.context_pointer_set("node", node)
357
358         if hasattr(node, "draw_buttons_ext"):
359             node.draw_buttons_ext(context, layout)
360         elif hasattr(node, "draw_buttons"):
361             node.draw_buttons(context, layout)
362
363         # XXX this could be filtered further to exclude socket types which don't have meaningful input values (e.g. cycles shader)
364         value_inputs = [socket for socket in node.inputs if socket.enabled and not socket.is_linked]
365         if value_inputs:
366             layout.separator()
367             layout.label("Inputs:")
368             for socket in value_inputs:
369                 row = layout.row()
370                 socket.draw(context, row, node, iface_(socket.name, socket.bl_rna.translation_context))
371
372
373 # Node Backdrop options
374 class NODE_PT_backdrop(Panel):
375     bl_space_type = 'NODE_EDITOR'
376     bl_region_type = 'UI'
377     bl_label = "Backdrop"
378
379     @classmethod
380     def poll(cls, context):
381         snode = context.space_data
382         return snode.tree_type == 'CompositorNodeTree'
383
384     def draw_header(self, context):
385         snode = context.space_data
386         self.layout.prop(snode, "show_backdrop", text="")
387
388     def draw(self, context):
389         layout = self.layout
390
391         snode = context.space_data
392         layout.active = snode.show_backdrop
393         layout.prop(snode, "backdrop_channels", text="")
394         layout.prop(snode, "backdrop_zoom", text="Zoom")
395
396         col = layout.column(align=True)
397         col.label(text="Offset:")
398         col.prop(snode, "backdrop_x", text="X")
399         col.prop(snode, "backdrop_y", text="Y")
400         col.operator("node.backimage_move", text="Move")
401
402         layout.operator("node.backimage_fit", text="Fit")
403
404
405 class NODE_PT_quality(bpy.types.Panel):
406     bl_space_type = 'NODE_EDITOR'
407     bl_region_type = 'UI'
408     bl_label = "Performance"
409
410     @classmethod
411     def poll(cls, context):
412         snode = context.space_data
413         return snode.tree_type == 'CompositorNodeTree' and snode.node_tree is not None
414
415     def draw(self, context):
416         layout = self.layout
417
418         snode = context.space_data
419         tree = snode.node_tree
420
421         col = layout.column()
422         col.prop(tree, "render_quality", text="Render")
423         col.prop(tree, "edit_quality", text="Edit")
424         col.prop(tree, "chunk_size")
425
426         col = layout.column()
427         col.prop(tree, "use_opencl")
428         col.prop(tree, "use_groupnode_buffer")
429         col.prop(tree, "use_two_pass")
430         col.prop(tree, "use_viewer_border")
431         col.prop(snode, "show_highlight")
432
433
434 class NODE_UL_interface_sockets(bpy.types.UIList):
435     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
436         socket = item
437         color = socket.draw_color(context)
438
439         if self.layout_type in {'DEFAULT', 'COMPACT'}:
440             row = layout.row(align=True)
441
442             # inputs get icon on the left
443             if not socket.is_output:
444                 row.template_node_socket(color)
445
446             row.prop(socket, "name", text="", emboss=False, icon_value=icon)
447
448             # outputs get icon on the right
449             if socket.is_output:
450                 row.template_node_socket(color)
451
452         elif self.layout_type == 'GRID':
453             layout.alignment = 'CENTER'
454             layout.template_node_socket(color)
455
456
457 # Grease Pencil properties
458 class NODE_PT_grease_pencil(GreasePencilDataPanel, Panel):
459     bl_space_type = 'NODE_EDITOR'
460     bl_region_type = 'UI'
461
462     # NOTE: this is just a wrapper around the generic GP Panel
463
464     @classmethod
465     def poll(cls, context):
466         snode = context.space_data
467         return snode is not None and snode.node_tree is not None
468
469
470 # Grease Pencil palette colors
471 class NODE_PT_grease_pencil_palettecolor(GreasePencilPaletteColorPanel, Panel):
472     bl_space_type = 'NODE_EDITOR'
473     bl_region_type = 'UI'
474
475     # NOTE: this is just a wrapper around the generic GP Panel
476
477     @classmethod
478     def poll(cls, context):
479         snode = context.space_data
480         return snode is not None and snode.node_tree is not None
481
482
483 class NODE_PT_grease_pencil_tools(GreasePencilToolsPanel, Panel):
484     bl_space_type = 'NODE_EDITOR'
485     bl_region_type = 'UI'
486     bl_options = {'DEFAULT_CLOSED'}
487
488     # NOTE: this is just a wrapper around the generic GP tools panel
489     # It contains access to some essential tools usually found only in
490     # toolbar, but which may not necessarily be open
491
492
493 # Tool Shelf ------------------
494
495
496 # Grease Pencil drawing tools
497 class NODE_PT_tools_grease_pencil_draw(GreasePencilDrawingToolsPanel, Panel):
498     bl_space_type = 'NODE_EDITOR'
499     bl_region_type = 'TOOLS'
500
501
502 # Grease Pencil stroke editing tools
503 class NODE_PT_tools_grease_pencil_edit(GreasePencilStrokeEditPanel, Panel):
504     bl_space_type = 'NODE_EDITOR'
505     bl_region_type = 'TOOLS'
506
507
508 # Grease Pencil stroke sculpting tools
509 class NODE_PT_tools_grease_pencil_sculpt(GreasePencilStrokeSculptPanel, Panel):
510     bl_space_type = 'NODE_EDITOR'
511     bl_region_type = 'TOOLS'
512
513 # Grease Pencil drawing brushes
514 class NODE_PT_tools_grease_pencil_brush(GreasePencilBrushPanel, Panel):
515     bl_space_type = 'NODE_EDITOR'
516     bl_region_type = 'TOOLS'
517
518 # Grease Pencil drawing curves
519 class NODE_PT_tools_grease_pencil_brushcurves(GreasePencilBrushCurvesPanel, Panel):
520     bl_space_type = 'NODE_EDITOR'
521     bl_region_type = 'TOOLS'
522
523 # -----------------------------
524
525
526 def node_draw_tree_view(layout, context):
527     pass
528
529 classes = (
530     NODE_HT_header,
531     NODE_MT_editor_menus,
532     NODE_MT_add,
533     NODE_MT_view,
534     NODE_MT_select,
535     NODE_MT_node,
536     NODE_MT_node_color_presets,
537     NODE_MT_node_color_specials,
538     NODE_PT_active_node_generic,
539     NODE_PT_active_node_color,
540     NODE_PT_active_node_properties,
541     NODE_PT_backdrop,
542     NODE_PT_quality,
543     NODE_UL_interface_sockets,
544     NODE_PT_grease_pencil,
545     NODE_PT_grease_pencil_palettecolor,
546     NODE_PT_grease_pencil_tools,
547     NODE_PT_tools_grease_pencil_draw,
548     NODE_PT_tools_grease_pencil_edit,
549     NODE_PT_tools_grease_pencil_sculpt,
550     NODE_PT_tools_grease_pencil_brush,
551     NODE_PT_tools_grease_pencil_brushcurves,
552 )
553
554
555 if __name__ == "__main__":  # only for live edit.
556     from bpy.utils import register_class
557     for cls in classes:
558         register_class(cls)