Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-12-09 12:57:40 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-12-09 12:57:40 +0300
commitec6873e90f2d1e2765f85b58dfa6addeb2a592dd (patch)
tree3fc32258b929da3b8ec31e8e39b1eaf9d3ab08a0 /object_collection_manager/internals.py
parent14420434d2aa4c0c1d7897440e40f1656ea57de0 (diff)
Use "object" prefix for collection manager
This was defining it's own category, which should be avoided and isn't needed in this case since it manages object collections.
Diffstat (limited to 'object_collection_manager/internals.py')
-rw-r--r--object_collection_manager/internals.py107
1 files changed, 107 insertions, 0 deletions
diff --git a/object_collection_manager/internals.py b/object_collection_manager/internals.py
new file mode 100644
index 00000000..e898de1c
--- /dev/null
+++ b/object_collection_manager/internals.py
@@ -0,0 +1,107 @@
+from bpy.types import PropertyGroup
+from bpy.props import StringProperty
+
+layer_collections = {}
+
+collection_tree = []
+
+expanded = []
+
+max_lvl = 0
+row_index = 0
+
+def get_max_lvl():
+ return max_lvl
+
+def update_col_name(self, context):
+ if self.name != self.last_name:
+ if self.name == '':
+ self.name = self.last_name
+ return
+
+ if self.last_name != '':
+ layer_collections[self.last_name]["ptr"].collection.name = self.name
+
+ update_property_group(context)
+
+ self.last_name = self.name
+
+class CMListCollection(PropertyGroup):
+ name: StringProperty(update=update_col_name)
+ last_name: StringProperty()
+
+
+def update_collection_tree(context):
+ global max_lvl
+ global row_index
+ collection_tree.clear()
+ layer_collections.clear()
+ max_lvl = 0
+ row_index = 0
+
+ init_laycol_list = context.view_layer.layer_collection.children
+
+ master_laycol = {"id": 0,
+ "name": context.view_layer.layer_collection.name,
+ "lvl": -1,
+ "row_index": -1,
+ "visible": True,
+ "has_children": True,
+ "expanded": True,
+ "parent": None,
+ "children": [],
+ "ptr": context.view_layer.layer_collection
+ }
+
+ get_all_collections(context, init_laycol_list, master_laycol, collection_tree, visible=True)
+
+
+def get_all_collections(context, collections, parent, tree, level=0, visible=False):
+ global row_index
+
+ for item in collections:
+ laycol = {"id": len(layer_collections) +1,
+ "name": item.name,
+ "lvl": level,
+ "row_index": row_index,
+ "visible": visible,
+ "has_children": False,
+ "expanded": False,
+ "parent": parent,
+ "children": [],
+ "ptr": item
+ }
+
+ row_index += 1
+
+ layer_collections[item.name] = laycol
+ tree.append(laycol)
+
+ if len(item.children) > 0:
+ global max_lvl
+ max_lvl += 1
+ laycol["has_children"] = True
+
+ if item.name in expanded and laycol["visible"]:
+ laycol["expanded"] = True
+ get_all_collections(context, item.children, laycol, laycol["children"], level+1, visible=True)
+
+ else:
+ get_all_collections(context, item.children, laycol, laycol["children"], level+1)
+
+
+def update_property_group(context):
+ update_collection_tree(context)
+ context.scene.CMListCollection.clear()
+ create_property_group(context, collection_tree)
+
+
+def create_property_group(context, tree):
+ global in_filter
+
+ for laycol in tree:
+ new_cm_listitem = context.scene.CMListCollection.add()
+ new_cm_listitem.name = laycol["name"]
+
+ if laycol["has_children"]:
+ create_property_group(context, laycol["children"])