[Bf-extensions-cvs] [742fa200] master: mesh_snap_utilities_line: Update for changes in Blender

mano-wii noreply at git.blender.org
Mon Mar 18 19:51:23 CET 2019


Commit: 742fa2002ee416cddcc81e90ca8dbaa5ab520428
Author: mano-wii
Date:   Mon Mar 18 15:51:09 2019 -0300
Branches: master
https://developer.blender.org/rBA742fa2002ee416cddcc81e90ca8dbaa5ab520428

mesh_snap_utilities_line: Update for changes in Blender

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

M	mesh_snap_utilities_line/__init__.py
M	mesh_snap_utilities_line/common_classes.py
M	mesh_snap_utilities_line/common_utilities.py
M	mesh_snap_utilities_line/drawing_utilities.py
A	mesh_snap_utilities_line/keys.py
M	mesh_snap_utilities_line/navigation_ops.py
M	mesh_snap_utilities_line/op_line.py
M	mesh_snap_utilities_line/preferences.py
M	mesh_snap_utilities_line/snap_context_l/__init__.py
M	mesh_snap_utilities_line/widgets.py

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

diff --git a/mesh_snap_utilities_line/__init__.py b/mesh_snap_utilities_line/__init__.py
index 1080cd9b..7db59012 100644
--- a/mesh_snap_utilities_line/__init__.py
+++ b/mesh_snap_utilities_line/__init__.py
@@ -22,7 +22,7 @@
 bl_info = {
     "name": "Snap_Utilities_Line",
     "author": "Germano Cavalcante",
-    "version": (5, 9, 6),
+    "version": (5, 9, 8),
     "blender": (2, 80, 0),
     "location": "View3D > TOOLS > Line Tool",
     "description": "Extends Blender Snap controls",
@@ -35,11 +35,13 @@ if "bpy" in locals():
     importlib.reload(widgets)
     importlib.reload(preferences)
     importlib.reload(op_line)
+    importlib.reload(keys)
 else:
     from . import navigation_ops
     from . import widgets
     from . import preferences
     from . import op_line
+    from . import keys
 
 import bpy
 from bpy.utils.toolsystem import ToolDef
@@ -65,7 +67,8 @@ def tool_line():
     icons_dir = os.path.join(os.path.dirname(__file__), "icons")
 
     return dict(
-        text="Make Line",
+        idname="snap_utilities.line",
+        label="Make Line",
         description=(
             "Make Lines\n"
             "Connect them to split faces"
@@ -73,7 +76,7 @@ def tool_line():
         icon=os.path.join(icons_dir, "ops.mesh.snap_utilities_line"),
         widget="MESH_GGT_snap_point",
         #operator="mesh.snap_utilities_line",
-        keymap="3D View Tool: Edit Mesh, Make Line",
+        keymap=keys.km_tool_snap_utilities_line,
         draw_settings=draw_settings,
     )
 
@@ -81,16 +84,6 @@ def tool_line():
 # -----------------------------------------------------------------------------
 # Tool Registraion
 
-def km_3d_view_snap_tools(tool_mouse = 'LEFTMOUSE'):
-    return [(
-        tool_line.keymap[0],
-        {"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
-        {"items": [
-            ("mesh.snap_utilities_line", {"type": tool_mouse, "value": 'CLICK'},
-             {"properties": [("wait_for_input", False)]}),
-        ]},
-    )]
-
 
 def get_tool_list(space_type, context_mode):
     from bl_ui.space_toolsystem_common import ToolSelectPanelHelper
@@ -102,23 +95,12 @@ def register_snap_tools():
     tools = get_tool_list('VIEW_3D', 'EDIT_MESH')
 
     for index, tool in enumerate(tools, 1):
-        if isinstance(tool, ToolDef) and tool.text == "Measure":
+        if isinstance(tool, ToolDef) and tool.label == "Measure":
             break
 
     tools[:index] += None, tool_line
 
-    del tools, index
-
-    keyconfigs = bpy.context.window_manager.keyconfigs
-    kc_defaultconf = keyconfigs.get("blender")
-    kc_addonconf   = keyconfigs.get("blender addon")
-
-    keyconfig_data = km_3d_view_snap_tools()
-
-    # TODO: find the user defined tool_mouse.
-    from bl_keymap_utils.io import keyconfig_init_from_data
-    keyconfig_init_from_data(kc_defaultconf, keyconfig_data)
-    keyconfig_init_from_data(kc_addonconf, keyconfig_data)
+    del tools
 
 
 def unregister_snap_tools():
@@ -128,16 +110,35 @@ def unregister_snap_tools():
     tools.pop(index)
     tools.remove(tool_line)
 
-    del tools, index
+    del tools
+    del index
+
+
+def register_keymaps():
+    keyconfigs = bpy.context.window_manager.keyconfigs
+    kc_defaultconf = keyconfigs.default
+    kc_addonconf   = keyconfigs.addon
+
+    # TODO: find the user defined tool_mouse.
+    from bl_keymap_utils.io import keyconfig_init_from_data
+    keyconfig_init_from_data(kc_defaultconf, keys.generate_empty_snap_utilities_tools_keymaps())
+    keyconfig_init_from_data(kc_addonconf, keys.generate_snap_utilities_keymaps())
+
+    #snap_modalkeymap = kc_addonconf.keymaps.find(keys.km_snap_utilities_modal_keymap)
+    #snap_modalkeymap.assign("MESH_OT_snap_utilities_line")
 
+
+def unregister_keymaps():
     keyconfigs = bpy.context.window_manager.keyconfigs
     defaultmap = keyconfigs.get("blender").keymaps
     addonmap   = keyconfigs.get("blender addon").keymaps
 
-    for keyconfig_data in km_3d_view_snap_tools():
+    for keyconfig_data in keys.generate_snap_utilities_keymaps():
         km_name, km_args, km_content = keyconfig_data
-
         addonmap.remove(addonmap.find(km_name, **km_args))
+
+    for keyconfig_data in keys.generate_empty_snap_utilities_tools_keymaps():
+        km_name, km_args, km_content = keyconfig_data
         defaultmap.remove(defaultmap.find(km_name, **km_args))
 
 
@@ -158,9 +159,11 @@ def register():
         bpy.utils.register_class(cls)
 
     register_snap_tools()
+    register_keymaps()
 
 
 def unregister():
+    unregister_keymaps()
     unregister_snap_tools()
 
     for cls in reversed(classes):
diff --git a/mesh_snap_utilities_line/common_classes.py b/mesh_snap_utilities_line/common_classes.py
index c36216e0..8b433382 100644
--- a/mesh_snap_utilities_line/common_classes.py
+++ b/mesh_snap_utilities_line/common_classes.py
@@ -26,6 +26,17 @@ from .common_utilities import (
 
 
 class SnapNavigation():
+    __slots__ = (
+        'use_ndof',
+        '_rotate',
+        '_move',
+        '_zoom',
+        '_ndof_all',
+        '_ndof_orbit',
+        '_ndof_orbit_zoom',
+        '_ndof_pan')
+
+
     @staticmethod
     def debug_key(key):
         for member in dir(key):
@@ -93,10 +104,13 @@ class SnapNavigation():
 
         for key in self._zoom:
             if evkey == key[0:3]:
-                if snap_location and key[3]:
-                    bpy.ops.view3d.zoom_custom_target('INVOKE_DEFAULT', delta=key[3], target=snap_location)
+                if key[3]:
+                    if snap_location:
+                        bpy.ops.view3d.zoom_custom_target('INVOKE_DEFAULT', delta=key[3], target=snap_location)
+                    else:
+                        bpy.ops.view3d.zoom('INVOKE_DEFAULT', delta=key[3])
                 else:
-                    bpy.ops.view3d.zoom('INVOKE_DEFAULT', delta=key[3])
+                    bpy.ops.view3d.zoom('INVOKE_DEFAULT')
                 return True
 
         if self.use_ndof:
@@ -118,6 +132,13 @@ class SnapNavigation():
 
 
 class CharMap:
+    __slots__ = (
+        'unit_system',
+        'uinfo',
+        'length_entered',
+        'length_entered_value',
+        'line_pos')
+
     ascii = {
         ".", ",", "-", "+", "1", "2", "3",
         "4", "5", "6", "7", "8", "9", "0",
@@ -194,16 +215,26 @@ class CharMap:
 
 
 class SnapUtilities:
-#    __slots__ = (
-#        "sctx",
-#        "draw_cache",
-#        "outer_verts",
-#        "snap_face",
-#        "snap_to_grid",
-#        "unit_system",
-#        "rd",
-#        "incremental",
-#    )
+    """
+    __slots__ = (
+        "sctx",
+        "draw_cache",
+        "outer_verts",
+        "unit_system",
+        "rd",
+        "obj",
+        "bm",
+        "geom",
+        "type",
+        "location",
+        "preferences",
+        "normal",
+        "snap_vert",
+        "snap_edge",
+        "snap_face",
+        "incremental",
+    )
+    """
 
     constrain_keys = {
         'X': Vector((1,0,0)),
@@ -327,7 +358,6 @@ class SnapUtilities:
         else:
             #init these variables to avoid errors
             self.obj = context.active_object
-            self.bm = None
             self.geom = None
             self.type = 'OUT'
             self.location = Vector()
diff --git a/mesh_snap_utilities_line/common_utilities.py b/mesh_snap_utilities_line/common_utilities.py
index a6ecbdc9..c62968d5 100644
--- a/mesh_snap_utilities_line/common_utilities.py
+++ b/mesh_snap_utilities_line/common_utilities.py
@@ -148,16 +148,35 @@ def get_snap_bm_geom(sctx, main_snap_obj, mcursor):
     return r_snp_obj, r_loc, r_elem, r_elem_co, r_view_vector, r_orig, r_bm, r_bm_geom
 
 
-class SnapCache:
-    snp_obj = None
-    edge = None
+class SnapCache(object):
+    __slots__ = 'edge', 'face'
 
-    vmid = None
-    vperp = None
-    v2dmid = None
-    v2dperp = None
+    class Edge:
+        __slots__ = 'snp_obj', 'elem', 'vmid', 'vperp', 'v2dmid', 'v2dperp', 'is_increment'
 
-    is_increment = False
+        def __init__(self):
+            self.snp_obj = None
+            self.elem = None
+            self.vmid = None
+            self.vperp = None
+            self.v2dmid = None
+            self.v2dperp = None
+            self.is_increment = False
+
+    class Face:
+        __slots__ = 'bm_face', 'vmid', 'v2dmid'
+
+        def __init__(self):
+            self.bm_face = None
+
+    def __init__(self):
+        self.edge = self.Edge()
+        self.face = self.Face()
+
+    def clear(self):
+        self.edge.snp_obj = self.face.bm_face = None
+
+_snap_cache = SnapCache()
 
 
 def snap_utilities(
@@ -171,7 +190,7 @@ def snap_utilities(
 
     is_increment = False
     r_loc = None
-    r_type = None
+    r_type = 'OUT'
     r_len = 0.0
 
     if not snp_obj:
@@ -183,71 +202,89 @@ def snap_utilities(
                 t_loc = constrain
             r_loc = t_loc[0]
         else:
-            r_type = 'OUT'
             r_loc = out_Location(sctx.rv3d, orig, view_vector)
 
     elif len(elem) == 1:
         r_type = 'VERT'
+
         if constrain:
             r_loc = intersect_point_line(loc, constrain[0], constrain[1])[0]
         else:
             r_loc = loc
 
     elif len(elem) == 2:
-        if SnapCache.snp_obj is not snp_obj or not (elem == SnapCache.edge).all():
-            SnapCache.snp_obj = snp_obj
-            SnapCache.edge = elem
+        r_type = 'EDGE'
+
+        if _snap_cache.edge.snp_obj is not snp_obj or not (elem == _snap_cache.edge.elem).all():
+            _snap_cache.edge.snp_obj = snp_obj
+            _snap_cache.edge.elem = elem
 
             v0 = elem_co[0]
             v1 = elem_co[1]
-            SnapCache.vmid = 0.5 * (v0 + v1)
-            SnapCache.v2dmid = location_3d_to_region_2d(sctx.region, sctx.rv3d, SnapCache.vmid)
+            _snap_cache.edge.vmid = 0.5 * (v0 + v1)
+            _snap_cache.edge.v2dmid = location_3d_to_region_2d(
+                    sctx.region, sctx.rv3d, _snap_cache.edge.vmid)
 
             if previous_vert and (not bm_geom or previous_vert not in bm_geom.verts):
                 pvert_co = main_snap_obj.mat @ previous_vert.co
                 perp_point = intersect_point_line(pvert_co, v0, v1)
-                SnapCache.vperp = perp_point[0

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list