GPv3: Select ends operator #108864

Merged
Falk David merged 6 commits from Chao-Li/blender:gpv3-select-ends into main 2023-06-13 13:02:56 +02:00
2 changed files with 62 additions and 0 deletions

View File

@ -2034,6 +2034,15 @@ class VIEW3D_MT_select_edit_gpencil(Menu):
layout.separator()
op = layout.operator("grease_pencil.select_ends", text="First")
op.amount_start = 1
op.amount_end = 0
op = layout.operator("grease_pencil.select_ends", text="Last")
op.amount_start = 0
op.amount_end = 1
layout.separator()
layout.operator("grease_pencil.select_more")
layout.operator("grease_pencil.select_less")

View File

@ -172,6 +172,58 @@ static void GREASE_PENCIL_OT_select_linked(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
static int select_ends_exec(bContext *C, wmOperator *op)
{
const int amount_start = RNA_int_get(op->ptr, "amount_start");
const int amount_end = RNA_int_get(op->ptr, "amount_end");
Scene *scene = CTX_data_scene(C);
Object *object = CTX_data_active_object(C);
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
grease_pencil.foreach_editable_drawing(
scene->r.cfra, [&](int /*drawing_index*/, GreasePencilDrawing &drawing) {
blender::ed::curves::select_ends(drawing.geometry.wrap(), amount_start, amount_end);
Chao-Li marked this conversation as resolved
Review

Just capture [&] in the lambda instead of these specific variables. There's no benefit to being specific here

Just capture `[&]` in the lambda instead of these specific variables. There's no benefit to being specific here
});
Chao-Li marked this conversation as resolved
Review

Comments should use the /* */ style (https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Comments)

But also this isn't really correct, right? There's no way to support this on the curve domain.

Comments should use the `/* */` style (https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Comments) But also this isn't really correct, right? There's no way to support this on the curve domain.
Review

Correct, the comment should be removed.

Correct, the comment should be removed.
/* 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_ends(wmOperatorType *ot)
{
ot->name = "Select Ends";
ot->idname = "GREASE_PENCIL_OT_select_ends";
ot->description = "Select end points of strokes";
Chao-Li marked this conversation as resolved Outdated

Select end points of strokes

`Select end points of strokes`
ot->exec = select_ends_exec;
ot->poll = editable_grease_pencil_poll;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
RNA_def_int(ot->srna,
"amount_start",
0,
0,
INT32_MAX,
"Amount Start",
"Number of points to select from the start",
0,
INT32_MAX);
RNA_def_int(ot->srna,
"amount_end",
1,
0,
INT32_MAX,
"Amount End",
"Number of points to select from the end",
0,
INT32_MAX);
}
static void keymap_grease_pencil_editing(wmKeyConfig *keyconf)
{
wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Grease Pencil Edit Mode", 0, 0);
@ -187,6 +239,7 @@ void ED_operatortypes_grease_pencil(void)
WM_operatortype_append(GREASE_PENCIL_OT_select_more);
WM_operatortype_append(GREASE_PENCIL_OT_select_less);
WM_operatortype_append(GREASE_PENCIL_OT_select_linked);
WM_operatortype_append(GREASE_PENCIL_OT_select_ends);
}
void ED_keymap_grease_pencil(wmKeyConfig *keyconf)