[Bf-extensions-cvs] [39700063] blender-v2.83-release: Collection Manager: Fix QCD numeration. Task: T69577

Ryan Inch noreply at git.blender.org
Thu Apr 23 09:50:16 CEST 2020


Commit: 39700063154bf540ab3828d58469b530bf1a028b
Author: Ryan Inch
Date:   Thu Apr 23 03:47:20 2020 -0400
Branches: blender-v2.83-release
https://developer.blender.org/rBA39700063154bf540ab3828d58469b530bf1a028b

Collection Manager: Fix QCD numeration. Task: T69577

Fix auto-numeration missing slots.
Fix renumerate not starting at slot 1.
Fix name spelling and tooltips.

===================================================================

M	object_collection_manager/__init__.py
M	object_collection_manager/internals.py
M	object_collection_manager/qcd_operators.py

===================================================================

diff --git a/object_collection_manager/__init__.py b/object_collection_manager/__init__.py
index f4d5900d..3ee2b18e 100644
--- a/object_collection_manager/__init__.py
+++ b/object_collection_manager/__init__.py
@@ -22,7 +22,7 @@ bl_info = {
     "name": "Collection Manager",
     "description": "Manage collections and their objects",
     "author": "Ryan Inch",
-    "version": (2, 7, 12),
+    "version": (2, 7, 13),
     "blender": (2, 80, 0),
     "location": "View3D - Object Mode (Shortcut - M)",
     "warning": '',  # used for warning icon and text in addons panel
diff --git a/object_collection_manager/internals.py b/object_collection_manager/internals.py
index 1ad8038a..f3bcf37f 100644
--- a/object_collection_manager/internals.py
+++ b/object_collection_manager/internals.py
@@ -189,33 +189,68 @@ class QCDSlots():
             if not layer_collections.get(name, None):
                 qcd_slots.del_slot(name=name)
 
-    def auto_numerate(self, *, renumerate=False):
-        global max_lvl
-
+    def auto_numerate(self):
         if self.length() < 20:
-            lvl = 0
-            num = 1
-            while lvl <= max_lvl:
-                if num > 20:
+            laycol = bpy.context.view_layer.layer_collection
+
+            laycol_iter_list = list(laycol.children)
+            while laycol_iter_list:
+                layer_collection = laycol_iter_list.pop(0)
+                laycol_iter_list.extend(list(layer_collection.children))
+
+                if layer_collection.name in qcd_slots.overrides:
+                    continue
+
+                for x in range(20):
+                    if (not self.contains(idx=str(x+1)) and
+                        not self.contains(name=layer_collection.name)):
+                            self.add_slot(str(x+1), layer_collection.name)
+
+
+                if self.length() > 20:
+                    break
+
+    def renumerate(self, *, beginning=False):
+        if beginning:
+            self.clear_slots()
+            self.overrides.clear()
+
+        starting_laycol_name = self.get_name("1")
+        if starting_laycol_name:
+            laycol = layer_collections[starting_laycol_name]["parent"]["ptr"]
+
+        else:
+            laycol = bpy.context.view_layer.layer_collection
+            starting_laycol_name = laycol.children[0].name
+
+        self.clear_slots()
+        self.overrides.clear()
+
+        laycol_iter_list = []
+        for laycol in laycol.children:
+            if laycol.name == starting_laycol_name or laycol_iter_list:
+                laycol_iter_list.append(laycol)
+
+        while laycol_iter_list:
+            layer_collection = laycol_iter_list.pop(0)
+
+            for x in range(20):
+                if self.contains(name=layer_collection.name):
                     break
 
-                for laycol in layer_collections.values():
-                    if num > 20:
-                        break
+                if not self.contains(idx=f"{x+1}"):
+                        self.add_slot(f"{x+1}", layer_collection.name)
+
 
-                    if int(laycol["lvl"]) == lvl:
-                        if laycol["name"] in qcd_slots.overrides:
-                            if not renumerate:
-                                num += 1
-                            continue
+            laycol_iter_list.extend(list(layer_collection.children))
 
-                        if (not self.contains(idx=str(num)) and
-                            not self.contains(name=laycol["name"])):
-                                self.add_slot(str(num), laycol["name"])
+            if self.length() > 20:
+                break
 
-                        num += 1
 
-                lvl += 1
+        for laycol in layer_collections.values():
+            if not self.contains(name=laycol["name"]):
+                self.overrides.add(laycol["name"])
 
 qcd_slots = QCDSlots()
 
@@ -399,7 +434,7 @@ class CMListCollection(PropertyGroup):
     qcd_slot_idx: StringProperty(name="QCD Slot", update=update_qcd_slot)
 
 
-def update_collection_tree(context, *, renumerate_qcd=False):
+def update_collection_tree(context):
     global max_lvl
     global row_index
     global collection_tree
@@ -433,7 +468,7 @@ def update_collection_tree(context, *, renumerate_qcd=False):
 
     qcd_slots.update_qcd()
 
-    qcd_slots.auto_numerate(renumerate=renumerate_qcd)
+    qcd_slots.auto_numerate()
 
 
 def get_all_collections(context, collections, parent, tree, level=0, visible=False):
@@ -472,13 +507,13 @@ def get_all_collections(context, collections, parent, tree, level=0, visible=Fal
                 get_all_collections(context, item.children, laycol, laycol["children"], level+1)
 
 
-def update_property_group(context, *, renumerate_qcd=False):
+def update_property_group(context):
     global collection_tree
     global qcd_slots
 
     qcd_slots.allow_update = False
 
-    update_collection_tree(context, renumerate_qcd=renumerate_qcd)
+    update_collection_tree(context)
     context.scene.collection_manager.cm_list_collection.clear()
     create_property_group(context, collection_tree)
 
diff --git a/object_collection_manager/qcd_operators.py b/object_collection_manager/qcd_operators.py
index 9b47df8d..ba299a65 100644
--- a/object_collection_manager/qcd_operators.py
+++ b/object_collection_manager/qcd_operators.py
@@ -281,10 +281,11 @@ class ViewQCDSlot(Operator):
 
 
 class RenumerateQCDSlots(Operator):
-    bl_label = "Re-numerate QCD Slots"
+    bl_label = "Renumerate QCD Slots"
     bl_description = (
-        "Re-numerate QCD slots\n"
-        "  * Ctrl+LMB - Include collections marked by the user as non QCD slots"
+        "Renumerate QCD slots.\n"
+        "  * LMB - Renumerate starting from the slot designated 1.\n"
+        "  * Alt+LMB - Renumerate from the beginning"
         )
     bl_idname = "view3d.renumerate_qcd_slots"
     bl_options = {'REGISTER', 'UNDO'}
@@ -292,11 +293,14 @@ class RenumerateQCDSlots(Operator):
     def invoke(self, context, event):
         global qcd_slots
 
-        qcd_slots.clear_slots()
+        modifiers = get_modifiers(event)
+
+        if modifiers == {'alt'}:
+            qcd_slots.renumerate(beginning=True)
 
-        if event.ctrl:
-            qcd_slots.overrides.clear()
+        else:
+            qcd_slots.renumerate()
 
-        update_property_group(context, renumerate_qcd=True)
+        update_property_group(context)
 
         return {'FINISHED'}



More information about the Bf-extensions-cvs mailing list