Curves: Add delete operator to edit mode #104765

Merged
Jacques Lucke merged 3 commits from HooglyBoogly/blender:curves-edit-mode-delete into main 2023-02-15 10:50:12 +01:00
3 changed files with 50 additions and 0 deletions

View File

@ -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

View File

@ -5311,6 +5311,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):

View File

@ -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<bool> selection = attributes.lookup_or_default<bool>(".selection", domain, false);
Review

Not important right now, but this should be abstracted away somehow, because the default shouldn't have to be specified here.

Not important right now, but this should be abstracted away somehow, because the default shouldn't have to be specified here.
const int domain_size_orig = attributes.domain_size(domain);
Vector<int64_t> 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_in_edit_mode_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)