From 1627de3197e021dcb90a7d59fb1766735e4c0f5e Mon Sep 17 00:00:00 2001 From: Falk David Date: Fri, 9 Jun 2023 11:58:31 +0200 Subject: [PATCH 1/4] Add "amount_front"/"-back" options for select_ends --- scripts/startup/bl_ui/space_view3d.py | 4 +- .../editors/curves/intern/curves_ops.cc | 39 ++++++++++++------- .../editors/curves/intern/curves_selection.cc | 11 ++---- source/blender/editors/include/ED_curves.h | 6 +-- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/scripts/startup/bl_ui/space_view3d.py b/scripts/startup/bl_ui/space_view3d.py index 48b1d0be7e7..e96c3ed2793 100644 --- a/scripts/startup/bl_ui/space_view3d.py +++ b/scripts/startup/bl_ui/space_view3d.py @@ -2103,7 +2103,7 @@ class VIEW3D_MT_select_edit_curves(Menu): layout.separator() layout.operator("curves.select_random", text="Random") - layout.operator("curves.select_end", text="Endpoints") + layout.operator("curves.select_ends", text="Endpoints") layout.operator("curves.select_linked", text="Linked") layout.separator() @@ -2121,7 +2121,7 @@ class VIEW3D_MT_select_sculpt_curves(Menu): layout.operator("curves.select_all", text="None").action = 'DESELECT' layout.operator("curves.select_all", text="Invert").action = 'INVERT' layout.operator("sculpt_curves.select_random", text="Random") - layout.operator("curves.select_end", text="Endpoints") + layout.operator("curves.select_ends", text="Endpoints") layout.operator("sculpt_curves.select_grow", text="Grow") diff --git a/source/blender/editors/curves/intern/curves_ops.cc b/source/blender/editors/curves/intern/curves_ops.cc index f0edf8b8cae..ae81dcafcd9 100644 --- a/source/blender/editors/curves/intern/curves_ops.cc +++ b/source/blender/editors/curves/intern/curves_ops.cc @@ -938,15 +938,15 @@ static void CURVES_OT_select_random(wmOperatorType *ot) 1.0f); } -static int select_end_exec(bContext *C, wmOperator *op) +static int select_ends_exec(bContext *C, wmOperator *op) { VectorSet unique_curves = curves::get_unique_editable_curves(*C); - const bool end_points = RNA_boolean_get(op->ptr, "end_points"); - const int amount = RNA_int_get(op->ptr, "amount"); + const int amount_front = RNA_int_get(op->ptr, "amount_front"); + const int amount_back = RNA_int_get(op->ptr, "amount_back"); for (Curves *curves_id : unique_curves) { CurvesGeometry &curves = curves_id->geometry.wrap(); - select_ends(curves, amount, end_points); + select_ends(curves, amount_front, amount_back); /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic * attribute for now. */ @@ -957,24 +957,35 @@ static int select_end_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static void CURVES_OT_select_end(wmOperatorType *ot) +static void CURVES_OT_select_ends(wmOperatorType *ot) { ot->name = "Select End"; ot->idname = __func__; ot->description = "Select end points of curves"; - ot->exec = select_end_exec; + ot->exec = select_ends_exec; ot->poll = editable_curves_point_domain_poll; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - RNA_def_boolean(ot->srna, - "end_points", - true, - "End Points", - "Select points at the end of the curve as opposed to the beginning"); - RNA_def_int( - ot->srna, "amount", 1, 0, INT32_MAX, "Amount", "Number of points to select", 0, INT32_MAX); + RNA_def_int(ot->srna, + "amount_front", + 0, + 0, + INT32_MAX, + "Amount Front", + "Number of points to select from the front", + 0, + INT32_MAX); + RNA_def_int(ot->srna, + "amount_back", + 1, + 0, + INT32_MAX, + "Amount Back", + "Number of points to select from the back", + 0, + INT32_MAX); } static int select_linked_exec(bContext *C, wmOperator * /*op*/) @@ -1181,7 +1192,7 @@ void ED_operatortypes_curves() WM_operatortype_append(CURVES_OT_set_selection_domain); WM_operatortype_append(CURVES_OT_select_all); WM_operatortype_append(CURVES_OT_select_random); - WM_operatortype_append(CURVES_OT_select_end); + WM_operatortype_append(CURVES_OT_select_ends); WM_operatortype_append(CURVES_OT_select_linked); WM_operatortype_append(CURVES_OT_select_more); WM_operatortype_append(CURVES_OT_select_less); diff --git a/source/blender/editors/curves/intern/curves_selection.cc b/source/blender/editors/curves/intern/curves_selection.cc index aebaf763e14..76478ec4260 100644 --- a/source/blender/editors/curves/intern/curves_selection.cc +++ b/source/blender/editors/curves/intern/curves_selection.cc @@ -222,7 +222,7 @@ void select_all(bke::CurvesGeometry &curves, const eAttrDomain selection_domain, } } -void select_ends(bke::CurvesGeometry &curves, int amount, bool end_points) +void select_ends(bke::CurvesGeometry &curves, int amount_front, int amount_back) { const bool was_anything_selected = has_anything_selected(curves); const OffsetIndices points_by_curve = curves.points_by_curve(); @@ -240,12 +240,9 @@ void select_ends(bke::CurvesGeometry &curves, int amount, bool end_points) MutableSpan selection_typed = selection.span.typed(); threading::parallel_for(curves.curves_range(), 256, [&](const IndexRange range) { for (const int curve_i : range) { - if (end_points) { - selection_typed.slice(points_by_curve[curve_i].drop_back(amount)).fill(T(0)); - } - else { - selection_typed.slice(points_by_curve[curve_i].drop_front(amount)).fill(T(0)); - } + selection_typed + .slice(points_by_curve[curve_i].drop_front(amount_front).drop_back(amount_back)) + .fill(T(0)); } }); } diff --git a/source/blender/editors/include/ED_curves.h b/source/blender/editors/include/ED_curves.h index ddd60730dfc..acd8c941f38 100644 --- a/source/blender/editors/include/ED_curves.h +++ b/source/blender/editors/include/ED_curves.h @@ -150,10 +150,10 @@ void select_all(bke::CurvesGeometry &curves, eAttrDomain selection_domain, int a /** * Select the ends (front or back) of all the curves. * - * \param amount: The amount of points to select from the front or back. - * \param end_points: If true, select the last point(s), if false, select the first point(s). + * \param amount_front: The amount of points to select from the front. + * \param amount_back: The amount of points to select from the back. */ -void select_ends(bke::CurvesGeometry &curves, int amount, bool end_points); +void select_ends(bke::CurvesGeometry &curves, int amount_front, int amount_back); /** * Select the points of all curves that have at least one point selected. -- 2.30.2 From 6c113a019543d7b2958fea2cb6be27559b984b2a Mon Sep 17 00:00:00 2001 From: Falk David Date: Fri, 9 Jun 2023 15:09:22 +0200 Subject: [PATCH 2/4] Rename operator to "Select Ends" --- source/blender/editors/curves/intern/curves_ops.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/editors/curves/intern/curves_ops.cc b/source/blender/editors/curves/intern/curves_ops.cc index ae81dcafcd9..ae446d0f47b 100644 --- a/source/blender/editors/curves/intern/curves_ops.cc +++ b/source/blender/editors/curves/intern/curves_ops.cc @@ -959,7 +959,7 @@ static int select_ends_exec(bContext *C, wmOperator *op) static void CURVES_OT_select_ends(wmOperatorType *ot) { - ot->name = "Select End"; + ot->name = "Select Ends"; ot->idname = __func__; ot->description = "Select end points of curves"; -- 2.30.2 From c51eb3a3e9b3c732c46c70f90722146caa6e9510 Mon Sep 17 00:00:00 2001 From: Falk David Date: Fri, 9 Jun 2023 15:29:15 +0200 Subject: [PATCH 3/4] Add custom ui callback --- .../blender/editors/curves/intern/curves_ops.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/blender/editors/curves/intern/curves_ops.cc b/source/blender/editors/curves/intern/curves_ops.cc index ae446d0f47b..55633bbf597 100644 --- a/source/blender/editors/curves/intern/curves_ops.cc +++ b/source/blender/editors/curves/intern/curves_ops.cc @@ -16,6 +16,8 @@ #include "BLI_utildefines.h" #include "BLI_vector_set.hh" +#include "BLT_translation.h" + #include "ED_curves.h" #include "ED_object.h" #include "ED_screen.h" @@ -957,6 +959,18 @@ static int select_ends_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +static void select_ends_ui(bContext * /*C*/, wmOperator *op) +{ + uiLayout *layout = op->layout; + + uiLayoutSetPropSep(layout, true); + + uiLayout *col = uiLayoutColumn(layout, true); + uiLayoutSetPropDecorate(col, false); + uiItemR(col, op->ptr, "amount_front", 0, IFACE_("Amount Front"), ICON_NONE); + uiItemR(col, op->ptr, "amount_back", 0, IFACE_("Back"), ICON_NONE); +} + static void CURVES_OT_select_ends(wmOperatorType *ot) { ot->name = "Select Ends"; @@ -964,6 +978,7 @@ static void CURVES_OT_select_ends(wmOperatorType *ot) ot->description = "Select end points of curves"; ot->exec = select_ends_exec; + ot->ui = select_ends_ui; ot->poll = editable_curves_point_domain_poll; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -- 2.30.2 From 415da99b5510ed5ebc4ddf165fdfefe77515d6ca Mon Sep 17 00:00:00 2001 From: Falk David Date: Fri, 9 Jun 2023 15:58:40 +0200 Subject: [PATCH 4/4] Rename "front"/"back" to "start"/"end" --- source/blender/editors/curves/intern/curves_ops.cc | 14 +++++++------- .../editors/curves/intern/curves_selection.cc | 4 ++-- source/blender/editors/include/ED_curves.h | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/blender/editors/curves/intern/curves_ops.cc b/source/blender/editors/curves/intern/curves_ops.cc index 55633bbf597..401e85192b9 100644 --- a/source/blender/editors/curves/intern/curves_ops.cc +++ b/source/blender/editors/curves/intern/curves_ops.cc @@ -943,12 +943,12 @@ static void CURVES_OT_select_random(wmOperatorType *ot) static int select_ends_exec(bContext *C, wmOperator *op) { VectorSet unique_curves = curves::get_unique_editable_curves(*C); - const int amount_front = RNA_int_get(op->ptr, "amount_front"); - const int amount_back = RNA_int_get(op->ptr, "amount_back"); + const int amount_start = RNA_int_get(op->ptr, "amount_start"); + const int amount_end = RNA_int_get(op->ptr, "amount_end"); for (Curves *curves_id : unique_curves) { CurvesGeometry &curves = curves_id->geometry.wrap(); - select_ends(curves, amount_front, amount_back); + select_ends(curves, amount_start, amount_end); /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a generic * attribute for now. */ @@ -967,8 +967,8 @@ static void select_ends_ui(bContext * /*C*/, wmOperator *op) uiLayout *col = uiLayoutColumn(layout, true); uiLayoutSetPropDecorate(col, false); - uiItemR(col, op->ptr, "amount_front", 0, IFACE_("Amount Front"), ICON_NONE); - uiItemR(col, op->ptr, "amount_back", 0, IFACE_("Back"), ICON_NONE); + uiItemR(col, op->ptr, "amount_start", 0, IFACE_("Amount Start"), ICON_NONE); + uiItemR(col, op->ptr, "amount_end", 0, IFACE_("End"), ICON_NONE); } static void CURVES_OT_select_ends(wmOperatorType *ot) @@ -984,7 +984,7 @@ static void CURVES_OT_select_ends(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_int(ot->srna, - "amount_front", + "amount_start", 0, 0, INT32_MAX, @@ -993,7 +993,7 @@ static void CURVES_OT_select_ends(wmOperatorType *ot) 0, INT32_MAX); RNA_def_int(ot->srna, - "amount_back", + "amount_end", 1, 0, INT32_MAX, diff --git a/source/blender/editors/curves/intern/curves_selection.cc b/source/blender/editors/curves/intern/curves_selection.cc index 76478ec4260..591ed935e6f 100644 --- a/source/blender/editors/curves/intern/curves_selection.cc +++ b/source/blender/editors/curves/intern/curves_selection.cc @@ -222,7 +222,7 @@ void select_all(bke::CurvesGeometry &curves, const eAttrDomain selection_domain, } } -void select_ends(bke::CurvesGeometry &curves, int amount_front, int amount_back) +void select_ends(bke::CurvesGeometry &curves, int amount_start, int amount_end) { const bool was_anything_selected = has_anything_selected(curves); const OffsetIndices points_by_curve = curves.points_by_curve(); @@ -241,7 +241,7 @@ void select_ends(bke::CurvesGeometry &curves, int amount_front, int amount_back) threading::parallel_for(curves.curves_range(), 256, [&](const IndexRange range) { for (const int curve_i : range) { selection_typed - .slice(points_by_curve[curve_i].drop_front(amount_front).drop_back(amount_back)) + .slice(points_by_curve[curve_i].drop_front(amount_start).drop_back(amount_end)) .fill(T(0)); } }); diff --git a/source/blender/editors/include/ED_curves.h b/source/blender/editors/include/ED_curves.h index acd8c941f38..e4404ab0971 100644 --- a/source/blender/editors/include/ED_curves.h +++ b/source/blender/editors/include/ED_curves.h @@ -150,10 +150,10 @@ void select_all(bke::CurvesGeometry &curves, eAttrDomain selection_domain, int a /** * Select the ends (front or back) of all the curves. * - * \param amount_front: The amount of points to select from the front. - * \param amount_back: The amount of points to select from the back. + * \param amount_start: The amount of points to select from the front. + * \param amount_end: The amount of points to select from the back. */ -void select_ends(bke::CurvesGeometry &curves, int amount_front, int amount_back); +void select_ends(bke::CurvesGeometry &curves, int amount_start, int amount_end); /** * Select the points of all curves that have at least one point selected. -- 2.30.2