[Bf-blender-cvs] [8bc6f574f81] soc-2020-greasepencil-curve: GPencil: Add prop error threshold to select all

Falk David noreply at git.blender.org
Tue Jun 16 19:54:20 CEST 2020


Commit: 8bc6f574f816c0f47df22d1523c45fa14be9d74f
Author: Falk David
Date:   Tue Jun 16 19:53:35 2020 +0200
Branches: soc-2020-greasepencil-curve
https://developer.blender.org/rB8bc6f574f816c0f47df22d1523c45fa14be9d74f

GPencil: Add prop error threshold to select all

The error threshold for the curve fitting can be changed, when a
stroke that has no editcurve yet, is selected.

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

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/makesrna/intern/rna_gpencil.c

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

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_threshold_define(ot);
 }
 
 /** \} */
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 534ee6b151d..52274520176 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -2611,7 +2611,7 @@ void ED_gpencil_select_toggle_all(bContext *C, int action)
   }
 }
 
-void ED_gpencil_select_curve_toggle_all(bContext *C, int action)
+void ED_gpencil_select_curve_toggle_all(bContext *C, int action, float error_threshold)
 {
   /* if toggle, check if we need to select or deselect */
   if (action == SEL_TOGGLE) {
@@ -2645,7 +2645,10 @@ void ED_gpencil_select_curve_toggle_all(bContext *C, int action)
 
       /* Make sure stroke has a curve */
       if (gps->editcurve == NULL) {
-        BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
+        BKE_gpencil_stroke_editcurve_update(gps, error_threshold);
+        gps->editcurve->resolution = gpd->editcurve_resolution;
+        gps->editcurve->flag |= GP_CURVE_RECALC_GEOMETRY;
+        BKE_gpencil_stroke_geometry_update(gps);
       }
 
       bGPDcurve *gpc = gps->editcurve;
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 775944e4085..9cd6171e286 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -307,7 +307,7 @@ int ED_gpencil_select_stroke_segment(struct bGPDlayer *gpl,
                                      float r_hitb[3]);
 
 void ED_gpencil_select_toggle_all(struct bContext *C, int action);
-void ED_gpencil_select_curve_toggle_all(struct bContext *C, int action);
+void ED_gpencil_select_curve_toggle_all(struct bContext *C, int action, float error_threshold);
 
 /* Ensure stroke sbuffer size is enough */
 struct tGPspoint *ED_gpencil_sbuffer_ensure(struct tGPspoint *buffer_array,
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 092f6f7c47a..d476612bf31 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -2332,9 +2332,10 @@ static void rna_def_gpencil_data(BlenderRNA *brna)
   /* Curve editing error threshold. */
   prop = RNA_def_property(srna, "curve_edit_threshold", PROP_FLOAT, PROP_FACTOR);
   RNA_def_property_float_sdna(prop, NULL, "curve_edit_threshold");
-  RNA_def_property_range(prop, 0.0f, 1.0f);
+  RNA_def_property_range(prop, FLT_MIN, 10.0);
   RNA_def_property_float_default(prop, GP_DEFAULT_CURVE_ERROR);
   RNA_def_property_ui_text(prop, "Threshold", "Curve conversion error threshold");
+  RNA_def_property_ui_range(prop, FLT_MIN, 10.0, 2, 5);
   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 
   prop = RNA_def_property(srna, "use_multiedit", PROP_BOOLEAN, PROP_NONE);



More information about the Bf-blender-cvs mailing list