GPencil: New Set Start point operator

This operator allows to set the start point for any cyclic stroke.

This is very handy to fit interpolation issues or
use thickness modifier.

Note: There is small change in this commit to fix
a typo error in the name of the operator.

Reviewed By: mendio, frogstomp

Maniphest Tasks: T100827

Differential Revision: https://developer.blender.org/D15881
This commit is contained in:
Antonio Vazquez 2022-09-10 15:42:17 +02:00
parent 2c23b4e0bf
commit 98c4e1e590
Notes: blender-bot 2023-02-14 05:22:18 +01:00
Referenced by issue #100827, GPencil: New operator to set Stroke start point
4 changed files with 98 additions and 0 deletions

View File

@ -5175,6 +5175,7 @@ class VIEW3D_MT_edit_gpencil_stroke(Menu):
layout.operator("gpencil.stroke_cyclical_set", text="Toggle Cyclic").type = 'TOGGLE'
layout.operator_menu_enum("gpencil.stroke_caps_set", text="Toggle Caps", property="type")
layout.operator("gpencil.stroke_flip", text="Switch Direction")
layout.operator("gpencil.stroke_start_set", text="Set Start Point")
layout.separator()
layout.operator("gpencil.stroke_normalize", text="Normalize Thickness").mode = 'THICKNESS'

View File

@ -3790,6 +3790,101 @@ void GPENCIL_OT_stroke_flip(wmOperatorType *ot)
/** \} */
/* -------------------------------------------------------------------- */
/** \name Stroke Start Set Operator
* \{ */
static int gpencil_stroke_start_set_exec(bContext *C, wmOperator *op)
{
Object *ob = CTX_data_active_object(C);
bGPdata *gpd = ob->data;
/* sanity checks */
if (ELEM(NULL, ob, gpd)) {
return OPERATOR_CANCELLED;
}
const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
const bool is_curve_edit = (bool)GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd);
if (is_curve_edit) {
BKE_report(op->reports, RPT_ERROR, "Curve Edit mode not supported");
return OPERATOR_CANCELLED;
}
bool changed = false;
/* Read all selected strokes. */
CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
if (gpf == NULL) {
continue;
}
LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
if (gps->flag & GP_STROKE_SELECT) {
/* skip strokes that are invalid for current view */
if (ED_gpencil_stroke_can_use(C, gps) == false) {
continue;
}
/* check if the color is editable */
if (ED_gpencil_stroke_material_editable(ob, gpl, gps) == false) {
continue;
}
/* Only cyclic strokes. */
if ((gps->flag & GP_STROKE_CYCLIC) == 0) {
continue;
}
/* Find first selected point and set start. */
bGPDspoint *pt;
for (int i = 0; i < gps->totpoints; i++) {
pt = &gps->points[i];
if (pt->flag & GP_SPOINT_SELECT) {
BKE_gpencil_stroke_start_set(gps, i);
BKE_gpencil_stroke_geometry_update(gpd, gps);
changed = true;
break;
}
}
}
}
}
/* If not multi-edit, exit loop. */
if (!is_multiedit) {
break;
}
}
}
CTX_DATA_END;
if (changed) {
/* notifiers */
DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
}
return OPERATOR_FINISHED;
}
void GPENCIL_OT_stroke_start_set(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Set Start Point";
ot->idname = "GPENCIL_OT_stroke_start_set";
ot->description = "Set start point for cyclic strokes";
/* api callbacks */
ot->exec = gpencil_stroke_start_set_exec;
ot->poll = gpencil_active_layer_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Stroke Re-project Operator
* \{ */

View File

@ -593,6 +593,7 @@ void GPENCIL_OT_stroke_cyclical_set(struct wmOperatorType *ot);
*/
void GPENCIL_OT_stroke_caps_set(struct wmOperatorType *ot);
void GPENCIL_OT_stroke_join(struct wmOperatorType *ot);
void GPENCIL_OT_stroke_start_set(struct wmOperatorType *ot);
void GPENCIL_OT_stroke_flip(struct wmOperatorType *ot);
void GPENCIL_OT_stroke_subdivide(struct wmOperatorType *ot);
void GPENCIL_OT_stroke_simplify(struct wmOperatorType *ot);

View File

@ -621,6 +621,7 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_stroke_caps_set);
WM_operatortype_append(GPENCIL_OT_stroke_join);
WM_operatortype_append(GPENCIL_OT_stroke_flip);
WM_operatortype_append(GPENCIL_OT_stroke_start_set);
WM_operatortype_append(GPENCIL_OT_stroke_subdivide);
WM_operatortype_append(GPENCIL_OT_stroke_simplify);
WM_operatortype_append(GPENCIL_OT_stroke_simplify_fixed);