Commit: 967c5b7da55507b8302b65a7dc813449321232c4 Author: Falk David Date: Tue Jul 7 12:27:22 2020 +0200 Branches: soc-2020-greasepencil-curve https://developer.blender.org/rB967c5b7da55507b8302b65a7dc813449321232c4
GPencil: Adapt select operators to curve edit mode All select operators now check if curve edit mode is active. These include GPENCIL_OT_select, GPENCIL_OT_select_all, GPENCIL_OT_select_circle, GPENCIL_OT_select_box, GPENCIL_OT_select_lasso, GPENCIL_OT_select_linked, GPENCIL_OT_select_grouped, GPENCIL_OT_select_more, GPENCIL_OT_select_less, GPENCIL_OT_select_first, GPENCIL_OT_select_last, GPENCIL_OT_select_alternate and GPENCIL_OT_select_vertex_color =================================================================== M source/blender/editors/gpencil/gpencil_select.c =================================================================== diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c index a5af22dc502..6dc7228b70a 100644 --- a/source/blender/editors/gpencil/gpencil_select.c +++ b/source/blender/editors/gpencil/gpencil_select.c @@ -151,6 +151,7 @@ static int gpencil_select_all_exec(bContext *C, wmOperator *op) { bGPdata *gpd = ED_gpencil_data_get_active(C); int action = RNA_enum_get(op->ptr, "action"); + const bool is_curve_edit = (bool)GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd); if (gpd == NULL) { BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data"); @@ -170,7 +171,7 @@ static int gpencil_select_all_exec(bContext *C, wmOperator *op) } } - if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) { + if (is_curve_edit) { ED_gpencil_select_curve_toggle_all(C, action); } else { @@ -188,7 +189,6 @@ static int gpencil_select_all_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } - void GPENCIL_OT_select_all(wmOperatorType *ot) { /* identifiers */ @@ -215,6 +215,7 @@ void GPENCIL_OT_select_all(wmOperatorType *ot) static int gpencil_select_linked_exec(bContext *C, wmOperator *op) { bGPdata *gpd = ED_gpencil_data_get_active(C); + const bool is_curve_edit = (bool)GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd); if (gpd == NULL) { BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data"); @@ -226,7 +227,7 @@ static int gpencil_select_linked_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) { + if (is_curve_edit) { GP_EDITABLE_CURVES_BEGIN(gps_iter, C, gpl, gps, gpc) { if (gpc->flag & GP_CURVE_SELECT) { @@ -289,8 +290,9 @@ void GPENCIL_OT_select_linked(wmOperatorType *ot) static int gpencil_select_alternate_exec(bContext *C, wmOperator *op) { - const bool unselect_ends = RNA_boolean_get(op->ptr, "unselect_ends"); bGPdata *gpd = ED_gpencil_data_get_active(C); + const bool unselect_ends = RNA_boolean_get(op->ptr, "unselect_ends"); + const bool is_curve_edit = (bool)GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd); if (gpd == NULL) { BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data"); @@ -302,47 +304,58 @@ static int gpencil_select_alternate_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - /* select all points in selected strokes */ - CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) { - if ((gps->flag & GP_STROKE_SELECT) && (gps->totpoints > 1)) { - bGPDspoint *pt; - int row = 0; - int start = 0; - if (unselect_ends) { - start = 1; - } + bool changed = false; + if (is_curve_edit) { + /* TODO: do curve select */ + } + else { + /* select all points in selected strokes */ + CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) { + if ((gps->flag & GP_STROKE_SELECT) && (gps->totpoints > 1)) { + bGPDspoint *pt; + int row = 0; + int start = 0; + if (unselect_ends) { + start = 1; + } - for (int i = start; i < gps->totpoints; i++) { - pt = &gps->points[i]; - if ((row % 2) == 0) { - pt->flag |= GP_SPOINT_SELECT; + for (int i = start; i < gps->totpoints; i++) { + pt = &gps->points[i]; + if ((row % 2) == 0) { + pt->flag |= GP_SPOINT_SELECT; + } + else { + pt->flag &= ~GP_SPOINT_SELECT; + } + row++; } - else { + + /* unselect start and end points */ + if (unselect_ends) { + pt = &gps->points[0]; pt->flag &= ~GP_SPOINT_SELECT; - } - row++; - } - /* unselect start and end points */ - if (unselect_ends) { - pt = &gps->points[0]; - pt->flag &= ~GP_SPOINT_SELECT; + pt = &gps->points[gps->totpoints - 1]; + pt->flag &= ~GP_SPOINT_SELECT; + } - pt = &gps->points[gps->totpoints - 1]; - pt->flag &= ~GP_SPOINT_SELECT; + changed = true; } } + CTX_DATA_END; } - CTX_DATA_END; - /* updates */ - DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY); + if (changed) { + /* updates */ + DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY); - /* copy on write tag is needed, or else no refresh happens */ - DEG_id_tag_update(&gpd->id, ID_RECALC_COPY_ON_WRITE); + /* copy on write tag is needed, or else no refresh happens */ + DEG_id_tag_update(&gpd->id, ID_RECALC_COPY_ON_WRITE); + + WM_event_add_notifier(C, NC_GPENCIL | NA_SELECTED, NULL); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL); + } - WM_event_add_notifier(C, NC_GPENCIL | NA_SELECTED, NULL); - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL); return OPERATOR_FINISHED; } @@ -389,84 +402,110 @@ typedef enum eGP_SelectGrouped { /* ----------------------------------- */ /* On each visible layer, check for selected strokes - if found, select all others */ -static void gpencil_select_same_layer(bContext *C) +static bool gpencil_select_same_layer(bContext *C) { Scene *scene = CTX_data_scene(C); + Object *ob = CTX_data_active_object(C); + bGPdata *gpd = ED_gpencil_data_get_active(C); + const bool is_curve_edit = (bool)GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd); - CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { - bGPDframe *gpf = BKE_gpencil_layer_frame_get(gpl, CFRA, GP_GETFRAME_USE_PREV); - bGPDstroke *gps; - bool found = false; - - if (gpf == NULL) { - continue; - } + bool changed = false; + if (is_curve_edit) { + /* TODO: do curve select */ + } + else { + CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { + bGPDframe *gpf = BKE_gpencil_layer_frame_get(gpl, CFRA, GP_GETFRAME_USE_PREV); + bGPDstroke *gps; + bool found = false; - /* Search for a selected stroke */ - for (gps = gpf->strokes.first; gps; gps = gps->next) { - if (ED_gpencil_stroke_can_use(C, gps)) { - if (gps->flag & GP_STROKE_SELECT) { - found = true; - break; - } + if (gpf == NULL) { + continue; } - } - /* Select all if found */ - if (found) { + /* Search for a selected stroke */ for (gps = gpf->strokes.first; gps; gps = gps->next) { if (ED_gpencil_stroke_can_use(C, gps)) { - bGPDspoint *pt; - int i; - - for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { - pt->flag |= GP_SPOINT_SELECT; + if (gps->flag & GP_STROKE_SELECT) { + found = true; + break; } + } + } + + /* Select all if found */ + if (found) { + for (gps = gpf->strokes.first; gps; gps = gps->next) { + if (ED_gpencil_stroke_can_use(C, gps)) { + bGPDspoint *pt; + int i; + + for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { + pt->flag |= GP_SPOINT_SELECT; + } + + gps->flag |= GP_STROKE_SELECT; - gps->flag |= GP_STROKE_SELECT; + changed = true; + } } } } + CTX_DATA_END; } - CTX_DATA_END; + + return changed; } /* Select all strokes with same colors as selected ones */ -static void gpencil_select_same_material(bContext *C) +static bool gpencil_select_same_material(bContext *C) { + Object *ob = CTX_data_active_object(C); + bGPdata *gpd = ED_gpencil_data_get_active(C); + const bool is_curve_edit = (bool)GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd); /* First, build set containing all the colors of selected strokes */ GSet *selected_colors = BLI_gset_str_new("GP Selected Colors"); - CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) { - if (gps->flag & GP_STROKE_SELECT) { - /* add instead of insert here, otherwise the uniqueness check gets skipped, - * and we get many duplicate entries... - */ - BLI_gset_add(selected_colors, &gps->mat_nr); - } + bool changed = false; + if (is_curve_edit) { + /* TODO: do curve select */ } - CTX_DATA_END; + else { + CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) { + if (gps->flag & GP_STROKE_SELECT) { + /* add instead of insert here, otherwise the uniqueness check gets skipped, + * and we get many duplicate entries... + */ + BLI_gset_add(selected_colors, &gps->mat_nr); + } + } + CTX_DATA_END; - /* Second, select any visible stroke that uses these colors */ - CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) { - if (BLI_gset_haskey(selected_colors, &gps->mat_nr)) { - /* select this stroke */ - bGPDspoint *pt; - int i; + /* Second, select any visible stroke that uses these colors */ + CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) { + if (BLI_gset_haskey(selected_colors, &gps->mat_nr)) { + /* select this stroke */ + bGPDspoint *pt; + int i; - for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { - pt->flag |= GP_SPOINT_SELECT; - } + for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { + pt->flag |= GP_SPOINT_SELECT; + } - gps->flag |= GP_STROKE_SELECT; + gps->flag |= GP_STROKE_SELECT; + + changed = true; + } } + CTX_DATA_END; } - CTX_DATA_END; /* free memomy */ if (selected_colors != NULL) { BLI_gset_free(selected_colors, NULL); } + + return changed; } /* ----------------------------------- */ @@ -480,12 +519,14 @@ static int gpencil_select_grouped_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } + bool changed = false; + switch (mode) { case GP_SEL_SAME_LAYER: - gpencil_select_same_layer(C); + changed = gpencil_select_same_layer(C); break; case GP_SEL_SAME_MATERIAL: - gpencil_select_same_material(C); + changed = gpencil_select_same_material(C); break; default: @@ -493,14 +534,16 @@ static int gpencil_select_grouped_exec(bContext *C, wmOperator *op) break; } - /* updates */ - DEG_id_tag_update(&gpd->id, ID_RECALC_ @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs