From 7bced8c6205f0344e11c42bb9242a597d87cee49 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 14 Feb 2023 17:56:06 -0500 Subject: [PATCH 1/2] Curves: Add delete operator to edit mode This could also be called "dissolve", but since it's simple and the expected behavior for current use cases, just call it "Delete". The operation is already implemented for geometry nodes, this commit just exposes it as an operator in the keymap and the edit mode "Curves" menu. --- .../keyconfig/keymap_data/blender_default.py | 2 + release/scripts/startup/bl_ui/space_view3d.py | 1 + .../editors/curves/intern/curves_ops.cc | 47 +++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py index 393c73cc230..4bad5530e52 100644 --- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -5629,6 +5629,8 @@ def km_curves(params): ("curves.disable_selection", {"type": 'TWO', "value": 'PRESS', "alt": True}, None), *_template_items_select_actions(params, "curves.select_all"), ("curves.select_linked", {"type": 'L', "value": 'PRESS', "ctrl": True}, None), + ("curves.delete", {"type": 'X', "value": 'PRESS'}, None), + ("curves.delete", {"type": 'DEL', "value": 'PRESS'}, None), ]) return keymap diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index a1548741187..01c69db8a7e 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -5310,6 +5310,7 @@ class VIEW3D_MT_edit_curves(Menu): layout.menu("VIEW3D_MT_transform") layout.separator() + layout.operator("curves.delete") class VIEW3D_MT_object_mode_pie(Menu): diff --git a/source/blender/editors/curves/intern/curves_ops.cc b/source/blender/editors/curves/intern/curves_ops.cc index d80ebff2adc..e4601f6bc5d 100644 --- a/source/blender/editors/curves/intern/curves_ops.cc +++ b/source/blender/editors/curves/intern/curves_ops.cc @@ -1091,6 +1091,52 @@ static void CURVES_OT_surface_set(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } +namespace curves_delete { + +static int delete_exec(bContext *C, wmOperator * /*op*/) +{ + for (Curves *curves_id : get_unique_editable_curves(*C)) { + bke::CurvesGeometry &curves = curves_id->geometry.wrap(); + const eAttrDomain domain = eAttrDomain(curves_id->selection_domain); + const bke::AttributeAccessor attributes = curves.attributes(); + const VArray selection = attributes.lookup_or_default(".selection", domain, false); + const int domain_size_orig = attributes.domain_size(domain); + Vector indices; + const IndexMask mask = index_mask_ops::find_indices_from_virtual_array( + selection.index_range(), selection, 4096, indices); + switch (domain) { + case ATTR_DOMAIN_POINT: + curves.remove_points(mask); + break; + case ATTR_DOMAIN_CURVE: + curves.remove_curves(mask); + break; + default: + BLI_assert_unreachable(); + } + if (attributes.domain_size(domain) != domain_size_orig) { + DEG_id_tag_update(&curves_id->id, ID_RECALC_GEOMETRY); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, curves_id); + } + } + + return OPERATOR_FINISHED; +} + +} // namespace curves_delete + +static void CURVES_OT_delete(wmOperatorType *ot) +{ + ot->name = "Delete"; + ot->idname = __func__; + ot->description = "Remove selected control points or curves"; + + ot->exec = curves_delete::delete_exec; + ot->poll = editable_curves_poll; + + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + } // namespace blender::ed::curves void ED_operatortypes_curves() @@ -1105,6 +1151,7 @@ void ED_operatortypes_curves() WM_operatortype_append(CURVES_OT_select_end); WM_operatortype_append(CURVES_OT_select_linked); WM_operatortype_append(CURVES_OT_surface_set); + WM_operatortype_append(CURVES_OT_delete); } void ED_keymap_curves(wmKeyConfig *keyconf) -- 2.30.2 From a2ae7537b83756c8f7d85817b30edcb4c8dc5c75 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 14 Feb 2023 23:21:17 -0500 Subject: [PATCH 2/2] Fix poll to only allow curves in edit mode --- source/blender/editors/curves/intern/curves_ops.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/curves/intern/curves_ops.cc b/source/blender/editors/curves/intern/curves_ops.cc index e4601f6bc5d..d9496cf6e25 100644 --- a/source/blender/editors/curves/intern/curves_ops.cc +++ b/source/blender/editors/curves/intern/curves_ops.cc @@ -1132,7 +1132,7 @@ static void CURVES_OT_delete(wmOperatorType *ot) ot->description = "Remove selected control points or curves"; ot->exec = curves_delete::delete_exec; - ot->poll = editable_curves_poll; + ot->poll = editable_curves_in_edit_mode_poll; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } -- 2.30.2