From 09133c5abdc1236ea61a98e68a0f23ba3503b472 Mon Sep 17 00:00:00 2001 From: Ryan Inch Date: Wed, 22 Jul 2020 02:44:42 -0400 Subject: Collection Manager: Update QCD Renumbering. Task: T69577 Added a linear renumbering option. Added a constrain to branch option. Allowed all options to be combined with each other. Updated tooltip. --- object_collection_manager/__init__.py | 2 +- object_collection_manager/internals.py | 55 +++++++++++++++++++----------- object_collection_manager/qcd_operators.py | 27 ++++++++++----- 3 files changed, 55 insertions(+), 29 deletions(-) diff --git a/object_collection_manager/__init__.py b/object_collection_manager/__init__.py index 90783e7e..04422b84 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, 10, 0), + "version": (2, 11, 0), "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 8e0c5b90..8a225443 100644 --- a/object_collection_manager/internals.py +++ b/object_collection_manager/internals.py @@ -210,46 +210,63 @@ class QCDSlots(): if self.length() > 20: break - def renumerate(self, *, depth_first=False, beginning=False): + def renumerate(self, *, beginning=False, depth_first=False, constrain=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: + if not starting_laycol_name: 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) + if depth_first: + parent = layer_collections[starting_laycol_name]["parent"] + x = 1 + + for laycol in layer_collections.values(): + if self.length() == 0 and starting_laycol_name != laycol["name"]: + continue + + if constrain: + if self.length(): + if laycol["parent"]["name"] == parent["name"]: + break - while laycol_iter_list: - layer_collection = laycol_iter_list.pop(0) + self.add_slot(f"{x}", laycol["name"]) - for x in range(20): - if self.contains(name=layer_collection.name): + x += 1 + + if self.length() > 20: break - if not self.contains(idx=f"{x+1}"): - self.add_slot(f"{x+1}", layer_collection.name) + else: + laycol = layer_collections[starting_laycol_name]["parent"]["ptr"] + laycol_iter_list = [] + for laycol in laycol.children: + if laycol.name == starting_laycol_name: + laycol_iter_list.append(laycol) - if depth_first: - laycol_iter_list[0:0] = list(layer_collection.children) + elif not constrain and laycol_iter_list: + laycol_iter_list.append(laycol) + + x = 1 + while laycol_iter_list: + layer_collection = laycol_iter_list.pop(0) + + self.add_slot(f"{x}", layer_collection.name) - else: laycol_iter_list.extend(list(layer_collection.children)) - if self.length() > 20: - break + x += 1 + + if self.length() > 20: + break for laycol in layer_collections.values(): diff --git a/object_collection_manager/qcd_operators.py b/object_collection_manager/qcd_operators.py index 7330dd0f..56df1501 100644 --- a/object_collection_manager/qcd_operators.py +++ b/object_collection_manager/qcd_operators.py @@ -287,9 +287,10 @@ class RenumerateQCDSlots(Operator): bl_label = "Renumber QCD Slots" bl_description = ( "Renumber QCD slots.\n" - " * LMB - Renumber (breadth first) starting from the slot designated 1.\n" - " * Ctrl+LMB - Renumber (depth first) starting from the slot designated 1.\n" - " * Alt+LMB - Renumber from the beginning" + " * LMB - Renumber (breadth first) from slot 1.\n" + " * +Ctrl - Linear.\n" + " * +Alt - Reset.\n" + " * +Shift - Constrain to branch" ) bl_idname = "view3d.renumerate_qcd_slots" bl_options = {'REGISTER', 'UNDO'} @@ -299,14 +300,22 @@ class RenumerateQCDSlots(Operator): modifiers = get_modifiers(event) - if modifiers == {'alt'}: - qcd_slots.renumerate(beginning=True) + beginning = False + depth_first = False + constrain = False - elif modifiers == {'ctrl'}: - qcd_slots.renumerate(depth_first=True) + if 'alt' in modifiers: + beginning=True - else: - qcd_slots.renumerate() + if 'ctrl' in modifiers: + depth_first=True + + if 'shift' in modifiers: + constrain=True + + qcd_slots.renumerate(beginning=beginning, + depth_first=depth_first, + constrain=constrain) update_property_group(context) -- cgit v1.2.3