[Bf-extensions-cvs] [5731c638] blender2.8: mesh_snap_utilities_line: fix error messages when undo

mano-wii noreply at git.blender.org
Thu Dec 20 12:57:11 CET 2018


Commit: 5731c6385eb243e6536a5a384a24f43f812573e1
Author: mano-wii
Date:   Thu Dec 20 02:44:47 2018 -0200
Branches: blender2.8
https://developer.blender.org/rBA5731c6385eb243e6536a5a384a24f43f812573e1

mesh_snap_utilities_line: fix error messages when undo

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

M	mesh_snap_utilities_line/__init__.py
M	mesh_snap_utilities_line/ops_line.py
M	mesh_snap_utilities_line/snap_context_l/__init__.py
M	mesh_snap_utilities_line/snap_context_l/mesh_drawing.py

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

diff --git a/mesh_snap_utilities_line/__init__.py b/mesh_snap_utilities_line/__init__.py
index 68a9bfcc..92ec2d60 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, 8, 25),
+    "version": (5, 8, 26),
     "blender": (2, 80, 0),
     "location": "View3D > TOOLS > Make Line",
     "description": "Extends Blender Snap controls",
diff --git a/mesh_snap_utilities_line/ops_line.py b/mesh_snap_utilities_line/ops_line.py
index 11a40871..981c99af 100644
--- a/mesh_snap_utilities_line/ops_line.py
+++ b/mesh_snap_utilities_line/ops_line.py
@@ -206,8 +206,7 @@ def draw_line(self, bm_geom, location):
         self.sctx.tag_update_drawn_snap_object(self.main_snap_obj)
         #bm.verts.index_update()
 
-        if not self.wait_for_input:
-            bpy.ops.ed.undo_push(message="Undo draw line*")
+        bpy.ops.ed.undo_push(message="Undo draw line*")
 
     return [obj.matrix_world @ v.co for v in self.list_verts]
 
@@ -249,6 +248,50 @@ class SnapUtilitiesLine(bpy.types.Operator):
         context.tool_settings.mesh_select_mode = self.select_mode
         context.space_data.overlay.show_face_center = self.show_face_center
 
+    def _init_snap_context(self, context):
+        if self.sctx:
+            self.sctx.clear_snap_objects()
+        else:
+            #Create Snap Context
+            from .snap_context_l import SnapContext
+            self.sctx = SnapContext(context.region, context.space_data)
+            self.sctx.set_pixel_dist(12)
+            self.sctx.use_clip_planes(True)
+
+        if self.outer_verts:
+            for base in context.visible_bases:
+                self.sctx.add_obj(base.object, base.object.matrix_world)
+
+        self.sctx.set_snap_mode(True, True, self.snap_face)
+
+        if self.snap_widget:
+            self.geom = self.snap_widget.geom
+            self.type = self.snap_widget.type
+            self.location = self.snap_widget.loc
+            if self.snap_widget.snap_obj:
+                context.view_layer.objects.active = self.snap_widget.snap_obj.data[0]
+        else:
+            #init these variables to avoid errors
+            self.geom = None
+            self.type = 'OUT'
+            self.location = Vector()
+
+        self.prevloc = Vector()
+        self.list_verts = []
+        self.list_edges = []
+        self.list_verts_co = []
+        self.bool_update = False
+        self.vector_constrain = ()
+        self.len = 0
+        self.length_entered = ""
+        self.line_pos = 0
+
+        active_object = context.active_object
+        mesh = active_object.data
+
+        self.main_snap_obj = self.snap_obj = self.sctx._get_snap_obj_by_obj(active_object)
+        self.main_bm = self.bm = bmesh.from_edit_mesh(mesh)
+
     def modal(self, context, event):
         if self.navigation_ops.run(context, event, self.prevloc if self.vector_constrain else self.location):
             return {'RUNNING_MODAL'}
@@ -256,19 +299,17 @@ class SnapUtilitiesLine(bpy.types.Operator):
         context.area.tag_redraw()
 
         if event.ctrl and event.type == 'Z' and event.value == 'PRESS':
-            if self.bm:
-                self.bm.free()
-                self.bm = None
-            if self.main_bm:
-                self.main_bm.free()
+            del self.bm
+            del self.main_bm
+
             bpy.ops.ed.undo()
-            self.vector_constrain = None
-            self.list_verts_co = []
-            self.list_verts = []
-            self.list_edges = []
             bpy.ops.object.mode_set(mode='EDIT') # just to be sure
-            self.main_bm = bmesh.from_edit_mesh(self.main_snap_obj.data[0].data)
-            self.sctx.tag_update_drawn_snap_object(self.main_snap_obj)
+            bpy.ops.mesh.select_all(action='DESELECT')
+            context.tool_settings.mesh_select_mode = (True, False, True)
+            context.space_data.overlay.show_face_center = True
+
+            self._init_snap_context(context)
+            self.sctx.update_all()
             return {'RUNNING_MODAL'}
 
         is_making_lines = bool(self.list_verts_co)
@@ -468,18 +509,7 @@ class SnapUtilitiesLine(bpy.types.Operator):
                     tuple(context.user_preferences.themes[0].user_interface.axis_z) + (1.0,)
                 )
 
-                #Init Snap Context
-                from .snap_context_l import SnapContext
-
-                self.sctx = SnapContext(context.region, context.space_data)
-                self.sctx.set_pixel_dist(12)
-                self.sctx.use_clip_planes(True)
-
-                if preferences.outer_verts:
-                    for base in context.visible_bases:
-                        self.sctx.add_obj(base.object, base.object.matrix_world)
-
-                self.sctx.set_snap_mode(True, True, self.snap_face)
+                self.sctx = None
 
             #Configure the unit of measure
             self.unit_system = context.scene.unit_settings.system
