[Bf-blender-cvs] [1383c53e188] temp-library-overrides-outliner: Display modifiers and other collections with overrides in the tree

Julian Eisel noreply at git.blender.org
Tue Mar 1 15:38:24 CET 2022


Commit: 1383c53e188ae4bd083634c3cd03247c3ff2448f
Author: Julian Eisel
Date:   Tue Mar 1 15:27:56 2022 +0100
Branches: temp-library-overrides-outliner
https://developer.blender.org/rB1383c53e188ae4bd083634c3cd03247c3ff2448f

Display modifiers and other collections with overrides in the tree

Rather than only displaying individual overriden modifier in the tree,
all are shown now, since the other modifiers add important context (e.g.
the order). This is especially important when a modifier was added
through an override. Same for constraints and in fact all other
collection properties now. The items are grouped together under a parent
item (e.g. "Modifiers").

Also:
- Path segments that define nested structs (RNA pointer properties where
  the pointer property itself isn't the override) will also be displayed
  as a parent item now, as explained in T95802, since this comes
  naturally from the code added for grouping collection items. If we end
  up not liking this, and rather display a single item with a sub-path,
  this can easily be done still.

===================================================================

M	source/blender/editors/space_outliner/outliner_draw.cc
M	source/blender/editors/space_outliner/outliner_tree.cc
M	source/blender/editors/space_outliner/tree/tree_element.cc
M	source/blender/editors/space_outliner/tree/tree_element.hh
M	source/blender/editors/space_outliner/tree/tree_element_overrides.cc
M	source/blender/editors/space_outliner/tree/tree_element_overrides.hh
M	source/blender/makesdna/DNA_outliner_types.h

===================================================================

diff --git a/source/blender/editors/space_outliner/outliner_draw.cc b/source/blender/editors/space_outliner/outliner_draw.cc
index c6816bc9bd2..16c6c4809e1 100644
--- a/source/blender/editors/space_outliner/outliner_draw.cc
+++ b/source/blender/editors/space_outliner/outliner_draw.cc
@@ -2405,6 +2405,12 @@ TreeElementIcon tree_element_get_icon(TreeStoreElem *tselem, TreeElement *te)
       case TSE_LIBRARY_OVERRIDE:
         data.icon = ICON_LIBRARY_DATA_OVERRIDE;
         break;
+      case TSE_LIBRARY_OVERRIDE_RNA_COLLECTION_ITEM: {
+        const auto &override_col_item = tree_element_cast<TreeElementOverrideRNACollectionItem>(
+            te);
+        data.icon = override_col_item->getIcon();
+        break;
+      }
       case TSE_LINKED_OB:
         data.icon = ICON_OBJECT_DATA;
         break;
@@ -3337,7 +3343,11 @@ static void outliner_draw_tree_element(bContext *C,
     offsx += UI_UNIT_X;
 
     /* Data-type icon. */
-    if (!(ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM, TSE_ID_BASE))) {
+    if (!(ELEM(tselem->type,
+               TSE_RNA_PROPERTY,
+               TSE_RNA_ARRAY_ELEM,
+               TSE_ID_BASE,
+               TSE_LIBRARY_OVERRIDE_RNA_CONTAINER))) {
       tselem_draw_icon(block,
                        xmax,
                        (float)startx + offsx,
diff --git a/source/blender/editors/space_outliner/outliner_tree.cc b/source/blender/editors/space_outliner/outliner_tree.cc
index 06a5918f25c..673fe8ae1c6 100644
--- a/source/blender/editors/space_outliner/outliner_tree.cc
+++ b/source/blender/editors/space_outliner/outliner_tree.cc
@@ -871,7 +871,11 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner,
       BLI_assert_msg(0, "Expected this ID type to be ported to new Outliner tree-element design");
     }
   }
-  else if (ELEM(type, TSE_LIBRARY_OVERRIDE_BASE, TSE_LIBRARY_OVERRIDE)) {
+  else if (ELEM(type,
+                TSE_LIBRARY_OVERRIDE_BASE,
+                TSE_LIBRARY_OVERRIDE,
+                TSE_LIBRARY_OVERRIDE_RNA_CONTAINER,
+                TSE_LIBRARY_OVERRIDE_RNA_COLLECTION_ITEM)) {
     if (!te->abstract_element) {
       BLI_assert_msg(0,
                      "Expected override types to be ported to new Outliner tree-element design");
diff --git a/source/blender/editors/space_outliner/tree/tree_element.cc b/source/blender/editors/space_outliner/tree/tree_element.cc
index 3c2023d7905..7b0db0d46ba 100644
--- a/source/blender/editors/space_outliner/tree/tree_element.cc
+++ b/source/blender/editors/space_outliner/tree/tree_element.cc
@@ -74,6 +74,12 @@ 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_RNA_CONTAINER:
+      return std::make_unique<TreeElementOverrideRNAContainer>(
+          legacy_te, *static_cast<PropertyPointerRNA *>(idv));
+    case TSE_LIBRARY_OVERRIDE_RNA_COLLECTION_ITEM:
+      return std::make_unique<TreeElementOverrideRNACollectionItem>(
+          legacy_te, *static_cast<PointerRNA *>(idv));
     case TSE_RNA_STRUCT:
       return std::make_unique<TreeElementRNAStruct>(legacy_te,
                                                     *reinterpret_cast<PointerRNA *>(idv));
@@ -98,6 +104,11 @@ std::unique_ptr<AbstractTreeElement> AbstractTreeElement::createFromType(const i
   return nullptr;
 }
 
+TreeElement &AbstractTreeElement::getLegacyElement() const
+{
+  return legacy_te_;
+}
+
 void tree_element_expand(const AbstractTreeElement &tree_element, SpaceOutliner &space_outliner)
 {
   /* Most types can just expand. IDs optionally expand (hence the poll) and do additional, common
diff --git a/source/blender/editors/space_outliner/tree/tree_element.hh b/source/blender/editors/space_outliner/tree/tree_element.hh
index 996f51eee82..9e52f9fc34b 100644
--- a/source/blender/editors/space_outliner/tree/tree_element.hh
+++ b/source/blender/editors/space_outliner/tree/tree_element.hh
@@ -53,6 +53,8 @@ class AbstractTreeElement {
     return true;
   }
 
+  TreeElement &getLegacyElement() const;
+
   friend void tree_element_expand(const AbstractTreeElement &tree_element,
                                   SpaceOutliner &space_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 4820a0f69ac..97279df560e 100644
--- a/source/blender/editors/space_outliner/tree/tree_element_overrides.cc
+++ b/source/blender/editors/space_outliner/tree/tree_element_overrides.cc
@@ -38,6 +38,63 @@ TreeElementOverridesBase::TreeElementOverridesBase(TreeElement &legacy_te, ID &i
   }
 }
 
+static void expand_from_rna_path(SpaceOutliner &space_outliner,
+                                 TreeElement &path_root_te,
+                                 TreeElementOverridesData &override_data,
+                                 int *index)
+{
+  PointerRNA idpoin;
+  RNA_id_pointer_create(&override_data.id, &idpoin);
+
+  TreeElement *parent_to_expand = &path_root_te;
+
+  ListBase path_elems{nullptr};
+  RNA_path_resolve_elements(&idpoin, override_data.override_property.rna_path, &path_elems);
+
+  /* Iterate the properties represented by the path. */
+  LISTBASE_FOREACH (PropertyElemRNA *, prop_ptr_from_path, &path_elems) {
+    /* Create containers for all items that are not leafs (i.e. that are not simple properties, but
+     * may contain child properties). */
+    if (prop_ptr_from_path->next) {
+      PropertyPointerRNA property_and_ptr = {prop_ptr_from_path->ptr, prop_ptr_from_path->prop};
+      TreeElement *container_te = outliner_add_element(&space_outliner,
+                                                       &parent_to_expand->subtree,
+                                                       &property_and_ptr,
+                                                       parent_to_expand,
+                                                       TSE_LIBRARY_OVERRIDE_RNA_CONTAINER,
+                                                       *index++);
+
+      parent_to_expand = container_te;
+      /* Iterate over the children the container item expanded, and continue building the path for
+       * the item that matches the current path segment. */
+      LISTBASE_FOREACH (TreeElement *, container_item_te, &container_te->subtree) {
+        if (auto *col_item_te = tree_element_cast<TreeElementOverrideRNACollectionItem>(
+                container_item_te)) {
+          /* Does the collection item RNA pointer match the RNA pointer of the next property in the
+           * path? */
+          if (col_item_te->item_ptr.data == prop_ptr_from_path->next->ptr.data) {
+            parent_to_expand = &col_item_te->getLegacyElement();
+          }
+        }
+      }
+
+      continue;
+    }
+
+    /* The actually overridden property. Must be a "leaf" property (end of the path). */
+    BLI_assert(prop_ptr_from_path->next == nullptr);
+    /* The actual override. */
+    outliner_add_element(&space_outliner,
+                         &parent_to_expand->subtree,
+                         &override_data,
+                         parent_to_expand,
+                         TSE_LIBRARY_OVERRIDE,
+                         *index++);
+  }
+
+  BLI_freelistN(&path_elems);
+}
+
 void TreeElementOverridesBase::expand(SpaceOutliner &space_outliner) const
 {
   BLI_assert(id_.override_library != nullptr);
@@ -50,7 +107,7 @@ void TreeElementOverridesBase::expand(SpaceOutliner &space_outliner) const
 
   PointerRNA override_rna_ptr;
   PropertyRNA *override_rna_prop;
-  short index = 0;
+  int index = 0;
 
   for (IDOverrideLibraryProperty *override_prop :
        ListBaseWrapper<IDOverrideLibraryProperty>(id_.override_library->properties)) {
@@ -73,10 +130,9 @@ void TreeElementOverridesBase::expand(SpaceOutliner &space_outliner) const
       }
     }
 
-    TreeElementOverridesData data = {
+    TreeElementOverridesData override_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++);
+    expand_from_rna_path(space_outliner, legacy_te_, override_data, &index);
   }
 }
 
@@ -89,10 +145,59 @@ TreeElementOverridesProperty::TreeElementOverridesProperty(TreeElement &legacy_t
 {
   BLI_assert(legacy_te.store_elem->type == TSE_LIBRARY_OVERRIDE);
 
-  legacy_te.name = override_prop_.rna_path;
+  legacy_te.name = RNA_property_identifier(&override_rna_prop);
   /* Abusing this for now, better way to do it is also pending current refactor of the whole tree
    * code to use C++. */
   legacy_te.directdata = POINTER_FROM_UINT(override_data.is_rna_path_valid);
 }
 
+TreeElementOverrideRNAContainer::TreeElementOverrideRNAContainer(
+    TreeElement &legacy_te, PropertyPointerRNA &container_prop_and_ptr)
+    : AbstractTreeElement(legacy_te),
+      container_ptr(container_prop_and_ptr.ptr),
+      container_prop(*container_prop_and_ptr.prop)
+{
+  BLI_assert(legacy_te.store_elem->type == TSE_LIBRARY_OVERRIDE_RNA_CONTAINER);
+  legacy_te.name = RNA_property_ui_name(&container_prop);
+}
+
+void TreeElementOverrideRNAContainer::expand(SpaceOutliner &space_outliner) const
+{
+  if (RNA_property_type(&container_prop) != PROP_COLLECTION) {
+    /* Only expand RNA collections. For them the exact item order may matter (e.g. for modifiers),
+     * so display them all to provide full context. */
+    return;
+  }
+
+  int index = 0;
+  /* Non-const copy. */
+  PointerRNA ptr = container_ptr;
+  RNA_PROP_BEGIN (&ptr, itemptr, &container_prop) {
+    outliner_add_element(&space_outliner,
+                         &legacy_te_.subtree,
+                         &itemptr,
+                         &legacy_te_,
+                         TSE_LIBRARY_OVERRIDE_RNA_COLLECTION_ITEM,
+                         index++);
+  }
+  RNA_PROP_END;
+}
+
+TreeElementOverrideRNACollectionItem::TreeElementOverrideRNACollectionItem(
+    TreeElement &legacy_te, const PointerRNA &item_ptr)
+    : AbstractTreeElement(legacy_te), item_ptr(item_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list