Changeset View
Changeset View
Standalone View
Standalone View
source/blender/makesrna/intern/rna_pose.c
| Show First 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | static char *rna_PoseBone_path(PointerRNA *ptr) | ||||
| char name_esc[sizeof(pchan->name) * 2]; | char name_esc[sizeof(pchan->name) * 2]; | ||||
| BLI_str_escape(name_esc, pchan->name, sizeof(name_esc)); | BLI_str_escape(name_esc, pchan->name, sizeof(name_esc)); | ||||
| return BLI_sprintfN("pose.bones[\"%s\"]", name_esc); | return BLI_sprintfN("pose.bones[\"%s\"]", name_esc); | ||||
| } | } | ||||
| /* Bone groups only. */ | /* Bone groups only. */ | ||||
| static bActionGroup *rna_bone_group_new(ID *id, bPose *pose, const char *name) | static bool rna_bone_group_poll(Object *ob, ReportList *reports) | ||||
| { | { | ||||
| if ((ob->proxy != NULL) || (ob->proxy_group != NULL) || ID_IS_OVERRIDE_LIBRARY(ob)) { | |||||
| BKE_report(reports, RPT_ERROR, "Cannot edit bonegroups for proxies or library overrides"); | |||||
mont29: No need to check for NULL `reports` I think? Iirc `BKE_report` API deals properly with them… | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | |||||
| static bActionGroup *rna_bone_group_new(ID *id, bPose *pose, ReportList *reports, const char *name) | |||||
| { | |||||
| if (!rna_bone_group_poll((Object *)id, reports)) { | |||||
| return NULL; | |||||
| } | |||||
| bActionGroup *grp = BKE_pose_add_group(pose, name); | bActionGroup *grp = BKE_pose_add_group(pose, name); | ||||
| WM_main_add_notifier(NC_OBJECT | ND_POSE | NA_ADDED, id); | WM_main_add_notifier(NC_OBJECT | ND_POSE | NA_ADDED, id); | ||||
| return grp; | return grp; | ||||
| } | } | ||||
| static void rna_bone_group_remove(ID *id, bPose *pose, ReportList *reports, PointerRNA *grp_ptr) | static void rna_bone_group_remove(ID *id, bPose *pose, ReportList *reports, PointerRNA *grp_ptr) | ||||
| { | { | ||||
| if (!rna_bone_group_poll((Object *)id, reports)) { | |||||
| return; | |||||
| } | |||||
| bActionGroup *grp = grp_ptr->data; | bActionGroup *grp = grp_ptr->data; | ||||
| const int grp_idx = BLI_findindex(&pose->agroups, grp); | const int grp_idx = BLI_findindex(&pose->agroups, grp); | ||||
| if (grp_idx == -1) { | if (grp_idx == -1) { | ||||
| BKE_reportf(reports, RPT_ERROR, "Bone group '%s' not found in this object", grp->name); | BKE_reportf(reports, RPT_ERROR, "Bone group '%s' not found in this object", grp->name); | ||||
| return; | return; | ||||
| } | } | ||||
| BKE_pose_remove_group(pose, grp, grp_idx + 1); | BKE_pose_remove_group(pose, grp, grp_idx + 1); | ||||
| WM_main_add_notifier(NC_OBJECT | ND_POSE | NA_REMOVED, id); | WM_main_add_notifier(NC_OBJECT | ND_POSE | NA_REMOVED, id); | ||||
| } | } | ||||
| /* shared for actions groups and bone groups */ | /* shared for actions groups and bone groups */ | ||||
| void rna_ActionGroup_colorset_set(PointerRNA *ptr, int value) | void rna_ActionGroup_colorset_set(PointerRNA *ptr, int value) | ||||
| { | { | ||||
| Object *ob = (Object *)ptr->owner_id; | |||||
| if (!rna_bone_group_poll(ob, NULL)) { | |||||
| return; | |||||
| } | |||||
| bActionGroup *grp = ptr->data; | bActionGroup *grp = ptr->data; | ||||
| /* ensure only valid values get set */ | /* ensure only valid values get set */ | ||||
| if ((value >= -1) && (value < 21)) { | if ((value >= -1) && (value < 21)) { | ||||
| grp->customCol = value; | grp->customCol = value; | ||||
| /* sync colors stored with theme colors based on the index specified */ | /* sync colors stored with theme colors based on the index specified */ | ||||
| action_group_colors_sync(grp, NULL); | action_group_colors_sync(grp, NULL); | ||||
| } | } | ||||
| } | } | ||||
| bool rna_ActionGroup_is_custom_colorset_get(PointerRNA *ptr) | bool rna_ActionGroup_is_custom_colorset_get(PointerRNA *ptr) | ||||
| { | { | ||||
| bActionGroup *grp = ptr->data; | bActionGroup *grp = ptr->data; | ||||
| return (grp->customCol < 0); | return (grp->customCol < 0); | ||||
| } | } | ||||
| static void rna_BoneGroup_name_set(PointerRNA *ptr, const char *value) | static void rna_BoneGroup_name_set(PointerRNA *ptr, const char *value) | ||||
| { | { | ||||
| Object *ob = (Object *)ptr->owner_id; | Object *ob = (Object *)ptr->owner_id; | ||||
| if (!rna_bone_group_poll(ob, NULL)) { | |||||
| return; | |||||
| } | |||||
| bActionGroup *agrp = ptr->data; | bActionGroup *agrp = ptr->data; | ||||
| /* copy the new name into the name slot */ | /* copy the new name into the name slot */ | ||||
| BLI_strncpy_utf8(agrp->name, value, sizeof(agrp->name)); | BLI_strncpy_utf8(agrp->name, value, sizeof(agrp->name)); | ||||
| BLI_uniquename(&ob->pose->agroups, | BLI_uniquename(&ob->pose->agroups, | ||||
| agrp, | agrp, | ||||
| CTX_DATA_(BLT_I18NCONTEXT_ID_ARMATURE, "Group"), | CTX_DATA_(BLT_I18NCONTEXT_ID_ARMATURE, "Group"), | ||||
| ▲ Show 20 Lines • Show All 1,419 Lines • ▼ Show 20 Lines | static void rna_def_bone_groups(BlenderRNA *brna, PropertyRNA *cprop) | ||||
| RNA_def_property_srna(cprop, "BoneGroups"); | RNA_def_property_srna(cprop, "BoneGroups"); | ||||
| srna = RNA_def_struct(brna, "BoneGroups", NULL); | srna = RNA_def_struct(brna, "BoneGroups", NULL); | ||||
| RNA_def_struct_sdna(srna, "bPose"); | RNA_def_struct_sdna(srna, "bPose"); | ||||
| RNA_def_struct_ui_text(srna, "Bone Groups", "Collection of bone groups"); | RNA_def_struct_ui_text(srna, "Bone Groups", "Collection of bone groups"); | ||||
| func = RNA_def_function(srna, "new", "rna_bone_group_new"); | func = RNA_def_function(srna, "new", "rna_bone_group_new"); | ||||
| RNA_def_function_ui_description(func, "Add a new bone group to the object"); | RNA_def_function_ui_description(func, "Add a new bone group to the object"); | ||||
| RNA_def_function_flag(func, FUNC_USE_SELF_ID); /* ID needed for refresh */ | RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_REPORTS); /* ID needed for refresh */ | ||||
| RNA_def_string(func, "name", "Group", MAX_NAME, "", "Name of the new group"); | RNA_def_string(func, "name", "Group", MAX_NAME, "", "Name of the new group"); | ||||
| /* return type */ | /* return type */ | ||||
| parm = RNA_def_pointer(func, "group", "BoneGroup", "", "New bone group"); | parm = RNA_def_pointer(func, "group", "BoneGroup", "", "New bone group"); | ||||
| RNA_def_function_return(func, parm); | RNA_def_function_return(func, parm); | ||||
| func = RNA_def_function(srna, "remove", "rna_bone_group_remove"); | func = RNA_def_function(srna, "remove", "rna_bone_group_remove"); | ||||
| RNA_def_function_ui_description(func, "Remove a bone group from this object"); | RNA_def_function_ui_description(func, "Remove a bone group from this object"); | ||||
| RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID); /* ID needed for refresh */ | RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID); /* ID needed for refresh */ | ||||
| ▲ Show 20 Lines • Show All 113 Lines • Show Last 20 Lines | |||||
No need to check for NULL reports I think? Iirc BKE_report API deals properly with them, and just prints to console then.