[Bf-blender-cvs] [2a45405fe28] soc-2021-curves: Support for enabling functionalities from Properties
dilithjay
noreply at git.blender.org
Sat Dec 25 13:28:02 CET 2021
Commit: 2a45405fe28360b12f338618058885a3c9d96842
Author: dilithjay
Date: Sat Dec 25 09:45:33 2021 +0530
Branches: soc-2021-curves
https://developer.blender.org/rB2a45405fe28360b12f338618058885a3c9d96842
Support for enabling functionalities from Properties
===================================================================
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 b025f72388f..3cf53ff7081 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -4584,7 +4584,6 @@ def km_curve(params):
("curve.dissolve_verts", {"type": 'X', "value": 'PRESS', "ctrl": True}, None),
("curve.dissolve_verts", {"type": 'DEL', "value": 'PRESS', "ctrl": True}, None),
("curve.tilt_clear", {"type": 'T', "value": 'PRESS', "alt": True}, None),
- ("curve.pen", {"type": 'X', "value": 'PRESS', "alt": True}, None),
op_tool_optional(
("transform.tilt", {"type": 'T', "value": 'PRESS', "ctrl": True}, None),
(op_tool_cycle, "builtin.tilt"), params),
@@ -6084,20 +6083,6 @@ def km_sculpt_expand_modal(_params):
])
return keymap
-def km_curve_pen_modal_map(_params):
- items = []
- keymap = (
- "Curve Pen Modal Map",
- {"space_type": 'EMPTY', "region_type": 'WINDOW', "modal": True},
- {"items": items},
- )
-
- items.extend([
- ("FREE_MOVE_HANDLE", {"type": 'LEFT_SHIFT', "value": 'PRESS', "any": True}, None),
- ])
-
- return keymap
-
# Fallback for gizmos that don't have custom a custom key-map.
def km_generic_gizmo(_params):
@@ -7007,11 +6992,16 @@ def km_3d_view_tool_edit_curve_pen(params):
{"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
{"items": [
("curve.pen", {"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": []}),
+ {"properties": [
+ ("add_point", True),
+ ("move_segment", True),
+ ("select_point", True),
+ ("move_point", True)
+ ]}),
+ ("curve.pen", {"type": params.tool_mouse, "value": 'PRESS', "ctrl": True},
+ {"properties": [("delete_point", True),]}),
+ ("curve.pen", {"type": params.tool_mouse, "value": 'PRESS', "shift": True},
+ {"properties": [("insert_point", True),]}),
]},
)
@@ -7816,7 +7806,6 @@ def generate_keymaps(params=None):
km_view3d_dolly_modal(params),
km_paint_stroke_modal(params),
km_sculpt_expand_modal(params),
- km_curve_pen_modal_map(params),
# Gizmos.
km_generic_gizmo(params),
diff --git a/source/blender/editors/curve/curve_intern.h b/source/blender/editors/curve/curve_intern.h
index b4e9d9a78a3..3d8406cce91 100644
--- a/source/blender/editors/curve/curve_intern.h
+++ b/source/blender/editors/curve/curve_intern.h
@@ -231,6 +231,3 @@ void CURVE_OT_draw(struct wmOperatorType *ot);
/* editcurve_pen.c */
void CURVE_OT_pen(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 d2f9115951d..174b095584e 100644
--- a/source/blender/editors/curve/curve_ops.c
+++ b/source/blender/editors/curve/curve_ops.c
@@ -128,8 +128,6 @@ void ED_operatortypes_curve(void)
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_delete);
- WM_operatortype_append(CURVE_OT_pen_insert);
WM_operatortype_append(CURVE_OT_extrude);
WM_operatortype_append(CURVE_OT_cyclic_toggle);
@@ -169,6 +167,4 @@ void ED_keymap_curve(wmKeyConfig *keyconf)
/* only set in editmode curve, by space_view3d listener */
keymap = WM_keymap_ensure(keyconf, "Curve", 0, 0);
keymap->poll = ED_operator_editsurfcurve;
-
- curve_pen_modal_keymap(keyconf);
}
diff --git a/source/blender/editors/curve/editcurve_pen.c b/source/blender/editors/curve/editcurve_pen.c
index 67c1cc13f95..c38c8136a12 100644
--- a/source/blender/editors/curve/editcurve_pen.c
+++ b/source/blender/editors/curve/editcurve_pen.c
@@ -19,6 +19,7 @@
*/
#include "DNA_curve_types.h"
+#include "DNA_windowmanager_types.h"
#include "MEM_guardedalloc.h"
@@ -690,7 +691,10 @@ static void add_bp_to_nurb(Nurb *nu, const CutData *data, Curve *cu)
}
/* Make a cut on the nearest nurb at the closest point. Return true if spline is nearby. */
-static bool make_cut(const wmEvent *event, Curve *cu, Nurb **r_nu, const ViewContext *vc)
+static bool insert_point_to_segment(const wmEvent *event,
+ Curve *cu,
+ Nurb **r_nu,
+ const ViewContext *vc)
{
CutData data = {.bezt_index = 0,
.bp_index = 0,
@@ -771,7 +775,7 @@ static void add_vertex_connected_to_selected_vertex(const ViewContext *vc,
}
/* Check if a spline segment is nearby. */
-static bool is_spline_nearby(ViewContext *vc, wmOperator *op, const wmEvent *event)
+static bool is_spline_nearby(ViewContext *vc, struct wmOperator *op, const wmEvent *event)
{
Curve *cu = vc->obedit->data;
ListBase *nurbs = BKE_curve_editNurbs_get(cu);
@@ -788,12 +792,15 @@ static bool is_spline_nearby(ViewContext *vc, wmOperator *op, const wmEvent *eve
update_data_for_all_nurbs(nurbs, vc, &data);
const float sel_dist_mul = RNA_float_get(op->ptr, "sel_dist_mul");
const float threshold_distance = ED_view3d_select_dist_px() * sel_dist_mul;
- if (data.nurb && !data.nurb->bp && data.min_dist < threshold_distance) {
- MoveSegmentData *seg_data;
- op->customdata = seg_data = MEM_callocN(sizeof(MoveSegmentData), __func__);
- seg_data->bezt_index = data.bezt_index;
- seg_data->nu = data.nurb;
- seg_data->t = data.parameter;
+
+ if (data.min_dist < threshold_distance) {
+ if (data.nurb && !data.nurb->bp && RNA_boolean_get(op->ptr, "move_segment")) {
+ MoveSegmentData *seg_data;
+ op->customdata = seg_data = MEM_callocN(sizeof(MoveSegmentData), __func__);
+ seg_data->bezt_index = data.bezt_index;
+ seg_data->nu = data.nurb;
+ seg_data->t = data.parameter;
+ }
return true;
}
return false;
@@ -885,32 +892,129 @@ static void toggle_bezt_free_align_handles(BezTriple *bezt)
}
}
-enum {
- PEN_MODAL_FREE_MOVE_HANDLE = 1,
-};
+/* Returns true if point was found under mouse. */
+static bool delete_point_under_mouse(ViewContext *vc, const wmEvent *event)
+{
+ BezTriple *bezt = NULL;
+ BPoint *bp = NULL;
+ Nurb *nu = NULL;
+ 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;
+
+ bool deleted = false;
+ if (found_point) {
+ ED_curve_deselect_all(cu->editnurb);
+ if (nu) {
+ if (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 {
+ delete_bp_from_nurb(bp, nu);
+ }
-wmKeyMap *curve_pen_modal_keymap(wmKeyConfig *keyconf)
+ if (nu->pntsu == 0) {
+ delete_nurb(cu, nu);
+ }
+ deleted = true;
+ cu->actvert = CU_ACT_NONE;
+ }
+ }
+
+ if (nu && nu->type == CU_BEZIER) {
+ BKE_nurb_handles_calc(nu);
+ }
+
+ return deleted;
+}
+
+static void move_adjacent_handle(ViewContext *vc, const wmEvent *event)
{
- static const EnumPropertyItem modal_items[] = {
- {PEN_MODAL_FREE_MOVE_HANDLE,
- "FREE_MOVE_HANDLE",
- 0,
- "Free Move handle",
- "Move handle of newly added point freely"},
- {0, NULL, 0, NULL, NULL},
- };
-
- wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Curve Pen Modal Map");
-
- if (keymap && keymap->modal_items) {
- return NULL;
+ Nurb *nu;
+ BezTriple *bezt;
+ BPoint *bp;
+ ED_curve_nurb_vert_selected_find(vc->obedit->data, vc->v3d, &nu, &bezt, &bp);
+
+ /* Get the adjacent `BezTriple` */
+ BezTriple *adj_bezt = BKE_nurb_bezt_get_prev(nu, bezt);
+ int cp_index = 2;
+ if (!adj_bezt) {
+ adj_bezt = BKE_nurb_bezt_get_next(nu, bezt);
+ cp_index = 0;
}
- keymap = WM_modalkeymap_ensure(keyconf, "Curve Pen Modal Map", modal_items);
+ float screen_co_fl[2];
+ int displacement[2], screen_co_int[2];
+ /* Get the screen space coordinates of moved handle. */
+ ED_view3d_project_float_object(vc->region,
+ adj_bezt->vec[cp_index],
+ screen_co_fl,
+ V3D_PROJ_RET_CLIP_BB | V3D_PROJ_RET_CLIP_WIN);
+ sub_v2_v2v2_int(displacement, event->xy, event->prev_xy);
+ screen_co_int[0] = (int)screen_co_fl[0];
+ screen_co_int[1] = (int)screen_co_fl[1];
+
+ /* Add the displacement of the mouse to the handle position. */
+ add_v2_v2v2_int(screen_co_int, screen_co_int, displacement);
+ move_bezt_handle_or_vertex_to_location(adj_bezt, screen_co_int, cp_index, vc);
+ BKE_nurb_handles_calc(nu);
+}
+
+/* Close the spline if endpoints are selected consecutively. Return true if cycle was created. */
+static bool make_cyclic_if_endpoints(Nurb *sel_nu,
+ BezTriple *sel_bezt,
+ BPoint *sel_bp,
+ ViewContext *vc,
+ bContext *C,
+ const float sel_dist_mul)
+{
+ if (sel_bezt || sel_bp) {
+ const bool is_bezt_endpoint
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list