Commit: c7c711bb726b32ded12a921baffda3b434d44ddb
Author: Joshua Leung
Date:   Wed Feb 18 12:08:07 2015 +1300
Branches: master
https://developer.blender.org/rBc7c711bb726b32ded12a921baffda3b434d44ddb

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.

===================================================================

M       source/blender/editors/gpencil/gpencil_edit.c

===================================================================

diff --git a/source/blender/editors/gpencil/gpencil_edit.c 
b/source/blender/editors/gpencil/gpencil_edit.c
index a830253..212d384 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -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);
+                       }
                }
        }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to