@@ -495,50 +525,17 @@ class SnapUtilitiesLine(bpy.types.Operator):
             self.snap_to_grid = preferences.increments_grid
             self.incremental = bpy.utils.units.to_value(self.unit_system, 'LENGTH', str(preferences.incremental))
 
-            if self.snap_widget:
-                self.geom = self.snap_widget.geom
-                self.type = self.snap_widget.type
-                self.location = self.snap_widget.loc
-                if self.snap_widget.snap_obj:
-                    context.view_layer.objects.active = self.snap_widget.snap_obj.data[0]
-            else:
-                #init these variables to avoid errors
-                self.geom = None
-                self.type = 'OUT'
-                self.location = Vector()
-
-            self.prevloc = Vector()
-            self.list_verts = []
-            self.list_edges = []
-            self.list_verts_co = []
-            self.bool_update = False
-            self.vector_constrain = ()
-            self.len = 0
-            self.length_entered = ""
-            self.line_pos = 0
-
             self.navigation_ops = SnapNavigation(context, True)
 
-            active_object = context.active_object
-
-            #Create a new object
-            if active_object is None or active_object.type != 'MESH':
-                mesh = bpy.data.meshes.new("")
-                active_object = bpy.data.objects.new("", mesh)
-                context.scene.objects.link(obj)
-                context.scene.objects.active = active_object
-            else:
-                mesh = active_object.data
-
-            self.main_snap_obj = self.snap_obj = self.sctx._get_snap_obj_by_obj(active_object)
-            self.main_bm = self.bm = bmesh.from_edit_mesh(mesh) #remove at end
+            self._init_snap_context(context)
 
             #modals
+            context.window_manager.modal_handler_add(self)
+
             if not self.wait_for_input:
                 self.modal(context, event)
 
             self._handle = bpy.types.SpaceView3D.draw_handler_add(self.draw_callback_px, (), 'WINDOW', 'POST_VIEW')
-            context.window_manager.modal_handler_add(self)
 
             return {'RUNNING_MODAL'}
         else:
diff --git a/mesh_snap_utilities_line/snap_context_l/__init__.py b/mesh_snap_utilities_line/snap_context_l/__init__.py
index c4b03156..86e2f19c 100644
--- a/mesh_snap_utilities_line/snap_context_l/__init__.py
+++ b/mesh_snap_utilities_line/snap_context_l/__init__.py
@@ -33,6 +33,7 @@ class _Internal:
         gpu_Indices_restore_state,
         gpu_Indices_use_clip_planes,
         gpu_Indices_set_ProjectionMatrix,
+        gpu_Indices_mesh_cache_clear,
         )
 
     from .utils_projection import (
@@ -294,6 +295,10 @@ class SnapContext():
 
     ## PUBLIC ##
 
+    def clear_snap_objects(self):
+        self.snap_objects.clear()
+        _Internal.gpu_Indices_mesh_cache_clear()
+
     def update_all(self):
         self.drawn_count = 0
         self._offset_cur = 1
diff --git a/mesh_snap_utilities_line/snap_context_l/mesh_drawing.py b/mesh_snap_utilities_line/snap_context_l/mesh_drawing.py
index 6ef0b0a0..0b0b099c 100644
--- a/mesh_snap_utilities_line/snap_context_l/mesh_drawing.py
+++ b/mesh_snap_utilities_line/snap_context_l/mesh_drawing.py
@@ -22,8 +22,6 @@ import numpy as np
 from mathutils import Matrix
 import gpu
 
-_Hash = {}
-
 def load_shader(shadername):
     from os import path
     with open(path.join(path.dirname(__file__), 'shaders', shadername), 'r') as f:
@@ -177,6 +175,7 @@ class GPU_Indices_Mesh():
         "users"
     )
 
+    _Hash = {}
     shader = None
 
     @classmethod
@@ -218,8 +217,8 @@ class GPU_Indices_Mesh():
     def __init__(self, obj, draw_tris, draw_edges, draw_verts):
         self.obj = obj
 
-        if obj.data in _Hash:
-            src = _Hash[obj.data]
+        if obj.data in GPU_Indices_Mesh._Hash:
+            src = GPU_Indices_Mesh._Hash[obj.data]
             dst = self
 
             dst.draw_tris    = src.draw_tris
@@ -238,7 +237,7 @@ class GPU_Indices_Mesh():
             update = obj.type == 'MESH' and obj.data.is_editmode
 
         else:
-            _Hash[obj.data] = self
+            GPU_Indices_Mesh._Hash[obj.data] = self
             self.users = [self]
             update = True;
 
@@ -372,8 +371,7 @@ class GPU_Indices_Mesh():
 
     def __del__(self):
         if len(self.users) == 1:
-            self.free_gl()
-            _Hash.pop(obj.data)
+            GPU_Indices_Mesh._Hash.pop(obj.data)
 
         self.user.remove(self)
         #print('mesh_del', self.obj.name)
@@ -410,3 +408,7 @@ def gpu_Indices_use_clip_planes(rv3d, value):
 def gpu_Indices_set_ProjectionMatrix(P):
     gpu.matrix.load_projection_matrix(P)
     GPU_Indices_Mesh.P[:] = P
+
+
+def gpu_Indices_mesh_cache_clear():
+    GPU_Indices_Mesh._Hash.clear()



More information about the Bf-extensions-cvs mailing list