[Bf-blender-cvs] [285f7ee9f9f] soc-2021-curves: Separated the single operator into 3 operators: Add, Delete, Insert

dilithjay noreply at git.blender.org
Sat Dec 4 17:40:38 CET 2021


Commit: 285f7ee9f9f56e22720c8eb1f32b15df1dc78524
Author: dilithjay
Date:   Sun Nov 7 08:50:53 2021 +0530
Branches: soc-2021-curves
https://developer.blender.org/rB285f7ee9f9f56e22720c8eb1f32b15df1dc78524

Separated the single operator into 3 operators:
Add, Delete, Insert

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	source/blender/editors/curve/curve_intern.h
M	source/blender/editors/curve/curve_ops.c
M	source/blender/editors/curve/editcurve_pen.c

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 809487e6757..0ae9bd1c6ee 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -6997,10 +6997,12 @@ def km_3d_view_tool_edit_curve_pen(params):
         "3D View Tool: Edit Curve, Curve Pen",
         {"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
         {"items": [
-            ("curve.pen", {"type": params.tool_mouse, "value": 'PRESS'},
-             {"properties": [("wait_for_input", False), ("cut_or_delete", False)]}),
-            ("curve.pen", {"type": params.tool_mouse, "value": 'PRESS', "ctrl": True},
-             {"properties": [("cut_or_delete", True)]}),
+            ("curve.pen_add", {"type": params.tool_mouse, "value": 'PRESS'},
+             {"properties": []}),
+            ("curve.pen_delete", {"type": params.tool_mouse, "value": 'PRESS', "ctrl": True},
+             {"properties": []}),
+            ("curve.pen_insert", {"type": params.tool_mouse, "value": 'PRESS', "shift": True},
+             {"properties": []}),
         ]},
     )
 
diff --git a/source/blender/editors/curve/curve_intern.h b/source/blender/editors/curve/curve_intern.h
index f42f0c14037..22ddfff6696 100644
--- a/source/blender/editors/curve/curve_intern.h
+++ b/source/blender/editors/curve/curve_intern.h
@@ -209,5 +209,7 @@ void ED_curve_nurb_vert_selected_find(
 void CURVE_OT_draw(struct wmOperatorType *ot);
 
 /* editcurve_pen.c */
-void CURVE_OT_pen(struct wmOperatorType *ot);
+void CURVE_OT_pen_add(struct wmOperatorType *ot);
+void CURVE_OT_pen_delete(struct wmOperatorType *ot);
+void CURVE_OT_pen_insert(struct wmOperatorType *ot);
 struct wmKeyMap *curve_pen_modal_keymap(struct wmKeyConfig *keyconf);
diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c
index e509b0ff5d6..9a285d5f05f 100644
--- a/source/blender/editors/curve/curve_ops.c
+++ b/source/blender/editors/curve/curve_ops.c
@@ -127,7 +127,9 @@ void ED_operatortypes_curve(void)
   WM_operatortype_append(CURVE_OT_spin);
   WM_operatortype_append(CURVE_OT_vertex_add);
   WM_operatortype_append(CURVE_OT_draw);
-  WM_operatortype_append(CURVE_OT_pen);
+  WM_operatortype_append(CURVE_OT_pen_add);
+  WM_operatortype_append(CURVE_OT_pen_delete);
+  WM_operatortype_append(CURVE_OT_pen_insert);
   WM_operatortype_append(CURVE_OT_extrude);
   WM_operatortype_append(CURVE_OT_cyclic_toggle);
 
diff --git a/source/blender/editors/curve/editcurve_pen.c b/source/blender/editors/curve/editcurve_pen.c
index b0131a11935..56888c3f040 100644
--- a/source/blender/editors/curve/editcurve_pen.c
+++ b/source/blender/editors/curve/editcurve_pen.c
@@ -851,12 +851,12 @@ wmKeyMap *curve_pen_modal_keymap(wmKeyConfig *keyconf)
 
   keymap = WM_modalkeymap_ensure(keyconf, "Curve Pen Modal Map", modal_items);
 
-  WM_modalkeymap_assign(keymap, "CURVE_OT_pen");
+  WM_modalkeymap_assign(keymap, "CURVE_OT_pen_add");
 
   return keymap;
 }
 
