GPv3: Show and hide layers operators #114348

Merged
Falk David merged 6 commits from mendio/blender:GPv3_Show_Hide_Layers into main 2023-12-01 12:55:39 +01:00
3 changed files with 119 additions and 1 deletions

View File

@ -4578,6 +4578,9 @@ def km_grease_pencil_paint(_params):
# Active layer
op_menu("GREASE_PENCIL_MT_layer_active", {"type": 'Y', "value": 'PRESS'}),
# Show/hide
*_template_items_hide_reveal_actions("grease_pencil.layer_hide", "grease_pencil.layer_reveal"),
])
return keymap
@ -4610,6 +4613,9 @@ def km_grease_pencil_edit(params):
# Keyframe Menu
op_menu("VIEW3D_MT_edit_greasepencil_animation", {"type": 'I', "value": 'PRESS'}),
# Show/hide
*_template_items_hide_reveal_actions("grease_pencil.layer_hide", "grease_pencil.layer_reveal"),
# Transform Actions.
*_template_items_transform_actions(params, use_bend=True, use_mirror=True, use_tosphere=True, use_shear=True),
("transform.transform", {"type": 'S', "value": 'PRESS', "alt": True},

View File

@ -2163,13 +2163,17 @@ class VIEW3D_MT_select_edit_grease_pencil(Menu):
class VIEW3D_MT_paint_grease_pencil(Menu):
bl_label = "Paint"
bl_label = "Draw"
def draw(self, _context):
layout = self.layout
layout.menu("GREASE_PENCIL_MT_layer_active", text="Active Layer")
layout.separator()
layout.menu("VIEW3D_MT_edit_greasepencil_showhide")
class VIEW3D_MT_paint_gpencil(Menu):
bl_label = "Paint"
@ -5802,6 +5806,19 @@ class VIEW3D_MT_edit_gpencil_showhide(Menu):
layout.operator("gpencil.hide", text="Hide Active Layer").unselected = False
layout.operator("gpencil.hide", text="Hide Inactive Layers").unselected = True
class VIEW3D_MT_edit_greasepencil_showhide(Menu):
bl_label = "Show/Hide"
def draw(self, _context):
layout = self.layout
layout.operator("grease_pencil.layer_reveal", text="Show All Layers")
layout.separator()
layout.operator("grease_pencil.layer_hide", text="Hide Active Layer").unselected = False
layout.operator("grease_pencil.layer_hide", text="Hide Inactive Layers").unselected = True
class VIEW3D_MT_edit_greasepencil(Menu):
bl_label = "Grease Pencil"
@ -5821,6 +5838,10 @@ class VIEW3D_MT_edit_greasepencil(Menu):
layout.separator()
layout.menu("VIEW3D_MT_edit_greasepencil_showhide")
layout.separator()
layout.menu("VIEW3D_MT_edit_greasepencil_delete")
@ -8803,6 +8824,7 @@ classes = (
VIEW3D_MT_edit_gpencil_point,
VIEW3D_MT_edit_gpencil_delete,
VIEW3D_MT_edit_gpencil_showhide,
VIEW3D_MT_edit_greasepencil_showhide,
VIEW3D_MT_weight_gpencil,
VIEW3D_MT_gpencil_animation,
VIEW3D_MT_gpencil_simplify,

View File

@ -281,6 +281,94 @@ static void GREASE_PENCIL_OT_layer_group_add(wmOperatorType *ot)
ot->prop = prop;
}
static int grease_pencil_layer_hide_exec(bContext *C, wmOperator *op)
{
using namespace blender::bke::greasepencil;
Object *object = CTX_data_active_object(C);
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
const bool unselected = RNA_boolean_get(op->ptr, "unselected");
if (!grease_pencil.has_active_layer()) {
return OPERATOR_CANCELLED;
}
if (unselected) {
/* hide unselected */
for (Layer *layer : grease_pencil.layers_for_write()) {
const bool is_active = grease_pencil.is_layer_active(layer);
layer->set_visible(is_active);
}
}
else {
/* hide selected/active */
Layer &active_layer = *grease_pencil.get_active_layer_for_write();
active_layer.set_visible(false);
}
/* notifiers */
DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
mendio marked this conversation as resolved
Review

this is unused now. We can remove it

this is unused now. We can remove it
WM_event_add_notifier(C, NC_GEOM | ND_DATA, &grease_pencil);
return OPERATOR_FINISHED;
}
static void GREASE_PENCIL_OT_layer_hide(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Hide Layer(s)";
mendio marked this conversation as resolved
Review

select property should select points of revealed layers.
As far as I understand,set_selected() selects the layer, which is wrong.

`select` property should select points of revealed layers. As far as I understand,`set_selected()` selects the layer, which is wrong.
Review

You are right, in GPv2 the behaviour is that when you unhide a Layer all the strokes of the unhided Layer are selected. But this is destructive of all the selections you had in the Layer before it was hidden, IMO we should follow what meshes do and mantain selections.

You are right, in GPv2 the behaviour is that when you unhide a Layer all the strokes of the unhided Layer are selected. But this is destructive of all the selections you had in the Layer before it was hidden, IMO we should follow what meshes do and mantain selections.
Review

I removed Layer selection after unhide the layer

I removed Layer selection after unhide the layer
ot->idname = "GREASE_PENCIL_OT_layer_hide";
ot->description = "Hide selected/unselected Grease Pencil layers";
/* callbacks */
ot->exec = grease_pencil_layer_hide_exec;
ot->poll = active_grease_pencil_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* props */
PropertyRNA *prop = RNA_def_boolean(
ot->srna, "unselected", false, "Unselected", "Hide unselected rather than selected layers");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
ot->prop = prop;
}
static int grease_pencil_layer_reveal_exec(bContext *C, wmOperator *op)
{
using namespace blender::bke::greasepencil;
Object *object = CTX_data_active_object(C);
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
mendio marked this conversation as resolved Outdated

same here

same here
if (!grease_pencil.has_active_layer()) {
return OPERATOR_CANCELLED;
}
for (Layer *layer : grease_pencil.layers_for_write()) {
layer->set_visible(true);
}
/* notifiers */
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_layer_reveal(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Show All Layers";
ot->idname = "GREASE_PENCIL_OT_layer_reveal";
ot->description = "Show all Grease Pencil layers";
/* callbacks */
ot->exec = grease_pencil_layer_reveal_exec;
ot->poll = active_grease_pencil_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
} // namespace blender::ed::greasepencil
void ED_operatortypes_grease_pencil_layers()
@ -290,6 +378,8 @@ void ED_operatortypes_grease_pencil_layers()
WM_operatortype_append(GREASE_PENCIL_OT_layer_remove);
WM_operatortype_append(GREASE_PENCIL_OT_layer_reorder);
WM_operatortype_append(GREASE_PENCIL_OT_layer_active);
WM_operatortype_append(GREASE_PENCIL_OT_layer_hide);
WM_operatortype_append(GREASE_PENCIL_OT_layer_reveal);
WM_operatortype_append(GREASE_PENCIL_OT_layer_group_add);
}