GPencil Fix: Added checks to ensure that copy/paste doesn't paste incompatible strokes
authorJoshua Leung <aligorith@gmail.com>
Tue, 17 Feb 2015 23:08:07 +0000 (12:08 +1300)
committerJoshua Leung <aligorith@gmail.com>
Wed, 18 Feb 2015 01:49:41 +0000 (14:49 +1300)
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.

source/blender/editors/gpencil/gpencil_edit.c

index a830253f634d5bbd2b0261ab9c0e3ef2865890cb..212d384e5caa86861f36f84adc35b9951cd5ab2d 100644 (file)
@@ -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);
+                       }
                }
        }