[Bf-extensions-cvs] [1142e215] master: mesh_snap_utilties_line: Add Gizmos support

mano-wii noreply at git.blender.org
Wed Feb 6 07:15:04 CET 2019


Commit: 1142e215758f00714a139769d9ff6af35da0fa6c
Author: mano-wii
Date:   Wed Feb 6 03:13:10 2019 -0200
Branches: master
https://developer.blender.org/rBA1142e215758f00714a139769d9ff6af35da0fa6c

mesh_snap_utilties_line: Add Gizmos support

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

M	mesh_snap_utilities_line/__init__.py
M	mesh_snap_utilities_line/common_classes.py
R076	mesh_snap_utilities_line/icons/ops.mesh.make_line.dat	mesh_snap_utilities_line/icons/ops.mesh.snap_utilities_line.dat
M	mesh_snap_utilities_line/ops_line.py
M	mesh_snap_utilities_line/snap_context_l/__init__.py

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

diff --git a/mesh_snap_utilities_line/__init__.py b/mesh_snap_utilities_line/__init__.py
index 58511339..0ce402b5 100644
--- a/mesh_snap_utilities_line/__init__.py
+++ b/mesh_snap_utilities_line/__init__.py
@@ -22,37 +22,40 @@
 bl_info = {
     "name": "Snap_Utilities_Line",
     "author": "Germano Cavalcante",
-    "version": (5, 8, 30),
+    "version": (5, 9, 00),
     "blender": (2, 80, 0),
-    "location": "View3D > TOOLS > Make Line",
+    "location": "View3D > TOOLS > Line Tool",
     "description": "Extends Blender Snap controls",
     #"wiki_url" : "http://blenderartists.org/forum/showthread.php?363859-Addon-CAD-Snap-Utilities",
     "category": "Mesh"}
 
 if "bpy" in locals():
     import importlib
+    importlib.reload(common_classes)
     importlib.reload(preferences)
     importlib.reload(ops_line)
-    importlib.reload(common_classes)
 else:
+    from . import common_classes
     from . import preferences
     from . import ops_line
 
 import bpy
 from bpy.utils.toolsystem import ToolDef
 
+if not __package__:
+    __package__ = "mesh_snap_utilities_line"
+
 @ToolDef.from_fn
-def tool_make_line():
+def tool_line():
     import os
     def draw_settings(context, layout, tool):
-        addon_prefs = context.preferences.addons["mesh_snap_utilities_line"].preferences
+        addon_prefs = context.preferences.addons[__package__].preferences
 
         layout.prop(addon_prefs, "incremental")
         layout.prop(addon_prefs, "increments_grid")
-        if addon_prefs.increments_grid:
-            layout.prop(addon_prefs, "relative_scale")
         layout.prop(addon_prefs, "create_face")
-        layout.prop(addon_prefs, "outer_verts")
+        if context.mode == 'EDIT_MESH':
+            layout.prop(addon_prefs, "outer_verts")
         #props = tool.operator_properties("mesh.snap_utilities_line")
         #layout.prop(props, "radius")
 
@@ -64,9 +67,9 @@ def tool_make_line():
             "Make Lines\n"
             "Connect them to split faces"
         ),
-        icon=os.path.join(icons_dir, "ops.mesh.make_line"),
-        #widget="MESH_GGT_mouse_point",
-        operator="mesh.make_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",
         draw_settings=draw_settings,
     )
@@ -75,12 +78,13 @@ def tool_make_line():
 # -----------------------------------------------------------------------------
 # Tool Registraion
 
-def km_3d_view_tool_make_line(tool_mouse = 'LEFTMOUSE'):
+def km_3d_view_snap_tools(tool_mouse = 'LEFTMOUSE'):
     return [(
-        "3D View Tool: Edit Mesh, Make Line",
+        tool_line.keymap[0],
         {"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
         {"items": [
-            ("mesh.make_line", {"type": tool_mouse, "value": 'CLICK'}, None),
+            ("mesh.snap_utilities_line", {"type": tool_mouse, "value": 'CLICK'},
+             {"properties": [("wait_for_input", False)]}),
         ]},
     )]
 
@@ -91,67 +95,75 @@ def get_tool_list(space_type, context_mode):
     return cls._tools[context_mode]
 
 
-def register_make_line_tool():
+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 == "Add Cube":
+        if isinstance(tool, ToolDef) and tool.text == "Measure":
             break
 
-    tools.insert(index, tool_make_line)
+    tools[:index] += None, tool_line
+
+    del tools
 
     keyconfigs = bpy.context.window_manager.keyconfigs
     kc_defaultconf = keyconfigs.get("blender")
     kc_addonconf   = keyconfigs.get("blender addon")
 
-    # TODO: find the user defined tool_mouse.
-    keyconfig_data = km_3d_view_tool_make_line()
+    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)
 
 
-def unregister_make_line_tool():
+def unregister_snap_tools():
     tools = get_tool_list('VIEW_3D', 'EDIT_MESH')
-    tools.remove(tool_make_line)
 
-    km_name, km_args, km_content = km_3d_view_tool_make_line()[0]
+    index = tools.index(tool_line) - 1 #None
+    tools.pop(index)
+    tools.remove(tool_line)
+
+    del tools
+    del index
 
     keyconfigs = bpy.context.window_manager.keyconfigs
     defaultmap = keyconfigs.get("blender").keymaps
     addonmap   = keyconfigs.get("blender addon").keymaps
 
-    addonmap.remove(addonmap.find(km_name, **km_args))
-    defaultmap.remove(defaultmap.find(km_name, **km_args))
+    for keyconfig_data in km_3d_view_snap_tools():
+        km_name, km_args, km_content = keyconfig_data
+
+        addonmap.remove(addonmap.find(km_name, **km_args))
+        defaultmap.remove(defaultmap.find(km_name, **km_args))
 
 
 # -----------------------------------------------------------------------------
 # Addon Registraion
 
