GPencil Fix: Added checks to ensure that copy/paste doesn't paste incompatible strokes
There was a problem with the copy/paste functionality, where it would be possible to paste 3d strokes into 2D editors, or 2D strokes into the 3D view. The problem with that though is that these will not show up, and because there's no feedback at the time, users may end up doing this pasting several times.
This commit is contained in:
parent
bd92168643
commit
c7c711bb72
|
@ -805,6 +805,30 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op)
|
|||
BKE_report(op->reports, RPT_ERROR, "Can not paste strokes when active layer is hidden or locked");
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
else {
|
||||
/* Check that some of the strokes in the buffer can be used */
|
||||
bGPDstroke *gps;
|
||||
bool ok = false;
|
||||
|
||||
for (gps = gp_strokes_copypastebuf.first; gps; gps = gps->next) {
|
||||
if (ED_gpencil_stroke_can_use(C, gps)) {
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ok == false) {
|
||||
/* XXX: this check is not 100% accurate (i.e. image editor is incompatible with normal 2D strokes),
|
||||
* but should be enough to give users a good idea of what's going on
|
||||
*/
|
||||
if (CTX_wm_area(C)->spacetype == SPACE_VIEW3D)
|
||||
BKE_report(op->reports, RPT_ERROR, "Cannot paste 2D strokes in 3D View");
|
||||
else
|
||||
BKE_report(op->reports, RPT_ERROR, "Cannot paste 3D strokes in 2D editors");
|
||||
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
}
|
||||
|
||||
/* Deselect all strokes first */
|
||||
CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
|
||||
|
@ -832,12 +856,14 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op)
|
|||
|
||||
/* Copy each stroke into the layer */
|
||||
for (gps = gp_strokes_copypastebuf.first; gps; gps = gps->next) {
|
||||
bGPDstroke *new_stroke = MEM_dupallocN(gps);
|
||||
|
||||
new_stroke->points = MEM_dupallocN(gps->points);
|
||||
new_stroke->next = new_stroke->prev = NULL;
|
||||
|
||||
BLI_addtail(&gpf->strokes, new_stroke);
|
||||
if (ED_gpencil_stroke_can_use(C, gps)) {
|
||||
bGPDstroke *new_stroke = MEM_dupallocN(gps);
|
||||
|
||||
new_stroke->points = MEM_dupallocN(gps->points);
|
||||
new_stroke->next = new_stroke->prev = NULL;
|
||||
|
||||
BLI_addtail(&gpf->strokes, new_stroke);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue