[Bf-blender-cvs] [591047baef5] greasepencil-edit-curve: GPencil: Apply GSoC changes

Antonio Vazquez noreply at git.blender.org
Sat Jul 4 10:00:25 CEST 2020


Commit: 591047baef59d26e910ca01f146c86618a5774a4
Author: Antonio Vazquez
Date:   Sat Jul 4 10:00:08 2020 +0200
Branches: greasepencil-edit-curve
https://developer.blender.org/rB591047baef59d26e910ca01f146c86618a5774a4

GPencil: Apply GSoC changes

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenkernel/intern/gpencil_curve.c
M	source/blender/blenkernel/intern/gpencil_geom.c
M	source/blender/editors/gpencil/gpencil_edit_curve.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_ops.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/transform/transform_convert_gpencil.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 3fbd005b942..7a66efca7c4 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -3180,6 +3180,9 @@ def km_grease_pencil_stroke_edit_mode(params):
          {"properties": [("mode", 'GPENCIL_OPACITY')]}),
         # Proportional editing.
         *_template_items_proportional_editing(connected=True),
+        # Curve edit mode toggle.
+        ("wm.context_toggle", {"type": 'U', "value": 'PRESS'},
+         {"properties": [("data_path", 'gpencil_data.use_curve_edit')]}),
         # Add menu
         ("object.gpencil_add", {"type": 'A', "value": 'PRESS', "shift": True}, None),
         # Vertex group menu
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 9df10ca6dab..761ab719255 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -941,13 +941,26 @@ void BKE_gpencil_curve_sync_selection(bGPDcurve *gpc)
   }
 
   gpc->flag &= ~GP_CURVE_SELECT;
+  bool is_selected = false;
   for (int i = 0; i < gpc->tot_curve_points; i++) {
     bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
+    BezTriple *bezt = &gpc_pt->bezt;
+
+    if (BEZT_ISSEL_ANY(bezt)) {
+      gpc_pt->flag |= GP_SPOINT_SELECT;
+    }
+    else {
+      gpc_pt->flag &= ~GP_SPOINT_SELECT;
+    }
+
     if (gpc_pt->flag & GP_SPOINT_SELECT) {
-      gpc->flag |= GP_STROKE_SELECT;
-      break;
+      is_selected = true;
     }
   }
+
+  if (is_selected) {
+    gpc->flag |= GP_CURVE_SELECT;
+  }
 }
 
 /* ************************************************** */
diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c
index 74b537d595b..0159ac836e5 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -528,7 +528,7 @@ bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps, float error_th
 }
 
 /**
- * Updates the editcurve for a stroke.
+ * Updates the editcurve for a stroke. Frees the old curve if one exists and generates a new one.
  */
 void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps, float error_threshold)
 {
@@ -544,11 +544,13 @@ void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps, float error_threshold)
   if (editcurve == NULL) {
     return;
   }
-  /* update the selection based on the selected points in the stroke */
-  BKE_gpencil_editcurve_stroke_sync_selection(gps, editcurve);
+
   gps->editcurve = editcurve;
 }
 
