64 const int curve_index,
73 const IndexRange segments = segments_by_curve[curve_index];
75 for (
const int segment_i : segments) {
79 if (segment_i < segments.
last()) {
80 const int next_segment_i = segment_i + 1;
85 const int first_point_i = (segment_fraction == 0.0f ?
88 const int next_first_point_i = (next_segment_fraction == 0.0f ?
89 next_segment_point_i :
99 const int first_point_i = (segment_fraction == 0.0f ?
103 const int next_first_point_i = (first_segment_fraction == 0.0f ?
104 first_segment_point_i :
111 fn(segment_i, points_range1, points_range2);
114 return segments.
size();
130 for (
const StringRef selection_attribute_name : selection_attribute_names) {
167 if (attribute_name !=
".selection") {
172 if (point_selection_mask.
is_empty()) {
179 points_by_curve, point_selection_mask, memory);
185 curves, changed_curve_mask, screen_space_positions, tree_data, tree_data_range);
193 point_selection_mask.
to_bools(changed_points);
195 auto test_points_range = [&](
const IndexRange range) ->
bool {
196 for (
const int point_i : range) {
197 if (changed_points[point_i]) {
203 auto update_points_range = [&](
const IndexRange range) {
204 for (
const int point_i : range) {
210 for (const int curve_i : range) {
211 const IndexRange points = points_by_curve[curve_i];
213 const int num_segments = foreach_curve_segment(
217 [&](const int , const IndexRange points1, const IndexRange points2) {
218 if (test_points_range(points1) || test_points_range(points2)) {
219 update_points_range(points1);
220 update_points_range(points2);
223 if (num_segments == 0 && test_points_range(points)) {
225 update_points_range(points);
230 attribute_writer.finish();
248 bool changed =
false;
253 if (drawings.is_empty()) {
256 const int frame_number = drawings.first().frame_number;
261 if (use_segment_selection) {
267 for (
const int i_drawing : drawings.index_range()) {
278 *
object, info, selection_domain, memory);
285 for (
const StringRef attribute_name : selection_attribute_names) {
287 curves.attributes_for_write().lookup_or_add_for_write_span<
bool>(
288 attribute_name, selection_domain))
297 for (
const StringRef attribute_name : selection_attribute_names) {
298 IndexMask changed_element_mask = select_operation(info, elements, attribute_name, memory);
303 changed_element_mask,
curves, selection_domain, memory);
306 if (use_segment_selection) {
309 const IndexRange tree_data_range = tree_data_by_drawing[i_drawing];
311 curves, changed_element_mask, attribute_name, tree_data, tree_data_range, sel_op);
315 curves, changed_element_mask, selection_domain, attribute_name, sel_op);
346 *
object, info, selection_domain, memory);
347 if (selectable_elements.
is_empty()) {
369 ot->
name =
"(De)select All Strokes";
370 ot->
idname =
"GREASE_PENCIL_OT_select_all";
371 ot->
description =
"(De)select all visible strokes";
407 ot->
name =
"Select More";
408 ot->
idname =
"GREASE_PENCIL_OT_select_more";
409 ot->
description =
"Grow the selection by one point";
443 ot->
name =
"Select Less";
444 ot->
idname =
"GREASE_PENCIL_OT_select_less";
445 ot->
description =
"Shrink the selection by one point";
465 if (selectable_strokes.
is_empty()) {
481 ot->
name =
"Select Linked";
482 ot->
idname =
"GREASE_PENCIL_OT_select_linked";
483 ot->
description =
"Select all points in curves with any point selection";
491 ot->
srna,
"deselect",
false,
"Deselect linked",
"Deselect linked strokes");
520 *
object, info, selection_domain, memory);
521 if (selectable_elements.
is_empty()) {
524 return random_mask(selectable_elements,
541 ot->
name =
"Select Random";
542 ot->
idname =
"GREASE_PENCIL_OT_select_random";
543 ot->
description =
"Selects random points from the current strokes selection";
575 ot->
name =
"Select Alternate";
576 ot->
idname =
"GREASE_PENCIL_OT_select_alternate";
577 ot->
description =
"Select alternated points in strokes with already selected points";
588 "(De)select the first and last point of each stroke");
605 {0,
nullptr, 0,
nullptr,
nullptr},
629 [&](
const int index) {
630 Set<T> &local_value_set = value_set_by_thread.local();
640 [&](
const int index) {
641 Set<T> &local_value_set = value_set_by_thread.local();
650 for (
const Set<T> &local_value_set : value_set_by_thread) {
652 for (
const T &key : local_value_set) {
653 r_value_set.
add(key);
658template<
typename T,
typename DistanceFn>
666 DistanceFn distance_fn)
683 *
object, info, selection_domain, memory);
686 name, selection_domain, default_value);
690 for (
const int i : selection_attribute_names.index_range()) {
696 [&](
const int index) {
697 if (selection[
index]) {
700 for (
const T &test_value : selected_values) {
701 if (distance_fn(values[
index], test_value) <= threshold) {
702 selection[
index] =
true;
708 selection_writer.
finish();
724 *info.drawing.strokes().attributes().lookup_or_default<
bool>(
".selection", domain,
true);
727 selected_layers.
add(info.layer_index);
797 [](
const float a,
const float b) ->
float {
return math::distance(a,
b); });
808 [](
const float a,
const float b) ->
float {
return math::distance(a,
b); });
820 ot->
name =
"Select Similar";
821 ot->
idname =
"GREASE_PENCIL_OT_select_similar";
822 ot->
description =
"Select all strokes with similar characteristics";
854 info.
drawing.
strokes(), selectable_strokes, amount_start, amount_end,
false, memory);
867 ot->
name =
"Select Ends";
868 ot->
idname =
"GREASE_PENCIL_OT_select_ends";
882 "Number of points to select from the start",
891 "Number of points to select from the end",
927 const int fill_id = fill_ids[curve_i];
929 selected_fill_ids.
add(fill_id);
934 selected_strokes.
to_bools(selected_curves);
938 const int fill_id = fill_ids[curve_i];
940 return selected_curves[curve_i];
942 return selected_fill_ids.
contains(fill_id);
949 for (
const int i : selection_attribute_names.
index_range()) {
952 switch (selection_domain) {
958 strokes.foreach_index(
959 [&](
const int curve) {
960 const IndexRange points = points_by_curve[curve];
983 ot->
name =
"Select Fill";
984 ot->
idname =
"GREASE_PENCIL_OT_select_fill";
995 bool changed =
false;
1015 const std::optional<bke::AttributeMetaData> meta_data = attributes.
lookup_meta_data(
1020 if ((!meta_data) || (meta_data->domain == domain)) {
1033 for (
const StringRef selection_attribute_name :
1040 selection_writer.
finish();
1050 for (
const StringRef selection_attribute_name :
1057 selection_writer.
finish();
1064 for (
const StringRef selection_attribute_name :
1068 const GVArray src = *attributes.
lookup(selection_attribute_name, domain);
1073 attributes.
remove(selection_attribute_name);
1074 attributes.
add(selection_attribute_name,
1078 dst->remove_user_and_delete_if_last();
1099 bool changed =
false;
1132 ot->
name =
"Select Mode";
1134 ot->
description =
"Change the selection mode for Grease Pencil strokes";
1153 const int material_index =
object->actcol - 1;
1156 if (material_index == -1) {
1166 *
object, info.
drawing, material_index, memory);
1175 for (
const int i : selection_attribute_names.
index_range()) {
1185 const IndexRange points = points_by_curve[curve_index];
1206 ot->
name =
"Select Material";
1207 ot->
idname =
"GREASE_PENCIL_OT_material_select";
1208 ot->
description =
"Select/Deselect all Grease Pencil strokes using current material";
1235 const StrokeType stroke_type = StrokeType(
RNA_enum_get(op->
ptr,
"type"));
1239 std::atomic<bool> changed =
false;
1245 if (selectable_strokes.
is_empty()) {
1250 if (stroke_type == StrokeType::Stroke) {
1263 changed.store(
true, std::memory_order_relaxed);
1265 else if (stroke_type == StrokeType::Fill) {
1270 selectable_strokes, memory, [&](
const int index) {
return fill_id[
index] != 0; });
1275 changed.store(
true, std::memory_order_relaxed);
1291 {int(StrokeType::Stroke),
"STROKE", 0,
"Stroke",
""},
1292 {int(StrokeType::Fill),
"FILL", 0,
"Fill",
""},
1293 {0,
nullptr, 0,
nullptr,
nullptr},
1300 ot->
name =
"Select By Stroke Type";
1301 ot->
idname =
"GREASE_PENCIL_OT_select_by_stroke_type";
1302 ot->
description =
"Select/Deselect all strokes or fills";
Low-level operations for curves.
Low-level operations for curves.
Low-level operations for grease pencil.
General operations, lookup, etc. for blender objects.
#define BLI_SCOPED_DEFER(function_to_defer)
Object is a sort of wrapper for general info.
#define BLI_assert_unreachable()
static const CPPType & get()
void default_construct(void *ptr) const
GMutableSpan slice(const int64_t start, int64_t size) const
MutableSpan< T > typed() const
const CPPType & type() const
void materialize_to_uninitialized(void *dst) const
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
static IndexMask from_ranges(OffsetIndices< T > offsets, const IndexMask &mask, LinearAllocator<> &memory)
static IndexMask from_bools_inverse(Span< bool > bools, LinearAllocator<> &memory)
constexpr int64_t first() const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
constexpr bool is_empty() const
static constexpr IndexRange from_begin_end(const int64_t begin, const int64_t end)
constexpr IndexRange()=default
static constexpr IndexRange from_begin_end_inclusive(const int64_t begin, const int64_t last)
bool contains(const Key &key) const
constexpr IndexRange index_range() const
bool contains(const Key &key) const
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
std::optional< AttributeMetaData > lookup_meta_data(StringRef name) const
GAttributeReader lookup(const StringRef name) const
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
bool remove(const StringRef name)
bke::CurvesGeometry & strokes_for_write()
const bke::CurvesGeometry & strokes() const
constexpr IndexRange index_range() const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
void to_bools(MutableSpan< bool > r_bools) const
IndexRange index_range() const
IndexMask point_to_curve_selection(OffsetIndices< int > points_by_curve, const IndexMask &point_mask, LinearAllocator<> &memory)
IndexMask selected_mask_to_fills(const IndexMask &selected_mask, const CurvesGeometry &curves, AttrDomain selection_domain, IndexMaskMemory &memory)
AttrType cpp_type_to_attribute_type(const CPPType &type)
bool has_anything_selected(const VArray< bool > &varray, const IndexRange range_to_check)
void apply_selection_operation_at_index(GMutableSpan selection, const int index, const eSelectOp sel_op)
void select_linked(bke::CurvesGeometry &curves, const IndexMask &curves_mask, const bool unselect)
void select_all(bke::CurvesGeometry &curves, const IndexMask &mask, const bke::AttrDomain selection_domain, int action)
IndexMask retrieve_selected_points(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
void select_alternate(bke::CurvesGeometry &curves, const IndexMask &curves_mask, const bool deselect_ends)
void fill_selection_false(GMutableSpan selection)
IndexMask select_adjacent_mask(const bke::CurvesGeometry &curves, const IndexMask &curves_mask, const StringRef attribute_name, const bool deselect, IndexMaskMemory &memory)
IndexMask retrieve_selected_curves(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
void fill_selection_true(GMutableSpan selection)
Span< StringRef > get_curves_selection_attribute_names(const bke::CurvesGeometry &curves)
void fill_selection(GMutableSpan selection, bool value)
IndexMask end_points(const bke::CurvesGeometry &curves, const IndexMask &curves_mask, const int amount_start, const int amount_end, const bool inverted, IndexMaskMemory &memory)
bke::GSpanAttributeWriter ensure_selection_attribute(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain, bke::AttrType create_type, StringRef attribute_name)
static void GREASE_PENCIL_OT_select_linked(wmOperatorType *ot)
static void select_similar_by_value(Scene *scene, Object *object, GreasePencil &grease_pencil, const bke::AttrDomain selection_domain, const StringRef name, const eHandleDisplay handle_display, float threshold, DistanceFn distance_fn)
IndexMask retrieve_editable_and_selected_strokes(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
static wmOperatorStatus select_fill_exec(bContext *C, wmOperator *)
static wmOperatorStatus select_ends_exec(bContext *C, wmOperator *op)
FunctionRef< IndexMask(const ed::greasepencil::MutableDrawingInfo &info, const IndexMask &universe, StringRef attribute_name, IndexMaskMemory &memory)> SelectionUpdateFunc
static const EnumPropertyItem select_by_stroke_type_items[]
bool apply_mask_as_selection(bke::CurvesGeometry &curves, const IndexMask &selection_mask, const bke::AttrDomain selection_domain, const StringRef attribute_name, const eSelectOp sel_op)
static void GREASE_PENCIL_OT_select_more(wmOperatorType *ot)
static wmOperatorStatus select_set_mode_exec(bContext *C, wmOperator *op)
bool selection_update(const ViewContext *vc, const eSelectOp sel_op, SelectionUpdateFunc select_operation)
bool ensure_selection_domain(ToolSettings *ts, Object *object)
static wmOperatorStatus select_more_exec(bContext *C, wmOperator *)
bool editable_grease_pencil_point_selection_poll(bContext *C)
IndexMask retrieve_editable_elements(Object &object, const MutableDrawingInfo &info, const bke::AttrDomain selection_domain, IndexMaskMemory &memory)
void free_curves_2d_bvh_data(Curves2DBVHTree &data)
static const EnumPropertyItem select_similar_mode_items[]
CurveSegmentsData find_curve_segments(const bke::CurvesGeometry &curves, const IndexMask &curve_mask, const Span< float2 > screen_space_positions, const Curves2DBVHTree &tree_data, const IndexRange tree_data_range)
static wmOperatorStatus select_alternate_exec(bContext *C, wmOperator *op)
static void select_similar_by_layer(Scene *scene, Object *object, GreasePencil &grease_pencil, bke::AttrDomain domain)
IndexMask retrieve_editable_strokes_by_material(Object &object, const bke::greasepencil::Drawing &drawing, const int mat_i, IndexMaskMemory &memory)
static wmOperatorStatus select_all_exec(bContext *C, wmOperator *op)
static wmOperatorStatus select_random_exec(bContext *C, wmOperator *op)
int clamp_range(const IndexRange range, const int index)
bool editable_grease_pencil_poll(bContext *C)
static wmOperatorStatus select_similar_exec(bContext *C, wmOperator *op)
static int foreach_curve_segment(const CurveSegmentsData &segment_data, const int curve_index, const IndexRange points, Fn &&fn)
static void GREASE_PENCIL_OT_select_less(wmOperatorType *ot)
IndexMask retrieve_editable_and_all_selected_points(Object &object, const bke::greasepencil::Drawing &drawing, const int layer_index, const eHandleDisplay handle_display, IndexMaskMemory &memory)
bool apply_mask_as_segment_selection(bke::CurvesGeometry &curves, const IndexMask &point_selection_mask, const StringRef attribute_name, const Curves2DBVHTree &tree_data, const IndexRange tree_data_range, const eSelectOp sel_op)
static void GREASE_PENCIL_OT_select_all(wmOperatorType *ot)
static void GREASE_PENCIL_OT_select_alternate(wmOperatorType *ot)
static void GREASE_PENCIL_OT_select_ends(wmOperatorType *ot)
eHandleDisplay view3d_handle_type_or_default(const View3D *v3d)
static void GREASE_PENCIL_OT_select_similar(wmOperatorType *ot)
IndexMask retrieve_editable_strokes(Object &object, const bke::greasepencil::Drawing &drawing, int layer_index, IndexMaskMemory &memory)
static wmOperatorStatus select_less_exec(bContext *C, wmOperator *)
Vector< MutableDrawingInfo > retrieve_editable_drawings(const Scene &scene, GreasePencil &grease_pencil)
Curves2DBVHTree build_curves_2d_bvh_from_visible(const ViewContext &vc, const Object &object, const GreasePencil &grease_pencil, Span< MutableDrawingInfo > drawings, const int frame_number)
void insert_selected_values(Object *object, const MutableDrawingInfo &info, const bke::AttrDomain domain, const StringRef name, const eHandleDisplay handle_display, Set< T > &r_value_set)
static void GREASE_PENCIL_OT_select_random(wmOperatorType *ot)
static wmOperatorStatus grease_pencil_material_select_exec(bContext *C, wmOperator *op)
static void GREASE_PENCIL_OT_material_select(wmOperatorType *ot)
static void GREASE_PENCIL_OT_set_selection_mode(wmOperatorType *ot)
static wmOperatorStatus grease_pencil_select_by_stroke_type_exec(bContext *C, wmOperator *op)
Array< Vector< MutableDrawingInfo > > retrieve_editable_drawings_grouped_per_frame(const Scene &scene, GreasePencil &grease_pencil)
static void GREASE_PENCIL_OT_select_by_stroke_type(wmOperatorType *ot)
static void GREASE_PENCIL_OT_select_fill(wmOperatorType *ot)
static wmOperatorStatus select_linked_exec(bContext *C, wmOperator *op)
constexpr ParallelGrainSize grain_size(int grain_size)
void masked_fill(MutableSpan< T > data, const T &value, const IndexMask &mask)
T distance(const T &a, const T &b)
void parallel_for_each(Range &&range, const Function &function)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
void WM_main_add_notifier(uint type, void *reference)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
int RNA_enum_get(PointerRNA *ptr, const char *name)
void WM_operator_properties_select_random(wmOperatorType *ot)
ViewContext ED_view3d_viewcontext_init(bContext *C, Depsgraph *depsgraph)
eGP_Sculpt_SelectMaskFlag
@ GP_SCULPT_MASK_SELECTMODE_POINT
@ GP_SCULPT_MASK_SELECTMODE_STROKE
@ GP_SCULPT_MASK_SELECTMODE_SEGMENT
bool ED_grease_pencil_vertex_segment_selection_enabled(const ToolSettings *tool_settings)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
int WM_operator_properties_select_random_seed_increment_get(wmOperator *op)
bool ED_grease_pencil_segment_selection_enabled(const ToolSettings *tool_settings, const Object *object)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void ED_operatortypes_grease_pencil_select()
int RNA_int_get(PointerRNA *ptr, const char *name)
void WM_operator_properties_select_all(wmOperatorType *ot)
VecBase< float, 4 > float4
bke::AttrDomain ED_grease_pencil_sculpt_selection_domain_get(const ToolSettings *tool_settings)
eGP_Vertex_SelectMaskFlag
@ GP_VERTEX_MASK_SELECTMODE_STROKE
@ GP_VERTEX_MASK_SELECTMODE_POINT
@ GP_VERTEX_MASK_SELECTMODE_SEGMENT
void DEG_id_tag_update(ID *id, unsigned int flags)
@ OB_MODE_VERTEX_GREASE_PENCIL
@ OB_MODE_SCULPT_GREASE_PENCIL
@ OB_MODE_PAINT_GREASE_PENCIL
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
bke::AttrDomain ED_grease_pencil_edit_selection_domain_get(const ToolSettings *tool_settings)
ToolSettings * CTX_data_tool_settings(const bContext *C)
bool ED_grease_pencil_any_vertex_mask_selection(const ToolSettings *tool_settings)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
bke::AttrDomain ED_grease_pencil_selection_domain_get(const ToolSettings *tool_settings, const Object *object)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
bool ED_grease_pencil_edit_segment_selection_enabled(const ToolSettings *tool_settings)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
const EnumPropertyItem rna_enum_grease_pencil_selectmode_items[]
bool ED_grease_pencil_sculpt_segment_selection_enabled(const ToolSettings *tool_settings)
bke::AttrDomain ED_grease_pencil_vertex_selection_domain_get(const ToolSettings *tool_settings)
Scene * CTX_data_scene(const bContext *C)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
eGPencil_Selectmode_types
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
bool BKE_object_is_mode_compat(const Object *ob, eObjectMode object_mode)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
Object * CTX_data_active_object(const bContext *C)
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
float RNA_float_get(PointerRNA *ptr, const char *name)
View3D * CTX_wm_view3d(const bContext *C)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
GreasePencilDrawingType type
struct ToolSettings * toolsettings
Array< int > segment_offsets
Array< int > segment_start_points
Array< float > segment_start_fractions
Array< int > drawing_offsets
Array< float2 > start_positions
bke::greasepencil::Drawing & drawing
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT