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
9 "name": "Snap_Utilities_Line",
10 "author": "Germano Cavalcante",
13 "location": "View3D > TOOLS > Line Tool",
14 "description": "Extends Blender Snap controls",
15 "doc_url": "{BLENDER_MANUAL_URL}/addons/mesh/snap_utilities_line.html",
21 importlib
.reload(navigation_ops
)
22 importlib
.reload(widgets
)
23 importlib
.reload(preferences
)
24 importlib
.reload(op_line
)
25 importlib
.reload(keys
)
27 from . import navigation_ops
29 from . import preferences
35 from bpy
.utils
.toolsystem
import ToolDef
39 __package__
= "mesh_snap_utilities_line"
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")
61 idname
="snap_utilities.line",
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 # -----------------------------------------------------------------------------
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":
92 tools
[:index
] += None, tool_line
97 def unregister_snap_tools():
98 tools
= get_tool_list('VIEW_3D', 'EDIT_MESH')
100 index
= tools
.index(tool_line
) - 1 # None
102 tools
.remove(tool_line
)
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:
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:
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])
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 # -----------------------------------------------------------------------------
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
,
168 bpy
.utils
.register_class(cls
)
170 register_snap_tools()
176 unregister_snap_tools()
178 for cls
in reversed(classes
):
179 bpy
.utils
.unregister_class(cls
)
182 if __name__
== "__main__":