code cleanup: move get_selected_defgroups into object_deform.c and make it behave...
[blender.git] / source / blender / blenkernel / intern / object_deform.c
index 911f50874126650dc7f300150e20b98196ab08c1..7f9578250f2e500e9bc73c54b1912068f33a6c83 100644 (file)
  */
 
 #include <stdlib.h>
+#include <string.h>
 
 #include "MEM_guardedalloc.h"
 
 #include "BLI_utildefines.h"
 #include "BLI_ghash.h"
 
+#include "BKE_action.h"
 #include "BKE_object_deform.h"  /* own include */
+#include "BKE_object.h"
 #include "BKE_modifier.h"
 
 #include "DNA_armature_types.h"
@@ -121,3 +124,33 @@ char *BKE_objdef_validmap_get(Object *ob, const int defbase_tot)
 
        return vgroup_validmap;
 }
+
+/* Returns total selected vgroups,
+ * wpi.defbase_sel is assumed malloc'd, all values are set */
+char *BKE_objdef_selected_get(Object *ob, int defbase_tot, int *r_dg_flags_sel_tot)
+{
+       char *dg_selection = MEM_mallocN(defbase_tot * sizeof(char), __func__);
+       bDeformGroup *defgroup;
+       unsigned int i;
+       Object *armob = BKE_object_pose_armature_get(ob);
+       (*r_dg_flags_sel_tot) = 0;
+
+       if (armob) {
+               bPose *pose = armob->pose;
+               for (i = 0, defgroup = ob->defbase.first; i < defbase_tot && defgroup; defgroup = defgroup->next, i++) {
+                       bPoseChannel *pchan = BKE_pose_channel_find_name(pose, defgroup->name);
+                       if (pchan && (pchan->bone->flag & BONE_SELECTED)) {
+                               dg_selection[i] = TRUE;
+                               (*r_dg_flags_sel_tot) += 1;
+                       }
+                       else {
+                               dg_selection[i] = FALSE;
+                       }
+               }
+       }
+       else {
+               memset(dg_selection, FALSE, sizeof(char) * defbase_tot);
+       }
+
+       return dg_selection;
+}