Export_3ds: Added distance cue chunk export
[blender-addons.git] / mesh_snap_utilities_line / __init__.py
blobf664db88c0832ae7d189104e5c6a862c39b03106
1 # SPDX-FileCopyrightText: 2018-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # Contact for more information about the Addon:
6 # Email: germano.costa@ig.com.br
7 # Twitter: wii_mano @mano_wii
8 bl_info = {
9 "name": "Snap_Utilities_Line",
10 "author": "Germano Cavalcante",
11 "version": (6, 8, 0),
12 "blender": (3, 2, 0),
13 "location": "View3D > TOOLS > Line Tool",
14 "description": "Extends Blender Snap controls",
15 "doc_url": "{BLENDER_MANUAL_URL}/addons/mesh/snap_utilities_line.html",
16 "category": "Mesh",
19 if "bpy" in locals():
20 import importlib
21 importlib.reload(navigation_ops)
22 importlib.reload(widgets)
23 importlib.reload(preferences)
24 importlib.reload(op_line)
25 importlib.reload(keys)
26 else:
27 from . import navigation_ops
28 from . import widgets
29 from . import preferences
30 from . import op_line
31 from . import keys
33 # autopep8: off
34 import bpy
35 from bpy.utils.toolsystem import ToolDef
36 # autopep8: on
38 if not __package__:
39 __package__ = "mesh_snap_utilities_line"
42 @ToolDef.from_fn
43 def tool_line():
44 import os
46 def draw_settings(context, layout, tool):
47 addon_prefs = context.preferences.addons[__package__].preferences
49 layout.prop(addon_prefs, "incremental")
50 layout.prop(addon_prefs, "increments_grid")
51 layout.prop(addon_prefs, "intersect")
52 layout.prop(addon_prefs, "create_face")
53 if context.mode == 'EDIT_MESH':
54 layout.prop(addon_prefs, "outer_verts")
55 # props = tool.operator_properties("mesh.snap_utilities_line")
56 # layout.prop(props, "radius")
58 icons_dir = os.path.join(os.path.dirname(__file__), "icons")
60 return dict(
61 idname="snap_utilities.line",
62 label="Make Line",
63 description=(
64 "Make Lines\n"
65 "Connect them to split faces"
67 icon=os.path.join(icons_dir, "ops.mesh.snap_utilities_line"),
68 widget="MESH_GGT_snap_point",
69 # operator="mesh.snap_utilities_line",
70 keymap=keys.km_tool_snap_utilities_line,
71 draw_settings=draw_settings,
75 # -----------------------------------------------------------------------------
76 # Tool Registration
79 def get_tool_list(space_type, context_mode):
80 from bl_ui.space_toolsystem_common import ToolSelectPanelHelper
81 cls = ToolSelectPanelHelper._tool_class_from_space_type(space_type)
82 return cls._tools[context_mode]
85 def register_snap_tools():
86 tools = get_tool_list('VIEW_3D', 'EDIT_MESH')
88 for index, tool in enumerate(tools, 1):
89 if isinstance(tool, ToolDef) and tool.label == "Measure":
90 break
92 tools[:index] += None, tool_line
94 del tools
97 def unregister_snap_tools():
98 tools = get_tool_list('VIEW_3D', 'EDIT_MESH')
100 index = tools.index(tool_line) - 1 # None
101 tools.pop(index)
102 tools.remove(tool_line)
104 del tools
105 del index
108 def register_keymaps():
109 keyconfigs = bpy.context.window_manager.keyconfigs
110 kc_defaultconf = keyconfigs.default
111 kc_addonconf = keyconfigs.addon
112 # In background mode.
113 if kc_defaultconf is None or kc_addonconf is None:
114 return
116 # TODO: find the user defined tool_mouse.
117 from bl_keymap_utils.io import keyconfig_init_from_data
118 keyconfig_init_from_data(
119 kc_defaultconf, keys.generate_empty_snap_utilities_tools_keymaps())
120 keyconfig_init_from_data(
121 kc_addonconf, keys.generate_snap_utilities_keymaps())
123 # snap_modalkeymap = kc_addonconf.keymaps.find(keys.km_snap_utilities_modal_keymap)
124 # snap_modalkeymap.assign("MESH_OT_snap_utilities_line")
127 def unregister_keymaps():
128 keyconfigs = bpy.context.window_manager.keyconfigs
129 defaultmap = getattr(keyconfigs.get("Blender"), "keymaps", None)
130 addonmap = getattr(keyconfigs.get("Blender addon"), "keymaps", None)
131 # In background mode.
132 if defaultmap is None or addonmap is None:
133 return
135 for keyconfig_data in keys.generate_snap_utilities_global_keymaps():
136 km_name, km_args, km_content = keyconfig_data
137 keymap = addonmap.find(km_name, **km_args)
138 keymap_items = keymap.keymap_items
139 for item in km_content['items']:
140 item_id = keymap_items.find(item[0])
141 if item_id != -1:
142 keymap_items.remove(keymap_items[item_id])
144 for keyconfig_data in keys.generate_snap_utilities_tools_keymaps():
145 km_name, km_args, km_content = keyconfig_data
146 addonmap.remove(addonmap.find(km_name, **km_args))
148 for keyconfig_data in keys.generate_empty_snap_utilities_tools_keymaps():
149 km_name, km_args, km_content = keyconfig_data
150 defaultmap.remove(defaultmap.find(km_name, **km_args))
153 # -----------------------------------------------------------------------------
154 # Addon Registration
156 classes = (
157 preferences.SnapUtilitiesPreferences,
158 op_line.SnapUtilitiesLine,
159 navigation_ops.VIEW3D_OT_rotate_custom_pivot,
160 navigation_ops.VIEW3D_OT_zoom_custom_target,
161 widgets.SnapPointWidget,
162 widgets.SnapPointWidgetGroup,
166 def register():
167 for cls in classes:
168 bpy.utils.register_class(cls)
170 register_snap_tools()
171 register_keymaps()
174 def unregister():
175 unregister_keymaps()
176 unregister_snap_tools()
178 for cls in reversed(classes):
179 bpy.utils.unregister_class(cls)
182 if __name__ == "__main__":
183 register()