space_outliner.py 14 KB

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