[Bf-extensions-cvs] [ed9bcd8] master: patch D2380 Added display options for the Math Vis Addon

Gaia Clary noreply at git.blender.org
Wed Nov 30 22:51:19 CET 2016


Commit: ed9bcd88c7fb1f8b48b96051b61f4d7d724e2e52
Author: Gaia Clary
Date:   Wed Nov 30 22:50:46 2016 +0100
Branches: master
https://developer.blender.org/rBAed9bcd88c7fb1f8b48b96051b61f4d7d724e2e52

patch D2380 Added display options for the Math Vis Addon

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

M	space_view3d_math_vis/__init__.py
M	space_view3d_math_vis/draw.py
M	space_view3d_math_vis/utils.py

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

diff --git a/space_view3d_math_vis/__init__.py b/space_view3d_math_vis/__init__.py
index 056e83f..88f90ef 100644
--- a/space_view3d_math_vis/__init__.py
+++ b/space_view3d_math_vis/__init__.py
@@ -40,20 +40,178 @@ else:
     from . import utils, draw
 
 import bpy
+from bpy.props import StringProperty, BoolProperty, BoolVectorProperty, FloatProperty, PointerProperty, CollectionProperty
+from .utils import get_var_states
+
+
+class PanelConsoleVars(bpy.types.Panel):
+    bl_space_type = 'VIEW_3D'
+    bl_region_type = 'TOOLS'
+    bl_label = "Console Vars"
+    bl_idname = "mathvis.panel_console_vars"
+    bl_category = "Math Vis"
+    bl_options = {'DEFAULT_CLOSED'}
+
+    def draw(self, context):
+        layout = self.layout
+        box = layout.box()
+        col = box.column(align=True)
+        variables = utils.get_math_data()
+        var_states = get_var_states()
+
+        for key in sorted(variables):
+            ktype = variables[key]
+            row = col.row(align=True)
+            row.label(text='%s - %s' % (key, ktype.__name__))
+
+            icon = 'RESTRICT_VIEW_OFF' if var_states.is_visible(key) else 'RESTRICT_VIEW_ON'
+            prop = row.operator("mathvis.toggle_display", text='', icon=icon, emboss=False)
+            prop.key = key
+
+            icon = 'LOCKED' if var_states.is_locked(key) else 'UNLOCKED'
+            prop = row.operator("mathvis.toggle_lock", text='', icon=icon, emboss=False)
+            prop.key = key
+
+            if var_states.is_locked(key):
+                row.label(text='', icon='BLANK1')
+            else:
+                prop = row.operator("mathvis.delete_var", text='', icon='X', emboss=False)
+                prop.key = key
+
+        col = layout.column()
+        col.prop(bpy.context.scene.MathVisProp, "name_hide")
+        col.prop(bpy.context.scene.MathVisProp, "bbox_hide")
+        col.prop(bpy.context.scene.MathVisProp, "bbox_scale")
+        col.operator("mathvis.cleanup_console")
+
+
+class DeleteVar(bpy.types.Operator):
+    bl_idname = "mathvis.delete_var"
+    bl_label = "Delete Var"
+    bl_description = "Remove the variable from the Console."
+    bl_options = {'REGISTER'}
+
+    key = StringProperty(name="Key")
+
+    def execute(self, context):
+        locals = utils.console_namespace()
+        var_states = get_var_states()
+        var_states.delete(self.key)
+        del locals[self.key]
+        draw.tag_redraw_all_view3d_areas()
+        return {'FINISHED'}
+
+
+class ToggleDisplay(bpy.types.Operator):
+    bl_idname = "mathvis.toggle_display"
+    bl_label = "Hide/Unhide"
+    bl_description = "Change the display state of the var"
+    bl_options = {'REGISTER'}
+
+    key = StringProperty(name="Key")
+
+    def execute(self, context):
+        var_states = get_var_states()
+        var_states.toggle_display_state(self.key)
+        draw.tag_redraw_all_view3d_areas()
+        return {'FINISHED'}
+
+
+class ToggleLock(bpy.types.Operator):
+    bl_idname = "mathvis.toggle_lock"
+    bl_label = "Lock/Unlock"
+    bl_description = "Lock the var from being deleted"
+    bl_options = {'REGISTER'}
+
+    key = StringProperty(name="Key")
+
+    def execute(self, context):
+        var_states = get_var_states()
+        var_states.toggle_lock_state(self.key)
+        draw.tag_redraw_all_view3d_areas()
+        return {'FINISHED'}
+
+
+class ToggleMatrixBBoxDisplay(bpy.types.Operator):
+    bl_idname = "mathvis.show_bbox"
+    bl_label = "Show BBox"
+    bl_description = "Show/Hide the BBox of Matrix items"
+    bl_options = {'REGISTER'}
+
+    def execute(self, context):
+        var_states = get_var_states()
+        var_states.toggle_show_bbox()
+        draw.tag_redraw_all_view3d_areas()
+        return {'FINISHED'}
+
+
+class CleanupConsole(bpy.types.Operator):
+    bl_idname = "mathvis.cleanup_console"
+    bl_label = "Cleanup Math Vis Console"
+    bl_description = "Remove all visualised variables from the Console."
+    bl_options = {'REGISTER'}
+
+    def execute(self, context):
+        utils.cleanup_math_data()
+        draw.tag_redraw_all_view3d_areas()
+        return {'FINISHED'}
+
+
+def menu_func_cleanup(self, context):
+    self.layout.operator("mathvis.cleanup_console", text="Clear Math Vis")
 
 
 def console_hook():
