1 # SPDX-FileCopyrightText: 2011 Ryan Inch
3 # SPDX-License-Identifier: GPL-2.0-or-later
8 importlib
.reload(internals
)
9 importlib
.reload(operator_utils
)
10 importlib
.reload(operators
)
12 importlib
.reload(preferences
)
15 from . import internals
16 from . import operator_utils
17 from . import operators
19 from . import preferences
22 from bpy
.app
.handlers
import persistent
23 from bpy
.types
import PropertyGroup
24 from bpy
.props
import (
34 class CollectionManagerProperties(PropertyGroup
):
35 cm_list_collection
: CollectionProperty(type=internals
.CMListCollection
)
36 cm_list_index
: IntProperty()
38 show_exclude
: BoolProperty(default
=True, name
="[EC] Exclude from View Layer")
39 show_selectable
: BoolProperty(default
=True, name
="[SS] Disable Selection")
40 show_hide_viewport
: BoolProperty(default
=True, name
="[VV] Hide in Viewport")
41 show_disable_viewport
: BoolProperty(default
=False, name
="[DV] Disable in Viewports")
42 show_render
: BoolProperty(default
=False, name
="[RR] Disable in Renders")
43 show_holdout
: BoolProperty(default
=False, name
="[HH] Holdout")
44 show_indirect_only
: BoolProperty(default
=False, name
="[IO] Indirect Only")
46 align_local_ops
: BoolProperty(default
=False, name
="Align Local Options",
47 description
="Align local options in a column to the right")
49 in_phantom_mode
: BoolProperty(default
=False)
51 update_header
: CollectionProperty(type=internals
.CMListCollection
)
53 ui_separator
: StringProperty(name
="", default
="")
55 qcd_slots_blend_data
: StringProperty()
59 addon_disable_objects_hotkey_keymaps
= []
62 internals
.CMListCollection
,
63 internals
.CMSendReport
,
64 internals
.CMUISeparatorButton
,
65 operators
.SetActiveCollection
,
66 operators
.ExpandAllOperator
,
67 operators
.ExpandSublevelOperator
,
68 operators
.CMExcludeOperator
,
69 operators
.CMUnExcludeAllOperator
,
70 operators
.CMRestrictSelectOperator
,
71 operators
.CMUnRestrictSelectAllOperator
,
72 operators
.CMHideOperator
,
73 operators
.CMUnHideAllOperator
,
74 operators
.CMDisableViewportOperator
,
75 operators
.CMUnDisableViewportAllOperator
,
76 operators
.CMDisableRenderOperator
,
77 operators
.CMUnDisableRenderAllOperator
,
78 operators
.CMHoldoutOperator
,
79 operators
.CMUnHoldoutAllOperator
,
80 operators
.CMIndirectOnlyOperator
,
81 operators
.CMUnIndirectOnlyAllOperator
,
82 operators
.CMNewCollectionOperator
,
83 operators
.CMRemoveCollectionOperator
,
84 operators
.CMRemoveEmptyCollectionsOperator
,
85 operators
.CMSelectCollectionObjectsOperator
,
86 operators
.SelectAllCumulativeObjectsOperator
,
87 operators
.CMSendObjectsToCollectionOperator
,
88 operators
.CMPhantomModeOperator
,
89 operators
.CMApplyPhantomModeOperator
,
90 operators
.CMDisableObjectsOperator
,
91 operators
.CMDisableUnSelectedObjectsOperator
,
92 operators
.CMRestoreDisabledObjectsOperator
,
93 operators
.CMUndoWrapper
,
94 operators
.CMRedoWrapper
,
95 preferences
.CMPreferences
,
98 ui
.CMDisplayOptionsPanel
,
100 CollectionManagerProperties
,
105 def depsgraph_update_post_handler(dummy
):
106 if internals
.move_triggered
:
107 internals
.move_triggered
= False
110 internals
.move_selection
.clear()
111 internals
.move_active
= None
114 def undo_redo_post_handler(dummy
):
115 internals
.move_selection
.clear()
116 internals
.move_active
= None
120 def global_load_pre_handler(dummy
):
121 internals
.move_triggered
= False
122 internals
.move_selection
.clear()
123 internals
.move_active
= None
126 def menu_addition(self
, context
):
129 layout
.operator('view3d.collection_manager')
131 if bpy
.context
.preferences
.addons
[__package__
].preferences
.enable_qcd
:
132 layout
.operator('view3d.qcd_move_widget')
136 def disable_objects_menu_addition(self
, context
):
137 preferences
= bpy
.context
.preferences
.addons
[__package__
].preferences
138 if preferences
.enable_disable_objects_override
:
141 layout
.operator('view3d.disable_selected_objects')
142 layout
.operator('view3d.disable_unselected_objects')
143 layout
.operator('view3d.restore_disabled_objects')
146 def register_disable_objects_hotkeys():
147 if addon_disable_objects_hotkey_keymaps
:
148 # guard to handle default value updates (mouse hover + backspace)
151 wm
= bpy
.context
.window_manager
152 if wm
.keyconfigs
.addon
: # not present when started with --background
153 km
= wm
.keyconfigs
.addon
.keymaps
.new(name
='Object Mode')
154 kmi
= km
.keymap_items
.new('view3d.disable_selected_objects', 'H', 'PRESS')
155 addon_disable_objects_hotkey_keymaps
.append((km
, kmi
))
157 km
= wm
.keyconfigs
.addon
.keymaps
.new(name
='Object Mode')
158 kmi
= km
.keymap_items
.new('view3d.disable_unselected_objects', 'H', 'PRESS', shift
=True)
159 addon_disable_objects_hotkey_keymaps
.append((km
, kmi
))
161 km
= wm
.keyconfigs
.addon
.keymaps
.new(name
='Object Mode')
162 kmi
= km
.keymap_items
.new('view3d.restore_disabled_objects', 'H', 'PRESS', alt
=True)
163 addon_disable_objects_hotkey_keymaps
.append((km
, kmi
))
165 def unregister_disable_objects_hotkeys():
166 # remove keymaps when disable objects hotkeys are deactivated
167 for km
, kmi
in addon_disable_objects_hotkey_keymaps
:
168 km
.keymap_items
.remove(kmi
)
169 addon_disable_objects_hotkey_keymaps
.clear()
174 bpy
.utils
.register_class(cls
)
176 bpy
.types
.Scene
.collection_manager
= PointerProperty(type=CollectionManagerProperties
)
178 # create the global menu hotkey
179 wm
= bpy
.context
.window_manager
180 if wm
.keyconfigs
.addon
: # not present when started with --background
181 km
= wm
.keyconfigs
.addon
.keymaps
.new(name
='Object Mode')
182 kmi
= km
.keymap_items
.new('view3d.collection_manager', 'M', 'PRESS')
183 addon_keymaps
.append((km
, kmi
))
185 # Add Collection Manager & QCD Move Widget to the Object->Collections menu
186 bpy
.types
.VIEW3D_MT_object_collection
.prepend(menu_addition
)
188 # Add Disable Object Operators to the Object->Show/Hide menu
189 bpy
.types
.VIEW3D_MT_object_showhide
.append(disable_objects_menu_addition
)
191 bpy
.app
.handlers
.depsgraph_update_post
.append(depsgraph_update_post_handler
)
192 bpy
.app
.handlers
.undo_post
.append(undo_redo_post_handler
)
193 bpy
.app
.handlers
.redo_post
.append(undo_redo_post_handler
)
194 bpy
.app
.handlers
.load_pre
.append(global_load_pre_handler
)
196 preferences
= bpy
.context
.preferences
.addons
[__package__
].preferences
197 if preferences
.enable_disable_objects_override
:
198 register_disable_objects_hotkeys()
201 preferences
= bpy
.context
.preferences
.addons
[__package__
].preferences
202 if preferences
.enable_disable_objects_override
:
203 unregister_disable_objects_hotkeys()
206 bpy
.utils
.unregister_class(cls
)
208 # Remove Collection Manager & QCD Move Widget from the Object->Collections menu
209 bpy
.types
.VIEW3D_MT_object_collection
.remove(menu_addition
)
211 # Remove Disable Object Operators to the Object->Show/Hide menu
212 bpy
.types
.VIEW3D_MT_object_showhide
.remove(disable_objects_menu_addition
)
214 bpy
.app
.handlers
.depsgraph_update_post
.remove(depsgraph_update_post_handler
)
215 bpy
.app
.handlers
.undo_post
.remove(undo_redo_post_handler
)
216 bpy
.app
.handlers
.redo_post
.remove(undo_redo_post_handler
)
217 bpy
.app
.handlers
.load_pre
.remove(global_load_pre_handler
)
219 del bpy
.types
.Scene
.collection_manager
221 # remove keymaps when add-on is deactivated
222 for km
, kmi
in addon_keymaps
:
223 km
.keymap_items
.remove(kmi
)
224 addon_keymaps
.clear()