1 # SPDX-License-Identifier: GPL-2.0-or-later
4 "name": "Math Vis (Console)",
5 "author": "Campbell Barton",
8 "location": "Properties: Scene > Math Vis Console and Python Console: Menu",
9 "description": "Display console defined mathutils variables in the 3D view",
10 "doc_url": "{BLENDER_MANUAL_URL}/addons/3d_view/math_vis_console.html",
11 "support": "OFFICIAL",
12 "category": "3D View",
18 importlib
.reload(utils
)
19 importlib
.reload(draw
)
25 from bpy
.types
import (
31 from bpy
.props
import (
42 class PanelConsoleVars(Panel
):
43 bl_space_type
= 'PROPERTIES'
44 bl_region_type
= 'WINDOW'
46 bl_label
= "Math Vis Console"
47 bl_idname
= "MATHVIS_PT_panel_console_vars"
48 bl_category
= "Math Vis"
49 bl_options
= {'DEFAULT_CLOSED'}
51 def draw(self
, context
):
53 wm
= context
.window_manager
54 state_props
= wm
.MathVisStatePropList
56 if len(state_props
) == 0:
58 col
= box
.column(align
=True)
59 col
.label(text
="No vars to display")
62 MathVisVarList
.bl_idname
,
63 'MathVisStatePropList',
64 bpy
.context
.window_manager
,
65 'MathVisStatePropList',
66 bpy
.context
.window_manager
.MathVisProp
,
72 col
.prop(mvp
, "name_hide")
73 col
.prop(mvp
, "bbox_hide")
74 col
.prop(mvp
, "in_front")
75 col
.prop(mvp
, "bbox_scale")
76 col
.operator("mathvis.cleanup_console")
79 class DeleteVar(Operator
):
80 bl_idname
= "mathvis.delete_var"
81 bl_label
= "Delete Var"
82 bl_description
= "Remove the variable from the Console"
83 bl_options
= {'REGISTER'}
85 key
: StringProperty(name
="Key")
87 def execute(self
, context
):
88 locals = utils
.console_namespace()
89 utils
.VarStates
.delete(self
.key
)
91 draw
.tag_redraw_areas()
95 class ToggleDisplay(Operator
):
96 bl_idname
= "mathvis.toggle_display"
97 bl_label
= "Hide/Unhide"
98 bl_description
= "Change the display state of the var"
99 bl_options
= {'REGISTER'}
101 key
: StringProperty(name
="Key")
103 def execute(self
, context
):
104 utils
.VarStates
.toggle_display_state(self
.key
)
105 draw
.tag_redraw_areas()
109 class ToggleLock(Operator
):
110 bl_idname
= "mathvis.toggle_lock"
111 bl_label
= "Lock/Unlock"
112 bl_description
= "Lock the var from being deleted"
113 bl_options
= {'REGISTER'}
115 key
: StringProperty(name
="Key")
117 def execute(self
, context
):
118 utils
.VarStates
.toggle_lock_state(self
.key
)
119 draw
.tag_redraw_areas()
123 class ToggleMatrixBBoxDisplay(Operator
):
124 bl_idname
= "mathvis.show_bbox"
125 bl_label
= "Show BBox"
126 bl_description
= "Show/Hide the BBox of Matrix items"
127 bl_options
= {'REGISTER'}
129 def execute(self
, context
):
130 utils
.VarStates
.toggle_show_bbox()
131 draw
.tag_redraw_areas()
135 class CleanupConsole(Operator
):
136 bl_idname
= "mathvis.cleanup_console"
137 bl_label
= "Cleanup Math Vis Console"
138 bl_description
= "Remove all visualized variables from the Console"
139 bl_options
= {'REGISTER'}
141 def execute(self
, context
):
142 utils
.cleanup_math_data()
143 draw
.tag_redraw_areas()
147 def menu_func_cleanup(self
, context
):
148 self
.layout
.operator("mathvis.cleanup_console", text
="Clear Math Vis")
152 utils
.VarStates
.store_states()
153 draw
.tag_redraw_areas()
154 context
= bpy
.context
155 for window
in context
.window_manager
.windows
:
156 window
.screen
.areas
.update()
159 def call_console_hook(self
, context
):
163 class MathVisStateProp(PropertyGroup
):
164 ktype
: StringProperty()
165 state
: BoolVectorProperty(default
=(False, False), size
=2)
168 class MathVisVarList(UIList
):
169 bl_idname
= "MATHVIS_UL_MathVisVarList"
181 col
= layout
.column()
184 is_visible
= item
.state
[0]
185 is_locked
= item
.state
[1]
187 row
= col
.row(align
=True)
188 row
.label(text
='%s - %s' % (key
, ktype
))
190 icon
= 'RESTRICT_VIEW_OFF' if is_visible
else 'RESTRICT_VIEW_ON'
191 prop
= row
.operator("mathvis.toggle_display", text
='', icon
=icon
, emboss
=False)
194 icon
= 'LOCKED' if is_locked
else 'UNLOCKED'
195 prop
= row
.operator("mathvis.toggle_lock", text
='', icon
=icon
, emboss
=False)
199 row
.label(text
='', icon
='BLANK1')
201 prop
= row
.operator("mathvis.delete_var", text
='', icon
='X', emboss
=False)
205 class MathVis(PropertyGroup
):
210 bbox_hide
: BoolProperty(
213 description
="Hide the bounding boxes rendered for Matrix like items",
214 update
=call_console_hook
216 name_hide
: BoolProperty(
219 description
="Hide the names of the rendered items",
220 update
=call_console_hook
222 bbox_scale
: FloatProperty(
225 description
="Resize the Bounding Box and the coordinate "
226 "lines for the display of Matrix items"
229 in_front
: BoolProperty(
230 name
="Always In Front",
232 description
="Draw Points and lines always in front",
233 update
=call_console_hook
242 ToggleMatrixBBoxDisplay
,
251 from bpy
.utils
import register_class
253 draw
.callback_enable()
255 import console_python
256 console_python
.execute
.hooks
.append((console_hook
, ()))
258 bpy
.utils
.register_class(cls
)
259 bpy
.types
.WindowManager
.MathVisProp
= PointerProperty(type=MathVis
)
260 bpy
.types
.WindowManager
.MathVisStatePropList
= CollectionProperty(type=MathVisStateProp
)
261 bpy
.types
.CONSOLE_MT_console
.prepend(menu_func_cleanup
)
265 from bpy
.utils
import unregister_class
267 draw
.callback_disable()
269 import console_python
270 console_python
.execute
.hooks
.remove((console_hook
, ()))
271 bpy
.types
.CONSOLE_MT_console
.remove(menu_func_cleanup
)
272 del bpy
.types
.WindowManager
.MathVisProp
273 del bpy
.types
.WindowManager
.MathVisStatePropList
276 unregister_class(cls
)