Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kim <pk15950@gmail.com>2022-09-08 07:00:12 +0300
committerPeter Kim <pk15950@gmail.com>2022-09-08 07:00:12 +0300
commit00dcfdf916c69672210b006e62d966f1bc2fbeb7 (patch)
tree0cbb1b91fe26c750197126085b74224a795a103c /source/blender/editors/space_outliner/tree
parenta39532670f6b668da7be5810fb1f844b82feeba3 (diff)
parentd5934974219135102f364f57c45a8b1465e2b8d9 (diff)
Merge branch 'master' into xr-devxr-dev
Diffstat (limited to 'source/blender/editors/space_outliner/tree')
-rw-r--r--source/blender/editors/space_outliner/tree/common.cc6
-rw-r--r--source/blender/editors/space_outliner/tree/common.hh4
-rw-r--r--source/blender/editors/space_outliner/tree/tree_display.cc5
-rw-r--r--source/blender/editors/space_outliner/tree/tree_display.hh16
-rw-r--r--source/blender/editors/space_outliner/tree/tree_display_data.cc5
-rw-r--r--source/blender/editors/space_outliner/tree/tree_display_override_library_hierarchies.cc297
-rw-r--r--source/blender/editors/space_outliner/tree/tree_element.cc43
-rw-r--r--source/blender/editors/space_outliner/tree/tree_element.hh24
-rw-r--r--source/blender/editors/space_outliner/tree/tree_element_anim_data.hh2
-rw-r--r--source/blender/editors/space_outliner/tree/tree_element_driver.hh2
-rw-r--r--source/blender/editors/space_outliner/tree/tree_element_label.cc36
-rw-r--r--source/blender/editors/space_outliner/tree/tree_element_label.hh36
-rw-r--r--source/blender/editors/space_outliner/tree/tree_element_overrides.cc397
-rw-r--r--source/blender/editors/space_outliner/tree/tree_element_overrides.hh40
-rw-r--r--source/blender/editors/space_outliner/tree/tree_element_rna.cc15
-rw-r--r--source/blender/editors/space_outliner/tree/tree_iterator.hh4
16 files changed, 798 insertions, 134 deletions
diff --git a/source/blender/editors/space_outliner/tree/common.cc b/source/blender/editors/space_outliner/tree/common.cc
index 349d36e2fe6..199c80f021a 100644
--- a/source/blender/editors/space_outliner/tree/common.cc
+++ b/source/blender/editors/space_outliner/tree/common.cc
@@ -21,6 +21,8 @@
#include "common.hh"
#include "tree_display.hh"
+namespace blender::ed::outliner {
+
/* -------------------------------------------------------------------- */
/** \name ID Helpers.
* \{ */
@@ -38,7 +40,7 @@ void outliner_make_object_parent_hierarchy(ListBase *lb)
{
/* build hierarchy */
/* XXX also, set extents here... */
- TreeElement *te = reinterpret_cast<TreeElement *>(lb->first);
+ TreeElement *te = static_cast<TreeElement *>(lb->first);
while (te) {
TreeElement *ten = te->next;
TreeStoreElem *tselem = TREESTORE(te);
@@ -63,3 +65,5 @@ bool outliner_animdata_test(const AnimData *adt)
}
return false;
}
+
+} // namespace blender::ed::outliner
diff --git a/source/blender/editors/space_outliner/tree/common.hh b/source/blender/editors/space_outliner/tree/common.hh
index 96c1eb34354..ba2d1c3fab6 100644
--- a/source/blender/editors/space_outliner/tree/common.hh
+++ b/source/blender/editors/space_outliner/tree/common.hh
@@ -8,7 +8,11 @@
struct ListBase;
+namespace blender::ed::outliner {
+
const char *outliner_idcode_to_plural(short idcode);
void outliner_make_object_parent_hierarchy(ListBase *lb);
bool outliner_animdata_test(const struct AnimData *adt);
+
+} // namespace blender::ed::outliner
diff --git a/source/blender/editors/space_outliner/tree/tree_display.cc b/source/blender/editors/space_outliner/tree/tree_display.cc
index 6ab497b3fbb..fe4937829d6 100644
--- a/source/blender/editors/space_outliner/tree/tree_display.cc
+++ b/source/blender/editors/space_outliner/tree/tree_display.cc
@@ -50,4 +50,9 @@ bool AbstractTreeDisplay::supportsModeColumn() const
return false;
}
+bool AbstractTreeDisplay::is_lazy_built() const
+{
+ return false;
+}
+
} // namespace blender::ed::outliner
diff --git a/source/blender/editors/space_outliner/tree/tree_display.hh b/source/blender/editors/space_outliner/tree/tree_display.hh
index 190e35c81d6..295eeb59eaa 100644
--- a/source/blender/editors/space_outliner/tree/tree_display.hh
+++ b/source/blender/editors/space_outliner/tree/tree_display.hh
@@ -30,11 +30,11 @@ struct Main;
struct Scene;
struct Sequence;
struct SpaceOutliner;
-struct TreeElement;
struct ViewLayer;
namespace blender::ed::outliner {
+struct TreeElement;
class TreeElementID;
/**
@@ -84,6 +84,15 @@ class AbstractTreeDisplay {
*/
virtual bool supportsModeColumn() const;
+ /**
+ * Some trees may want to skip building children of collapsed parents. This should be done if the
+ * tree type may become very complex, which could cause noticeable slowdowns.
+ * Problem: This doesn't address performance issues while searching, since all elements are
+ * constructed for that. Trees of this type have to be rebuilt for any change to the collapsed
+ * state of any element.
+ */
+ virtual bool is_lazy_built() const;
+
protected:
/** All derived classes will need a handle to this, so storing it in the base for convenience. */
SpaceOutliner &space_outliner_;
@@ -157,11 +166,12 @@ class TreeDisplayOverrideLibraryHierarchies final : public AbstractTreeDisplay {
ListBase buildTree(const TreeSourceData &source_data) override;
+ bool is_lazy_built() const override;
+
private:
ListBase build_hierarchy_for_lib_or_main(Main *bmain,
TreeElement &parent_te,
Library *lib = nullptr);
- void build_hierarchy_for_ID(Main *bmain, ID &override_root_id, TreeElementID &te_id) const;
};
/* -------------------------------------------------------------------- */
@@ -233,6 +243,8 @@ class TreeDisplayDataAPI final : public AbstractTreeDisplay {
TreeDisplayDataAPI(SpaceOutliner &space_outliner);
ListBase buildTree(const TreeSourceData &source_data) override;
+
+ bool is_lazy_built() const override;
};
} // namespace blender::ed::outliner
diff --git a/source/blender/editors/space_outliner/tree/tree_display_data.cc b/source/blender/editors/space_outliner/tree/tree_display_data.cc
index bfeb8ce2bdc..3d9b927fbf1 100644
--- a/source/blender/editors/space_outliner/tree/tree_display_data.cc
+++ b/source/blender/editors/space_outliner/tree/tree_display_data.cc
@@ -42,4 +42,9 @@ ListBase TreeDisplayDataAPI::buildTree(const TreeSourceData &source_data)
return tree;
}
+bool TreeDisplayDataAPI::is_lazy_built() const
+{
+ return true;
+}
+
} // namespace blender::ed::outliner
diff --git a/source/blender/editors/space_outliner/tree/tree_display_override_library_hierarchies.cc b/source/blender/editors/space_outliner/tree/tree_display_override_library_hierarchies.cc
index 67798e978ab..fa4479d0d9d 100644
--- a/source/blender/editors/space_outliner/tree/tree_display_override_library_hierarchies.cc
+++ b/source/blender/editors/space_outliner/tree/tree_display_override_library_hierarchies.cc
@@ -4,25 +4,24 @@
* \ingroup spoutliner
*/
-#include "DNA_ID.h"
-#include "DNA_collection_types.h"
#include "DNA_key_types.h"
#include "DNA_space_types.h"
-#include "BLI_listbase.h"
+#include "BLI_function_ref.hh"
+#include "BLI_ghash.h"
#include "BLI_map.hh"
+
#include "BLI_set.hh"
#include "BLT_translation.h"
-#include "BKE_collection.h"
+#include "BKE_lib_override.h"
#include "BKE_lib_query.h"
#include "BKE_main.h"
#include "../outliner_intern.hh"
#include "common.hh"
#include "tree_display.hh"
-#include "tree_element_id.hh"
namespace blender::ed::outliner {
@@ -42,8 +41,8 @@ ListBase TreeDisplayOverrideLibraryHierarchies::buildTree(const TreeSourceData &
TreeElement *current_file_te = outliner_add_element(
&space_outliner_, &tree, source_data.bmain, nullptr, TSE_ID_BASE, -1);
current_file_te->name = IFACE_("Current File");
+ AbstractTreeElement::uncollapse_by_default(current_file_te);
{
- AbstractTreeElement::uncollapse_by_default(current_file_te);
build_hierarchy_for_lib_or_main(source_data.bmain, *current_file_te);
/* Add dummy child if there's nothing to display. */
@@ -76,11 +75,57 @@ ListBase TreeDisplayOverrideLibraryHierarchies::buildTree(const TreeSourceData &
return tree;
}
+bool TreeDisplayOverrideLibraryHierarchies::is_lazy_built() const
+{
+ return true;
+}
+
+/* -------------------------------------------------------------------- */
+/** \name Library override hierarchy building
+ * \{ */
+
+class OverrideIDHierarchyBuilder {
+ SpaceOutliner &space_outliner_;
+ Main &bmain_;
+ MainIDRelations &id_relations_;
+
+ struct HierarchyBuildData {
+ const ID &override_root_id_;
+ /* The ancestor IDs leading to the current ID, to avoid IDs recursing into themselves. Changes
+ * with every level of recursion. */
+ Set<const ID *> parent_ids{};
+ /* The IDs that were already added to #parent_te, to avoid duplicates. Entirely new set with
+ * every level of recursion. */
+ Set<const ID *> sibling_ids{};
+ };
+
+ public:
+ OverrideIDHierarchyBuilder(SpaceOutliner &space_outliner,
+ Main &bmain,
+ MainIDRelations &id_relations)
+ : space_outliner_(space_outliner), bmain_(bmain), id_relations_(id_relations)
+ {
+ }
+
+ void build_hierarchy_for_ID(ID &root_id, TreeElement &te_to_expand);
+
+ private:
+ void build_hierarchy_for_ID_recursive(const ID &parent_id,
+ HierarchyBuildData &build_data,
+ TreeElement &te_to_expand);
+};
+
ListBase TreeDisplayOverrideLibraryHierarchies::build_hierarchy_for_lib_or_main(
Main *bmain, TreeElement &parent_te, Library *lib)
{
ListBase tree = {nullptr};
+ /* Ensure #Main.relations contains the latest mapping of relations. Must be freed before
+ * returning. */
+ BKE_main_relations_create(bmain, 0);
+
+ OverrideIDHierarchyBuilder builder(space_outliner_, *bmain, *bmain->relations);
+
/* Keep track over which ID base elements were already added, and expand them once added. */
Map<ID_Type, TreeElement *> id_base_te_map;
/* Index for the ID base elements ("Objects", "Materials", etc). */
@@ -109,108 +154,194 @@ ListBase TreeDisplayOverrideLibraryHierarchies::build_hierarchy_for_lib_or_main(
TreeElement *new_id_te = outliner_add_element(
&space_outliner_, &new_base_te->subtree, iter_id, new_base_te, TSE_SOME_ID, 0, false);
- build_hierarchy_for_ID(bmain, *iter_id, *tree_element_cast<TreeElementID>(new_id_te));
+ builder.build_hierarchy_for_ID(*iter_id, *new_id_te);
}
FOREACH_MAIN_ID_END;
+ BKE_main_relations_free(bmain);
+
return tree;
}
-struct BuildHierarchyForeachIDCbData {
- /* Don't allow copies, the sets below would need deep copying. */
- BuildHierarchyForeachIDCbData(const BuildHierarchyForeachIDCbData &) = delete;
-
- Main &bmain;
- SpaceOutliner &space_outliner;
- ID &override_root_id;
-
- /* The tree element to expand. Changes with every level of recursion. */
- TreeElementID *parent_te;
- /* The ancestor IDs leading to the current ID, to avoid IDs recursing into themselves. Changes
- * with every level of recursion. */
- Set<ID *> parent_ids{};
- /* The IDs that were already added to #parent_te, to avoid duplicates. Entirely new set with
- * every level of recursion. */
- Set<ID *> sibling_ids{};
+void OverrideIDHierarchyBuilder::build_hierarchy_for_ID(ID &override_root_id,
+ TreeElement &te_to_expand)
+{
+ HierarchyBuildData build_data{override_root_id};
+ build_hierarchy_for_ID_recursive(override_root_id, build_data, te_to_expand);
+}
+
+enum ForeachChildReturn {
+ FOREACH_CONTINUE,
+ FOREACH_BREAK,
};
+/* Helpers (defined below). */
+static void foreach_natural_hierarchy_child(const MainIDRelations &id_relations,
+ const ID &parent_id,
+ FunctionRef<ForeachChildReturn(ID &)> fn);
+static bool id_is_in_override_hierarchy(const Main &bmain,
+ const ID &id,
+ const ID &relationship_parent_id,
+ const ID &override_root_id);
+
+void OverrideIDHierarchyBuilder::build_hierarchy_for_ID_recursive(const ID &parent_id,
+ HierarchyBuildData &build_data,
+ TreeElement &te_to_expand)
+{
+ /* In case this isn't added to the parents yet (does nothing if already there). */
+ build_data.parent_ids.add(&parent_id);
+
+ foreach_natural_hierarchy_child(id_relations_, parent_id, [&](ID &id) {
+ /* Some IDs can use themselves, early abort. */
+ if (&id == &parent_id) {
+ return FOREACH_CONTINUE;
+ }
+ if (!id_is_in_override_hierarchy(bmain_, id, parent_id, build_data.override_root_id_)) {
+ return FOREACH_CONTINUE;
+ }
+
+ /* Avoid endless recursion: If there is an ancestor for this ID already, it recurses into
+ * itself. */
+ if (build_data.parent_ids.lookup_key_default(&id, nullptr)) {
+ return FOREACH_CONTINUE;
+ }
+
+ /* Avoid duplicates: If there is a sibling for this ID already, the same ID is just used
+ * multiple times by the same parent. */
+ if (build_data.sibling_ids.lookup_key_default(&id, nullptr)) {
+ return FOREACH_CONTINUE;
+ }
+
+ /* We only want to add children whose parent isn't collapsed. Otherwise, in complex scenes with
+ * thousands of relationships, the building can slow down tremendously. Tag the parent to allow
+ * un-collapsing, but don't actually add the children. */
+ if (!TSELEM_OPEN(TREESTORE(&te_to_expand), &space_outliner_)) {
+ te_to_expand.flag |= TE_PRETEND_HAS_CHILDREN;
+ return FOREACH_BREAK;
+ }
+
+ TreeElement *new_te = outliner_add_element(
+ &space_outliner_, &te_to_expand.subtree, &id, &te_to_expand, TSE_SOME_ID, 0, false);
+
+ build_data.sibling_ids.add(&id);
+
+ /* Recurse into this ID. */
+ HierarchyBuildData child_build_data{build_data.override_root_id_};
+ child_build_data.parent_ids = build_data.parent_ids;
+ child_build_data.parent_ids.add(&id);
+ child_build_data.sibling_ids.reserve(10);
+ build_hierarchy_for_ID_recursive(id, child_build_data, *new_te);
-static int build_hierarchy_foreach_ID_cb(LibraryIDLinkCallbackData *cb_data)
+ return FOREACH_CONTINUE;
+ });
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Helpers for library override hierarchy building
+ * \{ */
+
+/**
+ * Iterate over the IDs \a parent_id uses. E.g. the child collections and contained objects of a
+ * parent collection. Also does special handling for object parenting, so that:
+ * - When iterating over a child object, \a fn is executed for the parent instead.
+ * - When iterating over a parent object, \a fn is _additionally_ executed for all children. Given
+ * that the parent object isn't skipped, the caller has to ensure it's not added in the hierarchy
+ * twice.
+ * This allows us to build the hierarchy in the expected ("natural") order, where parent objects
+ * are actual parent elements in the hierarchy, even though in data, the relation goes the other
+ * way around (children point to or "use" the parent).
+ *
+ * Only handles regular object parenting, not cases like the "Child of" constraint. Other Outliner
+ * display modes don't show this as parent in the hierarchy either.
+ */
+static void foreach_natural_hierarchy_child(const MainIDRelations &id_relations,
+ const ID &parent_id,
+ FunctionRef<ForeachChildReturn(ID &)> fn)
{
- if (!*cb_data->id_pointer) {
- return IDWALK_RET_NOP;
+ const MainIDRelationsEntry *relations_of_id = static_cast<MainIDRelationsEntry *>(
+ BLI_ghash_lookup(id_relations.relations_from_pointers, &parent_id));
+
+ /* Iterate over all IDs used by the parent ID (e.g. the child-collections of a collection). */
+ for (MainIDRelationsEntryItem *to_id_entry = relations_of_id->to_ids; to_id_entry;
+ to_id_entry = to_id_entry->next) {
+ /* An ID pointed to (used) by the ID to recurse into. */
+ ID &target_id = **to_id_entry->id_pointer.to;
+
+ /* Don't walk up the hierarchy, e.g. ignore pointers to parent collections. */
+ if (to_id_entry->usage_flag & IDWALK_CB_LOOPBACK) {
+ continue;
+ }
+
+ /* Special case for objects: Process the parent object instead of the child object. Below the
+ * parent will add the child objects then. */
+ if (GS(target_id.name) == ID_OB) {
+ const Object &potential_child_ob = reinterpret_cast<const Object &>(target_id);
+ if (potential_child_ob.parent) {
+ if (fn(potential_child_ob.parent->id) == FOREACH_BREAK) {
+ return;
+ }
+ continue;
+ }
+ }
+
+ if (fn(target_id) == FOREACH_BREAK) {
+ return;
+ }
+ }
+
+ /* If the ID is an object, find and iterate over any child objects. */
+ if (GS(parent_id.name) == ID_OB) {
+ for (MainIDRelationsEntryItem *from_id_entry = relations_of_id->from_ids; from_id_entry;
+ from_id_entry = from_id_entry->next) {
+ ID &potential_child_id = *from_id_entry->id_pointer.from;
+
+ if (GS(potential_child_id.name) != ID_OB) {
+ continue;
+ }
+
+ const Object &potential_child_ob = reinterpret_cast<Object &>(potential_child_id);
+ if (!potential_child_ob.parent || &potential_child_ob.parent->id != &parent_id) {
+ continue;
+ }
+
+ if (fn(potential_child_id) == FOREACH_BREAK) {
+ return;
+ }
+ }
}
+}
- BuildHierarchyForeachIDCbData &build_data = *reinterpret_cast<BuildHierarchyForeachIDCbData *>(
- cb_data->user_data);
- /* Note that this may be an embedded ID (see #real_override_id). */
- ID &id = **cb_data->id_pointer;
+static bool id_is_in_override_hierarchy(const Main &bmain,
+ const ID &id,
+ const ID &relationship_parent_id,
+ const ID &override_root_id)
+{
/* If #id is an embedded ID, this will be set to the owner, which is a real ID and contains the
* override data. So queries of override data should be done via this, but the actual tree
* element we add is the embedded ID. */
const ID *real_override_id = &id;
if (ID_IS_OVERRIDE_LIBRARY_VIRTUAL(&id)) {
- if (GS(id.name) == ID_KE) {
- Key *key = (Key *)&id;
- real_override_id = key->from;
- }
- else if (id.flag & LIB_EMBEDDED_DATA) {
- /* TODO Needs double-checking if this handles all embedded IDs correctly. */
- real_override_id = cb_data->id_owner;
- }
+ /* In many cases, `relationship_parent_id` is the owner, but not always (e.g. there can be
+ * drivers directly between an object and a shapekey). */
+ BKE_lib_override_library_get(const_cast<Main *>(&bmain),
+ const_cast<ID *>(&id),
+ const_cast<ID *>(&relationship_parent_id),
+ const_cast<ID **>(&real_override_id));
}
if (!ID_IS_OVERRIDE_LIBRARY(real_override_id)) {
- return IDWALK_RET_NOP;
+ return false;
}
/* Is this ID part of the same override hierarchy? */
- if (real_override_id->override_library->hierarchy_root != &build_data.override_root_id) {
- return IDWALK_RET_NOP;
+ if (real_override_id->override_library->hierarchy_root != &override_root_id) {
+ return false;
}
- /* Avoid endless recursion: If there is an ancestor for this ID already, it recurses into itself.
- */
- if (build_data.parent_ids.lookup_key_default(&id, nullptr)) {
- return IDWALK_RET_NOP;
- }
-
- /* Avoid duplicates: If there is a sibling for this ID already, the same ID is just used multiple
- * times by the same parent. */
- if (build_data.sibling_ids.lookup_key_default(&id, nullptr)) {
- return IDWALK_RET_NOP;
- }
-
- TreeElement *new_te = outliner_add_element(&build_data.space_outliner,
- &build_data.parent_te->getLegacyElement().subtree,
- &id,
- &build_data.parent_te->getLegacyElement(),
- TSE_SOME_ID,
- 0,
- false);
- build_data.sibling_ids.add(&id);
-
- BuildHierarchyForeachIDCbData child_build_data{build_data.bmain,
- build_data.space_outliner,
- build_data.override_root_id,
- tree_element_cast<TreeElementID>(new_te)};
- child_build_data.parent_ids = build_data.parent_ids;
- child_build_data.parent_ids.add(&id);
- child_build_data.sibling_ids.reserve(10);
- BKE_library_foreach_ID_link(
- &build_data.bmain, &id, build_hierarchy_foreach_ID_cb, &child_build_data, IDWALK_READONLY);
-
- return IDWALK_RET_NOP;
+ return true;
}
-void TreeDisplayOverrideLibraryHierarchies::build_hierarchy_for_ID(Main *bmain,
- ID &override_root_id,
- TreeElementID &te_id) const
-{
- BuildHierarchyForeachIDCbData build_data{*bmain, space_outliner_, override_root_id, &te_id};
- build_data.parent_ids.add(&override_root_id);
-
- BKE_library_foreach_ID_link(
- bmain, &te_id.get_ID(), build_hierarchy_foreach_ID_cb, &build_data, IDWALK_READONLY);
-}
+/** \} */
} // namespace blender::ed::outliner
diff --git a/source/blender/editors/space_outliner/tree/tree_element.cc b/source/blender/editors/space_outliner/tree/tree_element.cc
index 94d55b70e3c..4a540c3ce87 100644
--- a/source/blender/editors/space_outliner/tree/tree_element.cc
+++ b/source/blender/editors/space_outliner/tree/tree_element.cc
@@ -4,6 +4,9 @@
* \ingroup spoutliner
*/
+#include <string>
+#include <string_view>
+
#include "DNA_anim_types.h"
#include "DNA_listBase.h"
#include "DNA_space_types.h"
@@ -17,6 +20,7 @@
#include "tree_element_driver.hh"
#include "tree_element_gpencil_layer.hh"
#include "tree_element_id.hh"
+#include "tree_element_label.hh"
#include "tree_element_nla.hh"
#include "tree_element_overrides.hh"
#include "tree_element_rna.hh"
@@ -52,9 +56,11 @@ std::unique_ptr<AbstractTreeElement> AbstractTreeElement::createFromType(const i
switch (type) {
case TSE_SOME_ID:
return TreeElementID::createFromID(legacy_te, *static_cast<ID *>(idv));
+ case TSE_GENERIC_LABEL:
+ return std::make_unique<TreeElementLabel>(legacy_te, static_cast<const char *>(idv));
case TSE_ANIM_DATA:
return std::make_unique<TreeElementAnimData>(legacy_te,
- *reinterpret_cast<IdAdtTemplate *>(idv)->adt);
+ *static_cast<IdAdtTemplate *>(idv)->adt);
case TSE_DRIVER_BASE:
return std::make_unique<TreeElementDriverBase>(legacy_te, *static_cast<AnimData *>(idv));
case TSE_NLA:
@@ -76,23 +82,24 @@ std::unique_ptr<AbstractTreeElement> AbstractTreeElement::createFromType(const i
case TSE_LIBRARY_OVERRIDE:
return std::make_unique<TreeElementOverridesProperty>(
legacy_te, *static_cast<TreeElementOverridesData *>(idv));
+ case TSE_LIBRARY_OVERRIDE_OPERATION:
+ return std::make_unique<TreeElementOverridesPropertyOperation>(
+ legacy_te, *static_cast<TreeElementOverridesData *>(idv));
case TSE_RNA_STRUCT:
- return std::make_unique<TreeElementRNAStruct>(legacy_te,
- *reinterpret_cast<PointerRNA *>(idv));
+ return std::make_unique<TreeElementRNAStruct>(legacy_te, *static_cast<PointerRNA *>(idv));
case TSE_RNA_PROPERTY:
return std::make_unique<TreeElementRNAProperty>(
- legacy_te, *reinterpret_cast<PointerRNA *>(idv), legacy_te.index);
+ legacy_te, *static_cast<PointerRNA *>(idv), legacy_te.index);
case TSE_RNA_ARRAY_ELEM:
return std::make_unique<TreeElementRNAArrayElement>(
- legacy_te, *reinterpret_cast<PointerRNA *>(idv), legacy_te.index);
+ legacy_te, *static_cast<PointerRNA *>(idv), legacy_te.index);
case TSE_SEQUENCE:
- return std::make_unique<TreeElementSequence>(legacy_te, *reinterpret_cast<Sequence *>(idv));
+ return std::make_unique<TreeElementSequence>(legacy_te, *static_cast<Sequence *>(idv));
case TSE_SEQ_STRIP:
- return std::make_unique<TreeElementSequenceStrip>(legacy_te,
- *reinterpret_cast<Strip *>(idv));
+ return std::make_unique<TreeElementSequenceStrip>(legacy_te, *static_cast<Strip *>(idv));
case TSE_SEQUENCE_DUP:
- return std::make_unique<TreeElementSequenceStripDuplicate>(
- legacy_te, *reinterpret_cast<Sequence *>(idv));
+ return std::make_unique<TreeElementSequenceStripDuplicate>(legacy_te,
+ *static_cast<Sequence *>(idv));
default:
break;
}
@@ -105,6 +112,22 @@ StringRefNull AbstractTreeElement::getWarning() const
return "";
}
+std::optional<BIFIconID> AbstractTreeElement::getIcon() const
+{
+ return {};
+}
+
+void AbstractTreeElement::print_path()
+{
+ std::string path = legacy_te_.name;
+
+ for (TreeElement *parent = legacy_te_.parent; parent; parent = parent->parent) {
+ path = parent->name + std::string_view("/") + path;
+ }
+
+ std::cout << path << std::endl;
+}
+
void AbstractTreeElement::uncollapse_by_default(TreeElement *legacy_te)
{
if (!TREESTORE(legacy_te)->used) {
diff --git a/source/blender/editors/space_outliner/tree/tree_element.hh b/source/blender/editors/space_outliner/tree/tree_element.hh
index 1098068d628..1b145a48daa 100644
--- a/source/blender/editors/space_outliner/tree/tree_element.hh
+++ b/source/blender/editors/space_outliner/tree/tree_element.hh
@@ -7,15 +7,18 @@
#pragma once
#include <memory>
+#include <optional>
#include "BLI_string_ref.hh"
+#include "UI_resources.h"
struct ListBase;
struct SpaceOutliner;
-struct TreeElement;
namespace blender::ed::outliner {
+struct TreeElement;
+
/* -------------------------------------------------------------------- */
/* Tree-Display Interface */
@@ -64,6 +67,25 @@ class AbstractTreeElement {
virtual StringRefNull getWarning() const;
/**
+ * Define the icon to be displayed for this element. If this returns an icon, this will be
+ * displayed. Otherwise, #tree_element_get_icon() may still determine an icon. By default no
+ * value is returned (#std::nullopt).
+ *
+ * All elements should be ported to use this over #tree_element_get_icon().
+ */
+ virtual std::optional<BIFIconID> getIcon() const;
+
+ /**
+ * Debugging helper: Print effective path of this tree element, constructed out of the
+ * #TreeElement.name of each element. E.g.:
+ * - Lorem
+ * - ipsum dolor sit
+ * - amet
+ * will print: Lorem/ipsum dolor sit/amet.
+ */
+ void print_path();
+
+ /**
* Expand this tree element if it is displayed for the first time (as identified by its
* tree-store element).
*
diff --git a/source/blender/editors/space_outliner/tree/tree_element_anim_data.hh b/source/blender/editors/space_outliner/tree/tree_element_anim_data.hh
index 956cf3dec48..f3372329dd1 100644
--- a/source/blender/editors/space_outliner/tree/tree_element_anim_data.hh
+++ b/source/blender/editors/space_outliner/tree/tree_element_anim_data.hh
@@ -8,8 +8,6 @@
#include "tree_element.hh"
-struct TreeElement;
-
namespace blender::ed::outliner {
class TreeElementAnimData final : public AbstractTreeElement {
diff --git a/source/blender/editors/space_outliner/tree/tree_element_driver.hh b/source/blender/editors/space_outliner/tree/tree_element_driver.hh
index 053217e18ec..f0213dd39f2 100644
--- a/source/blender/editors/space_outliner/tree/tree_element_driver.hh
+++ b/source/blender/editors/space_outliner/tree/tree_element_driver.hh
@@ -8,8 +8,6 @@
#include "tree_element.hh"
-struct TreeElement;
-
namespace blender::ed::outliner {
class TreeElementDriverBase final : public AbstractTreeElement {
diff --git a/source/blender/editors/space_outliner/tree/tree_element_label.cc b/source/blender/editors/space_outliner/tree/tree_element_label.cc
new file mode 100644
index 00000000000..32fa62c5f5e
--- /dev/null
+++ b/source/blender/editors/space_outliner/tree/tree_element_label.cc
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup spoutliner
+ */
+
+#include "DNA_listBase.h"
+
+#include "DNA_outliner_types.h"
+
+#include "../outliner_intern.hh"
+
+#include "tree_element_label.hh"
+
+namespace blender::ed::outliner {
+
+TreeElementLabel::TreeElementLabel(TreeElement &legacy_te, const char *label)
+ : AbstractTreeElement(legacy_te), label_(label)
+{
+ BLI_assert(legacy_te_.store_elem->type == TSE_GENERIC_LABEL);
+ /* The draw string is actually accessed via #TreeElement.name, so make sure this always points to
+ * our string. */
+ legacy_te_.name = label_.c_str();
+}
+
+void TreeElementLabel::setIcon(const BIFIconID icon)
+{
+ icon_ = icon;
+}
+
+std::optional<BIFIconID> TreeElementLabel::getIcon() const
+{
+ return icon_;
+}
+
+} // namespace blender::ed::outliner
diff --git a/source/blender/editors/space_outliner/tree/tree_element_label.hh b/source/blender/editors/space_outliner/tree/tree_element_label.hh
new file mode 100644
index 00000000000..fc730c7b8f4
--- /dev/null
+++ b/source/blender/editors/space_outliner/tree/tree_element_label.hh
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup spoutliner
+ */
+
+#pragma once
+
+#include <string>
+
+#include "UI_resources.h"
+
+#include "tree_element.hh"
+
+namespace blender::ed::outliner {
+
+/**
+ * A basic, general purpose tree element to just display a label and an icon. Can be used to group
+ * together items underneath as well of course.
+ *
+ * Make sure to give this a unique index, so the element can be identified uniquely. Otherwise
+ * glitches like multiple highlighted elements happen, that share all state (e.g. collapsed,
+ * selected, etc.).
+ */
+class TreeElementLabel final : public AbstractTreeElement {
+ const std::string label_;
+ BIFIconID icon_ = ICON_NONE;
+
+ public:
+ TreeElementLabel(TreeElement &legacy_te, const char *label);
+
+ void setIcon(BIFIconID icon);
+ std::optional<BIFIconID> getIcon() const override;
+};
+
+} // namespace blender::ed::outliner
diff --git a/source/blender/editors/space_outliner/tree/tree_element_overrides.cc b/source/blender/editors/space_outliner/tree/tree_element_overrides.cc
index 871de39b1dd..11067d37966 100644
--- a/source/blender/editors/space_outliner/tree/tree_element_overrides.cc
+++ b/source/blender/editors/space_outliner/tree/tree_element_overrides.cc
@@ -7,30 +7,60 @@
#include "BKE_collection.h"
#include "BKE_lib_override.h"
-#include "BLI_utildefines.h"
-
+#include "BLI_function_ref.hh"
#include "BLI_listbase_wrapper.hh"
+#include "BLI_map.hh"
+#include "BLI_utildefines.h"
#include "BLT_translation.h"
#include "DNA_space_types.h"
#include "RNA_access.h"
+#include "RNA_path.h"
#include "../outliner_intern.hh"
+#include "tree_element_label.hh"
#include "tree_element_overrides.hh"
namespace blender::ed::outliner {
+class OverrideRNAPathTreeBuilder {
+ SpaceOutliner &space_outliner_;
+ Map<std::string, TreeElement *> path_te_map;
+
+ public:
+ OverrideRNAPathTreeBuilder(SpaceOutliner &space_outliner);
+ void build_path(TreeElement &parent, TreeElementOverridesData &override_data, short &index);
+
+ private:
+ TreeElement &ensure_label_element_for_prop(
+ TreeElement &parent, StringRef elem_path, PointerRNA &ptr, PropertyRNA &prop, short &index);
+ TreeElement &ensure_label_element_for_ptr(TreeElement &parent,
+ StringRef elem_path,
+ PointerRNA &ptr,
+ short &index);
+ void ensure_entire_collection(TreeElement &te_to_expand,
+ const TreeElementOverridesData &override_data,
+ const char *coll_prop_path,
+ short &index);
+};
+
+/* -------------------------------------------------------------------- */
+/** \name Base Element
+ *
+ * Represents an ID that has overridden properties. The expanding will invoke building of tree
+ * elements for the full RNA path of the property.
+ *
+ * \{ */
+
TreeElementOverridesBase::TreeElementOverridesBase(TreeElement &legacy_te, ID &id)
: AbstractTreeElement(legacy_te), id(id)
{
BLI_assert(legacy_te.store_elem->type == TSE_LIBRARY_OVERRIDE_BASE);
if (legacy_te.parent != nullptr &&
- ELEM(legacy_te.parent->store_elem->type, TSE_SOME_ID, TSE_LAYER_COLLECTION))
-
- {
+ ELEM(legacy_te.parent->store_elem->type, TSE_SOME_ID, TSE_LAYER_COLLECTION)) {
legacy_te.name = IFACE_("Library Overrides");
}
else {
@@ -51,21 +81,17 @@ StringRefNull TreeElementOverridesBase::getWarning() const
return {};
}
-void TreeElementOverridesBase::expand(SpaceOutliner &space_outliner) const
+static void iterate_properties_to_display(ID &id,
+ const bool show_system_overrides,
+ FunctionRef<void(TreeElementOverridesData &data)> fn)
{
- BLI_assert(id.override_library != nullptr);
+ PointerRNA override_rna_ptr;
+ PropertyRNA *override_rna_prop;
- const bool show_system_overrides = (SUPPORT_FILTER_OUTLINER(&space_outliner) &&
- (space_outliner.filter & SO_FILTER_SHOW_SYSTEM_OVERRIDES) !=
- 0);
PointerRNA idpoin;
RNA_id_pointer_create(&id, &idpoin);
- PointerRNA override_rna_ptr;
- PropertyRNA *override_rna_prop;
- short index = 0;
-
- for (auto *override_prop :
+ for (IDOverrideLibraryProperty *override_prop :
ListBaseWrapper<IDOverrideLibraryProperty>(id.override_library->properties)) {
int rnaprop_index = 0;
const bool is_rna_path_valid = BKE_lib_override_rna_property_find(
@@ -80,15 +106,13 @@ void TreeElementOverridesBase::expand(SpaceOutliner &space_outliner) const
/* Matching ID pointers are considered as system overrides. */
if (ELEM(override_prop->rna_prop_type, PROP_POINTER, PROP_COLLECTION) &&
RNA_struct_is_ID(RNA_property_pointer_type(&override_rna_ptr, override_rna_prop))) {
- for (auto *override_prop_op :
+ for (IDOverrideLibraryPropertyOperation *override_prop_op :
ListBaseWrapper<IDOverrideLibraryPropertyOperation>(override_prop->operations)) {
if ((override_prop_op->flag & IDOVERRIDE_LIBRARY_FLAG_IDPOINTER_MATCH_REFERENCE) == 0) {
do_skip = false;
break;
}
- else {
- is_system_override = true;
- }
+ is_system_override = true;
}
}
@@ -105,11 +129,36 @@ void TreeElementOverridesBase::expand(SpaceOutliner &space_outliner) const
TreeElementOverridesData data = {
id, *override_prop, override_rna_ptr, *override_rna_prop, is_rna_path_valid};
- outliner_add_element(
- &space_outliner, &legacy_te_.subtree, &data, &legacy_te_, TSE_LIBRARY_OVERRIDE, index++);
+
+ fn(data);
}
}
+void TreeElementOverridesBase::expand(SpaceOutliner &space_outliner) const
+{
+ BLI_assert(id.override_library != nullptr);
+
+ const bool show_system_overrides = (SUPPORT_FILTER_OUTLINER(&space_outliner) &&
+ (space_outliner.filter & SO_FILTER_SHOW_SYSTEM_OVERRIDES) !=
+ 0);
+
+ OverrideRNAPathTreeBuilder path_builder(space_outliner);
+ short index = 0;
+
+ iterate_properties_to_display(id, show_system_overrides, [&](TreeElementOverridesData &data) {
+ path_builder.build_path(legacy_te_, data, index);
+ });
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Overridden Property
+ *
+ * Represents an RNA property that was overridden.
+ *
+ * \{ */
+
TreeElementOverridesProperty::TreeElementOverridesProperty(TreeElement &legacy_te,
TreeElementOverridesData &override_data)
: AbstractTreeElement(legacy_te),
@@ -118,9 +167,10 @@ TreeElementOverridesProperty::TreeElementOverridesProperty(TreeElement &legacy_t
rna_path(override_data.override_property.rna_path),
is_rna_path_valid(override_data.is_rna_path_valid)
{
- BLI_assert(legacy_te.store_elem->type == TSE_LIBRARY_OVERRIDE);
+ BLI_assert(
+ ELEM(legacy_te.store_elem->type, TSE_LIBRARY_OVERRIDE, TSE_LIBRARY_OVERRIDE_OPERATION));
- legacy_te.name = override_data.override_property.rna_path;
+ legacy_te.name = RNA_property_ui_name(&override_data.override_rna_prop);
}
StringRefNull TreeElementOverridesProperty::getWarning() const
@@ -134,4 +184,305 @@ StringRefNull TreeElementOverridesProperty::getWarning() const
return {};
}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Overridden Property Operation
+ *
+ * See #TreeElementOverridesPropertyOperation.
+ * \{ */
+
+TreeElementOverridesPropertyOperation::TreeElementOverridesPropertyOperation(
+ TreeElement &legacy_te, TreeElementOverridesData &override_data)
+ : TreeElementOverridesProperty(legacy_te, override_data)
+{
+ BLI_assert(legacy_te.store_elem->type == TSE_LIBRARY_OVERRIDE_OPERATION);
+ BLI_assert_msg(RNA_property_type(&override_rna_prop) == PROP_COLLECTION,
+ "Override operations are only supported for collections right now");
+ /* Quiet Clang Static Analyzer warning by throwing instead of asserting (possible
+ * null-dereference). */
+ if (!override_data.operation) {
+ throw std::invalid_argument("missing operation");
+ }
+
+ operation_ = std::make_unique<IDOverrideLibraryPropertyOperation>(*override_data.operation);
+ /* Just for extra sanity. */
+ operation_->next = operation_->prev = nullptr;
+
+ if (std::optional<PointerRNA> col_item_ptr = get_collection_ptr()) {
+ const char *dyn_name = RNA_struct_name_get_alloc(&*col_item_ptr, nullptr, 0, nullptr);
+ if (dyn_name) {
+ legacy_te.name = dyn_name;
+ legacy_te.flag |= TE_FREE_NAME;
+ }
+ else {
+ legacy_te.name = RNA_struct_ui_name(col_item_ptr->type);
+ }
+ }
+}
+
+StringRefNull TreeElementOverridesPropertyOperation::getOverrideOperationLabel() const
+{
+ if (ELEM(operation_->operation,
+ IDOVERRIDE_LIBRARY_OP_INSERT_AFTER,
+ IDOVERRIDE_LIBRARY_OP_INSERT_BEFORE)) {
+ return TIP_("Added through override");
+ }
+
+ BLI_assert_unreachable();
+ return {};
+}
+
+std::optional<BIFIconID> TreeElementOverridesPropertyOperation::getIcon() const
+{
+ if (const std::optional<PointerRNA> col_item_ptr = get_collection_ptr()) {
+ return (BIFIconID)RNA_struct_ui_icon(col_item_ptr->type);
+ }
+
+ return {};
+}
+
+std::optional<PointerRNA> TreeElementOverridesPropertyOperation::get_collection_ptr() const
+{
+ PointerRNA col_item_ptr;
+ if (RNA_property_collection_lookup_int(const_cast<PointerRNA *>(&override_rna_ptr),
+ &override_rna_prop,
+ operation_->subitem_local_index,
+ &col_item_ptr)) {
+ return col_item_ptr;
+ }
+
+ return {};
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Helper to build a hierarchy from an RNA path.
+ *
+ * Builds a nice hierarchy representing the nested structs of the override property's RNA path
+ * using UI names and icons. For example `animation_visualization_mothion_path.frame_end` becomes:
+ * - Animation Visualization
+ * - Motion Paths
+ * - End Frame
+ *
+ * Paths are merged so that each RNA sub-path is only represented once in the tree. So there is
+ * some finicky path building going on to create a path -> tree-element map.
+ *
+ * This is more complicated than you'd think it needs to be. Mostly because of RNA collection
+ * overrides:
+ * - A single override may add (and in future remove) multiple collection items. So all operations
+ * of the override have to be considered.
+ * - The order of collection items may matter (e.g. for modifiers), so if collection items are
+ * added/removed, we want to show all other collection items too, in the right order.
+ *
+ * - If the override is inside some collection item, the collection item has to be built, but the
+ * RNA path iterator doesn't
+ * \{ */
+
+OverrideRNAPathTreeBuilder::OverrideRNAPathTreeBuilder(SpaceOutliner &space_outliner)
+ : space_outliner_(space_outliner)
+{
+}
+
+void OverrideRNAPathTreeBuilder::build_path(TreeElement &parent,
+ TreeElementOverridesData &override_data,
+ short &index)
+{
+ PointerRNA idpoin;
+ RNA_id_pointer_create(&override_data.id, &idpoin);
+
+ ListBase path_elems = {nullptr};
+ if (!RNA_path_resolve_elements(&idpoin, override_data.override_property.rna_path, &path_elems)) {
+ return;
+ }
+
+ const char *elem_path = nullptr;
+ TreeElement *te_to_expand = &parent;
+
+ LISTBASE_FOREACH (PropertyElemRNA *, elem, &path_elems) {
+ if (!elem->next) {
+ /* The last element is added as #TSE_LIBRARY_OVERRIDE below. */
+ break;
+ }
+ const char *previous_path = elem_path;
+ const char *new_path = RNA_path_append(previous_path, &elem->ptr, elem->prop, -1, nullptr);
+
+ te_to_expand = &ensure_label_element_for_prop(
+ *te_to_expand, new_path, elem->ptr, *elem->prop, index);
+
+ /* Above the collection property was added (e.g. "Modifiers"), to get the actual collection
+ * item the path refers to, we have to peek at the following path element and add a tree
+ * element for its pointer (e.g. "My Subdiv Modifier"). */
+ if (RNA_property_type(elem->prop) == PROP_COLLECTION) {
+ const int coll_item_idx = RNA_property_collection_lookup_index(
+ &elem->ptr, elem->prop, &elem->next->ptr);
+ const char *coll_item_path = RNA_path_append(
+ previous_path, &elem->ptr, elem->prop, coll_item_idx, nullptr);
+
+ te_to_expand = &ensure_label_element_for_ptr(
+ *te_to_expand, coll_item_path, elem->next->ptr, index);
+
+ MEM_delete(new_path);
+ new_path = coll_item_path;
+ }
+
+ if (new_path) {
+ MEM_delete(elem_path);
+ elem_path = new_path;
+ }
+ }
+ BLI_freelistN(&path_elems);
+
+ /* Special case: Overriding collections, e.g. adding or removing items. In this case we add
+ * elements for all collection items to show full context, and indicate which ones were
+ * added/removed (currently added only). Note that a single collection override may add/remove
+ * multiple items. */
+ if (RNA_property_type(&override_data.override_rna_prop) == PROP_COLLECTION) {
+ /* Tree element for the actual collection item (e.g. "Modifiers"). Can just use the override
+ * ptr & prop here, since they point to the collection property (e.g. `modifiers`). */
+ te_to_expand = &ensure_label_element_for_prop(*te_to_expand,
+ override_data.override_property.rna_path,
+ override_data.override_rna_ptr,
+ override_data.override_rna_prop,
+ index);
+
+ ensure_entire_collection(*te_to_expand, override_data, elem_path, index);
+ }
+ /* Some properties have multiple operations (e.g. an array property with multiple changed
+ * values), so the element may already be present. At this point they are displayed as a single
+ * property in the tree, so don't add it multiple times here. */
+ else if (!path_te_map.contains(override_data.override_property.rna_path)) {
+ outliner_add_element(&space_outliner_,
+ &te_to_expand->subtree,
+ &override_data,
+ te_to_expand,
+ TSE_LIBRARY_OVERRIDE,
+ index++);
+ }
+
+ MEM_delete(elem_path);
+}
+
+void OverrideRNAPathTreeBuilder::ensure_entire_collection(
+ TreeElement &te_to_expand,
+ const TreeElementOverridesData &override_data,
+ /* The path of the owning collection property. */
+ const char *coll_prop_path,
+ short &index)
+{
+ BLI_assert(tree_element_cast<AbstractTreeElement>(&te_to_expand) != nullptr);
+
+ TreeElement *previous_te = nullptr;
+ int item_idx = 0;
+ RNA_PROP_BEGIN (&override_data.override_rna_ptr, itemptr, &override_data.override_rna_prop) {
+ const char *coll_item_path = RNA_path_append(coll_prop_path,
+ &override_data.override_rna_ptr,
+ &override_data.override_rna_prop,
+ item_idx,
+ nullptr);
+ IDOverrideLibraryPropertyOperation *item_operation =
+ BKE_lib_override_library_property_operation_find(
+ &override_data.override_property, nullptr, nullptr, -1, item_idx, false, nullptr);
+ TreeElement *current_te = nullptr;
+
+ TreeElement *existing_te = path_te_map.lookup_default(coll_item_path, nullptr);
+
+ if (existing_te) {
+ /* Reinsert the element to make sure the order is right. It may have been inserted by a
+ * previous override. */
+ BLI_remlink(&te_to_expand.subtree, existing_te);
+ BLI_insertlinkafter(&te_to_expand.subtree, previous_te, existing_te);
+ current_te = existing_te;
+ }
+ /* Is there an operation for this item (added or removed the item to/from the collection)? If
+ * so indicate it as override using #TSE_LIBRARY_OVERRIDE_OPERATION. Otherwise it's just a
+ * regular collection we display for context. */
+ else if (item_operation) {
+ TreeElementOverridesData override_op_data = override_data;
+ override_op_data.operation = item_operation;
+
+ current_te = outliner_add_element(&space_outliner_,
+ &te_to_expand.subtree,
+ /* Element will store a copy. */
+ &override_op_data,
+ &te_to_expand,
+ TSE_LIBRARY_OVERRIDE_OPERATION,
+ index++);
+ }
+ else {
+ current_te = &ensure_label_element_for_ptr(te_to_expand, coll_item_path, itemptr, index);
+ }
+
+ MEM_delete(coll_item_path);
+ item_idx++;
+ previous_te = current_te;
+ }
+ RNA_PROP_END;
+}
+
+static BIFIconID get_property_icon(PointerRNA &ptr, PropertyRNA &prop)
+{
+ BIFIconID icon = (BIFIconID)RNA_property_ui_icon(&prop);
+ if (icon) {
+ return icon;
+ }
+
+ /* Try if the collection item type has a dedicated icon (e.g. #ICON_MODIFIER for the
+ * #Object.modifiers property). */
+ if (RNA_property_type(&prop) == PROP_COLLECTION) {
+ const StructRNA *coll_ptr_type = RNA_property_pointer_type(&ptr, &prop);
+ icon = (BIFIconID)RNA_struct_ui_icon(coll_ptr_type);
+ if (icon != ICON_DOT) {
+ return icon;
+ }
+ }
+
+ return ICON_NONE;
+}
+
+TreeElement &OverrideRNAPathTreeBuilder::ensure_label_element_for_prop(
+ TreeElement &parent, StringRef elem_path, PointerRNA &ptr, PropertyRNA &prop, short &index)
+{
+ return *path_te_map.lookup_or_add_cb(elem_path, [&]() {
+ TreeElement *new_te = outliner_add_element(&space_outliner_,
+ &parent.subtree,
+ (void *)RNA_property_ui_name(&prop),
+ &parent,
+ TSE_GENERIC_LABEL,
+ index++,
+ false);
+ TreeElementLabel *te_label = tree_element_cast<TreeElementLabel>(new_te);
+
+ te_label->setIcon(get_property_icon(ptr, prop));
+ return new_te;
+ });
+}
+
+TreeElement &OverrideRNAPathTreeBuilder::ensure_label_element_for_ptr(TreeElement &parent,
+ StringRef elem_path,
+ PointerRNA &ptr,
+ short &index)
+{
+ return *path_te_map.lookup_or_add_cb(elem_path, [&]() {
+ const char *dyn_name = RNA_struct_name_get_alloc(&ptr, nullptr, 0, nullptr);
+
+ TreeElement *new_te = outliner_add_element(
+ &space_outliner_,
+ &parent.subtree,
+ (void *)(dyn_name ? dyn_name : RNA_struct_ui_name(ptr.type)),
+ &parent,
+ TSE_GENERIC_LABEL,
+ index++);
+ TreeElementLabel *te_label = tree_element_cast<TreeElementLabel>(new_te);
+ te_label->setIcon((BIFIconID)RNA_struct_ui_icon(ptr.type));
+
+ MEM_delete(dyn_name);
+
+ return new_te;
+ });
+}
+
+/** \} */
+
} // namespace blender::ed::outliner
diff --git a/source/blender/editors/space_outliner/tree/tree_element_overrides.hh b/source/blender/editors/space_outliner/tree/tree_element_overrides.hh
index 1db46d9af1d..f8ca146a4ea 100644
--- a/source/blender/editors/space_outliner/tree/tree_element_overrides.hh
+++ b/source/blender/editors/space_outliner/tree/tree_element_overrides.hh
@@ -14,6 +14,7 @@
struct ID;
struct IDOverrideLibraryProperty;
+struct IDOverrideLibraryPropertyOperation;
namespace blender::ed::outliner {
@@ -24,6 +25,11 @@ struct TreeElementOverridesData {
PropertyRNA &override_rna_prop;
bool is_rna_path_valid;
+
+ /* In case the property references a specific operation. Only used for collection overrides
+ * currently, where a single override may add/remove multiple collection items (only add
+ * currently). */
+ IDOverrideLibraryPropertyOperation *operation = nullptr;
};
class TreeElementOverridesBase final : public AbstractTreeElement {
@@ -38,7 +44,12 @@ class TreeElementOverridesBase final : public AbstractTreeElement {
StringRefNull getWarning() const override;
};
-class TreeElementOverridesProperty final : public AbstractTreeElement {
+/**
+ * Represent a single overridden property. Collection properties may support multiple override
+ * operations, e.g. to insert/remove multiple collection items. For these multiple operation cases,
+ * use #TreeElementOverridesPropertyOperation.
+ */
+class TreeElementOverridesProperty : public AbstractTreeElement {
public:
PointerRNA override_rna_ptr;
PropertyRNA &override_rna_prop;
@@ -50,6 +61,33 @@ class TreeElementOverridesProperty final : public AbstractTreeElement {
TreeElementOverridesProperty(TreeElement &legacy_te, TreeElementOverridesData &override_data);
StringRefNull getWarning() const override;
+
+ bool isCollectionOperation() const;
+};
+
+/**
+ * Represent a single operation within an overridden property. While usually a single override
+ * property represents a single operation (changing the value), a single overridden collection
+ * property may have multiple operations, e.g. to insert or remove collection items.
+ *
+ * Inherits from the override property class since it should look/behave mostly the same.
+ */
+class TreeElementOverridesPropertyOperation final : public TreeElementOverridesProperty {
+ /** See #TreeElementOverridesData::operation. Operations are recreated as part of the diffing
+ * (e.g. on undo pushes) so store a copy of the data here. */
+ std::unique_ptr<IDOverrideLibraryPropertyOperation> operation_;
+
+ public:
+ TreeElementOverridesPropertyOperation(TreeElement &legacy_te,
+ TreeElementOverridesData &override_data);
+
+ /** Return a short string to display in the right column of the properties mode, indicating what
+ * the override operation did (e.g. added or removed a collection item). */
+ StringRefNull getOverrideOperationLabel() const;
+ std::optional<BIFIconID> getIcon() const override;
+
+ private:
+ std::optional<PointerRNA> get_collection_ptr() const;
};
} // namespace blender::ed::outliner
diff --git a/source/blender/editors/space_outliner/tree/tree_element_rna.cc b/source/blender/editors/space_outliner/tree/tree_element_rna.cc
index 914104f1f06..9e1f22b49d6 100644
--- a/source/blender/editors/space_outliner/tree/tree_element_rna.cc
+++ b/source/blender/editors/space_outliner/tree/tree_element_rna.cc
@@ -117,14 +117,14 @@ void TreeElementRNAStruct::expand(SpaceOutliner &space_outliner) const
for (int index = 0; index < tot; index++) {
PointerRNA propptr;
RNA_property_collection_lookup_int(&ptr, iterprop, index, &propptr);
- if (!(RNA_property_flag(reinterpret_cast<PropertyRNA *>(propptr.data)) & PROP_HIDDEN)) {
+ if (!(RNA_property_flag(static_cast<PropertyRNA *>(propptr.data)) & PROP_HIDDEN)) {
outliner_add_element(
&space_outliner, &legacy_te_.subtree, &ptr, &legacy_te_, TSE_RNA_PROPERTY, index);
}
}
}
else if (tot) {
- legacy_te_.flag |= TE_LAZY_CLOSED;
+ legacy_te_.flag |= TE_PRETEND_HAS_CHILDREN;
}
}
@@ -146,7 +146,7 @@ TreeElementRNAProperty::TreeElementRNAProperty(TreeElement &legacy_te,
PropertyRNA *iterprop = RNA_struct_iterator_property(rna_ptr.type);
RNA_property_collection_lookup_int(&rna_ptr, iterprop, index, &propptr);
- PropertyRNA *prop = reinterpret_cast<PropertyRNA *>(propptr.data);
+ PropertyRNA *prop = static_cast<PropertyRNA *>(propptr.data);
legacy_te_.name = RNA_property_ui_name(prop);
rna_prop_ = prop;
@@ -172,7 +172,7 @@ void TreeElementRNAProperty::expand(SpaceOutliner &space_outliner) const
&space_outliner, &legacy_te_.subtree, &pptr, &legacy_te_, TSE_RNA_STRUCT, -1);
}
else {
- legacy_te_.flag |= TE_LAZY_CLOSED;
+ legacy_te_.flag |= TE_PRETEND_HAS_CHILDREN;
}
}
}
@@ -189,7 +189,7 @@ void TreeElementRNAProperty::expand(SpaceOutliner &space_outliner) const
}
}
else if (tot) {
- legacy_te_.flag |= TE_LAZY_CLOSED;
+ legacy_te_.flag |= TE_PRETEND_HAS_CHILDREN;
}
}
else if (ELEM(proptype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
@@ -207,7 +207,7 @@ void TreeElementRNAProperty::expand(SpaceOutliner &space_outliner) const
}
}
else if (tot) {
- legacy_te_.flag |= TE_LAZY_CLOSED;
+ legacy_te_.flag |= TE_PRETEND_HAS_CHILDREN;
}
}
}
@@ -232,8 +232,7 @@ TreeElementRNAArrayElement::TreeElementRNAArrayElement(TreeElement &legacy_te,
char c = RNA_property_array_item_char(TreeElementRNAArrayElement::getPropertyRNA(), index);
- legacy_te_.name = reinterpret_cast<char *>(
- MEM_callocN(sizeof(char[20]), "OutlinerRNAArrayName"));
+ legacy_te_.name = static_cast<char *>(MEM_callocN(sizeof(char[20]), "OutlinerRNAArrayName"));
if (c) {
sprintf((char *)legacy_te_.name, " %c", c);
}
diff --git a/source/blender/editors/space_outliner/tree/tree_iterator.hh b/source/blender/editors/space_outliner/tree/tree_iterator.hh
index de5bcd2c462..0c94c2f95cf 100644
--- a/source/blender/editors/space_outliner/tree/tree_iterator.hh
+++ b/source/blender/editors/space_outliner/tree/tree_iterator.hh
@@ -10,9 +10,11 @@
struct ListBase;
struct SpaceOutliner;
-struct TreeElement;
namespace blender::ed::outliner {
+
+struct TreeElement;
+
namespace tree_iterator {
using VisitorFn = FunctionRef<void(TreeElement *)>;