Skip to content
Snippets Groups Projects
Commit 5731c638 authored by mano-wii's avatar mano-wii
Browse files

mesh_snap_utilities_line: fix error messages when undo

parent ce4fead3
Branches
Tags
No related merge requests found
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
bl_info = { bl_info = {
"name": "Snap_Utilities_Line", "name": "Snap_Utilities_Line",
"author": "Germano Cavalcante", "author": "Germano Cavalcante",
"version": (5, 8, 25), "version": (5, 8, 26),
"blender": (2, 80, 0), "blender": (2, 80, 0),
"location": "View3D > TOOLS > Make Line", "location": "View3D > TOOLS > Make Line",
"description": "Extends Blender Snap controls", "description": "Extends Blender Snap controls",
......
...@@ -206,8 +206,7 @@ def draw_line(self, bm_geom, location): ...@@ -206,8 +206,7 @@ def draw_line(self, bm_geom, location):
self.sctx.tag_update_drawn_snap_object(self.main_snap_obj) self.sctx.tag_update_drawn_snap_object(self.main_snap_obj)
#bm.verts.index_update() #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] return [obj.matrix_world @ v.co for v in self.list_verts]
...@@ -249,6 +248,50 @@ class SnapUtilitiesLine(bpy.types.Operator): ...@@ -249,6 +248,50 @@ class SnapUtilitiesLine(bpy.types.Operator):
context.tool_settings.mesh_select_mode = self.select_mode context.tool_settings.mesh_select_mode = self.select_mode
context.space_data.overlay.show_face_center = self.show_face_center 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): def modal(self, context, event):
if self.navigation_ops.run(context, event, self.prevloc if self.vector_constrain else self.location): if self.navigation_ops.run(context, event, self.prevloc if self.vector_constrain else self.location):
return {'RUNNING_MODAL'} return {'RUNNING_MODAL'}
...@@ -256,19 +299,17 @@ class SnapUtilitiesLine(bpy.types.Operator): ...@@ -256,19 +299,17 @@ class SnapUtilitiesLine(bpy.types.Operator):
context.area.tag_redraw() context.area.tag_redraw()
if event.ctrl and event.type == 'Z' and event.value == 'PRESS': if event.ctrl and event.type == 'Z' and event.value == 'PRESS':
if self.bm: del self.bm
self.bm.free() del self.main_bm
self.bm = None
if self.main_bm:
self.main_bm.free()
bpy.ops.ed.undo() 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 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) bpy.ops.mesh.select_all(action='DESELECT')
self.sctx.tag_update_drawn_snap_object(self.main_snap_obj) 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'} return {'RUNNING_MODAL'}
is_making_lines = bool(self.list_verts_co) is_making_lines = bool(self.list_verts_co)
...@@ -468,18 +509,7 @@ class SnapUtilitiesLine(bpy.types.Operator): ...@@ -468,18 +509,7 @@ class SnapUtilitiesLine(bpy.types.Operator):
tuple(context.user_preferences.themes[0].user_interface.axis_z) + (1.0,) tuple(context.user_preferences.themes[0].user_interface.axis_z) + (1.0,)
) )
#Init Snap Context self.sctx = None
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)
#Configure the unit of measure #Configure the unit of measure
self.unit_system = context.scene.unit_settings.system self.unit_system = context.scene.unit_settings.system
...@@ -495,50 +525,17 @@ class SnapUtilitiesLine(bpy.types.Operator): ...@@ -495,50 +525,17 @@ class SnapUtilitiesLine(bpy.types.Operator):
self.snap_to_grid = preferences.increments_grid self.snap_to_grid = preferences.increments_grid
self.incremental = bpy.utils.units.to_value(self.unit_system, 'LENGTH', str(preferences.incremental)) 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) self.navigation_ops = SnapNavigation(context, True)
active_object = context.active_object self._init_snap_context(context)
#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
#modals #modals
context.window_manager.modal_handler_add(self)
if not self.wait_for_input: if not self.wait_for_input:
self.modal(context, event) self.modal(context, event)
self._handle = bpy.types.SpaceView3D.draw_handler_add(self.draw_callback_px, (), 'WINDOW', 'POST_VIEW') 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'} return {'RUNNING_MODAL'}
else: else:
......
...@@ -33,6 +33,7 @@ class _Internal: ...@@ -33,6 +33,7 @@ class _Internal:
gpu_Indices_restore_state, gpu_Indices_restore_state,
gpu_Indices_use_clip_planes, gpu_Indices_use_clip_planes,
gpu_Indices_set_ProjectionMatrix, gpu_Indices_set_ProjectionMatrix,
gpu_Indices_mesh_cache_clear,
) )
from .utils_projection import ( from .utils_projection import (
...@@ -294,6 +295,10 @@ class SnapContext(): ...@@ -294,6 +295,10 @@ class SnapContext():
## PUBLIC ## ## PUBLIC ##
def clear_snap_objects(self):
self.snap_objects.clear()
_Internal.gpu_Indices_mesh_cache_clear()
def update_all(self): def update_all(self):
self.drawn_count = 0 self.drawn_count = 0
self._offset_cur = 1 self._offset_cur = 1
......
...@@ -22,8 +22,6 @@ import numpy as np ...@@ -22,8 +22,6 @@ import numpy as np
from mathutils import Matrix from mathutils import Matrix
import gpu import gpu
_Hash = {}
def load_shader(shadername): def load_shader(shadername):
from os import path from os import path
with open(path.join(path.dirname(__file__), 'shaders', shadername), 'r') as f: with open(path.join(path.dirname(__file__), 'shaders', shadername), 'r') as f:
...@@ -177,6 +175,7 @@ class GPU_Indices_Mesh(): ...@@ -177,6 +175,7 @@ class GPU_Indices_Mesh():
"users" "users"
) )
_Hash = {}
shader = None shader = None
@classmethod @classmethod
...@@ -218,8 +217,8 @@ class GPU_Indices_Mesh(): ...@@ -218,8 +217,8 @@ class GPU_Indices_Mesh():
def __init__(self, obj, draw_tris, draw_edges, draw_verts): def __init__(self, obj, draw_tris, draw_edges, draw_verts):
self.obj = obj self.obj = obj
if obj.data in _Hash: if obj.data in GPU_Indices_Mesh._Hash:
src = _Hash[obj.data] src = GPU_Indices_Mesh._Hash[obj.data]
dst = self dst = self
dst.draw_tris = src.draw_tris dst.draw_tris = src.draw_tris
...@@ -238,7 +237,7 @@ class GPU_Indices_Mesh(): ...@@ -238,7 +237,7 @@ class GPU_Indices_Mesh():
update = obj.type == 'MESH' and obj.data.is_editmode update = obj.type == 'MESH' and obj.data.is_editmode
else: else:
_Hash[obj.data] = self GPU_Indices_Mesh._Hash[obj.data] = self
self.users = [self] self.users = [self]
update = True; update = True;
...@@ -372,8 +371,7 @@ class GPU_Indices_Mesh(): ...@@ -372,8 +371,7 @@ class GPU_Indices_Mesh():
def __del__(self): def __del__(self):
if len(self.users) == 1: if len(self.users) == 1:
self.free_gl() GPU_Indices_Mesh._Hash.pop(obj.data)
_Hash.pop(obj.data)
self.user.remove(self) self.user.remove(self)
#print('mesh_del', self.obj.name) #print('mesh_del', self.obj.name)
...@@ -410,3 +408,7 @@ def gpu_Indices_use_clip_planes(rv3d, value): ...@@ -410,3 +408,7 @@ def gpu_Indices_use_clip_planes(rv3d, value):
def gpu_Indices_set_ProjectionMatrix(P): def gpu_Indices_set_ProjectionMatrix(P):
gpu.matrix.load_projection_matrix(P) gpu.matrix.load_projection_matrix(P)
GPU_Indices_Mesh.P[:] = P GPU_Indices_Mesh.P[:] = P
def gpu_Indices_mesh_cache_clear():
GPU_Indices_Mesh._Hash.clear()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment