Sun position: remove unused prop in HDRI mode
[blender-addons.git] / space_view3d_math_vis / __init__.py
blobb99456f8502087f205da466044bdf19dc3bad45c
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 #####
19 # <pep8 compliant>
21 bl_info = {
22 "name": "Math Vis (Console)",
23 "author": "Campbell Barton",
24 "version": (0, 2, 1),
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",
34 if "bpy" in locals():
35 import importlib
36 importlib.reload(utils)
37 importlib.reload(draw)
38 else:
39 from . import utils
40 from . import draw
42 import bpy
43 from bpy.types import (
44 Operator,
45 Panel,
46 PropertyGroup,
47 UIList,
49 from bpy.props import (
50 StringProperty,
51 BoolProperty,
52 BoolVectorProperty,
53 FloatProperty,
54 IntProperty,
55 PointerProperty,
56 CollectionProperty,
60 class PanelConsoleVars(Panel):
61 bl_space_type = 'PROPERTIES'
62 bl_region_type = 'WINDOW'
63 bl_context = 'scene'
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):
70 layout = self.layout
71 wm = context.window_manager
72 state_props = wm.MathVisStatePropList
74 if len(state_props) == 0:
75 box = layout.box()
76 col = box.column(align=True)
77 col.label(text="No vars to display")
78 else:
79 layout.template_list(
80 MathVisVarList.bl_idname,
81 'MathVisStatePropList',
82 bpy.context.window_manager,
83 'MathVisStatePropList',
84 bpy.context.window_manager.MathVisProp,
85 'index',
86 rows=10
88 col = layout.column()
89 mvp = wm.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)
108 del locals[self.key]
109 draw.tag_redraw_areas()
110 return {'FINISHED'}
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()
124 return {'FINISHED'}
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()
138 return {'FINISHED'}
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()
150 return {'FINISHED'}
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()
162 return {'FINISHED'}
165 def menu_func_cleanup(self, context):
166 self.layout.operator("mathvis.cleanup_console", text="Clear Math Vis")
169 def console_hook():
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):
178 console_hook()
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"
189 def draw_item(self,
190 context,
191 layout,
192 data,
193 item,
194 icon,
195 active_data,
196 active_propname
199 col = layout.column()
200 key = item.name
201 ktype = item.ktype
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)
210 prop.key = key
212 icon = 'LOCKED' if is_locked else 'UNLOCKED'
213 prop = row.operator("mathvis.toggle_lock", text='', icon=icon, emboss=False)
214 prop.key = key
216 if is_locked:
217 row.label(text='', icon='BLANK1')
218 else:
219 prop = row.operator("mathvis.delete_var", text='', icon='X', emboss=False)
220 prop.key = key
223 class MathVis(PropertyGroup):
225 index: IntProperty(
226 name="index"
228 bbox_hide: BoolProperty(
229 name="Hide BBoxes",
230 default=False,
231 description="Hide the bounding boxes rendered for Matrix like items",
232 update=call_console_hook
234 name_hide: BoolProperty(
235 name="Hide Names",
236 default=False,
237 description="Hide the names of the rendered items",
238 update=call_console_hook
240 bbox_scale: FloatProperty(
241 name="Scale factor",
242 min=0, default=1,
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",
249 default=True,
250 description="Draw Points and lines always in front",
251 update=call_console_hook
255 classes = (
256 PanelConsoleVars,
257 DeleteVar,
258 ToggleDisplay,
259 ToggleLock,
260 ToggleMatrixBBoxDisplay,
261 CleanupConsole,
262 MathVisStateProp,
263 MathVisVarList,
264 MathVis,
268 def register():
269 from bpy.utils import register_class
271 draw.callback_enable()
273 import console_python
274 console_python.execute.hooks.append((console_hook, ()))
275 for cls in classes:
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)
282 def unregister():
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
293 for cls in classes:
294 unregister_class(cls)