diff options
Diffstat (limited to 'source/blender/editors/space_outliner/outliner_edit.cc')
-rw-r--r-- | source/blender/editors/space_outliner/outliner_edit.cc | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/source/blender/editors/space_outliner/outliner_edit.cc b/source/blender/editors/space_outliner/outliner_edit.cc index a10dbc94b34..b41b260b14a 100644 --- a/source/blender/editors/space_outliner/outliner_edit.cc +++ b/source/blender/editors/space_outliner/outliner_edit.cc @@ -74,6 +74,9 @@ #include "GPU_material.h" #include "outliner_intern.hh" +#include "tree/tree_element_rna.hh" + +using namespace blender::ed::outliner; static void outliner_show_active(SpaceOutliner *space_outliner, ARegion *region, @@ -1714,11 +1717,6 @@ static void tree_element_to_path(TreeElement *te, short *UNUSED(groupmode)) { ListBase hierarchy = {nullptr, nullptr}; - LinkData *ld; - TreeElement *tem, *temnext; - TreeStoreElem *tse /* , *tsenext */ /* UNUSED */; - PointerRNA *ptr, *nextptr; - PropertyRNA *prop; char *newpath = nullptr; /* optimize tricks: @@ -1738,20 +1736,19 @@ static void tree_element_to_path(TreeElement *te, */ /* step 1: flatten out hierarchy of parents into a flat chain */ - for (tem = te->parent; tem; tem = tem->parent) { - ld = MEM_cnew<LinkData>("LinkData for tree_element_to_path()"); + for (TreeElement *tem = te->parent; tem; tem = tem->parent) { + LinkData *ld = MEM_cnew<LinkData>("LinkData for tree_element_to_path()"); ld->data = tem; BLI_addhead(&hierarchy, ld); } /* step 2: step down hierarchy building the path * (NOTE: addhead in previous loop was needed so that we can loop like this) */ - for (ld = reinterpret_cast<LinkData *>(hierarchy.first); ld; ld = ld->next) { + LISTBASE_FOREACH (LinkData *, ld, &hierarchy) { /* get data */ - tem = (TreeElement *)ld->data; - tse = TREESTORE(tem); - ptr = &tem->rnaptr; - prop = reinterpret_cast<PropertyRNA *>(tem->directdata); + TreeElement *tem = (TreeElement *)ld->data; + TreeElementRNACommon *tem_rna = tree_element_cast<TreeElementRNACommon>(tem); + PointerRNA ptr = tem_rna->getPointerRNA(); /* check if we're looking for first ID, or appending to path */ if (*id) { @@ -1759,19 +1756,19 @@ static void tree_element_to_path(TreeElement *te, * - to prevent memory leaks, we must write to newpath not path, * then free old path + swap them. */ - if (tse->type == TSE_RNA_PROPERTY) { + if (TreeElementRNAProperty *tem_rna_prop = tree_element_cast<TreeElementRNAProperty>(tem)) { + PropertyRNA *prop = tem_rna_prop->getPropertyRNA(); + if (RNA_property_type(prop) == PROP_POINTER) { /* for pointer we just append property name */ - newpath = RNA_path_append(*path, ptr, prop, 0, nullptr); + newpath = RNA_path_append(*path, &ptr, prop, 0, nullptr); } else if (RNA_property_type(prop) == PROP_COLLECTION) { char buf[128], *name; - temnext = (TreeElement *)(ld->next->data); - // tsenext = TREESTORE(temnext); /* UNUSED */ - - nextptr = &temnext->rnaptr; - name = RNA_struct_name_get_alloc(nextptr, buf, sizeof(buf), nullptr); + TreeElement *temnext = (TreeElement *)(ld->next->data); + PointerRNA nextptr = tree_element_cast<TreeElementRNACommon>(temnext)->getPointerRNA(); + name = RNA_struct_name_get_alloc(&nextptr, buf, sizeof(buf), nullptr); if (name) { /* if possible, use name as a key in the path */ @@ -1789,6 +1786,7 @@ static void tree_element_to_path(TreeElement *te, if (temsub == temnext) { break; } + index++; } newpath = RNA_path_append(*path, nullptr, prop, index, nullptr); } @@ -1808,11 +1806,11 @@ static void tree_element_to_path(TreeElement *te, else { /* no ID, so check if entry is RNA-struct, * and if that RNA-struct is an ID datablock to extract info from. */ - if (tse->type == TSE_RNA_STRUCT) { + if (tree_element_cast<TreeElementRNAStruct>(tem)) { /* ptr->data not ptr->owner_id seems to be the one we want, * since ptr->data is sometimes the owner of this ID? */ - if (RNA_struct_is_ID(ptr->type)) { - *id = reinterpret_cast<ID *>(ptr->data); + if (RNA_struct_is_ID(ptr.type)) { + *id = reinterpret_cast<ID *>(ptr.data); /* clear path */ if (*path) { @@ -1827,8 +1825,7 @@ static void tree_element_to_path(TreeElement *te, /* step 3: if we've got an ID, add the current item to the path */ if (*id) { /* add the active property to the path */ - ptr = &te->rnaptr; - prop = reinterpret_cast<PropertyRNA *>(te->directdata); + PropertyRNA *prop = tree_element_cast<TreeElementRNACommon>(te)->getPropertyRNA(); /* array checks */ if (tselem->type == TSE_RNA_ARRAY_ELEM) { @@ -1886,9 +1883,12 @@ static void do_outliner_drivers_editop(SpaceOutliner *space_outliner, short flag = 0; short groupmode = KSP_GROUP_KSNAME; + TreeElementRNACommon *te_rna = tree_element_cast<TreeElementRNACommon>(te); + PointerRNA ptr = te_rna ? te_rna->getPointerRNA() : PointerRNA_NULL; + PropertyRNA *prop = te_rna ? te_rna->getPropertyRNA() : nullptr; + /* check if RNA-property described by this selected element is an animatable prop */ - if (ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM) && - RNA_property_animateable(&te->rnaptr, reinterpret_cast<PropertyRNA *>(te->directdata))) { + if (prop && RNA_property_animateable(&ptr, prop)) { /* get id + path + index info from the selected element */ tree_element_to_path(te, tselem, &id, &path, &array_index, &flag, &groupmode); } @@ -1901,8 +1901,7 @@ static void do_outliner_drivers_editop(SpaceOutliner *space_outliner, /* array checks */ if (flag & KSP_FLAG_WHOLE_ARRAY) { /* entire array was selected, so add drivers for all */ - arraylen = RNA_property_array_length(&te->rnaptr, - reinterpret_cast<PropertyRNA *>(te->directdata)); + arraylen = RNA_property_array_length(&ptr, prop); } else { arraylen = array_index; @@ -2084,8 +2083,10 @@ static void do_outliner_keyingset_editop(SpaceOutliner *space_outliner, short groupmode = KSP_GROUP_KSNAME; /* check if RNA-property described by this selected element is an animatable prop */ - if (ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM) && - RNA_property_animateable(&te->rnaptr, reinterpret_cast<PropertyRNA *>(te->directdata))) { + const TreeElementRNACommon *te_rna = tree_element_cast<TreeElementRNACommon>(te); + PointerRNA ptr = te_rna->getPointerRNA(); + if (te_rna && te_rna->getPropertyRNA() && + RNA_property_animateable(&ptr, te_rna->getPropertyRNA())) { /* get id + path + index info from the selected element */ tree_element_to_path(te, tselem, &id, &path, &array_index, &flag, &groupmode); } |