-    draw.tag_redraw_all_view3d()
+    draw.tag_redraw_all_view3d_areas()
+    context = bpy.context
+    for window in context.window_manager.windows:
+        window.screen.areas.update()
+
+
+def call_console_hook(self, context):
+    console_hook()
+
+
+class MathVisStateProp(bpy.types.PropertyGroup):
+    key = StringProperty()
+    state = BoolVectorProperty(default=(False, False), size=2)
+
+
+class MathVisProp(bpy.types.PropertyGroup):
+
+    bbox_hide = BoolProperty(name="Hide BBoxes",
+                             default=False,
+                             description="Hide the bounding boxes rendered for Matrix like items",
+                             update=call_console_hook)
+
+    name_hide = BoolProperty(name="Hide Names",
+                             default=False,
+                             description="Hide the names of the rendered items",
+                             update=call_console_hook)
+
+    bbox_scale = FloatProperty(name="Scale factor", min=0, default=1,
+                               description="Resize the Bounding Box and the coordinate lines for the display of Matrix items")
+
 
 def register():
     draw.callback_enable()
 
     import console_python
     console_python.execute.hooks.append((console_hook, ()))
+    bpy.utils.register_module(__name__)
+    if not 'MathVisStateProp' in dir(bpy.types.WindowManager):
+        bpy.types.Scene.MathVisProp = PointerProperty(type=MathVisProp)
+        bpy.types.WindowManager.MathVisStateProp = CollectionProperty(type=MathVisStateProp)
+    bpy.types.CONSOLE_MT_console.prepend(menu_func_cleanup)
 
 
 def unregister():
+    context = bpy.context
+    var_states = get_var_states()
+    var_states.store_states()
     draw.callback_disable()
 
     import console_python
     console_python.execute.hooks.remove((console_hook, ()))
+    bpy.types.CONSOLE_MT_console.remove(menu_func_cleanup)
+    bpy.utils.unregister_module(__name__)
diff --git a/space_view3d_math_vis/draw.py b/space_view3d_math_vis/draw.py
index 40c44f3..1890c3e 100644
--- a/space_view3d_math_vis/draw.py
+++ b/space_view3d_math_vis/draw.py
@@ -27,16 +27,14 @@ SpaceView3D = bpy.types.SpaceView3D
 callback_handle = []
 
 
-def tag_redraw_all_view3d():
+def tag_redraw_all_view3d_areas():
     context = bpy.context
 
     # Py cant access notifers
     for window in context.window_manager.windows:
         for area in window.screen.areas:
             if area.type == 'VIEW_3D':
-                for region in area.regions:
-                    if region.type == 'WINDOW':
-                        region.tag_redraw()
+                area.tag_redraw()
 
 
 def callback_enable():
