[Bf-blender-cvs] [6394287b1c2] soc-2020-greasepencil-curve: GPencil: Adapt edit mode operators for curve edit

Falk David noreply at git.blender.org
Fri Jul 10 16:41:25 CEST 2020


Commit: 6394287b1c2ab517b77a3038b4bc6e8863c7c0cb
Author: Falk David
Date:   Fri Jul 10 16:32:14 2020 +0200
Branches: soc-2020-greasepencil-curve
https://developer.blender.org/rB6394287b1c2ab517b77a3038b4bc6e8863c7c0cb

GPencil: Adapt edit mode operators for curve edit

Change the rest of the edit mode opearators (c62bc08f) so that they
check if curve edit mode is active (if needed).

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

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 40f71031dde..0666f523b67 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -1383,6 +1383,7 @@ static int gpencil_stroke_arrange_exec(bContext *C, wmOperator *op)
   const int direction = RNA_enum_get(op->ptr, "direction");
   const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
 
+  bool changed = false;
   CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
     /* temp listbase to store selected strokes */
     ListBase selected = {NULL};
@@ -1441,7 +1442,7 @@ static int gpencil_stroke_arrange_exec(bContext *C, wmOperator *op)
               break;
             /* Bring Forward */
             case GP_STROKE_MOVE_UP:
-              for (LinkData *link = selected.last; link; link = link->prev) {
+              LISTBASE_FOREACH_BACKWARD (LinkData *, link, &selected) {
                 gps = link->data;
                 BLI_listbase_link_move(&gpf->strokes, gps, 1);
               }
@@ -1455,7 +1456,7 @@ static int gpencil_stroke_arrange_exec(bContext *C, wmOperator *op)
               break;
             /* Send to Back */
             case GP_STROKE_MOVE_BOTTOM:
-              for (LinkData *link = selected.last; link; link = link->prev) {
+              LISTBASE_FOREACH_BACKWARD (LinkData *, link, &selected) {
                 gps = link->data;
                 BLI_remlink(&gpf->strokes, gps);
                 BLI_addhead(&gpf->strokes, gps);
@@ -1464,6 +1465,7 @@ static int gpencil_stroke_arrange_exec(bContext *C, wmOperator *op)
             default:
               BLI_assert(0);
               break;
+            changed = true;
           }
         }
         BLI_freelistN(&selected);
@@ -1477,9 +1479,11 @@ static int gpencil_stroke_arrange_exec(bContext *C, wmOperator *op)
   }
   CTX_DATA_END;
 
-  /* 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);
+  if (changed) {
+    /* 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;
 }
@@ -1545,6 +1549,7 @@ static int gpencil_stroke_change_color_exec(bContext *C, wmOperator *op)
     return OPERATOR_CANCELLED;
   }
 
+  bool changed = false;
   /* loop all strokes */
   CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
     bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
@@ -1569,6 +1574,8 @@ static int gpencil_stroke_change_color_exec(bContext *C, wmOperator *op)
 
             /* assign new color */
             gps->mat_nr = idx;
+
+            changed = true;
           }
         }
       }
@@ -1580,9 +1587,11 @@ static int gpencil_stroke_change_color_exec(bContext *C, wmOperator *op)
   }
   CTX_DATA_END;
 
-  /* 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);
+  if (changed) {
+    /* 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;
 }
@@ -1609,9 +1618,7 @@ void GPENCIL_OT_stroke_change_color(wmOperatorType *ot)
 static int gpencil_material_lock_unsused_exec(bContext *C, wmOperator *UNUSED(op))
 {
   bGPdata *gpd = ED_gpencil_data_get_active(C);
-
   Object *ob = CTX_data_active_object(C);
-
   short *totcol = BKE_object_material_len_p(ob);
 
   /* sanity checks */
@@ -1628,6 +1635,7 @@ static int gpencil_material_lock_unsused_exec(bContext *C, wmOperator *UNUSED(op
     }
   }
 
+  bool changed = false;
   /* loop all selected strokes and unlock any color */
   LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
     /* only editable and visible layers are considered */
@@ -1645,19 +1653,24 @@ static int gpencil_material_lock_unsused_exec(bContext *C, wmOperator *UNUSED(op
             tmp_ma->gp_style->flag &= ~GP_MATERIAL_LOCKED;
             DEG_id_tag_update(&tmp_ma->id, ID_RECALC_COPY_ON_WRITE);
           }
+
+          changed = true;
         }
       }
     }
   }
-  /* updates */
-  DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY);
+  
+  if (changed) {
+    /* updates */
+    DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY);
 
-  /* copy on write tag is needed, or else no refresh happens */
-  DEG_id_tag_update(&gpd->id, ID_RECALC_COPY_ON_WRITE);
+    /* copy on write tag is needed, or else no refresh happens */
+    DEG_id_tag_update(&gpd->id, ID_RECALC_COPY_ON_WRITE);
 
