Collection Manager: Prevent invalid states. Task: T69577
Fixed bug with Phantom Mode state checking. Fixed bug with copy/swap buffers getting stuck if state invalidated. Add checks on collection manager popup to verify RTO history and copy/swap buffer states.
This commit is contained in:
parent
9a32e84135
commit
507c04aa72
|
@ -22,7 +22,7 @@ bl_info = {
|
|||
"name": "Collection Manager",
|
||||
"description": "Manage collections and their objects",
|
||||
"author": "Ryan Inch",
|
||||
"version": (2,4,10),
|
||||
"version": (2,4,11),
|
||||
"blender": (2, 80, 0),
|
||||
"location": "View3D - Object Mode (Shortcut - M)",
|
||||
"warning": '', # used for warning icon and text in addons panel
|
||||
|
|
|
@ -34,6 +34,7 @@ from bpy.props import (
|
|||
|
||||
layer_collections = {}
|
||||
collection_tree = []
|
||||
collection_state = {}
|
||||
expanded = []
|
||||
row_index = 0
|
||||
|
||||
|
@ -356,6 +357,29 @@ def get_modifiers(event):
|
|||
|
||||
return set(modifiers)
|
||||
|
||||
def generate_state():
|
||||
global layer_collections
|
||||
|
||||
state = {
|
||||
"name": [],
|
||||
"exclude": [],
|
||||
"select": [],
|
||||
"hide": [],
|
||||
"disable": [],
|
||||
"render": [],
|
||||
}
|
||||
|
||||
for name, laycol in layer_collections.items():
|
||||
state["name"].append(name)
|
||||
state["exclude"].append(laycol["ptr"].exclude)
|
||||
state["select"].append(laycol["ptr"].collection.hide_select)
|
||||
state["hide"].append(laycol["ptr"].hide_viewport)
|
||||
state["disable"].append(laycol["ptr"].collection.hide_viewport)
|
||||
state["render"].append(laycol["ptr"].collection.hide_render)
|
||||
|
||||
return state
|
||||
|
||||
|
||||
|
||||
class CMSendReport(Operator):
|
||||
bl_label = "Send Report"
|
||||
|
|
|
@ -461,9 +461,6 @@ class CMUnExcludeAllOperator(Operator):
|
|||
copy_buffer["values"].append(laycol["ptr"].exclude)
|
||||
|
||||
else:
|
||||
if len(copy_buffer["values"]) != len(layer_collections):
|
||||
return {'CANCELLED'}
|
||||
|
||||
# paste
|
||||
for x, laycol in enumerate(layer_collections.values()):
|
||||
laycol["ptr"].exclude = copy_buffer["values"][x]
|
||||
|
@ -482,9 +479,6 @@ class CMUnExcludeAllOperator(Operator):
|
|||
swap_buffer["A"]["values"].append(laycol["ptr"].exclude)
|
||||
|
||||
else:
|
||||
if len(swap_buffer["A"]["values"]) != len(layer_collections):
|
||||
return {'CANCELLED'}
|
||||
|
||||
# get B
|
||||
swap_buffer["B"]["RTO"] = "exclude"
|
||||
for laycol in layer_collections.values():
|
||||
|
@ -793,9 +787,6 @@ class CMUnRestrictSelectAllOperator(Operator):
|
|||
copy_buffer["values"].append(laycol["ptr"].collection.hide_select)
|
||||
|
||||
else:
|
||||
if len(copy_buffer["values"]) != len(layer_collections):
|
||||
return {'CANCELLED'}
|
||||
|
||||
# paste
|
||||
for x, laycol in enumerate(layer_collections.values()):
|
||||
laycol["ptr"].collection.hide_select = copy_buffer["values"][x]
|
||||
|
@ -814,9 +805,6 @@ class CMUnRestrictSelectAllOperator(Operator):
|
|||
swap_buffer["A"]["values"].append(laycol["ptr"].collection.hide_select)
|
||||
|
||||
else:
|
||||
if len(swap_buffer["A"]["values"]) != len(layer_collections):
|
||||
return {'CANCELLED'}
|
||||
|
||||
# get B
|
||||
swap_buffer["B"]["RTO"] = "collection.hide_select"
|
||||
for laycol in layer_collections.values():
|
||||
|
@ -1121,9 +1109,6 @@ class CMUnHideAllOperator(Operator):
|
|||
copy_buffer["values"].append(laycol["ptr"].hide_viewport)
|
||||
|
||||
else:
|
||||
if len(copy_buffer["values"]) != len(layer_collections):
|
||||
return {'CANCELLED'}
|
||||
|
||||
# paste
|
||||
for x, laycol in enumerate(layer_collections.values()):
|
||||
laycol["ptr"].hide_viewport = copy_buffer["values"][x]
|
||||
|
@ -1142,9 +1127,6 @@ class CMUnHideAllOperator(Operator):
|
|||
swap_buffer["A"]["values"].append(laycol["ptr"].hide_viewport)
|
||||
|
||||
else:
|
||||
if len(swap_buffer["A"]["values"]) != len(layer_collections):
|
||||
return {'CANCELLED'}
|
||||
|
||||
# get B
|
||||
swap_buffer["B"]["RTO"] = "hide_viewport"
|
||||
for laycol in layer_collections.values():
|
||||
|
@ -1447,9 +1429,6 @@ class CMUnDisableViewportAllOperator(Operator):
|
|||
copy_buffer["values"].append(laycol["ptr"].collection.hide_viewport)
|
||||
|
||||
else:
|
||||
if len(copy_buffer["values"]) != len(layer_collections):
|
||||
return {'CANCELLED'}
|
||||
|
||||
# paste
|
||||
for x, laycol in enumerate(layer_collections.values()):
|
||||
laycol["ptr"].collection.hide_viewport = copy_buffer["values"][x]
|
||||
|
@ -1468,9 +1447,6 @@ class CMUnDisableViewportAllOperator(Operator):
|
|||
swap_buffer["A"]["values"].append(laycol["ptr"].collection.hide_viewport)
|
||||
|
||||
else:
|
||||
if len(swap_buffer["A"]["values"]) != len(layer_collections):
|
||||
return {'CANCELLED'}
|
||||
|
||||
# get B
|
||||
swap_buffer["B"]["RTO"] = "collection.hide_viewport"
|
||||
for laycol in layer_collections.values():
|
||||
|
@ -1776,9 +1752,6 @@ class CMUnDisableRenderAllOperator(Operator):
|
|||
copy_buffer["values"].append(laycol["ptr"].collection.hide_render)
|
||||
|
||||
else:
|
||||
if len(copy_buffer["values"]) != len(layer_collections):
|
||||
return {'CANCELLED'}
|
||||
|
||||
# paste
|
||||
for x, laycol in enumerate(layer_collections.values()):
|
||||
laycol["ptr"].collection.hide_render = copy_buffer["values"][x]
|
||||
|
@ -1797,9 +1770,6 @@ class CMUnDisableRenderAllOperator(Operator):
|
|||
swap_buffer["A"]["values"].append(laycol["ptr"].collection.hide_render)
|
||||
|
||||
else:
|
||||
if len(swap_buffer["A"]["values"]) != len(layer_collections):
|
||||
return {'CANCELLED'}
|
||||
|
||||
# get B
|
||||
swap_buffer["B"]["RTO"] = "collection.hide_render"
|
||||
for laycol in layer_collections.values():
|
||||
|
|
|
@ -28,12 +28,14 @@ from bpy.props import BoolProperty
|
|||
|
||||
from .internals import (
|
||||
collection_tree,
|
||||
collection_state,
|
||||
expanded,
|
||||
get_max_lvl,
|
||||
layer_collections,
|
||||
qcd_slots,
|
||||
update_collection_tree,
|
||||
update_property_group,
|
||||
generate_state,
|
||||
)
|
||||
|
||||
from .operators import (
|
||||
|
@ -260,14 +262,49 @@ class CollectionManager(Operator):
|
|||
except KeyError: # Master Collection isn't supported
|
||||
cm.cm_list_index = -1
|
||||
|
||||
# check if history/buffer state still correct
|
||||
if collection_state:
|
||||
new_state = generate_state()
|
||||
|
||||
if new_state["name"] != collection_state["name"]:
|
||||
copy_buffer["RTO"] = ""
|
||||
copy_buffer["values"].clear()
|
||||
|
||||
swap_buffer["A"]["RTO"] = ""
|
||||
swap_buffer["A"]["values"].clear()
|
||||
swap_buffer["B"]["RTO"] = ""
|
||||
swap_buffer["B"]["values"].clear()
|
||||
|
||||
for rto, history in rto_history.items():
|
||||
if view_layer.name in history:
|
||||
del history[view_layer.name]
|
||||
|
||||
|
||||
else:
|
||||
for rto in ["exclude", "select", "hide", "disable", "render"]:
|
||||
if new_state[rto] != collection_state[rto]:
|
||||
if view_layer.name in rto_history[rto]:
|
||||
del rto_history[rto][view_layer.name]
|
||||
|
||||
if view_layer.name in rto_history[rto+"_all"]:
|
||||
del rto_history[rto+"_all"][view_layer.name]
|
||||
|
||||
# check if in phantom mode and if it's still viable
|
||||
if cm.in_phantom_mode:
|
||||
if set(layer_collections.keys()) != set(phantom_history["initial_state"].keys()):
|
||||
if layer_collections.keys() != phantom_history["initial_state"].keys():
|
||||
cm.in_phantom_mode = False
|
||||
|
||||
if view_layer.name != phantom_history["view_layer"]:
|
||||
cm.in_phantom_mode = False
|
||||
|
||||
if not cm.in_phantom_mode:
|
||||
for key, value in phantom_history.items():
|
||||
try:
|
||||
value.clear()
|
||||
except AttributeError:
|
||||
if key == "view_layer":
|
||||
phantom_history["view_layer"] = ""
|
||||
|
||||
# handle window sizing
|
||||
max_width = 960
|
||||
min_width = 456
|
||||
|
@ -285,6 +322,12 @@ class CollectionManager(Operator):
|
|||
|
||||
return wm.invoke_popup(self, width=width)
|
||||
|
||||
def __del__(self):
|
||||
global collection_state
|
||||
|
||||
collection_state.clear()
|
||||
collection_state.update(generate_state())
|
||||
|
||||
|
||||
class CM_UL_items(UIList):
|
||||
last_filter_value = ""
|
||||
|
|
Loading…
Reference in New Issue