[Bf-blender-cvs] [ddc12efa217] greasepencil-object: GPencil: Remove Close operator and reuse Cyclic operator

Antonioya noreply at git.blender.org
Sun Jun 30 11:02:30 CEST 2019


Commit: ddc12efa2170a7f90a0986c21e88e4a0c8aede80
Author: Antonioya
Date:   Sun Jun 30 11:01:51 2019 +0200
Branches: greasepencil-object
https://developer.blender.org/rBddc12efa2170a7f90a0986c21e88e4a0c8aede80

GPencil: Remove Close operator and reuse Cyclic operator

Cyclic could do the same, so it's not logic to have duplicate code.

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_ops.c

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index d7c69bf5202..c888ce4402a 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -3009,7 +3009,8 @@ def km_grease_pencil_stroke_edit_mode(params):
         ("gpencil.stroke_join", {"type": 'J', "value": 'PRESS', "shift": True, "ctrl": True},
          {"properties": [("type", 'JOINCOPY')]}),
         # Close strokes
-        ("gpencil.stroke_close", {"type": 'F', "value": 'PRESS'}, None),
+        ("gpencil.stroke_cyclical_set", {"type": 'F', "value": 'PRESS'},
+         {"properties": [("type", 'CLOSE'), ("geometry", True)]}),
         # Copy + paset
         ("gpencil.copy", {"type": 'C', "value": 'PRESS', "ctrl": True}, None),
         ("gpencil.paste", {"type": 'V', "value": 'PRESS', "ctrl": True}, None),
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 10bd910db99..8630fe49696 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -4542,6 +4542,9 @@ class VIEW3D_MT_edit_gpencil(Menu):
         layout.operator_menu_enum("gpencil.stroke_separate", "mode", text="Separate...")
         layout.operator("gpencil.stroke_split", text="Split")
         layout.operator("gpencil.stroke_merge", text="Merge")
+        op = layout.operator("gpencil.stroke_cyclical_set", text="Close")
+        op.type = 'CLOSE'
+        op.geometry = True
         layout.operator_menu_enum("gpencil.stroke_join", "type", text="Join...")
         layout.operator("gpencil.stroke_flip", text="Flip Direction")
 
@@ -6295,7 +6298,10 @@ class VIEW3D_MT_gpencil_edit_context_menu(Menu):
         layout.operator("gpencil.stroke_join", text="Join & Copy").type = 'JOINCOPY'
         layout.menu("GPENCIL_MT_separate", text="Separate")
         layout.operator("gpencil.stroke_split", text="Split")
-
+        op = layout.operator("gpencil.stroke_cyclical_set", text="Close")
+        op.type = 'CLOSE'
+        op.geometry = True
+		
         layout.separator()
 
         layout.menu("VIEW3D_MT_mirror")
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 2fbcc786721..18d50827cb0 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -2871,6 +2871,8 @@ static int gp_stroke_cyclical_set_exec(bContext *C, wmOperator *op)
  */
 void GPENCIL_OT_stroke_cyclical_set(wmOperatorType *ot)
 {
+  PropertyRNA *prop;
+
   static const EnumPropertyItem cyclic_type[] = {
       {GP_STROKE_CYCLIC_CLOSE, "CLOSE", 0, "Close all", ""},
       {GP_STROKE_CYCLIC_OPEN, "OPEN", 0, "Open all", ""},
@@ -2892,8 +2894,9 @@ void GPENCIL_OT_stroke_cyclical_set(wmOperatorType *ot)
 
   /* properties */
   ot->prop = RNA_def_enum(ot->srna, "type", cyclic_type, GP_STROKE_CYCLIC_TOGGLE, "Type", "");
-  RNA_def_boolean(
-      ot->srna, "geometry", true, "Create Geometry", "Create new geometry for closing stroke");
+  prop = RNA_def_boolean(
+      ot->srna, "geometry", false, "Create Geometry", "Create new geometry for closing stroke");
+  RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }
 
 /* ******************* Flat Stroke Caps ************************** */
@@ -4596,68 +4599,3 @@ bool ED_object_gpencil_exit(struct Main *bmain, Object *ob)
   }
   return ok;
 }
-
-/* Add geometry to stroke for closing the path */
-static int gpencil_close_exec(bContext *C, wmOperator *op)
-{
-  Object *obact = CTX_data_active_object(C);
-  bGPdata *gpd = (bGPdata *)obact->data;
-  const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
-  bGPDstroke *gps = NULL;
-
-  if (gpd == NULL) {
-    BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data");
-    return OPERATOR_CANCELLED;
-  }
-
-  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))) {
-        if (gpf == NULL) {
-          continue;
-        }
-
-        for (gps = gpf->strokes.first; gps; gps = gps->next) {
-          /* skip strokes that are invalid for current view */
-          if (ED_gpencil_stroke_can_use(C, gps) == false) {
-            continue;
-          }
-
-          if (gps->flag & GP_STROKE_SELECT) {
-            /* generate geometry */
-            BKE_gpencil_close_stroke(gps);
-          }
-        }
-        /* if not multiedit, exit loop*/
-        if (!is_multiedit) {
-          break;
-        }
-      }
-    }
-  }
-  CTX_DATA_END;
-
-  /* updates */
-  DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
-  DEG_id_tag_update(&obact->id, ID_RECALC_COPY_ON_WRITE);
-  WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-
-  return OPERATOR_FINISHED;
-}
-
-void GPENCIL_OT_stroke_close(wmOperatorType *ot)
-{
-  /* identifiers */
-  ot->name = "Stroke Close";
-  ot->description = "Add geometry to close stroke";
-  ot->idname = "GPENCIL_OT_stroke_close";
-
-  /* callbacks */
-  ot->exec = gpencil_close_exec;
-  ot->poll = gp_strokes_edit3d_poll;
-
-  /* flag */
-  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 3778ea1023f..a9acd8057c1 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -489,7 +489,6 @@ void GPENCIL_OT_stroke_smooth(struct wmOperatorType *ot);
 void GPENCIL_OT_stroke_merge(struct wmOperatorType *ot);
 void GPENCIL_OT_stroke_cutter(struct wmOperatorType *ot);
 void GPENCIL_OT_stroke_trim(struct wmOperatorType *ot);
-void GPENCIL_OT_stroke_close(struct wmOperatorType *ot);
 
 void GPENCIL_OT_brush_presets_create(struct wmOperatorType *ot);
 
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index b1edcf5499b..db4c601709c 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -309,7 +309,6 @@ void ED_operatortypes_gpencil(void)
   WM_operatortype_append(GPENCIL_OT_stroke_merge);
   WM_operatortype_append(GPENCIL_OT_stroke_cutter);
   WM_operatortype_append(GPENCIL_OT_stroke_trim);
-  WM_operatortype_append(GPENCIL_OT_stroke_close);
 
   WM_operatortype_append(GPENCIL_OT_brush_presets_create);



More information about the Bf-blender-cvs mailing list