[Bf-blender-cvs] [362618ec0b1] greasepencil-edit-curve: GPencil: Apply all GSoC changes

Antonio Vazquez noreply at git.blender.org
Thu Jun 18 20:35:37 CEST 2020


Commit: 362618ec0b11764acc8748be8e0c622b6be4540d
Author: Antonio Vazquez
Date:   Wed Jun 17 10:20:24 2020 +0200
Branches: greasepencil-edit-curve
https://developer.blender.org/rB362618ec0b11764acc8748be8e0c622b6be4540d

GPencil: Apply all GSoC changes

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

M	source/blender/blenkernel/BKE_gpencil_curve.h
M	source/blender/blenkernel/intern/gpencil_curve.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_select.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_gpencil.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_curve.h b/source/blender/blenkernel/BKE_gpencil_curve.h
index 1d9c0f04477..2e8ba51e95d 100644
--- a/source/blender/blenkernel/BKE_gpencil_curve.h
+++ b/source/blender/blenkernel/BKE_gpencil_curve.h
@@ -43,8 +43,9 @@ void BKE_gpencil_convert_curve(struct Main *bmain,
                                const bool use_collections,
                                const bool only_stroke);
 
-struct bGPDcurve *BKE_gpencil_stroke_editcurve_generate(struct bGPDstroke *gps);
-void BKE_gpencil_stroke_editcurve_update(struct bGPDstroke *gps);
+struct bGPDcurve *BKE_gpencil_stroke_editcurve_generate(struct bGPDstroke *gps,
+                                                        float error_threshold);
+void BKE_gpencil_stroke_editcurve_update(struct bGPDstroke *gps, float error_threshold);
 void BKE_gpencil_selected_strokes_editcurve_update(struct bGPdata *gpd);
 void BKE_gpencil_stroke_update_geometry_from_editcurve(struct bGPDstroke *gps);
 
diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c
index 0b26defec4e..3591894d36a 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -456,15 +456,12 @@ void BKE_gpencil_convert_curve(Main *bmain,
 /**
  * Creates a bGPDcurve by doing a cubic curve fitting on the grease pencil stroke points.
  */
-bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps)
+bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps, float error_threshold)
 {
   if (gps->totpoints < 1) {
     return NULL;
   }
 
-  /* TODO: GPXX this should be a parameter */
-  float error_threshold = 0.1f;
-
   float *points = MEM_callocN(sizeof(float) * gps->totpoints * POINT_DIM, __func__);
   for (int i = 0; i < gps->totpoints; i++) {
     bGPDspoint *pt = &gps->points[i];
@@ -527,9 +524,9 @@ bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps)
 /**
  * Updates the editcurve for a stroke.
  */
-void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps)
+void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps, float error_threshold)
 {
-  if (gps == NULL || gps->totpoints < 0 || gps->editcurve != NULL) {
+  if (gps == NULL || gps->totpoints < 0) {
     return;
   }
 
@@ -537,7 +534,7 @@ void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps)
     BKE_gpencil_free_stroke_editcurve(gps);
   }
 
-  bGPDcurve *editcurve = BKE_gpencil_stroke_editcurve_generate(gps);
+  bGPDcurve *editcurve = BKE_gpencil_stroke_editcurve_generate(gps, error_threshold);
   if (editcurve == NULL) {
     return;
   }
@@ -568,7 +565,7 @@ void BKE_gpencil_selected_strokes_editcurve_update(bGPdata *gpd)
             continue;
           }
 
-          BKE_gpencil_stroke_editcurve_update(gps);
+          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;
diff --git a/source/blender/editors/gpencil/gpencil_edit_curve.c b/source/blender/editors/gpencil/gpencil_edit_curve.c
index 56a2ea4297d..098b3ba84f1 100644
--- a/source/blender/editors/gpencil/gpencil_edit_curve.c
+++ b/source/blender/editors/gpencil/gpencil_edit_curve.c
@@ -36,6 +36,7 @@
 #include "BKE_context.h"
 #include "BKE_gpencil.h"
 #include "BKE_gpencil_curve.h"
+#include "BKE_gpencil_geom.h"
 
 #include "BLI_listbase.h"
 #include "BLI_math.h"
@@ -78,7 +79,7 @@ static int gp_write_stroke_curve_data_exec(bContext *C, wmOperator *op)
       if (gps->editcurve != NULL) {
         BKE_gpencil_free_stroke_editcurve(gps);
       }
-      BKE_gpencil_stroke_editcurve_update(gps);
+      BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
       if (gps->editcurve != NULL) {
         gps->editcurve->resolution = gpd->editcurve_resolution;
       }
