Update scripts to account for removal of the context override to bpy.ops
[blender-addons.git] / mesh_tiny_cad / CFG.py
blob3cac50e523330f589d8fb15c3d6653cdf9ec10d5
1 # SPDX-License-Identifier: GPL-2.0-or-later
4 import os
5 import bpy
7 ICONS = 'BIX CCEN V2X VTX XALL E2F'.split(' ')
8 icon_collection = {}
11 class TinyCADProperties(bpy.types.PropertyGroup):
13 num_verts: bpy.props.IntProperty(
14 min=3, max=60, default=12)
16 rescale: bpy.props.FloatProperty(
17 default=1.0,
18 precision=4,
19 min=0.0001)
22 class VIEW3D_MT_edit_mesh_tinycad(bpy.types.Menu):
23 bl_label = "TinyCAD"
25 @classmethod
26 def poll(cls, context):
27 return bool(context.object)
29 def draw(self, context):
31 pcoll = icon_collection["main"]
33 def cicon(name):
34 return pcoll[name].icon_id
36 op = self.layout.operator
37 op('tinycad.autovtx', text='VTX | AUTO', icon_value=cicon('VTX'))
38 op('tinycad.vertintersect', text='V2X | Vertex at intersection', icon_value=cicon('V2X'))
39 op('tinycad.intersectall', text='XALL | Intersect selected edges', icon_value=cicon('XALL'))
40 op('tinycad.linetobisect', text='BIX | Bisector of 2 planar edges', icon_value=cicon('BIX'))
41 op('tinycad.circlecenter', text='CCEN | Resurrect circle center', icon_value=cicon('CCEN'))
42 op('tinycad.edge_to_face', text='E2F | Extend Edge to Face', icon_value=cicon('E2F'))
45 def register_icons():
46 import bpy.utils.previews
47 pcoll = bpy.utils.previews.new()
48 icons_dir = os.path.join(os.path.dirname(__file__), "icons")
49 for icon_name in ICONS:
50 pcoll.load(icon_name, os.path.join(icons_dir, icon_name + '.png'), 'IMAGE')
52 icon_collection["main"] = pcoll
55 def unregister_icons():
56 for pcoll in icon_collection.values():
57 bpy.utils.previews.remove(pcoll)
58 icon_collection.clear()