Export_3ds: Improved distance cue node search
[blender-addons.git] / space_view3d_math_vis / __init__.py
blob75804ffb2744418df29dd3d350957a67e1264ad2
1 # SPDX-FileCopyrightText: 2010-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 bl_info = {
6 "name": "Math Vis (Console)",
7 "author": "Campbell Barton",
8 "version": (0, 2, 2),
9 "blender": (3, 0, 0),
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",
18 if "bpy" in locals():
19 import importlib
20 importlib.reload(utils)
21 importlib.reload(draw)
22 else:
23 from . import utils
24 from . import draw
26 import bpy
27 from bpy.types import (
28 Operator,
29 Panel,
30 PropertyGroup,
31 UIList,
33 from bpy.props import (
34 StringProperty,
35 BoolProperty,
36 BoolVectorProperty,
37 FloatProperty,
38 IntProperty,
39 PointerProperty,
40 CollectionProperty,
44 class PanelConsoleVars(Panel):
45 bl_space_type = 'PROPERTIES'
46 bl_region_type = 'WINDOW'
47 bl_context = 'scene'
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):
54 layout = self.layout
55 wm = context.window_manager
56 state_props = wm.MathVisStatePropList
58 if len(state_props) == 0:
59 box = layout.box()
60 col = box.column(align=True)
61 col.label(text="No vars to display")
62 else:
63 layout.template_list(
64 MathVisVarList.bl_idname,
65 'MathVisStatePropList',
66 bpy.context.window_manager,
67 'MathVisStatePropList',
68 bpy.context.window_manager.MathVisProp,
69 'index',
70 rows=10
72 col = layout.column()
73 mvp = wm.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)
92 del locals[self.key]
93 draw.tag_redraw_areas()
94 return {'FINISHED'}
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()
108 return {'FINISHED'}
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()
122 return {'FINISHED'}
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()
134 return {'FINISHED'}
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()
146 return {'FINISHED'}
149 def menu_func_cleanup(self, context):
150 self.layout.operator("mathvis.cleanup_console", text="Clear Math Vis")
153 def console_hook():
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):
162 console_hook()
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"
173 def draw_item(self,
174 context,
175 layout,
176 data,
177 item,
178 icon,
179 active_data,
180 active_propname
183 col = layout.column()
184 key = item.name
185 ktype = item.ktype
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)
194 prop.key = key
196 icon = 'LOCKED' if is_locked else 'UNLOCKED'
197 prop = row.operator("mathvis.toggle_lock", text='', icon=icon, emboss=False)
198 prop.key = key
200 if is_locked:
201 row.label(text='', icon='BLANK1')
202 else:
203 prop = row.operator("mathvis.delete_var", text='', icon='X', emboss=False)
204 prop.key = key
207 class MathVis(PropertyGroup):
209 index: IntProperty(
210 name="index"
212 bbox_hide: BoolProperty(
213 name="Hide BBoxes",
214 default=False,
215 description="Hide the bounding boxes rendered for Matrix like items",
216 update=call_console_hook
218 name_hide: BoolProperty(
219 name="Hide Names",
220 default=False,
221 description="Hide the names of the rendered items",
222 update=call_console_hook
224 bbox_scale: FloatProperty(
225 name="Scale factor",
226 min=0, default=1,
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",
233 default=True,
234 description="Draw Points and lines always in front",
235 update=call_console_hook
239 classes = (
240 PanelConsoleVars,
241 DeleteVar,
242 ToggleDisplay,
243 ToggleLock,
244 ToggleMatrixBBoxDisplay,
245 CleanupConsole,
246 MathVisStateProp,
247 MathVisVarList,
248 MathVis,
252 def register():
253 from bpy.utils import register_class
255 draw.callback_enable()
257 import console_python
258 console_python.execute.hooks.append((console_hook, ()))
259 for cls in classes:
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)
266 def unregister():
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
277 for cls in classes:
278 unregister_class(cls)