[Bf-blender-cvs] [9c4c3fbabc4] master: GPencil: Make Layer and Frame duplicate functions more flexible

Antonio Vazquez noreply at git.blender.org
Thu Jan 21 16:09:44 CET 2021


Commit: 9c4c3fbabc4f1d535d77f2219db7aedcae222ac9
Author: Antonio Vazquez
Date:   Thu Jan 21 15:57:10 2021 +0100
Branches: master
https://developer.blender.org/rB9c4c3fbabc4f1d535d77f2219db7aedcae222ac9

GPencil: Make Layer and Frame duplicate functions more flexible

Now it's possible to copy only part of the data. This will be used in future operators.

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenloader/intern/versioning_290.c
M	source/blender/editors/gpencil/editaction_gpencil.c
M	source/blender/editors/gpencil/gpencil_interpolate.c
M	source/blender/editors/gpencil/gpencil_undo.c
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 8903abee432..b7fad9c891a 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -109,8 +109,11 @@ struct bGPDframe *BKE_gpencil_frame_addcopy(struct bGPDlayer *gpl, int cframe);
 struct bGPDlayer *BKE_gpencil_layer_addnew(struct bGPdata *gpd, const char *name, bool setactive);
 struct bGPdata *BKE_gpencil_data_addnew(struct Main *bmain, const char name[]);
 
