[Bf-extensions-cvs] [13892426] master: ui_layer_manager moved to contrib: T63750

meta-androcto noreply at git.blender.org
Fri May 24 01:55:39 CEST 2019


Commit: 138924263fe38f594f8bbd2366e0cf796beccbb9
Author: meta-androcto
Date:   Fri May 24 09:55:15 2019 +1000
Branches: master
https://developer.blender.org/rBAC138924263fe38f594f8bbd2366e0cf796beccbb9

ui_layer_manager moved to contrib: T63750

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

A	ui_layer_manager.py

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

diff --git a/ui_layer_manager.py b/ui_layer_manager.py
new file mode 100644
index 00000000..918ca5af
--- /dev/null
+++ b/ui_layer_manager.py
@@ -0,0 +1,674 @@
+# ##### 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 #####
+
+# <pep8 compliant>
+
+bl_info = {
+    "name": "Layer Management",
+    "author": "Alfonso Annarumma, Bastien Montagne",
+    "version": (1, 5, 5),
+    "blender": (2, 79, 0),
+    "location": "Toolshelf > Layers Tab",
+    "warning": "",
+    "description": "Display and Edit Layer Name",
+    "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
+                "Scripts/3D_interaction/layer_manager",
+    "category": "3D View",
+}
+
+import bpy
+from bpy.types import (
+        Operator,
+        Panel,
+        UIList,
+        PropertyGroup,
+        AddonPreferences,
+        )
+from bpy.props import (
+        StringProperty,
+        BoolProperty,
+        IntProperty,
+        CollectionProperty,
+        BoolVectorProperty,
+        PointerProperty,
+        )
+from bpy.app.handlers import persistent
+
+EDIT_MODES = {'EDIT_MESH', 'EDIT_CURVE', 'EDIT_SURFACE', 'EDIT_METABALL', 'EDIT_TEXT', 'EDIT_ARMATURE'}
+
+NUM_LAYERS = 20
+
+FAKE_LAYER_GROUP = [True] * NUM_LAYERS
+
+
+class NamedLayer(PropertyGroup):
+    name: StringProperty(
+            name="Layer Name"
+            )
+    use_lock: BoolProperty(
+            name="Lock Layer",
+            default=False
+            )
+    use_object_select: BoolProperty(
+            name="Object Select",
+            default=True
+            )
+    use_wire: BoolProperty(
+            name="Wire Layer",
+            default=False
+            )
+
+
+class NamedLayers(PropertyGroup):
+    layers: CollectionProperty(type=NamedLayer)
+
+    use_hide_empty_layers: BoolProperty(
+            name="Hide Empty Layer",
+            default=False
+            )
+    use_extra_options: BoolProperty(
+            name="Show Extra Options",
+            default=True
+            )
+    use_layer_indices: BoolProperty(
+            name="Show Layer Indices",
+            default=False
+            )
+    use_classic: BoolProperty(
+            name="Classic",
+            default=False,
+            description="Use a classic layer selection visibility"
+            )
+    use_init: BoolProperty(
+            default=True,
+            options={'HIDDEN'}
+            )
+
+
+# Stupid, but only solution currently is to use a handler to init that layers collection...
+ at persistent
+def check_init_data(scene):
+    namedlayers = scene.namedlayers
+    if namedlayers.use_init:
+        while namedlayers.layers:
+            namedlayers.layers.remove(0)
+        for i in range(NUM_LAYERS):
+            layer = namedlayers.layers.add()
+            layer.name = "Layer%.2d" % (i + 1)  # Blender use layer nums starting from 1, not 0.
+        namedlayers.use_init = False
+
+
+class LayerGroup(PropertyGroup):
+    use_toggle: BoolProperty(name="", default=False)
+    use_wire: BoolProperty(name="", default=False)
+    use_lock: BoolProperty(name="", default=False)
+
+    layers = BoolVectorProperty(name="Layers", default=([False] * NUM_LAYERS), size=NUM_LAYERS, subtype='LAYER')
+
+
+class SCENE_OT_namedlayer_group_add(Operator):
+    """Add and select a new layer group"""
+    bl_idname = "scene.namedlayer_group_add"
+    bl_label = "Add Layer Group"
+
+    layers = BoolVectorProperty(name="Layers", default=([False] * NUM_LAYERS), size=NUM_LAYERS)
+
+    @classmethod
+    def poll(cls, context):
+        return bool(context.scene)
+
+    def execute(self, context):
+        scene = context.scene
+        layergroups = scene.layergroups
+        layers = self.layers
+
+        group_idx = len(layergroups)
+        layer_group = layergroups.add()
+        layer_group.name = "LayerGroup.%.3d" % group_idx
+        layer_group.layers = layers
+        scene.layergroups_index = group_idx
+
+        return {'FINISHED'}
+
+
+class SCENE_OT_namedlayer_group_remove(Operator):
+    """Remove selected layer group"""
+    bl_idname = "scene.namedlayer_group_remove"
+    bl_label = "Remove Layer Group"
+
+    group_idx: bpy.props.IntProperty()
+
+    @classmethod
+    def poll(cls, context):
+        return bool(context.scene)
+
+    def execute(self, context):
+        scene = context.scene
+        group_idx = self.group_idx
+
+        scene.layergroups.remove(group_idx)
+        if scene.layergroups_index > len(scene.layergroups) - 1:
+            scene.layergroups_index = len(scene.layergroups) - 1
+
+        return {'FINISHED'}
+
+
+class SCENE_OT_namedlayer_toggle_visibility(Operator):
+    """Show or hide given layer (shift to extend)"""
+    bl_idname = "scene.namedlayer_toggle_visibility"
+    bl_label = "Show/Hide Layer"
+
+    layer_idx: IntProperty()
+    group_idx: IntProperty()
+    use_spacecheck: BoolProperty()
+    extend: BoolProperty(options={'SKIP_SAVE'})
+
+    @classmethod
+    def poll(cls, context):
+        return context.scene and (context.area.spaces.active.type == 'VIEW_3D')
+
+    def execute(self, context):
+        scene = context.scene
+        layer_cont = context.area.spaces.active if self.use_spacecheck else context.scene
+        layer_idx = self.layer_idx
+
+        if layer_idx == -1:
+            group_idx = self.group_idx
+            layergroups = scene.layergroups[group_idx]
+            group_layers = layergroups.layers
+            layers = layer_cont.layers
+
+            if layergroups.use_toggle:
+                layer_cont.layers = [not group_layer and layer for group_layer, layer in zip(group_layers, layers)]
+                layergroups.use_toggle = False
+            else:
+                layer_cont.layers = [group_layer or layer for group_layer, layer in zip(group_layers, layers)]
+                layergroups.use_toggle = True
+        else:
+            if self.extend:
+                layer_cont.layers[layer_idx] = not layer_cont.layers[layer_idx]
+            else:
+                layers = [False] * NUM_LAYERS
+                layers[layer_idx] = True
+                layer_cont.layers = layers
+        return {'FINISHED'}
+
+    def invoke(self, context, event):
+        self.extend = event.shift
+        return self.execute(context)
+
+
+class SCENE_OT_namedlayer_move_to_layer(Operator):
+    """Move selected objects to this Layer (shift to extend)"""
+    bl_idname = "scene.namedlayer_move_to_layer"
+    bl_label = "Move Objects To Layer"
+
+    layer_idx: IntProperty()
+    extend: BoolProperty(options={'SKIP_SAVE'})
+
+    @classmethod
+    def poll(cls, context):
+        return context.scene
+
+    def execute(self, context):
+        layer_idx = self.layer_idx
+        scene = context.scene
+
+        # Cycle all objects in the layer
+        for obj in scene.objects:
+            if obj.select_get():
+                # If object is in at least one of the scene's visible layers...
+                if True in {ob_layer and sce_layer for ob_layer, sce_layer in zip(obj.layers, scene.layers)}:
+                    if self.extend:
+                        obj.layers[layer_idx] = not obj.layers[layer_idx]
+                    else:
+                        layer = [False] * NUM_LAYERS
+                        layer[layer_idx] = True
+                        obj.layers = layer
+        return {'FINISHED'}
+
+    def invoke(self, context, event):
+        self.extend = event.shift
+        return self.execute(context)
+
+
+class SCENE_OT_namedlayer_toggle_wire(Operator):
+    """Toggle all objects on this layer draw as wire"""
+    bl_idname = "scene.namedlayer_toggle_wire"
+    bl_label = "Toggle Objects Draw Wire"
+
+    layer_idx: IntProperty()
+    use_wire: BoolProperty()
+    group_idx: IntProperty()
+
+    @classmethod
+    def poll(cls, context):
+        return context.scene and (context.area.spaces.active.type == 'VIEW_3D')
+
+    def execute(self, context):
+        scene = context.scene
+        layer_idx = self.layer_idx
+        use_wire = self.use_wire
+
+        view_3d = context.area.spaces.active
+
+        # Check if layer have some thing
+        if view_3d.layers_used[layer_idx] or layer_idx == -1:
+            display = 'WIRE' if use_wire else 'TEXTURED'
+            # Cycle all objects in the layer.
+            for obj in context.scene.objects:
+                if layer_idx == -1:
+                    group_idx = self.group_idx
+                    group_layers = scene.layergroups[group_idx].layers
+                    layers = obj.layers
+                    if True in {layer and group_layer for layer, group_layer in zip(layers, group_layers)}:
+                        obj.display_type = display
+                        scene.layergroups[group_idx].use_wire = use_wire
+                else:
+                    if obj.layers[layer_idx]:
+                        obj.display_type = display
+                        scene.namedlayers.layers[layer_idx].use_wire = use_wire
+
+        return {'FINISHED'}
+
+
+class SCENE_OT_namedlayer_lock_all(Operator):
+    """Lock all objects on this layer"""
+    bl_idname = "scene.namedlayer_lock_all"
+    bl_label = "Lock Objects"
+
+    layer_idx: IntProperty()
+    use_lock: BoolProperty()
+    group_idx: IntProperty()
+
+    @classmethod
+    def poll(cls, context):
+        return context.scene and (context.area.spaces.active.type == 'VIEW_3D')
+
+    def execute(self, context):
+        scene = context.scene
+        view_3d = context.area.spac

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list