Blender V5.0
select_linked_pick.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_context.hh"
6#include "BKE_curves.hh"
7#include "BKE_layer.hh"
8
9#include "RNA_access.hh"
10#include "RNA_define.hh"
11
12#include "DEG_depsgraph.hh"
13
14#include "WM_api.hh"
15#include "WM_types.hh"
16
17#include "ED_curves.hh"
18#include "ED_view3d.hh"
19
20namespace blender::ed::curves {
21
27 const ViewContext &vc,
28 const Span<Base *> bases,
29 const int2 &mval)
30{
32 bases.index_range(),
33 1L,
35 [&](const IndexRange range, const ClosestCurveDataBlock &init) {
36 ClosestCurveDataBlock new_closest = init;
37 for (Base *base : bases.slice(range)) {
38 Object &curves_ob = *base->object;
39 Curves &curves_id = *static_cast<Curves *>(curves_ob.data);
42 const bke::CurvesGeometry &curves = curves_id.geometry.wrap();
43 const float4x4 projection = ED_view3d_ob_project_mat_get(vc.rv3d, &curves_ob);
45 curves,
46 deformation,
48 [&](IndexRange range, Span<float3> positions, StringRef /*selection_name*/) {
49 std::optional<FindClosestData> new_closest_elem = closest_elem_find_screen_space(
50 vc,
51 curves.points_by_curve(),
52 positions,
53 curves.cyclic(),
54 projection,
55 range,
56 bke::AttrDomain::Curve,
57 mval,
58 new_closest.elem);
59 if (new_closest_elem) {
60 new_closest.elem = *new_closest_elem;
61 new_closest.curves_id = &curves_id;
62 }
63 });
64 }
65 return new_closest;
66 },
67 [](const ClosestCurveDataBlock &a, const ClosestCurveDataBlock &b) {
68 return (a.elem.distance_sq < b.elem.distance_sq) ? a : b;
69 });
70}
71
72static bool select_linked_pick(bContext &C, const int2 &mval, const SelectPick_Params &params)
73{
77 vc.scene, vc.view_layer, vc.v3d);
78
80 if (!closest.curves_id) {
81 return false;
82 }
83
84 bke::CurvesGeometry &closest_curves = closest.curves_id->geometry.wrap();
85 const bke::AttrDomain selection_domain = bke::AttrDomain(closest.curves_id->selection_domain);
86
87 if (selection_domain == bke::AttrDomain::Point) {
88 const OffsetIndices points_by_curve = closest_curves.points_by_curve();
90 closest_curves, bke::AttrDomain::Point, [&](bke::GSpanAttributeWriter &selection) {
91 for (const int point : points_by_curve[closest.elem.index]) {
92 apply_selection_operation_at_index(selection.span, point, params.sel_op);
93 }
94 });
95 }
96 else if (selection_domain == bke::AttrDomain::Curve) {
99 apply_selection_operation_at_index(selection.span, closest.elem.index, params.sel_op);
100 selection.finish();
101 }
102
103 /* Use #ID_RECALC_GEOMETRY instead of #ID_RECALC_SELECT because it is handled as a
104 * generic attribute for now. */
107
108 return true;
109}
110
112 wmOperator *op,
113 const wmEvent *event)
114{
116 params.sel_op = RNA_boolean_get(op->ptr, "deselect") ? SEL_OP_SUB : SEL_OP_ADD;
117 params.deselect_all = false;
118 params.select_passthrough = false;
119
120 if (!select_linked_pick(*C, event->mval, params)) {
121 return OPERATOR_CANCELLED;
122 }
123
124 return OPERATOR_FINISHED;
125}
126
128{
129 ot->name = "Select Linked";
130 ot->idname = "CURVES_OT_select_linked_pick";
131 ot->description = "Select all points in the curve under the cursor";
132
134 ot->poll = editable_curves_poll;
135
137
138 RNA_def_boolean(ot->srna,
139 "deselect",
140 false,
141 "Deselect",
142 "Deselect linked control points rather than selecting them");
143}
144
145} // namespace blender::ed::curves
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Low-level operations for curves.
blender::Vector< Base * > BKE_view_layer_array_from_bases_in_edit_mode_unique_data(const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
void DEG_id_tag_update(ID *id, unsigned int flags)
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
eHandleDisplay
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ SEL_OP_ADD
@ SEL_OP_SUB
ViewContext ED_view3d_viewcontext_init(bContext *C, Depsgraph *depsgraph)
blender::float4x4 ED_view3d_ob_project_mat_get(const RegionView3D *rv3d, const Object *ob)
#define C
Definition RandGen.cpp:29
#define NC_GEOM
Definition WM_types.hh:393
#define ND_DATA
Definition WM_types.hh:509
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
BPy_StructRNA * depsgraph
bool closest(btVector3 &v)
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:137
constexpr IndexRange index_range() const
Definition BLI_span.hh:401
OffsetIndices< int > points_by_curve() const
static wmOperatorStatus select_linked_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
GeometryDeformation get_evaluated_curves_deformation(const Object *ob_eval, const Object &ob_orig)
static bool select_linked_pick(bContext &C, const int2 &mval, const SelectPick_Params &params)
void apply_selection_operation_at_index(GMutableSpan selection, const int index, const eSelectOp sel_op)
static ClosestCurveDataBlock find_closest_curve(const Depsgraph &depsgraph, const ViewContext &vc, const Span< Base * > bases, const int2 &mval)
static wmOperatorStatus select_linked_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void foreach_selectable_curve_range(const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, eHandleDisplay handle_display, SelectionRangeFn range_consumer)
bool editable_curves_poll(bContext *C)
void foreach_selection_attribute_writer(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain, blender::FunctionRef< void(bke::GSpanAttributeWriter &selection)> fn)
bke::GSpanAttributeWriter ensure_selection_attribute(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain, bke::AttrType create_type, StringRef attribute_name)
void CURVES_OT_select_linked_pick(wmOperatorType *ot)
Value parallel_reduce(IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
Definition BLI_task.hh:151
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 2 > int2
static void init(bNodeTree *, bNode *node)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
blender::ed::curves::FindClosestData elem
CurvesGeometry geometry
View3DOverlay overlay
RegionView3D * rv3d
Definition ED_view3d.hh:80
Scene * scene
Definition ED_view3d.hh:73
ViewLayer * view_layer
Definition ED_view3d.hh:74
View3D * v3d
Definition ED_view3d.hh:78
int mval[2]
Definition WM_types.hh:763
struct PointerRNA * ptr
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition wm_files.cc:4237