-struct bGPDframe *BKE_gpencil_frame_duplicate(const struct bGPDframe *gpf_src);
-struct bGPDlayer *BKE_gpencil_layer_duplicate(const struct bGPDlayer *gpl_src);
+struct bGPDframe *BKE_gpencil_frame_duplicate(const struct bGPDframe *gpf_src,
+                                              const bool dup_strokes);
+struct bGPDlayer *BKE_gpencil_layer_duplicate(const struct bGPDlayer *gpl_src,
+                                              const bool dup_frames,
+                                              const bool dup_strokes);
 void BKE_gpencil_frame_copy_strokes(struct bGPDframe *gpf_src, struct bGPDframe *gpf_dst);
 struct bGPDcurve *BKE_gpencil_stroke_curve_duplicate(struct bGPDcurve *gpc_src);
 struct bGPDstroke *BKE_gpencil_stroke_duplicate(struct bGPDstroke *gps_src,
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 453960fbd61..0eb154bf991 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -93,7 +93,7 @@ static void greasepencil_copy_data(Main *UNUSED(bmain),
     /* make a copy of source layer and its data */
 
     /* TODO here too could add unused flags... */
-    bGPDlayer *gpl_dst = BKE_gpencil_layer_duplicate(gpl_src);
+    bGPDlayer *gpl_dst = BKE_gpencil_layer_duplicate(gpl_src, true, true);
 
     /* Apply local layer transform to all frames. Calc the active frame is not enough
      * because onion skin can use more frames. This is more slow but required here. */
@@ -607,7 +607,7 @@ bGPDframe *BKE_gpencil_frame_addcopy(bGPDlayer *gpl, int cframe)
   }
 
   /* Create a copy of the frame */
-  new_frame = BKE_gpencil_frame_duplicate(gpl->actframe);
+  new_frame = BKE_gpencil_frame_duplicate(gpl->actframe, true);
 
   /* Find frame to insert it before */
   LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
@@ -991,7 +991,7 @@ bGPDstroke *BKE_gpencil_stroke_duplicate(bGPDstroke *gps_src,
  * \param gpf_src: Source grease pencil frame
  * \return Pointer to new frame
  */
-bGPDframe *BKE_gpencil_frame_duplicate(const bGPDframe *gpf_src)
+bGPDframe *BKE_gpencil_frame_duplicate(const bGPDframe *gpf_src, const bool dup_strokes)
 {
   bGPDstroke *gps_dst = NULL;
   bGPDframe *gpf_dst;
@@ -1005,12 +1005,14 @@ bGPDframe *BKE_gpencil_frame_duplicate(const bGPDframe *gpf_src)
   gpf_dst = MEM_dupallocN(gpf_src);
   gpf_dst->prev = gpf_dst->next = NULL;
 
-  /* copy strokes */
+  /* Copy strokes. */
   BLI_listbase_clear(&gpf_dst->strokes);
-  LISTBASE_FOREACH (bGPDstroke *, gps_src, &gpf_src->strokes) {
-    /* make copy of source stroke */
-    gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true, true);
-    BLI_addtail(&gpf_dst->strokes, gps_dst);
+  if (dup_strokes) {
+    LISTBASE_FOREACH (bGPDstroke *, gps_src, &gpf_src->strokes) {
+      /* make copy of source stroke */
+      gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true, true);
+      BLI_addtail(&gpf_dst->strokes, gps_dst);
+    }
   }
 
   /* return new frame */
@@ -1044,7 +1046,9 @@ void BKE_gpencil_frame_copy_strokes(bGPDframe *gpf_src, struct bGPDframe *gpf_ds
  * \param gpl_src: Source grease pencil layer
  * \return Pointer to new layer
  */
-bGPDlayer *BKE_gpencil_layer_duplicate(const bGPDlayer *gpl_src)
+bGPDlayer *BKE_gpencil_layer_duplicate(const bGPDlayer *gpl_src,
+                                       const bool dup_frames,
+                                       const bool dup_strokes)
 {
   const bGPDframe *gpf_src;
   bGPDframe *gpf_dst;
@@ -1069,14 +1073,16 @@ bGPDlayer *BKE_gpencil_layer_duplicate(const bGPDlayer *gpl_src)
 
   /* copy frames */
   BLI_listbase_clear(&gpl_dst->frames);
-  for (gpf_src = gpl_src->frames.first; gpf_src; gpf_src = gpf_src->next) {
-    /* make a copy of source frame */
-    gpf_dst = BKE_gpencil_frame_duplicate(gpf_src);
-    BLI_addtail(&gpl_dst->frames, gpf_dst);
-
-    /* if source frame was the current layer's 'active' frame, reassign that too */
-    if (gpf_src == gpl_dst->actframe) {
-      gpl_dst->actframe = gpf_dst;
+  if (dup_frames) {
+    for (gpf_src = gpl_src->frames.first; gpf_src; gpf_src = gpf_src->next) {
+      /* make a copy of source frame */
+      gpf_dst = BKE_gpencil_frame_duplicate(gpf_src, dup_strokes);
+      BLI_addtail(&gpl_dst->frames, gpf_dst);
+
+      /* if source frame was the current layer's 'active' frame, reassign that too */
+      if (gpf_src == gpl_dst->actframe) {
+        gpl_dst->actframe = gpf_dst;
+      }
     }
   }
 
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index ff82dab3405..627eecddeaa 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -475,7 +475,7 @@ void do_versions_after_linking_290(Main *bmain, ReportList *UNUSED(reports))
         LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
           bGPDframe *gpf = gpl->frames.first;
           if (gpf && gpf->framenum > scene->r.sfra) {
-            bGPDframe *gpf_dup = BKE_gpencil_frame_duplicate(gpf);
+            bGPDframe *gpf_dup = BKE_gpencil_frame_duplicate(gpf, true);
             gpf_dup->framenum = scene->r.sfra;
             BLI_addhead(&gpl->frames, gpf_dup);
           }
diff --git a/source/blender/editors/gpencil/editaction_gpencil.c b/source/blender/editors/gpencil/editaction_gpencil.c
index aae31b11025..166111c582c 100644
--- a/source/blender/editors/gpencil/editaction_gpencil.c
+++ b/source/blender/editors/gpencil/editaction_gpencil.c
@@ -276,7 +276,7 @@ void ED_gpencil_layer_frames_duplicate(bGPDlayer *gpl)
       bGPDframe *gpfd;
 
       /* duplicate frame, and deselect self */
-      gpfd = BKE_gpencil_frame_duplicate(gpf);
+      gpfd = BKE_gpencil_frame_duplicate(gpf, true);
       gpf->flag &= ~GP_FRAME_SELECT;
 
       BLI_insertlinkafter(&gpl->frames, gpf, gpfd);
@@ -361,7 +361,7 @@ bool ED_gpencil_anim_copybuf_copy(bAnimContext *ac)
       /* if frame is selected, make duplicate it and its strokes */
       if (gpf->flag & GP_FRAME_SELECT) {
         /* make a copy of this frame */
-        bGPDframe *new_frame = BKE_gpencil_frame_duplicate(gpf);
+        bGPDframe *new_frame = BKE_gpencil_frame_duplicate(gpf, true);
         BLI_addtail(&copied_frames, new_frame);
 
         /* extend extents for keyframes encountered */
diff --git a/source/blender/editors/gpencil/gpencil_interpolate.c b/source/blender/editors/gpencil/gpencil_interpolate.c
index 9a952e1a54b..fd0d5656448 100644
--- a/source/blender/editors/gpencil/gpencil_interpolate.c
+++ b/source/blender/editors/gpencil/gpencil_interpolate.c
@@ -283,8 +283,8 @@ static void gpencil_interpolate_set_points(bContext *C, tGPDinterpolate *tgpi)
     tgpil = MEM_callocN(sizeof(tGPDinterpolate_layer), "GPencil Interpolate Layer");
 
     tgpil->gpl = gpl;
-    tgpil->prevFrame = BKE_gpencil_frame_duplicate(gpl->actframe);
-    tgpil->nextFrame = BKE_gpencil_frame_duplicate(gpl->actframe->next);
+    tgpil->prevFrame = BKE_gpencil_frame_duplicate(gpl->actframe, true);
+    tgpil->nextFrame = BKE_gpencil_frame_duplicate(gpl->actframe->next, true);
 
     BLI_addtail(&tgpi->ilayers, tgpil);
 
@@ -998,8 +998,8 @@ static int gpencil_interpolate_seq_exec(bContext *C, wmOperator *op)
     }
 
     /* store extremes */
-    prevFrame = BKE_gpencil_frame_duplicate(gpl->actframe);
-    nextFrame = BKE_gpencil_frame_duplicate(gpl->actframe->next);
+    prevFrame = BKE_gpencil_frame_duplicate(gpl->actframe, true);
+    nextFrame = BKE_gpencil_frame_duplicate(gpl->actframe->next, true);
 
     /* Loop over intermediary frames and create the interpolation */
     for (cframe = prevFrame->framenum + step; cframe < nextFrame->framenum; cframe += step) {
diff --git a/source/blender/editors/gpencil/gpencil_undo.c b/source/blender/editors/gpencil/gpencil_undo.c
index d9bc77c8715..e545a3365e9 100644
--- a/source/blender/editors/gpencil/gpencil_undo.c
+++ b/source/blender/editors/gpencil/gpencil_undo.c
@@ -93,7 +93,7 @@ int ED_undo_gpencil_step(bContext *C, const int step)
 
         LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
           /* make a copy of source layer and its data */
-          gpld = BKE_gpencil_layer_duplicate(gpl);
+          gpld = BKE_gpencil_layer_duplicate(gpl, true, true);
           BLI_addtail(&gpd->layers, gpld);
         }
       }
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index dec25c0143f..209dc21d386 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -950,7 +950,7 @@ static void rna_GPencil_frame_remove(bGPDlayer *layer, ReportList *reports, Poin
 
 static bGPDframe *rna_GPencil_frame_copy(bGPDlayer *layer, bGPDframe *src)
 {
-  bGPDframe *frame = BKE_gpencil_frame_duplicate(src);
+  bGPDframe *frame = BKE_gpencil_frame_duplicate(src, true);
 
   while (BKE_gpencil_layer_frame_find(layer, frame->framenum)) {
     frame->framenum++;



More information about the Bf-blender-cvs mailing list