-static int curve_pen_modal(bContext *C, wmOperator *op, const wmEvent *event)
+static int curve_pen_add_modal(bContext *C, wmOperator *op, const wmEvent *event)
 {
   Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
   ViewContext vc;
@@ -871,8 +871,6 @@ static int curve_pen_modal(bContext *C, wmOperator *op, const wmEvent *event)
   int ret = OPERATOR_RUNNING_MODAL;
   /* Whether the mouse is clicking and dragging. */
   bool dragging = RNA_boolean_get(op->ptr, "dragging");
-  /* Whether the tool should cut or delete. */
-  const bool cut_or_delete = RNA_boolean_get(op->ptr, "cut_or_delete");
   /* Whether a new point was added at the beginning of tool execution. */
   const bool is_new_point = RNA_boolean_get(op->ptr, "new");
   /* Whether a segment is being altered by click and drag. */
@@ -896,7 +894,7 @@ static int curve_pen_modal(bContext *C, wmOperator *op, const wmEvent *event)
     }
   }
 
-  if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE) && !cut_or_delete) {
+  if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
     if (!dragging && WM_event_drag_test(event, event->prev_click_xy) && event->val == KM_PRESS) {
       RNA_boolean_set(op->ptr, "dragging", true);
       dragging = true;
@@ -935,68 +933,29 @@ static int curve_pen_modal(bContext *C, wmOperator *op, const wmEvent *event)
   }
   else if (ELEM(event->type, LEFTMOUSE)) {
     if (event->val == KM_PRESS) {
-      if (cut_or_delete) {
-        Curve *cu = vc.obedit->data;
-        ListBase *nurbs = BKE_curve_editNurbs_get(cu);
-        float mouse_point[2] = {(float)event->mval[0], (float)event->mval[1]};
-
-        get_closest_vertex_to_point_in_nurbs(nurbs, &nu, &bezt, &bp, mouse_point, &vc);
-        const bool found_point = nu != NULL;
-
-        if (found_point) {
-          ED_curve_deselect_all(cu->editnurb);
-          if (nu && nu->type == CU_BEZIER) {
-            BezTriple *next_bezt = BKE_nurb_bezt_get_next(nu, bezt);
-            BezTriple *prev_bezt = BKE_nurb_bezt_get_prev(nu, bezt);
-            if (next_bezt && prev_bezt) {
-              const int bez_index = BKE_curve_nurb_vert_index_get(nu, bezt);
-              uint span_step[2] = {bez_index, bez_index};
-              ed_dissolve_bez_segment(prev_bezt, next_bezt, nu, cu, 1, span_step);
-            }
-            delete_bezt_from_nurb(bezt, nu);
-          }
-          else if (nu->type == CU_NURBS || nu->type == CU_POLY) {
-            delete_bp_from_nurb(bp, nu);
-          }
+      Curve *cu = vc.obedit->data;
+      /* Get currently selected point if any. Used for making spline cyclic. */
+      ED_curve_nurb_vert_selected_find(cu, vc.v3d, &nu, &bezt, &bp);
 
-          if (nu->pntsu == 0) {
-            delete_nurb(cu, nu);
-          }
-        }
-        else {
-          make_cut(event, cu, &nu, &vc);
-        }
+      const bool found_point = ED_curve_editnurb_select_pick(C, event->mval, false, false, false);
+      RNA_boolean_set(op->ptr, "new", !found_point);
 
-        if (nu && nu->type == CU_BEZIER) {
-          BKE_nurb_handles_calc(nu);
+      if (found_point) {
+        copy_v2_v2_int(vc.mval, event->mval);
+        if (nu && !(nu->flagu & CU_NURB_CYCLIC)) {
+          const bool closed = nu->pntsu > 2 && make_cyclic_if_endpoints(nu, bezt, bp, &vc, C);
+
+          /* Set "new" to true to be able to click and drag to control handles when added. */
+          RNA_boolean_set(op->ptr, "new", closed);
         }
       }
       else {
-        Curve *cu = vc.obedit->data;
-        /* Get currently selected point if any. Used for making spline cyclic. */
-        ED_curve_nurb_vert_selected_find(cu, vc.v3d, &nu, &bezt, &bp);
-
-        const bool found_point = ED_curve_editnurb_select_pick(
-            C, event->mval, false, false, false);
-        RNA_boolean_set(op->ptr, "new", !found_point);
-
-        if (found_point) {
-          copy_v2_v2_int(vc.mval, event->mval);
-          if (nu && !(nu->flagu & CU_NURB_CYCLIC)) {
-            const bool closed = nu->pntsu > 2 && make_cyclic_if_endpoints(nu, bezt, bp, &vc, C);
-
-            /* Set "new" to true to be able to click and drag to control handles when added. */
-            RNA_boolean_set(op->ptr, "new", closed);
-          }
+        if (is_spline_nearby(&vc, op, event)) {
+          RNA_boolean_set(op->ptr, "moving_segment", true);
+          moving_segment = true;
         }
         else {
-          if (is_spline_nearby(&vc, op, event)) {
-            RNA_boolean_set(op->ptr, "moving_segment", true);
-            moving_segment = true;
-          }
-          else {
-            add_vertex_connected_to_selected_vertex(&vc, obedit, event);
-          }
+          add_vertex_connected_to_selected_vertex(&vc, obedit, event);
         }
       }
     }
@@ -1023,9 +982,132 @@ static int curve_pen_modal(bContext *C, wmOperator *op, const wmEvent *event)
   return ret;
 }
 
-static int curve_pen_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+static int curve_pen_delete_modal(bContext *C, wmOperator *op, const wmEvent *event)
+{
+  Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+  ViewContext vc;
+  Object *obedit = CTX_data_edit_object(C);
+
+  ED_view3d_viewcontext_init(C, &vc, depsgraph);
+
+  BezTriple *bezt = NULL;
+  BPoint *bp = NULL;
+  Nurb *nu = NULL;
+
+  int ret = OPERATOR_RUNNING_MODAL;
+
+  if (ELEM(event->type, LEFTMOUSE)) {
+    if (event->val == KM_PRESS) {
+      Curve *cu = vc.obedit->data;
+      ListBase *nurbs = BKE_curve_editNurbs_get(cu);
+      float mouse_point[2] = {(float)event->mval[0], (float)event->mval[1]};
+
+      get_closest_vertex_to_point_in_nurbs(nurbs, &nu, &bezt, &bp, mouse_point, &vc);
+      const bool found_point = nu != NULL;
+
+      if (found_point) {
+        ED_curve_deselect_all(cu->editnurb);
+        if (nu && nu->type == CU_BEZIER) {
+          BezTriple *next_bezt = BKE_nurb_bezt_get_next(nu, bezt);
+          BezTriple *prev_bezt = BKE_nurb_bezt_get_prev(nu, bezt);
+          if (next_bezt && prev_bezt) {
+            const int bez_index = BKE_curve_nurb_vert_index_get(nu, bezt);
+            uint span_step[2] = {bez_index, bez_index};
+            ed_dissolve_bez_segment(prev_bezt, next_bezt, nu, cu, 1, span_step);
+          }
+          delete_bezt_from_nurb(bezt, nu);
+        }
+        else if (nu->type == CU_NURBS || nu->type == CU_POLY) {
+          delete_bp_from_nurb(bp, nu);
+        }
+
+        if (nu->pntsu == 0) {
+          delete_nurb(cu, nu);
+        }
+      }
+
+      if (nu && nu->type == CU_BEZIER) {
+        BKE_nurb_handles_calc(nu);
+      }
+    }
+    else if (event->val == KM_RELEASE) {
+      ret = OPERATOR_FINISHED;
+    }
+  }
+
+  WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
+  WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+  DEG_id_tag_update(obedit->data, 0);
+
+  return ret;
+}
+
+static int curve_pen_insert_modal(bContext *C, wmOperator *op, const wmEvent *event)
+{
+  Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
+  ViewContext vc;
+  Object *obedit = CTX_data_edit_object(C);
+
+  ED_view3d_viewcontext_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list