From 126bff3099998f0041c8b4f086e6440ae8470480 Mon Sep 17 00:00:00 2001 From: Chao Li Date: Sun, 11 Jun 2023 17:35:49 +0200 Subject: [PATCH] GPv3: "Select Linked" operator This adds `GREASE_PENCIL_OT_select_linked` operator for the new grease pencil data. Resolves #108750. Pull Request: https://projects.blender.org/blender/blender/pulls/108829 --- .../keyconfig/keymap_data/blender_default.py | 3 ++ scripts/startup/bl_ui/space_view3d.py | 4 +++ .../grease_pencil/intern/grease_pencil_ops.cc | 34 ++++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/scripts/presets/keyconfig/keymap_data/blender_default.py b/scripts/presets/keyconfig/keymap_data/blender_default.py index dba98cb1d1f..d138101eb68 100644 --- a/scripts/presets/keyconfig/keymap_data/blender_default.py +++ b/scripts/presets/keyconfig/keymap_data/blender_default.py @@ -4508,6 +4508,9 @@ def km_grease_pencil_edit(params): items.extend([ *_template_items_select_actions(params, "grease_pencil.select_all"), + # Select linked + ("grease_pencil.select_linked", {"type": 'L', "value": 'PRESS'}, None), + ("grease_pencil.select_linked", {"type": 'L', "value": 'PRESS', "ctrl": True}, None), ("grease_pencil.select_more", {"type": 'NUMPAD_PLUS', "value": 'PRESS', "ctrl": True, "repeat": True}, None), ("grease_pencil.select_less", {"type": 'NUMPAD_MINUS', "value": 'PRESS', "ctrl": True, "repeat": True}, None), ]) diff --git a/scripts/startup/bl_ui/space_view3d.py b/scripts/startup/bl_ui/space_view3d.py index 1d1b0f572a5..5b99214919e 100644 --- a/scripts/startup/bl_ui/space_view3d.py +++ b/scripts/startup/bl_ui/space_view3d.py @@ -2030,6 +2030,10 @@ class VIEW3D_MT_select_edit_gpencil(Menu): layout.separator() + layout.operator("grease_pencil.select_linked", text="Linked") + + layout.separator() + layout.operator("grease_pencil.select_more") layout.operator("grease_pencil.select_less") diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc index 61634053e3b..fccf9ade39c 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_ops.cc @@ -125,7 +125,6 @@ static int select_less_exec(bContext *C, wmOperator * /*op*/) DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY); WM_event_add_notifier(C, NC_GEOM | ND_DATA, &grease_pencil); - return OPERATOR_FINISHED; } @@ -141,6 +140,38 @@ static void GREASE_PENCIL_OT_select_less(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } +static int select_linked_exec(bContext *C, wmOperator * /*op*/) +{ + Scene *scene = CTX_data_scene(C); + Object *object = CTX_data_active_object(C); + GreasePencil &grease_pencil = *static_cast(object->data); + + grease_pencil.foreach_editable_drawing( + scene->r.cfra, [](int /*drawing_index*/, GreasePencilDrawing &drawing) { + // TODO: Support different selection domains. + blender::ed::curves::select_linked(drawing.geometry.wrap()); + }); + + /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic + * attribute for now. */ + DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, &grease_pencil); + + return OPERATOR_FINISHED; +} + +static void GREASE_PENCIL_OT_select_linked(wmOperatorType *ot) +{ + ot->name = "Select Linked"; + ot->idname = "GREASE_PENCIL_OT_select_linked"; + ot->description = "Select all points in curves with any point selection"; + + ot->exec = select_linked_exec; + ot->poll = editable_grease_pencil_poll; + + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + static void keymap_grease_pencil_editing(wmKeyConfig *keyconf) { wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Edit Mode", 0, 0); @@ -155,6 +186,7 @@ void ED_operatortypes_grease_pencil(void) WM_operatortype_append(GREASE_PENCIL_OT_select_all); WM_operatortype_append(GREASE_PENCIL_OT_select_more); WM_operatortype_append(GREASE_PENCIL_OT_select_less); + WM_operatortype_append(GREASE_PENCIL_OT_select_linked); } void ED_keymap_grease_pencil(wmKeyConfig *keyconf)