Commit 29ab8a6b authored by Ryan Inch's avatar Ryan Inch
Browse files

Collection Manager: Add Phantom Mode. Task: T69577

First attempt to mimic the restore on quit functionality
requested by Paul Kotelevets (1D_Inc).
parent c4e727c0
......@@ -23,7 +23,7 @@ bl_info = {
"name": "Collection Manager",
"description": "Manage collections and their objects",
"author": "Ryan Inch",
"version": (1,2,2),
"version": (1,3,0),
"blender": (2, 80, 0),
"location": "View3D - Object Mode (Shortcut - M)",
"warning": '', # used for warning icon and text in addons panel
......@@ -69,6 +69,7 @@ classes = (
operators.CMNewCollectionOperator,
operators.CMRemoveCollectionOperator,
operators.CMSetCollectionOperator,
operators.CMPhantomModeOperator,
ui.CM_UL_items,
ui.CollectionManager,
ui.CMRestrictionTogglesPanel,
......@@ -86,6 +87,8 @@ def register():
bpy.types.Scene.show_hideviewport = BoolProperty(default=True, name="Hide in Viewport")
bpy.types.Scene.show_disableviewport = BoolProperty(default=False, name="Disable in Viewports")
bpy.types.Scene.show_render = BoolProperty(default=False, name="Disable in Renders")
bpy.types.Scene.CM_Phantom_Mode = BoolProperty(default=False)
# create the global menu hotkey
......@@ -107,6 +110,8 @@ def unregister():
del bpy.types.Scene.show_disableviewport
del bpy.types.Scene.show_render
del bpy.types.Scene.CM_Phantom_Mode
# remove keymaps when add-on is deactivated
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
......
......@@ -13,6 +13,11 @@ row_index = 0
def get_max_lvl():
return max_lvl
def clone_list(l1, l2):
l1.clear()
for x in l2:
l1.append(x)
class CMListCollection(PropertyGroup):
name: StringProperty()
......
......@@ -825,3 +825,119 @@ class CMNewCollectionOperator(bpy.types.Operator):
disablerenderall_history.clear()
return {'FINISHED'}
phantom_history = {"view_layer": "",
"initial_state": {},
"excludeall_history": [],
"restrictselectall_history": [],
"hideall_history": [],
"disableviewall_history": [],
"disablerenderall_history": [],
"exclude_history": [],
"restrictselect_history": [],
"hide_history": [],
"disableview_history": [],
"disablerender_history": []
}
phantom_view_layer = []
class CMPhantomModeOperator(bpy.types.Operator):
'''Toggle Phantom Mode'''
bl_label = "Toggle Phantom Mode"
bl_idname = "view3d.toggle_phantom_mode"
def execute(self, context):
global phantom_history
scn = context.scene
# enter Phantom Mode
if not scn.CM_Phantom_Mode:
scn.CM_Phantom_Mode = True
# save current visibility state
phantom_history["view_layer"] = context.view_layer.name
laycol_iter_list = [context.view_layer.layer_collection.children]
while len(laycol_iter_list) > 0:
new_laycol_iter_list = []
for laycol_iter in laycol_iter_list:
for layer_collection in laycol_iter:
phantom_history["initial_state"][layer_collection.name] = {
"exclude": layer_collection.exclude,
"selectable": layer_collection.collection.hide_select,
"hide_viewport": layer_collection.hide_viewport,
"disable_viewport": layer_collection.collection.hide_viewport,
"renderable": layer_collection.collection.hide_render,
}
if len(layer_collection.children) > 0:
new_laycol_iter_list.append(layer_collection.children)
laycol_iter_list = new_laycol_iter_list
phantom_history["excludeall_history"] = excludeall_history[:]
phantom_history["restrictselectall_history"] = restrictselectall_history[:]
phantom_history["hideall_history"] = hideall_history[:]
phantom_history["disableviewall_history"] = disableviewall_history[:]
phantom_history["disablerenderall_history"] = disablerenderall_history[:]
phantom_history["exclude_history"] = exclude_history[:]
phantom_history["restrictselect_history"] = restrictselect_history[:]
phantom_history["hide_history"] = hide_history[:]
phantom_history["disableview_history"] = disableview_history[:]
phantom_history["disablerender_history"] = disablerender_history[:]
# return to normal mode
else:
laycol_iter_list = [context.view_layer.layer_collection.children]
while len(laycol_iter_list) > 0:
new_laycol_iter_list = []
for laycol_iter in laycol_iter_list:
for layer_collection in laycol_iter:
phantom_laycol = phantom_history["initial_state"][layer_collection.name]
layer_collection.exclude = \
phantom_laycol["exclude"]
layer_collection.collection.hide_select = \
phantom_laycol["selectable"]
layer_collection.hide_viewport = \
phantom_laycol["hide_viewport"]
layer_collection.collection.hide_viewport = \
phantom_laycol["disable_viewport"]
layer_collection.collection.hide_render = \
phantom_laycol["renderable"]
if len(layer_collection.children) > 0:
new_laycol_iter_list.append(layer_collection.children)
laycol_iter_list = new_laycol_iter_list
clone_list(excludeall_history, phantom_history["excludeall_history"])
clone_list(restrictselectall_history, phantom_history["restrictselectall_history"])
clone_list(hideall_history,phantom_history["hideall_history"])
clone_list(disableviewall_history, phantom_history["disableviewall_history"])
clone_list(disablerenderall_history, phantom_history["disablerenderall_history"])
clone_list(exclude_history, phantom_history["exclude_history"])
clone_list(restrictselect_history, phantom_history["restrictselect_history"])
clone_list(hide_history, phantom_history["hide_history"])
clone_list(disableview_history, phantom_history["disableview_history"])
clone_list(disablerender_history, phantom_history["disablerender_history"])
scn.CM_Phantom_Mode = False
return {'FINISHED'}
......@@ -13,6 +13,7 @@ from .operators import (
disableviewall_history,
disablerenderall_history,
rename,
phantom_history,
)
......@@ -105,6 +106,14 @@ class CollectionManager(Operator):
addcollec_row.operator("view3d.add_collection", text="Add SubCollection", icon='COLLECTION_NEW').child = True
phantom_row = layout.row()
toggle_text = "Disable " if scn.CM_Phantom_Mode else "Enable "
phantom_row.operator("view3d.toggle_phantom_mode", text=toggle_text+"Phantom Mode")
if scn.CM_Phantom_Mode:
view.enabled = False
addcollec_row.enabled = False
def execute(self, context):
wm = context.window_manager
......@@ -135,6 +144,13 @@ class CollectionManager(Operator):
except:
context.scene.CMListIndex = 0
if context.scene.CM_Phantom_Mode:
if set(layer_collections.keys()) != set(phantom_history["initial_state"].keys()):
context.scene.CM_Phantom_Mode = False
if context.view_layer.name != phantom_history["view_layer"]:
context.scene.CM_Phantom_Mode = False
return wm.invoke_popup(self, width=(400+(lvl*20)))
......@@ -237,6 +253,11 @@ class CM_UL_items(UIList):
rm_op = split.row()
rm_op.alignment = 'RIGHT'
rm_op.operator("view3d.remove_collection", text="", icon='X', emboss=False).collection_name = item.name
if scn.CM_Phantom_Mode:
name_row.enabled = False
row_setcol.enabled = False
rm_op.enabled = False
def filter_items(self, context, data, propname):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment