GPv3: Select strokes by material operator
Port legacy gp operator `GPENCIL_OT_material_select` Pull Request: https://projects.blender.org/blender/blender/pulls/118652
This commit is contained in:
committed by
Pratik Borhade
parent
0a2544f2e8
commit
7ae8e1dc07
@@ -606,6 +606,8 @@ class GreasePencilMaterialsPanel:
|
||||
if is_grease_pencil_version3 and ob.mode == 'EDIT':
|
||||
row = layout.row(align=True)
|
||||
row.operator("grease_pencil.stroke_material_set", text="Assign")
|
||||
row.operator("grease_pencil.material_select", text="Select").deselect = False
|
||||
row.operator("grease_pencil.material_select", text="Deselect").deselect = True
|
||||
elif not is_grease_pencil_version3 and ob.data.use_stroke_edit_mode:
|
||||
row = layout.row(align=True)
|
||||
row.operator("gpencil.stroke_change_color", text="Assign")
|
||||
|
||||
@@ -459,6 +459,59 @@ static void GREASE_PENCIL_OT_set_selection_mode(wmOperatorType *ot)
|
||||
RNA_def_property_flag(prop, (PropertyFlag)(PROP_HIDDEN | PROP_SKIP_SAVE));
|
||||
}
|
||||
|
||||
static int grease_pencil_material_select_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
const Scene *scene = CTX_data_scene(C);
|
||||
Object *object = CTX_data_active_object(C);
|
||||
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
|
||||
const bool select = !RNA_boolean_get(op->ptr, "deselect");
|
||||
const int material_index = object->actcol - 1;
|
||||
|
||||
if (material_index == -1) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
const Vector<MutableDrawingInfo> drawings = retrieve_editable_drawings(*scene, grease_pencil);
|
||||
threading::parallel_for_each(drawings, [&](const MutableDrawingInfo &info) {
|
||||
bke::CurvesGeometry &curves = info.drawing.strokes_for_write();
|
||||
|
||||
IndexMaskMemory memory;
|
||||
const IndexMask strokes = retrieve_editable_strokes_by_material(
|
||||
*object, info.drawing, material_index, memory);
|
||||
if (strokes.is_empty()) {
|
||||
return;
|
||||
}
|
||||
bke::GSpanAttributeWriter selection = ed::curves::ensure_selection_attribute(
|
||||
curves, bke::AttrDomain::Curve, CD_PROP_BOOL);
|
||||
index_mask::masked_fill(selection.span.typed<bool>(), select, strokes);
|
||||
selection.finish();
|
||||
});
|
||||
|
||||
DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA | NA_EDITED, &grease_pencil);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
static void GREASE_PENCIL_OT_material_select(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name = "Select Material";
|
||||
ot->idname = "GREASE_PENCIL_OT_material_select";
|
||||
ot->description = "Select/Deselect all Grease Pencil strokes using current material";
|
||||
|
||||
/* callbacks. */
|
||||
ot->exec = grease_pencil_material_select_exec;
|
||||
ot->poll = editable_grease_pencil_poll;
|
||||
|
||||
/* flags. */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
/* props */
|
||||
ot->prop = RNA_def_boolean(ot->srna, "deselect", false, "Deselect", "Unselect strokes");
|
||||
RNA_def_property_flag(ot->prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
}
|
||||
|
||||
} // namespace blender::ed::greasepencil
|
||||
|
||||
blender::bke::AttrDomain ED_grease_pencil_selection_domain_get(const ToolSettings *tool_settings)
|
||||
@@ -485,4 +538,5 @@ void ED_operatortypes_grease_pencil_select()
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_select_alternate);
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_select_ends);
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_set_selection_mode);
|
||||
WM_operatortype_append(GREASE_PENCIL_OT_material_select);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user