Node Wrangler: Add more specific poll methods
[blender-addons.git] / mesh_tiny_cad / CFG.py
blob2d5d98c4a31080ab4a1180d1bd6a9412a08bfd13
1 # SPDX-FileCopyrightText: 2016-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
6 import os
7 import bpy
9 ICONS = 'BIX CCEN V2X VTX XALL E2F'.split(' ')
10 icon_collection = {}
13 class TinyCADProperties(bpy.types.PropertyGroup):
15 num_verts: bpy.props.IntProperty(
16 min=3, max=60, default=12)
18 rescale: bpy.props.FloatProperty(
19 default=1.0,
20 precision=4,
21 min=0.0001)
24 class VIEW3D_MT_edit_mesh_tinycad(bpy.types.Menu):
25 bl_label = "TinyCAD"
27 @classmethod
28 def poll(cls, context):
29 return bool(context.object)
31 def draw(self, context):
33 pcoll = icon_collection["main"]
35 def cicon(name):
36 return pcoll[name].icon_id
38 op = self.layout.operator
39 op('tinycad.autovtx', text='VTX | AUTO', icon_value=cicon('VTX'))
40 op('tinycad.vertintersect', text='V2X | Vertex at intersection', icon_value=cicon('V2X'))
41 op('tinycad.intersectall', text='XALL | Intersect selected edges', icon_value=cicon('XALL'))
42 op('tinycad.linetobisect', text='BIX | Bisector of 2 planar edges', icon_value=cicon('BIX'))
43 op('tinycad.circlecenter', text='CCEN | Resurrect circle center', icon_value=cicon('CCEN'))
44 op('tinycad.edge_to_face', text='E2F | Extend Edge to Face', icon_value=cicon('E2F'))
47 def register_icons():
48 import bpy.utils.previews
49 pcoll = bpy.utils.previews.new()
50 icons_dir = os.path.join(os.path.dirname(__file__), "icons")
51 for icon_name in ICONS:
52 pcoll.load(icon_name, os.path.join(icons_dir, icon_name + '.png'), 'IMAGE')
54 icon_collection["main"] = pcoll
57 def unregister_icons():
58 for pcoll in icon_collection.values():
59 bpy.utils.previews.remove(pcoll)
60 icon_collection.clear()