Merging r50049 through r50076 from trunk into soc-2011-tomato
[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         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 == 'SHADER':
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 == 'TEXTURE':
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 == 'COMPOSITING':
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         layout.separator()
89
90         # Snap
91         row = layout.row(align=True)
92         row.prop(toolsettings, "use_snap", text="")
93         row.prop(toolsettings, "snap_node_element", text="", icon_only=True)
94         if toolsettings.snap_node_element != 'INCREMENT':
95             row.prop(toolsettings, "snap_target", text="")
96
97         row = layout.row(align=True)
98         row.operator("node.clipboard_copy", text="", icon='COPYDOWN')
99         row.operator("node.clipboard_paste", text="", icon='PASTEDOWN')
100
101         layout.template_running_jobs()
102
103
104 class NODE_MT_view(Menu):
105     bl_label = "View"
106
107     def draw(self, context):
108         layout = self.layout
109
110         layout.operator("node.properties", icon='MENU_PANEL')
111         layout.separator()
112
113         layout.operator("view2d.zoom_in")
114         layout.operator("view2d.zoom_out")
115
116         layout.separator()
117
118         layout.operator("node.view_selected")
119         layout.operator("node.view_all")
120
121         if context.space_data.show_backdrop:
122             layout.separator()
123
124             layout.operator("node.backimage_move", text="Backdrop move")
125             layout.operator("node.backimage_zoom", text="Backdrop zoom in").factor = 1.2
126             layout.operator("node.backimage_zoom", text="Backdrop zoom out").factor = 0.833
127
128         layout.separator()
129
130         layout.operator("screen.area_dupli")
131         layout.operator("screen.screen_full_area")
132
133
134 class NODE_MT_select(Menu):
135     bl_label = "Select"
136
137     def draw(self, context):
138         layout = self.layout
139
140         layout.operator("node.select_border")
141
142         layout.separator()
143         layout.operator("node.select_all").action = 'TOGGLE'
144         layout.operator("node.select_all", text="Inverse").action = 'INVERT'
145         layout.operator("node.select_linked_from")
146         layout.operator("node.select_linked_to")
147         layout.operator("node.select_same_type")
148         layout.operator("node.select_same_type_next")
149         layout.operator("node.select_same_type_prev")
150
151
152 class NODE_MT_node(Menu):
153     bl_label = "Node"
154
155     def draw(self, context):
156         layout = self.layout
157
158         layout.operator("transform.translate")
159         layout.operator("transform.rotate")
160         layout.operator("transform.resize")
161
162         layout.separator()
163
164         layout.operator("node.duplicate_move")
165         layout.operator("node.delete")
166         layout.operator("node.delete_reconnect")
167
168         layout.separator()
169         layout.operator("node.link_make")
170         layout.operator("node.link_make", text="Make and Replace Links").replace = True
171         layout.operator("node.links_cut")
172
173         layout.separator()
174         layout.operator("node.group_edit")
175         layout.operator("node.group_ungroup")
176         layout.operator("node.group_make")
177
178         layout.separator()
179
180         layout.operator("node.hide_toggle")
181         layout.operator("node.mute_toggle")
182         layout.operator("node.preview_toggle")
183         layout.operator("node.hide_socket_toggle")
184         layout.operator("node.options_toggle")
185         layout.operator("node.collapse_hide_unused_toggle")
186
187         layout.separator()
188
189         layout.operator("node.show_cyclic_dependencies")
190         layout.operator("node.read_renderlayers")
191         layout.operator("node.read_fullsamplelayers")
192
193
194 class NODE_PT_display_properties(Panel):
195     bl_space_type = 'NODE_EDITOR'
196     bl_region_type = 'UI'
197     bl_label = "Display Properties"
198
199     def draw(self, context):
200         layout = self.layout
201         space = context.space_data
202
203         layout.template_colormanaged_view_settings(space, "view_settings", True)
204
205
206 # Node Backdrop options
207 class NODE_PT_properties(Panel):
208     bl_space_type = 'NODE_EDITOR'
209     bl_region_type = 'UI'
210     bl_label = "Backdrop"
211
212     @classmethod
213     def poll(cls, context):
214         snode = context.space_data
215         return snode.tree_type == 'COMPOSITING'
216
217     def draw_header(self, context):
218         snode = context.space_data
219         self.layout.prop(snode, "show_backdrop", text="")
220
221     def draw(self, context):
222         layout = self.layout
223
224         snode = context.space_data
225         layout.active = snode.show_backdrop
226         layout.prop(snode, "backdrop_channels", text="")
227         layout.prop(snode, "backdrop_zoom", text="Zoom")
228
229         col = layout.column(align=True)
230         col.label(text="Offset:")
231         col.prop(snode, "backdrop_x", text="X")
232         col.prop(snode, "backdrop_y", text="Y")
233         col.operator("node.backimage_move", text="Move")
234
235
236 class NODE_PT_quality(bpy.types.Panel):
237     bl_space_type = 'NODE_EDITOR'
238     bl_region_type = 'UI'
239     bl_label = "Performance"
240
241     @classmethod
242     def poll(cls, context):
243         snode = context.space_data
244         return snode.tree_type == 'COMPOSITING' and snode.node_tree is not None
245
246     def draw(self, context):
247         layout = self.layout
248
249         snode = context.space_data
250         tree = snode.node_tree
251
252         col = layout.column()
253         col.prop(tree, "render_quality", text="Render")
254         col.prop(tree, "edit_quality", text="Edit")
255         col.prop(tree, "chunk_size")
256
257         col = layout.column()
258         col.prop(tree, "use_opencl")
259         col.prop(tree, "two_pass")
260         col.prop(snode, "show_highlight")
261         col.prop(snode, "use_hidden_preview")
262
263
264 class NODE_MT_node_color_presets(Menu):
265     """Predefined node color"""
266     bl_label = "Color Presets"
267     preset_subdir = "node_color"
268     preset_operator = "script.execute_preset"
269     draw = Menu.draw_preset
270
271
272 class NODE_MT_node_color_specials(Menu):
273     bl_label = "Node Color Specials"
274
275     def draw(self, context):
276         layout = self.layout
277
278         layout.operator("node.node_copy_color", icon='COPY_ID')
279
280
281 if __name__ == "__main__":  # only for live edit.
282     bpy.utils.register_module(__name__)