Fix #132987: Grease Pencil: Ensure selection domain when switching modes
Grease Pencil tool settings could have different selection modes for different object modes (like edit mode and sculpt mode). This fix ensures when switching object modes, the selection domain is updated to match the selection mode. Pull Request: https://projects.blender.org/blender/blender/pulls/133030
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "BKE_context.hh"
|
||||
#include "BKE_curves.hh"
|
||||
#include "BKE_grease_pencil.hh"
|
||||
#include "BKE_object.hh"
|
||||
|
||||
#include "BLI_enumerable_thread_specific.hh"
|
||||
#include "BLI_offset_indices.hh"
|
||||
@@ -848,19 +849,11 @@ static void GREASE_PENCIL_OT_select_ends(wmOperatorType *ot)
|
||||
INT32_MAX);
|
||||
}
|
||||
|
||||
static int select_set_mode_exec(bContext *C, wmOperator *op)
|
||||
bool ensure_selection_domain(ToolSettings *ts, Object *object)
|
||||
{
|
||||
using namespace blender::bke::greasepencil;
|
||||
|
||||
/* Set new selection mode. */
|
||||
const int mode_new = RNA_enum_get(op->ptr, "mode");
|
||||
ToolSettings *ts = CTX_data_tool_settings(C);
|
||||
|
||||
bool changed = (mode_new != ts->gpencil_selectmode_edit);
|
||||
ts->gpencil_selectmode_edit = mode_new;
|
||||
bool changed = false;
|
||||
|
||||
/* Convert all drawings of the active GP to the new selection domain. */
|
||||
Object *object = CTX_data_active_object(C);
|
||||
const bke::AttrDomain domain = ED_grease_pencil_selection_domain_get(ts, object);
|
||||
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
|
||||
Span<GreasePencilDrawingBase *> drawings = grease_pencil.drawings();
|
||||
@@ -914,9 +907,38 @@ static int select_set_mode_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
static int select_set_mode_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
using namespace blender::bke::greasepencil;
|
||||
|
||||
/* Set new selection mode. */
|
||||
const int mode_new = RNA_enum_get(op->ptr, "mode");
|
||||
ToolSettings *ts = CTX_data_tool_settings(C);
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
|
||||
bool changed = false;
|
||||
if (BKE_object_is_mode_compat(ob, OB_MODE_EDIT)) {
|
||||
changed = (mode_new != ts->gpencil_selectmode_edit);
|
||||
ts->gpencil_selectmode_edit = mode_new;
|
||||
}
|
||||
else if (BKE_object_is_mode_compat(ob, OB_MODE_SCULPT_GREASE_PENCIL)) {
|
||||
changed = (mode_new != ts->gpencil_selectmode_sculpt);
|
||||
ts->gpencil_selectmode_sculpt = mode_new;
|
||||
}
|
||||
else if (BKE_object_is_mode_compat(ob, OB_MODE_VERTEX_GREASE_PENCIL)) {
|
||||
changed = (mode_new != ts->gpencil_selectmode_vertex);
|
||||
ts->gpencil_selectmode_vertex = mode_new;
|
||||
}
|
||||
|
||||
changed = changed || ensure_selection_domain(ts, ob);
|
||||
|
||||
if (changed) {
|
||||
/* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic
|
||||
* attribute for now. */
|
||||
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(ob->data);
|
||||
DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA, &grease_pencil);
|
||||
|
||||
|
||||
@@ -912,4 +912,7 @@ GreasePencil *from_context(bContext &C);
|
||||
bke::CurvesGeometry remove_points_and_split(const bke::CurvesGeometry &curves,
|
||||
const IndexMask &point_mask);
|
||||
|
||||
/* Make sure selection domain is updated to match the current selection mode. */
|
||||
bool ensure_selection_domain(ToolSettings *ts, Object *object);
|
||||
|
||||
} // namespace blender::ed::greasepencil
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
#include "ED_asset_menu_utils.hh"
|
||||
#include "ED_curve.hh"
|
||||
#include "ED_gpencil_legacy.hh"
|
||||
#include "ED_grease_pencil.hh"
|
||||
#include "ED_image.hh"
|
||||
#include "ED_keyframes_keylist.hh"
|
||||
#include "ED_lattice.hh"
|
||||
@@ -897,6 +898,7 @@ bool editmode_enter_ex(Main *bmain, Scene *scene, Object *ob, int flag)
|
||||
}
|
||||
else if (ob->type == OB_GREASE_PENCIL) {
|
||||
ok = true;
|
||||
blender::ed::greasepencil::ensure_selection_domain(scene->toolsettings, ob);
|
||||
WM_main_add_notifier(NC_SCENE | ND_MODE | NS_EDITMODE_GREASE_PENCIL, scene);
|
||||
}
|
||||
else if (ob->type == OB_POINTCLOUD) {
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "BKE_volume.hh"
|
||||
|
||||
#include "ED_gpencil_legacy.hh"
|
||||
#include "ED_grease_pencil.hh"
|
||||
#include "ED_object.hh"
|
||||
#include "ED_uvedit.hh"
|
||||
|
||||
@@ -792,52 +793,82 @@ static void rna_ToolSettings_snap_uv_mode_set(PointerRNA *ptr, int value)
|
||||
}
|
||||
}
|
||||
|
||||
static void rna_Gpencil_mask_point_update(bContext * /*C*/, PointerRNA *ptr)
|
||||
static void rna_Gpencil_mask_point_update(bContext *C, PointerRNA *ptr)
|
||||
{
|
||||
ToolSettings *ts = (ToolSettings *)ptr->data;
|
||||
|
||||
ts->gpencil_selectmode_sculpt &= ~GP_SCULPT_MASK_SELECTMODE_STROKE;
|
||||
ts->gpencil_selectmode_sculpt &= ~GP_SCULPT_MASK_SELECTMODE_SEGMENT;
|
||||
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
if (ob && ob->type == OB_GREASE_PENCIL) {
|
||||
blender::ed::greasepencil::ensure_selection_domain(ts, ob);
|
||||
}
|
||||
}
|
||||
|
||||
static void rna_Gpencil_mask_stroke_update(bContext * /*C*/, PointerRNA *ptr)
|
||||
static void rna_Gpencil_mask_stroke_update(bContext *C, PointerRNA *ptr)
|
||||
{
|
||||
ToolSettings *ts = (ToolSettings *)ptr->data;
|
||||
|
||||
ts->gpencil_selectmode_sculpt &= ~GP_SCULPT_MASK_SELECTMODE_POINT;
|
||||
ts->gpencil_selectmode_sculpt &= ~GP_SCULPT_MASK_SELECTMODE_SEGMENT;
|
||||
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
if (ob && ob->type == OB_GREASE_PENCIL) {
|
||||
blender::ed::greasepencil::ensure_selection_domain(ts, ob);
|
||||
}
|
||||
}
|
||||
|
||||
static void rna_Gpencil_mask_segment_update(bContext * /*C*/, PointerRNA *ptr)
|
||||
static void rna_Gpencil_mask_segment_update(bContext *C, PointerRNA *ptr)
|
||||
{
|
||||
ToolSettings *ts = (ToolSettings *)ptr->data;
|
||||
|
||||
ts->gpencil_selectmode_sculpt &= ~GP_SCULPT_MASK_SELECTMODE_POINT;
|
||||
ts->gpencil_selectmode_sculpt &= ~GP_SCULPT_MASK_SELECTMODE_STROKE;
|
||||
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
if (ob && ob->type == OB_GREASE_PENCIL) {
|
||||
blender::ed::greasepencil::ensure_selection_domain(ts, ob);
|
||||
}
|
||||
}
|
||||
|
||||
static void rna_Gpencil_vertex_mask_point_update(bContext * /*C*/, PointerRNA *ptr)
|
||||
static void rna_Gpencil_vertex_mask_point_update(bContext *C, PointerRNA *ptr)
|
||||
{
|
||||
ToolSettings *ts = (ToolSettings *)ptr->data;
|
||||
|
||||
ts->gpencil_selectmode_vertex &= ~GP_VERTEX_MASK_SELECTMODE_STROKE;
|
||||
ts->gpencil_selectmode_vertex &= ~GP_VERTEX_MASK_SELECTMODE_SEGMENT;
|
||||
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
if (ob && ob->type == OB_GREASE_PENCIL) {
|
||||
blender::ed::greasepencil::ensure_selection_domain(ts, ob);
|
||||
}
|
||||
}
|
||||
|
||||
static void rna_Gpencil_vertex_mask_stroke_update(bContext * /*C*/, PointerRNA *ptr)
|
||||
static void rna_Gpencil_vertex_mask_stroke_update(bContext *C, PointerRNA *ptr)
|
||||
{
|
||||
ToolSettings *ts = (ToolSettings *)ptr->data;
|
||||
|
||||
ts->gpencil_selectmode_vertex &= ~GP_VERTEX_MASK_SELECTMODE_POINT;
|
||||
ts->gpencil_selectmode_vertex &= ~GP_VERTEX_MASK_SELECTMODE_SEGMENT;
|
||||
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
if (ob && ob->type == OB_GREASE_PENCIL) {
|
||||
blender::ed::greasepencil::ensure_selection_domain(ts, ob);
|
||||
}
|
||||
}
|
||||
|
||||
static void rna_Gpencil_vertex_mask_segment_update(bContext * /*C*/, PointerRNA *ptr)
|
||||
static void rna_Gpencil_vertex_mask_segment_update(bContext *C, PointerRNA *ptr)
|
||||
{
|
||||
ToolSettings *ts = (ToolSettings *)ptr->data;
|
||||
|
||||
ts->gpencil_selectmode_vertex &= ~GP_VERTEX_MASK_SELECTMODE_POINT;
|
||||
ts->gpencil_selectmode_vertex &= ~GP_VERTEX_MASK_SELECTMODE_STROKE;
|
||||
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
if (ob && ob->type == OB_GREASE_PENCIL) {
|
||||
blender::ed::greasepencil::ensure_selection_domain(ts, ob);
|
||||
}
|
||||
}
|
||||
|
||||
static void rna_active_grease_pencil_update(bContext *C, PointerRNA * /*ptr*/)
|
||||
|
||||
Reference in New Issue
Block a user