Changeset View
Changeset View
Standalone View
Standalone View
source/blender/makesrna/intern/rna_access.c
| Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_animsys.h" | #include "BKE_animsys.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_idcode.h" | #include "BKE_idcode.h" | ||||
| #include "BKE_idprop.h" | #include "BKE_idprop.h" | ||||
| #include "BKE_fcurve.h" | #include "BKE_fcurve.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "BKE_node.h" | |||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| #include "RNA_enum_types.h" | #include "RNA_enum_types.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| ▲ Show 20 Lines • Show All 5,690 Lines • ▼ Show 20 Lines | if (haystack) { /* can fail when called on bones */ | ||||
| needle = ptr->data; | needle = ptr->data; | ||||
| return rna_idp_path(&id_ptr, haystack, needle, NULL); | return rna_idp_path(&id_ptr, haystack, needle, NULL); | ||||
| } | } | ||||
| else { | else { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * @brief Find the actual ID pointer and path from it to the given ID. | |||||
| * @param id: ID reference to search the global owner for. | |||||
| * @param[out] r_path: Path from the real ID to the initial ID. | |||||
| * @return The ID pointer, or NULL in case of failure. | |||||
mont29: Please use same syntax as everywhere in blender : `\param id blah...`
And `\brief` is useless… | |||||
| */ | |||||
| ID *RNA_find_real_ID_and_path(Main *bmain, ID *id, const char **r_path) | |||||
| { | |||||
| if (r_path) { | |||||
| *r_path = ""; | |||||
| } | |||||
| if ((id != NULL) && (id->flag & LIB_PRIVATE_DATA)) { | |||||
| switch (GS(id->name)) { | |||||
| case ID_NT: | |||||
| if (r_path) { | |||||
| *r_path = "node_tree"; | |||||
| } | |||||
| return BKE_node_tree_find_owner_ID(bmain, (bNodeTree *)id); | |||||
| default: | |||||
| return NULL; | |||||
| } | |||||
| } | |||||
| else { | |||||
| return id; | |||||
| } | |||||
| } | |||||
| static char *rna_prepend_real_ID_path(Main *bmain, ID *id, char *path, ID **r_real) | |||||
| { | |||||
| if (path) { | |||||
| const char *prefix; | |||||
| char *new_path = NULL; | |||||
| *r_real = RNA_find_real_ID_and_path(bmain, id, &prefix); | |||||
| if (*r_real) { | |||||
| if (prefix[0]) { | |||||
| new_path = BLI_sprintfN("%s%s%s", prefix, path[0] == '[' ? "" : ".", path); | |||||
| } | |||||
| else { | |||||
| return path; | |||||
| } | |||||
| } | |||||
| MEM_freeN(path); | |||||
| return new_path; | |||||
| } | |||||
| else { | |||||
| return NULL; | |||||
| } | |||||
| } | |||||
| char *RNA_path_from_ID_to_struct(PointerRNA *ptr) | char *RNA_path_from_ID_to_struct(PointerRNA *ptr) | ||||
| { | { | ||||
| char *ptrpath = NULL; | char *ptrpath = NULL; | ||||
| if (!ptr->id.data || !ptr->data) { | if (!ptr->id.data || !ptr->data) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| Show All 26 Lines | if (!RNA_struct_is_ID(ptr->type)) { | ||||
| else { | else { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| } | } | ||||
| return ptrpath; | return ptrpath; | ||||
| } | } | ||||
| char *RNA_path_from_real_ID_to_struct(Main *bmain, PointerRNA *ptr, struct ID **r_real) | |||||
| { | |||||
| char *path = RNA_path_from_ID_to_struct(ptr); | |||||
| return rna_prepend_real_ID_path(bmain, ptr->id.data, path, r_real); | |||||
| } | |||||
| static void rna_path_array_multi_from_flat_index(const int dimsize[RNA_MAX_ARRAY_LENGTH], | static void rna_path_array_multi_from_flat_index(const int dimsize[RNA_MAX_ARRAY_LENGTH], | ||||
| const int totdims, | const int totdims, | ||||
| const int index_dim, | const int index_dim, | ||||
| int index, | int index, | ||||
| int r_index_multi[RNA_MAX_ARRAY_LENGTH]) | int r_index_multi[RNA_MAX_ARRAY_LENGTH]) | ||||
| { | { | ||||
| int dimsize_step[RNA_MAX_ARRAY_LENGTH + 1]; | int dimsize_step[RNA_MAX_ARRAY_LENGTH + 1]; | ||||
| int i = totdims - 1; | int i = totdims - 1; | ||||
| ▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | char *RNA_path_from_ID_to_property_index(PointerRNA *ptr, | ||||
| return path; | return path; | ||||
| } | } | ||||
| char *RNA_path_from_ID_to_property(PointerRNA *ptr, PropertyRNA *prop) | char *RNA_path_from_ID_to_property(PointerRNA *ptr, PropertyRNA *prop) | ||||
| { | { | ||||
| return RNA_path_from_ID_to_property_index(ptr, prop, 0, -1); | return RNA_path_from_ID_to_property_index(ptr, prop, 0, -1); | ||||
| } | } | ||||
| char *RNA_path_from_real_ID_to_property_index( | |||||
| Main *bmain, PointerRNA *ptr, PropertyRNA *prop, int index_dim, int index, ID **r_real) | |||||
| { | |||||
| char *path = RNA_path_from_ID_to_property_index(ptr, prop, index_dim, index); | |||||
| return rna_prepend_real_ID_path(bmain, ptr->id.data, path, r_real); | |||||
| } | |||||
| /** | /** | ||||
| * \return the path to given ptr/prop from the closest ancestor of given type, | * \return the path to given ptr/prop from the closest ancestor of given type, | ||||
| * if any (else return NULL). | * if any (else return NULL). | ||||
| */ | */ | ||||
| char *RNA_path_resolve_from_type_to_property(PointerRNA *ptr, | char *RNA_path_resolve_from_type_to_property(PointerRNA *ptr, | ||||
| PropertyRNA *prop, | PropertyRNA *prop, | ||||
| const StructRNA *type) | const StructRNA *type) | ||||
| { | { | ||||
| Show All 30 Lines | char *RNA_path_resolve_from_type_to_property(PointerRNA *ptr, | ||||
| MEM_freeN(full_path); | MEM_freeN(full_path); | ||||
| return path; | return path; | ||||
| } | } | ||||
| /** | /** | ||||
| * Get the ID as a python representation, eg: | * Get the ID as a python representation, eg: | ||||
| * bpy.data.foo["bar"] | * bpy.data.foo["bar"] | ||||
| */ | */ | ||||
| char *RNA_path_full_ID_py(ID *id) | char *RNA_path_full_ID_py(Main *bmain, ID *id) | ||||
| { | { | ||||
| const char *path; | |||||
| ID *id_real = RNA_find_real_ID_and_path(bmain, id, &path); | |||||
| if (id_real) { | |||||
| id = id_real; | |||||
| } | |||||
| else { | |||||
| path = ""; | |||||
| } | |||||
| char id_esc[(sizeof(id->name) - 2) * 2]; | char id_esc[(sizeof(id->name) - 2) * 2]; | ||||
| BLI_strescape(id_esc, id->name + 2, sizeof(id_esc)); | BLI_strescape(id_esc, id->name + 2, sizeof(id_esc)); | ||||
| return BLI_sprintfN("bpy.data.%s[\"%s\"]", BKE_idcode_to_name_plural(GS(id->name)), id_esc); | return BLI_sprintfN("bpy.data.%s[\"%s\"]%s%s", | ||||
| BKE_idcode_to_name_plural(GS(id->name)), | |||||
| id_esc, | |||||
| path[0] ? "." : "", | |||||
| path); | |||||
| } | } | ||||
| /** | /** | ||||
| * Get the ID.struct as a python representation, eg: | * Get the ID.struct as a python representation, eg: | ||||
| * bpy.data.foo["bar"].some_struct | * bpy.data.foo["bar"].some_struct | ||||
| */ | */ | ||||
| char *RNA_path_full_struct_py(struct PointerRNA *ptr) | char *RNA_path_full_struct_py(Main *bmain, struct PointerRNA *ptr) | ||||
| { | { | ||||
| char *id_path; | char *id_path; | ||||
| char *data_path; | char *data_path; | ||||
| char *ret; | char *ret; | ||||
| if (!ptr->id.data) { | if (!ptr->id.data) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* never fails */ | /* never fails */ | ||||
| id_path = RNA_path_full_ID_py(ptr->id.data); | id_path = RNA_path_full_ID_py(bmain, ptr->id.data); | ||||
| data_path = RNA_path_from_ID_to_struct(ptr); | data_path = RNA_path_from_ID_to_struct(ptr); | ||||
| /* XXX data_path may be NULL (see T36788), | /* XXX data_path may be NULL (see T36788), | ||||
| * do we want to get the 'bpy.data.foo["bar"].(null)' stuff? */ | * do we want to get the 'bpy.data.foo["bar"].(null)' stuff? */ | ||||
| ret = BLI_sprintfN("%s.%s", id_path, data_path); | ret = BLI_sprintfN("%s.%s", id_path, data_path); | ||||
| if (data_path) { | if (data_path) { | ||||
| MEM_freeN(data_path); | MEM_freeN(data_path); | ||||
| } | } | ||||
| MEM_freeN(id_path); | MEM_freeN(id_path); | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| /** | /** | ||||
| * Get the ID.struct.property as a python representation, eg: | * Get the ID.struct.property as a python representation, eg: | ||||
| * bpy.data.foo["bar"].some_struct.some_prop[10] | * bpy.data.foo["bar"].some_struct.some_prop[10] | ||||
| */ | */ | ||||
| char *RNA_path_full_property_py_ex(PointerRNA *ptr, | char *RNA_path_full_property_py_ex( | ||||
| PropertyRNA *prop, | Main *bmain, PointerRNA *ptr, PropertyRNA *prop, int index, bool use_fallback) | ||||
| int index, | |||||
| bool use_fallback) | |||||
| { | { | ||||
| char *id_path; | char *id_path; | ||||
| const char *data_delim; | const char *data_delim; | ||||
| const char *data_path; | const char *data_path; | ||||
| bool data_path_free; | bool data_path_free; | ||||
| char *ret; | char *ret; | ||||
| if (!ptr->id.data) { | if (!ptr->id.data) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* never fails */ | /* never fails */ | ||||
| id_path = RNA_path_full_ID_py(ptr->id.data); | id_path = RNA_path_full_ID_py(bmain, ptr->id.data); | ||||
| data_path = RNA_path_from_ID_to_property(ptr, prop); | data_path = RNA_path_from_ID_to_property(ptr, prop); | ||||
| if (data_path) { | if (data_path) { | ||||
| data_delim = (data_path[0] == '[') ? "" : "."; | data_delim = (data_path[0] == '[') ? "" : "."; | ||||
| data_path_free = true; | data_path_free = true; | ||||
| } | } | ||||
| else { | else { | ||||
| if (use_fallback) { | if (use_fallback) { | ||||
| Show All 16 Lines | char *RNA_path_full_property_py_ex( | ||||
| MEM_freeN(id_path); | MEM_freeN(id_path); | ||||
| if (data_path_free) { | if (data_path_free) { | ||||
| MEM_freeN((void *)data_path); | MEM_freeN((void *)data_path); | ||||
| } | } | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| char *RNA_path_full_property_py(PointerRNA *ptr, PropertyRNA *prop, int index) | char *RNA_path_full_property_py(Main *bmain, PointerRNA *ptr, PropertyRNA *prop, int index) | ||||
| { | { | ||||
| return RNA_path_full_property_py_ex(ptr, prop, index, false); | return RNA_path_full_property_py_ex(bmain, ptr, prop, index, false); | ||||
| } | } | ||||
| /** | /** | ||||
| * Get the struct.property as a python representation, eg: | * Get the struct.property as a python representation, eg: | ||||
| * some_struct.some_prop[10] | * some_struct.some_prop[10] | ||||
| */ | */ | ||||
| char *RNA_path_struct_property_py(PointerRNA *ptr, PropertyRNA *prop, int index) | char *RNA_path_struct_property_py(PointerRNA *ptr, PropertyRNA *prop, int index) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 581 Lines • ▼ Show 20 Lines | char *RNA_pointer_as_string_id(bContext *C, PointerRNA *ptr) | ||||
| BLI_dynstr_append(dynstr, "}"); | BLI_dynstr_append(dynstr, "}"); | ||||
| cstring = BLI_dynstr_get_cstring(dynstr); | cstring = BLI_dynstr_get_cstring(dynstr); | ||||
| BLI_dynstr_free(dynstr); | BLI_dynstr_free(dynstr); | ||||
| return cstring; | return cstring; | ||||
| } | } | ||||
| static char *rna_pointer_as_string__bldata(PointerRNA *ptr) | static char *rna_pointer_as_string__bldata(Main *bmain, PointerRNA *ptr) | ||||
| { | { | ||||
| if (ptr->type == NULL || ptr->id.data == NULL) { | if (ptr->type == NULL || ptr->id.data == NULL) { | ||||
| return BLI_strdup("None"); | return BLI_strdup("None"); | ||||
| } | } | ||||
| else if (RNA_struct_is_ID(ptr->type)) { | else if (RNA_struct_is_ID(ptr->type)) { | ||||
| return RNA_path_full_ID_py(ptr->id.data); | return RNA_path_full_ID_py(bmain, ptr->id.data); | ||||
| } | } | ||||
| else { | else { | ||||
| return RNA_path_full_struct_py(ptr); | return RNA_path_full_struct_py(bmain, ptr); | ||||
| } | } | ||||
| } | } | ||||
| char *RNA_pointer_as_string(bContext *C, | char *RNA_pointer_as_string(bContext *C, | ||||
| PointerRNA *ptr, | PointerRNA *ptr, | ||||
| PropertyRNA *prop_ptr, | PropertyRNA *prop_ptr, | ||||
| PointerRNA *ptr_prop) | PointerRNA *ptr_prop) | ||||
| { | { | ||||
| IDProperty *prop; | IDProperty *prop; | ||||
| if (ptr_prop->data == NULL) { | if (ptr_prop->data == NULL) { | ||||
| return BLI_strdup("None"); | return BLI_strdup("None"); | ||||
| } | } | ||||
| else if ((prop = rna_idproperty_check(&prop_ptr, ptr)) && prop->type != IDP_ID) { | else if ((prop = rna_idproperty_check(&prop_ptr, ptr)) && prop->type != IDP_ID) { | ||||
| return RNA_pointer_as_string_id(C, ptr_prop); | return RNA_pointer_as_string_id(C, ptr_prop); | ||||
| } | } | ||||
| else { | else { | ||||
| return rna_pointer_as_string__bldata(ptr_prop); | return rna_pointer_as_string__bldata(CTX_data_main(C), ptr_prop); | ||||
| } | } | ||||
| } | } | ||||
| /* context can be NULL */ | /* context can be NULL */ | ||||
| char *RNA_pointer_as_string_keywords_ex(bContext *C, | char *RNA_pointer_as_string_keywords_ex(bContext *C, | ||||
| PointerRNA *ptr, | PointerRNA *ptr, | ||||
| const bool as_function, | const bool as_function, | ||||
| const bool all_args, | const bool all_args, | ||||
| ▲ Show 20 Lines • Show All 1,417 Lines • Show Last 20 Lines | |||||
Please use same syntax as everywhere in blender : \param id blah...
And \brief is useless and redundant, just type in description, doxy will take first block as brief one.