@@ -47,7 +45,7 @@ def callback_enable():
     handle_view = SpaceView3D.draw_handler_add(draw_callback_view, (), 'WINDOW', 'POST_VIEW')
     callback_handle[:] = handle_pixel, handle_view
 
-    tag_redraw_all_view3d()
+    tag_redraw_all_view3d_areas()
 
 
 def callback_disable():
@@ -59,7 +57,7 @@ def callback_disable():
     SpaceView3D.draw_handler_remove(handle_view, 'WINDOW')
     callback_handle[:] = []
 
-    tag_redraw_all_view3d()
+    tag_redraw_all_view3d_areas()
 
 
 def draw_callback_px():
@@ -71,6 +69,11 @@ def draw_callback_px():
 
     data_matrix, data_quat, data_euler, data_vector, data_vector_array = utils.console_math_data()
 
+    name_hide = context.scene.MathVisProp.name_hide
+
+    if name_hide:
+        return
+
     if not data_matrix and not data_quat and not data_euler and not data_vector and not data_vector_array:
 
         '''
@@ -92,13 +95,13 @@ def draw_callback_px():
     # vars for projection
     perspective_matrix = region3d.perspective_matrix.copy()
 
-    def draw_text(text, vec):
+    def draw_text(text, vec, dx=3.0, dy=-4.0):
         vec_4d = perspective_matrix * vec.to_4d()
         if vec_4d.w > 0.0:
             x = region_mid_width + region_mid_width * (vec_4d.x / vec_4d.w)
             y = region_mid_height + region_mid_height * (vec_4d.y / vec_4d.w)
 
-            blf.position(font_id, x + 3.0, y - 4.0, 0.0)
+            blf.position(font_id, x + dx, y + dy, 0.0)
             blf.draw(font_id, text)
 
     # points
@@ -114,34 +117,56 @@ def draw_callback_px():
     # matrix
     if data_matrix:
         for key, mat in data_matrix.items():
-            draw_text(key, mat[3])
+            loc = Vector((mat[0][3], mat[1][3], mat[2][3]))
+            draw_text(key, loc, dx=10, dy=-20)
 
+    line = 20
     if data_quat:
         loc = context.scene.cursor_location.copy()
         for key, mat in data_quat.items():
-            draw_text(key, loc)
+            draw_text(key, loc, dy=-line)
+            line += 20
 
     if data_euler:
         loc = context.scene.cursor_location.copy()
         for key, mat in data_euler.items():
-            draw_text(key, loc)
+            draw_text(key, loc, dy=-line)
+            line += 20
 
 
 def draw_callback_view():
     context = bpy.context
 
-    from bgl import glEnable, glDisable, glColor3f, glVertex3f, glPointSize, glLineWidth, glBegin, glEnd, glLineStipple, GL_POINTS, GL_LINE_STRIP, GL_LINES, GL_LINE_STIPPLE
+    from bgl import (
+        glEnable,
+        glDisable,
+        glColor3f,
+        glVertex3f,
+        glPointSize,
+        glLineWidth,
+        glBegin,
+        glEnd,
+        glLineStipple,
+        GL_POINTS,
+        GL_LINE_STRIP,
+        GL_LINES,
+        GL_LINE_STIPPLE
+    )
 
     data_matrix, data_quat, data_euler, data_vector, data_vector_array = utils.console_math_data()
 
+    # draw_matrix modifiers
+    bbox_hide = context.scene.MathVisProp.bbox_hide
+    bbox_scale = context.scene.MathVisProp.bbox_scale
+
     # draw_matrix vars
     zero = Vector((0.0, 0.0, 0.0))
-    x_p = Vector((1.0, 0.0, 0.0))
-    x_n = Vector((-1.0, 0.0, 0.0))
-    y_p = Vector((0.0, 1.0, 0.0))
-    y_n = Vector((0.0, -1.0, 0.0))
-    z_p = Vector((0.0, 0.0, 1.0))
-    z_n = Vector((0.0, 0.0, -1.0))
+    x_p = Vector((bbox_sca

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list