+/**
+ * Sync the selection from stroke to editcurve
+ */
 void BKE_gpencil_editcurve_stroke_sync_selection(bGPDstroke *gps, bGPDcurve *gpc)
 {
   if (gps->flag & GP_STROKE_SELECT) {
@@ -572,6 +574,9 @@ void BKE_gpencil_editcurve_stroke_sync_selection(bGPDstroke *gps, bGPDcurve *gpc
   }
 }
 
+/**
+ * Sync the selection from editcurve to stroke
+ */
 void BKE_gpencil_stroke_editcurve_sync_selection(bGPDstroke *gps, bGPDcurve *gpc)
 {
   if (gpc->flag & GP_CURVE_SELECT) {
@@ -601,45 +606,6 @@ void BKE_gpencil_stroke_editcurve_sync_selection(bGPDstroke *gps, bGPDcurve *gpc
   }
 }
 
-/**
- * Update editcurve for all selected strokes.
- */
-void BKE_gpencil_selected_strokes_editcurve_update(bGPdata *gpd)
-{
-  if (gpd == NULL) {
-    return;
-  }
-
-  const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
-
-  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
-    if (!BKE_gpencil_layer_is_editable(gpl)) {
-      continue;
-    }
-    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)) {
-        LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
-          /* skip deselected stroke */
-          if (!(gps->flag & GP_STROKE_SELECT)) {
-            continue;
-          }
-
-          if (gps->editcurve == NULL) {
-            BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
-            if (gps->editcurve != NULL) {
-              gps->editcurve->resolution = gpd->editcurve_resolution;
-              gps->editcurve->flag |= GP_CURVE_RECALC_GEOMETRY;
-            }
-            BKE_gpencil_stroke_geometry_update(gpd, gps);
-          }
-          BKE_gpencil_editcurve_stroke_sync_selection(gps, gps->editcurve);
-        }
-      }
-    }
-  }
-}
-
 static void gpencil_interpolate_fl_from_to(
     float from, float to, float *point_offset, int it, int stride)
 {
@@ -765,9 +731,13 @@ void BKE_gpencil_stroke_update_geometry_from_editcurve(bGPDstroke *gps)
     copy_v4_v4(pt->vert_color, &points[i][5]);
   }
 
+  /* free temp data */
   MEM_freeN(points);
 }
 
