[Bf-blender-cvs] [0ba1d68c30f] greasepencil-edit-curve: GPencil: Apply GSoC changes

Antonio Vazquez noreply at git.blender.org
Fri Jun 19 10:34:35 CEST 2020


Commit: 0ba1d68c30ff605e96ae0a8f9451511d2bdd789c
Author: Antonio Vazquez
Date:   Fri Jun 19 10:34:14 2020 +0200
Branches: greasepencil-edit-curve
https://developer.blender.org/rB0ba1d68c30ff605e96ae0a8f9451511d2bdd789c

GPencil: Apply  GSoC changes

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_select.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/makesdna/DNA_curve_types.h
M	source/blender/makesdna/DNA_gpencil_types.h
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 f9d1290910f..c7a347a2d80 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -103,6 +103,7 @@ void BKE_gpencil_batch_cache_dirty_tag(struct bGPdata *gpd);
 void BKE_gpencil_batch_cache_free(struct bGPdata *gpd);
 
 void BKE_gpencil_stroke_sync_selection(struct bGPDstroke *gps);
+void BKE_gpencil_curve_sync_selection(struct bGPDcurve *gpc);
 
 struct bGPDframe *BKE_gpencil_frame_addnew(struct bGPDlayer *gpl, int cframe);
 struct bGPDframe *BKE_gpencil_frame_addcopy(struct bGPDlayer *gpl, int cframe);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 0c8d9b6f6d7..60765e72489 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -842,6 +842,22 @@ void BKE_gpencil_stroke_sync_selection(bGPDstroke *gps)
   }
 }
 
+void BKE_gpencil_curve_sync_selection(bGPDcurve *gpc)
+{
+  if (gpc == NULL) {
+    return;
+  }
+
+  gpc->flag &= ~GP_CURVE_SELECT;
+  for (int i = 0; i < gpc->tot_curve_points; i++) {
+    bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
+    if (gpc_pt->flag & GP_SPOINT_SELECT) {
+      gpc->flag |= GP_STROKE_SELECT;
+      break;
+    }
+  }
+}
+
 /* ************************************************** */
 /* GP Frame API */
 
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index dec06e68909..3bc7a39c1d9 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -684,6 +684,55 @@ struct GP_EditableStrokes_Iter {
   } \
   (void)0
 
+/**
+ * Iterate over all editable editcurves in the current context,
+ * stopping on each usable layer + stroke + curve pair (i.e. gpl, gps and gpc)
+ * to perform some operations on the curve.
+ *
+ * \param gpl: The identifier to use for the layer of the stroke being processed.
+ *                    Choose a suitable value to avoid name clashes.
+ * \param gps: The identifier to use for current stroke being processed.
+ *                    Choose a suitable value to avoid name clashes.
+ * \param gpc: The identifier to use for current editcurve being processed.
+ *                    Choose a suitable value to avoid name clashes.
+ */
+#define GP_EDITABLE_CURVES_BEGIN(gpstroke_iter, C, gpl, gps, gpc) \
+  { \
+    struct GP_EditableStrokes_Iter gpstroke_iter = {{{0}}}; \
+    Depsgraph *depsgraph_ = CTX_data_ensure_evaluated_depsgraph(C); \
+    Object *obact_ = CTX_data_active_object(C); \
+    bGPdata *gpd_ = CTX_data_gpencil_data(C); \
+    const bool is_multiedit_ = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd_); \
+    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_)) { \
+          BKE_gpencil_parent_matrix_get(depsgraph_, obact_, gpl, gpstroke_iter.diff_mat); \
+          invert_m4_m4(gpstroke_iter.inverse_diff_mat, gpstroke_iter.diff_mat); \
+          /* loop over strokes */ \
+          bGPDstroke *gpsn_; \
+          for (bGPDstroke *gps = gpf_->strokes.first; gps; gps = gpsn_) { \
+            gpsn_ = gps->next; \
+            /* skip strokes that are invalid for current view */ \
+            if (ED_gpencil_stroke_can_use(C, gps) == false) \
+              continue; \
+            if (gps->editcurve == NULL) \
+              continue; \
+            bGPDcurve *gpc = gps->editcurve;\
+    /* ... Do Stuff With Strokes ...  */
+
+#define GP_EDITABLE_CURVES_END(gpstroke_iter) \
+  } \
+  } \
+  if (!is_multiedit_) { \
+    break; \
+  } \
+  } \
+  } \
+  CTX_DATA_END; \
+  } \
+  (void)0
+
 /**
  * Iterate over all editable strokes using evaluated data in the current context,
  * stopping on each usable layer + stroke pair (i.e. gpl and gps)
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index 3e3fffe55b3..6accc06d175 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -59,6 +59,7 @@
 
 #include "ED_gpencil.h"
 #include "ED_select_utils.h"
+#include "ED_view3d.h"
 
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_query.h"
@@ -131,6 +132,31 @@ static bool gpencil_select_poll(bContext *C)
   return false;
 }
 
+static bool error_threshold_display_poll(bContext *C)
+{
+  CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
+    if (gps->editcurve == NULL) {
+      return true;
+    }
+  }
+  CTX_DATA_END;
+  return false;
+}
+
+static void gpencil_select_ui(bContext *C, wmOperator *op)
+{
+  uiLayout *layout = op->layout;
+  PointerRNA ptr;
+
+  Object *ob = CTX_data_active_object(C);
+  bGPdata *gpd = ob->data;
+
+  if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd) && error_threshold_display_poll(C)) {
+    RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
+    uiItemR(layout, &ptr, "error_threshold", 0, NULL, ICON_NONE);
+  }
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
@@ -192,7 +218,7 @@ static int gpencil_select_all_exec(bContext *C, wmOperator *op)
   return OPERATOR_FINISHED;
 }
 
-static void property_error_threshold_define(wmOperatorType *ot)
+static void WM_operator_property_error_threshold(wmOperatorType *ot)
 {
   PropertyRNA *prop = RNA_def_float(ot->srna,
                                     "error_threshold",
@@ -206,31 +232,6 @@ static void property_error_threshold_define(wmOperatorType *ot)
   RNA_def_property_ui_range(prop, FLT_MIN, 10.0f, 0.1f, 5);
 }
 
-static bool error_threshold_display_poll(bContext *C)
-{
-  CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
-    if (gps->editcurve == NULL) {
-      return true;
-    }
-  }
-  CTX_DATA_END;
-  return false;
-}
-
-static void select_all_ui(bContext *C, wmOperator *op)
-{
-  uiLayout *layout = op->layout;
-  PointerRNA ptr;
-
-  Object *ob = CTX_data_active_object(C);
-  bGPdata *gpd = ob->data;
-
-  if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd) && error_threshold_display_poll(C)) {
-    RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
-    uiItemR(layout, &ptr, "error_threshold", 0, NULL, ICON_NONE);
-  }
-}
-
 void GPENCIL_OT_select_all(wmOperatorType *ot)
 {
   /* identifiers */
