1 # SPDX-FileCopyrightText: 2010-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
6 "name": "Math Vis (Console)",
7 "author": "Campbell Barton",
10 "location": "Properties: Scene > Math Vis Console and Python Console: Menu",
11 "description": "Display console defined mathutils variables in the 3D view",
12 "doc_url": "{BLENDER_MANUAL_URL}/addons/3d_view/math_vis_console.html",
13 "support": "OFFICIAL",
14 "category": "3D View",
20 importlib
.reload(utils
)
21 importlib
.reload(draw
)
27 from bpy
.types
import (
33 from bpy
.props
import (
44 class PanelConsoleVars(Panel
):
45 bl_space_type
= 'PROPERTIES'
46 bl_region_type
= 'WINDOW'
48 bl_label
= "Math Vis Console"
49 bl_idname
= "MATHVIS_PT_panel_console_vars"
50 bl_category
= "Math Vis"
51 bl_options
= {'DEFAULT_CLOSED'}
53 def draw(self
, context
):
55 wm
= context
.window_manager
56 state_props
= wm
.MathVisStatePropList
58 if len(state_props
) == 0:
60 col
= box
.column(align
=True)
61 col
.label(text
="No vars to display")
64 MathVisVarList
.bl_idname
,
65 'MathVisStatePropList',
66 bpy
.context
.window_manager
,
67 'MathVisStatePropList',
68 bpy
.context
.window_manager
.MathVisProp
,
74 col
.prop(mvp
, "name_hide")
75 col
.prop(mvp
, "bbox_hide")
76 col
.prop(mvp
, "in_front")
77 col
.prop(mvp
, "bbox_scale")
78 col
.operator("mathvis.cleanup_console")
81 class DeleteVar(Operator
):
82 bl_idname
= "mathvis.delete_var"
83 bl_label
= "Delete Var"
84 bl_description
= "Remove the variable from the Console"
85 bl_options
= {'REGISTER'}
87 key
: StringProperty(name
="Key")
89 def execute(self
, context
):
90 locals = utils
.console_namespace()
91 utils
.VarStates
.delete(self
.key
)
93 draw
.tag_redraw_areas()
97 class ToggleDisplay(Operator
):
98 bl_idname
= "mathvis.toggle_display"
99 bl_label
= "Hide/Unhide"
100 bl_description
= "Change the display state of the var"
101 bl_options
= {'REGISTER'}
103 key
: StringProperty(name
="Key")
105 def execute(self
, context
):
106 utils
.VarStates
.toggle_display_state(self
.key
)
107 draw
.tag_redraw_areas()
111 class ToggleLock(Operator
):
112 bl_idname
= "mathvis.toggle_lock"
113 bl_label
= "Lock/Unlock"
114 bl_description
= "Lock the var from being deleted"
115 bl_options
= {'REGISTER'}
117 key
: StringProperty(name
="Key")
119 def execute(self
, context
):
120 utils
.VarStates
.toggle_lock_state(self
.key
)
121 draw
.tag_redraw_areas()
125 class ToggleMatrixBBoxDisplay(Operator
):
126 bl_idname
= "mathvis.show_bbox"
127 bl_label
= "Show BBox"
128 bl_description
= "Show/Hide the BBox of Matrix items"
129 bl_options
= {'REGISTER'}
131 def execute(self
, context
):
132 utils
.VarStates
.toggle_show_bbox()
133 draw
.tag_redraw_areas()
137 class CleanupConsole(Operator
):
138 bl_idname
= "mathvis.cleanup_console"
139 bl_label
= "Cleanup Math Vis Console"
140 bl_description
= "Remove all visualized variables from the Console"
141 bl_options
= {'REGISTER'}
143 def execute(self
, context
):
144 utils
.cleanup_math_data()
145 draw
.tag_redraw_areas()
149 def menu_func_cleanup(self
, context
):
150 self
.layout
.operator("mathvis.cleanup_console", text
="Clear Math Vis")
154 utils
.VarStates
.store_states()
155 draw
.tag_redraw_areas()
156 context
= bpy
.context
157 for window
in context
.window_manager
.windows
:
158 window
.screen
.areas
.update()
161 def call_console_hook(self
, context
):
165 class MathVisStateProp(PropertyGroup
):
166 ktype
: StringProperty()
167 state
: BoolVectorProperty(default
=(False, False), size
=2)
170 class MathVisVarList(UIList
):
171 bl_idname
= "MATHVIS_UL_MathVisVarList"
183 col
= layout
.column()
186 is_visible
= item
.state
[0]
187 is_locked
= item
.state
[1]
189 row
= col
.row(align
=True)
190 row
.label(text
='%s - %s' % (key
, ktype
))
192 icon
= 'RESTRICT_VIEW_OFF' if is_visible
else 'RESTRICT_VIEW_ON'
193 prop
= row
.operator("mathvis.toggle_display", text
='', icon
=icon
, emboss
=False)
196 icon
= 'LOCKED' if is_locked
else 'UNLOCKED'
197 prop
= row
.operator("mathvis.toggle_lock", text
='', icon
=icon
, emboss
=False)
201 row
.label(text
='', icon
='BLANK1')
203 prop
= row
.operator("mathvis.delete_var", text
='', icon
='X', emboss
=False)
207 class MathVis(PropertyGroup
):
212 bbox_hide
: BoolProperty(
215 description
="Hide the bounding boxes rendered for Matrix like items",
216 update
=call_console_hook
218 name_hide
: BoolProperty(
221 description
="Hide the names of the rendered items",
222 update
=call_console_hook
224 bbox_scale
: FloatProperty(
227 description
="Resize the Bounding Box and the coordinate "
228 "lines for the display of Matrix items"
231 in_front
: BoolProperty(
232 name
="Always In Front",
234 description
="Draw Points and lines always in front",
235 update
=call_console_hook
244 ToggleMatrixBBoxDisplay
,
253 from bpy
.utils
import register_class
255 draw
.callback_enable()
257 import console_python
258 console_python
.execute
.hooks
.append((console_hook
, ()))
260 bpy
.utils
.register_class(cls
)
261 bpy
.types
.WindowManager
.MathVisProp
= PointerProperty(type=MathVis
)
262 bpy
.types
.WindowManager
.MathVisStatePropList
= CollectionProperty(type=MathVisStateProp
)
263 bpy
.types
.CONSOLE_MT_console
.prepend(menu_func_cleanup
)
267 from bpy
.utils
import unregister_class
269 draw
.callback_disable()
271 import console_python
272 console_python
.execute
.hooks
.remove((console_hook
, ()))
273 bpy
.types
.CONSOLE_MT_console
.remove(menu_func_cleanup
)
274 del bpy
.types
.WindowManager
.MathVisProp
275 del bpy
.types
.WindowManager
.MathVisStatePropList
278 unregister_class(cls
)