+/**
+ * Recalculate the handles of the edit curve of a grease pencil stroke
+ */
 void BKE_gpencil_editcurve_recalculate_handles(bGPDstroke *gps)
 {
   if (gps == NULL || gps->editcurve == NULL) {
@@ -776,13 +746,19 @@ void BKE_gpencil_editcurve_recalculate_handles(bGPDstroke *gps)
 
   bool changed = false;
   bGPDcurve *gpc = gps->editcurve;
+  if (gpc->tot_curve_points < 1) {
+    return;
+  }
+
   for (int i = 0; i < gpc->tot_curve_points; i++) {
     bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
-    if (gpc_pt->flag & GP_CURVE_POINT_SELECT) {
-      bGPDcurve_point *gpc_pt_prev = (i > 0) ? &gpc->curve_points[i - 1] : NULL;
-      bGPDcurve_point *gpc_pt_next = (i < gpc->tot_curve_points - 1) ? &gpc->curve_points[i + 1] :
-                                                                       NULL;
-
+    bGPDcurve_point *gpc_pt_prev = (i > 0) ? &gpc->curve_points[i - 1] : NULL;
+    bGPDcurve_point *gpc_pt_next = (i < gpc->tot_curve_points - 1) ? &gpc->curve_points[i + 1] :
+                                                                     NULL;
+    /* update handle if point or neighbour is selected */
+    if (gpc_pt->flag & GP_CURVE_POINT_SELECT ||
+        (gpc_pt_prev != NULL && gpc_pt_prev->flag & GP_CURVE_POINT_SELECT) ||
+        (gpc_pt_next != NULL && gpc_pt_next->flag & GP_CURVE_POINT_SELECT)) {
       BezTriple *bezt = &gpc_pt->bezt;
       BezTriple *bezt_prev = gpc_pt_prev != NULL ? &gpc_pt_prev->bezt : NULL;
       BezTriple *bezt_next = gpc_pt_next != NULL ? &gpc_pt_next->bezt : NULL;
@@ -793,7 +769,7 @@ void BKE_gpencil_editcurve_recalculate_handles(bGPDstroke *gps)
   }
 
   if (changed) {
-    gpc->flag |= GP_CURVE_RECALC_GEOMETRY;
+    gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
   }
 }
 
diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c
index f374e09b0d4..101e3c6c486 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.c
+++ b/source/blender/blenkernel/intern/gpencil_geom.c
@@ -1273,16 +1273,23 @@ void BKE_gpencil_stroke_uv_update(bGPDstroke *gps)
  * \param gpd: Grease pencil data-block
  * \param gps: Grease pencil stroke
  */
-void BKE_gpencil_stroke_geometry_update(bGPdata *UNUSED(gpd), bGPDstroke *gps)
+void BKE_gpencil_stroke_geometry_update(bGPdata *gpd, bGPDstroke *gps)
 {
   if (gps == NULL) {
     return;
   }
 
   if (gps->editcurve != NULL) {
-    if (gps->editcurve->flag & GP_CURVE_RECALC_GEOMETRY) {
-      BKE_gpencil_stroke_update_geometry_from_editcurve(gps);
-      gps->editcurve->flag &= ~GP_CURVE_RECALC_GEOMETRY;
+    if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) {
+      /* curve geometry was updated: stroke needs recalculation */
+      if (gps->flag & GP_STROKE_NEEDS_CURVE_UPDATE) {
+        BKE_gpencil_stroke_update_geometry_from_editcurve(gps);
+        gps->flag &= ~GP_STROKE_NEEDS_CURVE_UPDATE;
+      }
+    }
+    else {
+      /* stroke geometry was updated: editcurve needs recalculation */
+      gps->editcurve->flag |= GP_CURVE_NEEDS_STROKE_UPDATE;
     }
   }
 
diff --git a/source/blender/editors/gpencil/gpencil_edit_curve.c b/source/blender/editors/gpencil/gpencil_edit_curve.c
index 9692ca28082..b919f73d024 100644
--- a/source/blender/editors/gpencil/gpencil_edit_curve.c
+++ b/source/blender/editors/gpencil/gpencil_edit_curve.c
@@ -70,68 +70,6 @@ static bool gpencil_curve_edit_mode_poll(bContext *C)
   return (gpl != NULL);
 }
 
-/* -------------------------------------------------------------------- */
-/** \name Test Operator for curve editing
- * \{ */
-
-static int gpencil_write_stroke_curve_data_exec(bContext *C, wmOperator *op)
-{
-  Object *ob = CTX_data_active_object(C);
-  bGPdata *gpd = ob->data;
-
-  // int num_points = RNA_int_get(op->ptr, "num_points");
-
-  if (ELEM(NULL, gpd)) {
-    return OPERATOR_CANCELLED;
-  }
-
-  bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd);
-  bGPDframe *gpf = gpl->actframe;
-  if (ELEM(NULL, gpf)) {
-    return OPERATOR_CANCELLED;
-  }
-
-  LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
-    if (gps->flag & GP_STROKE_SELECT) {
-      if (gps->editcurve != NULL) {
-        BKE_gpencil_free_stroke_editcurve(gps);
-      }
-      BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
-      if (gps->editcurve != NULL) {
-        gps->editcurve->resolution = gpd->editcurve_resolution;
-      }
-    }
-  }
-
-  /* notifiers */
-  DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
-  WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-
-  return OPERATOR_FINISHED;
-}
-
-void GPENCIL_OT_write_sample_stroke_curve_data(wmOperatorType *ot)
-{
-  // PropertyRNA *prop;
-
-  /* identifiers */
-  ot->name = "Write sample stroke curve data";
-  ot->idname = "GPENCIL_OT_write_stroke_curve_data";
-  ot->description =
-      "Test operator to write sample curve data to the selected grease pencil strokes";
-
-  /* api callbacks */
-  ot->exec = gpencil_write_stroke_curve_data_exec;
-  ot->poll = gpencil_active_layer_poll;
-
-  /* flags */
-  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
-  /* properties */
-  // prop = RNA_def_int(
-  //     ot->srna, "num_points", 2, 0, 100, "Curve points", "Number of test curve points", 0, 100);
-}
-
 static int gpencil_stroke_enter_editcurve_mode(bContext *C, wmOperator *op)
 {
   Objec

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list