Import_3ds: Improved distance cue chunk import
[blender-addons.git] / object_collection_manager / cm_init.py
blob9a96967786b71656c51123d1cb40a485b93c73ce
1 # SPDX-FileCopyrightText: 2011 Ryan Inch
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 if "bpy" in locals():
6 import importlib
8 importlib.reload(internals)
9 importlib.reload(operator_utils)
10 importlib.reload(operators)
11 importlib.reload(ui)
12 importlib.reload(preferences)
14 else:
15 from . import internals
16 from . import operator_utils
17 from . import operators
18 from . import ui
19 from . import preferences
21 import bpy
22 from bpy.app.handlers import persistent
23 from bpy.types import PropertyGroup
24 from bpy.props import (
25 CollectionProperty,
26 EnumProperty,
27 IntProperty,
28 BoolProperty,
29 StringProperty,
30 PointerProperty,
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()
58 addon_keymaps = []
59 addon_disable_objects_hotkey_keymaps = []
61 classes = (
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,
96 ui.CM_UL_items,
97 ui.CollectionManager,
98 ui.CMDisplayOptionsPanel,
99 ui.SpecialsMenu,
100 CollectionManagerProperties,
104 @persistent
105 def depsgraph_update_post_handler(dummy):
106 if internals.move_triggered:
107 internals.move_triggered = False
108 return
110 internals.move_selection.clear()
111 internals.move_active = None
113 @persistent
114 def undo_redo_post_handler(dummy):
115 internals.move_selection.clear()
116 internals.move_active = None
119 @persistent
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):
127 layout = self.layout
129 layout.operator('view3d.collection_manager')
131 if bpy.context.preferences.addons[__package__].preferences.enable_qcd:
132 layout.operator('view3d.qcd_move_widget')
134 layout.separator()
136 def disable_objects_menu_addition(self, context):
137 preferences = bpy.context.preferences.addons[__package__].preferences
138 if preferences.enable_disable_objects_override:
139 layout = self.layout
140 layout.separator()
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)
149 return
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()
172 def register_cm():
173 for cls in classes:
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()
200 def unregister_cm():
201 preferences = bpy.context.preferences.addons[__package__].preferences
202 if preferences.enable_disable_objects_override:
203 unregister_disable_objects_hotkeys()
205 for cls in classes:
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()