[Bf-extensions-cvs] [f72fce5e] master: Collection Manager: Add to release. Task: T69577
Ryan Inch
noreply at git.blender.org
Mon Dec 9 06:53:47 CET 2019
Commit: f72fce5e82ff3b59227d5e665ee2ab5634711cff
Author: Ryan Inch
Date: Mon Dec 9 00:52:11 2019 -0500
Branches: master
https://developer.blender.org/rBAf72fce5e82ff3b59227d5e665ee2ab5634711cff
Collection Manager: Add to release. Task: T69577
===================================================================
A collection_manager/__init__.py
A collection_manager/internals.py
A collection_manager/operators.py
A collection_manager/ui.py
===================================================================
diff --git a/collection_manager/__init__.py b/collection_manager/__init__.py
new file mode 100644
index 00000000..75142a35
--- /dev/null
+++ b/collection_manager/__init__.py
@@ -0,0 +1,121 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+
+""" Copyright 2011 GPL licence applies"""
+
+bl_info = {
+ "name": "Collection Manager",
+ "description": "Manage collections and their objects",
+ "author": "Ryan Inch",
+ "version": (1,8,0),
+ "blender": (2, 80, 0),
+ "location": "View3D - Object Mode (Shortcut - M)",
+ "warning": '', # used for warning icon and text in addons panel
+ "wiki_url": "",
+ "category": "User Interface"}
+
+
+if "bpy" in locals():
+ import importlib
+
+ importlib.reload(internals)
+ importlib.reload(operators)
+ importlib.reload(ui)
+
+else:
+ from . import internals
+ from . import operators
+ from . import ui
+
+import bpy
+from bpy.props import (
+ CollectionProperty,
+ IntProperty,
+ BoolProperty,
+ )
+
+addon_keymaps = []
+
+classes = (
+ internals.CMListCollection,
+ operators.ExpandAllOperator,
+ operators.ExpandSublevelOperator,
+ operators.CMExcludeOperator,
+ operators.CMUnExcludeAllOperator,
+ operators.CMRestrictSelectOperator,
+ operators.CMUnRestrictSelectAllOperator,
+ operators.CMHideOperator,
+ operators.CMUnHideAllOperator,
+ operators.CMDisableViewportOperator,
+ operators.CMUnDisableViewportAllOperator,
+ operators.CMDisableRenderOperator,
+ operators.CMUnDisableRenderAllOperator,
+ operators.CMNewCollectionOperator,
+ operators.CMRemoveCollectionOperator,
+ operators.CMSetCollectionOperator,
+ operators.CMPhantomModeOperator,
+ ui.CM_UL_items,
+ ui.CollectionManager,
+ ui.CMRestrictionTogglesPanel,
+ )
+
+def register():
+ for cls in classes:
+ bpy.utils.register_class(cls)
+
+ bpy.types.Scene.CMListCollection = CollectionProperty(type=internals.CMListCollection)
+ bpy.types.Scene.CMListIndex = IntProperty(update=ui.update_selection)
+
+ bpy.types.Scene.show_exclude = BoolProperty(default=True, name="Exclude from View Layer")
+ bpy.types.Scene.show_selectable = BoolProperty(default=True, name="Selectable")
+ 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
+ wm = bpy.context.window_manager
+ km = wm.keyconfigs.addon.keymaps.new(name='Object Mode')
+ kmi = km.keymap_items.new('view3d.collection_manager', 'M', 'PRESS')
+ addon_keymaps.append((km, kmi))
+
+def unregister():
+ for cls in classes:
+ bpy.utils.unregister_class(cls)
+
+ del bpy.types.Scene.CMListCollection
+ del bpy.types.Scene.CMListIndex
+
+ del bpy.types.Scene.show_exclude
+ del bpy.types.Scene.show_selectable
+ del bpy.types.Scene.show_hideviewport
+ 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)
+ addon_keymaps.clear()
+
+if __name__ == "__main__":
+ register()
diff --git a/collection_manager/internals.py b/collection_manager/internals.py
new file mode 100644
index 00000000..e898de1c
--- /dev/null
+++ b/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"])
diff --git a/collection_manager/operators.py b/collection_manager/operators.py
new file mode 100644
index 00000000..84396e7e
--- /dev/null
+++ b/collection_manager/operators.py
@@ -0,0 +1,1210 @@
+import bpy
+from bpy.types import Operator
+from bpy.props import (
+ BoolProperty,
+ StringProperty,
+ IntProperty
+ )
+
+from .internals import *
+
+rto_history = {"exclude": {},
+ "exclude_all": {},
+ "select": {},
+ "select_all": {},
+ "hide": {},
+ "hide_all": {},
+ "disable": {},
+ "disable_all": {},
+ "render": {},
+ "render_all": {}
+ }
+
+class ExpandAllOperator(bpy.types.Operator):
+ '''Expand/Collapse all collections'''
+ bl_label = "Expand All Items"
+ bl_idname = "view3d.expand_all_items"
+ bl_options = {'REGISTER', 'UNDO'}
+
+ def execute(self, context):
+ if len(expanded) > 0:
+ expanded.clear()
+ else:
+ for laycol in layer_collections.values():
+ if laycol["ptr"].children:
+ expanded.append(laycol["name"])
+
+ # update tree view
+ update_property_group(context)
+
+ return {'FINISHED'}
+
+
+class ExpandSublevelOperator(bpy.types.Operator):
+ ''' * Shift-Click to expand/collapse all sublevels'''
+ bl_label = "Expand Sublevel Items"
+ bl_idname = "view3d.expand_sublevel"
+ bl_options = {'REGISTER', 'UNDO'}
+
+ expand: BoolProperty()
+ name: StringProperty()
+ index: IntProperty()
+
+ def invoke(self, context, event):
+ if event.shift:
+ # expand/collapse all subcollections
+ expand = None
+
+ # check whether to expand or collapse
+ if self.name in expanded:
+ expanded.remove(self.name)
+ expand = False
+ else:
+ expanded.append(self.name)
+ expand = True
+
+ # do expanding/collapsing
+ def loop(laycol):
+ for item in laycol.children:
+ if expand:
+ if not item.name in expanded:
+ expanded.append(item.name)
+ else:
+ if item.name in expanded:
+ expanded.remove(item.name)
+
+ if len(item.children) > 0:
+ loop(item)
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list