Outliner: Collection - Duplicate Hierarchy, and Duplicate Linked Hierarchy
[blender.git] / release / scripts / startup / bl_ui / space_outliner.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 OUTLINER_HT_header(Header):
25     bl_space_type = 'OUTLINER'
26
27     def draw(self, context):
28         layout = self.layout
29
30         space = context.space_data
31         display_mode = space.display_mode
32         scene = context.scene
33         ks = context.scene.keying_sets.active
34
35         row = layout.row(align=True)
36         row.template_header()
37
38         layout.prop(space, "display_mode", icon_only=True)
39
40         if display_mode == 'DATA_API':
41             OUTLINER_MT_editor_menus.draw_collapsible(context, layout)
42
43         layout.separator_spacer()
44
45         row = layout.row(align=True)
46         row.prop(space, "filter_text", icon='VIEWZOOM', text="")
47
48         layout.separator_spacer()
49
50         row = layout.row(align=True)
51         if display_mode in {'VIEW_LAYER'}:
52             row.popover(
53                 panel="OUTLINER_PT_filter",
54                 text="",
55                 icon='FILTER',
56             )
57         elif display_mode in {'LIBRARIES', 'ORPHAN_DATA'}:
58             row.prop(space, "use_filter_id_type", text="", icon='FILTER')
59             sub = row.row(align=True)
60             sub.active = space.use_filter_id_type
61             sub.prop(space, "filter_id_type", text="", icon_only=True)
62
63         if display_mode == 'VIEW_LAYER':
64             layout.operator("outliner.collection_new", text="", icon='GROUP').nested = True
65
66         elif display_mode == 'ORPHAN_DATA':
67             layout.operator("outliner.orphans_purge", text="Purge")
68
69         elif space.display_mode == 'DATA_API':
70             layout.separator()
71
72             row = layout.row(align=True)
73             row.operator("outliner.keyingset_add_selected", icon='ADD', text="")
74             row.operator("outliner.keyingset_remove_selected", icon='REMOVE', text="")
75
76             if ks:
77                 row = layout.row()
78                 row.prop_search(scene.keying_sets, "active", scene, "keying_sets", text="")
79
80                 row = layout.row(align=True)
81                 row.operator("anim.keyframe_insert", text="", icon='KEY_HLT')
82                 row.operator("anim.keyframe_delete", text="", icon='KEY_DEHLT')
83             else:
84                 row = layout.row()
85                 row.label(text="No Keying Set Active")
86
87
88 class OUTLINER_MT_editor_menus(Menu):
89     bl_idname = "OUTLINER_MT_editor_menus"
90     bl_label = ""
91
92     def draw(self, context):
93         layout = self.layout
94         space = context.space_data
95
96         if space.display_mode == 'DATA_API':
97             layout.menu("OUTLINER_MT_edit_datablocks")
98
99
100 class OUTLINER_MT_context(Menu):
101     bl_label = "Outliner"
102
103     def draw(self, context):
104         layout = self.layout
105
106         layout.menu("OUTLINER_MT_context_view")
107
108         layout.separator()
109
110         layout.menu("INFO_MT_area")
111
112
113 class OUTLINER_MT_context_view(Menu):
114     bl_label = "View"
115
116     def draw(self, context):
117         layout = self.layout
118
119         layout.operator("outliner.show_active")
120
121         layout.separator()
122
123         layout.operator("outliner.show_hierarchy")
124         layout.operator("outliner.show_one_level", text="Show One Level")
125         layout.operator("outliner.show_one_level", text="Hide One Level").open = False
126
127
128 class OUTLINER_MT_edit_datablocks(Menu):
129     bl_label = "Edit"
130
131     def draw(self, context):
132         layout = self.layout
133
134         layout.operator("outliner.keyingset_add_selected")
135         layout.operator("outliner.keyingset_remove_selected")
136
137         layout.separator()
138
139         layout.operator("outliner.drivers_add_selected")
140         layout.operator("outliner.drivers_delete_selected")
141
142
143 class OUTLINER_MT_collection_view_layer(Menu):
144     bl_label = "View Layer"
145
146     def draw(self, context):
147         layout = self.layout
148
149         layout.operator("outliner.collection_exclude_set")
150         layout.operator("outliner.collection_exclude_clear")
151
152         if context.engine == 'CYCLES':
153             layout.operator("outliner.collection_indirect_only_set")
154             layout.operator("outliner.collection_indirect_only_clear")
155
156             layout.operator("outliner.collection_holdout_set")
157             layout.operator("outliner.collection_holdout_clear")
158
159
160 class OUTLINER_MT_collection_duplicate(Menu):
161     bl_label = "Duplicate"
162
163     def draw(self, context):
164         layout = self.layout
165
166         layout.operator("outliner.collection_duplicate", text="Collection")
167         layout.operator("outliner.collection_duplicate_hierarchy", text="Hierarchy")
168         layout.operator("outliner.collection_duplicate_linked_hierarchy", text="Linked Hierarchy")
169
170
171 class OUTLINER_MT_collection_visibility(Menu):
172     bl_label = "Visibility"
173
174     def draw(self, context):
175         layout = self.layout
176
177         layout.operator("outliner.collection_isolate", text="Isolate")
178
179         layout.separator()
180
181         layout.operator("outliner.collection_show", text="Show", icon="HIDE_OFF")
182         layout.operator("outliner.collection_show_inside", text="Show All Inside")
183         layout.operator("outliner.collection_hide", text="Hide", icon="HIDE_ON")
184         layout.operator("outliner.collection_hide_inside", text="Hide All Inside")
185
186         layout.separator()
187
188         layout.operator("outliner.collection_enable", text="Enable in Viewports", icon="RESTRICT_VIEW_OFF")
189         layout.operator("outliner.collection_disable", text="Disable in Viewports")
190
191         layout.separator()
192
193         layout.operator("outliner.collection_enable_render", text="Enable in Render", icon="RESTRICT_RENDER_OFF")
194         layout.operator("outliner.collection_disable_render", text="Disable in Render")
195
196
197 class OUTLINER_MT_collection(Menu):
198     bl_label = "Collection"
199
200     def draw(self, context):
201         layout = self.layout
202
203         space = context.space_data
204
205         layout.operator("outliner.collection_new", text="New").nested = True
206         layout.menu("OUTLINER_MT_collection_duplicate")
207
208         layout.separator()
209
210         layout.operator("outliner.collection_delete", text="Delete", icon="X").hierarchy = False
211         layout.operator("outliner.collection_delete", text="Delete Hierarchy").hierarchy = True
212
213         layout.separator()
214
215         layout.operator("outliner.collection_objects_select", text="Select Objects", icon="RESTRICT_SELECT_OFF")
216         layout.operator("outliner.collection_objects_deselect", text="Deselect Objects")
217
218         layout.separator()
219
220         layout.operator("outliner.collection_instance", text="Instance to Scene")
221
222         if space.display_mode != 'VIEW_LAYER':
223             layout.operator("outliner.collection_link", text="Link to Scene")
224         layout.operator("outliner.id_operation", text="Unlink").type = 'UNLINK'
225
226         layout.separator()
227
228         layout.menu("OUTLINER_MT_collection_visibility")
229
230         if space.display_mode == 'VIEW_LAYER':
231             layout.separator()
232             layout.menu("OUTLINER_MT_collection_view_layer", icon="RENDERLAYERS")
233
234         layout.separator()
235
236         layout.operator_menu_enum("outliner.id_operation", "type", text="ID Data")
237
238         layout.separator()
239
240         OUTLINER_MT_context.draw(self, context)
241
242
243 class OUTLINER_MT_collection_new(Menu):
244     bl_label = "Collection"
245
246     def draw(self, context):
247         layout = self.layout
248
249         layout.operator("outliner.collection_new", text="New").nested = False
250
251         layout.separator()
252
253         OUTLINER_MT_context.draw(self, context)
254
255
256 class OUTLINER_MT_object(Menu):
257     bl_label = "Object"
258
259     def draw(self, context):
260         layout = self.layout
261
262         space = context.space_data
263         obj = context.active_object
264         object_mode = 'OBJECT' if obj is None else obj.mode
265
266         layout.operator("outliner.object_operation", text="Delete", icon="X").type = 'DELETE'
267
268         if space.display_mode == 'VIEW_LAYER' and not space.use_filter_collection:
269             layout.operator("outliner.object_operation", text="Delete Hierarchy").type = 'DELETE_HIERARCHY'
270
271         layout.separator()
272
273         layout.operator("outliner.object_operation", text="Select", icon="RESTRICT_SELECT_OFF").type = 'SELECT'
274         layout.operator("outliner.object_operation", text="Select Hierarchy").type = 'SELECT_HIERARCHY'
275         layout.operator("outliner.object_operation", text="Deselect").type = 'DESELECT'
276
277         layout.separator()
278
279         if object_mode in {'EDIT', 'POSE'}:
280             name = bpy.types.Object.bl_rna.properties["mode"].enum_items[object_mode].name
281             layout.operator("outliner.object_operation", text=f"{name:s} Set").type = 'OBJECT_MODE_ENTER'
282             layout.operator("outliner.object_operation", text=f"{name:s} Clear").type = 'OBJECT_MODE_EXIT'
283             del name
284
285             layout.separator()
286
287         if not (space.display_mode == 'VIEW_LAYER' and not space.use_filter_collection):
288             layout.operator("outliner.id_operation", text="Unlink").type = 'UNLINK'
289             layout.separator()
290
291         layout.operator_menu_enum("outliner.id_operation", "type", text="ID Data")
292
293         layout.separator()
294
295         OUTLINER_MT_context.draw(self, context)
296
297
298 class OUTLINER_PT_filter(Panel):
299     bl_space_type = 'OUTLINER'
300     bl_region_type = 'HEADER'
301     bl_label = "Filter"
302
303     def draw(self, context):
304         layout = self.layout
305
306         space = context.space_data
307         display_mode = space.display_mode
308
309         layout.prop(space, "use_filter_complete", text="Exact Match Search")
310         layout.prop(space, "use_filter_case_sensitive", text="Case Sensitive Search")
311
312         layout.separator()
313
314         if display_mode != 'DATA_API':
315             layout.prop(space, "use_sort_alpha")
316             layout.prop(space, "show_restrict_columns")
317             layout.separator()
318
319         col = layout.column(align=True)
320
321         col.prop(space, "use_filter_collection", text="Collections", icon='GROUP')
322         col.prop(space, "use_filter_object", text="Objects", icon='OBJECT_DATAMODE')
323
324         sub = col.column(align=True)
325         sub.active = space.use_filter_object
326
327         if bpy.data.meshes:
328             sub.prop(space, "use_filter_object_mesh", text="Meshes", icon='MESH_DATA')
329         if bpy.data.armatures:
330             sub.prop(space, "use_filter_object_armature", text="Armatures", icon='ARMATURE_DATA')
331         if bpy.data.lights:
332             sub.prop(space, "use_filter_object_light", text="Lights", icon='LIGHT_DATA')
333         if bpy.data.cameras:
334             sub.prop(space, "use_filter_object_camera", text="Cameras", icon='CAMERA_DATA')
335
336         sub.prop(space, "use_filter_object_empty", text="Empties", icon='EMPTY_DATA')
337
338         if (
339                 bpy.data.curves or
340                 bpy.data.metaballs or
341                 bpy.data.lightprobes or
342                 bpy.data.lattices or
343                 bpy.data.fonts or
344                 bpy.data.speakers
345         ):
346             sub.prop(space, "use_filter_object_others", text="Others")
347
348         subsub = sub.column(align=False)
349         subsub.prop(space, "filter_state", text="")
350         subsub.prop(space, "use_filter_object_content", text="Object Contents")
351         subsub.prop(space, "use_filter_children", text="Object Children")
352
353
354 classes = (
355     OUTLINER_HT_header,
356     OUTLINER_MT_editor_menus,
357     OUTLINER_MT_edit_datablocks,
358     OUTLINER_MT_collection,
359     OUTLINER_MT_collection_duplicate,
360     OUTLINER_MT_collection_new,
361     OUTLINER_MT_collection_visibility,
362     OUTLINER_MT_collection_view_layer,
363     OUTLINER_MT_object,
364     OUTLINER_MT_context,
365     OUTLINER_MT_context_view,
366     OUTLINER_PT_filter,
367 )
368
369 if __name__ == "__main__":  # only for live edit.
370     from bpy.utils import register_class
371     for cls in classes:
372         register_class(cls)