[Bf-blender-cvs] [c62bc08f45b] soc-2020-greasepencil-curve: GPencil: Adapt edit operators to curve edit mode

Falk David noreply at git.blender.org
Tue Jul 7 17:27:13 CEST 2020


Commit: c62bc08f45b7714c889c147d87a3f8a145984d33
Author: Falk David
Date:   Tue Jul 7 17:25:50 2020 +0200
Branches: soc-2020-greasepencil-curve
https://developer.blender.org/rBc62bc08f45b7714c889c147d87a3f8a145984d33

GPencil: Adapt edit operators to curve edit mode

Currently all operators do nothing in curve edit mode, but they should
work normally in edit mode. This is the first step of implementing
the operators in curve edit mode.

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

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

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

diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 96b0296a7de..40f71031dde 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -3324,7 +3324,7 @@ static int gpencil_set_active_material_exec(bContext *C, wmOperator *op)
 {
   Object *ob = CTX_data_active_object(C);
   bGPdata *gpd = ED_gpencil_data_get_active(C);
-  bool changed = false;
+  const bool is_curve_edit = (bool)GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd);
 
   /* Sanity checks. */
   if (gpd == NULL) {
@@ -3332,17 +3332,23 @@ static int gpencil_set_active_material_exec(bContext *C, wmOperator *op)
     return OPERATOR_CANCELLED;
   }
 
