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