mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 18:16:40 +00:00
Added default blender selection behaviour to CAD Tool
Similarly to BIM Tool (85bba9d)
Now it works exactly as default blender selection - supports box selection etc
This commit is contained in:
@@ -34,7 +34,7 @@ class CadTool(WorkSpaceTool):
|
||||
bl_icon = os.path.join(os.path.dirname(__file__), "ops.authoring.cad")
|
||||
bl_widget = None
|
||||
# https://docs.blender.org/api/current/bpy.types.KeyMapItems.html
|
||||
bl_keymap = (
|
||||
bl_keymap = tool.Blender.get_default_selection_keypmap() + (
|
||||
("bim.cad_hotkey", {"type": "C", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_C")]}),
|
||||
("bim.cad_hotkey", {"type": "E", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_E")]}),
|
||||
("bim.cad_hotkey", {"type": "F", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_F")]}),
|
||||
|
||||
@@ -39,46 +39,10 @@ class BimTool(WorkSpaceTool):
|
||||
bl_icon = os.path.join(os.path.dirname(__file__), "ops.authoring.bim")
|
||||
bl_widget = None
|
||||
# https://docs.blender.org/api/current/bpy.types.KeyMapItems.html
|
||||
bl_keymap = (
|
||||
bl_keymap = tool.Blender.get_default_selection_keypmap() + (
|
||||
# ("bim.wall_tool_op", {"type": 'MOUSEMOVE', "value": 'ANY'}, {"properties": []}),
|
||||
# ("mesh.add_wall", {"type": 'LEFTMOUSE', "value": 'PRESS'}, {"properties": []}),
|
||||
# ("bim.sync_modeling", {"type": 'MOUSEMOVE', "value": 'ANY'}, {"properties": []}),
|
||||
# Replicate default blender selection behaviour with click and box selection
|
||||
# code below comes from blender_default.py which is part of default blender scripts licensed under GPL v2
|
||||
# https://github.com/blender/blender/blob/master/release/scripts/presets/keyconfig/keymap_data/blender_default.py
|
||||
# the code is the data from evaluating km_3d_view_tool_select() and km_3d_view_tool_select_box()
|
||||
#
|
||||
# You can run the snippet below in Blender console
|
||||
# to regenerate those keybindings in case of errors in the future
|
||||
# ```
|
||||
# import os
|
||||
# version = ".".join(bpy.app.version_string.split(".")[:2])
|
||||
# fl = os.path.join(os.getcwd(), version, "scripts/presets/keyconfig/keymap_data/blender_default.py")
|
||||
# def_keymap = bpy.utils.execfile(fl)
|
||||
# params = def_keymap.Params
|
||||
# box_keymap = def_keymap.km_3d_view_tool_select_box(def_keymap.Params(), fallback=None)[2]["items"]
|
||||
# click_keymap = def_keymap.km_3d_view_tool_select(def_keymap.Params(select_mouse="LEFTMOUSE"), fallback=None)[2]["items"]
|
||||
# ```
|
||||
# box selection keymap
|
||||
("view3d.select_box", {"type": "LEFTMOUSE", "value": "CLICK_DRAG"}, None),
|
||||
(
|
||||
"view3d.select_box",
|
||||
{"type": "LEFTMOUSE", "value": "CLICK_DRAG", "shift": True},
|
||||
{"properties": [("mode", "ADD")]},
|
||||
),
|
||||
(
|
||||
"view3d.select_box",
|
||||
{"type": "LEFTMOUSE", "value": "CLICK_DRAG", "ctrl": True},
|
||||
{"properties": [("mode", "SUB")]},
|
||||
),
|
||||
(
|
||||
"view3d.select_box",
|
||||
{"type": "LEFTMOUSE", "value": "CLICK_DRAG", "shift": True, "ctrl": True},
|
||||
{"properties": [("mode", "AND")]},
|
||||
),
|
||||
# left-click selection keymap
|
||||
("view3d.select", {"type": "LEFTMOUSE", "value": "PRESS"}, {"properties": [("deselect_all", True)]}),
|
||||
("view3d.select", {"type": "LEFTMOUSE", "value": "PRESS", "shift": True}, {"properties": [("toggle", True)]}),
|
||||
("bim.hotkey", {"type": "A", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_A")]}),
|
||||
("bim.hotkey", {"type": "C", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_C")]}),
|
||||
("bim.hotkey", {"type": "E", "value": "PRESS", "shift": True}, {"properties": [("hotkey", "S_E")]}),
|
||||
|
||||
@@ -105,14 +105,60 @@ class Blender:
|
||||
area = next(area for area in bpy.context.screen.areas if area.type == "VIEW_3D")
|
||||
context_override = {"area": area}
|
||||
return context_override
|
||||
|
||||
|
||||
@classmethod
|
||||
def update_viewport(cls):
|
||||
def update_viewport(cls):
|
||||
# if it stops working in future Blender versions
|
||||
# there is an alternative:
|
||||
# bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
|
||||
|
||||
tool.Blender.get_viewport_context()['area'].tag_redraw()
|
||||
tool.Blender.get_viewport_context()["area"].tag_redraw()
|
||||
|
||||
@classmethod
|
||||
def get_default_selection_keypmap(cls):
|
||||
"""keymap to replicate default blender selection behaviour with click and box selection"""
|
||||
# code below comes from blender_default.py which is part of default blender scripts licensed under GPL v2
|
||||
# https://github.com/blender/blender/blob/master/release/scripts/presets/keyconfig/keymap_data/blender_default.py
|
||||
# the code is the data from evaluating km_3d_view_tool_select() and km_3d_view_tool_select_box()
|
||||
#
|
||||
# You can run the snippet below in Blender console
|
||||
# to regenerate those keybindings in case of errors in the future
|
||||
# ```
|
||||
# import os
|
||||
# version = ".".join(bpy.app.version_string.split(".")[:2])
|
||||
# fl = os.path.join(os.getcwd(), version, "scripts/presets/keyconfig/keymap_data/blender_default.py")
|
||||
# def_keymap = bpy.utils.execfile(fl)
|
||||
# params = def_keymap.Params
|
||||
# box_keymap = def_keymap.km_3d_view_tool_select_box(def_keymap.Params(), fallback=None)[2]["items"]
|
||||
# click_keymap = def_keymap.km_3d_view_tool_select(def_keymap.Params(select_mouse="LEFTMOUSE"), fallback=None)[2]["items"]
|
||||
# ```
|
||||
keymap = (
|
||||
# box selection keymap
|
||||
("view3d.select_box", {"type": "LEFTMOUSE", "value": "CLICK_DRAG"}, None),
|
||||
(
|
||||
"view3d.select_box",
|
||||
{"type": "LEFTMOUSE", "value": "CLICK_DRAG", "shift": True},
|
||||
{"properties": [("mode", "ADD")]},
|
||||
),
|
||||
(
|
||||
"view3d.select_box",
|
||||
{"type": "LEFTMOUSE", "value": "CLICK_DRAG", "ctrl": True},
|
||||
{"properties": [("mode", "SUB")]},
|
||||
),
|
||||
(
|
||||
"view3d.select_box",
|
||||
{"type": "LEFTMOUSE", "value": "CLICK_DRAG", "shift": True, "ctrl": True},
|
||||
{"properties": [("mode", "AND")]},
|
||||
),
|
||||
# left-click selection keymap
|
||||
("view3d.select", {"type": "LEFTMOUSE", "value": "PRESS"}, {"properties": [("deselect_all", True)]}),
|
||||
(
|
||||
"view3d.select",
|
||||
{"type": "LEFTMOUSE", "value": "PRESS", "shift": True},
|
||||
{"properties": [("toggle", True)]},
|
||||
),
|
||||
)
|
||||
return keymap
|
||||
|
||||
## BMESH UTILS ##
|
||||
@classmethod
|
||||
@@ -137,7 +183,7 @@ class Blender:
|
||||
# until you restart EDIT mode
|
||||
# which may result in errors when some other scripts will try to get bmesh
|
||||
bm.free()
|
||||
|
||||
|
||||
mesh.update()
|
||||
|
||||
@classmethod
|
||||
@@ -167,4 +213,4 @@ class Blender:
|
||||
if callback:
|
||||
callback(bm_a, new_verts, new_edges, new_faces)
|
||||
|
||||
return bm_a
|
||||
return bm_a
|
||||
|
||||
Reference in New Issue
Block a user