-  /* 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);
+    /* 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;
 }
@@ -3348,7 +3361,7 @@ static int gpencil_set_active_material_exec(bContext *C, wmOperator *op)
     }
     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 e5095ebb768..4375f601db2 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -51,6 +51,7 @@
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_gpencil.h"
+#include "BKE_gpencil_curve.h"
 #include "BKE_gpencil_geom.h"
 #include "BKE_lib_id.h"
 #include "BKE_main.h"
@@ -139,6 +140,18 @@ static bool gpencil_editmode_toggle_poll(bContext *C)
   return ED_gpencil_data_get_active(C) != NULL;
 }
 
+static bool gpencil_stroke_not_in_curve_edit_mode(bContext *C)
+{
+  Object *ob = CTX_data_active_object(C);
+  if ((ob == NULL) || (ob->type != OB_GPENCIL)) {
+    return false;
+  }
+  bGPdata *gpd = (bGPdata *)ob->data;
+  bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd);
+
+  return (gpl != NULL && !GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd));
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
@@ -3134,6 +3147,7 @@ static int gpencil_stroke_apply_thickness_exec(bContext *C, wmOperator *UNUSED(o
       }
     }
   }
+
   /* clear value */
   gpl->thickness = 0.0f;
   gpl->line_change = 0;
@@ -3177,6 +3191,7 @@ static int gpencil_stroke_cyclical_set_exec(bContext *C, wmOperator *op)
   const int type = RNA_enum_get(op->ptr, "type");
   const bool geometry = RNA_boolean_get(op->ptr, "geometry");
   const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
+  const bool is_curve_edit = (bool)GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd);
   bGPDstroke *gps = NULL;
 
   /* sanity checks */
@@ -3184,6 +3199,7 @@ static int gpencil_stroke_cyclical_set_exec(bContext *C, wmOperator *op)
     return OPERATOR_CANCELLED;
   }
 
+  bool changed = false;
   /* loop all selected strokes */
   CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
     bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
@@ -3207,6 +3223,7 @@ static int gpencil_stroke_cyclical_set_exec(bContext *C, wmOperator *op)
             continue;
           }
 
+          bool before = (bool)(gps->flag & GP_STROKE_CYCLIC);
           switch (type) {
             case GP_STROKE_CYCLIC_CLOSE:
               /* Close all (enable) */
@@ -3225,9 +3242,19 @@ static int gpencil_stroke_cyclical_set_exec(bContext *C, wmOperator *op)
               break;
           }
 
-          /* Create new geometry. */
-          if ((gps->flag & GP_STROKE_CYCLIC) && (geometry)) {
-            BKE_gpencil_stroke_close(gps);
+          if (before != (gps->flag & GP_STROKE_CYCLIC)) {
+            /* Create new geometry. */
+            if (is_curve_edit) {
+              BKE_gpencil_editcurve_recalculate_handles(gps);
+              gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
+              BKE_gpencil_stroke_geometry_update(gpd, gps);
+            }
+            else if ((gps->flag & GP_STROKE_CYCLIC) && geometry) {
+              BKE_gpencil_stroke_close(gps);
+              BKE_gpencil_stroke_geometry_update(gpd, gps);
+            }
+
+            changed = true;
           }
         }
 
@@ -3240,13 +3267,31 @@ static int gpencil_stroke_cyclical_set_exec(bContext *C, wmOperator *op)
   }
   CTX_DATA_END;
 
-  /* 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);
+  if (changed) {
+    /* 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;
 }
 
+static bool gpencil_cyclical_set_curve_edit_poll_property(const bContext *C,
+                                                          wmOperator *UNUSED(op),
+                                                          const PropertyRNA *prop)
+{
+  bGPdata *gpd = ED_gpencil_data_get_active(C);
+  if (gpd != NULL && GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) {
+    const char *prop_id = RNA_property_identifier(prop);
+    /* Only show type in curve edit mode */
+    if (!STREQ(prop_id, "type")) {
+      return false;
+    }
+  }
+
+  return true;
+}
+
 /**
  * Similar to #CURVE_OT_cyclic_toggle or #MASK_OT_cyclic_toggle, but with
  * option to force opened/closed strokes instead of just toggle behavior.
@@ -3270,6 +3315,7 @@ void GPENCIL_OT_stroke_cyclical_set(wmOperatorType *ot)
   /* api callbacks */
   ot->exec = gpencil_stroke_cyclical_set_exec;
   ot->poll = gpencil_active_layer_poll;
+  ot->poll_property = gpencil_cyclical_set_curve_edit_poll_property;
 
   /* flags */
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -3298,7 +3344,6 @@ static int gpencil_stroke_caps_set_exec(bContext *C, wmOperator *op)
 {
   bGPdata *gpd = ED_gpencil_data_get_active(C);
   Object *ob = CTX_data_activ

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list