+classes = (
+    preferences.SnapUtilitiesLinePreferences,
+    ops_line.SnapUtilitiesLine,
+    common_classes.VIEW3D_OT_rotate_custom_pivot,
+    common_classes.VIEW3D_OT_zoom_custom_target,
+    common_classes.SnapPointWidget,
+    common_classes.SnapPointWidgetGroup,
+)
+
 def register():
-    bpy.utils.register_class(preferences.SnapUtilitiesLinePreferences)
-    bpy.utils.register_class(common_classes.VIEW3D_OT_rotate_custom_pivot)
-    bpy.utils.register_class(common_classes.VIEW3D_OT_zoom_custom_target)
-    bpy.utils.register_class(ops_line.SnapUtilitiesLine)
-    #bpy.utils.register_class(common_classes.MousePointWidget)
-    #bpy.utils.register_class(common_classes.MousePointWidgetGroup)
+    for cls in classes:
+        bpy.utils.register_class(cls)
 
-    register_make_line_tool()
+    register_snap_tools()
 
 
 def unregister():
-    unregister_make_line_tool()
+    unregister_snap_tools()
 
-    #bpy.utils.unregister_class(common_classes.MousePointWidgetGroup)
-    #bpy.utils.unregister_class(common_classes.MousePointWidget)
-    bpy.utils.unregister_class(ops_line.SnapUtilitiesLine)
-    bpy.utils.unregister_class(common_classes.VIEW3D_OT_zoom_custom_target)
-    bpy.utils.unregister_class(common_classes.VIEW3D_OT_rotate_custom_pivot)
-    bpy.utils.unregister_class(preferences.SnapUtilitiesLinePreferences)
+    for cls in reversed(classes):
+        bpy.utils.unregister_class(cls)
 
 
 if __name__ == "__main__":
-    __name__ = "mesh_snap_utilities_line"
-    __package__ = "mesh_snap_utilities_line"
     register()
diff --git a/mesh_snap_utilities_line/common_classes.py b/mesh_snap_utilities_line/common_classes.py
index 1c6d75db..ae763828 100644
--- a/mesh_snap_utilities_line/common_classes.py
+++ b/mesh_snap_utilities_line/common_classes.py
@@ -18,7 +18,13 @@
 import bpy
 import bgl
 
-from .common_utilities import snap_utilities
+from mathutils import Vector
+
+from .common_utilities import (
+    convert_distance,
+    get_units_info,
+    snap_utilities,
+    )
 
 
 class SnapDrawn():
@@ -52,8 +58,6 @@ class SnapDrawn():
         self._program_smooth_col = gpu.shader.from_builtin("3D_SMOOTH_COLOR")
 
         self._batch_point = None
-        self._batch_circle = None
-        self._batch_vector = None
 
 
     def batch_line_strip_create(self, coords):
@@ -171,6 +175,7 @@ class SnapDrawn():
         gpu.matrix.pop()
 
     def draw_elem(self, snap_obj, bm, elem):
+        #TODO: Cache coords (because antialiasing)
         import gpu
         from bmesh.types import(
             BMVert,
@@ -332,122 +337,67 @@ class CharMap:
         'LEFT_ARROW', 'RIGHT_ARROW'
         }
 
-    @staticmethod
-    def modal(self, context, event):
-        c = event.ascii
-        if c:
-            if c == ",":
-                c = "."
-            self.length_entered = self.length_entered[:self.line_pos] + c + self.length_entered[self.line_pos:]
-            self.line_pos += 1
-        if self.length_entered:
-            if event.type == 'BACK_SPACE':
-                self.length_entered = self.length_entered[:self.line_pos - 1] + self.length_entered[self.line_pos:]
-                self.line_pos -= 1
-
-            elif event.type == 'DEL':
-                self.length_entered = self.length_entered[:self.line_pos] + self.length_entered[self.line_pos + 1:]
-
-            elif event.type == 'LEFT_ARROW':
-                self.line_pos = (self.line_pos - 1) % (len(self.length_entered) + 1)
-
-            elif event.type == 'RIGHT_ARROW':
-                self.line_pos = (self.line_pos + 1) % (len(self.length_entered) + 1)
-
-g_snap_widget = [None]
-
-class MousePointWidget(bpy.types.Gizmo):
-    bl_idname = "VIEW3D_GT_mouse_point"
+    def __init__(self, context):
+        scale = context.scene.unit_settings.scale_length
+        separate_units = context.scene.unit_settings.use_separate
+        self.unit_system = context.scene.unit_settings.system
+        self.uinfo = get_units_info(scale, self.unit_system, separate_units)
+
+        self.clear()
+
+    def modal_(self, context, event):
+        if event.value == 'PRESS':
+            type = event.type
+            ascii = event.ascii
+            if (type in self.type) or (ascii in self.ascii):
+                if ascii:
+                    pos = self.line_pos
+                    if ascii == ",":
+                        ascii = "."
+                    self.length_entered = self.length_entered[:pos] + ascii + self.length_entered[pos:]
+                    self.line_pos += 1
+
+                if self.length_entered:
+                    pos = self.line_pos
+                    if type == 'BACK_SPACE':
+                        self.length_entered = self.length_entered[:pos - 1] + self.length_entered[pos:]
+                        self.line_pos -= 1
+
+                    elif type == 'DEL':
+                        self.length_entered = self.length_entered[:pos] + self.length_entered[pos + 1:]
+
+                    elif type == 'LEFT_ARROW':
+                        self.line_pos = (pos - 1) % (len(self.length_entered) + 1)
+
+                    elif type == 'RIGHT_ARROW':
+        

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list