1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
22 "name": "Math Vis (Console)",
23 "author": "Campbell Barton",
25 "blender": (2, 80, 0),
26 "location": "Properties: Scene > Math Vis Console and Python Console: Menu",
27 "description": "Display console defined mathutils variables in the 3D view",
28 "doc_url": "{BLENDER_MANUAL_URL}/addons/3d_view/math_vis_console.html",
29 "support": "OFFICIAL",
30 "category": "3D View",
36 importlib
.reload(utils
)
37 importlib
.reload(draw
)
43 from bpy
.types
import (
49 from bpy
.props
import (
60 class PanelConsoleVars(Panel
):
61 bl_space_type
= 'PROPERTIES'
62 bl_region_type
= 'WINDOW'
64 bl_label
= "Math Vis Console"
65 bl_idname
= "MATHVIS_PT_panel_console_vars"
66 bl_category
= "Math Vis"
67 bl_options
= {'DEFAULT_CLOSED'}
69 def draw(self
, context
):
71 wm
= context
.window_manager
72 state_props
= wm
.MathVisStatePropList
74 if len(state_props
) == 0:
76 col
= box
.column(align
=True)
77 col
.label(text
="No vars to display")
80 MathVisVarList
.bl_idname
,
81 'MathVisStatePropList',
82 bpy
.context
.window_manager
,
83 'MathVisStatePropList',
84 bpy
.context
.window_manager
.MathVisProp
,
90 col
.prop(mvp
, "name_hide")
91 col
.prop(mvp
, "bbox_hide")
92 col
.prop(mvp
, "in_front")
93 col
.prop(mvp
, "bbox_scale")
94 col
.operator("mathvis.cleanup_console")
97 class DeleteVar(Operator
):
98 bl_idname
= "mathvis.delete_var"
99 bl_label
= "Delete Var"
100 bl_description
= "Remove the variable from the Console"
101 bl_options
= {'REGISTER'}
103 key
: StringProperty(name
="Key")
105 def execute(self
, context
):
106 locals = utils
.console_namespace()
107 utils
.VarStates
.delete(self
.key
)
109 draw
.tag_redraw_areas()
113 class ToggleDisplay(Operator
):
114 bl_idname
= "mathvis.toggle_display"
115 bl_label
= "Hide/Unhide"
116 bl_description
= "Change the display state of the var"
117 bl_options
= {'REGISTER'}
119 key
: StringProperty(name
="Key")
121 def execute(self
, context
):
122 utils
.VarStates
.toggle_display_state(self
.key
)
123 draw
.tag_redraw_areas()
127 class ToggleLock(Operator
):
128 bl_idname
= "mathvis.toggle_lock"
129 bl_label
= "Lock/Unlock"
130 bl_description
= "Lock the var from being deleted"
131 bl_options
= {'REGISTER'}
133 key
: StringProperty(name
="Key")
135 def execute(self
, context
):
136 utils
.VarStates
.toggle_lock_state(self
.key
)
137 draw
.tag_redraw_areas()
141 class ToggleMatrixBBoxDisplay(Operator
):
142 bl_idname
= "mathvis.show_bbox"
143 bl_label
= "Show BBox"
144 bl_description
= "Show/Hide the BBox of Matrix items"
145 bl_options
= {'REGISTER'}
147 def execute(self
, context
):
148 utils
.VarStates
.toggle_show_bbox()
149 draw
.tag_redraw_areas()
153 class CleanupConsole(Operator
):
154 bl_idname
= "mathvis.cleanup_console"
155 bl_label
= "Cleanup Math Vis Console"
156 bl_description
= "Remove all visualized variables from the Console"
157 bl_options
= {'REGISTER'}
159 def execute(self
, context
):
160 utils
.cleanup_math_data()
161 draw
.tag_redraw_areas()
165 def menu_func_cleanup(self
, context
):
166 self
.layout
.operator("mathvis.cleanup_console", text
="Clear Math Vis")
170 utils
.VarStates
.store_states()
171 draw
.tag_redraw_areas()
172 context
= bpy
.context
173 for window
in context
.window_manager
.windows
:
174 window
.screen
.areas
.update()
177 def call_console_hook(self
, context
):
181 class MathVisStateProp(PropertyGroup
):
182 ktype
: StringProperty()
183 state
: BoolVectorProperty(default
=(False, False), size
=2)
186 class MathVisVarList(UIList
):
187 bl_idname
= "MATHVIS_UL_MathVisVarList"
199 col
= layout
.column()
202 is_visible
= item
.state
[0]
203 is_locked
= item
.state
[1]
205 row
= col
.row(align
=True)
206 row
.label(text
='%s - %s' % (key
, ktype
))
208 icon
= 'RESTRICT_VIEW_OFF' if is_visible
else 'RESTRICT_VIEW_ON'
209 prop
= row
.operator("mathvis.toggle_display", text
='', icon
=icon
, emboss
=False)
212 icon
= 'LOCKED' if is_locked
else 'UNLOCKED'
213 prop
= row
.operator("mathvis.toggle_lock", text
='', icon
=icon
, emboss
=False)
217 row
.label(text
='', icon
='BLANK1')
219 prop
= row
.operator("mathvis.delete_var", text
='', icon
='X', emboss
=False)
223 class MathVis(PropertyGroup
):
228 bbox_hide
: BoolProperty(
231 description
="Hide the bounding boxes rendered for Matrix like items",
232 update
=call_console_hook
234 name_hide
: BoolProperty(
237 description
="Hide the names of the rendered items",
238 update
=call_console_hook
240 bbox_scale
: FloatProperty(
243 description
="Resize the Bounding Box and the coordinate "
244 "lines for the display of Matrix items"
247 in_front
: BoolProperty(
248 name
="Always In Front",
250 description
="Draw Points and lines always in front",
251 update
=call_console_hook
260 ToggleMatrixBBoxDisplay
,
269 from bpy
.utils
import register_class
271 draw
.callback_enable()
273 import console_python
274 console_python
.execute
.hooks
.append((console_hook
, ()))
276 bpy
.utils
.register_class(cls
)
277 bpy
.types
.WindowManager
.MathVisProp
= PointerProperty(type=MathVis
)
278 bpy
.types
.WindowManager
.MathVisStatePropList
= CollectionProperty(type=MathVisStateProp
)
279 bpy
.types
.CONSOLE_MT_console
.prepend(menu_func_cleanup
)
283 from bpy
.utils
import unregister_class
285 draw
.callback_disable()
287 import console_python
288 console_python
.execute
.hooks
.remove((console_hook
, ()))
289 bpy
.types
.CONSOLE_MT_console
.remove(menu_func_cleanup
)
290 del bpy
.types
.WindowManager
.MathVisProp
291 del bpy
.types
.WindowManager
.MathVisStatePropList
294 unregister_class(cls
)