2023-08-16 00:20:26 +10:00
|
|
|
# SPDX-FileCopyrightText: 2020-2023 Blender Authors
|
2023-06-15 13:09:04 +10:00
|
|
|
#
|
2022-02-11 09:07:11 +11:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2020-10-22 12:29:42 +11:00
|
|
|
|
|
|
|
# Update Blender version this key-map was written in:
|
|
|
|
#
|
2022-03-15 14:53:49 +11:00
|
|
|
# When the version is `(0, 0, 0)`, the key-map being loaded didn't contain any versioning information.
|
|
|
|
# This will older than `(2, 92, 0)`.
|
2020-10-22 12:29:42 +11:00
|
|
|
|
|
|
|
def keyconfig_update(keyconfig_data, keyconfig_version):
|
|
|
|
from bpy.app import version_file as blender_version
|
|
|
|
if keyconfig_version >= blender_version:
|
|
|
|
return keyconfig_data
|
|
|
|
|
|
|
|
# Version the key-map.
|
|
|
|
import copy
|
2023-11-30 12:22:47 +01:00
|
|
|
|
2022-03-14 20:41:05 +11:00
|
|
|
# Only copy once.
|
2020-10-22 12:29:42 +11:00
|
|
|
has_copy = False
|
|
|
|
|
2023-11-09 21:32:16 -03:00
|
|
|
def get_transform_modal_map():
|
2023-11-30 12:22:47 +01:00
|
|
|
for km_name, _km_params, km_items_data in keyconfig_data:
|
2023-11-09 21:32:16 -03:00
|
|
|
if km_name == "Transform Modal Map":
|
|
|
|
return km_items_data
|
2023-11-30 12:22:47 +01:00
|
|
|
|
|
|
|
def remove_properties(op_prop_map):
|
|
|
|
nonlocal keyconfig_data
|
|
|
|
nonlocal has_copy
|
|
|
|
|
|
|
|
changed_items = []
|
2024-02-09 18:17:17 +11:00
|
|
|
for km_index, (km_name, _km_parms, km_items_data) in enumerate(keyconfig_data):
|
2023-11-30 12:22:47 +01:00
|
|
|
for kmi_item_index, (item_op, item_event, item_prop) in enumerate(km_items_data["items"]):
|
|
|
|
if item_prop and item_op in op_prop_map:
|
|
|
|
properties = item_prop.get("properties", [])
|
|
|
|
filtered_properties = [
|
|
|
|
prop for prop in properties if not any(
|
|
|
|
key in prop for key in op_prop_map[item_op])
|
|
|
|
]
|
|
|
|
|
|
|
|
if not filtered_properties:
|
|
|
|
filtered_properties = None
|
|
|
|
|
|
|
|
if filtered_properties is None or len(filtered_properties) < len(properties):
|
2024-02-09 18:17:17 +11:00
|
|
|
changed_items.append((km_index, kmi_item_index, filtered_properties))
|
2023-11-30 12:22:47 +01:00
|
|
|
|
|
|
|
if changed_items:
|
|
|
|
if not has_copy:
|
|
|
|
keyconfig_data = copy.deepcopy(keyconfig_data)
|
|
|
|
has_copy = True
|
|
|
|
|
2024-02-09 18:17:17 +11:00
|
|
|
for km_index, kmi_item_index, filtered_properties in changed_items:
|
|
|
|
item_op, item_event, item_prop = keyconfig_data[km_index][2]["items"][kmi_item_index]
|
2023-11-30 12:22:47 +01:00
|
|
|
item_prop["properties"] = filtered_properties
|
2024-02-09 18:17:17 +11:00
|
|
|
keyconfig_data[km_index][2]["items"][kmi_item_index] = (item_op, item_event, item_prop)
|
2023-11-09 21:32:16 -03:00
|
|
|
|
2024-02-09 18:09:05 +11:00
|
|
|
def rename_keymap(km_name_map):
|
|
|
|
nonlocal keyconfig_data
|
|
|
|
nonlocal has_copy
|
|
|
|
|
|
|
|
for km_index, (km_name, km_parms, km_items_data) in enumerate(keyconfig_data):
|
|
|
|
km_name_dst = km_name_map.get(km_name)
|
|
|
|
if km_name_dst is None:
|
|
|
|
continue
|
|
|
|
if not has_copy:
|
|
|
|
keyconfig_data = copy.deepcopy(keyconfig_data)
|
|
|
|
has_copy = True
|
|
|
|
keyconfig_data[km_index] = (km_name_dst, km_parms, km_items_data)
|
|
|
|
|
2020-10-22 12:29:42 +11:00
|
|
|
# Default repeat to false.
|
|
|
|
if keyconfig_version <= (2, 92, 0):
|
|
|
|
if not has_copy:
|
|
|
|
keyconfig_data = copy.deepcopy(keyconfig_data)
|
|
|
|
has_copy = True
|
|
|
|
|
|
|
|
for _km_name, _km_parms, km_items_data in keyconfig_data:
|
|
|
|
for (_item_op, item_event, _item_prop) in km_items_data["items"]:
|
|
|
|
if item_event.get("value") == 'PRESS':
|
2023-04-18 10:42:00 +10:00
|
|
|
# Unfortunately we don't know the `map_type` at this point.
|
2020-10-22 12:29:42 +11:00
|
|
|
# Setting repeat true on other kinds of events is harmless.
|
|
|
|
item_event["repeat"] = True
|
|
|
|
|
2022-03-02 15:07:00 +11:00
|
|
|
if keyconfig_version <= (3, 2, 5):
|
|
|
|
if not has_copy:
|
|
|
|
keyconfig_data = copy.deepcopy(keyconfig_data)
|
|
|
|
has_copy = True
|
|
|
|
|
|
|
|
for _km_name, _km_parms, km_items_data in keyconfig_data:
|
|
|
|
for (_item_op, item_event, _item_prop) in km_items_data["items"]:
|
|
|
|
if ty_new := {
|
|
|
|
'EVT_TWEAK_L': 'LEFTMOUSE',
|
|
|
|
'EVT_TWEAK_M': 'MIDDLEMOUSE',
|
|
|
|
'EVT_TWEAK_R': 'RIGHTMOUSE',
|
|
|
|
}.get(item_event.get("type")):
|
|
|
|
item_event["type"] = ty_new
|
|
|
|
if (value := item_event["value"]) != 'ANY':
|
|
|
|
item_event["direction"] = value
|
|
|
|
item_event["value"] = 'CLICK_DRAG'
|
|
|
|
|
2022-03-14 20:41:05 +11:00
|
|
|
if keyconfig_version <= (3, 2, 6):
|
|
|
|
if not has_copy:
|
|
|
|
keyconfig_data = copy.deepcopy(keyconfig_data)
|
|
|
|
has_copy = True
|
|
|
|
|
|
|
|
for _km_name, _km_parms, km_items_data in keyconfig_data:
|
|
|
|
for (_item_op, item_event, _item_prop) in km_items_data["items"]:
|
|
|
|
if ty_new := {
|
|
|
|
'NDOF_BUTTON_ESC': 'ESC',
|
|
|
|
'NDOF_BUTTON_ALT': 'LEFT_ALT',
|
|
|
|
'NDOF_BUTTON_SHIFT': 'LEFT_SHIFT',
|
|
|
|
'NDOF_BUTTON_CTRL': 'LEFT_CTRL',
|
|
|
|
}.get(item_event.get("type")):
|
|
|
|
item_event["type"] = ty_new
|
|
|
|
|
2022-12-22 18:41:44 -03:00
|
|
|
if keyconfig_version <= (3, 6, 0):
|
|
|
|
# The modal keys "Vert/Edge Slide" and "TrackBall" didn't exist until then.
|
|
|
|
# The operator reused the "Move" and "Rotate" respectively.
|
|
|
|
if not has_copy:
|
|
|
|
keyconfig_data = copy.deepcopy(keyconfig_data)
|
|
|
|
has_copy = True
|
|
|
|
|
2023-11-09 21:32:16 -03:00
|
|
|
if km_items_data := get_transform_modal_map():
|
|
|
|
km_items = km_items_data["items"]
|
|
|
|
for (item_modal, item_event, _item_prop) in km_items:
|
|
|
|
if item_modal == 'TRANSLATE':
|
|
|
|
km_items.append(('VERT_EDGE_SLIDE', item_event, None))
|
|
|
|
elif item_modal == 'ROTATE':
|
|
|
|
km_items.append(('TRACKBALL', item_event, None))
|
2022-12-22 18:41:44 -03:00
|
|
|
|
2023-11-13 09:47:10 -03:00
|
|
|
# The modal key for "Rotate Normals" also didn't exist until then.
|
|
|
|
km_items.append(('ROTATE_NORMALS', {"type": 'N', "value": 'PRESS'}, None))
|
2022-12-22 18:41:44 -03:00
|
|
|
|
2023-06-07 09:22:34 -03:00
|
|
|
if keyconfig_version <= (4, 0, 3):
|
Transform: new feature to edit the 'Snap Base'
This commit implements a new modifier key (`B`) for the transform
operators.
This new key allows changing the 'Snap Base' of a transform by snapping
it to a defined point in the scene.
Ref #66424
# Implementation Details
- This feature is only available in the 3D View.
- This feature is only available for the transform modes:
- `Move`,
- `Rotate`,
- `Scale`,
- `Vert Slide` and
- `Edge Slide`.
- The `Snap Base Edit` is enabled while we are transforming and we
press the key `B`
- The `Snap Base Edit` is confirmed when we press any of the keys:
`B`, `LMB`, `Enter`
- During um operation, if no snap target is set for an element in the
scene (Vertex, Edge...), the snap targets to geometry Vertex, Edge,
Face, Center of Edge and Perpendicular of Edge are set automatically.
- Constraint or similar modal features are not available during the
`Snap Base Edit` mode.
- Text input is not available during the `Snap Base Edit` mode.
- A prone snap base point is indicated with an small cursor drawing.
Pull Request: https://projects.blender.org/blender/blender/pulls/104443
2023-06-03 04:18:49 +02:00
|
|
|
if not has_copy:
|
|
|
|
keyconfig_data = copy.deepcopy(keyconfig_data)
|
|
|
|
has_copy = True
|
|
|
|
|
2023-07-04 14:53:39 +02:00
|
|
|
# "Snap Source Toggle" did not exist until then.
|
2023-11-09 21:32:16 -03:00
|
|
|
if km_items_data := get_transform_modal_map():
|
|
|
|
km_items_data["items"].append(("EDIT_SNAP_SOURCE_ON", {"type": 'B', "value": 'PRESS'}, None))
|
|
|
|
km_items_data["items"].append(("EDIT_SNAP_SOURCE_OFF", {"type": 'B', "value": 'PRESS'}, None))
|
|
|
|
|
|
|
|
if keyconfig_version <= (4, 1, 5):
|
2023-11-30 12:22:47 +01:00
|
|
|
remove_properties({
|
2024-02-12 09:33:07 -03:00
|
|
|
"transform.edge_slide": ["alt_navigation"],
|
2023-11-30 12:22:47 +01:00
|
|
|
"transform.resize": ["alt_navigation"],
|
2024-02-12 09:33:07 -03:00
|
|
|
"transform.rotate": ["alt_navigation"],
|
|
|
|
"transform.shrink_fatten": ["alt_navigation"],
|
|
|
|
"transform.transform": ["alt_navigation"],
|
|
|
|
"transform.translate": ["alt_navigation"],
|
|
|
|
"transform.vert_slide": ["alt_navigation"],
|
2023-11-30 12:22:47 +01:00
|
|
|
"view3d.edit_mesh_extrude_move_normal": ["alt_navigation"],
|
|
|
|
"armature.extrude_move": ["TRANSFORM_OT_translate"],
|
|
|
|
"curve.extrude_move": ["TRANSFORM_OT_translate"],
|
|
|
|
"gpencil.extrude_move": ["TRANSFORM_OT_translate"],
|
|
|
|
"mesh.rip_edge_move": ["TRANSFORM_OT_translate"],
|
|
|
|
"mesh.duplicate_move": ["TRANSFORM_OT_translate"],
|
|
|
|
"object.duplicate_move": ["TRANSFORM_OT_translate"],
|
|
|
|
"object.duplicate_move_linked": ["TRANSFORM_OT_translate"],
|
|
|
|
})
|
|
|
|
|
2023-11-09 21:32:16 -03:00
|
|
|
if km_items_data := get_transform_modal_map():
|
|
|
|
def use_alt_navigate():
|
|
|
|
km_item = next((i for i in km_items_data["items"] if i[0] ==
|
|
|
|
"PROPORTIONAL_SIZE" and i[1]["type"] == 'TRACKPADPAN'), None)
|
|
|
|
if km_item:
|
|
|
|
return "alt" not in km_item[1] or km_item[1]["alt"] is False
|
|
|
|
|
|
|
|
# Fallback.
|
|
|
|
import bpy
|
|
|
|
return getattr(
|
|
|
|
bpy.context.window_manager.keyconfigs.active.preferences,
|
|
|
|
"use_alt_navigation",
|
|
|
|
False)
|
|
|
|
|
|
|
|
if use_alt_navigate():
|
|
|
|
if not has_copy:
|
|
|
|
keyconfig_data = copy.deepcopy(keyconfig_data)
|
|
|
|
has_copy = True
|
|
|
|
km_items_data = get_transform_modal_map()
|
|
|
|
|
|
|
|
km_items_data["items"].append(
|
|
|
|
("PASSTHROUGH_NAVIGATE", {"type": 'LEFT_ALT', "value": 'ANY', "any": True}, None))
|
Transform: new feature to edit the 'Snap Base'
This commit implements a new modifier key (`B`) for the transform
operators.
This new key allows changing the 'Snap Base' of a transform by snapping
it to a defined point in the scene.
Ref #66424
# Implementation Details
- This feature is only available in the 3D View.
- This feature is only available for the transform modes:
- `Move`,
- `Rotate`,
- `Scale`,
- `Vert Slide` and
- `Edge Slide`.
- The `Snap Base Edit` is enabled while we are transforming and we
press the key `B`
- The `Snap Base Edit` is confirmed when we press any of the keys:
`B`, `LMB`, `Enter`
- During um operation, if no snap target is set for an element in the
scene (Vertex, Edge...), the snap targets to geometry Vertex, Edge,
Face, Center of Edge and Perpendicular of Edge are set automatically.
- Constraint or similar modal features are not available during the
`Snap Base Edit` mode.
- Text input is not available during the `Snap Base Edit` mode.
- A prone snap base point is indicated with an small cursor drawing.
Pull Request: https://projects.blender.org/blender/blender/pulls/104443
2023-06-03 04:18:49 +02:00
|
|
|
|
2024-02-09 18:15:05 +11:00
|
|
|
if keyconfig_version <= (4, 1, 21):
|
2024-02-09 18:09:05 +11:00
|
|
|
rename_keymap({"NLA Channels": "NLA Tracks"})
|
|
|
|
|
2020-10-22 12:29:42 +11:00
|
|
|
return keyconfig_data
|