[Bf-blender-cvs] [43ce8e63080] greasepencil-refactor: GPencil: Use BKE function to duplicate stroke

Antonio Vazquez noreply at git.blender.org
Tue Jan 21 10:51:36 CET 2020


Commit: 43ce8e630803a581c4da849c5f156d035b0fb1e4
Author: Antonio Vazquez
Date:   Tue Jan 21 09:20:48 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB43ce8e630803a581c4da849c5f156d035b0fb1e4

GPencil: Use BKE function to duplicate stroke

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

M	source/blender/editors/gpencil/editaction_gpencil.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_interpolate.c
M	source/blender/editors/gpencil/gpencil_sculpt_paint.c

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

diff --git a/source/blender/editors/gpencil/editaction_gpencil.c b/source/blender/editors/gpencil/editaction_gpencil.c
index 9136c36b35f..773d77b0592 100644
--- a/source/blender/editors/gpencil/editaction_gpencil.c
+++ b/source/blender/editors/gpencil/editaction_gpencil.c
@@ -502,14 +502,8 @@ bool ED_gpencil_anim_copybuf_paste(bAnimContext *ac, const short offset_mode)
          */
         for (gps = gpfs->strokes.first; gps; gps = gps->next) {
           /* make a copy of stroke, then of its points array */
-          gpsn = MEM_dupallocN(gps);
-          gpsn->points = MEM_dupallocN(gps->points);
-          if (gps->dvert != NULL) {
-            gpsn->dvert = MEM_dupallocN(gps->dvert);
-            BKE_gpencil_stroke_weights_duplicate(gps, gpsn);
-          }
-          /* duplicate triangle information */
-          gpsn->triangles = MEM_dupallocN(gps->triangles);
+          gpsn = BKE_gpencil_stroke_duplicate(gps, true);
+
           /* append stroke to frame */
           BLI_addtail(&gpf->strokes, gpsn);
         }
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 303e2c9e615..ae8d891fcb9 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -782,8 +782,7 @@ static void gp_duplicate_points(const bGPDstroke *gps,
         bGPDstroke *gpsd;
 
         /* make a stupid copy first of the entire stroke (to get the flags too) */
-        gpsd = MEM_dupallocN(gps);
-        gpsd->triangles = MEM_dupallocN(gps->triangles);
+        gpsd = BKE_gpencil_stroke_duplicate((bGPDstroke *)gps, false);
 
         /* saves original layer name */
         BLI_strncpy(gpsd->runtime.tmp_layerinfo, layername, sizeof(gpsd->runtime.tmp_layerinfo));
@@ -861,15 +860,9 @@ static int gp_duplicate_exec(bContext *C, wmOperator *op)
           bGPDstroke *gpsd;
 
           /* make direct copies of the stroke and its points */
-          gpsd = MEM_dupallocN(gps);
-          gpsd->triangles = MEM_dupallocN(gps->triangles);
+          gpsd = BKE_gpencil_stroke_duplicate(gps, true);
 
           BLI_strncpy(gpsd->runtime.tmp_layerinfo, gpl->info, sizeof(gpsd->runtime.tmp_layerinfo));
-          gpsd->points = MEM_dupallocN(gps->points);
-          if (gps->dvert != NULL) {
-            gpsd->dvert = MEM_dupallocN(gps->dvert);
-            BKE_gpencil_stroke_weights_duplicate(gps, gpsd);
-          }
 
           /* Initialize triangle information. */
           BKE_gpencil_stroke_geometry_update(gpsd);
@@ -981,8 +974,7 @@ static void gpencil_add_move_points(bGPDframe *gpf, bGPDstroke *gps)
     pt = &gps->points[i];
     if (pt->flag == GP_SPOINT_SELECT) {
       /* duplicate original stroke data */
-      bGPDstroke *gps_new = MEM_dupallocN(gps);
-      gps_new->triangles = MEM_dupallocN(gps->triangles);
+      bGPDstroke *gps_new = BKE_gpencil_stroke_duplicate(gps, false);
       gps_new->prev = gps_new->next = NULL;
 
       /* add new points array */
@@ -1311,8 +1303,7 @@ static int gp_strokes_copy_exec(bContext *C, wmOperator *op)
           bGPDstroke *gpsd;
 
           /* make direct copies of the stroke and its points */
-          gpsd = MEM_dupallocN(gps);
-          gpsd->triangles = MEM_dupallocN(gps->triangles);
+          gpsd = BKE_gpencil_stroke_duplicate(gps, false);
 
           /* saves original layer name */
           BLI_strncpy(gpsd->runtime.tmp_layerinfo, gpl->info, sizeof(gpsd->runtime.tmp_layerinfo));
@@ -1502,7 +1493,7 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op)
       gpf = BKE_gpencil_layer_frame_get(gpl, CFRA, GP_GETFRAME_ADD_NEW);
       if (gpf) {
         /* Create new stroke */
-        bGPDstroke *new_stroke = MEM_dupallocN(gps);
+        bGPDstroke *new_stroke = BKE_gpencil_stroke_duplicate(gps, false);
         new_stroke->runtime.tmp_layerinfo[0] = '\0';
 
         new_stroke->points = MEM_dupallocN(gps->points);
@@ -2218,7 +2209,7 @@ static void gp_stroke_join_islands(bGPDframe *gpf, bGPDstroke *gps_first, bGPDst
   const int totpoints = gps_first->totpoints + gps_last->totpoints;
 
   /* create new stroke */
-  bGPDstroke *join_stroke = MEM_dupallocN(gps_first);
+  bGPDstroke *join_stroke = BKE_gpencil_stroke_duplicate(gps_first, false);
 
   join_stroke->points = MEM_callocN(sizeof(bGPDspoint) * totpoints, __func__);
   join_stroke->totpoints = totpoints;
@@ -2361,8 +2352,7 @@ void gp_stroke_delete_tagged_points(bGPDframe *gpf,
     /* Create each new stroke... */
     for (idx = 0; idx < num_islands; idx++) {
       tGPDeleteIsland *island = &islands[idx];
-      new_stroke = MEM_dupallocN(gps);
-      new_stroke->triangles = MEM_dupallocN(gps->triangles);
+      new_stroke = BKE_gpencil_stroke_duplicate(gps, false);
 
       /* if cyclic and first stroke, save to join later */
       if ((is_cyclic) && (gps_first == NULL)) {
@@ -3363,12 +3353,7 @@ static int gp_stroke_join_exec(bContext *C, wmOperator *op)
 
           /* create a new stroke if was not created before (only created if something to join) */
           if (new_stroke == NULL) {
-            new_stroke = MEM_dupallocN(stroke_a);
-            new_stroke->points = MEM_dupallocN(stroke_a->points);
-            if (stroke_a->dvert != NULL) {
-              new_stroke->dvert = MEM_dupallocN(stroke_a->dvert);
-              BKE_gpencil_stroke_weights_duplicate(stroke_a, new_stroke);
-            }
+            new_stroke = BKE_gpencil_stroke_duplicate(stroke_a, true);
 
             /* if new, set current color */
             if (type == GP_STROKE_JOINCOPY) {
diff --git a/source/blender/editors/gpencil/gpencil_interpolate.c b/source/blender/editors/gpencil/gpencil_interpolate.c
index 8a70ff30d3e..1da202064cf 100644
--- a/source/blender/editors/gpencil/gpencil_interpolate.c
+++ b/source/blender/editors/gpencil/gpencil_interpolate.c
@@ -594,12 +594,7 @@ static int gpencil_interpolate_modal(bContext *C, wmOperator *op, const wmEvent
           }
 
           /* make copy of source stroke, then adjust pointer to points too */
-          gps_dst = MEM_dupallocN(gps_src);
-          gps_dst->points = MEM_dupallocN(gps_src->points);
-          if (gps_src->dvert != NULL) {
-            gps_dst->dvert = MEM_dupallocN(gps_src->dvert);
-            BKE_gpencil_stroke_weights_duplicate(gps_src, gps_dst);
-          }
+          gps_dst = BKE_gpencil_stroke_duplicate(gps_src, true);
           /* Calc geometry data. */
           BKE_gpencil_stroke_geometry_update(gps_dst);
 
diff --git a/source/blender/editors/gpencil/gpencil_sculpt_paint.c b/source/blender/editors/gpencil/gpencil_sculpt_paint.c
index e8b6faee0ec..f95aba84b20 100644
--- a/source/blender/editors/gpencil/gpencil_sculpt_paint.c
+++ b/source/blender/editors/gpencil/gpencil_sculpt_paint.c
@@ -1106,14 +1106,7 @@ static void gp_brush_clone_add(bContext *C, tGP_BrushEditData *gso)
       bGPDframe *gpf = BKE_gpencil_layer_frame_get(gpl, CFRA, GP_GETFRAME_ADD_NEW);
 
       /* Make a new stroke */
-      new_stroke = MEM_dupallocN(gps);
-
-      new_stroke->points = MEM_dupallocN(gps->points);
-      if (gps->dvert != NULL) {
-        new_stroke->dvert = MEM_dupallocN(gps->dvert);
-        BKE_gpencil_stroke_weights_duplicate(gps, new_stroke);
-      }
-      new_stroke->triangles = MEM_dupallocN(gps->triangles);
+      new_stroke = BKE_gpencil_stroke_duplicate(gps, true);
 
       new_stroke->next = new_stroke->prev = NULL;
       BLI_addtail(&gpf->strokes, new_stroke);



More information about the Bf-blender-cvs mailing list