-  /* Loop all selected strokes. */
-  GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) {
-    if (gps->flag & GP_STROKE_SELECT) {
-      /* Change Active material. */
-      ob->actcol = gps->mat_nr + 1;
-      changed = true;
-      break;
+  bool changed = false;
+  if (is_curve_edit) {
+    /* TODO: set curve stroke material */
+  }
+  else {
+    /* Loop all selected strokes. */
+    GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) {
+      if (gps->flag & GP_STROKE_SELECT) {
+        /* Change Active material. */
+        ob->actcol = gps->mat_nr + 1;
+        changed = true;
+        break;
+      }
     }
+    GP_EDITABLE_STROKES_END(gpstroke_iter);
   }
-  GP_EDITABLE_STROKES_END(gpstroke_iter);
-
+  
   /* notifiers */
   if (changed) {
     WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index bcce94ca5eb..e5095ebb768 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -803,9 +803,9 @@ void GPENCIL_OT_selection_opacity_toggle(wmOperatorType *ot)
 
 /* Make copies of selected point segments in a selected stroke */
 static void gpencil_duplicate_points(bGPdata *gpd,
-                                const bGPDstroke *gps,
-                                ListBase *new_strokes,
-                                const char *layername)
+                                     const bGPDstroke *gps,
+                                     ListBase *new_strokes,
+                                     const char *layername)
 {
   bGPDspoint *pt;
   int i;
@@ -884,6 +884,7 @@ static void gpencil_duplicate_points(bGPdata *gpd,
 static int gpencil_duplicate_exec(bContext *C, wmOperator *op)
 {
   bGPdata *gpd = ED_gpencil_data_get_active(C);
+  const bool is_curve_edit = (bool)GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd);
 
   if (gpd == NULL) {
     BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data");
@@ -895,65 +896,74 @@ static int gpencil_duplicate_exec(bContext *C, wmOperator *op)
     return OPERATOR_CANCELLED;
   }
 
-  /* for each visible (and editable) layer's selected strokes,
-   * copy the strokes into a temporary buffer, then append
-   * once all done
-   */
-  CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
-    ListBase new_strokes = {NULL, NULL};
-    bGPDframe *gpf = gpl->actframe;
-    bGPDstroke *gps;
-
-    if (gpf == NULL) {
-      continue;
-    }
+  bool changed = false;
+  if (is_curve_edit) {
+    /* TODO: handle copy in curve edit mode */
+  }
+  else {
+    /* for each visible (and editable) layer's selected strokes,
+     * copy the strokes into a temporary buffer, then append
+     * once all done
+     */
+    CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
+      ListBase new_strokes = {NULL, NULL};
+      bGPDframe *gpf = gpl->actframe;
+      bGPDstroke *gps;
 
-    /* make copies of selected strokes, and deselect these once we're done */
-    for (gps = gpf->strokes.first; gps; gps = gps->next) {
-      /* skip strokes that are invalid for current view */
-      if (ED_gpencil_stroke_can_use(C, gps) == false) {
+      if (gpf == NULL) {
         continue;
       }
 
-      if (gps->flag & GP_STROKE_SELECT) {
-        if (gps->totpoints == 1) {
-          /* Special Case: If there's just a single point in this stroke... */
-          bGPDstroke *gpsd;
+      /* make copies of selected strokes, and deselect these once we're done */
+      for (gps = gpf->strokes.first; gps; gps = gps->next) {
+        /* skip strokes that are invalid for current view */
+        if (ED_gpencil_stroke_can_use(C, gps) == false) {
+          continue;
+        }
 
-          /* make direct copies of the stroke and its points */
-          gpsd = BKE_gpencil_stroke_duplicate(gps, true);
+        if (gps->flag & GP_STROKE_SELECT) {
+          if (gps->totpoints == 1) {
+            /* Special Case: If there's just a single point in this stroke... */
+            bGPDstroke *gpsd;
 
-          BLI_strncpy(gpsd->runtime.tmp_layerinfo, gpl->info, sizeof(gpsd->runtime.tmp_layerinfo));
+            /* make direct copies of the stroke and its points */
+            gpsd = BKE_gpencil_stroke_duplicate(gps, true);
 
-          /* Initialize triangle information. */
-          BKE_gpencil_stroke_geometry_update(gpd, gpsd);
+            BLI_strncpy(
+                gpsd->runtime.tmp_layerinfo, gpl->info, sizeof(gpsd->runtime.tmp_layerinfo));
 
-          /* add to temp buffer */
-          gpsd->next = gpsd->prev = NULL;
-          BLI_addtail(&new_strokes, gpsd);
-        }
-        else {
-          /* delegate to a helper, as there's too much to fit in here (for copying subsets)... */
-          gpencil_duplicate_points(gpd, gps, &new_strokes, gpl->info);
-        }
+            /* Initialize triangle information. */
+            BKE_gpencil_stroke_geometry_update(gpd, gpsd);
 
-        /* deselect original stroke, or else the originals get moved too
-         * (when using the copy + move macro)
-         */
-        bGPDspoint *pt;
-        int i;
-        for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
-          pt->flag &= ~GP_SPOINT_SELECT;
+            /* add to temp buffer */
+            gpsd->next = gpsd->prev = NULL;
+            BLI_addtail(&new_strokes, gpsd);
+          }
+          else {
+            /* delegate to a helper, as there's too much to fit in here (for copying subsets)... */
+            gpencil_duplicate_points(gpd, gps, &new_strokes, gpl->info);
+          }
+
+          /* deselect original stroke, or else the originals get moved too
+           * (when using the copy + move macro)
+           */
+          bGPDspoint *pt;
+          int i;
+          for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+            pt->flag &= ~GP_SPOINT_SELECT;
+          }
+          gps->flag &= ~GP_STROKE_SELECT;
+
+          changed = true;
         }
-        gps->flag &= ~GP_STROKE_SELECT;
       }
-    }
 
-    /* add all new strokes in temp buffer to the frame (preventing double-copies) */
-    BLI_movelisttolist(&gpf->strokes, &new_strokes);
-    BLI_assert(new_strokes.first == NULL);
+      /* add all new strokes in temp buffer to the frame (preventing double-copies) */
+      BLI_movelisttolist(&gpf->strokes, &new_strokes);
+      BLI_assert(new_strokes.first == NULL);
+    }
+    CTX_DATA_END;
   }
-  CTX_DATA_END;
 
   /* updates */
   DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
@@ -1144,6 +1154,7 @@ static int gpencil_extrude_exec(bContext *C, wmOperator *op)
 {
   Object *obact = CTX_data_active_object(C);
   bGPdata *gpd = (bGPdata *)obact->data;
+  const bool is_curve_edit = (bool)GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd);
   const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
   bGPDstroke *gps = NULL;
 
@@ -1152,38 +1163,49 @@ static int gpencil_extrude_exec(bContext *C, wmOperator *op)
     return OPERATOR_CANCELLED;
   }
 
-  CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
-    bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
-
-    for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
-      if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
-        if (gpf == NULL) {
-          continue;
-        }
+  bool changed = false;
+  if (is_curve_edit) {
+    /* TODO: do curve extude */
+  }
+  else {
+    CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
+      bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
 
-        for (gps = gpf->strokes.first; gps; gps = gps->next) {
-          /* skip strokes that are invalid for current view */
-          if (ED_gpencil_stroke_can_use(C, gps) == false) {
+      for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
+        if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
+          if (gpf == NULL) {
             continue;
           }
 
-          if (gps->flag & GP_STROKE_SELECT) {
-            gpencil_add_move_points(gpd, gpf, gps);
+          for (gps = gpf->strokes.first; gps; gps = gps->next) {
+            /* skip strokes that are invalid for current view */
+            if (ED_gpencil_stroke_can_use(C, gps) == false) {
+              continue;
+            }
+
+            if (gps->flag & GP_STROKE_SELECT) {
+              gpencil_add_move_points(gpd, gpf, gps);
+
+              changed = true;
+            }
+          }
+          /* if not multiedit, exit loop*/
+          if (!is_multiedit) {
+            break;
           }
-        }
-        /* if not multiedit, exit loop*/
-        if (!is_multiedit) {
-          break;
         }
       }
     }
+    CTX_DATA_END;
   }
-  CTX_DATA_END;
 
-  /* updates */
-  DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
-  DEG_id_tag_update(&obact->id, ID_RECALC_COPY_ON_WRITE);
-  WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+  if (changed) {
+    /* updates */
+    DEG_id_tag_update(&gpd->id,
+                      ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
+    DEG_id_tag_update(&obact->id, ID_RECALC_COPY_ON_WRITE);
+    WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+  }
 
   return OPERATOR_FINISHED;
 }
@@ -1337,6 +1359,7 @@ static int gpencil_strokes_copy_exec(bCo

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list