diff options
-rw-r--r-- | source/blender/blenkernel/BKE_mball.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mball.c | 41 | ||||
-rw-r--r-- | source/blender/editors/metaball/mball_edit.c | 34 |
3 files changed, 62 insertions, 17 deletions
diff --git a/source/blender/blenkernel/BKE_mball.h b/source/blender/blenkernel/BKE_mball.h index 2eee5f72c0f..ae86d978cb7 100644 --- a/source/blender/blenkernel/BKE_mball.h +++ b/source/blender/blenkernel/BKE_mball.h @@ -49,6 +49,7 @@ struct MetaBall *BKE_mball_copy(struct Main *bmain, const struct MetaBall *mb); void BKE_mball_make_local(struct Main *bmain, struct MetaBall *mb, const bool lib_local); bool BKE_mball_is_any_selected(const struct MetaBall *mb); +bool BKE_mball_is_any_selected_multi(struct Object **objects, int objects_len); bool BKE_mball_is_any_unselected(const struct MetaBall *mb); bool BKE_mball_is_basis_for(struct Object *ob1, struct Object *ob2); bool BKE_mball_is_basis(struct Object *ob); @@ -71,8 +72,11 @@ void BKE_mball_translate(struct MetaBall *mb, const float offset[3]); struct MetaElem *BKE_mball_element_add(struct MetaBall *mb, const int type); void BKE_mball_select_all(struct MetaBall *mb); +void BKE_mball_select_all_multi(struct Object **objects, int objects_len); void BKE_mball_deselect_all(struct MetaBall *mb); +void BKE_mball_deselect_all_multi(struct Object **objects, int objects_len); void BKE_mball_select_swap(struct MetaBall *mb); +void BKE_mball_select_swap_multi(struct Object **objects, int objects_len); /* **** Depsgraph evaluation **** */ diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index f39808231e1..5b1accd955d 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -338,6 +338,19 @@ bool BKE_mball_is_any_selected(const MetaBall *mb) return false; } + +bool BKE_mball_is_any_selected_multi(Object **objects, int objects_len) +{ + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + MetaBall *mb = (MetaBall *)obedit->data; + if (BKE_mball_is_any_selected(mb)) { + return true; + } + } + return false; +} + bool BKE_mball_is_any_unselected(const MetaBall *mb) { for (const MetaElem *ml = mb->editelems->first; ml != NULL; ml = ml->next) { @@ -557,6 +570,15 @@ void BKE_mball_select_all(struct MetaBall *mb) } } +void BKE_mball_select_all_multi(Object **objects, int objects_len) +{ + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + MetaBall *mb = (MetaBall *)obedit->data; + BKE_mball_select_all(mb); + } +} + void BKE_mball_deselect_all(MetaBall *mb) { MetaElem *ml; @@ -566,6 +588,16 @@ void BKE_mball_deselect_all(MetaBall *mb) } } +void BKE_mball_deselect_all_multi(Object **objects, int objects_len) +{ + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + MetaBall *mb = (MetaBall *)obedit->data; + + BKE_mball_deselect_all(mb); + } +} + void BKE_mball_select_swap(struct MetaBall *mb) { MetaElem *ml; @@ -575,6 +607,15 @@ void BKE_mball_select_swap(struct MetaBall *mb) } } +void BKE_mball_select_swap_multi(Object **objects, int objects_len) +{ + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + MetaBall *mb = (MetaBall *)obedit->data; + BKE_mball_select_swap(mb); + } +} + /* **** Depsgraph evaluation **** */ /* Draw Engine */ diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c index 816d91dbad9..b959ff80024 100644 --- a/source/blender/editors/metaball/mball_edit.c +++ b/source/blender/editors/metaball/mball_edit.c @@ -125,38 +125,38 @@ MetaElem *ED_mball_add_primitive(bContext *UNUSED(C), Object *obedit, float mat[ /* Select or deselect all MetaElements */ static int mball_select_all_exec(bContext *C, wmOperator *op) { - Object *obedit = CTX_data_edit_object(C); - MetaBall *mb = (MetaBall *)obedit->data; - MetaElem *ml; int action = RNA_enum_get(op->ptr, "action"); - if (BLI_listbase_is_empty(mb->editelems)) - return OPERATOR_CANCELLED; + ViewLayer *view_layer = CTX_data_view_layer(C); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); if (action == SEL_TOGGLE) { - action = SEL_SELECT; - for (ml = mb->editelems->first; ml; ml = ml->next) { - if (ml->flag & SELECT) { - action = SEL_DESELECT; - break; - } - } + action = BKE_mball_is_any_selected_multi(objects, objects_len) ? + SEL_DESELECT : + SEL_SELECT; } switch (action) { case SEL_SELECT: - BKE_mball_select_all(mb); + BKE_mball_select_all_multi(objects, objects_len); break; case SEL_DESELECT: - BKE_mball_deselect_all(mb); + BKE_mball_deselect_all_multi(objects, objects_len); break; case SEL_INVERT: - BKE_mball_select_swap(mb); + BKE_mball_select_swap_multi(objects, objects_len); break; } - DEG_id_tag_update(&mb->id, DEG_TAG_SELECT_UPDATE); - WM_event_add_notifier(C, NC_GEOM | ND_SELECT, mb); + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + MetaBall *mb = (MetaBall *)obedit->data; + DEG_id_tag_update(&mb->id, DEG_TAG_SELECT_UPDATE); + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, mb); + } + + MEM_freeN(objects); return OPERATOR_FINISHED; } |