Cycles Node Editor:
[blender.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
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 == 'SHADER':
48             if scene.render.use_shading_nodes:
49                 layout.prop(snode, "shader_type", text="", expand=True)
50
51             if (not scene.render.use_shading_nodes or snode.shader_type == 'OBJECT') and ob:
52                 # Show material.new when no active ID/slot exists
53                 if not id_from and ob.type in {'MESH', 'CURVE', 'SURFACE', 'FONT', 'METABALL'}:
54                     layout.template_ID(ob, "active_material", new="material.new")
55                 # Material ID, but not for Lamps
56                 if id_from and ob.type != 'LAMP':
57                     layout.template_ID(id_from, "active_material", new="material.new")
58                 # Don't show "Use Nodes" Button when Engine is BI for Lamps
59                 if snode_id and not (scene.render.use_shading_nodes == 0 and ob.type == 'LAMP'):
60                     layout.prop(snode_id, "use_nodes")
61                     
62             if snode.shader_type == 'WORLD':
63                 layout.template_ID(scene, "world", new="world.new")
64                 layout.prop(snode_id, "use_nodes")
65
66         elif snode.tree_type == 'TEXTURE':
67             layout.prop(snode, "texture_type", text="", expand=True)
68
69             if id_from:
70                 if snode.texture_type == 'BRUSH':
71                     layout.template_ID(id_from, "texture", new="texture.new")
72                 else:
73                     layout.template_ID(id_from, "active_texture", new="texture.new")
74             if snode_id:
75                 layout.prop(snode_id, "use_nodes")
76
77         elif snode.tree_type == 'COMPOSITING':
78             layout.prop(snode_id, "use_nodes")
79             layout.prop(snode_id.render, "use_free_unused_nodes", text="Free Unused")
80             layout.prop(snode, "show_backdrop")
81             if snode.show_backdrop:
82                 row = layout.row(align=True)
83                 row.prop(snode, "backdrop_channels", text="", expand=True)
84             layout.prop(snode, "use_auto_render")
85
86         layout.separator()
87
88         layout.template_running_jobs()
89
90
91 class NODE_MT_view(Menu):
92     bl_label = "View"
93
94     def draw(self, context):
95         layout = self.layout
96
97         layout.operator("node.properties", icon='MENU_PANEL')
98         layout.separator()
99
100         layout.operator("view2d.zoom_in")
101         layout.operator("view2d.zoom_out")
102
103         layout.separator()
104
105         layout.operator("node.view_all")
106
107         if context.space_data.show_backdrop:
108             layout.separator()
109
110             layout.operator("node.backimage_move", text="Backdrop move")
111             layout.operator("node.backimage_zoom", text="Backdrop zoom in").factor = 1.2
112             layout.operator("node.backimage_zoom", text="Backdrop zoom out").factor = 0.833
113
114         layout.separator()
115
116         layout.operator("screen.area_dupli")
117         layout.operator("screen.screen_full_area")
118
119
120 class NODE_MT_select(Menu):
121     bl_label = "Select"
122
123     def draw(self, context):
124         layout = self.layout
125
126         layout.operator("node.select_border")
127
128         layout.separator()
129         layout.operator("node.select_all")
130         layout.operator("node.select_linked_from")
131         layout.operator("node.select_linked_to")
132         layout.operator("node.select_same_type")
133         layout.operator("node.select_same_type_next")
134         layout.operator("node.select_same_type_prev")
135
136
137 class NODE_MT_node(Menu):
138     bl_label = "Node"
139
140     def draw(self, context):
141         layout = self.layout
142
143         layout.operator("transform.translate")
144         layout.operator("transform.rotate")
145         layout.operator("transform.resize")
146
147         layout.separator()
148
149         layout.operator("node.duplicate_move")
150         layout.operator("node.delete")
151         layout.operator("node.delete_reconnect")
152
153         layout.separator()
154         layout.operator("node.link_make")
155         layout.operator("node.link_make", text="Make and Replace Links").replace = True
156         layout.operator("node.links_cut")
157
158         layout.separator()
159         layout.operator("node.group_edit")
160         layout.operator("node.group_ungroup")
161         layout.operator("node.group_make")
162
163         layout.separator()
164
165         layout.operator("node.hide_toggle")
166         layout.operator("node.mute_toggle")
167         layout.operator("node.preview_toggle")
168         layout.operator("node.hide_socket_toggle")
169         layout.operator("node.options_toggle")
170
171         layout.separator()
172
173         layout.operator("node.show_cyclic_dependencies")
174         layout.operator("node.read_renderlayers")
175         layout.operator("node.read_fullsamplelayers")
176
177
178 # Node Backdrop options
179 class NODE_PT_properties(Panel):
180     bl_space_type = 'NODE_EDITOR'
181     bl_region_type = 'UI'
182     bl_label = "Backdrop"
183
184     @classmethod
185     def poll(cls, context):
186         snode = context.space_data
187         return snode.tree_type == 'COMPOSITING'
188
189     def draw_header(self, context):
190         snode = context.space_data
191         self.layout.prop(snode, "show_backdrop", text="")
192
193     def draw(self, context):
194         layout = self.layout
195
196         snode = context.space_data
197         layout.active = snode.show_backdrop
198         layout.prop(snode, "backdrop_channels", text="")
199         layout.prop(snode, "backdrop_zoom", text="Zoom")
200
201         col = layout.column(align=True)
202         col.label(text="Offset:")
203         col.prop(snode, "backdrop_x", text="X")
204         col.prop(snode, "backdrop_y", text="Y")
205         col.operator("node.backimage_move", text="Move")
206
207 if __name__ == "__main__":  # only for live edit.
208     bpy.utils.register_module(__name__)