@@ -114,4 +115,72 @@ void GPENCIL_OT_write_sample_stroke_curve_data(wmOperatorType *ot)
   //     ot->srna, "num_points", 2, 0, 100, "Curve points", "Number of test curve points", 0, 100);
 }
 
+static int gp_stroke_enter_editcurve_mode(bContext *C, wmOperator *op)
+{
+  Object *ob = CTX_data_active_object(C);
+  bGPdata *gpd = ob->data;
+
+  float error_threshold = RNA_float_get(op->ptr, "error_threshold");
+  gpd->curve_edit_threshold = error_threshold;
+
+  if (ELEM(NULL, gpd)) {
+    return OPERATOR_CANCELLED;
+  }
+
+  const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
+
+  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+    LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+      if (gpf == gpl->actframe) {
+        LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
+          /* only allow selected and non-converted strokes to be transformed */
+          if (gps->flag & GP_STROKE_SELECT && 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(gps);
+          }
+        }
+      }
+    }
+  }
+
+  /* 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_stroke_enter_editcurve_mode(wmOperatorType *ot)
+{
+  PropertyRNA *prop;
+
+  /* identifiers */
+  ot->name = "Enter curve edit mode";
+  ot->idname = "GPENCIL_OT_stroke_enter_editcurve_mode";
+  ot->description = "Called to transform a stroke into a curve";
+
+  /* api callbacks */
+  ot->exec = gp_stroke_enter_editcurve_mode;
+  ot->poll = gp_active_layer_poll;
+
+  /* flags */
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+  /* properties */
+  prop = RNA_def_float(ot->srna,
+                       "error_threshold",
+                       0.1f,
+                       FLT_MIN,
+                       100.0f,
+                       "Error Threshold",
+                       "Threshold on the maximum deviation from the actual stroke",
+                       FLT_MIN,
+                       10.f);
+  RNA_def_property_ui_range(prop, FLT_MIN, 10.0f, 0.1f, 5);
+}
+
 /** \} */
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 0eb8b5c91ad..dec06e68909 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -445,6 +445,7 @@ void GPENCIL_OT_reproject(struct wmOperatorType *ot);
 void GPENCIL_OT_recalc_geometry(struct wmOperatorType *ot);
 
 void GPENCIL_OT_write_sample_stroke_curve_data(struct wmOperatorType *ot);
+void GPENCIL_OT_stroke_enter_editcurve_mode(struct wmOperatorType *ot);
 
 /* stroke sculpting -- */
 
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 96772fce1a8..bbb455a2eba 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -570,6 +570,7 @@ void ED_operatortypes_gpencil(void)
   WM_operatortype_append(GPENCIL_OT_weight_paint);
 
   WM_operatortype_append(GPENCIL_OT_write_sample_stroke_curve_data);
+  WM_operatortype_append(GPENCIL_OT_stroke_enter_editcurve_mode);
 
   /* Editing (Buttons) ------------ */
 
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index 9bb8296a6df..3e3fffe55b3 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -47,6 +47,7 @@
 #include "BKE_report.h"
 
 #include "UI_interface.h"
+#include "UI_resources.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -153,6 +154,7 @@ static int gpencil_select_all_exec(bContext *C, wmOperator *op)
 {
   bGPdata *gpd = ED_gpencil_data_get_active(C);
   int action = RNA_enum_get(op->ptr, "action");
+  float error_threshold = RNA_float_get(op->ptr, "error_threshold");
 
   if (gpd == NULL) {
     BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data");
@@ -173,7 +175,7 @@ static int gpencil_select_all_exec(bContext *C, wmOperator *op)
   }
 
   if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) {
-    ED_gpencil_select_curve_toggle_all(C, action);
+    ED_gpencil_select_curve_toggle_all(C, action, error_threshold);
   }
   else {
     ED_gpencil_select_toggle_all(C, action);
@@ -190,6 +192,45 @@ static int gpencil_select_all_exec(bContext *C, wmOperator *op)
   return OPERATOR_FINISHED;
 }
 
+static void property_error_threshold_define(wmOperatorType *ot)
+{
+  PropertyRNA *prop = RNA_def_float(ot->srna,
+                                    "error_threshold",
+                                    0.1f,
+                                    FLT_MIN,
+                                    100.0f,
+                                    "Error Threshold",
+                                    "Threshold on the maximum deviation from the actual stroke",
+                                    FLT_MIN,
+                                    10.f);
+  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 */
@@ -204,7 +245,10 @@ void GPENCIL_OT_select_all(wmOperatorType *ot)
   /* flags */
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
+  ot->ui = select_all_ui;
+
   WM_operator_properties_select_all(ot);
+  property_error_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list