@@ -245,10 +246,10 @@ void GPENCIL_OT_select_all(wmOperatorType *ot)
   /* flags */
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
-  ot->ui = select_all_ui;
+  ot->ui = gpencil_select_ui;
 
   WM_operator_properties_select_all(ot);
-  property_error_threshold_define(ot);
+  WM_operator_property_error_threshold(ot);
 }
 
 /** \} */
@@ -272,16 +273,18 @@ static int gpencil_select_linked_exec(bContext *C, wmOperator *op)
   }
 
   if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) {
-    CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
-      if (gps->editcurve != NULL && gps->flag & GP_STROKE_SELECT) {
-        bGPDcurve *gpc = gps->editcurve;
+    GP_EDITABLE_CURVES_BEGIN(gps_iter, C, gpl, gps, gpc)
+    {
+      if (gpc->flag & GP_CURVE_SELECT) {
         for (int i = 0; i < gpc->tot_curve_points; i++) {
-          BezTriple *bezt = &gpc->curve_points[i].bezt;
+          bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
+          BezTriple *bezt = &gpc_pt->bezt;
+          gpc_pt->flag |= GP_CURVE_POINT_SELECT;
           BEZT_SEL_ALL(bezt);
         }
       }
     }
-    CTX_DATA_END;
+    GP_EDITABLE_CURVES_END(gps_iter);
   }
   else {
     /* select all points in selected strokes */
@@ -1578,10 +1581,75 @@ static void deselect_all_selected(bContext *C)
       /* deselect stroke itself too */
       gps->flag &= ~GP_STROKE_SELECT;
     }
+    if (gps->editcurve != NULL) {
+      bGPDcurve *gpc = gps->editcurve;
+      for (int i = 0; i < gpc->tot_curve_points; i++) {
+        bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
+        BezTriple *bezt = &gpc_pt->bezt;
+        gpc_pt->flag &= ~GP_CURVE_POINT_SELECT;
+        BEZT_DESEL_ALL(bezt);
+      }
+
+      gpc->flag &= ~GP_CURVE_SELECT;
+    }
   }
   CTX_DATA_END;
 }
 
+static void gpencil_select_curve_point(bContext *C,
+                                       const int mval[2],
+                                       const int radius_squared,
+                                       bGPDcurve **r_gpc,
+                                       bGPDcurve_point **r_pt,
+                                       char *handle)
+{
+  ARegion *region = CTX_wm_region(C);
+  View3D *v3d = CTX_wm_view3d(C);
+  const bool only_selected = (v3d->overlay.handle_display == CURVE_HANDLE_SELECTED);
+
+  int hit_distance = radius_squared;
+
+  GP_EDITABLE_CURVES_BEGIN(gps_iter, C, gpl, gps, gpc)
+  {
+    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->hide == 1) {
+        continue;
+      }
+
+      const bool handles_visible = (v3d->overlay.handle_display != CURVE_HANDLE_NONE) &&
+                                   (!only_selected || BEZT_ISSEL_ANY(bezt));
+
+      /* if the handles are not visible only check ctrl point (vec[1])*/
+      int from = (!handles_visible) ? 1 : 0;
+      int to = (!handles_visible) ? 2 : 3;
+
+      for (int j = from; j < to; j++) {
+        float parent_co[3];
+        mul_v3_m4v3(parent_co, gps_iter.diff_mat, bezt->vec[j]);
+        int screen_co[2];
+        if (ED_view3d_project_int_global(
+                region, parent_co, screen_co, V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN) ==
+            V3D_PROJ_RET_OK) {
+          if (!ELEM(V2D_IS_CLIPPED, screen_co[0], screen_co[1])) {
+            const int pt_distance = len_manhattan_v2v2_int(mval, screen_co);
+
+            if (pt_distance <= radius_squared && pt_distance < hit_distance) {
+              *r_gpc = gpc;
+              *r_pt = gpc_pt;
+              *handle = j;
+              hit_distance = pt_distance;
+            }
+          }
+        }

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list